forked from domiSchenk/PouchDB-typescript-definitions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pouch.d.ts
445 lines (386 loc) · 21.4 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
// Generated by typings
// Source: https://raw.githubusercontent.com/domiSchenk/PouchDB-typescript-definitions/master/pouch.d.ts
/**
* Define a global PouchDB object
*/
declare var PouchDB: pouchDB.IPouchDB;
import pDB = pouchDB;
import PouchRes = pouchDB.Response;
import PouchOpt = pouchDB.Options;
// Support AMD require
declare module 'PouchDB' {
export = pouchDB;
}
declare module pouchDB {
interface IPouchDB {
new (name: string): IPouchDB;
new (name: string, options: Options.IBase): IPouchDB;
destroy(): Promise<any>;
destroy(callback: (err: IError, any) => void): any;
destroy(options: any): Promise<any>;
destroy(options: any, callback: (err: IError, any) => void): any;
put<T>(doc: T): Promise<Response.IOk>;
put<T>(doc: T, callback: (err: IError, res: Response.IOk) => void): any;
put<T>(doc: T, docId: string): Promise<Response.IOk>;
put<T>(doc: T, docId: string, callback: (err: IError, res: Response.IOk) => void): any;
put<T>(doc: T, docId: string, docRev: string): Promise<Response.IOk>;
put<T>(doc: T, docId: string, docRev: string, callback: (err: IError, res: Response.IOk) => void): any;
put<T>(doc: T, docId: string, docRev: string, options: any): Promise<Response.IOk>;
put<T>(doc: T, docId: string, docRev: string, options: any, callback: (err: IError, res: Response.IOk) => void): any;
post<T>(doc: T): Promise<Response.IOk>;
post<T>(doc: T, callback: (err: IError, res: Response.IOk) => void): any;
post<T>(doc: T, options: any): Promise<Response.IOk>;
post<T>(doc: T, options: any, callback: (err: IError, res: Response.IOk) => void): any;
get<T>(docId: string): Promise<T>;
get<T>(docId: string, callback: (err: IError, res: T) => void): any;
get<T>(docId: string, options: Options.IFetch): Promise<T>;
get<T>(docId: string, options: Options.IFetch, callback: (err: IError, res: T) => void): any;
remove<T>(doc: T): Promise<Response.IOk>;
remove<T>(doc: T, callback: (err: IError, res: Response.IOk) => void): any;
remove<T>(doc: T, options: any): Promise<Response.IOk>;
remove<T>(doc: T, options: any, callback: (err: IError, res: Response.IOk) => void): any;
remove(docId: string, docRev: string): Promise<Response.IOk>;
remove(docId: string, docRev: string, callback: (err: IError, res: Response.IOk) => void): any;
remove(docId: string, docRev: string, options: any): Promise<Response.IOk>;
remove(docId: string, docRev: string, options: any, callback: (err: IError, res: Response.IOk) => void): any;
bulkDocs<T>(docs: T[]): Promise<Response.IOk[]>;
bulkDocs<T>(docs: T[], options: Options.IBulkDoc): Promise<Response.IOk[]>;
bulkDocs<T>(docs: T[], callback: (err: IError, res: Response.IOk[]) => void): any;
bulkDocs<T>(docs: T[], options: Options.IBulkDoc, callback: (err: IError, res: Response.IOk[]) => void): any;
allDocs<T>(): Promise<Response.IBatchFetch<T>>;
allDocs<T>(options: Options.IBatchFetch): Promise<Response.IBatchFetch<T>>;
// allDocs<T>(options: Options.IBatchFetch): Promise<Response.IBatchFetch<T>, IError>;
//allDocs<T>(options: Options.IBatchFetch): Promise<any>;
allDocs<T>(callback: (err: IError, res: Response.IBatchFetch<T>) => void): any;
allDocs<T>(options: Options.IBatchFetch, callback: (err: IError, res: Response.IBatchFetch<T>) => void): any;
changes(options: Options.IChanges): IPouchDBOn;
cancel(): IPouchDB;
replicate: IPouchDBReplicate;
sync(src: string, target: string): IPouchDBOn;
sync(src: string, target: string, options: Options.ISync): IPouchDBOn;
sync(remoteDB: string): IPouchDBOn;
sync(remoteDB: string, options: Options.ISync): IPouchDBOn;
putAttachment(docId: string, attachmentId: string, attachment: Object, type: string): Promise<Response.IOk>;
putAttachment(docId: string, attachmentId: string, attachment: Object, type: string, callback: (err: IError, res: Response.IOk) => void): any;
putAttachment(docId: string, attachmentId: string, rev: string, attachment: Object, type: string): Promise<Response.IOk>;
putAttachment(docId: string, attachmentId: string, rev: string, attachment: Object, type: string, callback: (err: IError, res: Response.IOk) => void): any;
getAttachment(docId: string, attachmentId: string): Promise<Response.IGetAttachement>;
getAttachment(docId: string, attachmentId: string, options: Options.IGetAttachement): Promise<Response.IGetAttachement>;
getAttachment(docId: string, attachmentId: string, callback: (err: IError, res: Response.IGetAttachement) => void): any;
getAttachment(docId: string, attachmentId: string, options: Options.IGetAttachement, callback: (err: IError, res: Response.IGetAttachement) => void): any;
removeAttachment(docId: string, attachmentId: string, rev: string): Promise<Response.IOk>;
removeAttachment(docId: string, attachmentId: string, rev: string, callback: (err: IError, res: Response.IOk) => void): any;
query(fun: ((doc: any) => void) | string): Promise<any>;
query(fun: ((doc: any) => void) | string, callback: (err: IError, res: any) => void): any;
query(fun: ((doc: any) => void) | string, options: Options.IQuery): Promise<any>;
query(fun: ((doc: any) => void) | string, options: Options.IQuery, callback: (err: IError, res: any) => void): any;
viewCleanup(): Promise<Response.IViewCleanup>
viewCleanup(callback: (err: IError, res: Response.IViewCleanup) => void): void
info(): Promise<Response.IInfo>;
info(callback: (err: IError, res: Response.IInfo) => void): void;
compact(): Promise<Response.IOk>;
compact(options: Options.ICompact): Promise<Response.IOk>;
compact(options: Options.ICompact, callback: (err: IError, res: Response.IOk) => void): void;
compact(callback: (err: IError, res: Response.IOk) => void): void;
revsDiff(diff: Object): Promise<any>;
revsDiff(diff: Object, callback: (err: IError, res: any) => void): void;
on(event: string, callback: (Object: any) => void): IPouchDB;
defaults(): IPouchDB;
defaults(options: Object): IPouchDB;
plugin(plugin: Object);
debug: IPouchDBDebug;
}
interface IPouchDBOn {
on(event: string, callback: (Object: any) => void): IPouchDBOn
cancel(): void;
}
interface IPouchDBDebug {
enable(opt: string): void;
disable(): void;
}
interface IPouchDBReplicate {
to(remoteDB: string | IPouchDB): any;
to(remoteDB: string | IPouchDB, options: Options.ISync): any;
from(remoteDB: string | IPouchDB): any;
from(remoteDB: string | IPouchDB, options: Options.ISync): any;
(source: string | IPouchDB, target: string | IPouchDB): IPouchDB;
(source: string | IPouchDB, target: string | IPouchDB, options: Options.ISync): IPouchDB;
}
export module Options { }
module Options {
interface IBulkDoc{
/** You can also specify a new_edits property on the options object
that when set to false allows you to post and overwrite existing documents.
Normally only the replication algorithm needs to do this.*/
new_edits: boolean;
}
interface IFetch {
/** Fetch specific revision of a document. Defaults to winning revision*/
rev?: string;
/** Include revision history of the document.*/
revs?: boolean;
/** Include a list of revisions of the document, and their availability.*/
revs_info?: boolean;
/** Fetch all leaf revisions if open_revs="all" or fetch all leaf revisions specified in open_revs array.
Leaves will be returned in the same order as specified in input array. */
open_revs?: string | string[];
/** If specified, conflicting leaf revisions will be attached in _conflicts array.*/
conflicts?: boolean;
/** Include attachment data. */
attachments?: boolean;
/** An object of options to be sent to the ajax requester.*/
ajax?: any;
}
interface IBatchFetch {
/** Include the document in each row in the doc field. */
include_docs?: boolean;
/** Include conflicts in the _conflicts field of a doc. */
conflicts?: boolean;
/** Include attachment data. */
attachments?: boolean;
/** Get rows with keys in a certain range (inclusive/inclusive).*/
startkey?: string;
/** Get rows with keys in a certain range (inclusive/inclusive).*/
endkey?: string;
inclusive_end?: any;
/** Maximum number of rows to return. */
limit?: number;
/** Number of rows to skip before returning (warning: poor performance on IndexedDB/LevelDB!). */
skip?: number;
/** Reverse the order of the output rows. */
descending?: string;
/** Only return rows matching this key.*/
key?: string;
/** Array of keys to fetch in a single shot.
* - Neither startkey nor endkey can be specified with this option.
* - The rows are returned in the same order as the supplied keys array.
* - The row for a deleted document will have the revision ID of the deletion, and an extra key "deleted":true in the value property.
* - The row for a nonexistent document will just contain an "error" property with the value "not_found".
*/
keys?: string[];
}
interface IGetAttachement {
rev: string;
}
interface IQuery {
/** Reduce function, or the string name of a built-in function: '_sum', '_count', or '_stats'. Defaults to false (no reduce). */
reduce?: ((...args: any[]) => void) | string;
/** Include the document in each row in the doc field. */
include_docs?: boolean;
/** Include conflicts in the _conflicts field of a doc. */
conflicts?: boolean;
/** Include attachment data. */
attachments?: boolean;
/** Get rows with keys in a certain range (inclusive/inclusive).*/
startkey?: string;
/** Get rows with keys in a certain range (inclusive/inclusive).*/
endkey?: string;
/** Include rows having a key equal to the given options.endkey. Default: true. */
inclusive_end?: boolean;
/** Maximum number of rows to return. */
limit?: number;
/** Number of rows to skip before returning (warning: poor performance on IndexedDB/LevelDB!). */
skip?: number;
/** Reverse the order of the output rows. */
descending?: string;
/** Only return rows matching this key.*/
key?: string;
/** Array of keys to fetch in a single shot.
* - Neither startkey nor endkey can be specified with this option.
* - The rows are returned in the same order as the supplied keys array.
* - The row for a deleted document will have the revision ID of the deletion, and an extra key "deleted":true in the value property.
* - The row for a nonexistent document will just contain an "error" property with the value "not_found".
*/
keys?: string[];
/** rue if you want the reduce function to group results by keys, rather than returning a single result. Defaults to false.*/
group?: boolean;
/** Number of elements in a key to group by, assuming the keys are arrays. Defaults to the full length of the array.*/
group_level?: number;
/** options.stale: One of 'ok' or 'update_after'. Only applies to saved views. Can be one of:
* - unspecified (default): Returns the latest results, waiting for the view to build if necessary.
* - 'ok': Returns results immediately, even if they’re out-of-date.
* - 'update_after': Returns results immediately, but kicks off a build afterwards.
*/
stale?: string;
}
interface ICompact {
interval: number;
}
interface IBase {
/** This turns on auto compaction, which means compact() is called after every change to the database.
Defaults to false.*/
auto_compaction?: boolean;
/** One of 'idb', 'leveldb', 'websql', or 'http'. If unspecified,
PouchDB will infer this automatically, preferring IndexedDB to WebSQL in browsers
that support both (i.e. Chrome, Opera and Android 4.4+).*/
adapter?: string;
/** When using the 'leveldb' adapter (the default on Node), any other options given
will be passed to levelup. The storage layer of leveldb can be replaced
by passing a level backend factory (such as MemDOWN) as options.db. */
db?: any;
/** (Remote databases only) Ajax requester options. For instance, passing in the options*/
ajax?: IAjax;
/** You can specify HTTP auth parameters either by using a database
with a name in the form http://user:pass@host/name or via the auth.username + auth.password options.*/
auth?: IAuth;
/** WebSQL-only: Amount in MB to request for storage, which you will need
if you are storing >5MB in order to avoid storage limit errors on iOS/Safari.*/
size?: number;
/** SQLite Plugin: Where to store data on iOS, which may affect iTunes/iCloud backup,
and thus whether or not your app gets rejected by Apple*/
location?: string;
/** SQLite Plugin: Use a pre-populated database, so you can package it with your app and users don’t have to wait for it to load*/
createFromLocation?: string;
/** SQLite Plugin:
- 1 to use the new sqlite4java implementation
- 2 to use the older version based on the native Android APIs.
Defaults to 1*/
androidDatabaseImplementation?: number;
}
interface IAuth {
username: string;
password: string;
}
interface IAjax {
cache: boolean;
timeout: number;
headers: any;
}
interface ISync {
/** If true, starts subscribing to future changes in the source database and continue
replicating them.*/
live?: boolean;
/** If true will attempt to retry replications in the case of failure (due to being offline),
using a backoff algorithm that retries at longer and longer intervals until a connection is re-
established. Only applicable if options.live is also true. */
retry?: boolean;
/** Reference a filter function from a design document to selectively get updates.
To use a view function, pass _view here and provide a reference to the view function
in options.view. See filtered replication for details.*/
filter?: any;
/** Only show changes for docs with these ids (array of strings).*/
doc_ids?: string | string[];
/** Object containing properties that are passed to the filter function,
e.g. {"foo:"bar"}, where "bar" will be available in the filter function
as params.query.foo. To access the params, define your filter function
like function (doc, params) { ... }*/
query_param?: any;
/** Specify a view function (e.g. 'design_doc_name/view_name') to act as a filter.
Documents counted as “passed” for a view filter if a map function emits at least one record for them.
Note: options.filter must be set to '_view' for this option to work.*/
view?: any;
/** Replicate changes after the given sequence number.*/
since?: any;
/** Number of documents to process at a time. Defaults to 100.
This affects the number of docs held in memory and the number sent at a time to the target server.
You may need to adjust downward if targeting devices with low amounts of memory (e.g. phones)
or if the documents are large in size (e.g. with attachments).
If your documents are small in size, then increasing this number will probably speed replication up.*/
batch_size?: number;
/** Number of batches to process at a time. Defaults to 10.
This (along wtih batch_size) controls how many docs are kept in memory at a time,
so the maximum docs in memory at once would equal batch_size × batches_limit */
batches_limit?: number;
/** backoff function to be used in retry replication.
This is a function that takes the current backoff as input (or 0 the first time)
and returns a new backoff in milliseconds. You can use this to tweak when and
how replication will try to reconnect to a remote database when the user goes offline.
Defaults to a function that chooses a random backoff between 0 and 2 seconds
and doubles every time it fails to connect. */
back_off_function?: any;
}
interface IChanges {
/** Does “live” changes, using CouchDB’s _longpoll_ feed if remote.*/
live?: boolean;
/** Include the document in each row in the doc field. */
include_docs?: boolean;
/** Include conflicts in the _conflicts field of a doc. */
conflicts?: boolean;
/** Include attachment data. */
attachments?: boolean;
/** Reverse the order of the output rows. */
descending?: string;
/** Replicate changes after the given sequence number.*/
since?: any;
/** Maximum number of rows to return. */
limit?: number;
/** Request timeout (in milliseconds).*/
timeout?: any;
/** Reference a filter function from a design document to selectively get updates.
To use a view function, pass _view here and provide a reference to the view function
in options.view. See filtered replication for details.*/
filter?: any;
/** Only show changes for docs with these ids (array of strings).*/
doc_ids?: string | string[];
/** Object containing properties that are passed to the filter function,
e.g. {"foo:"bar"}, where "bar" will be available in the filter function
as params.query.foo. To access the params, define your filter function
like function (doc, params) { ... }*/
query_param?: any;
/** Specify a view function (e.g. 'design_doc_name/view_name') to act as a filter.
Documents counted as “passed” for a view filter if a map function emits at least one record for them.
Note: options.filter must be set to '_view' for this option to work.*/
view?: any;
/** Is available for non-http databases and defaults to true.
Passing false prevents the changes feed from keeping all the documents in memory –
in other words complete always has an empty results array, and the change event
is the only way to get the event.
Useful for large change sets where otherwise you would run out of memory.*/
returnDocs?: boolean;
/** Only available for http databases, this configures how many changes to fetch at a time.
Increasing this can reduce the number of requests made. Default is 25.*/
batch_size?: number;
/** Specifies how many revisions are returned in the changes array.
The default, 'main_only', will only return the current “winning” revision;
'all_docs' will return all leaf revisions (including conflicts and deleted former conflicts).
Most likely you won’t need this unless you’re writing a replicator.*/
style?: any;
}
}
module Response {
interface IBatchFetch<T> {
total_rows: number;
offset: number;
rows: IBatchDoc<T>[];
}
interface IBatchDoc<T> {
doc: T;
id: string;
key: string;
value: IPouchDBBatchDocRev;
}
interface IGetAttachement {
_attachments: Object;
_id: string;
_rev: string;
}
interface IInfo {
db_name: string;
doc_count: number;
update_seq: string;
idb_attachment_format: string;
sqlite_plugin: boolean;
websql_encoding: string;
}
interface IViewCleanup {
ok: string;
}
interface IOk {
ok: boolean;
id: string;
rev: string;
}
}
interface IError {
status: number;
error: string;
reason: string;
}
interface IBaseDoc {
_id: string;
_rev: string;
}
interface IPouchDBBatchDocRev {
rev: string;
}
}