@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { C as extractModuleMetadata, M as getEndpointMetadata, O as getControllerMetadata, T as hasModuleMetadata, _ as EndpointAdapterToken, b as getManagedMetadata, c as XmlStreamAdapterToken, d as Reply, f as NaviosOptionsToken, k as hasControllerMetadata, l as StreamAdapterToken, m as HttpAdapterToken, p as MultipartAdapterToken, u as Request, w as getModuleMetadata, x as hasManagedMetadata } from "./use-guards.decorator-Be_QUx6b.mjs";
|
|
2
|
-
import { Container, Factory, Injectable, InjectableScope, InjectionToken, getInjectableToken, inject } from "@navios/di";
|
|
2
|
+
import { Container, Factory, Injectable, InjectableScope, InjectionToken, getInjectableToken, inject, optional } from "@navios/di";
|
|
3
3
|
import { env } from "node:process";
|
|
4
4
|
import z, { ZodError, treeifyError, z as z$1 } from "zod/v4";
|
|
5
5
|
import { NaviosError } from "@navios/builder";
|
|
@@ -3774,6 +3774,165 @@ var InstanceResolverService = class {
|
|
|
3774
3774
|
* @deprecated Use InstanceResolverService instead
|
|
3775
3775
|
*/ const ControllerResolverService = _InstanceResolverService;
|
|
3776
3776
|
|
|
3777
|
+
//#endregion
|
|
3778
|
+
//#region src/services/abstract-handler-adapter.service.mts
|
|
3779
|
+
const defaultOptions = {
|
|
3780
|
+
adapter: [],
|
|
3781
|
+
validateResponses: true,
|
|
3782
|
+
enableRequestId: false
|
|
3783
|
+
};
|
|
3784
|
+
/**
|
|
3785
|
+
* Abstract base class for HTTP handler adapter services.
|
|
3786
|
+
*
|
|
3787
|
+
* Provides shared logic for:
|
|
3788
|
+
* - Controller resolution (singleton vs request-scoped)
|
|
3789
|
+
* - Argument formatting (sync/async detection)
|
|
3790
|
+
* - Handler generation with static/dynamic branching
|
|
3791
|
+
* - Standardized error handling
|
|
3792
|
+
*
|
|
3793
|
+
* Adapters implement abstract methods for framework-specific behavior:
|
|
3794
|
+
* - Request parsing (query, body, URL params)
|
|
3795
|
+
* - Response creation
|
|
3796
|
+
* - Schema provision
|
|
3797
|
+
*
|
|
3798
|
+
* Supports all adapter types:
|
|
3799
|
+
* - Endpoint adapters: JSON request/response with validation
|
|
3800
|
+
* - Stream adapters: Streaming responses with extra context
|
|
3801
|
+
* - Multipart adapters: Form data parsing (extends endpoint)
|
|
3802
|
+
*
|
|
3803
|
+
* @typeParam TRequest - Framework request type (BunRequest, FastifyRequest)
|
|
3804
|
+
* @typeParam TReply - Framework reply type (void for Bun, FastifyReply)
|
|
3805
|
+
* @typeParam TConfig - Endpoint configuration type
|
|
3806
|
+
*/ var AbstractHandlerAdapterService = class {
|
|
3807
|
+
instanceResolver = inject(_InstanceResolverService);
|
|
3808
|
+
options = optional(NaviosOptionsToken) ?? defaultOptions;
|
|
3809
|
+
/**
|
|
3810
|
+
* Prepares argument getters for parsing request data.
|
|
3811
|
+
*
|
|
3812
|
+
* Public alias for createArgumentGetters to satisfy interface contracts.
|
|
3813
|
+
* Subclasses should override createArgumentGetters instead.
|
|
3814
|
+
*
|
|
3815
|
+
* @param handlerMetadata - Handler metadata with schemas and configuration
|
|
3816
|
+
* @returns Array of getter functions
|
|
3817
|
+
*/ prepareArguments(handlerMetadata) {
|
|
3818
|
+
return this.createArgumentGetters(handlerMetadata);
|
|
3819
|
+
}
|
|
3820
|
+
/**
|
|
3821
|
+
* Checks if the handler has any validation schemas defined.
|
|
3822
|
+
*
|
|
3823
|
+
* Override in subclasses to add additional schema checks
|
|
3824
|
+
* (e.g., response schema validation for endpoint adapters).
|
|
3825
|
+
*
|
|
3826
|
+
* @param handlerMetadata - Handler metadata with configuration
|
|
3827
|
+
* @returns true if handler has schemas
|
|
3828
|
+
*/ hasSchema(handlerMetadata) {
|
|
3829
|
+
const config = handlerMetadata.config;
|
|
3830
|
+
return !!config.requestSchema || !!config.querySchema;
|
|
3831
|
+
}
|
|
3832
|
+
/**
|
|
3833
|
+
* Provides schema information for the framework's validation system.
|
|
3834
|
+
*
|
|
3835
|
+
* Override in subclasses for frameworks that support schema registration
|
|
3836
|
+
* (e.g., Fastify). Default returns empty object (suitable for Bun).
|
|
3837
|
+
*
|
|
3838
|
+
* @param handlerMetadata - Handler metadata with configuration
|
|
3839
|
+
* @returns Schema object for framework registration
|
|
3840
|
+
*/ provideSchema(_handlerMetadata) {
|
|
3841
|
+
return {};
|
|
3842
|
+
}
|
|
3843
|
+
/**
|
|
3844
|
+
* Creates a request handler function for the endpoint.
|
|
3845
|
+
*
|
|
3846
|
+
* This method orchestrates the entire handler creation:
|
|
3847
|
+
* 1. Prepares argument getters for request parsing
|
|
3848
|
+
* 2. Builds optimized formatArguments function (sync/async)
|
|
3849
|
+
* 3. Resolves the controller (singleton vs request-scoped)
|
|
3850
|
+
* 4. Creates appropriate handler (static or dynamic)
|
|
3851
|
+
*
|
|
3852
|
+
* @param controller - Controller class containing the handler method
|
|
3853
|
+
* @param handlerMetadata - Handler metadata with configuration
|
|
3854
|
+
* @returns Handler result (static or dynamic)
|
|
3855
|
+
*/ async provideHandler(controller, handlerMetadata) {
|
|
3856
|
+
const getters = this.createArgumentGetters(handlerMetadata);
|
|
3857
|
+
const formatArguments = this.buildFormatArguments(getters);
|
|
3858
|
+
const hasArguments = getters.length > 0;
|
|
3859
|
+
const context = {
|
|
3860
|
+
methodName: handlerMetadata.classMethod,
|
|
3861
|
+
statusCode: handlerMetadata.successStatusCode,
|
|
3862
|
+
headers: handlerMetadata.headers,
|
|
3863
|
+
handlerMetadata,
|
|
3864
|
+
hasArguments
|
|
3865
|
+
};
|
|
3866
|
+
const resolution = await this.instanceResolver.resolve(controller);
|
|
3867
|
+
if (resolution.cached) {
|
|
3868
|
+
const cachedController = resolution.instance;
|
|
3869
|
+
const boundMethod = cachedController[context.methodName].bind(cachedController);
|
|
3870
|
+
return this.createStaticHandler(boundMethod, formatArguments, context);
|
|
3871
|
+
}
|
|
3872
|
+
return this.createDynamicHandler(resolution, formatArguments, context);
|
|
3873
|
+
}
|
|
3874
|
+
/**
|
|
3875
|
+
* Builds a formatArguments function from argument getters.
|
|
3876
|
+
*
|
|
3877
|
+
* Automatically detects sync vs async getters and optimizes accordingly:
|
|
3878
|
+
* - If all getters are sync: returns sync function (no Promise overhead)
|
|
3879
|
+
* - If any getter is async: returns async function with Promise.all
|
|
3880
|
+
* - If no getters: returns frozen empty object (zero allocation)
|
|
3881
|
+
*
|
|
3882
|
+
* This method is public to allow composition-based adapters (like XML adapter)
|
|
3883
|
+
* to reuse the optimized formatArguments logic without inheritance.
|
|
3884
|
+
*
|
|
3885
|
+
* @param getters - Array of argument getter functions
|
|
3886
|
+
* @returns Function to format arguments from request
|
|
3887
|
+
*/ buildFormatArguments(getters) {
|
|
3888
|
+
if (getters.length === 0) {
|
|
3889
|
+
const emptyArgs = Object.freeze({});
|
|
3890
|
+
return () => emptyArgs;
|
|
3891
|
+
}
|
|
3892
|
+
if (getters.some((g) => g.constructor.name === "AsyncFunction")) return async (request) => {
|
|
3893
|
+
const argument = {};
|
|
3894
|
+
const promises = [];
|
|
3895
|
+
for (const getter of getters) {
|
|
3896
|
+
const res = getter(argument, request);
|
|
3897
|
+
if (res instanceof Promise) promises.push(res);
|
|
3898
|
+
}
|
|
3899
|
+
await Promise.all(promises);
|
|
3900
|
+
return argument;
|
|
3901
|
+
};
|
|
3902
|
+
return (request) => {
|
|
3903
|
+
const argument = {};
|
|
3904
|
+
for (const getter of getters) getter(argument, request);
|
|
3905
|
+
return argument;
|
|
3906
|
+
};
|
|
3907
|
+
}
|
|
3908
|
+
/**
|
|
3909
|
+
* Checks if the URL pattern contains URL parameters.
|
|
3910
|
+
*
|
|
3911
|
+
* @param config - Endpoint configuration
|
|
3912
|
+
* @returns true if URL contains '$' parameter markers
|
|
3913
|
+
*/ hasUrlParams(config) {
|
|
3914
|
+
return config.url.includes("$");
|
|
3915
|
+
}
|
|
3916
|
+
/**
|
|
3917
|
+
* Wraps handler execution with standardized error handling.
|
|
3918
|
+
*
|
|
3919
|
+
* Re-throws HttpExceptions as-is for framework error handlers.
|
|
3920
|
+
* Other errors are re-thrown for global error handling.
|
|
3921
|
+
*
|
|
3922
|
+
* @param fn - Handler function to wrap
|
|
3923
|
+
* @returns Wrapped function with error handling
|
|
3924
|
+
*/ wrapWithErrorHandling(fn) {
|
|
3925
|
+
return async (...args) => {
|
|
3926
|
+
try {
|
|
3927
|
+
return await fn(...args);
|
|
3928
|
+
} catch (error) {
|
|
3929
|
+
if (error && typeof error === "object" && "statusCode" in error) throw error;
|
|
3930
|
+
throw error;
|
|
3931
|
+
}
|
|
3932
|
+
};
|
|
3933
|
+
}
|
|
3934
|
+
};
|
|
3935
|
+
|
|
3777
3936
|
//#endregion
|
|
3778
3937
|
//#region src/services/guard-runner.service.mts
|
|
3779
3938
|
function applyDecs2203RFactory$10() {
|
|
@@ -7583,5 +7742,5 @@ var NaviosApplication = class {
|
|
|
7583
7742
|
};
|
|
7584
7743
|
|
|
7585
7744
|
//#endregion
|
|
7586
|
-
export {
|
|
7587
|
-
//# sourceMappingURL=src-
|
|
7745
|
+
export { isNumber as $, ForbiddenException as A, _ConsoleLogger as B, NotFoundResponderToken as C, UnauthorizedException as D, ConflictException as E, provideConfig as F, getRequestId as G, LoggerOutput as H, ConfigServiceOptionsSchema as I, addLeadingSlash as J, runWithRequestId as K, ConfigServiceToken as L, HttpException as M, ConfigProviderOptions as N, NotFoundException as O, EnvConfigProvider as P, isNil as Q, _ConfigService as R, InternalServerErrorResponderToken as S, FrameworkError as T, loggerOptionsSchema as U, Logger as V, generateRequestId as W, isEmpty as X, isConstructor as Y, isFunction as Z, _NotFoundResponderService as _, _ReplyFactory as a, normalizePath as at, _ErrorResponseProducerService as b, _HttpAdapterFactory as c, filterLogLevels as ct, _ModuleLoaderService as d, clc as dt, isObject as et, _GuardRunnerService as f, yellow as ft, _ValidationErrorResponderService as g, _InstanceResolverService as h, _StreamAdapterFactory as i, isUndefined as it, BadRequestException as j, InternalServerErrorException as k, _EndpointAdapterFactory as l, isLogLevel as lt, ControllerResolverService as m, envString as mt, _NaviosApplication as n, isString as nt, _RequestFactory as o, stripEndSlash as ot, AbstractHandlerAdapterService as p, envInt as pt, setRequestIdEnabled as q, _XmlStreamAdapterFactory as r, isSymbol as rt, _MultipartAdapterFactory as s, isLogLevelEnabled as st, NaviosFactory as t, isPlainObject as tt, AttributeFactory as u, LOG_LEVELS as ut, _InternalServerErrorResponderService as v, ValidationErrorResponderToken as w, ForbiddenResponderToken as x, _ForbiddenResponderService as y, _LoggerInstance as z };
|
|
7746
|
+
//# sourceMappingURL=src-j1cBuAgy.mjs.map
|