Skip to content

Commit

Permalink
docs: Update types and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ldoppea committed Jul 26, 2024
1 parent c056f77 commit 1ef1168
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/api/cozy-pouch-link/classes/PouchLink.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ CozyLink.constructor

### replicationStatus

**replicationStatus**: `Record`<`string`, `SyncStatus`>
**replicationStatus**: `Record`<`string`, `ReplicationStatus`>

*Defined in*

Expand Down
10 changes: 5 additions & 5 deletions packages/cozy-pouch-link/types/CozyPouchLink.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ export function getReplicationURL(uri: any, token: any, doctype: any): string;
export function isExpiredTokenError(pouchError: any): boolean;
export default PouchLink;
export type CozyClientDocument = any;
export type SyncStatus = "idle" | "replicating";
export type ReplicationStatus = "idle" | "replicating";
/**
* @typedef {import('cozy-client/src/types').CozyClientDocument} CozyClientDocument
*
* @typedef {"idle"|"replicating"} SyncStatus
* @typedef {"idle"|"replicating"} ReplicationStatus
*/
/**
* Link to be passed to a `CozyClient` instance to support CouchDB. It instantiates
Expand Down Expand Up @@ -49,8 +49,8 @@ declare class PouchLink extends CozyLink {
doctypesReplicationOptions: any[];
indexes: {};
storage: PouchLocalStorage;
/** @type {Record<string, SyncStatus>} - Stores replication states per doctype */
replicationStatus: Record<string, SyncStatus>;
/** @type {Record<string, ReplicationStatus>} - Stores replication states per doctype */
replicationStatus: Record<string, ReplicationStatus>;
getReplicationURL(doctype: any): string;
registerClient(client: any): Promise<void>;
client: any;
Expand Down Expand Up @@ -117,7 +117,7 @@ declare class PouchLink extends CozyLink {
*/
public stopReplication(): void;
onSyncError(error: any): Promise<void>;
getSyncInfo(doctype: any): any;
getSyncInfo(doctype: any): import("./types").SyncInfo;
getPouch(doctype: any): any;
supportsOperation(operation: any): boolean;
/**
Expand Down
37 changes: 26 additions & 11 deletions packages/cozy-pouch-link/types/PouchManager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ declare class PouchManager {
events: any;
init(): Promise<void>;
pouches: import("lodash").Dictionary<any>;
syncedDoctypes: any;
/** @type {Record<string, import('./types').SyncInfo>} - Stores synchronization info per doctype */
syncedDoctypes: Record<string, import('./types').SyncInfo>;
warmedUpQueries: any;
getReplicationURL: any;
doctypesReplicationOptions: any;
Expand All @@ -30,8 +31,10 @@ declare class PouchManager {
/** Stop periodic syncing of the pouches */
stopReplicationLoop(): void;
/** Starts replication */
replicateOnce(): Promise<void | import("./types").CancelablePromises>;
replicateOnce(): Promise<any>;
executeQuery: any;
/** @type {import('./types').CancelablePromise[]} - Stores replication promises */
replications: import('./types').CancelablePromise[];
addListeners(): void;
removeListeners(): void;
destroy(): Promise<any[]>;
Expand All @@ -48,19 +51,31 @@ declare class PouchManager {
* immediately
*/
syncImmediately(): void;
/**
* Creating each replication
*
* @type {import('./types').CancelablePromises}
*/
replications: import('./types').CancelablePromises;
handleReplicationError(err: any): void;
cancelCurrentReplications(): void;
waitForCurrentReplications(): Promise<void> | Promise<any[]>;
getPouch(doctype: any): any;
updateSyncInfo(doctype: any): Promise<void>;
getSyncInfo(doctype: any): any;
isSynced(doctype: any): boolean;
/**
* Update the Sync info for the specifed doctype
*
* @param {string} doctype - The doctype to update
* @param {import('./types').SyncStatus} status - The new Sync status for the doctype
*/
updateSyncInfo(doctype: string, status?: import('./types').SyncStatus): Promise<void>;
/**
* Get the Sync info for the specified doctype
*
* @param {string} doctype - The doctype to check
* @returns {import('./types').SyncInfo}
*/
getSyncInfo(doctype: string): import('./types').SyncInfo;
/**
* Get the Sync status for the specified doctype
*
* @param {string} doctype - The doctype to check
* @returns {import('./types').SyncStatus}
*/
getSyncStatus(doctype: string): import('./types').SyncStatus;
clearSyncedDoctypes(): Promise<void>;
warmupQueries(doctype: any, queries: any): Promise<void>;
checkToWarmupDoctype(doctype: any, replicationOptions: any): void;
Expand Down
4 changes: 4 additions & 0 deletions packages/cozy-pouch-link/types/remote.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
export const DATABASE_NOT_FOUND_ERROR: "Database does not exist";
export const DATABASE_RESERVED_DOCTYPE_ERROR: "Reserved doctype";
export function isDatabaseNotFoundError(error: any): boolean;
export function isDatabaseUnradableError(error: any): boolean;
export function fetchRemoteInstance(url: URL, params?: object): Promise<object>;
export function fetchRemoteLastSequence(baseUrl: string): Promise<string>;
29 changes: 29 additions & 0 deletions packages/cozy-pouch-link/types/replicateOnce.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export function replicateOnce(pouchManager: import('./PouchManager').default): Promise<any>;
export type FulfilledPromise = {
/**
* - The status of the promise
*/
status: 'fulfilled';
/**
* - The Error rejected by the promise (undefined when fulfilled)
*/
reason: undefined;
/**
* - The resolved value of the promise
*/
value: any;
};
export type RejectedPromise = {
/**
* - The status of the promise
*/
status: 'rejected';
/**
* - The Error rejected by the promise
*/
reason: Error;
/**
* - The resolved value of the promise (undefined when rejected)
*/
value: undefined;
};
10 changes: 9 additions & 1 deletion packages/cozy-pouch-link/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ export type Cancelable = {
};
export type CancelablePromise = Promise<any> & Cancelable;
export type CancelablePromises = CancelablePromise[] & Cancelable;
export type SyncStatus = "synced" | "not_synced" | "not_complete";
export type SyncInfo = {
Date: string;
/**
* - The date of the last synchronization
*/
date: string;
/**
* - The current synchronization status
*/
status: SyncStatus;
};
export type LocalStorage = {
getItem: (arg0: string) => Promise<string | null>;
Expand Down
1 change: 1 addition & 0 deletions packages/cozy-pouch-link/types/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export function getDatabaseName(prefix: string, doctype: string): string;
export function getPrefix(uri: string): string;
export function formatAggregatedError(aggregatedError: any): any;

0 comments on commit 1ef1168

Please sign in to comment.