@aeriajs/types 0.0.26 → 0.0.28
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/api.d.ts +4 -2
- package/dist/config.d.ts +7 -3
- package/dist/context.d.ts +19 -11
- package/dist/contract.d.ts +7 -4
- package/dist/http.d.ts +1 -0
- package/dist/schema.d.ts +4 -0
- package/dist/security.d.ts +5 -0
- package/dist/security.js +6 -0
- package/dist/security.mjs +5 -0
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -14,13 +14,15 @@ export type UserACProfile = {
|
|
|
14
14
|
readonly roles: string[];
|
|
15
15
|
readonly allowed_functions?: string[];
|
|
16
16
|
};
|
|
17
|
-
export type
|
|
17
|
+
export type AuthenticatedToken = {
|
|
18
18
|
authenticated: true;
|
|
19
19
|
sub: ObjectId;
|
|
20
20
|
roles: string[];
|
|
21
21
|
userinfo: PackReferences<Collections['user']['item']>;
|
|
22
22
|
allowed_functions?: FunctionPath[];
|
|
23
|
-
}
|
|
23
|
+
};
|
|
24
|
+
export type UnauthenticatedToken = {
|
|
24
25
|
authenticated: false;
|
|
25
26
|
sub: null;
|
|
26
27
|
};
|
|
28
|
+
export type DecodedToken = AuthenticatedToken | UnauthenticatedToken;
|
package/dist/config.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RouteContext, RouteUri, RateLimitingParams } from '.';
|
|
2
2
|
export type ApiConfig = {
|
|
3
3
|
secret?: string;
|
|
4
4
|
apiUrl?: string;
|
|
5
|
+
apiBase?: RouteUri;
|
|
5
6
|
port?: number;
|
|
6
7
|
paginationLimit?: number;
|
|
7
8
|
database?: {
|
|
@@ -22,7 +23,10 @@ export type ApiConfig = {
|
|
|
22
23
|
roles: string[];
|
|
23
24
|
active: boolean;
|
|
24
25
|
}>;
|
|
25
|
-
|
|
26
|
+
security?: {
|
|
27
|
+
logSuccessfulAuthentications?: boolean;
|
|
28
|
+
authenticationRateLimiting?: RateLimitingParams | null;
|
|
29
|
+
};
|
|
26
30
|
tokenUserProperties?: string[];
|
|
27
|
-
errorHandler?: <TError extends Error>(context:
|
|
31
|
+
errorHandler?: <TError extends Error>(context: RouteContext, error: TError) => any | Promise<any>;
|
|
28
32
|
};
|
package/dist/context.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Collection as MongoCollection } from 'mongodb';
|
|
2
2
|
import type { GenericRequest, GenericResponse } from './http';
|
|
3
|
-
import type { Description, PackReferences, SchemaWithId, FunctionPath, DecodedToken, ApiConfig, CollectionDocument, CollectionFunctions } from '.';
|
|
3
|
+
import type { Either, Description, PackReferences, SchemaWithId, FunctionPath, DecodedToken, ApiConfig, CollectionDocument, CollectionFunctions, RateLimitingParams, RateLimitingErrors } from '.';
|
|
4
4
|
export type CollectionModel<TDescription extends Description> = MongoCollection<Omit<PackReferences<SchemaWithId<TDescription>>, '_id'>>;
|
|
5
|
-
type OmitContextParameter<TFunction> = TFunction extends () => any ? TFunction : TFunction extends (payload: infer Payload, context: Context, ...args: infer Rest) => infer Return ? (payload: Payload, ...args: Rest) => Return : never;
|
|
5
|
+
type OmitContextParameter<TFunction> = TFunction extends () => any ? TFunction : TFunction extends (payload: undefined, ...args: any[]) => infer Return ? () => Return : TFunction extends (payload: infer Payload, context: Context, ...args: infer Rest) => infer Return ? (payload: Payload, ...args: Rest) => Return : never;
|
|
6
6
|
type RestParameters<TFunction> = TFunction extends (payload: any, context: Context, ...args: infer Rest) => any ? Rest : never;
|
|
7
7
|
type UnionFunctions<TFunctions, TSchema extends CollectionDocument<any>> = {
|
|
8
8
|
[P in keyof TFunctions]: (P extends keyof CollectionFunctions<any> ? CollectionFunctions<TSchema>[P] extends infer CollFunction ? CollFunction extends (...args: any[]) => any ? Extract<undefined, Parameters<CollFunction>[0]> extends never ? (payload: Parameters<CollFunction>[0], ...args: RestParameters<TFunctions[P]>) => ReturnType<CollFunction> : (payload?: Parameters<CollFunction>[0], ...args: RestParameters<TFunctions[P]>) => ReturnType<CollFunction> : never : never : OmitContextParameter<TFunctions[P]>) extends (...args: infer Args) => infer Return ? Return extends Promise<any> ? (...args: Args) => Return : (...args: Args) => Promise<Return> : never;
|
|
@@ -18,29 +18,37 @@ export type IndepthCollection<TCollection> = TCollection extends {
|
|
|
18
18
|
export type IndepthCollections = {
|
|
19
19
|
[P in keyof Collections]: IndepthCollection<Collections[P]>;
|
|
20
20
|
};
|
|
21
|
-
export type ContextOptions
|
|
21
|
+
export type ContextOptions = {
|
|
22
22
|
config?: ApiConfig;
|
|
23
|
-
parentContext?:
|
|
23
|
+
parentContext?: RouteContext | Context;
|
|
24
24
|
collectionName?: string;
|
|
25
25
|
token?: DecodedToken;
|
|
26
26
|
inherited?: boolean;
|
|
27
27
|
calledFunction?: string;
|
|
28
28
|
};
|
|
29
|
-
export type
|
|
30
|
-
description: TDescription;
|
|
31
|
-
collection: TDescription['$id'] extends keyof Collections ? IndepthCollection<{
|
|
32
|
-
description: TDescription;
|
|
33
|
-
functions: TFunctions;
|
|
34
|
-
}> : TDescription;
|
|
29
|
+
export type RouteContext = {
|
|
35
30
|
collections: IndepthCollections;
|
|
36
31
|
functionPath: FunctionPath;
|
|
37
32
|
token: DecodedToken;
|
|
38
|
-
collectionName?: (keyof Collections & string) | string;
|
|
39
33
|
request: GenericRequest;
|
|
40
34
|
response: GenericResponse;
|
|
41
35
|
log: (message: string, details?: any) => Promise<any>;
|
|
36
|
+
limitRate: (params: RateLimitingParams) => Promise<Either<RateLimitingErrors, {
|
|
37
|
+
hits: number;
|
|
38
|
+
points: number;
|
|
39
|
+
last_reach: Date;
|
|
40
|
+
last_maximum_reach: Date;
|
|
41
|
+
}>>;
|
|
42
42
|
config: ApiConfig;
|
|
43
43
|
inherited: boolean;
|
|
44
44
|
calledFunction: string;
|
|
45
45
|
};
|
|
46
|
+
export type Context<TDescription extends Description = any, TFunctions = any> = RouteContext & {
|
|
47
|
+
description: TDescription;
|
|
48
|
+
collectionName?: (keyof Collections & string) | string;
|
|
49
|
+
collection: TDescription['$id'] extends keyof Collections ? IndepthCollection<{
|
|
50
|
+
description: TDescription;
|
|
51
|
+
functions: TFunctions;
|
|
52
|
+
}> : TDescription;
|
|
53
|
+
};
|
|
46
54
|
export {};
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import type { Property, InferProperty, Context } from '.';
|
|
1
|
+
import type { Property, InferProperty, InferResponse, Context } from '.';
|
|
2
|
+
export type ContractBase = {
|
|
3
|
+
builtin?: boolean;
|
|
4
|
+
};
|
|
2
5
|
export type ContractRoles = {
|
|
3
6
|
roles?: (Collections['user']['item']['roles'][number] | 'root' | 'guest')[];
|
|
4
7
|
};
|
|
5
|
-
export type Contract = {
|
|
8
|
+
export type Contract = ContractBase & ({
|
|
6
9
|
response: Property | Property[];
|
|
7
10
|
} | {
|
|
8
11
|
payload: Property;
|
|
@@ -12,7 +15,7 @@ export type Contract = {
|
|
|
12
15
|
response?: Property | Property[];
|
|
13
16
|
payload?: Property;
|
|
14
17
|
query?: Property;
|
|
15
|
-
};
|
|
18
|
+
});
|
|
16
19
|
export type ContractWithRoles = ContractRoles & Contract;
|
|
17
|
-
export type ContractToFunction<TContract extends Contract | ContractWithRoles, ContextParameter = Context> = ('payload' extends keyof TContract ? InferProperty<TContract['payload']> : undefined) extends infer Payload ? ('response' extends keyof TContract ?
|
|
20
|
+
export type ContractToFunction<TContract extends Contract | ContractWithRoles, ContextParameter = Context> = ('payload' extends keyof TContract ? InferProperty<TContract['payload']> : undefined) extends infer Payload ? ('response' extends keyof TContract ? InferResponse<TContract['response']> : any) extends infer Response ? Payload extends undefined ? (payload: Payload | undefined, context: ContextParameter) => Response : (payload: Payload, context: ContextParameter) => Response : never : never;
|
|
18
21
|
export declare const defineContract: <const TContractWithRoles extends ContractWithRoles>(contract: TContractWithRoles) => TContractWithRoles;
|
package/dist/http.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { ServerResponse, IncomingMessage } from 'http';
|
|
3
3
|
import type { MapSchemaUnion } from '.';
|
|
4
4
|
export declare const REQUEST_METHODS: readonly ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "TRACE", "SEARCH"];
|
|
5
|
+
export type RouteUri = `/${string}`;
|
|
5
6
|
export type RequestMethod = (typeof REQUEST_METHODS)[number];
|
|
6
7
|
export type GenericRequest = {
|
|
7
8
|
url: string;
|
package/dist/schema.d.ts
CHANGED
|
@@ -28,6 +28,10 @@ export type InferProperty<T> = T extends TestType<{
|
|
|
28
28
|
}> ? Schema<T & {
|
|
29
29
|
timestamps: false;
|
|
30
30
|
}> : T extends TestType<{
|
|
31
|
+
additionalProperties: infer K;
|
|
32
|
+
}> ? {
|
|
33
|
+
[P: string]: InferProperty<K> | undefined;
|
|
34
|
+
} : T extends TestType<{
|
|
31
35
|
type: 'object';
|
|
32
36
|
}> ? any : T extends TestType<{
|
|
33
37
|
items: infer K;
|
package/dist/security.d.ts
CHANGED
package/dist/security.js
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RateLimitingErrors = void 0;
|
|
4
|
+
var RateLimitingErrors;
|
|
5
|
+
(function (RateLimitingErrors) {
|
|
6
|
+
RateLimitingErrors["Unauthenticated"] = "UNAUTHENTICATED";
|
|
7
|
+
RateLimitingErrors["LimitReached"] = "LIMIT_REACHED";
|
|
8
|
+
})(RateLimitingErrors || (exports.RateLimitingErrors = RateLimitingErrors = {}));
|
package/dist/security.mjs
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
export var RateLimitingErrors = /* @__PURE__ */ ((RateLimitingErrors2) => {
|
|
3
|
+
RateLimitingErrors2["Unauthenticated"] = "UNAUTHENTICATED";
|
|
4
|
+
RateLimitingErrors2["LimitReached"] = "LIMIT_REACHED";
|
|
5
|
+
return RateLimitingErrors2;
|
|
6
|
+
})(RateLimitingErrors || {});
|