-
Notifications
You must be signed in to change notification settings - Fork 64
/
index.d.ts
64 lines (52 loc) · 1.67 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
declare module 'apollo-datasource-mongodb' {
import { KeyValueCache } from '@apollo/utils.keyvaluecache'
import { Collection as MongoCollection, ObjectId } from 'mongodb'
import {
Collection as MongooseCollection,
Document,
Model as MongooseModel,
} from 'mongoose'
export type Collection<T extends { [key: string]: any }, U = MongoCollection<T>> = T extends Document
? MongooseCollection
: U
export type Model<T, U = MongooseModel<T>> = T extends Document
? U
: undefined
export type ModelOrCollection<T extends { [key: string]: any }, U = Model<T>> = T extends Document
? U
: Collection<T>
export interface Fields {
[fieldName: string]:
| string
| number
| boolean
| ObjectId
| (string | number | boolean | ObjectId)[]
}
export interface Options {
ttl: number
}
export interface MongoDataSourceConfig<TData extends { [key: string]: any }> {
modelOrCollection: ModelOrCollection<TData>
cache?: KeyValueCache<TData>
}
export class MongoDataSource<TData extends { [key: string]: any }> {
protected collection: Collection<TData>
protected model: Model<TData>
constructor(options: MongoDataSourceConfig<TData>)
findOneById(
id: ObjectId | string,
options?: Options
): Promise<TData | null | undefined>
findManyByIds(
ids: (ObjectId | string)[],
options?: Options
): Promise<(TData | null | undefined)[]>
findByFields(
fields: Fields,
options?: Options
): Promise<(TData | null | undefined)[]>
deleteFromCacheById(id: ObjectId | string): Promise<void>
deleteFromCacheByFields(fields: Fields): Promise<void>
}
}