forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pouch.d.ts
232 lines (197 loc) · 6.38 KB
/
pouch.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
// Type definitions for Pouch 0.1
// Project: http://pouchdb.com
// Definitions by: Bill Sears <https://github.com/MrBigDog2U/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface PouchError {
status: number;
error: string;
reason: string;
}
interface PouchApi {
type(): string;
id(): string;
close(callback: () => void): void;
}
interface PouchInfoResponse {
db_name: string;
doc_count: number;
update_seq: string;
}
interface PouchApi {
info(callback: (err: PouchError, res: PouchInfoResponse) => void): void;
}
interface PouchGetOptions {
rev?: string;
revs?: boolean;
revs_info?: boolean;
conflicts?: boolean;
attachments?: boolean;
}
interface PouchGetResponse {
_id: string;
_rev: string;
_attachments: any;
}
interface PouchAllDocsOptions {
startkey?: string;
endKey?: string;
descending?: boolean;
include_docs?: boolean;
conflicts?: boolean;
}
interface PouchAllDocsItem {
id: string;
key: string;
value: any;
doc: any;
}
interface PouchAllDocsResponse {
total_rows: number;
rows: PouchAllDocsItem[];
}
interface PouchApi {
//
// get == select by id
//
get(id: string, opts: PouchGetOptions, callback: (err: PouchError, res: PouchGetResponse) => void): void;
get(id: string, callback: (err: PouchError, res: PouchGetResponse) => void): void;
allDocs(opts: PouchAllDocsOptions, callback: (err: PouchError, res: PouchAllDocsResponse) => void): void;
allDocs(callback: (err: PouchError, res: PouchAllDocsResponse) => void): void;
}
interface PouchBulkDocsRequest {
docs: any[];
}
interface PouchUpdateOptions {
new_edits?: boolean;
}
interface PouchUpdateResponse {
ok: boolean;
id: string;
rev: string;
}
interface PouchApi {
bulkDocs(req: PouchBulkDocsRequest, opts: PouchUpdateOptions, callback: (err: PouchError, res: PouchUpdateResponse[]) => void): void;
bulkDocs(req: PouchBulkDocsRequest, callback: (err: PouchError, res: PouchUpdateResponse[]) => void): void;
//
// post == insert (doc does not contain an _id)
//
post(doc: any, opts: PouchUpdateOptions, callback: (err: PouchError, res: PouchUpdateResponse) => void): void;
post(doc: any, callback: (err: PouchError, res: PouchUpdateResponse) => void): void;
//
// put == update (doc DOES contain an _id)
//
put(doc: any, opts: PouchUpdateOptions, callback: (err: PouchError, res: PouchUpdateResponse) => void): void;
put(doc: any, callback: (err: PouchError, res: PouchUpdateResponse) => void): void;
//
// remove == delete
//
remove(doc: any, opts: PouchUpdateOptions, callback: (err: PouchError, res: PouchUpdateResponse) => void): void;
remove(doc: any, callback: (err: PouchError, res: PouchUpdateResponse) => void): void;
}
interface PouchFilter {
map: (doc: any) => void;
reduce?: (key: string, value: any) => any;
}
interface PouchQueryOptions {
complete?: any;
include_docs?: boolean;
error?: (err: PouchError) => void;
descending?: boolean;
reduce?: boolean;
}
interface PouchQueryResponse {
rows: any[];
}
interface PouchApi {
//
// query == select by other criteria
//
query(fun: string, opts: PouchQueryOptions, callback: (err: PouchError, res: PouchQueryResponse) => void): void;
query(fun: string, callback: (err: PouchError, res: PouchQueryResponse) => void): void;
query(fun: PouchFilter, opts: PouchQueryOptions, callback: (err: PouchError, res: PouchQueryResponse) => void): void;
query(fun: PouchFilter, callback: (err: PouchError, res: PouchQueryResponse) => void): void;
}
interface PouchAttachmentOptions {
decode?: boolean;
}
interface PouchApi {
getAttachment(id: string, opts: PouchAttachmentOptions, callback: (err: PouchError, res: any) => void): void;
getAttachment(id: string, callback: (err: PouchError, res: any) => void): void;
putAttachment(id: string, rev: string, doc: any, type: string, callback: (err: PouchError, res: PouchUpdateResponse) => void): void;
removeAttachment(id: string, rev: string, callback: (err: PouchError, res: PouchUpdateResponse) => void): void;
}
interface PouchCancellable {
cancel: () => void;
}
interface PouchChangesOptions {
onChange: (change: PouchChange) => void;
complete?: (err: PouchError, res: PouchChanges) => void;
seq?: number;
since?: number;
descending?: boolean;
filter?: PouchFilter;
continuous?: boolean;
include_docs?: boolean;
conflicts?: boolean;
}
interface PouchChange {
changes: any;
doc: PouchGetResponse;
id: string;
seq: number;
}
interface PouchChanges {
results: PouchChange[];
}
interface PouchApi {
changes(opts: PouchChangesOptions, callback: (err: PouchError, res: PouchChanges) => void): PouchCancellable;
changes(callback: (err: PouchError, res: PouchChanges) => void): PouchCancellable;
}
interface PouchRevsDiffOptions {
}
interface PouchReplicateOptions {
continuous?: boolean;
onChange?: (e: any) => void;
filter?: any; // Can be either string or PouchFilter
complete?: (err: PouchError, res: PouchChanges) => void;
}
interface PouchReplicateResponse {
ok: boolean;
start_time: Date;
end_time: Date;
docs_read: number;
docs_written: number;
}
interface PouchReplicate {
from(url: string, opts: PouchReplicateOptions, callback: (err: PouchError, res: PouchReplicateResponse) => void): PouchCancellable;
from(url: string, callback: (err: PouchError, res: PouchReplicateResponse) => void): PouchCancellable;
to(dbName: string, opts: PouchReplicateOptions, callback: (err: PouchError, res: PouchReplicateResponse) => void): PouchCancellable;
to(dbName: string, callback: (err: PouchError, res: PouchReplicateResponse) => void): PouchCancellable;
}
interface PouchApi {
revsDiff(req: any, opts: PouchRevsDiffOptions, callback: (missing: any) => void): void;
revsDiff(req: any, callback: (missing: any) => void): void;
replicate: PouchReplicate;
}
interface PouchOptions {
name?: string;
adapter?: string;
skip_setup?: boolean;
}
interface PouchDB extends PouchApi {
new (name: string, opts: PouchOptions, callback: (err: PouchError, res: PouchDB) => void): PouchDB;
new (name: string, callback: (err: PouchError, res: PouchDB) => void): PouchDB;
new (name: string, opts: PouchOptions): PouchDB;
new (name: string): PouchDB;
destroy(name: string, callback: (err: PouchError) => void): void;
}
declare var PouchDB: PouchDB;
// Support AMD require
declare module 'pouchdb' {
export = PouchDB;
}
//
// emit is the function that the PouchFilter.map function should call in order to add a particular item to
// a filter view.
//
declare function emit(key: any, value: any): void;