@aeriajs/types 0.0.89 → 0.0.91
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/config.d.ts +1 -0
- package/dist/context.d.ts +1 -1
- package/dist/endpointError.d.ts +1 -7
- package/dist/functions.d.ts +6 -6
- package/dist/http.d.ts +2 -2
- package/dist/schema.d.ts +5 -2
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
package/dist/context.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export type RouteContext<TAcceptedRole extends AcceptedRole = null> = {
|
|
|
43
43
|
request: GenericRequest;
|
|
44
44
|
response: GenericResponse;
|
|
45
45
|
log: (message: string, details?: unknown) => Promise<unknown>;
|
|
46
|
-
error: <const THTTPStatus extends HTTPStatus, const TEndpointError extends EndpointError
|
|
46
|
+
error: <const THTTPStatus extends HTTPStatus, const TEndpointError extends Omit<EndpointError, 'httpStatus'>>(httpStatus: THTTPStatus, error: TEndpointError) => Result.Error<TEndpointError & {
|
|
47
47
|
httpStatus: THTTPStatus;
|
|
48
48
|
}>;
|
|
49
49
|
limitRate: (params: RateLimitingParams) => Promise<Result.Either<EndpointError<RateLimitingError, HTTPStatus.TooManyRequests>, {
|
package/dist/endpointError.d.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import type { HTTPStatus } from './http.js';
|
|
2
2
|
export declare const ERROR_SYMBOL_DESCRIPTION = "#__ERROR_SYMBOL__";
|
|
3
3
|
export declare const ERROR_SYMBOL: unique symbol;
|
|
4
|
-
export type EndpointError<TCode extends string = string, TDetails = unknown, THTTPStatus extends HTTPStatus = HTTPStatus, TMessage extends string = string> = {
|
|
5
|
-
code: TCode;
|
|
6
|
-
details?: TDetails;
|
|
7
|
-
httpStatus?: THTTPStatus;
|
|
8
|
-
message?: TMessage;
|
|
9
|
-
};
|
|
10
|
-
export type StrictEndpointError<TCode extends string = string, TDetails = unknown, THTTPStatus extends HTTPStatus | undefined = HTTPStatus, TMessage extends string | undefined = string> = {
|
|
4
|
+
export type EndpointError<TCode extends string = string, TDetails = unknown, THTTPStatus extends HTTPStatus | undefined = HTTPStatus, TMessage extends string | undefined = string> = {
|
|
11
5
|
code: TCode;
|
|
12
6
|
details?: TDetails;
|
|
13
7
|
httpStatus: THTTPStatus;
|
package/dist/functions.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FilterOperators, StrictFilter as Filter, WithId, ObjectId } from 'mongodb';
|
|
2
|
-
import type { Result } from './result.js';
|
|
3
|
-
import type { EndpointError
|
|
2
|
+
import type { Result, ExtractError } from './result.js';
|
|
3
|
+
import type { EndpointError } from './endpointError.js';
|
|
4
4
|
import type { PackReferences } from './schema.js';
|
|
5
5
|
import type { ACError } from './accessControl.js';
|
|
6
6
|
import type { ValidationErrorCode, TraverseError } from './validation.js';
|
|
@@ -69,12 +69,12 @@ export type RemoveFilePayload = UploadAuxProps & {
|
|
|
69
69
|
_id: ObjectId | string;
|
|
70
70
|
};
|
|
71
71
|
};
|
|
72
|
-
export type InsertReturnType<TDocument> = Result.Either<
|
|
73
|
-
export type GetReturnType<TDocument> = Result.Either<
|
|
72
|
+
export type InsertReturnType<TDocument> = Result.Either<EndpointError<ACError.InsecureOperator | ACError.OwnershipError | ACError.ResourceNotFound | ACError.TargetImmutable | ACError.MalformedInput | ValidationErrorCode | TraverseError.InvalidDocumentId | TraverseError.InvalidTempfile, unknown, HTTPStatus.Forbidden | HTTPStatus.NotFound | HTTPStatus.UnprocessableContent | HTTPStatus.BadRequest>, TDocument>;
|
|
73
|
+
export type GetReturnType<TDocument> = Result.Either<EndpointError<ACError.ResourceNotFound | ACError.OwnershipError | ACError.MalformedInput, unknown, HTTPStatus.Forbidden | HTTPStatus.NotFound | HTTPStatus.BadRequest>, TDocument>;
|
|
74
|
+
export type GetAllReturnType<TDocument> = Result.Either<EndpointError<ACError.InvalidLimit | ACError.OwnershipError, unknown, HTTPStatus.Forbidden>, TDocument[]>;
|
|
74
75
|
export type CountReturnType = Result.Either<EndpointError, number>;
|
|
75
|
-
export type GetAllReturnType<TDocument> = Result.Either<EndpointError, TDocument[]>;
|
|
76
76
|
export type RemoveReturnType<TDocument> = Result.Either<EndpointError, TDocument>;
|
|
77
|
-
export type PaginatedGetAllReturnType<TDocument> = Result.Either<
|
|
77
|
+
export type PaginatedGetAllReturnType<TDocument> = Result.Either<ExtractError<GetAllReturnType<TDocument>>, {
|
|
78
78
|
data: TDocument[];
|
|
79
79
|
pagination: Pagination;
|
|
80
80
|
}>;
|
package/dist/http.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ServerResponse, IncomingMessage } from 'http';
|
|
2
2
|
import type { Result, ExtractError, ExtractResult } from './result.js';
|
|
3
|
-
import type { EndpointError
|
|
3
|
+
import type { EndpointError } from './endpointError.js';
|
|
4
4
|
import type { ACError } from './accessControl.js';
|
|
5
5
|
import type { RateLimitingError } from './security.js';
|
|
6
6
|
export declare const REQUEST_METHODS: readonly ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "TRACE", "SEARCH"];
|
|
@@ -32,7 +32,7 @@ type ExtractCode<TRouteResponse> = TRouteResponse extends EndpointError<infer PC
|
|
|
32
32
|
type ExtractHTTPStatus<TRouteResponse> = TRouteResponse extends EndpointError<string, unknown, infer PHTTPStatus> ? PHTTPStatus : never;
|
|
33
33
|
export type NativeError = ACError.AuthenticationError | ACError.AuthorizationError | RateLimitingError.LimitReached | RateLimitingError.Unauthenticated;
|
|
34
34
|
export type NativeHTTPErrorStatus = HTTPStatus.Unauthorized | HTTPStatus.TooManyRequests;
|
|
35
|
-
export type WithACErrors<TRouteResponse> = TRouteResponse extends Result.Either<infer InferredError, unknown> ? Result.Either<ExtractError<TRouteResponse> |
|
|
35
|
+
export type WithACErrors<TRouteResponse> = TRouteResponse extends Result.Either<infer InferredError, unknown> ? Result.Either<ExtractError<TRouteResponse> | EndpointError<ExtractCode<InferredError> | NativeError, unknown, ExtractHTTPStatus<InferredError> | NativeHTTPErrorStatus>, ExtractResult<TRouteResponse>> : TRouteResponse | Result.Error<EndpointError<NativeError, unknown, NativeHTTPErrorStatus>>;
|
|
36
36
|
export type EndpointFunction<TRouteMethod extends RequestMethod, TRouteResponse, TRoutePayload> = (TRoutePayload extends null ? <T = TRouteResponse>(payload?: unknown) => 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;
|
|
37
37
|
export type MakeEndpoint<TRoute extends string, TRouteMethod extends RequestMethod, TRouteResponse = unknown, 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>>;
|
|
38
38
|
export {};
|
package/dist/schema.d.ts
CHANGED
|
@@ -40,11 +40,14 @@ export type InferProperty<T> = T extends TestType<{
|
|
|
40
40
|
}> ? Awaited<K> : T extends TestType<{
|
|
41
41
|
const: infer K;
|
|
42
42
|
}> ? K : never;
|
|
43
|
+
type ExtractRequiredPropNames<T> = T extends readonly (infer PropName)[] ? PropName : Record<never, never> extends T ? null : keyof {
|
|
44
|
+
[K in keyof T as T[K] extends true ? K : never]: never;
|
|
45
|
+
};
|
|
43
46
|
export type InferSchema<TSchema> = MergeReferences<TSchema> extends infer MappedTypes ? TSchema extends {
|
|
44
|
-
|
|
47
|
+
required: readonly [];
|
|
45
48
|
} ? Partial<MappedTypes> : TSchema extends {
|
|
46
49
|
required: infer InferredRequired;
|
|
47
|
-
} ? InferredRequired extends
|
|
50
|
+
} ? ExtractRequiredPropNames<InferredRequired> extends infer RequiredPropName ? Pick<MappedTypes, Extract<keyof MappedTypes, RequiredPropName>> extends infer RequiredProps ? RequiredProps & Partial<Exclude<MappedTypes, keyof RequiredProps>> : never : Partial<MappedTypes> : MappedTypes : never;
|
|
48
51
|
export type Schema<TSchema> = CaseTimestamped<TSchema, CaseOwned<TSchema, InferSchema<TSchema>>>;
|
|
49
52
|
export type SchemaWithId<TSchema> = Schema<TSchema> & {
|
|
50
53
|
_id: ObjectId;
|