@aeriajs/types 0.0.54 → 0.0.56
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/context.d.ts +5 -4
- package/dist/description.d.ts +1 -0
- package/dist/endpointError.d.ts +15 -0
- package/dist/functions.d.ts +4 -3
- package/dist/http.d.ts +5 -4
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/index.mjs +1 -2
- package/dist/result.d.ts +15 -0
- package/package.json +6 -1
- package/dist/either.d.ts +0 -11
- package/dist/error.d.ts +0 -21
- /package/dist/{error.js → endpointError.js} +0 -0
- /package/dist/{error.mjs → endpointError.mjs} +0 -0
- /package/dist/{either.js → result.js} +0 -0
- /package/dist/{either.mjs → result.mjs} +0 -0
package/dist/context.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ import type { AcceptedRole } from './token.js';
|
|
|
3
3
|
import type { ApiConfig } from './config.js';
|
|
4
4
|
import type { CollectionDocument, CollectionFunctions } from './functions.js';
|
|
5
5
|
import type { Description } from './description.js';
|
|
6
|
-
import type {
|
|
6
|
+
import type { Result } from './result.js';
|
|
7
|
+
import type { EndpointError } from './endpointError.js';
|
|
7
8
|
import type { GenericRequest, GenericResponse, HTTPStatus } from './http.js';
|
|
8
9
|
import type { PackReferences, SchemaWithId } from './schema.js';
|
|
9
10
|
import type { RateLimitingParams, RateLimitingError } from './security.js';
|
|
@@ -39,15 +40,15 @@ export type RouteContext<TAcceptedRole extends AcceptedRole = null> = {
|
|
|
39
40
|
request: GenericRequest;
|
|
40
41
|
response: GenericResponse;
|
|
41
42
|
log: (message: string, details?: any) => Promise<any>;
|
|
42
|
-
error: <const THTTPStatus extends HTTPStatus, const
|
|
43
|
+
error: <const THTTPStatus extends HTTPStatus, const TEndpointError extends EndpointError>(httpStatus: THTTPStatus, error: TEndpointError) => Result.Error<TEndpointError & {
|
|
43
44
|
httpStatus: THTTPStatus;
|
|
44
45
|
}>;
|
|
45
|
-
limitRate: (params: RateLimitingParams) => Promise<EndpointError<
|
|
46
|
+
limitRate: (params: RateLimitingParams) => Promise<Result.Either<EndpointError<RateLimitingError, HTTPStatus.TooManyRequests>, {
|
|
46
47
|
hits: number;
|
|
47
48
|
points: number;
|
|
48
49
|
last_reach: Date;
|
|
49
50
|
last_maximum_reach: Date;
|
|
50
|
-
}
|
|
51
|
+
}>>;
|
|
51
52
|
config: ApiConfig;
|
|
52
53
|
inherited: boolean;
|
|
53
54
|
calledFunction: string;
|
package/dist/description.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export type CollectionAction<TDescription extends Description> = {
|
|
|
18
18
|
clearItem?: boolean;
|
|
19
19
|
params?: Record<string, any>;
|
|
20
20
|
query?: Record<string, any>;
|
|
21
|
+
roles?: readonly string[];
|
|
21
22
|
requires?: readonly PropertiesWithId<TDescription>[];
|
|
22
23
|
};
|
|
23
24
|
export type CollectionActions<TDescription extends Description> = Record<string, null | CollectionAction<TDescription>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HTTPStatus } from './http.js';
|
|
2
|
+
export declare const ERROR_SYMBOL_DESCRIPTION = "#__ERROR_SYMBOL__";
|
|
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> = {
|
|
11
|
+
code: TCode;
|
|
12
|
+
details?: TDetails;
|
|
13
|
+
httpStatus: THTTPStatus;
|
|
14
|
+
message?: TMessage;
|
|
15
|
+
};
|
package/dist/functions.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { FilterOperators, StrictFilter as Filter, StrictUpdateFilter, WithId, OptionalId, ObjectId } from 'mongodb';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Result } from './result.js';
|
|
3
|
+
import type { StrictEndpointError } from './endpointError.js';
|
|
3
4
|
import type { PackReferences } from './schema.js';
|
|
4
5
|
import type { ACError } from './accessControl.js';
|
|
5
6
|
import type { ValidationErrorCode } from './validation.js';
|
|
@@ -68,8 +69,8 @@ export type RemoveFilePayload = UploadAuxProps & {
|
|
|
68
69
|
_id: any;
|
|
69
70
|
};
|
|
70
71
|
};
|
|
71
|
-
export type InsertReturnType<TDocument> =
|
|
72
|
-
export type GetReturnType<TDocument> =
|
|
72
|
+
export type InsertReturnType<TDocument> = Result.Either<StrictEndpointError<ACError.InsecureOperator | ACError.OwnershipError | ACError.ResourceNotFound | ACError.TargetImmutable | ValidationErrorCode, unknown, HTTPStatus.NotFound | HTTPStatus.UnprocessableContent>, TDocument>;
|
|
73
|
+
export type GetReturnType<TDocument> = Result.Either<StrictEndpointError<ACError.ResourceNotFound | ACError.MalformedInput, unknown, HTTPStatus.NotFound | HTTPStatus.BadRequest>, TDocument>;
|
|
73
74
|
export type CollectionFunctions<TDocument extends CollectionDocument<OptionalId<any>>> = {
|
|
74
75
|
count: (payload: CountPayload<TDocument>) => Promise<number>;
|
|
75
76
|
get: (payload: GetPayload<TDocument>) => Promise<GetReturnType<TDocument>>;
|
package/dist/http.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { ServerResponse, IncomingMessage } from 'http';
|
|
3
3
|
import type { MapSchemaUnion } from './schema.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { ExtractError, ExtractResult, Result } from './result.js';
|
|
5
|
+
import type { EndpointError, StrictEndpointError } from './endpointError.js';
|
|
5
6
|
import type { ACError } from './accessControl.js';
|
|
6
7
|
import type { RateLimitingError } from './security.js';
|
|
7
8
|
export declare const REQUEST_METHODS: readonly ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "TRACE", "SEARCH"];
|
|
@@ -28,9 +29,9 @@ export type GenericRequest = {
|
|
|
28
29
|
nodeRequest: IncomingMessage;
|
|
29
30
|
};
|
|
30
31
|
export type GenericResponse = ServerResponse;
|
|
31
|
-
type ExtractCode<TRouteResponse> = TRouteResponse extends EndpointError<
|
|
32
|
-
type ExtractHTTPStatus<TRouteResponse> = TRouteResponse extends EndpointError<
|
|
33
|
-
export type WithACErrors<TRouteResponse> =
|
|
32
|
+
type ExtractCode<TRouteResponse> = TRouteResponse extends Result.Error<EndpointError<infer PCode>> ? PCode : never;
|
|
33
|
+
type ExtractHTTPStatus<TRouteResponse> = TRouteResponse extends Result.Error<EndpointError<any, unknown, infer PHTTPStatus>> ? PHTTPStatus : never;
|
|
34
|
+
export type WithACErrors<TRouteResponse> = Result.Either<ExtractError<TRouteResponse> | StrictEndpointError<ExtractCode<TRouteResponse> | ACError.AuthenticationError | ACError.AuthorizationError | RateLimitingError.LimitReached | RateLimitingError.Unauthenticated, unknown, ExtractHTTPStatus<TRouteResponse> | HTTPStatus.Unauthorized | HTTPStatus.TooManyRequests>, ExtractResult<TRouteResponse>>;
|
|
34
35
|
export type EndpointFunction<TRouteMethod extends RequestMethod, TRouteResponse, TRoutePayload> = (TRoutePayload extends null ? (payload?: any) => Promise<WithACErrors<TRouteResponse>> : TRoutePayload extends undefined ? () => Promise<WithACErrors<TRouteResponse>> : (payload: TRoutePayload) => Promise<WithACErrors<TRouteResponse>>) extends infer Function ? Record<TRouteMethod, Function> : never;
|
|
35
36
|
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>>;
|
|
36
37
|
type UnwrapResponse<TResponse> = TResponse extends readonly any[] ? TResponse : TResponse[];
|
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,7 @@ export * from './config.js';
|
|
|
5
5
|
export * from './context.js';
|
|
6
6
|
export * from './contract.js';
|
|
7
7
|
export * from './description.js';
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './error.js';
|
|
8
|
+
export * from './endpointError.js';
|
|
10
9
|
export * from './functions.js';
|
|
11
10
|
export * from './http.js';
|
|
12
11
|
export * from './property.js';
|
package/dist/index.js
CHANGED
|
@@ -21,8 +21,7 @@ __exportStar(require("./config.js"), exports);
|
|
|
21
21
|
__exportStar(require("./context.js"), exports);
|
|
22
22
|
__exportStar(require("./contract.js"), exports);
|
|
23
23
|
__exportStar(require("./description.js"), exports);
|
|
24
|
-
__exportStar(require("./
|
|
25
|
-
__exportStar(require("./error.js"), exports);
|
|
24
|
+
__exportStar(require("./endpointError.js"), exports);
|
|
26
25
|
__exportStar(require("./functions.js"), exports);
|
|
27
26
|
__exportStar(require("./http.js"), exports);
|
|
28
27
|
__exportStar(require("./property.js"), exports);
|
package/dist/index.mjs
CHANGED
|
@@ -6,8 +6,7 @@ export * from "./config.mjs";
|
|
|
6
6
|
export * from "./context.mjs";
|
|
7
7
|
export * from "./contract.mjs";
|
|
8
8
|
export * from "./description.mjs";
|
|
9
|
-
export * from "./
|
|
10
|
-
export * from "./error.mjs";
|
|
9
|
+
export * from "./endpointError.mjs";
|
|
11
10
|
export * from "./functions.mjs";
|
|
12
11
|
export * from "./http.mjs";
|
|
13
12
|
export * from "./property.mjs";
|
package/dist/result.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare namespace Result {
|
|
2
|
+
type Error<T> = {
|
|
3
|
+
readonly _tag: 'Error';
|
|
4
|
+
readonly error: T;
|
|
5
|
+
readonly result: undefined;
|
|
6
|
+
};
|
|
7
|
+
type Result<T> = {
|
|
8
|
+
readonly _tag: 'Result';
|
|
9
|
+
readonly error: undefined;
|
|
10
|
+
readonly result: T;
|
|
11
|
+
};
|
|
12
|
+
type Either<E, R> = Result.Error<E> | Result.Result<R>;
|
|
13
|
+
}
|
|
14
|
+
export type ExtractError<T> = T extends Result.Error<infer L> ? L : never;
|
|
15
|
+
export type ExtractResult<T> = T extends Result.Result<infer R> ? R : never;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/types",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.56",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -13,6 +13,11 @@
|
|
|
13
13
|
"import": "./dist/index.mjs",
|
|
14
14
|
"require": "./dist/index.js",
|
|
15
15
|
"types": "./dist/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./result": {
|
|
18
|
+
"import": "./dist/result.mjs",
|
|
19
|
+
"require": "./dist/result.js",
|
|
20
|
+
"types": "./dist/result.d.ts"
|
|
16
21
|
}
|
|
17
22
|
},
|
|
18
23
|
"keywords": [],
|
package/dist/either.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type Left<T> = {
|
|
2
|
-
readonly _tag: 'Left';
|
|
3
|
-
readonly value: T;
|
|
4
|
-
};
|
|
5
|
-
export type Right<T> = {
|
|
6
|
-
readonly _tag: 'Right';
|
|
7
|
-
readonly value: T;
|
|
8
|
-
};
|
|
9
|
-
export type ExtractLeft<T> = T extends Left<infer L> ? L : never;
|
|
10
|
-
export type ExtractRight<T> = T extends Right<infer R> ? R : never;
|
|
11
|
-
export type Either<L, R> = Left<L> | Right<R>;
|
package/dist/error.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { HTTPStatus } from './http.js';
|
|
2
|
-
export declare const ERROR_SYMBOL_DESCRIPTION = "#__ERROR_SYMBOL__";
|
|
3
|
-
export declare const ERROR_SYMBOL: unique symbol;
|
|
4
|
-
export type EndpointErrorContent<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 StrictEndpointErrorContent<TCode extends string = string, TDetails = unknown, THTTPStatus extends HTTPStatus | undefined = HTTPStatus, TMessage extends string | undefined = string> = {
|
|
11
|
-
code: TCode;
|
|
12
|
-
details?: TDetails;
|
|
13
|
-
httpStatus: THTTPStatus;
|
|
14
|
-
message?: TMessage;
|
|
15
|
-
};
|
|
16
|
-
export type EndpointError<TEndpointErrorContent extends EndpointErrorContent | unknown = EndpointErrorContent> = {
|
|
17
|
-
readonly _tag: 'Error';
|
|
18
|
-
readonly value: TEndpointErrorContent;
|
|
19
|
-
};
|
|
20
|
-
export type ExtractError<T> = T extends EndpointError ? T : never;
|
|
21
|
-
export type ExtractSuccessful<T> = T extends EndpointError ? never : T;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|