@aeriajs/types 0.0.68 → 0.0.69
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/description.d.ts +1 -1
- package/dist/http.d.ts +7 -5
- package/package.json +1 -1
package/dist/description.d.ts
CHANGED
|
@@ -81,7 +81,7 @@ export type Description<TDescription extends Description = any> = JsonSchema<TDe
|
|
|
81
81
|
preferred?: Record<string, RuntimeDescription<TDescription>>;
|
|
82
82
|
icon?: Icon;
|
|
83
83
|
options?: CollectionOptions<TDescription>;
|
|
84
|
-
indexes?: readonly
|
|
84
|
+
indexes?: readonly PropertiesWithId<TDescription>[];
|
|
85
85
|
defaults?: Record<string, any>;
|
|
86
86
|
owned?: OwnershipMode;
|
|
87
87
|
temporary?: {
|
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 {
|
|
3
|
+
import type { Result } 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';
|
|
@@ -29,10 +29,12 @@ export declare const STREAMED_RESPONSE: unique symbol;
|
|
|
29
29
|
export type GenericResponse = ServerResponse & {
|
|
30
30
|
[STREAMED_RESPONSE]?: boolean;
|
|
31
31
|
};
|
|
32
|
-
type ExtractCode<TRouteResponse> = TRouteResponse extends
|
|
33
|
-
type ExtractHTTPStatus<TRouteResponse> = TRouteResponse extends
|
|
34
|
-
export type
|
|
35
|
-
export type
|
|
32
|
+
type ExtractCode<TRouteResponse> = TRouteResponse extends EndpointError<infer PCode> ? PCode : never;
|
|
33
|
+
type ExtractHTTPStatus<TRouteResponse> = TRouteResponse extends EndpointError<any, unknown, infer PHTTPStatus> ? PHTTPStatus : never;
|
|
34
|
+
export type NativeError = ACError.AuthenticationError | ACError.AuthorizationError | RateLimitingError.LimitReached | RateLimitingError.Unauthenticated;
|
|
35
|
+
export type NativeHTTPErrorStatus = HTTPStatus.Unauthorized | HTTPStatus.TooManyRequests;
|
|
36
|
+
export type WithACErrors<TRouteResponse> = TRouteResponse extends Result.Either<infer InferredError, infer InferredResult> ? Result.Either<InferredError | StrictEndpointError<ExtractCode<InferredError> | NativeError, unknown, ExtractHTTPStatus<InferredError> | NativeHTTPErrorStatus>, InferredResult> : TRouteResponse | Result.Error<StrictEndpointError<NativeError, unknown, NativeHTTPErrorStatus>>;
|
|
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;
|
|
36
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>>;
|
|
37
39
|
type UnwrapResponse<TResponse> = TResponse extends readonly any[] ? TResponse : TResponse[];
|
|
38
40
|
export type InferResponse<TResponse> = MapSchemaUnion<UnwrapResponse<TResponse>> extends infer InferredResponse ? InferredResponse | Promise<InferredResponse> : never;
|