@aeriajs/types 0.0.133 → 0.0.135
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 +7 -3
- package/dist/functions.d.ts +14 -9
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { RouteContext } from './context.js';
|
|
2
|
-
import type { RouteUri } from './http.js';
|
|
2
|
+
import type { GenericRequest, GenericResponse, RouteUri } from './http.js';
|
|
3
3
|
import type { RateLimitingParams } from './security.js';
|
|
4
4
|
import type { CollectionItem } from './collection.js';
|
|
5
|
-
import type { UserRole } from './token.js';
|
|
5
|
+
import type { Token, UserRole } from './token.js';
|
|
6
|
+
import type { Result } from './result.js';
|
|
6
7
|
export type RolesHierarchy = Record<UserRole, readonly UserRole[] | boolean>;
|
|
8
|
+
export type GetTokenFunction = (request: GenericRequest, context: RouteContext) => Promise<Result.Either<unknown, Token>>;
|
|
9
|
+
export type CorsFunction = (req: GenericRequest, res: GenericResponse, config: CorsConfig) => Promise<null | undefined>;
|
|
7
10
|
export type CorsConfig = {
|
|
8
11
|
allowOrigin?: readonly string[];
|
|
9
12
|
allowMethods?: readonly string[];
|
|
@@ -15,7 +18,8 @@ export type ServerOptions = {
|
|
|
15
18
|
port?: number;
|
|
16
19
|
enableLogging?: boolean;
|
|
17
20
|
noWarmup?: boolean;
|
|
18
|
-
cors?: CorsConfig |
|
|
21
|
+
cors?: null | CorsConfig | CorsFunction;
|
|
22
|
+
getToken?: GetTokenFunction;
|
|
19
23
|
};
|
|
20
24
|
export type ApiConfig = {
|
|
21
25
|
name?: string;
|
package/dist/functions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FilterOperators, StrictFilter as Filter,
|
|
1
|
+
import type { FilterOperators, StrictFilter as Filter, ObjectId } from 'mongodb';
|
|
2
2
|
import type { Result, ExtractError } from './result.js';
|
|
3
3
|
import type { EndpointError } from './endpointError.js';
|
|
4
4
|
import type { SchemaWithId, InferSchema, PackReferences } from './schema.js';
|
|
@@ -41,16 +41,19 @@ export type What<TDocument> = ({
|
|
|
41
41
|
[P in keyof InferredDocument]: InferredDocument[P] | null;
|
|
42
42
|
} : never;
|
|
43
43
|
export type Projection<TDocument> = keyof TDocument | '_id' extends infer DocumentProp ? [DocumentProp] extends [string] ? DocumentProp[] : string[] : never;
|
|
44
|
-
export type
|
|
45
|
-
|
|
44
|
+
export type WithStringId<TDocument> = TDocument & {
|
|
45
|
+
_id: ObjectId | string;
|
|
46
|
+
};
|
|
47
|
+
export type QuerySort<TDocument> = Partial<Record<keyof WithStringId<TDocument>, 1 | -1>>;
|
|
48
|
+
export type CountPayload<TDocument extends WithStringId<unknown>> = {
|
|
46
49
|
filters?: Filters<TDocument>;
|
|
47
50
|
};
|
|
48
|
-
export type GetPayload<TDocument extends
|
|
51
|
+
export type GetPayload<TDocument extends WithStringId<unknown>> = {
|
|
49
52
|
filters: Filters<TDocument>;
|
|
50
53
|
project?: Projection<TDocument>;
|
|
51
54
|
populate?: (keyof TDocument)[];
|
|
52
55
|
};
|
|
53
|
-
export type GetAllPayload<TDocument extends
|
|
56
|
+
export type GetAllPayload<TDocument extends WithStringId<unknown>> = {
|
|
54
57
|
filters?: Filters<TDocument>;
|
|
55
58
|
project?: Projection<TDocument>;
|
|
56
59
|
offset?: number;
|
|
@@ -58,11 +61,11 @@ export type GetAllPayload<TDocument extends WithId<unknown>> = {
|
|
|
58
61
|
sort?: QuerySort<TDocument>;
|
|
59
62
|
populate?: (keyof TDocument)[];
|
|
60
63
|
};
|
|
61
|
-
export type InsertPayload<TDocument extends
|
|
64
|
+
export type InsertPayload<TDocument extends WithStringId<unknown>> = {
|
|
62
65
|
what: What<TDocument>;
|
|
63
66
|
project?: Projection<TDocument>;
|
|
64
67
|
};
|
|
65
|
-
export type RemovePayload<TDocument extends
|
|
68
|
+
export type RemovePayload<TDocument extends WithStringId<unknown>> = {
|
|
66
69
|
filters: Filters<TDocument>;
|
|
67
70
|
};
|
|
68
71
|
export type RemoveAllPayload = {
|
|
@@ -82,7 +85,7 @@ export type GetAllReturnType<TDocument> = Result.Either<ExtractError<Unpaginated
|
|
|
82
85
|
data: TDocument[];
|
|
83
86
|
pagination: Pagination;
|
|
84
87
|
}>;
|
|
85
|
-
export type CollectionFunctions<TSchema extends JsonSchema = JsonSchema> = SchemaWithId<TSchema> extends infer InferredDocument ? InferredDocument extends
|
|
88
|
+
export type CollectionFunctions<TSchema extends JsonSchema = JsonSchema> = SchemaWithId<TSchema> extends infer InferredDocument ? InferredDocument extends WithStringId<unknown> ? {
|
|
86
89
|
count: (payload: CountPayload<InferredDocument>) => Promise<CountReturnType>;
|
|
87
90
|
get: (payload: GetPayload<InferredDocument>) => Promise<GetReturnType<InferredDocument>>;
|
|
88
91
|
getAll: (payload?: GetAllPayload<InferredDocument>) => Promise<GetAllReturnType<InferredDocument>>;
|
|
@@ -94,7 +97,9 @@ export type CollectionFunctions<TSchema extends JsonSchema = JsonSchema> = Schem
|
|
|
94
97
|
removeFile: (payload: RemoveFilePayload) => Promise<unknown>;
|
|
95
98
|
unpaginatedGetAll: (payload?: GetAllPayload<InferredDocument>) => Promise<UnpaginatedGetAllReturnType<InferredDocument>>;
|
|
96
99
|
} : never : never;
|
|
97
|
-
export type CollectionFunctionsSDK<TSchema extends JsonSchema = JsonSchema> = SchemaWithId<TSchema
|
|
100
|
+
export type CollectionFunctionsSDK<TSchema extends JsonSchema = JsonSchema> = SchemaWithId<TSchema, {
|
|
101
|
+
useObjectIds: false;
|
|
102
|
+
}> extends infer InferredDocument ? InferredDocument extends WithStringId<unknown> ? {
|
|
98
103
|
count: (payload: CountPayload<InferredDocument>) => Promise<WithACErrors<CountReturnType>>;
|
|
99
104
|
get: (payload: GetPayload<InferredDocument>) => Promise<WithACErrors<GetReturnType<InferredDocument>>>;
|
|
100
105
|
getAll: (payload?: GetAllPayload<InferredDocument>) => Promise<WithACErrors<GetAllReturnType<InferredDocument>>>;
|