generated from hyper63/adapter-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
67 lines (52 loc) · 1.57 KB
/
types.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
65
66
67
import type { Document } from '../types.ts'
export interface MongoInstanceClient {
db(name: string): MongoDatabaseClient
}
export interface MongoDatabaseClient {
drop(): Promise<boolean>
collection<T extends Document = Document>(
name: string,
): MongoCollectionClient<T>
}
export interface MongoCollectionClient<T extends Document> {
createIndex(
spec: { [field: string]: 1 | -1 },
options: { partialFilterExpression?: Document; name: string },
): Promise<string>
insertOne(doc: T): Promise<{ insertedId: string }>
insertMany(docs: T[]): Promise<{ insertedIds: string[] }>
findOne(
filter: Document,
options: { projection?: Document },
): Promise<T | null>
find(
filter?: Document,
options?: {
projection?: Document
sort?: Document
limit?: number
skip?: number
},
): Promise<T[]>
replaceOne(
filter: Document,
replacement: Document,
options: { upsert?: boolean },
): Promise<{
matchedCount: number
modifiedCount: number
upsertedCount: number
upsertedId?: string
}>
deleteOne(filter: Document): Promise<{ deletedCount: number }>
deleteMany(filter: Document): Promise<{ deletedCount: number }>
bulk(operations: BulkOperation[]): Promise<boolean>
aggregate<T = Document>(pipeline: Document[]): Promise<T[]>
countDocuments(
filter?: Document,
options?: { limit?: number; skip?: number },
): Promise<number>
}
export type BulkOperation =
| { replaceOne: { filter: Document; replacement: Document; upsert: boolean } }
| { deleteOne: { filter: Document } }