@aeriajs/types 0.0.132 → 0.0.134
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/functions.d.ts +14 -9
- package/dist/schema.d.ts +22 -17
- package/package.json +1 -1
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>>>;
|
package/dist/schema.d.ts
CHANGED
|
@@ -13,11 +13,17 @@ type CaseTimestamped<TSchema, TType> = TSchema extends {
|
|
|
13
13
|
timestamps: false;
|
|
14
14
|
} ? TType : TType & Timestamped;
|
|
15
15
|
type TestType<T> = T & Record<string, unknown>;
|
|
16
|
-
|
|
16
|
+
type SchemaOptions = {
|
|
17
|
+
readonly keepTempIds?: boolean;
|
|
18
|
+
readonly useObjectIds?: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type InferProperty<T, TSchemaOptions extends SchemaOptions = {}> = T extends TestType<{
|
|
17
21
|
format: 'date' | 'date-time';
|
|
18
22
|
}> ? Date : T extends TestType<{
|
|
19
23
|
format: 'objectid';
|
|
20
|
-
}> ?
|
|
24
|
+
}> ? TSchemaOptions extends {
|
|
25
|
+
useObjectIds: false;
|
|
26
|
+
} ? string : ObjectId : T extends TestType<{
|
|
21
27
|
enum: ReadonlyArray<infer K>;
|
|
22
28
|
}> ? K : T extends TestType<{
|
|
23
29
|
type: 'string';
|
|
@@ -29,15 +35,15 @@ export type InferProperty<T> = T extends TestType<{
|
|
|
29
35
|
properties: unknown;
|
|
30
36
|
}> ? Schema<T & {
|
|
31
37
|
timestamps: false;
|
|
32
|
-
}> : T extends TestType<{
|
|
38
|
+
}, TSchemaOptions> : T extends TestType<{
|
|
33
39
|
additionalProperties: true;
|
|
34
40
|
}> ? any : T extends TestType<{
|
|
35
41
|
additionalProperties: infer K;
|
|
36
42
|
}> ? {
|
|
37
|
-
[P: string]: InferProperty<K> | undefined;
|
|
43
|
+
[P: string]: InferProperty<K, TSchemaOptions> | undefined;
|
|
38
44
|
} : T extends TestType<{
|
|
39
45
|
items: infer K;
|
|
40
|
-
}> ? InferProperty<K>[] : T extends TestType<{
|
|
46
|
+
}> ? InferProperty<K, TSchemaOptions>[] : T extends TestType<{
|
|
41
47
|
getter: (doc: unknown) => infer K;
|
|
42
48
|
}> ? Awaited<K> : T extends TestType<{
|
|
43
49
|
const: infer K;
|
|
@@ -47,9 +53,6 @@ export type InferProperty<T> = T extends TestType<{
|
|
|
47
53
|
type ExtractRequiredPropNames<T> = T extends readonly (infer PropName)[] ? PropName : Record<never, never> extends T ? null : keyof {
|
|
48
54
|
[K in keyof T as T[K] extends true ? K : never]: never;
|
|
49
55
|
};
|
|
50
|
-
type SchemaOptions = {
|
|
51
|
-
readonly keepTempIds?: boolean;
|
|
52
|
-
};
|
|
53
56
|
export type InferSchema<TSchema, TSchemaOptions extends SchemaOptions = {}> = MergeReferences<TSchema, TSchemaOptions> extends infer MappedTypes ? TSchema extends {
|
|
54
57
|
required: readonly [];
|
|
55
58
|
} ? Partial<MappedTypes> : TSchema extends {
|
|
@@ -57,22 +60,24 @@ export type InferSchema<TSchema, TSchemaOptions extends SchemaOptions = {}> = Me
|
|
|
57
60
|
} ? 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;
|
|
58
61
|
export type Schema<TSchema, TSchemaOptions extends SchemaOptions = {}> = CaseTimestamped<TSchema, CaseOwned<TSchema, InferSchema<TSchema, TSchemaOptions>>>;
|
|
59
62
|
export type SchemaWithId<TSchema, TSchemaOptions extends SchemaOptions = {}> = Schema<TSchema, TSchemaOptions> & {
|
|
60
|
-
_id:
|
|
63
|
+
_id: TSchemaOptions extends {
|
|
64
|
+
useObjectIds: false;
|
|
65
|
+
} ? string : ObjectId;
|
|
61
66
|
};
|
|
62
|
-
export type InferProperties<TSchema> = (TSchema extends readonly unknown[] ? TSchema extends readonly (infer SchemaOption)[] ? SchemaOption extends unknown ? SchemaOption : never : never : TSchema) extends infer InferredSchema ? InferredSchema extends {
|
|
67
|
+
export type InferProperties<TSchema, TSchemaOptions extends SchemaOptions = {}> = (TSchema extends readonly unknown[] ? TSchema extends readonly (infer SchemaOption)[] ? SchemaOption extends unknown ? SchemaOption : never : never : TSchema) extends infer InferredSchema ? InferredSchema extends {
|
|
63
68
|
$ref: infer K;
|
|
64
69
|
} | {
|
|
65
70
|
items: {
|
|
66
71
|
$ref: infer K;
|
|
67
72
|
};
|
|
68
|
-
} ? K extends keyof Collections ? 'items' extends keyof InferredSchema ? Collections[K]['item'][] : Collections[K]['item'] : never : InferProperty<InferredSchema> : never;
|
|
73
|
+
} ? K extends keyof Collections ? 'items' extends keyof InferredSchema ? Collections[K]['item'][] : Collections[K]['item'] : never : InferProperty<InferredSchema, TSchemaOptions> : never;
|
|
69
74
|
export type PackReferences<T> = {
|
|
70
75
|
[P in keyof T]: PackReferencesAux<T[P]>;
|
|
71
76
|
};
|
|
72
|
-
export type FilterReadonlyProperties<TProperties> = {
|
|
77
|
+
export type FilterReadonlyProperties<TProperties, TSchemaOptions extends SchemaOptions = {}> = {
|
|
73
78
|
[P in keyof TProperties as TProperties[P] extends {
|
|
74
79
|
readOnly: true;
|
|
75
|
-
} ? P : never]: InferProperty<TProperties[P]>;
|
|
80
|
+
} ? P : never]: InferProperty<TProperties[P], TSchemaOptions>;
|
|
76
81
|
};
|
|
77
82
|
type MapReferences<TSchema, TSchemaOptions extends SchemaOptions> = TSchema extends {
|
|
78
83
|
properties: infer Properties;
|
|
@@ -102,10 +107,10 @@ type MapReferences<TSchema, TSchemaOptions extends SchemaOptions> = TSchema exte
|
|
|
102
107
|
type PackReferencesAux<T> = T extends (...args: unknown[]) => unknown ? T : T extends ObjectId ? T : T extends {
|
|
103
108
|
_id: infer Id;
|
|
104
109
|
} ? Id : T extends Record<string, unknown> ? PackReferences<T> : T extends unknown[] | readonly unknown[] ? PackReferencesAux<T[number]>[] : T;
|
|
105
|
-
type CombineProperties<TSchema> = TSchema extends {
|
|
110
|
+
type CombineProperties<TSchema, TSchemaOptions extends SchemaOptions> = TSchema extends {
|
|
106
111
|
properties: infer Properties;
|
|
107
|
-
} ? FilterReadonlyProperties<Properties> extends infer ReadonlyProperties ? Readonly<ReadonlyProperties> & {
|
|
108
|
-
[P in Exclude<keyof Properties, keyof ReadonlyProperties>]: InferProperty<Properties[P]>;
|
|
112
|
+
} ? FilterReadonlyProperties<Properties, TSchemaOptions> extends infer ReadonlyProperties ? Readonly<ReadonlyProperties> & {
|
|
113
|
+
[P in Exclude<keyof Properties, keyof ReadonlyProperties>]: InferProperty<Properties[P], TSchemaOptions>;
|
|
109
114
|
} : never : never;
|
|
110
|
-
type MergeReferences<TSchema, TSchemaOptions extends SchemaOptions> = CombineProperties<TSchema> extends infer CombinedProperties ? MapReferences<TSchema, TSchemaOptions> extends infer MappedReferences ? MappedReferences & Omit<CombinedProperties, keyof MappedReferences> : never : never;
|
|
115
|
+
type MergeReferences<TSchema, TSchemaOptions extends SchemaOptions> = CombineProperties<TSchema, TSchemaOptions> extends infer CombinedProperties ? MapReferences<TSchema, TSchemaOptions> extends infer MappedReferences ? MappedReferences & Omit<CombinedProperties, keyof MappedReferences> : never : never;
|
|
111
116
|
export {};
|