-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathindex.d.ts
More file actions
72 lines (59 loc) · 2.01 KB
/
index.d.ts
File metadata and controls
72 lines (59 loc) · 2.01 KB
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
65
66
67
68
69
70
71
72
declare module 'apollo-datasource-mongodb' {
import { KeyValueCache } from '@apollo/utils.keyvaluecache'
import { Collection as MongoCollection, ObjectId } from 'mongodb'
import {
Document,
Collection as MongooseCollection,
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 MongoDataSourceOptions {
/** When enabled it won't return mongoose getters (like `id`) by default, if you want them back install the plugin https://github.com/mongoosejs/mongoose-lean-getters */
lean?: boolean
disableMemoize?: boolean
keyPrefix?: string
}
export interface MongoDataSourceConfig<TData extends { [key: string]: any }> {
modelOrCollection: ModelOrCollection<TData>
cache?: KeyValueCache<TData>
options?: MongoDataSourceOptions
}
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>
}
}