@aeriajs/types 0.0.4 → 0.0.5
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 +2 -1
- package/dist/context.d.ts +5 -1
- package/dist/functions.d.ts +19 -4
- package/dist/http.d.ts +16 -1
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { ObjectId } from 'mongodb';
|
|
2
|
-
import type { Context, Description, SecurityPolicy, AccessControl, PackReferences } from '.';
|
|
2
|
+
import type { Context, Contract, Description, SecurityPolicy, AccessControl, PackReferences } from '.';
|
|
3
3
|
export type Collection<TCollection extends Collection = any> = {
|
|
4
4
|
description: Description;
|
|
5
5
|
item?: any;
|
|
6
6
|
security?: SecurityPolicy;
|
|
7
7
|
accessControl?: AccessControl<TCollection>;
|
|
8
8
|
functions?: Record<string, (payload: any, context: Context, ...args: any[]) => any>;
|
|
9
|
+
functionContracts?: Record<string, Contract>;
|
|
9
10
|
};
|
|
10
11
|
export type AssetType = keyof Collection;
|
|
11
12
|
export type FunctionPath = `${string}@${string}`;
|
package/dist/context.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export type CollectionModel<TDescription extends Description> = MongoCollection<
|
|
|
5
5
|
type OmitContextParameter<TFunction> = 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
|
-
[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]
|
|
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;
|
|
9
9
|
};
|
|
10
10
|
export type IndepthCollection<TCollection> = TCollection extends {
|
|
11
11
|
description: infer InferredDescription;
|
|
@@ -23,6 +23,8 @@ export type ContextOptions<TContext> = {
|
|
|
23
23
|
parentContext?: TContext;
|
|
24
24
|
collectionName?: string;
|
|
25
25
|
token?: DecodedToken;
|
|
26
|
+
inherited?: boolean;
|
|
27
|
+
calledFunction?: string;
|
|
26
28
|
};
|
|
27
29
|
export type Context<TDescription extends Description = any, TFunctions = any> = {
|
|
28
30
|
description: TDescription;
|
|
@@ -38,5 +40,7 @@ export type Context<TDescription extends Description = any, TFunctions = any> =
|
|
|
38
40
|
response: GenericResponse;
|
|
39
41
|
log: (message: string, details?: any) => Promise<any>;
|
|
40
42
|
config: ApiConfig;
|
|
43
|
+
inherited: boolean;
|
|
44
|
+
calledFunction: string;
|
|
41
45
|
};
|
|
42
46
|
export {};
|
package/dist/functions.d.ts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import type { FilterOperators, UpdateFilter, WithId, OptionalId, ObjectId } from 'mongodb';
|
|
2
|
-
import type { PackReferences, Either, ValidationError } from '.';
|
|
2
|
+
import type { PackReferences, Either, ValidationError, ACErrors, Context, Description } from '.';
|
|
3
3
|
export type UploadAuxProps = {
|
|
4
4
|
parentId: string;
|
|
5
5
|
propertyName: string;
|
|
6
6
|
};
|
|
7
|
+
export type Pagination = {
|
|
8
|
+
recordsCount: number;
|
|
9
|
+
recordsTotal: number;
|
|
10
|
+
offset: number;
|
|
11
|
+
limit: number;
|
|
12
|
+
};
|
|
7
13
|
export type Filters<TDocument> = FilterOperators<TDocument>;
|
|
8
14
|
export type What<TDocument> = Omit<UpdateFilter<TDocument>, keyof TDocument> & {
|
|
9
15
|
[P in keyof TDocument]?: '_id' extends keyof TDocument[P] ? TDocument[P] | string : TDocument[P];
|
|
10
16
|
};
|
|
11
|
-
export type Projection<TDocument
|
|
17
|
+
export type Projection<TDocument> = keyof TDocument | '_id' extends infer DocumentProp ? TDocument extends string ? DocumentProp[] : string[] : never;
|
|
12
18
|
export type QuerySort<TDocument> = Partial<Record<keyof WithId<TDocument>, 1 | -1>>;
|
|
13
|
-
export type CollectionDocument<TDocument> =
|
|
19
|
+
export type CollectionDocument<TDocument> = TDocument;
|
|
14
20
|
export type CountPayload<TDocument extends CollectionDocument<OptionalId<any>>> = {
|
|
15
21
|
filters?: Filters<TDocument>;
|
|
16
22
|
};
|
|
@@ -48,8 +54,17 @@ export type CollectionFunctions<TDocument extends CollectionDocument<OptionalId<
|
|
|
48
54
|
count: (payload: CountPayload<TDocument>) => Promise<number>;
|
|
49
55
|
get: (payload: GetPayload<TDocument>) => Promise<TDocument | null>;
|
|
50
56
|
getAll: (payload?: GetAllPayload<TDocument>) => Promise<TDocument[]>;
|
|
51
|
-
insert: (payload: InsertPayload<TDocument>) => Promise<Either<ValidationError, TDocument>>;
|
|
57
|
+
insert: (payload: InsertPayload<TDocument>) => Promise<Either<ValidationError | ACErrors, TDocument>>;
|
|
52
58
|
remove: (payload: RemovePayload<TDocument>) => Promise<TDocument>;
|
|
53
59
|
removeAll: (payload: RemoveAllPayload) => Promise<any>;
|
|
54
60
|
removeFile: (payload: RemoveFilePayload) => Promise<any>;
|
|
55
61
|
};
|
|
62
|
+
export type CollectionFunctionsPaginated<TDocument extends CollectionDocument<OptionalId<any>>> = Omit<CollectionFunctions<TDocument>, 'getAll'> & {
|
|
63
|
+
getAll: (payload?: GetAllPayload<TDocument>) => Promise<{
|
|
64
|
+
data: TDocument[];
|
|
65
|
+
pagination: Pagination;
|
|
66
|
+
}>;
|
|
67
|
+
};
|
|
68
|
+
export type CollectionFunctionsWithContext<TDocument extends CollectionDocument<OptionalId<any>>, TDescription extends Description = any, TFunctions = any> = {
|
|
69
|
+
[P in keyof CollectionFunctions<TDocument>]: (payload: Parameters<CollectionFunctions<TDocument>[P]>[0], context: Context<TDescription, TFunctions>) => ReturnType<CollectionFunctions<TDocument>[P]>;
|
|
70
|
+
};
|
package/dist/http.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { ServerResponse, IncomingMessage } from 'http';
|
|
3
|
-
import type { MapSchemaUnion } from '
|
|
3
|
+
import type { MapSchemaUnion, Property } from '.';
|
|
4
4
|
export declare const REQUEST_METHODS: readonly ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "TRACE", "SEARCH"];
|
|
5
5
|
export type RequestMethod = (typeof REQUEST_METHODS)[number];
|
|
6
6
|
export type GenericRequest = {
|
|
@@ -18,4 +18,19 @@ export type EndpointFunction<TRouteMethod extends RequestMethod, TRouteResponse,
|
|
|
18
18
|
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>>;
|
|
19
19
|
type UnwrapResponse<TResponse> = TResponse extends readonly any[] ? TResponse : TResponse[];
|
|
20
20
|
export type InferResponse<TResponse> = MapSchemaUnion<UnwrapResponse<TResponse>> extends infer InferredResponse ? InferredResponse | Promise<InferredResponse> : never;
|
|
21
|
+
export type ContractRoles = {
|
|
22
|
+
roles?: Collections['user']['item']['roles'];
|
|
23
|
+
};
|
|
24
|
+
export type Contract = {
|
|
25
|
+
response: Property | Property[];
|
|
26
|
+
} | {
|
|
27
|
+
payload: Property;
|
|
28
|
+
} | {
|
|
29
|
+
query: Property;
|
|
30
|
+
} | {
|
|
31
|
+
response?: Property | Property[];
|
|
32
|
+
payload?: Property;
|
|
33
|
+
query?: Property;
|
|
34
|
+
};
|
|
35
|
+
export type ContractWithRoles = ContractRoles & Contract;
|
|
21
36
|
export {};
|