@aeriajs/types 0.0.95 → 0.0.96
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 +6 -5
- package/dist/functions.d.ts +20 -15
- package/dist/schema.d.ts +18 -7
- package/package.json +1 -1
package/dist/context.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Collection as MongoCollection
|
|
1
|
+
import type { Collection as MongoCollection } from 'mongodb';
|
|
2
2
|
import type { AcceptedRole } from './token.js';
|
|
3
3
|
import type { Collection } from './collection.js';
|
|
4
4
|
import type { ApiConfig } from './config.js';
|
|
@@ -8,24 +8,25 @@ import type { Result } from './result.js';
|
|
|
8
8
|
import type { EndpointError } from './endpointError.js';
|
|
9
9
|
import type { GenericRequest, GenericResponse, HTTPStatus } from './http.js';
|
|
10
10
|
import type { PackReferences, SchemaWithId } from './schema.js';
|
|
11
|
+
import type { JsonSchema } from './property.js';
|
|
11
12
|
import type { RateLimitingParams, RateLimitingError } from './security.js';
|
|
12
13
|
import type { Token } from './token.js';
|
|
13
14
|
export type CollectionModel<TDescription extends Description> = MongoCollection<Omit<PackReferences<SchemaWithId<TDescription>>, '_id'>>;
|
|
14
15
|
type OmitContextParameter<TFunction> = TFunction extends () => unknown ? TFunction : TFunction extends (payload: undefined, ...args: any[]) => infer Return ? () => Return : TFunction extends (payload: infer Payload, context: Context<any>, ...args: infer Rest) => infer Return ? (payload: Payload, ...args: Rest) => Return : never;
|
|
15
16
|
type RestParameters<TFunction> = TFunction extends (payload: any, context: Context<any>, ...args: infer Rest) => unknown ? Rest : never;
|
|
16
|
-
type UnionFunctions<TFunctions, TSchema extends
|
|
17
|
+
type UnionFunctions<TFunctions, TSchema extends JsonSchema> = {
|
|
17
18
|
[P in keyof TFunctions]: (P extends keyof CollectionFunctions ? CollectionFunctions<TSchema>[P] extends infer CollFunction ? CollFunction extends (...args: infer Args) => unknown ? Extract<undefined, Args[0]> extends never ? (payload: Args[0], ...args: RestParameters<TFunctions[P]>) => ReturnType<CollFunction> : (payload?: Args[0], ...args: RestParameters<TFunctions[P]>) => ReturnType<CollFunction> : never : never : OmitContextParameter<TFunctions[P]>) extends (...args: infer Args) => infer Return ? Return extends Promise<unknown> ? (...args: Args) => Return : (...args: Args) => Promise<Return> : never;
|
|
18
19
|
};
|
|
19
20
|
export type IndepthCollection<TCollection> = TCollection extends {
|
|
20
21
|
description: infer InferredDescription;
|
|
21
22
|
functions?: infer CollFunctions;
|
|
22
|
-
} ? Omit<TCollection, 'functions'> & {
|
|
23
|
+
} ? InferredDescription extends JsonSchema ? Omit<TCollection, 'functions'> & {
|
|
23
24
|
item: SchemaWithId<InferredDescription>;
|
|
24
|
-
functions: UnionFunctions<CollFunctions,
|
|
25
|
+
functions: UnionFunctions<CollFunctions, InferredDescription>;
|
|
25
26
|
originalFunctions: CollFunctions;
|
|
26
27
|
model: InferredDescription extends Description ? CollectionModel<InferredDescription> : never;
|
|
27
28
|
middlewares?: Collection['middlewares'];
|
|
28
|
-
} : TCollection;
|
|
29
|
+
} : never : TCollection;
|
|
29
30
|
export type IndepthCollections = {
|
|
30
31
|
[P in keyof Collections]: IndepthCollection<Collections[P]>;
|
|
31
32
|
};
|
package/dist/functions.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { FilterOperators, StrictFilter as Filter, WithId, ObjectId } from 'mongodb';
|
|
2
2
|
import type { Result, ExtractError } from './result.js';
|
|
3
3
|
import type { EndpointError } from './endpointError.js';
|
|
4
|
-
import type { PackReferences } from './schema.js';
|
|
4
|
+
import type { SchemaWithId, PackReferences } from './schema.js';
|
|
5
|
+
import type { JsonSchema } from './property.js';
|
|
5
6
|
import type { ACError } from './accessControl.js';
|
|
6
7
|
import type { ValidationErrorCode, TraverseError } from './validation.js';
|
|
7
8
|
import type { HTTPStatus, WithACErrors } from './http.js';
|
|
@@ -78,22 +79,26 @@ export type PaginatedGetAllReturnType<TDocument> = Result.Either<ExtractError<Ge
|
|
|
78
79
|
data: TDocument[];
|
|
79
80
|
pagination: Pagination;
|
|
80
81
|
}>;
|
|
81
|
-
export type CollectionFunctions<
|
|
82
|
-
count: (payload: CountPayload<
|
|
83
|
-
get: (payload: GetPayload<
|
|
84
|
-
getAll: (payload?: GetAllPayload<
|
|
85
|
-
insert: (payload: InsertPayload<
|
|
86
|
-
|
|
82
|
+
export type CollectionFunctions<TSchema extends JsonSchema = JsonSchema> = SchemaWithId<TSchema> extends infer InferredDocument ? InferredDocument extends WithId<unknown> ? {
|
|
83
|
+
count: (payload: CountPayload<InferredDocument>) => Promise<CountReturnType>;
|
|
84
|
+
get: (payload: GetPayload<InferredDocument>) => Promise<GetReturnType<InferredDocument>>;
|
|
85
|
+
getAll: (payload?: GetAllPayload<InferredDocument>) => Promise<GetAllReturnType<InferredDocument>>;
|
|
86
|
+
insert: (payload: InsertPayload<SchemaWithId<TSchema, {
|
|
87
|
+
keepTempIds: true;
|
|
88
|
+
}>>) => Promise<InsertReturnType<InferredDocument>>;
|
|
89
|
+
remove: (payload: RemovePayload<InferredDocument>) => Promise<RemoveReturnType<InferredDocument>>;
|
|
87
90
|
removeAll: (payload: RemoveAllPayload) => Promise<unknown>;
|
|
88
91
|
removeFile: (payload: RemoveFilePayload) => Promise<unknown>;
|
|
89
|
-
};
|
|
90
|
-
export type CollectionFunctionsSDK<
|
|
91
|
-
count: (payload: CountPayload<
|
|
92
|
-
get: (payload: GetPayload<
|
|
93
|
-
getAll: (payload?: GetAllPayload<
|
|
94
|
-
insert: (payload: InsertPayload<
|
|
95
|
-
|
|
92
|
+
} : never : never;
|
|
93
|
+
export type CollectionFunctionsSDK<TSchema extends JsonSchema = JsonSchema> = SchemaWithId<TSchema> extends infer InferredDocument ? InferredDocument extends WithId<unknown> ? {
|
|
94
|
+
count: (payload: CountPayload<InferredDocument>) => Promise<WithACErrors<CountReturnType>>;
|
|
95
|
+
get: (payload: GetPayload<InferredDocument>) => Promise<WithACErrors<GetReturnType<InferredDocument>>>;
|
|
96
|
+
getAll: (payload?: GetAllPayload<InferredDocument>) => Promise<WithACErrors<PaginatedGetAllReturnType<InferredDocument>>>;
|
|
97
|
+
insert: (payload: InsertPayload<SchemaWithId<TSchema, {
|
|
98
|
+
keepTempIds: true;
|
|
99
|
+
}>>) => Promise<WithACErrors<InsertReturnType<InferredDocument>>>;
|
|
100
|
+
remove: (payload: RemovePayload<InferredDocument>) => Promise<WithACErrors<RemoveReturnType<InferredDocument>>>;
|
|
96
101
|
removeAll: (payload: RemoveAllPayload) => Promise<unknown>;
|
|
97
102
|
removeFile: (payload: RemoveFilePayload) => Promise<unknown>;
|
|
98
|
-
};
|
|
103
|
+
} : never : never;
|
|
99
104
|
export {};
|
package/dist/schema.d.ts
CHANGED
|
@@ -43,13 +43,16 @@ export type InferProperty<T> = T extends TestType<{
|
|
|
43
43
|
type ExtractRequiredPropNames<T> = T extends readonly (infer PropName)[] ? PropName : Record<never, never> extends T ? null : keyof {
|
|
44
44
|
[K in keyof T as T[K] extends true ? K : never]: never;
|
|
45
45
|
};
|
|
46
|
-
|
|
46
|
+
type SchemaOptions = {
|
|
47
|
+
readonly keepTempIds?: boolean;
|
|
48
|
+
};
|
|
49
|
+
export type InferSchema<TSchema, TSchemaOptions extends SchemaOptions = {}> = MergeReferences<TSchema, TSchemaOptions> extends infer MappedTypes ? TSchema extends {
|
|
47
50
|
required: readonly [];
|
|
48
51
|
} ? Partial<MappedTypes> : TSchema extends {
|
|
49
52
|
required: infer InferredRequired;
|
|
50
53
|
} ? 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;
|
|
51
|
-
export type Schema<TSchema> = CaseTimestamped<TSchema, CaseOwned<TSchema, InferSchema<TSchema>>>;
|
|
52
|
-
export type SchemaWithId<TSchema> = Schema<TSchema> & {
|
|
54
|
+
export type Schema<TSchema, TSchemaOptions extends SchemaOptions = {}> = CaseTimestamped<TSchema, CaseOwned<TSchema, InferSchema<TSchema, TSchemaOptions>>>;
|
|
55
|
+
export type SchemaWithId<TSchema, TSchemaOptions extends SchemaOptions = {}> = Schema<TSchema, TSchemaOptions> & {
|
|
53
56
|
_id: ObjectId;
|
|
54
57
|
};
|
|
55
58
|
export type InferProperties<TSchema> = TSchema extends readonly unknown[] ? TSchema extends readonly (infer SchemaOption)[] ? SchemaOption extends unknown ? SchemaOption extends {
|
|
@@ -67,7 +70,7 @@ export type FilterReadonlyProperties<TProperties> = {
|
|
|
67
70
|
readOnly: true;
|
|
68
71
|
} ? P : never]: InferProperty<TProperties[P]>;
|
|
69
72
|
};
|
|
70
|
-
type MapReferences<TSchema> = TSchema extends {
|
|
73
|
+
type MapReferences<TSchema, TSchemaOptions extends SchemaOptions> = TSchema extends {
|
|
71
74
|
properties: infer Properties;
|
|
72
75
|
} ? {
|
|
73
76
|
-readonly [P in keyof Properties as Properties[P] extends TestType<{
|
|
@@ -78,11 +81,19 @@ type MapReferences<TSchema> = TSchema extends {
|
|
|
78
81
|
};
|
|
79
82
|
}> ? P : never]: Properties[P] extends infer Prop ? Prop extends TestType<{
|
|
80
83
|
$ref: infer K;
|
|
81
|
-
}> ? K extends keyof Collections ?
|
|
84
|
+
}> ? K extends keyof Collections ? TSchemaOptions extends {
|
|
85
|
+
keepTempIds: true;
|
|
86
|
+
} ? K extends 'file' ? ObjectId | string | {
|
|
87
|
+
tempId: ObjectId | string;
|
|
88
|
+
} : Collections[K]['item'] : Collections[K]['item'] : never : Prop extends TestType<{
|
|
82
89
|
items: TestType<{
|
|
83
90
|
$ref: infer K;
|
|
84
91
|
}>;
|
|
85
|
-
}> ? K extends keyof Collections ?
|
|
92
|
+
}> ? K extends keyof Collections ? TSchemaOptions extends {
|
|
93
|
+
keepTempIds: true;
|
|
94
|
+
} ? K extends 'file' ? (ObjectId | string | {
|
|
95
|
+
tempId: ObjectId | string;
|
|
96
|
+
})[] : Collections[K]['item'][] : Collections[K]['item'][] : never : never : never;
|
|
86
97
|
} : never;
|
|
87
98
|
type PackReferencesAux<T> = T extends (...args: unknown[]) => unknown ? T : T extends ObjectId ? T : T extends {
|
|
88
99
|
_id: infer Id;
|
|
@@ -92,5 +103,5 @@ type CombineProperties<TSchema> = TSchema extends {
|
|
|
92
103
|
} ? FilterReadonlyProperties<Properties> extends infer ReadonlyProperties ? Readonly<ReadonlyProperties> & {
|
|
93
104
|
[P in Exclude<keyof Properties, keyof ReadonlyProperties>]: InferProperty<Properties[P]>;
|
|
94
105
|
} : never : never;
|
|
95
|
-
type MergeReferences<TSchema> = CombineProperties<TSchema> extends infer CombinedProperties ? MapReferences<TSchema> extends infer MappedReferences ? MappedReferences & Omit<CombinedProperties, keyof MappedReferences> : never : never;
|
|
106
|
+
type MergeReferences<TSchema, TSchemaOptions extends SchemaOptions> = CombineProperties<TSchema> extends infer CombinedProperties ? MapReferences<TSchema, TSchemaOptions> extends infer MappedReferences ? MappedReferences & Omit<CombinedProperties, keyof MappedReferences> : never : never;
|
|
96
107
|
export {};
|