cozy-pouch-link 48.25.0 → 49.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/CozyPouchLink.js +604 -237
  2. package/dist/CozyPouchLink.spec.js +100 -42
  3. package/dist/PouchManager.js +326 -255
  4. package/dist/PouchManager.spec.js +91 -58
  5. package/dist/helpers.js +79 -0
  6. package/dist/helpers.spec.js +85 -1
  7. package/dist/jsonapi.js +54 -7
  8. package/dist/jsonapi.spec.js +57 -14
  9. package/dist/localStorage.js +646 -207
  10. package/dist/localStorage.spec.js +48 -0
  11. package/dist/mango.js +72 -20
  12. package/dist/mango.spec.js +1 -1
  13. package/dist/migrations/adapter.js +1 -1
  14. package/dist/platformWeb.js +120 -0
  15. package/dist/remote.js +39 -5
  16. package/dist/remote.spec.js +214 -0
  17. package/dist/replicateOnce.js +337 -0
  18. package/dist/startReplication.js +70 -45
  19. package/dist/startReplication.spec.js +374 -39
  20. package/dist/types.js +80 -0
  21. package/dist/utils.js +11 -2
  22. package/package.json +9 -5
  23. package/types/AccessToken.d.ts +16 -0
  24. package/types/CozyPouchLink.d.ts +228 -0
  25. package/types/PouchManager.d.ts +86 -0
  26. package/types/__tests__/fixtures.d.ts +48 -0
  27. package/types/__tests__/mocks.d.ts +4 -0
  28. package/types/helpers.d.ts +17 -0
  29. package/types/index.d.ts +1 -0
  30. package/types/jsonapi.d.ts +19 -0
  31. package/types/localStorage.d.ts +124 -0
  32. package/types/logger.d.ts +2 -0
  33. package/types/loop.d.ts +60 -0
  34. package/types/mango.d.ts +3 -0
  35. package/types/migrations/adapter.d.ts +18 -0
  36. package/types/platformWeb.d.ts +17 -0
  37. package/types/remote.d.ts +6 -0
  38. package/types/replicateOnce.d.ts +29 -0
  39. package/types/startReplication.d.ts +12 -0
  40. package/types/types.d.ts +104 -0
  41. package/types/utils.d.ts +3 -0
