From c376d72fe7e9e08ef945da8a0fd1402261ca122e Mon Sep 17 00:00:00 2001 From: Ldoppea Date: Tue, 16 Jul 2024 17:30:28 +0200 Subject: [PATCH] docs: Update types and documentation --- docs/api/cozy-pouch-link/classes/PouchLink.md | 103 +++++++------ .../cozy-pouch-link/types/CozyPouchLink.d.ts | 14 +- .../cozy-pouch-link/types/PouchManager.d.ts | 15 +- .../cozy-pouch-link/types/localStorage.d.ts | 142 +++++++++++++++--- .../cozy-pouch-link/types/platformWeb.d.ts | 17 +++ .../types/startReplication.d.ts | 4 +- packages/cozy-pouch-link/types/types.d.ts | 22 +++ 7 files changed, 241 insertions(+), 76 deletions(-) create mode 100644 packages/cozy-pouch-link/types/platformWeb.d.ts diff --git a/docs/api/cozy-pouch-link/classes/PouchLink.md b/docs/api/cozy-pouch-link/classes/PouchLink.md index 4a112f365..a396a9c90 100644 --- a/docs/api/cozy-pouch-link/classes/PouchLink.md +++ b/docs/api/cozy-pouch-link/classes/PouchLink.md @@ -27,6 +27,7 @@ constructor - Initializes a new PouchLink | `opts` | `Object` | - | | `opts.doctypes` | `string`\[] | Doctypes to replicate | | `opts.doctypesReplicationOptions` | `any`\[] | 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") | +| `opts.platform` | `LinkPlatform` | Platform specific adapters and methods | | `opts.replicationInterval` | `number` | - | *Overrides* @@ -35,7 +36,7 @@ CozyLink.constructor *Defined in* -[CozyPouchLink.js:84](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L84) +[CozyPouchLink.js:81](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L81) ## Properties @@ -45,7 +46,7 @@ CozyLink.constructor *Defined in* -[CozyPouchLink.js:132](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L132) +[CozyPouchLink.js:134](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L134) *** @@ -55,7 +56,7 @@ CozyLink.constructor *Defined in* -[CozyPouchLink.js:94](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L94) +[CozyPouchLink.js:91](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L91) *** @@ -65,7 +66,7 @@ CozyLink.constructor *Defined in* -[CozyPouchLink.js:95](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L95) +[CozyPouchLink.js:92](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L92) *** @@ -75,17 +76,17 @@ CozyLink.constructor *Defined in* -[CozyPouchLink.js:96](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L96) +[CozyPouchLink.js:93](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L93) *** ### options -• **options**: { `replicationInterval`: `number` } & { `doctypes`: `string`\[] ; `doctypesReplicationOptions`: `any`\[] ; `replicationInterval`: `number` } +• **options**: { `replicationInterval`: `number` } & { `doctypes`: `string`\[] ; `doctypesReplicationOptions`: `any`\[] ; `platform`: `LinkPlatform` ; `replicationInterval`: `number` } *Defined in* -[CozyPouchLink.js:88](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L88) +[CozyPouchLink.js:85](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L85) *** @@ -95,7 +96,7 @@ CozyLink.constructor *Defined in* -[CozyPouchLink.js:202](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L202) +[CozyPouchLink.js:204](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L204) *** @@ -107,6 +108,16 @@ CozyLink.constructor [CozyPouchLink.js:99](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L99) +*** + +### storage + +• **storage**: `PouchLocalStorage` + +*Defined in* + +[CozyPouchLink.js:94](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L94) + ## Methods ### addReferencesTo @@ -125,7 +136,7 @@ CozyLink.constructor *Defined in* -[CozyPouchLink.js:563](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L563) +[CozyPouchLink.js:567](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L567) *** @@ -145,7 +156,7 @@ CozyLink.constructor *Defined in* -[CozyPouchLink.js:524](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L524) +[CozyPouchLink.js:528](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L528) *** @@ -166,7 +177,7 @@ CozyLink.constructor *Defined in* -[CozyPouchLink.js:567](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L567) +[CozyPouchLink.js:571](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L571) *** @@ -186,7 +197,7 @@ CozyLink.constructor *Defined in* -[CozyPouchLink.js:552](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L552) +[CozyPouchLink.js:556](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L556) *** @@ -207,7 +218,7 @@ CozyLink.constructor *Defined in* -[CozyPouchLink.js:423](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L423) +[CozyPouchLink.js:427](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L427) *** @@ -229,7 +240,7 @@ CozyLink.constructor *Defined in* -[CozyPouchLink.js:495](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L495) +[CozyPouchLink.js:499](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L499) *** @@ -249,7 +260,7 @@ CozyLink.constructor *Defined in* -[CozyPouchLink.js:441](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L441) +[CozyPouchLink.js:445](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L445) *** @@ -269,7 +280,7 @@ CozyLink.constructor *Defined in* -[CozyPouchLink.js:317](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L317) +[CozyPouchLink.js:321](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L321) *** @@ -289,7 +300,7 @@ CozyLink.constructor *Defined in* -[CozyPouchLink.js:112](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L112) +[CozyPouchLink.js:114](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L114) *** @@ -309,7 +320,7 @@ CozyLink.constructor *Defined in* -[CozyPouchLink.js:313](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L313) +[CozyPouchLink.js:317](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L317) *** @@ -329,7 +340,7 @@ CozyLink.constructor *Defined in* -[CozyPouchLink.js:254](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L254) +[CozyPouchLink.js:258](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L258) *** @@ -349,7 +360,7 @@ CozyLink.constructor *Defined in* -[CozyPouchLink.js:249](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L249) +[CozyPouchLink.js:253](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L253) *** @@ -375,7 +386,7 @@ Emits an event (pouchlink:sync:end) when the sync (all doctypes) is done *Defined in* -[CozyPouchLink.js:235](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L235) +[CozyPouchLink.js:239](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L239) *** @@ -395,7 +406,7 @@ Emits an event (pouchlink:sync:end) when the sync (all doctypes) is done *Defined in* -[CozyPouchLink.js:405](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L405) +[CozyPouchLink.js:409](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L409) *** @@ -416,7 +427,7 @@ Emits an event (pouchlink:sync:end) when the sync (all doctypes) is done *Defined in* -[CozyPouchLink.js:410](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L410) +[CozyPouchLink.js:414](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L414) *** @@ -446,13 +457,13 @@ Migrate the current adapter *Defined in* -[CozyPouchLink.js:146](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L146) +[CozyPouchLink.js:148](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L148) *** ### needsToWaitWarmup -▸ **needsToWaitWarmup**(`doctype`): `boolean` +▸ **needsToWaitWarmup**(`doctype`): `Promise`<`boolean`> Check if there is warmup queries for this doctype and return if those queries are already warmed up or not @@ -465,13 +476,13 @@ and return if those queries are already warmed up or not *Returns* -`boolean` +`Promise`<`boolean`> the need to wait for the warmup *Defined in* -[CozyPouchLink.js:391](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L391) +[CozyPouchLink.js:395](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L395) *** @@ -485,7 +496,7 @@ the need to wait for the warmup *Defined in* -[CozyPouchLink.js:165](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L165) +[CozyPouchLink.js:167](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L167) *** @@ -505,7 +516,7 @@ the need to wait for the warmup *Defined in* -[CozyPouchLink.js:293](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L293) +[CozyPouchLink.js:297](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L297) *** @@ -525,13 +536,13 @@ the need to wait for the warmup *Defined in* -[CozyPouchLink.js:131](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L131) +[CozyPouchLink.js:133](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L133) *** ### request -▸ **request**(`operation`, `result?`, `forward?`): `void` | `Promise`<`any`> +▸ **request**(`operation`, `result?`, `forward?`): `Promise`<`any`> *Parameters* @@ -543,7 +554,7 @@ the need to wait for the warmup *Returns* -`void` | `Promise`<`any`> +`Promise`<`any`> *Overrides* @@ -551,7 +562,7 @@ CozyLink.request *Defined in* -[CozyPouchLink.js:336](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L336) +[CozyPouchLink.js:340](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L340) *** @@ -565,7 +576,7 @@ CozyLink.request *Defined in* -[CozyPouchLink.js:219](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L219) +[CozyPouchLink.js:223](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L223) *** @@ -584,7 +595,7 @@ Emits pouchlink:sync:start event when the replication begins *Defined in* -[CozyPouchLink.js:268](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L268) +[CozyPouchLink.js:272](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L272) *** @@ -603,7 +614,7 @@ Emits pouchlink:sync:stop event *Defined in* -[CozyPouchLink.js:285](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L285) +[CozyPouchLink.js:289](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L289) *** @@ -623,7 +634,7 @@ Emits pouchlink:sync:stop event *Defined in* -[CozyPouchLink.js:321](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L321) +[CozyPouchLink.js:325](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L325) *** @@ -637,7 +648,7 @@ Emits pouchlink:sync:stop event *Defined in* -[CozyPouchLink.js:589](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L589) +[CozyPouchLink.js:593](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L593) *** @@ -657,7 +668,7 @@ Emits pouchlink:sync:stop event *Defined in* -[CozyPouchLink.js:529](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L529) +[CozyPouchLink.js:533](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L533) *** @@ -677,23 +688,29 @@ Emits pouchlink:sync:stop event *Defined in* -[CozyPouchLink.js:534](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L534) +[CozyPouchLink.js:538](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L538) *** ### getPouchAdapterName -▸ `Static` **getPouchAdapterName**(): `string` +▸ `Static` **getPouchAdapterName**(`localStorage`): `Promise`<`string`> Return the PouchDB adapter name. Should be IndexedDB for newest adapters. +*Parameters* + +| Name | Type | Description | +| :------ | :------ | :------ | +| `localStorage` | `LocalStorage` | Methods to access local storage | + *Returns* -`string` +`Promise`<`string`> The adapter name *Defined in* -[CozyPouchLink.js:108](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L108) +[CozyPouchLink.js:109](https://github.com/cozy/cozy-client/blob/master/packages/cozy-pouch-link/src/CozyPouchLink.js#L109) diff --git a/packages/cozy-pouch-link/types/CozyPouchLink.d.ts b/packages/cozy-pouch-link/types/CozyPouchLink.d.ts index 2bbfe5e6c..127c172b6 100644 --- a/packages/cozy-pouch-link/types/CozyPouchLink.d.ts +++ b/packages/cozy-pouch-link/types/CozyPouchLink.d.ts @@ -15,9 +15,10 @@ declare class PouchLink extends CozyLink { * Return the PouchDB adapter name. * Should be IndexedDB for newest adapters. * - * @returns {string} The adapter name + * @param {import('./types').LocalStorage} localStorage Methods to access local storage + * @returns {Promise} The adapter name */ - static getPouchAdapterName: () => string; + static getPouchAdapterName: (localStorage: import('./types').LocalStorage) => Promise; /** * constructor - Initializes a new PouchLink * @@ -25,11 +26,13 @@ declare class PouchLink extends CozyLink { * @param {number} [opts.replicationInterval] Milliseconds between replications * @param {string[]} opts.doctypes Doctypes to replicate * @param {object[]} opts.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") + * @param {import('./types').LinkPlatform} opts.platform Platform specific adapters and methods */ constructor(opts?: { replicationInterval: number; doctypes: string[]; doctypesReplicationOptions: object[]; + platform: import('./types').LinkPlatform; }); options: { replicationInterval: number; @@ -37,10 +40,12 @@ declare class PouchLink extends CozyLink { replicationInterval?: number; doctypes: string[]; doctypesReplicationOptions: object[]; + platform: import('./types').LinkPlatform; }; doctypes: string[]; doctypesReplicationOptions: any[]; indexes: {}; + storage: PouchLocalStorage; /** @type {Record} - Stores replication states per doctype */ replicationStatus: Record; getReplicationURL(doctype: any): string; @@ -118,9 +123,9 @@ declare class PouchLink extends CozyLink { * and return if those queries are already warmed up or not * * @param {string} doctype - Doctype to check - * @returns {boolean} the need to wait for the warmup + * @returns {Promise} the need to wait for the warmup */ - needsToWaitWarmup(doctype: string): boolean; + needsToWaitWarmup(doctype: string): Promise; hasIndex(name: any): boolean; mergePartialIndexInSelector(selector: any, partialFilter: any): any; ensureIndex(doctype: any, query: any): Promise; @@ -158,4 +163,5 @@ declare class PouchLink extends CozyLink { syncImmediately(): Promise; } import { CozyLink } from "cozy-client"; +import { PouchLocalStorage } from "./localStorage"; import PouchManager from "./PouchManager"; diff --git a/packages/cozy-pouch-link/types/PouchManager.d.ts b/packages/cozy-pouch-link/types/PouchManager.d.ts index a3919c36a..cbb07a737 100644 --- a/packages/cozy-pouch-link/types/PouchManager.d.ts +++ b/packages/cozy-pouch-link/types/PouchManager.d.ts @@ -8,6 +8,12 @@ export default PouchManager; declare class PouchManager { constructor(doctypes: any, options: any); options: any; + doctypes: any; + storage: PouchLocalStorage; + PouchDB: any; + isOnline: any; + events: any; + init(): Promise; pouches: import("lodash").Dictionary; syncedDoctypes: any; warmedUpQueries: any; @@ -52,13 +58,14 @@ declare class PouchManager { cancelCurrentReplications(): void; waitForCurrentReplications(): Promise | Promise; getPouch(doctype: any): any; - updateSyncInfo(doctype: any): void; + updateSyncInfo(doctype: any): Promise; getSyncInfo(doctype: any): any; isSynced(doctype: any): boolean; - clearSyncedDoctypes(): void; + clearSyncedDoctypes(): Promise; warmupQueries(doctype: any, queries: any): Promise; checkToWarmupDoctype(doctype: any, replicationOptions: any): void; - areQueriesWarmedUp(doctype: any, queries: any): any; - clearWarmedUpQueries(): void; + areQueriesWarmedUp(doctype: any, queries: any): Promise; + clearWarmedUpQueries(): Promise; } +import { PouchLocalStorage } from "./localStorage"; import Loop from "./loop"; diff --git a/packages/cozy-pouch-link/types/localStorage.d.ts b/packages/cozy-pouch-link/types/localStorage.d.ts index b3295b9c4..c60f0f36b 100644 --- a/packages/cozy-pouch-link/types/localStorage.d.ts +++ b/packages/cozy-pouch-link/types/localStorage.d.ts @@ -3,26 +3,122 @@ export const LOCALSTORAGE_WARMUPEDQUERIES_KEY: "cozy-client-pouch-link-warmupedq export const LOCALSTORAGE_LASTSEQUENCES_KEY: "cozy-client-pouch-link-lastreplicationsequence"; export const LOCALSTORAGE_LASTREPLICATEDDOCID_KEY: "cozy-client-pouch-link-lastreplicateddocid"; export const LOCALSTORAGE_ADAPTERNAME: "cozy-client-pouch-link-adaptername"; -export function persistLastReplicatedDocID(doctype: string, id: string): void; -export function getAllLastReplicatedDocID(): any; -export function getLastReplicatedDocID(doctype: string): string; -export function destroyAllLastReplicatedDocID(): void; -export function persistSyncedDoctypes(syncedDoctypes: Record): void; -export function getPersistedSyncedDoctypes(): object; -export function destroySyncedDoctypes(): void; -export function persistDoctypeLastSequence(doctype: string, sequence: string): void; -export function getAllLastSequences(): any; -export function getDoctypeLastSequence(doctype: string): string; -export function destroyAllDoctypeLastSequence(): void; -export function destroyDoctypeLastSequence(doctype: string): void; -export function persistWarmedUpQueries(warmedUpQueries: object): void; -export function getPersistedWarmedUpQueries(): object; -export function destroyWarmedUpQueries(): void; -export function getAdapterName(): string; -export function persistAdapterName(adapter: string): void; -/** - * Persist the synchronized doctypes - */ -export type SyncInfo = { - Date: string; -}; +export class PouchLocalStorage { + constructor(storageEngine: any); + storageEngine: any; + /** + * Persist the last replicated doc id for a doctype + * + * @param {string} doctype - The replicated doctype + * @param {string} id - The docid + * + * @returns {Promise} + */ + persistLastReplicatedDocID(doctype: string, id: string): Promise; + /** + * @returns {Promise>} + */ + getAllLastReplicatedDocID(): Promise>; + /** + * Get the last replicated doc id for a doctype + * + * @param {string} doctype - The doctype + * @returns {Promise} The last replicated docid + */ + getLastReplicatedDocID(doctype: string): Promise; + /** + * Destroy all the replicated doc id + * + * @returns {Promise} + */ + destroyAllLastReplicatedDocID(): Promise; + /** + * Persist the synchronized doctypes + * + * @param {Record} syncedDoctypes - The sync doctypes + * + * @returns {Promise} + */ + persistSyncedDoctypes(syncedDoctypes: Record): Promise; + /** + * Get the persisted doctypes + * + * @returns {Promise} The synced doctypes + */ + getPersistedSyncedDoctypes(): Promise; + /** + * Destroy the synced doctypes + * + * @returns {Promise} + */ + destroySyncedDoctypes(): Promise; + /** + * Persist the last CouchDB sequence for a synced doctype + * + * @param {string} doctype - The synced doctype + * @param {string} sequence - The sequence hash + * + * @returns {Promise} + */ + persistDoctypeLastSequence(doctype: string, sequence: string): Promise; + /** + * @returns {Promise} + */ + getAllLastSequences(): Promise; + /** + * Get the last CouchDB sequence for a doctype + * + * @param {string} doctype - The doctype + * + * @returns {Promise} the last sequence + */ + getDoctypeLastSequence(doctype: string): Promise; + /** + * Destroy all the last sequence + * + * @returns {Promise} + */ + destroyAllDoctypeLastSequence(): Promise; + /** + * Destroy the last sequence for a doctype + * + * @param {string} doctype - The doctype + * + * @returns {Promise} + */ + destroyDoctypeLastSequence(doctype: string): Promise; + /** + * Persist the warmed up queries + * + * @param {object} warmedUpQueries - The warmedup queries + * + * @returns {Promise} + */ + persistWarmedUpQueries(warmedUpQueries: object): Promise; + /** + * Get the warmed up queries + * + * @returns {Promise} the warmed up queries + */ + getPersistedWarmedUpQueries(): Promise; + /** + * Destroy the warmed queries + * + * @returns {Promise} + */ + destroyWarmedUpQueries(): Promise; + /** + * Get the adapter name + * + * @returns {Promise} The adapter name + */ + getAdapterName(): Promise; + /** + * Persist the adapter name + * + * @param {string} adapter - The adapter name + * + * @returns {Promise} + */ + persistAdapterName(adapter: string): Promise; +} diff --git a/packages/cozy-pouch-link/types/platformWeb.d.ts b/packages/cozy-pouch-link/types/platformWeb.d.ts new file mode 100644 index 000000000..9b8b8fdf7 --- /dev/null +++ b/packages/cozy-pouch-link/types/platformWeb.d.ts @@ -0,0 +1,17 @@ +export namespace platformWeb { + export { storage }; + export { events }; + export { PouchDB as pouchAdapter }; + export { isOnline }; +} +declare namespace storage { + function getItem(key: any): Promise; + function setItem(key: any, value: any): Promise; + function removeItem(key: any): Promise; +} +declare namespace events { + function addEventListener(eventName: any, handler: any): void; + function removeEventListener(eventName: any, handler: any): void; +} +declare function isOnline(): Promise; +export {}; diff --git a/packages/cozy-pouch-link/types/startReplication.d.ts b/packages/cozy-pouch-link/types/startReplication.d.ts index c820925f8..44ff8eb07 100644 --- a/packages/cozy-pouch-link/types/startReplication.d.ts +++ b/packages/cozy-pouch-link/types/startReplication.d.ts @@ -3,5 +3,5 @@ export function startReplication(pouch: object, replicationOptions: { initialReplication: boolean; doctype: string; warmupQueries: import('cozy-client/types/types').Query[]; -}, getReplicationURL: Function): import('./types').CancelablePromise; -export function replicateAllDocs(db: object, baseUrl: string, doctype: string): Promise; +}, getReplicationURL: Function, storage: import('./localStorage').PouchLocalStorage): import('./types').CancelablePromise; +export function replicateAllDocs(db: object, baseUrl: string, doctype: string, storage: import('./localStorage').PouchLocalStorage): Promise; diff --git a/packages/cozy-pouch-link/types/types.d.ts b/packages/cozy-pouch-link/types/types.d.ts index d38702d60..2cb24b393 100644 --- a/packages/cozy-pouch-link/types/types.d.ts +++ b/packages/cozy-pouch-link/types/types.d.ts @@ -8,3 +8,25 @@ export type Cancelable = { }; export type CancelablePromise = Promise & Cancelable; export type CancelablePromises = CancelablePromise[] & Cancelable; +export type SyncInfo = { + Date: string; +}; +export type LocalStorage = { + getItem: (arg0: string) => Promise; + setItem: (arg0: string, arg1: string) => Promise; + removeItem: (arg0: string) => Promise; +}; +export type LinkPlatform = { + /** + * Methods to access local storage + */ + storage: LocalStorage; + /** + * PouchDB class (can be pouchdb-core or pouchdb-browser) + */ + pouchAdapter: any; + /** + * Method that check if the app is connected to internet + */ + isOnline: () => Promise; +};