This repository has been archived by the owner on Sep 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathapp-pouchdb-database-behavior.d.ts
131 lines (117 loc) · 4.93 KB
/
app-pouchdb-database-behavior.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
/**
* DO NOT EDIT
*
* This file was automatically generated by
* https://github.com/Polymer/gen-typescript-declarations
*
* To modify these typings, edit the source file(s):
* app-pouchdb-database-behavior.html
*/
/// <reference path="../polymer/types/polymer.d.ts" />
/// <reference path="pouchdb.d.ts" />
declare namespace Polymer {
/**
* `Polymer.AppPouchDBDatabaseBehavior` is an abstract implementation that
* is intended to be shared by any element that refers to and operates on a
* PouchDB database instance. It includes implementation for creating and
* configuring a PouchDB database instance, and some advanced macro
* operations that might be performed on the database, including "upsert"
* and conflict-aware "put" and "post" operations.
*/
interface AppPouchDBDatabaseBehavior {
/**
* The PouchDB adapter to use. For more information on PouchDB adapters,
* please refer to the PouchDB documentation
* [here](https://pouchdb.com/api.html#create_database).
*/
adapter: string|null|undefined;
/**
* The name of the database. This can be either a local database (such
* as "cats"), or a remote one (e.g., "https://example.com:5678/cats").
*/
dbName: string|null|undefined;
/**
* The number of document revisions to keep track of. The default value
* (0) indicates no limit.
*/
revsLimit: number|null|undefined;
/**
* A reference to the PouchDB database instance that has been created.
*/
readonly db: object|null|undefined;
/**
* If true, all attempts to "put" or "post" values into the database
* will be automatically structured as an "upsert", where documents are
* updated if already available, or created if not.
*/
upsert: boolean|null|undefined;
/**
* If desired, assign a function that implements a conflict resolution
* strategy. This conflict resolution strategy will take precedence when
* a conflict occurs, and will prevent conflict notification events from
* being fired.
*
* Consider using an `app-pouchdb-conflict-resolver` element instead for
* a more declarative experience!
*/
resolveConflict: Function|null|undefined;
/**
* If the element is configured to `upsert`, this method performs an
* "upsert". Otherwise, it performs a conflict-aware "put".
*
* @param path The path through the PouchDB document to update.
*/
_put(path: string, value: any, doc: any): any;
/**
* If the element is configured to `upsert`, this method performs an
* "upsert". Otherwise, it performs a conflict-aware "post".
*
* @param doc The unsaved value of the document to create in the
* database.
* @returns A promise that resolves when the document creation
* has completed, or rejects with any unhandled error.
*/
_post(doc: object|null): Promise<any>|null;
/**
* Updates the document in the database, if it is already created,
* otherwise creates it.
*
* @param path The path through the PouchDB document to update.
*/
_upsert(path: string, value: any, doc: any): any;
/**
* Attempts a transaction with the PouchDB database, catches errors that
* result from a conflict, and attempts a conflict resolution process to
* complete the transaction.
*
* Conflict resolution prefers a conflict resolver that has been
* configured with the element as the `resolveConflict` property. The
* resolving function should have the following signature:
*
* `resolve(database:PouchDB, method:string, doc:Object, error:Error):Promise`
*
* It receives an instance of the database, the method attempted, the
* document that was attempted to be created or updated, and the error
* that was received by the error handler (which will implicitly always
* have status code 409). The resolver should return a `Promise` that
* resolves or rejects with the outcome of the conflict resolution.
*
* If no `resolveConflict` property is available, the element will request
* conflict resolution strategies by notifying of the conflict with a
* `app-pouchdb-conflict` event. The event detail has a `resolveConflict`
* method that can be called to pass a handler with the same signature as
* described above. The last conflict resolver obtained in this fashion by
* the time event propagation completes will be the one used.
*
* If no conflict resolver is obtained, then the error is re-thrown.
*
* @param method The method to attempt in a conflict-aware
* fashion, such as "put" or "post".
* @param doc The document to perform the method with.
* @returns A promise that resolves or rejects with the outcome
* of the conflict-aware transaction.
*/
_conflictAwareTransaction(method: string, doc: object|null): Promise<any>|null;
}
const AppPouchDBDatabaseBehavior: object;
}