@navios/core 1.0.0-alpha.2 → 1.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/lib/{index-BJjk2X1S.d.mts → index-BISYCYEG.d.mts} +435 -180
- package/lib/index-BISYCYEG.d.mts.map +1 -0
- package/lib/{index-DZ6NU03y.d.cts → index-CP80H6Dh.d.cts} +435 -180
- package/lib/index-CP80H6Dh.d.cts.map +1 -0
- package/lib/index.cjs +3 -2
- package/lib/index.d.cts +2 -2
- package/lib/index.d.mts +2 -2
- package/lib/index.mjs +2 -2
- package/lib/legacy-compat/index.cjs +38 -124
- package/lib/legacy-compat/index.cjs.map +1 -1
- package/lib/legacy-compat/index.d.cts +4 -60
- package/lib/legacy-compat/index.d.cts.map +1 -1
- package/lib/legacy-compat/index.d.mts +4 -60
- package/lib/legacy-compat/index.d.mts.map +1 -1
- package/lib/legacy-compat/index.mjs +12 -118
- package/lib/legacy-compat/index.mjs.map +1 -1
- package/lib/{src-C46ePe3d.cjs → src-CC5lmk_Q.cjs} +167 -2
- package/lib/src-CC5lmk_Q.cjs.map +1 -0
- package/lib/{src-K2k0riYJ.mjs → src-j1cBuAgy.mjs} +162 -3
- package/lib/src-j1cBuAgy.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 +1 -1
- package/lib/{use-guards.decorator-B6tghdxM.cjs → use-guards.decorator-DtCGXcWZ.cjs} +2 -2
- package/lib/{use-guards.decorator-B6tghdxM.cjs.map → use-guards.decorator-DtCGXcWZ.cjs.map} +1 -1
- package/package.json +2 -2
- package/src/__tests__/attribute.factory.spec.mts +300 -0
- package/src/__tests__/guard-runner.service.spec.mts +399 -0
- package/src/__tests__/logger.service.spec.mts +147 -0
- package/src/__tests__/responders.spec.mts +6 -5
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +86 -2
- package/src/legacy-compat/attribute.factory.mts +2 -2
- package/src/legacy-compat/decorators/controller.decorator.mts +1 -1
- package/src/legacy-compat/decorators/endpoint.decorator.mts +1 -1
- package/src/legacy-compat/decorators/header.decorator.mts +2 -1
- package/src/legacy-compat/decorators/http-code.decorator.mts +2 -1
- package/src/legacy-compat/decorators/index.mts +2 -2
- package/src/legacy-compat/decorators/module.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/legacy-compat/decorators/use-guards.decorator.mts +1 -1
- package/src/legacy-compat/index.mts +10 -5
- package/src/services/abstract-handler-adapter.service.mts +366 -0
- package/src/services/index.mts +1 -0
- package/lib/index-BJjk2X1S.d.mts.map +0 -1
- package/lib/index-DZ6NU03y.d.cts.map +0 -1
- package/lib/src-C46ePe3d.cjs.map +0 -1
- package/lib/src-K2k0riYJ.mjs.map +0 -1
- package/src/legacy-compat/context-compat.mts +0 -95
- package/src/legacy-compat/decorators/factory.decorator.mts +0 -37
- package/src/legacy-compat/decorators/injectable.decorator.mts +0 -41
|
@@ -979,8 +979,79 @@ type DynamicHandler<TRequest = any, TReply = any> = {
|
|
|
979
979
|
* Can be either static (pre-resolved) or dynamic (needs scoped container).
|
|
980
980
|
*/
|
|
981
981
|
type HandlerResult<TRequest = any, TReply = any> = StaticHandler<TRequest, TReply> | DynamicHandler<TRequest, TReply>;
|
|
982
|
-
|
|
983
|
-
|
|
982
|
+
/**
|
|
983
|
+
* Function type for argument getters that extract data from requests.
|
|
984
|
+
* Each getter populates a target object with data from the request.
|
|
985
|
+
*/
|
|
986
|
+
type ArgumentGetterFn<TRequest = any> = (target: Record<string, any>, request: TRequest) => void | Promise<void>;
|
|
987
|
+
/**
|
|
988
|
+
* Function type for formatting arguments from a request.
|
|
989
|
+
* Built from argument getters, optimized for sync/async handling.
|
|
990
|
+
*/
|
|
991
|
+
type FormatArgumentsFn$1<TRequest = any> = (request: TRequest) => Record<string, any> | Promise<Record<string, any>>;
|
|
992
|
+
/**
|
|
993
|
+
* Interface for HTTP handler adapter services.
|
|
994
|
+
*
|
|
995
|
+
* Adapters handle different types of HTTP requests (REST, streaming, multipart)
|
|
996
|
+
* and are responsible for:
|
|
997
|
+
* - Parsing and validating request data
|
|
998
|
+
* - Creating handler functions
|
|
999
|
+
* - Formatting responses
|
|
1000
|
+
* - Providing schema information (for frameworks like Fastify)
|
|
1001
|
+
*/
|
|
1002
|
+
interface AbstractHttpHandlerAdapterInterface<TRequest = any> {
|
|
1003
|
+
/**
|
|
1004
|
+
* Prepares argument getters for parsing request data.
|
|
1005
|
+
*
|
|
1006
|
+
* Creates functions that extract and validate data from the request,
|
|
1007
|
+
* populating a target object with validated arguments.
|
|
1008
|
+
*
|
|
1009
|
+
* @param handlerMetadata - The handler metadata with schemas and configuration.
|
|
1010
|
+
* @returns An array of getter functions that populate request arguments.
|
|
1011
|
+
*/
|
|
1012
|
+
prepareArguments?: (handlerMetadata: HandlerMetadata<any>) => ArgumentGetterFn<TRequest>[];
|
|
1013
|
+
/**
|
|
1014
|
+
* Builds a formatArguments function from argument getters.
|
|
1015
|
+
*
|
|
1016
|
+
* Automatically detects sync vs async getters and optimizes accordingly:
|
|
1017
|
+
* - If all getters are sync: returns sync function (no Promise overhead)
|
|
1018
|
+
* - If any getter is async: returns async function with Promise.all
|
|
1019
|
+
* - If no getters: returns frozen empty object (zero allocation)
|
|
1020
|
+
*
|
|
1021
|
+
* This method is useful for composition-based adapters that need to
|
|
1022
|
+
* build formatArguments without duplicating the optimization logic.
|
|
1023
|
+
*
|
|
1024
|
+
* @param getters - Array of argument getter functions
|
|
1025
|
+
* @returns Function to format arguments from request
|
|
1026
|
+
*/
|
|
1027
|
+
buildFormatArguments?: (getters: ArgumentGetterFn<TRequest>[]) => FormatArgumentsFn$1<TRequest>;
|
|
1028
|
+
/**
|
|
1029
|
+
* Checks if the handler has any validation schemas defined.
|
|
1030
|
+
*
|
|
1031
|
+
* @param handlerMetadata - The handler metadata containing configuration.
|
|
1032
|
+
* @returns `true` if the handler has any schemas (request, query, response).
|
|
1033
|
+
*/
|
|
1034
|
+
hasSchema?: (handlerMetadata: HandlerMetadata<any>) => boolean;
|
|
1035
|
+
/**
|
|
1036
|
+
* Provides schema information for the framework's validation system.
|
|
1037
|
+
*
|
|
1038
|
+
* For frameworks like Fastify, this returns route schema objects.
|
|
1039
|
+
* For frameworks like Bun, this typically returns an empty object.
|
|
1040
|
+
*
|
|
1041
|
+
* @param handlerMetadata - The handler metadata containing configuration.
|
|
1042
|
+
* @returns Schema information for framework registration.
|
|
1043
|
+
*/
|
|
1044
|
+
provideSchema?: (handlerMetadata: HandlerMetadata<any>) => Record<string, any>;
|
|
1045
|
+
/**
|
|
1046
|
+
* Creates a request handler function for the endpoint.
|
|
1047
|
+
*
|
|
1048
|
+
* This is the core method that generates the actual handler function
|
|
1049
|
+
* that will be called when a request matches the endpoint.
|
|
1050
|
+
*
|
|
1051
|
+
* @param controller - The controller class containing the handler method.
|
|
1052
|
+
* @param handlerMetadata - The handler metadata with configuration and schemas.
|
|
1053
|
+
* @returns A handler result that is either static or dynamic.
|
|
1054
|
+
*/
|
|
984
1055
|
provideHandler: (controller: ClassType, handlerMetadata: HandlerMetadata<any>) => Promise<HandlerResult>;
|
|
985
1056
|
}
|
|
986
1057
|
//#endregion
|
|
@@ -2104,180 +2175,6 @@ declare const ValidationErrorResponderToken: InjectionToken<ErrorResponder, unde
|
|
|
2104
2175
|
*/
|
|
2105
2176
|
declare const ForbiddenResponderToken: InjectionToken<ErrorResponder, undefined, false>;
|
|
2106
2177
|
//#endregion
|
|
2107
|
-
//#region src/services/instance-resolver.service.d.mts
|
|
2108
|
-
/**
|
|
2109
|
-
* Result of instance resolution attempt.
|
|
2110
|
-
* Contains either a cached singleton instance or a resolver function
|
|
2111
|
-
* that can be used to get a fresh instance per request.
|
|
2112
|
-
*/
|
|
2113
|
-
interface InstanceResolution<T = any> {
|
|
2114
|
-
/**
|
|
2115
|
-
* Whether the instance was successfully cached as a singleton.
|
|
2116
|
-
* If true, `instance` contains the cached instance.
|
|
2117
|
-
* If false, the class has request-scoped dependencies and
|
|
2118
|
-
* must be resolved per-request using `resolve()`.
|
|
2119
|
-
*/
|
|
2120
|
-
cached: boolean;
|
|
2121
|
-
/**
|
|
2122
|
-
* The cached instance (only available if `cached` is true).
|
|
2123
|
-
*/
|
|
2124
|
-
instance: T | null;
|
|
2125
|
-
/**
|
|
2126
|
-
* Resolves the instance from a scoped container.
|
|
2127
|
-
* Use this when `cached` is false to get a fresh instance per request.
|
|
2128
|
-
*/
|
|
2129
|
-
resolve: (scoped: ScopedContainer) => Promise<T>;
|
|
2130
|
-
}
|
|
2131
|
-
/**
|
|
2132
|
-
* Result of resolving multiple instances.
|
|
2133
|
-
* Contains either all cached singleton instances or a resolver function.
|
|
2134
|
-
*/
|
|
2135
|
-
interface MultiInstanceResolution<T = any> {
|
|
2136
|
-
/**
|
|
2137
|
-
* Whether ALL instances were successfully cached as singletons.
|
|
2138
|
-
* If true, `instances` contains all cached instances.
|
|
2139
|
-
* If false, at least one class has request-scoped dependencies.
|
|
2140
|
-
*/
|
|
2141
|
-
cached: boolean;
|
|
2142
|
-
/**
|
|
2143
|
-
* The cached instances (only available if `cached` is true).
|
|
2144
|
-
* Order matches the input array order.
|
|
2145
|
-
*/
|
|
2146
|
-
instances: T[] | null;
|
|
2147
|
-
/**
|
|
2148
|
-
* The original class types for dynamic resolution.
|
|
2149
|
-
*/
|
|
2150
|
-
classTypes: ClassType[];
|
|
2151
|
-
/**
|
|
2152
|
-
* Resolves all instances from a scoped container.
|
|
2153
|
-
* Use this when `cached` is false to get fresh instances per request.
|
|
2154
|
-
*/
|
|
2155
|
-
resolve: (scoped: ScopedContainer) => Promise<T[]>;
|
|
2156
|
-
}
|
|
2157
|
-
/**
|
|
2158
|
-
* Service responsible for resolving class instances with automatic scope detection.
|
|
2159
|
-
*
|
|
2160
|
-
* This service attempts to resolve classes as singletons from the root container.
|
|
2161
|
-
* If resolution fails (because the class has request-scoped dependencies),
|
|
2162
|
-
* it automatically updates the class's scope to Request and provides a
|
|
2163
|
-
* resolver function for per-request instantiation.
|
|
2164
|
-
*
|
|
2165
|
-
* This enables optimal performance:
|
|
2166
|
-
* - Classes without request-scoped deps stay as singletons (faster)
|
|
2167
|
-
* - Classes with request-scoped deps are automatically promoted to request scope
|
|
2168
|
-
*
|
|
2169
|
-
* @example
|
|
2170
|
-
* ```ts
|
|
2171
|
-
* const resolution = await instanceResolver.resolve(UserController)
|
|
2172
|
-
*
|
|
2173
|
-
* if (resolution.cached) {
|
|
2174
|
-
* // Use cached singleton
|
|
2175
|
-
* return resolution.instance.handleRequest(req)
|
|
2176
|
-
* } else {
|
|
2177
|
-
* // Resolve per request
|
|
2178
|
-
* const controller = await resolution.resolve(scopedContainer)
|
|
2179
|
-
* return controller.handleRequest(req)
|
|
2180
|
-
* }
|
|
2181
|
-
* ```
|
|
2182
|
-
*/
|
|
2183
|
-
declare class InstanceResolverService {
|
|
2184
|
-
private container;
|
|
2185
|
-
/**
|
|
2186
|
-
* Attempts to resolve a class instance, automatically detecting if it needs
|
|
2187
|
-
* request scope based on its dependencies.
|
|
2188
|
-
*
|
|
2189
|
-
* @param classType - The class to resolve
|
|
2190
|
-
* @returns A resolution result containing either a cached instance or resolver function
|
|
2191
|
-
*/
|
|
2192
|
-
resolve<T>(classType: ClassType): Promise<InstanceResolution<T>>;
|
|
2193
|
-
/**
|
|
2194
|
-
* Attempts to resolve multiple class instances, automatically detecting if any need
|
|
2195
|
-
* request scope based on their dependencies.
|
|
2196
|
-
*
|
|
2197
|
-
* Returns `cached: true` only if ALL classes can be resolved as singletons.
|
|
2198
|
-
* If any class has request-scoped dependencies, returns `cached: false`.
|
|
2199
|
-
*
|
|
2200
|
-
* @param classTypes - The classes to resolve
|
|
2201
|
-
* @returns A resolution result containing either all cached instances or resolver function
|
|
2202
|
-
*/
|
|
2203
|
-
resolveMany<T>(classTypes: ClassType[]): Promise<MultiInstanceResolution<T>>;
|
|
2204
|
-
}
|
|
2205
|
-
/**
|
|
2206
|
-
* @deprecated Use InstanceResolverService instead
|
|
2207
|
-
*/
|
|
2208
|
-
declare const ControllerResolverService: typeof InstanceResolverService;
|
|
2209
|
-
/**
|
|
2210
|
-
* @deprecated Use InstanceResolution instead
|
|
2211
|
-
*/
|
|
2212
|
-
type ControllerResolution<T = any> = InstanceResolution<T>;
|
|
2213
|
-
//#endregion
|
|
2214
|
-
//#region src/services/guard-runner.service.d.mts
|
|
2215
|
-
declare class GuardRunnerService {
|
|
2216
|
-
private readonly errorProducer;
|
|
2217
|
-
private readonly logger;
|
|
2218
|
-
/**
|
|
2219
|
-
* Runs guards that need to be resolved from a scoped container.
|
|
2220
|
-
* Use this when guards have request-scoped dependencies.
|
|
2221
|
-
*/
|
|
2222
|
-
runGuards(allGuards: Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>, executionContext: AbstractExecutionContext, context: ScopedContainer): Promise<boolean>;
|
|
2223
|
-
/**
|
|
2224
|
-
* Runs pre-resolved guard instances.
|
|
2225
|
-
* Use this when all guards are singletons and have been pre-resolved at startup.
|
|
2226
|
-
*/
|
|
2227
|
-
runGuardsStatic(guardInstances: CanActivate[], executionContext: AbstractExecutionContext): Promise<boolean>;
|
|
2228
|
-
/**
|
|
2229
|
-
* Shared guard execution logic.
|
|
2230
|
-
* Iterates through guard instances and calls canActivate on each.
|
|
2231
|
-
*/
|
|
2232
|
-
private executeGuards;
|
|
2233
|
-
makeContext(moduleMetadata: ModuleMetadata, controllerMetadata: ControllerMetadata, endpoint: HandlerMetadata): Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>;
|
|
2234
|
-
}
|
|
2235
|
-
//#endregion
|
|
2236
|
-
//#region src/stores/request-id.store.d.mts
|
|
2237
|
-
/**
|
|
2238
|
-
* Generates a simple incremental request ID.
|
|
2239
|
-
* Much faster than crypto.randomUUID() and sufficient for request tracking.
|
|
2240
|
-
*
|
|
2241
|
-
* @returns A unique request ID string (e.g., "req-1", "req-2", ...)
|
|
2242
|
-
*/
|
|
2243
|
-
declare function generateRequestId(): string;
|
|
2244
|
-
/**
|
|
2245
|
-
* Enables or disables request ID propagation.
|
|
2246
|
-
* Called by NaviosFactory based on the enableRequestId option.
|
|
2247
|
-
*
|
|
2248
|
-
* @param enabled - Whether to enable request ID propagation
|
|
2249
|
-
*/
|
|
2250
|
-
declare function setRequestIdEnabled(enabled: boolean): void;
|
|
2251
|
-
/**
|
|
2252
|
-
* Runs a function with a request ID in the async local storage context.
|
|
2253
|
-
* If request ID propagation is disabled, the function is called directly
|
|
2254
|
-
* without AsyncLocalStorage overhead.
|
|
2255
|
-
*
|
|
2256
|
-
* @param requestId - The request ID to set for this context
|
|
2257
|
-
* @param fn - The function to run within this context
|
|
2258
|
-
* @returns The return value of the function
|
|
2259
|
-
*/
|
|
2260
|
-
declare function runWithRequestId<R>(requestId: string, fn: () => R): R;
|
|
2261
|
-
/**
|
|
2262
|
-
* Gets the current request ID from the async local storage context.
|
|
2263
|
-
*
|
|
2264
|
-
* @returns The current request ID, or undefined if not in a request context
|
|
2265
|
-
*/
|
|
2266
|
-
declare function getRequestId(): string | undefined;
|
|
2267
|
-
//#endregion
|
|
2268
|
-
//#region src/tokens/endpoint-adapter.token.d.mts
|
|
2269
|
-
declare const EndpointAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface, undefined, false>;
|
|
2270
|
-
//#endregion
|
|
2271
|
-
//#region src/tokens/execution-context.token.d.mts
|
|
2272
|
-
declare const ExecutionContextInjectionToken = "ExecutionContextInjectionToken";
|
|
2273
|
-
declare const ExecutionContext: InjectionToken<AbstractExecutionContext, undefined, false>;
|
|
2274
|
-
//#endregion
|
|
2275
|
-
//#region src/tokens/http-adapter.token.d.mts
|
|
2276
|
-
declare const HttpAdapterToken: InjectionToken<AbstractHttpAdapterInterface<any, any, any, any>, undefined, false>;
|
|
2277
|
-
//#endregion
|
|
2278
|
-
//#region src/tokens/multipart-adapter.token.d.mts
|
|
2279
|
-
declare const MultipartAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface, undefined, false>;
|
|
2280
|
-
//#endregion
|
|
2281
2178
|
//#region src/navios.environment.d.mts
|
|
2282
2179
|
interface NaviosEnvironmentOptions {
|
|
2283
2180
|
httpTokens?: Map<InjectionToken<any, undefined>, AnyInjectableType>;
|
|
@@ -2522,6 +2419,364 @@ declare class NaviosApplication {
|
|
|
2522
2419
|
close(): Promise<void>;
|
|
2523
2420
|
}
|
|
2524
2421
|
//#endregion
|
|
2422
|
+
//#region src/services/instance-resolver.service.d.mts
|
|
2423
|
+
/**
|
|
2424
|
+
* Result of instance resolution attempt.
|
|
2425
|
+
* Contains either a cached singleton instance or a resolver function
|
|
2426
|
+
* that can be used to get a fresh instance per request.
|
|
2427
|
+
*/
|
|
2428
|
+
interface InstanceResolution<T = any> {
|
|
2429
|
+
/**
|
|
2430
|
+
* Whether the instance was successfully cached as a singleton.
|
|
2431
|
+
* If true, `instance` contains the cached instance.
|
|
2432
|
+
* If false, the class has request-scoped dependencies and
|
|
2433
|
+
* must be resolved per-request using `resolve()`.
|
|
2434
|
+
*/
|
|
2435
|
+
cached: boolean;
|
|
2436
|
+
/**
|
|
2437
|
+
* The cached instance (only available if `cached` is true).
|
|
2438
|
+
*/
|
|
2439
|
+
instance: T | null;
|
|
2440
|
+
/**
|
|
2441
|
+
* Resolves the instance from a scoped container.
|
|
2442
|
+
* Use this when `cached` is false to get a fresh instance per request.
|
|
2443
|
+
*/
|
|
2444
|
+
resolve: (scoped: ScopedContainer) => Promise<T>;
|
|
2445
|
+
}
|
|
2446
|
+
/**
|
|
2447
|
+
* Result of resolving multiple instances.
|
|
2448
|
+
* Contains either all cached singleton instances or a resolver function.
|
|
2449
|
+
*/
|
|
2450
|
+
interface MultiInstanceResolution<T = any> {
|
|
2451
|
+
/**
|
|
2452
|
+
* Whether ALL instances were successfully cached as singletons.
|
|
2453
|
+
* If true, `instances` contains all cached instances.
|
|
2454
|
+
* If false, at least one class has request-scoped dependencies.
|
|
2455
|
+
*/
|
|
2456
|
+
cached: boolean;
|
|
2457
|
+
/**
|
|
2458
|
+
* The cached instances (only available if `cached` is true).
|
|
2459
|
+
* Order matches the input array order.
|
|
2460
|
+
*/
|
|
2461
|
+
instances: T[] | null;
|
|
2462
|
+
/**
|
|
2463
|
+
* The original class types for dynamic resolution.
|
|
2464
|
+
*/
|
|
2465
|
+
classTypes: ClassType[];
|
|
2466
|
+
/**
|
|
2467
|
+
* Resolves all instances from a scoped container.
|
|
2468
|
+
* Use this when `cached` is false to get fresh instances per request.
|
|
2469
|
+
*/
|
|
2470
|
+
resolve: (scoped: ScopedContainer) => Promise<T[]>;
|
|
2471
|
+
}
|
|
2472
|
+
/**
|
|
2473
|
+
* Service responsible for resolving class instances with automatic scope detection.
|
|
2474
|
+
*
|
|
2475
|
+
* This service attempts to resolve classes as singletons from the root container.
|
|
2476
|
+
* If resolution fails (because the class has request-scoped dependencies),
|
|
2477
|
+
* it automatically updates the class's scope to Request and provides a
|
|
2478
|
+
* resolver function for per-request instantiation.
|
|
2479
|
+
*
|
|
2480
|
+
* This enables optimal performance:
|
|
2481
|
+
* - Classes without request-scoped deps stay as singletons (faster)
|
|
2482
|
+
* - Classes with request-scoped deps are automatically promoted to request scope
|
|
2483
|
+
*
|
|
2484
|
+
* @example
|
|
2485
|
+
* ```ts
|
|
2486
|
+
* const resolution = await instanceResolver.resolve(UserController)
|
|
2487
|
+
*
|
|
2488
|
+
* if (resolution.cached) {
|
|
2489
|
+
* // Use cached singleton
|
|
2490
|
+
* return resolution.instance.handleRequest(req)
|
|
2491
|
+
* } else {
|
|
2492
|
+
* // Resolve per request
|
|
2493
|
+
* const controller = await resolution.resolve(scopedContainer)
|
|
2494
|
+
* return controller.handleRequest(req)
|
|
2495
|
+
* }
|
|
2496
|
+
* ```
|
|
2497
|
+
*/
|
|
2498
|
+
declare class InstanceResolverService {
|
|
2499
|
+
private container;
|
|
2500
|
+
/**
|
|
2501
|
+
* Attempts to resolve a class instance, automatically detecting if it needs
|
|
2502
|
+
* request scope based on its dependencies.
|
|
2503
|
+
*
|
|
2504
|
+
* @param classType - The class to resolve
|
|
2505
|
+
* @returns A resolution result containing either a cached instance or resolver function
|
|
2506
|
+
*/
|
|
2507
|
+
resolve<T>(classType: ClassType): Promise<InstanceResolution<T>>;
|
|
2508
|
+
/**
|
|
2509
|
+
* Attempts to resolve multiple class instances, automatically detecting if any need
|
|
2510
|
+
* request scope based on their dependencies.
|
|
2511
|
+
*
|
|
2512
|
+
* Returns `cached: true` only if ALL classes can be resolved as singletons.
|
|
2513
|
+
* If any class has request-scoped dependencies, returns `cached: false`.
|
|
2514
|
+
*
|
|
2515
|
+
* @param classTypes - The classes to resolve
|
|
2516
|
+
* @returns A resolution result containing either all cached instances or resolver function
|
|
2517
|
+
*/
|
|
2518
|
+
resolveMany<T>(classTypes: ClassType[]): Promise<MultiInstanceResolution<T>>;
|
|
2519
|
+
}
|
|
2520
|
+
/**
|
|
2521
|
+
* @deprecated Use InstanceResolverService instead
|
|
2522
|
+
*/
|
|
2523
|
+
declare const ControllerResolverService: typeof InstanceResolverService;
|
|
2524
|
+
/**
|
|
2525
|
+
* @deprecated Use InstanceResolution instead
|
|
2526
|
+
*/
|
|
2527
|
+
type ControllerResolution<T = any> = InstanceResolution<T>;
|
|
2528
|
+
//#endregion
|
|
2529
|
+
//#region src/services/abstract-handler-adapter.service.d.mts
|
|
2530
|
+
/**
|
|
2531
|
+
* Function type for argument getters that extract data from requests.
|
|
2532
|
+
* Re-exported from interface for convenience in adapter implementations.
|
|
2533
|
+
*/
|
|
2534
|
+
type ArgumentGetter<TRequest> = ArgumentGetterFn<TRequest>;
|
|
2535
|
+
/**
|
|
2536
|
+
* Internal alias for FormatArgumentsFn from interface.
|
|
2537
|
+
* Not re-exported to avoid duplicate exports - use FormatArgumentsFn from interfaces instead.
|
|
2538
|
+
*/
|
|
2539
|
+
type FormatArgumentsFn<TRequest> = FormatArgumentsFn$1<TRequest>;
|
|
2540
|
+
/**
|
|
2541
|
+
* Static handler - can be called without a scoped container.
|
|
2542
|
+
*/
|
|
2543
|
+
type AbstractStaticHandler<TRequest, TReply = void> = {
|
|
2544
|
+
isStatic: true;
|
|
2545
|
+
handler: (request: TRequest, reply: TReply) => Promise<any>;
|
|
2546
|
+
};
|
|
2547
|
+
/**
|
|
2548
|
+
* Dynamic handler - requires a scoped container for resolution.
|
|
2549
|
+
*/
|
|
2550
|
+
type AbstractDynamicHandler<TRequest, TReply = void> = {
|
|
2551
|
+
isStatic: false;
|
|
2552
|
+
handler: (scoped: ScopedContainer, request: TRequest, reply: TReply) => Promise<any>;
|
|
2553
|
+
};
|
|
2554
|
+
/**
|
|
2555
|
+
* Handler result - either static or dynamic.
|
|
2556
|
+
*/
|
|
2557
|
+
type AbstractHandlerResult<TRequest, TReply = void> = AbstractStaticHandler<TRequest, TReply> | AbstractDynamicHandler<TRequest, TReply>;
|
|
2558
|
+
/**
|
|
2559
|
+
* Context passed to handler creation methods.
|
|
2560
|
+
*/
|
|
2561
|
+
interface HandlerContext<TConfig extends BaseEndpointOptions = BaseEndpointOptions> {
|
|
2562
|
+
methodName: string;
|
|
2563
|
+
statusCode: number;
|
|
2564
|
+
headers: Partial<Record<HttpHeader, number | string | string[] | undefined>>;
|
|
2565
|
+
handlerMetadata: HandlerMetadata<TConfig>;
|
|
2566
|
+
hasArguments: boolean;
|
|
2567
|
+
}
|
|
2568
|
+
/**
|
|
2569
|
+
* Abstract base class for HTTP handler adapter services.
|
|
2570
|
+
*
|
|
2571
|
+
* Provides shared logic for:
|
|
2572
|
+
* - Controller resolution (singleton vs request-scoped)
|
|
2573
|
+
* - Argument formatting (sync/async detection)
|
|
2574
|
+
* - Handler generation with static/dynamic branching
|
|
2575
|
+
* - Standardized error handling
|
|
2576
|
+
*
|
|
2577
|
+
* Adapters implement abstract methods for framework-specific behavior:
|
|
2578
|
+
* - Request parsing (query, body, URL params)
|
|
2579
|
+
* - Response creation
|
|
2580
|
+
* - Schema provision
|
|
2581
|
+
*
|
|
2582
|
+
* Supports all adapter types:
|
|
2583
|
+
* - Endpoint adapters: JSON request/response with validation
|
|
2584
|
+
* - Stream adapters: Streaming responses with extra context
|
|
2585
|
+
* - Multipart adapters: Form data parsing (extends endpoint)
|
|
2586
|
+
*
|
|
2587
|
+
* @typeParam TRequest - Framework request type (BunRequest, FastifyRequest)
|
|
2588
|
+
* @typeParam TReply - Framework reply type (void for Bun, FastifyReply)
|
|
2589
|
+
* @typeParam TConfig - Endpoint configuration type
|
|
2590
|
+
*/
|
|
2591
|
+
declare abstract class AbstractHandlerAdapterService<TRequest, TReply = void, TConfig extends BaseEndpointOptions = BaseEndpointOptions> {
|
|
2592
|
+
protected instanceResolver: InstanceResolverService;
|
|
2593
|
+
protected options: NaviosApplicationOptions;
|
|
2594
|
+
/**
|
|
2595
|
+
* Creates argument getter functions for extracting data from requests.
|
|
2596
|
+
*
|
|
2597
|
+
* Each getter populates a target object with data from the request
|
|
2598
|
+
* (query params, body, URL params, etc.).
|
|
2599
|
+
*
|
|
2600
|
+
* Implementation varies by adapter type:
|
|
2601
|
+
* - Endpoint: JSON body parsing with schema validation
|
|
2602
|
+
* - Stream: Same as endpoint (body + query + url params)
|
|
2603
|
+
* - Multipart: FormData/multipart stream parsing
|
|
2604
|
+
*
|
|
2605
|
+
* @param handlerMetadata - Handler metadata with schemas and configuration
|
|
2606
|
+
* @returns Array of getter functions
|
|
2607
|
+
*/
|
|
2608
|
+
protected abstract createArgumentGetters(handlerMetadata: HandlerMetadata<TConfig>): ArgumentGetter<TRequest>[];
|
|
2609
|
+
/**
|
|
2610
|
+
* Creates a static handler for singleton controllers.
|
|
2611
|
+
*
|
|
2612
|
+
* Implementation varies by adapter type:
|
|
2613
|
+
* - Endpoint: Invoke method(args), serialize response as JSON
|
|
2614
|
+
* - Stream: Invoke method(args, streamContext), return Response/use reply
|
|
2615
|
+
*
|
|
2616
|
+
* @param boundMethod - Pre-bound controller method
|
|
2617
|
+
* @param formatArguments - Function to format request arguments
|
|
2618
|
+
* @param context - Handler context with metadata
|
|
2619
|
+
* @returns Static handler result
|
|
2620
|
+
*/
|
|
2621
|
+
protected abstract createStaticHandler(boundMethod: (...args: any[]) => Promise<any>, formatArguments: FormatArgumentsFn<TRequest>, context: HandlerContext<TConfig>): AbstractStaticHandler<TRequest, TReply>;
|
|
2622
|
+
/**
|
|
2623
|
+
* Creates a dynamic handler for request-scoped controllers.
|
|
2624
|
+
*
|
|
2625
|
+
* Implementation varies by adapter type:
|
|
2626
|
+
* - Endpoint: Resolve controller per-request, invoke method(args)
|
|
2627
|
+
* - Stream: Resolve controller per-request, invoke method(args, streamContext)
|
|
2628
|
+
*
|
|
2629
|
+
* @param resolution - Instance resolution with resolve function
|
|
2630
|
+
* @param formatArguments - Function to format request arguments
|
|
2631
|
+
* @param context - Handler context with metadata
|
|
2632
|
+
* @returns Dynamic handler result
|
|
2633
|
+
*/
|
|
2634
|
+
protected abstract createDynamicHandler(resolution: InstanceResolution, formatArguments: FormatArgumentsFn<TRequest>, context: HandlerContext<TConfig>): AbstractDynamicHandler<TRequest, TReply>;
|
|
2635
|
+
/**
|
|
2636
|
+
* Prepares argument getters for parsing request data.
|
|
2637
|
+
*
|
|
2638
|
+
* Public alias for createArgumentGetters to satisfy interface contracts.
|
|
2639
|
+
* Subclasses should override createArgumentGetters instead.
|
|
2640
|
+
*
|
|
2641
|
+
* @param handlerMetadata - Handler metadata with schemas and configuration
|
|
2642
|
+
* @returns Array of getter functions
|
|
2643
|
+
*/
|
|
2644
|
+
prepareArguments(handlerMetadata: HandlerMetadata<TConfig>): ArgumentGetter<TRequest>[];
|
|
2645
|
+
/**
|
|
2646
|
+
* Checks if the handler has any validation schemas defined.
|
|
2647
|
+
*
|
|
2648
|
+
* Override in subclasses to add additional schema checks
|
|
2649
|
+
* (e.g., response schema validation for endpoint adapters).
|
|
2650
|
+
*
|
|
2651
|
+
* @param handlerMetadata - Handler metadata with configuration
|
|
2652
|
+
* @returns true if handler has schemas
|
|
2653
|
+
*/
|
|
2654
|
+
hasSchema(handlerMetadata: HandlerMetadata<TConfig>): boolean;
|
|
2655
|
+
/**
|
|
2656
|
+
* Provides schema information for the framework's validation system.
|
|
2657
|
+
*
|
|
2658
|
+
* Override in subclasses for frameworks that support schema registration
|
|
2659
|
+
* (e.g., Fastify). Default returns empty object (suitable for Bun).
|
|
2660
|
+
*
|
|
2661
|
+
* @param handlerMetadata - Handler metadata with configuration
|
|
2662
|
+
* @returns Schema object for framework registration
|
|
2663
|
+
*/
|
|
2664
|
+
provideSchema(_handlerMetadata: HandlerMetadata<TConfig>): Record<string, any>;
|
|
2665
|
+
/**
|
|
2666
|
+
* Creates a request handler function for the endpoint.
|
|
2667
|
+
*
|
|
2668
|
+
* This method orchestrates the entire handler creation:
|
|
2669
|
+
* 1. Prepares argument getters for request parsing
|
|
2670
|
+
* 2. Builds optimized formatArguments function (sync/async)
|
|
2671
|
+
* 3. Resolves the controller (singleton vs request-scoped)
|
|
2672
|
+
* 4. Creates appropriate handler (static or dynamic)
|
|
2673
|
+
*
|
|
2674
|
+
* @param controller - Controller class containing the handler method
|
|
2675
|
+
* @param handlerMetadata - Handler metadata with configuration
|
|
2676
|
+
* @returns Handler result (static or dynamic)
|
|
2677
|
+
*/
|
|
2678
|
+
provideHandler(controller: ClassType, handlerMetadata: HandlerMetadata<TConfig>): Promise<AbstractHandlerResult<TRequest, TReply>>;
|
|
2679
|
+
/**
|
|
2680
|
+
* Builds a formatArguments function from argument getters.
|
|
2681
|
+
*
|
|
2682
|
+
* Automatically detects sync vs async getters and optimizes accordingly:
|
|
2683
|
+
* - If all getters are sync: returns sync function (no Promise overhead)
|
|
2684
|
+
* - If any getter is async: returns async function with Promise.all
|
|
2685
|
+
* - If no getters: returns frozen empty object (zero allocation)
|
|
2686
|
+
*
|
|
2687
|
+
* This method is public to allow composition-based adapters (like XML adapter)
|
|
2688
|
+
* to reuse the optimized formatArguments logic without inheritance.
|
|
2689
|
+
*
|
|
2690
|
+
* @param getters - Array of argument getter functions
|
|
2691
|
+
* @returns Function to format arguments from request
|
|
2692
|
+
*/
|
|
2693
|
+
buildFormatArguments(getters: ArgumentGetter<TRequest>[]): FormatArgumentsFn<TRequest>;
|
|
2694
|
+
/**
|
|
2695
|
+
* Checks if the URL pattern contains URL parameters.
|
|
2696
|
+
*
|
|
2697
|
+
* @param config - Endpoint configuration
|
|
2698
|
+
* @returns true if URL contains '$' parameter markers
|
|
2699
|
+
*/
|
|
2700
|
+
protected hasUrlParams(config: TConfig): boolean;
|
|
2701
|
+
/**
|
|
2702
|
+
* Wraps handler execution with standardized error handling.
|
|
2703
|
+
*
|
|
2704
|
+
* Re-throws HttpExceptions as-is for framework error handlers.
|
|
2705
|
+
* Other errors are re-thrown for global error handling.
|
|
2706
|
+
*
|
|
2707
|
+
* @param fn - Handler function to wrap
|
|
2708
|
+
* @returns Wrapped function with error handling
|
|
2709
|
+
*/
|
|
2710
|
+
protected wrapWithErrorHandling<T extends (...args: any[]) => Promise<any>>(fn: T): T;
|
|
2711
|
+
}
|
|
2712
|
+
//#endregion
|
|
2713
|
+
//#region src/services/guard-runner.service.d.mts
|
|
2714
|
+
declare class GuardRunnerService {
|
|
2715
|
+
private readonly errorProducer;
|
|
2716
|
+
private readonly logger;
|
|
2717
|
+
/**
|
|
2718
|
+
* Runs guards that need to be resolved from a scoped container.
|
|
2719
|
+
* Use this when guards have request-scoped dependencies.
|
|
2720
|
+
*/
|
|
2721
|
+
runGuards(allGuards: Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>, executionContext: AbstractExecutionContext, context: ScopedContainer): Promise<boolean>;
|
|
2722
|
+
/**
|
|
2723
|
+
* Runs pre-resolved guard instances.
|
|
2724
|
+
* Use this when all guards are singletons and have been pre-resolved at startup.
|
|
2725
|
+
*/
|
|
2726
|
+
runGuardsStatic(guardInstances: CanActivate[], executionContext: AbstractExecutionContext): Promise<boolean>;
|
|
2727
|
+
/**
|
|
2728
|
+
* Shared guard execution logic.
|
|
2729
|
+
* Iterates through guard instances and calls canActivate on each.
|
|
2730
|
+
*/
|
|
2731
|
+
private executeGuards;
|
|
2732
|
+
makeContext(moduleMetadata: ModuleMetadata, controllerMetadata: ControllerMetadata, endpoint: HandlerMetadata): Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>;
|
|
2733
|
+
}
|
|
2734
|
+
//#endregion
|
|
2735
|
+
//#region src/stores/request-id.store.d.mts
|
|
2736
|
+
/**
|
|
2737
|
+
* Generates a simple incremental request ID.
|
|
2738
|
+
* Much faster than crypto.randomUUID() and sufficient for request tracking.
|
|
2739
|
+
*
|
|
2740
|
+
* @returns A unique request ID string (e.g., "req-1", "req-2", ...)
|
|
2741
|
+
*/
|
|
2742
|
+
declare function generateRequestId(): string;
|
|
2743
|
+
/**
|
|
2744
|
+
* Enables or disables request ID propagation.
|
|
2745
|
+
* Called by NaviosFactory based on the enableRequestId option.
|
|
2746
|
+
*
|
|
2747
|
+
* @param enabled - Whether to enable request ID propagation
|
|
2748
|
+
*/
|
|
2749
|
+
declare function setRequestIdEnabled(enabled: boolean): void;
|
|
2750
|
+
/**
|
|
2751
|
+
* Runs a function with a request ID in the async local storage context.
|
|
2752
|
+
* If request ID propagation is disabled, the function is called directly
|
|
2753
|
+
* without AsyncLocalStorage overhead.
|
|
2754
|
+
*
|
|
2755
|
+
* @param requestId - The request ID to set for this context
|
|
2756
|
+
* @param fn - The function to run within this context
|
|
2757
|
+
* @returns The return value of the function
|
|
2758
|
+
*/
|
|
2759
|
+
declare function runWithRequestId<R>(requestId: string, fn: () => R): R;
|
|
2760
|
+
/**
|
|
2761
|
+
* Gets the current request ID from the async local storage context.
|
|
2762
|
+
*
|
|
2763
|
+
* @returns The current request ID, or undefined if not in a request context
|
|
2764
|
+
*/
|
|
2765
|
+
declare function getRequestId(): string | undefined;
|
|
2766
|
+
//#endregion
|
|
2767
|
+
//#region src/tokens/endpoint-adapter.token.d.mts
|
|
2768
|
+
declare const EndpointAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface<any>, undefined, false>;
|
|
2769
|
+
//#endregion
|
|
2770
|
+
//#region src/tokens/execution-context.token.d.mts
|
|
2771
|
+
declare const ExecutionContextInjectionToken = "ExecutionContextInjectionToken";
|
|
2772
|
+
declare const ExecutionContext: InjectionToken<AbstractExecutionContext, undefined, false>;
|
|
2773
|
+
//#endregion
|
|
2774
|
+
//#region src/tokens/http-adapter.token.d.mts
|
|
2775
|
+
declare const HttpAdapterToken: InjectionToken<AbstractHttpAdapterInterface<any, any, any, any>, undefined, false>;
|
|
2776
|
+
//#endregion
|
|
2777
|
+
//#region src/tokens/multipart-adapter.token.d.mts
|
|
2778
|
+
declare const MultipartAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface<any>, undefined, false>;
|
|
2779
|
+
//#endregion
|
|
2525
2780
|
//#region src/tokens/navios-options.token.d.mts
|
|
2526
2781
|
declare const NaviosOptionsToken: InjectionToken<NaviosApplicationOptions, undefined, false>;
|
|
2527
2782
|
//#endregion
|
|
@@ -2532,10 +2787,10 @@ declare const Reply: InjectionToken<any, undefined, false>;
|
|
|
2532
2787
|
declare const Request: InjectionToken<any, undefined, false>;
|
|
2533
2788
|
//#endregion
|
|
2534
2789
|
//#region src/tokens/stream-adapter.token.d.mts
|
|
2535
|
-
declare const StreamAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface
|
|
2790
|
+
declare const StreamAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface<any>, undefined, false>;
|
|
2536
2791
|
//#endregion
|
|
2537
2792
|
//#region src/tokens/xml-stream-adapter.token.d.mts
|
|
2538
|
-
declare const XmlStreamAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface
|
|
2793
|
+
declare const XmlStreamAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface<any>, undefined, false>;
|
|
2539
2794
|
//#endregion
|
|
2540
2795
|
//#region src/attribute.factory.d.mts
|
|
2541
2796
|
/**
|
|
@@ -2818,5 +3073,5 @@ declare class NaviosFactory {
|
|
|
2818
3073
|
private static registerLoggerConfiguration;
|
|
2819
3074
|
}
|
|
2820
3075
|
//#endregion
|
|
2821
|
-
export {
|
|
2822
|
-
//# sourceMappingURL=index-
|
|
3076
|
+
export { ConflictException as $, normalizePath as $t, AbstractStaticHandler as A, Controller as An, StaticHandler as At, ForbiddenResponderToken as B, Path as Bn, ConsoleLoggerOptions as Bt, getRequestId as C, EndpointMetadataKey as Cn, OmitIndexSignature as Ct, AbstractDynamicHandler as D, Endpoint as Dn, DynamicHandler as Dt, GuardRunnerService as E, getEndpointMetadata as En, ArgumentGetterFn as Et, InstanceResolution as F, ConfigService as Fn, LoggerOptions as Ft, NotFoundResponderService as G, envString as Gn, isFunction as Gt, NotFoundResponderToken as H, PathImpl2 as Hn, addLeadingSlash as Ht, InstanceResolverService as I, ConfigServiceOptions as In, LoggerOutput as It, ErrorResponseProducerService as J, isObject as Jt, InternalServerErrorResponderService as K, isNil as Kt, MultiInstanceResolution as L, ConfigServiceOptionsSchema as Ln, loggerOptionsSchema as Lt, HandlerContext as M, ConfigProviderOptions as Mn, AbstractHttpListenOptions as Mt, ControllerResolution as N, EnvConfigProvider as Nn, AbstractHttpCorsOptions as Nt, AbstractHandlerAdapterService as O, EndpointParams as On, FormatArgumentsFn$1 as Ot, ControllerResolverService as P, provideConfig as Pn, Logger as Pt, FrameworkError as Q, isUndefined as Qt, NaviosApplication as R, ConfigServiceToken as Rn, LoggerInstance as Rt, generateRequestId as S, hasControllerMetadata as Sn, HttpHeader as St, setRequestIdEnabled as T, getAllEndpointMetadata as Tn, AbstractHttpHandlerAdapterInterface as Tt, ValidationErrorResponderToken as U, PathValue as Un, isConstructor as Ut, InternalServerErrorResponderToken as V, PathImpl as Vn, LoggerService as Vt, ValidationErrorResponderService as W, envInt as Wn, isEmpty as Wt, ErrorResponse as X, isString as Xt, ErrorResponder as Y, isPlainObject as Yt, ProblemDetails as Z, isSymbol as Zt, MultipartAdapterToken as _, hasModuleMetadata as _n, PluginContext as _t, RequestFactory as a, LogLevel as an, HttpException as at, ExecutionContextInjectionToken as b, extractControllerMetadata as bn, ModuleLoaderService as bt, EndpointAdapterFactory as c, AbstractExecutionContext as cn, StreamParams as ct, ClassSchemaAttribute as d, getManagedMetadata as dn, MultipartResult as dt, stripEndSlash as en, UnauthorizedException as et, XmlStreamAdapterToken as f, hasManagedMetadata as fn, Module as ft, NaviosOptionsToken as g, getModuleMetadata as gn, NaviosPlugin as gt, Reply as h, extractModuleMetadata as hn, Header as ht, ReplyFactory as i, LOG_LEVELS as in, BadRequestException as it, ArgumentGetter as j, ControllerOptions as jn, AbstractHttpAdapterInterface as jt, AbstractHandlerResult as k, EndpointResult as kn, HandlerResult as kt, AttributeFactory as l, ManagedMetadata as ln, Multipart as lt, Request as m, ModuleMetadataKey as mn, HttpCode as mt, XmlStreamAdapterFactory as n, isLogLevel as nn, InternalServerErrorException as nt, MultipartAdapterFactory as o, clc as on, UseGuards as ot, StreamAdapterToken as p, ModuleMetadata as pn, ModuleOptions as pt, ForbiddenResponderService as q, isNumber as qt, StreamAdapterFactory as r, filterLogLevels as rn, ForbiddenException as rt, HttpAdapterFactory as s, yellow as sn, Stream as st, NaviosFactory as t, isLogLevelEnabled as tn, NotFoundException as tt, ClassAttribute as u, NaviosManagedMetadataKey as un, MultipartParams as ut, HttpAdapterToken as v, ControllerMetadata as vn, PluginDefinition as vt, runWithRequestId as w, HandlerMetadata as wn, CanActivate as wt, EndpointAdapterToken as x, getControllerMetadata as xn, NaviosModule as xt, ExecutionContext as y, ControllerMetadataKey as yn, ModuleExtension as yt, NaviosApplicationOptions as z, ConfigServiceInterface as zn, ConsoleLogger as zt };
|
|
3077
|
+
//# sourceMappingURL=index-CP80H6Dh.d.cts.map
|