-
Notifications
You must be signed in to change notification settings - Fork 66
/
index.d.ts
155 lines (119 loc) · 4.04 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
declare module "react-native-local-mongodb" {
export interface StorageStatic {
getItem(
key: string,
callback?: (error?: Error, result?: string) => void
): Promise<string | null>;
setItem(
key: string,
value: string,
callback?: (error?: Error) => void
): Promise<void>;
removeItem(key: string, callback?: (error?: Error) => void): Promise<void>;
}
export interface Options {
filename?: string;
inMemoryOnly?: boolean;
timestampData?: boolean;
autoload?: boolean;
onload?: Function;
afterSerialization?: Function;
beforeDeserialization?: Function;
corruptAlertThreshold?: number;
compareStrings?: Function;
storage: StorageStatic;
}
export interface IndexOptions {
fieldName: string;
unique?: boolean;
sparse?: boolean;
expireAfterSeconds?: number;
}
export interface UpdateOptions {
multi?: boolean;
upsert?: boolean;
returnUpdatedDocs?: boolean;
}
export interface RemoveOptions {
multi?: boolean;
}
export interface MongoDocument {
[key: string]: any;
}
export interface Cursor<T> {
exec(): Promise<T>;
exec(cb: Callback<T>): void;
skip(value: number): Cursor<T>;
limit(value: number): Cursor<T>;
sort(doc: MongoDocument): Cursor<T>;
}
export type Query = object;
export type Projection = any;
export type Callback<T = void> = (err: Error | null, value: T) => void;
export type InsertCallback = (err: Error | null, doc: MongoDocument) => void;
export type CountCallback = (err: Error | null, count: number) => void;
export type FindCallback = (err: Error | null, docs: MongoDocument[]) => void;
export type FindOneCallback = (err: Error | null, doc: MongoDocument) => void;
export type UpdateCallback = (
err: Error | null,
numAffected: number,
affectedDocuments: MongoDocument | MongoDocument[] | null,
upsert: boolean
) => void;
export type RemoveCallback = (err: Error | null, numAffected: number) => void;
export default class Datastore {
constructor(options?: Options);
public loadDatabase(): void;
public getAllData(): any[];
public resetIndexes(newData: any): void;
public ensureIndex(options: IndexOptions, callback?: Callback): void;
public removeIndex(fieldName: string, callback?: Callback): void;
public addToIndexes(doc: MongoDocument): void;
public removeFromIndexes(doc: MongoDocument): void;
public updateIndexes(oldDoc: MongoDocument, newDoc: MongoDocument): void;
public getCandidates(
query: Query,
dontExpireStaleDocs: boolean,
callback?: Callback
): void;
public insert(newDoc: MongoDocument, cb: InsertCallback): void;
public createNewId(): number;
public count(query: Query): Cursor<number>;
public count(query: Query, callback: Callback<number>): void;
public find(query: Query): Cursor<MongoDocument[]>;
public find(query: Query, projection: Projection): Cursor<MongoDocument[]>;
public find(
query: Query,
projection: Projection,
callback: Callback<MongoDocument[]>
): void;
public findOne(query: Query): Cursor<MongoDocument>;
public findOne(query: Query, projection: Projection): Cursor<MongoDocument>;
public findOne(
query: Query,
projection: Projection,
callback: Callback<MongoDocument>
): void;
public update(
query: Query,
doc: MongoDocument,
options?: UpdateOptions,
callback?: UpdateCallback
): void;
public remove(
query: Query,
options?: RemoveOptions,
callback?: RemoveCallback
): void;
public loadDatabaseAsync(): Promise<void>;
public findAsync(query: Query): Promise<MongoDocument[]>;
public findOneAsync(query: Query): Promise<MongoDocument>;
public insertAsync(newDoc: MongoDocument): Promise<MongoDocument>;
public updateAsync(
query: Query,
doc: MongoDocument,
options?: UpdateOptions
): Promise<MongoDocument>;
public removeAsync(query: Query, options?: RemoveOptions): Promise<number>;
}
}