@@ -0,0 +1,228 @@
1
+ export function getReplicationURL(uri: any, token: any, doctype: any): string;
2
+ export function isExpiredTokenError(pouchError: any): boolean;
3
+ export default PouchLink;
4
+ export type CozyClientDocument = any;
5
+ export type ReplicationStatus = "idle" | "replicating";
6
+ export type PouchLinkOptions = {
7
+ /**
8
+ * Milliseconds between replications
9
+ */
10
+ replicationInterval?: number;
11
+ /**
12
+ * Doctypes to replicate
13
+ */
14
+ doctypes: string[];
15
+ /**
16
+ * A mapping from doctypes to replication options. All pouch replication options can be used, as well as the "strategy" option that determines which way the replication is done (can be "sync", "fromRemote" or "toRemote")
17
+ */
18
+ doctypesReplicationOptions: Record<string, object>;
19
+ /**
20
+ * Platform specific adapters and methods
21
+ */
22
+ platform: import('./types').LinkPlatform;
23
+ };
24
+ /**
25
+ * @typedef {import('cozy-client/src/types').CozyClientDocument} CozyClientDocument
26
+ *
27
+ * @typedef {"idle"|"replicating"} ReplicationStatus
28
+ */
29
+ /**
30
+ * @typedef {object} PouchLinkOptions
31
+ * @property {number} [replicationInterval] Milliseconds between replications
32
+ * @property {string[]} doctypes Doctypes to replicate
33
+ * @property {Record<string, object>} doctypesReplicationOptions A mapping from doctypes to replication options. All pouch replication options can be used, as well as the "strategy" option that determines which way the replication is done (can be "sync", "fromRemote" or "toRemote")
34
+ * @property {import('./types').LinkPlatform} platform Platform specific adapters and methods
35
+ */
36
+ /**
37
+ * Link to be passed to a `CozyClient` instance to support CouchDB. It instantiates
38
+ * PouchDB collections for each doctype that it supports and knows how
39
+ * to respond to queries and mutations.
40
+ */
41
+ declare class PouchLink extends CozyLink {
42
+ /**
43
+ * Return the PouchDB adapter name.
44
+ * Should be IndexedDB for newest adapters.
45
+ *
46
+ * @param {import('./types').LocalStorage} localStorage Methods to access local storage
47
+ * @returns {Promise<string>} The adapter name
48
+ */
49
+ static getPouchAdapterName: (localStorage: import('./types').LocalStorage) => Promise<string>;
50
+ /**
51
+ * constructor - Initializes a new PouchLink
52
+ *
53
+ * @param {PouchLinkOptions} [opts={}]
54
+ */
55
+ constructor(opts?: PouchLinkOptions);
56
+ options: {
57
+ replicationInterval: number;
58
+ } & PouchLinkOptions;
59
+ doctypes: string[];
60
+ doctypesReplicationOptions: Record<string, any>;
61
+ indexes: {};
62
+ storage: PouchLocalStorage;
63
+ /** @type {Record<string, ReplicationStatus>} - Stores replication states per doctype */
64
+ replicationStatus: Record<string, ReplicationStatus>;
65
+ getReplicationURL(doctype: any): string;
66
+ registerClient(client: any): Promise<void>;
67
+ client: any;
68
+ /**
69
+ * Migrate the current adapter
70
+ *
71
+ * @typedef {object} MigrationParams
72
+ * @property {string} [fromAdapter] - The current adapter type, e.g. 'idb'
73
+ * @property {string} [toAdapter] - The new adapter type, e.g. 'indexeddb'
74
+ * @property {string} [url] - The Cozy URL
75
+ * @property {Array<object>} [plugins] - The PouchDB plugins
76
+ *
77
+ * @param {MigrationParams} params - Migration params
78
+ */
79
+ migrateAdapter({ fromAdapter, toAdapter, url, plugins }: {
80
+ /**
81
+ * - The current adapter type, e.g. 'idb'
82
+ */
83
+ fromAdapter?: string;
84
+ /**
85
+ * - The new adapter type, e.g. 'indexeddb'
86
+ */
87
+ toAdapter?: string;
88
+ /**
89
+ * - The Cozy URL
90
+ */
91
+ url?: string;
92
+ /**
93
+ * - The PouchDB plugins
94
+ */
95
+ plugins?: Array<object>;
96
+ }): Promise<void>;
97
+ onLogin(): Promise<void>;
98
+ pouches: PouchManager;
99
+ /**
100
+ * Receives PouchDB updates (documents grouped by doctype).
101
+ * Normalizes the data (.id -> ._id, .rev -> _rev).
102
+ * Passes the data to the client and to the onSync handler.
103
+ *
104
+ * Emits an event (pouchlink:sync:end) when the sync (all doctypes) is done
105
+ */
106
+ handleOnSync(doctypeUpdates: any): void;
107
+ handleDoctypeSyncStart(doctype: any): void;
108
+ handleDoctypeSyncEnd(doctype: any): void;
109
+ /**
110
+ * User of the link can call this to start ongoing replications.
111
+ * Typically, it can be used when the application regains focus.
112
+ *
113
+ * Emits pouchlink:sync:start event when the replication begins
114
+ *
115
+ * @public
116
+ * @returns {void}
117
+ */
118
+ public startReplication(): void;
119
+ /**
120
+ * User of the link can call this to stop ongoing replications.
121
+ * Typically, it can be used when the applications loses focus.
122
+ *
123
+ * Emits pouchlink:sync:stop event
124
+ *
125
+ * @public
126
+ * @returns {void}
127
+ */
128
+ public stopReplication(): void;
129
+ onSyncError(error: any): Promise<void>;
130
+ getSyncInfo(doctype: any): import("./types").SyncInfo;
131
+ getPouch(doctype: any): any;
132
+ supportsOperation(operation: any): boolean;
133
+ sanitizeJsonApi(data: any): Pick<Pick<any, string | number | symbol>, string | number | symbol>;
134
+ /**
135
+ * Retrieve the existing document from Pouch
136
+ *
137
+ * @private
138
+ * @param {*} id - ID of the document to retrieve
139
+ * @param {*} type - Doctype of the document to retrieve
140
+ * @param {*} throwIfNotFound - If true the method will throw when the document is not found. Otherwise it will return null
141
+ * @returns {Promise<CozyClientDocument | null>}
142
+ */
143
+ private getExistingDocument;
144
+ /**
145
+ *
146
+ * Check if there is warmup queries for this doctype
147
+ * and return if those queries are already warmed up or not
148
+ *
149
+ * @param {string} doctype - Doctype to check
150
+ * @returns {Promise<boolean>} the need to wait for the warmup
151
+ */
152
+ needsToWaitWarmup(doctype: string): Promise<boolean>;
153
+ hasIndex(name: any): boolean;
154
+ /**
155
+ * Create the PouchDB index if not existing
156
+ *
157
+ * @param {Array} fields - Fields to index
158
+ * @param {object} indexOption - Options for the index
159
+ * @param {object} [indexOption.partialFilter] - partialFilter
160
+ * @param {string} [indexOption.indexName] - indexName
161
+ * @param {string} [indexOption.doctype] - doctype
162
+ * @returns {Promise<import('./types').PouchDbIndex>}
163
+ */
164
+ createIndex(fields: any[], { partialFilter, indexName, doctype }?: {
165
+ partialFilter: object;
166
+ indexName: string;
167
+ doctype: string;
168
+ }): Promise<import('./types').PouchDbIndex>;
169
+ /**
170
+ * Retrieve the PouchDB index if exist, undefined otherwise
171
+ *
172
+ * @param {string} doctype - The query's doctype
173
+ * @param {import('./types').MangoQueryOptions} options - The find options
174
+ * @param {string} indexName - The index name
175
+ * @returns {import('./types').PouchDbIndex | undefined}
176
+ */
177
+ findExistingIndex(doctype: string, options: import('./types').MangoQueryOptions, indexName: string): import('./types').PouchDbIndex | undefined;
178
+ /**
179
+ * Handle index creation if it is missing.
180
+ *
181
+ * When an index is missing, we first check if there is one with a different
182
+ * name but the same definition. If there is none, we create the new index.
183
+ *
184
+ * /!\ Warning: this method is similar to DocumentCollection.handleMissingIndex()
185
+ * If you edit this method, please check if the change is also needed in DocumentCollection
186
+ *
187
+ * @param {string} doctype The mango selector
188
+ * @param {import('./types').MangoQueryOptions} options The find options
189
+ * @returns {Promise<import('./types').PouchDbIndex>} index
190
+ * @private
191
+ */
192
+ private ensureIndex;
193
+ executeQuery({ doctype, selector, sort, fields, limit, id, ids, skip, indexedFields, partialFilter }: {
194
+ doctype: any;
195
+ selector: any;
196
+ sort: any;
197
+ fields: any;
198
+ limit: any;
199
+ id: any;
200
+ ids: any;
201
+ skip: any;
202
+ indexedFields: any;
203
+ partialFilter: any;
204
+ }): Promise<{
205
+ data: any;
206
+ meta?: undefined;
207
+ skip?: undefined;
208
+ next?: undefined;
209
+ } | {
210
+ data: any;
211
+ meta: {
212
+ count: any;
213
+ };
214
+ skip: any;
215
+ next: boolean;
216
+ }>;
217
+ executeMutation(mutation: any, result: any, forward: any): Promise<any>;
218
+ createDocument(mutation: any): Promise<any>;
219
+ updateDocument(mutation: any): Promise<any>;
220
+ updateDocuments(mutation: any): Promise<any[]>;
221
+ deleteDocument(mutation: any): Promise<any>;
222
+ addReferencesTo(mutation: any): Promise<void>;
223
+ dbMethod(method: any, mutation: any): Promise<any>;
224
+ syncImmediately(): Promise<void>;
225
+ }
226
+ import { CozyLink } from "cozy-client";
227
+ import { PouchLocalStorage } from "./localStorage";
228
+ import PouchManager from "./PouchManager";
@@ -0,0 +1,86 @@
1
+ export default PouchManager;
2
+ /**
3
+ * Handles the lifecycle of several pouches
4
+ *
5
+ * - Creates/Destroys the pouches
6
+ * - Replicates periodically
7
+ */
8
+ declare class PouchManager {
9
+ constructor(doctypes: any, options: any);
10
+ options: any;
11
+ doctypes: any;
12
+ storage: PouchLocalStorage;
13
+ PouchDB: any;
14
+ isOnline: any;
15
+ events: any;
16
+ init(): Promise<void>;
17
+ pouches: import("lodash").Dictionary<any>;
18
+ /** @type {Record<string, import('./types').SyncInfo>} - Stores synchronization info per doctype */
19
+ syncedDoctypes: Record<string, import('./types').SyncInfo>;
20
+ warmedUpQueries: any;
21
+ getReplicationURL: any;
22
+ doctypesReplicationOptions: any;
23
+ listenerLaunched: boolean;
24
+ ensureDatabasesExistDone: boolean;
25
+ /**
26
+ * Starts periodic syncing of the pouches
27
+ *
28
+ * @returns {Promise<Loop | void>}
29
+ */
30
+ startReplicationLoop(): Promise<Loop | void>;
31
+ /** Stop periodic syncing of the pouches */
32
+ stopReplicationLoop(): void;
33
+ /** Starts replication */
34
+ replicateOnce(): Promise<any>;
35
+ executeQuery: any;
36
+ /** @type {import('./types').CancelablePromise[]} - Stores replication promises */
37
+ replications: import('./types').CancelablePromise[];
38
+ addListeners(): void;
39
+ removeListeners(): void;
40
+ destroy(): Promise<any[]>;
41
+ /**
42
+ * Via a call to info() we ensure the database exist on the
43
+ * remote side. This is done only once since after the first
44
+ * call, we are sure that the databases have been created.
45
+ */
46
+ ensureDatabasesExist(): Promise<void>;
47
+ replicationLoop: Loop;
48
+ /**
49
+ * If a replication is currently ongoing, will start a replication
50
+ * just after it has finished. Otherwise it will start a replication
51
+ * immediately
52
+ */
53
+ syncImmediately(): void;
54
+ handleReplicationError(err: any): void;
55
+ cancelCurrentReplications(): void;
56
+ waitForCurrentReplications(): Promise<void> | Promise<any[]>;
57
+ getPouch(doctype: any): any;
58
+ /**
59
+ * Update the Sync info for the specifed doctype
60
+ *
61
+ * @param {string} doctype - The doctype to update
62
+ * @param {import('./types').SyncStatus} status - The new Sync status for the doctype
63
+ */
64
+ updateSyncInfo(doctype: string, status?: import('./types').SyncStatus): Promise<void>;
65
+ /**
66
+ * Get the Sync info for the specified doctype
67
+ *
68
+ * @param {string} doctype - The doctype to check
69
+ * @returns {import('./types').SyncInfo}
70
+ */
71
+ getSyncInfo(doctype: string): import('./types').SyncInfo;
72
+ /**
73
+ * Get the Sync status for the specified doctype
74
+ *
75
+ * @param {string} doctype - The doctype to check
76
+ * @returns {import('./types').SyncStatus}
77
+ */
78
+ getSyncStatus(doctype: string): import('./types').SyncStatus;
79
+ clearSyncedDoctypes(): Promise<void>;
80
+ warmupQueries(doctype: any, queries: any): Promise<void>;
81
+ checkToWarmupDoctype(doctype: any, replicationOptions: any): void;
82
+ areQueriesWarmedUp(doctype: any, queries: any): Promise<any>;
83
+ clearWarmedUpQueries(): Promise<void>;
84
+ }
85
+ import { PouchLocalStorage } from "./localStorage";
86
+ import Loop from "./loop";
@@ -0,0 +1,48 @@
1
+ export namespace TODO_1 {
2
+ const _id: string;
3
+ const _type: string;
4
+ const label: string;
5
+ const done: boolean;
6
+ }
7
+ export namespace TODO_2 {
8
+ const _id_1: string;
9
+ export { _id_1 as _id };
10
+ const _type_1: string;
11
+ export { _type_1 as _type };
12
+ const label_1: string;
13
+ export { label_1 as label };
14
+ const done_1: boolean;
15
+ export { done_1 as done };
16
+ }
17
+ export namespace TODO_3 {
18
+ const _id_2: string;
19
+ export { _id_2 as _id };
20
+ const _type_2: string;
21
+ export { _type_2 as _type };
22
+ const label_2: string;
23
+ export { label_2 as label };
24
+ const done_2: boolean;
25
+ export { done_2 as done };
26
+ }
27
+ export namespace TODO_4 {
28
+ const _id_3: string;
29
+ export { _id_3 as _id };
30
+ const _type_3: string;
31
+ export { _type_3 as _type };
32
+ const label_3: string;
33
+ export { label_3 as label };
34
+ const done_3: boolean;
35
+ export { done_3 as done };
36
+ }
37
+ export namespace SCHEMA {
38
+ namespace todos {
39
+ const doctype: string;
40
+ namespace relationships {
41
+ namespace attachments {
42
+ export const type: string;
43
+ const doctype_1: string;
44
+ export { doctype_1 as doctype };
45
+ }
46
+ }
47
+ }
48
+ }
@@ -0,0 +1,4 @@
1
+ export function pouchReplication(mockOptions: any): (url: any, options: any) => {
2
+ on: (event: any, fn: any) => any;
3
+ cancel: () => void;
4
+ };
@@ -0,0 +1,17 @@
1
+ export default helpers;
2
+ declare namespace helpers {
3
+ function isAdapterBugged(adapterName: any): boolean;
4
+ function withoutDesignDocuments(res: any): any;
5
+ function getDocs(db: any, fct: any, options?: {}): any;
6
+ function allDocs(db: any, options?: {}): Promise<any>;
7
+ function find(db: any, options?: {}): Promise<any>;
8
+ function isDesignDocument(doc: any): boolean;
9
+ function isDeletedDocument(doc: any): any;
10
+ function insertBulkDocs(db: any, docs: any): Promise<any>;
11
+ function normalizeFindSelector({ selector, sort, indexedFields, partialFilter }: {
12
+ selector: any;
13
+ sort: any;
14
+ indexedFields: any;
15
+ partialFilter: any;
16
+ }): any;
17
+ }
@@ -0,0 +1 @@
1
+ export { default } from "./CozyPouchLink";
@@ -0,0 +1,19 @@
1
+ export function normalizeDoc(doc: any, doctype: any, client: any): any;
2
+ export function fromPouchResult({ res, withRows, doctype, client }: {
3
+ res: any;
4
+ withRows: any;
5
+ doctype: any;
6
+ client: any;
7
+ }): {
8
+ data: any;
9
+ meta?: undefined;
10
+ skip?: undefined;
11
+ next?: undefined;
12
+ } | {
13
+ data: any;
14
+ meta: {
15
+ count: any;
16
+ };
17
+ skip: any;
18
+ next: boolean;
19
+ };
@@ -0,0 +1,124 @@
1
+ export const LOCALSTORAGE_SYNCED_KEY: "cozy-client-pouch-link-synced";
2
+ export const LOCALSTORAGE_WARMUPEDQUERIES_KEY: "cozy-client-pouch-link-warmupedqueries";
3
+ export const LOCALSTORAGE_LASTSEQUENCES_KEY: "cozy-client-pouch-link-lastreplicationsequence";
4
+ export const LOCALSTORAGE_LASTREPLICATEDDOCID_KEY: "cozy-client-pouch-link-lastreplicateddocid";
5
+ export const LOCALSTORAGE_ADAPTERNAME: "cozy-client-pouch-link-adaptername";
6
+ export class PouchLocalStorage {
7
+ constructor(storageEngine: any);
8
+ storageEngine: any;
9
+ /**
10
+ * Persist the last replicated doc id for a doctype
11
+ *
12
+ * @param {string} doctype - The replicated doctype
13
+ * @param {string} id - The docid
14
+ *
15
+ * @returns {Promise<void>}
16
+ */
17
+ persistLastReplicatedDocID(doctype: string, id: string): Promise<void>;
18
+ /**
19
+ * @returns {Promise<Record<string, string>>}
20
+ */
21
+ getAllLastReplicatedDocID(): Promise<Record<string, string>>;
22
+ /**
23
+ * Get the last replicated doc id for a doctype
24
+ *
25
+ * @param {string} doctype - The doctype
26
+ * @returns {Promise<string>} The last replicated docid
27
+ */
28
+ getLastReplicatedDocID(doctype: string): Promise<string>;
29
+ /**
30
+ * Destroy all the replicated doc id
31
+ *
32
+ * @returns {Promise<void>}
33
+ */
34
+ destroyAllLastReplicatedDocID(): Promise<void>;
35
+ /**
36
+ * Persist the synchronized doctypes
37
+ *
38
+ * @param {Record<string, import("./types").SyncInfo>} syncedDoctypes - The sync doctypes
39
+ *
40
+ * @returns {Promise<void>}
41
+ */
42
+ persistSyncedDoctypes(syncedDoctypes: Record<string, import("./types").SyncInfo>): Promise<void>;
43
+ /**
44
+ * Get the persisted doctypes
45
+ *
46
+ * @returns {Promise<object>} The synced doctypes
47
+ */
48
+ getPersistedSyncedDoctypes(): Promise<object>;
49
+ /**
50
+ * Destroy the synced doctypes
51
+ *
52
+ * @returns {Promise<void>}
53
+ */
54
+ destroySyncedDoctypes(): Promise<void>;
55
+ /**
56
+ * Persist the last CouchDB sequence for a synced doctype
57
+ *
58
+ * @param {string} doctype - The synced doctype
59
+ * @param {string} sequence - The sequence hash
60
+ *
61
+ * @returns {Promise<void>}
62
+ */
63
+ persistDoctypeLastSequence(doctype: string, sequence: string): Promise<void>;
64
+ /**
65
+ * @returns {Promise<object>}
66
+ */
67
+ getAllLastSequences(): Promise<object>;
68
+ /**
69
+ * Get the last CouchDB sequence for a doctype
70
+ *
71
+ * @param {string} doctype - The doctype
72
+ *
73
+ * @returns {Promise<string>} the last sequence
74
+ */
75
+ getDoctypeLastSequence(doctype: string): Promise<string>;
76
+ /**
77
+ * Destroy all the last sequence
78
+ *
79
+ * @returns {Promise<void>}
80
+ */
81
+ destroyAllDoctypeLastSequence(): Promise<void>;
82
+ /**
83
+ * Destroy the last sequence for a doctype
84
+ *
85
+ * @param {string} doctype - The doctype
86
+ *
87
+ * @returns {Promise<void>}
88
+ */
89
+ destroyDoctypeLastSequence(doctype: string): Promise<void>;
90
+ /**
91
+ * Persist the warmed up queries
92
+ *
93
+ * @param {object} warmedUpQueries - The warmedup queries
94
+ *
95
+ * @returns {Promise<void>}
96
+ */
97
+ persistWarmedUpQueries(warmedUpQueries: object): Promise<void>;
98
+ /**
99
+ * Get the warmed up queries
100
+ *
101
+ * @returns {Promise<object>} the warmed up queries
102
+ */
103
+ getPersistedWarmedUpQueries(): Promise<object>;
104
+ /**
105
+ * Destroy the warmed queries
106
+ *
107
+ * @returns {Promise<void>}
108
+ */
109
+ destroyWarmedUpQueries(): Promise<void>;
110
+ /**
111
+ * Get the adapter name
112
+ *
113
+ * @returns {Promise<string>} The adapter name
114
+ */
115
+ getAdapterName(): Promise<string>;
116
+ /**
117
+ * Persist the adapter name
118
+ *
119
+ * @param {string} adapter - The adapter name
120
+ *
121
+ * @returns {Promise<void>}
122
+ */
123
+ persistAdapterName(adapter: string): Promise<void>;
124
+ }
@@ -0,0 +1,2 @@
1
+ export default logger;
2
+ declare const logger: any;
@@ -0,0 +1,60 @@
1
+ export default Loop;
2
+ /**
3
+ * Utility to call a function (task) periodically
4
+ * and on demand immediately.
5
+ *
6
+ * Public API
7
+ *
8
+ * - start
9
+ * - stop
10
+ * - scheduleImmediateTask
11
+ * - waitForCurrentTask
12
+ */
13
+ declare class Loop {
14
+ constructor(task: any, delay: any, _afterRound: any, _sleep: any);
15
+ task: any;
16
+ delay: any;
17
+ /**
18
+ * Runs immediate tasks and then schedule the next round.
19
+ * Immediate tasks are called sequentially without delay
20
+ * There is a delay between immediate tasks and normal periodic tasks.
21
+ */
22
+ round(): Promise<void>;
23
+ immediateTasks: any[];
24
+ started: boolean;
25
+ afterRound: any;
26
+ sleep: any;
27
+ /**
28
+ * Starts the loop. Will run the task periodically each `this.delay` ms.
29
+ * Ignores multiple starts.
30
+ */
31
+ start(): void;
32
+ /**
33
+ * Stops the loop, clears immediate tasks.
34
+ * Cancels current task if possible
35
+ */
36
+ stop(): void;
37
+ waitForCurrent(): Promise<void>;
38
+ /**
39
+ * Flushes the immediate tasks list and calls each task.
40
+ * Each task is awaited before the next is started.
41
+ */
42
+ runImmediateTasks(): Promise<void>;
43
+ /**
44
+ * Schedules a task to be run immediately at next round.
45
+ * Ignored if loop is not started.
46
+ * If not task is passed, the default task from the loop is used.
47
+ *
48
+ * @param {Function} task - Optional custom function to be run immediately
49
+ */
50
+ scheduleImmediateTask(task?: Function): Promise<void>;
51
+ clearImmediateTasks(): void;
52
+ /**
53
+ * Calls and saves current task.
54
+ * Stops loop in case of error of the task.
55
+ */
56
+ runTask(task: any): Promise<void>;
57
+ currentTask: any;
58
+ _rounding: boolean;
59
+ timeout: NodeJS.Timeout;
60
+ }
@@ -0,0 +1,3 @@
1
+ export function makeKeyFromPartialFilter(condition: object): string;
2
+ export function getIndexNameFromFields(fields: Array<string>, partialFilter?: object): string;
3
+ export function getIndexFields({ selector, sort, partialFilter }: import('./types').MangoQueryOptions): string[];
@@ -0,0 +1,18 @@
1
+ export function migratePouch({ dbName, fromAdapter, toAdapter }: MigrationParams): Promise<object>;
2
+ /**
3
+ * Migrate a PouchDB database to a new adapter.
4
+ */
5
+ export type MigrationParams = {
6
+ /**
7
+ * - The database name
8
+ */
9
+ dbName?: string;
10
+ /**
11
+ * - The current adapter type, e.g. 'idb'
12
+ */
13
+ fromAdapter?: string;
14
+ /**
15
+ * - The new adapter type, e.g. 'indexeddb'
16
+ */
17
+ toAdapter?: string;
18
+ };
@@ -0,0 +1,17 @@
1
+ export namespace platformWeb {
2
+ export { storage };
3
+ export { events };
4
+ export { PouchDB as pouchAdapter };
5
+ export { isOnline };
6
+ }
7
+ declare namespace storage {
8
+ function getItem(key: any): Promise<string>;
9
+ function setItem(key: any, value: any): Promise<void>;
10
+ function removeItem(key: any): Promise<void>;
11
+ }
12
+ declare namespace events {
13
+ function addEventListener(eventName: any, handler: any): void;
14
+ function removeEventListener(eventName: any, handler: any): void;
15
+ }
16
+ declare function isOnline(): Promise<boolean>;
17
+ export {};
@@ -0,0 +1,6 @@
1
+ export const DATABASE_NOT_FOUND_ERROR: "Database does not exist";
2
+ export const DATABASE_RESERVED_DOCTYPE_ERROR: "Reserved doctype";
3
+ export function isDatabaseNotFoundError(error: any): boolean;
4
+ export function isDatabaseUnradableError(error: any): boolean;
5
+ export function fetchRemoteInstance(url: URL, params?: object): Promise<object>;
6
+ export function fetchRemoteLastSequence(baseUrl: string): Promise<string>;
@@ -0,0 +1,29 @@
1
+ export function replicateOnce(pouchManager: import('./PouchManager').default): Promise<any>;
2
+ export type FulfilledPromise = {
3
+ /**
4
+ * - The status of the promise
5
+ */
6
+ status: 'fulfilled';
7
+ /**
8
+ * - The Error rejected by the promise (undefined when fulfilled)
9
+ */
10
+ reason: undefined;
11
+ /**
12
+ * - The resolved value of the promise
13
+ */
14
+ value: any;
15
+ };
16
+ export type RejectedPromise = {
17
+ /**
18
+ * - The status of the promise
19
+ */
20
+ status: 'rejected';
21
+ /**
22
+ * - The Error rejected by the promise
23
+ */
24
+ reason: Error;
25
+ /**
26
+ * - The resolved value of the promise (undefined when rejected)
27
+ */
28
+ value: undefined;
29
+ };