@aeriajs/types 0.0.69 → 0.0.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/http.d.ts +2 -2
- package/package.json +1 -1
package/dist/http.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ServerResponse, IncomingMessage } from 'http';
|
|
2
2
|
import type { MapSchemaUnion } from './schema.js';
|
|
3
|
-
import type { Result } from './result.js';
|
|
3
|
+
import type { Result, ExtractError, ExtractResult } from './result.js';
|
|
4
4
|
import type { EndpointError, StrictEndpointError } from './endpointError.js';
|
|
5
5
|
import type { ACError } from './accessControl.js';
|
|
6
6
|
import type { RateLimitingError } from './security.js';
|
|
@@ -33,7 +33,7 @@ type ExtractCode<TRouteResponse> = TRouteResponse extends EndpointError<infer PC
|
|
|
33
33
|
type ExtractHTTPStatus<TRouteResponse> = TRouteResponse extends EndpointError<any, unknown, infer PHTTPStatus> ? PHTTPStatus : never;
|
|
34
34
|
export type NativeError = ACError.AuthenticationError | ACError.AuthorizationError | RateLimitingError.LimitReached | RateLimitingError.Unauthenticated;
|
|
35
35
|
export type NativeHTTPErrorStatus = HTTPStatus.Unauthorized | HTTPStatus.TooManyRequests;
|
|
36
|
-
export type WithACErrors<TRouteResponse> = TRouteResponse extends Result.Either<infer InferredError,
|
|
36
|
+
export type WithACErrors<TRouteResponse> = TRouteResponse extends Result.Either<infer InferredError, unknown> ? Result.Either<ExtractError<TRouteResponse> | StrictEndpointError<ExtractCode<InferredError> | NativeError, unknown, ExtractHTTPStatus<InferredError> | NativeHTTPErrorStatus>, ExtractResult<TRouteResponse>> : TRouteResponse | Result.Error<StrictEndpointError<NativeError, unknown, NativeHTTPErrorStatus>>;
|
|
37
37
|
export type EndpointFunction<TRouteMethod extends RequestMethod, TRouteResponse, TRoutePayload> = (TRoutePayload extends null ? <T = TRouteResponse>(payload?: any) => Promise<WithACErrors<T>> : TRoutePayload extends undefined ? <T = TRouteResponse>() => Promise<WithACErrors<T>> : <T = TRouteResponse>(payload: TRoutePayload) => Promise<WithACErrors<T>>) extends infer Function ? Record<TRouteMethod, Function> : never;
|
|
38
38
|
export type MakeEndpoint<TRoute extends string, TRouteMethod extends RequestMethod, TRouteResponse = any, TRoutePayload = null> = TRoute extends `/${infer RouteTail}` ? MakeEndpoint<RouteTail, TRouteMethod, TRouteResponse, TRoutePayload> : TRoute extends `${infer Route}/${infer RouteTail}` ? Record<Route, MakeEndpoint<RouteTail, TRouteMethod, TRouteResponse, TRoutePayload>> : TRoute extends `(${string}` ? Record<string, EndpointFunction<TRouteMethod, TRouteResponse, TRoutePayload>> : Record<TRoute, EndpointFunction<TRouteMethod, TRouteResponse, TRoutePayload>>;
|
|
39
39
|
type UnwrapResponse<TResponse> = TResponse extends readonly any[] ? TResponse : TResponse[];
|