Skip to content

Commit 2921150

Browse files
committed
feat: Improve CozyLink typing and add reset() method
In the Flagship app, we want to be able to reset the local PouchDB files in order to prevent beta testers to be blocked by an erroneous Pouch replication To make this possible we want to expose a public method that resets all the cozy-client's links
1 parent d1aee07 commit 2921150

7 files changed

Lines changed: 51 additions & 9 deletions

File tree

packages/cozy-client/src/CozyLink.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,37 @@ export default class CozyLink {
99
}
1010
}
1111

12-
request(operation, result, forward) {
12+
/**
13+
* Request the given operation from the link
14+
*
15+
* @param {any} operation - The operation to request
16+
* @param {any} result - The result from the previous request of the chain
17+
* @param {any} forward - The next request of the chain
18+
* @returns {Promise<any>}
19+
*/
20+
async request(operation, result, forward) {
1321
throw new Error('request is not implemented')
1422
}
1523

16-
persistCozyData(data, forward) {
24+
/**
25+
* Persist the given data into the links storage
26+
*
27+
* @param {any} data - The document to persist
28+
* @param {any} forward - The next persistCozyData of the chain
29+
* @returns {Promise<any>}
30+
*/
31+
async persistCozyData(data, forward) {
1732
throw new Error('persistCozyData is not implemented')
1833
}
34+
35+
/**
36+
* Reset the link data
37+
*
38+
* @returns {Promise<any>}
39+
*/
40+
async reset() {
41+
throw new Error('reset is not implemented')
42+
}
1943
}
2044

2145
const toLink = handler =>

packages/cozy-client/src/FlagshipLink.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class FlagshipLink extends CozyLink {
1414
// does nothing, we don't need any client for this kind of link
1515
}
1616

17-
reset() {
17+
async reset() {
1818
// does nothing, we don't need any client for this kind of link
1919
}
2020

packages/cozy-client/src/StackLink.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default class StackLink extends CozyLink {
8080
this.stackClient = client.stackClient || client.client
8181
}
8282

83-
reset() {
83+
async reset() {
8484
this.stackClient = null
8585
}
8686

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
export default class CozyLink {
22
constructor(requestHandler: any, persistHandler: any);
3-
request(operation: any, result: any, forward: any): void;
4-
persistCozyData(data: any, forward: any): void;
3+
/**
4+
* Request the given operation from the link
5+
*
6+
* @param {any} operation - The operation to request
7+
* @param {any} result - The result from the previous request of the chain
8+
* @param {any} forward - The next request of the chain
9+
* @returns {Promise<any>}
10+
*/
11+
request(operation: any, result: any, forward: any): Promise<any>;
12+
/**
13+
* Persist the given data into the links storage
14+
*
15+
* @param {any} data - The document to persist
16+
* @param {any} forward - The next persistCozyData of the chain
17+
* @returns {Promise<any>}
18+
*/
19+
persistCozyData(data: any, forward: any): Promise<any>;
20+
/**
21+
* Reset the link data
22+
*
23+
* @returns {Promise<any>}
24+
*/
25+
reset(): Promise<any>;
526
}
627
export function chain(links: any): any;

packages/cozy-client/types/FlagshipLink.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ export default class FlagshipLink extends CozyLink {
88
});
99
webviewIntent: import("cozy-intent").WebviewService;
1010
registerClient(client: any): void;
11-
reset(): void;
1211
}
1312
import CozyLink from "./CozyLink";

packages/cozy-client/types/StackLink.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export default class StackLink extends CozyLink {
1818
stackClient: any;
1919
isOnline: any;
2020
registerClient(client: any): void;
21-
reset(): void;
2221
/**
2322
*
2423
* @param {QueryDefinition} query - Query to execute

packages/cozy-pouch-link/types/CozyPouchLink.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ declare class PouchLink extends CozyLink {
9696
}): Promise<void>;
9797
onLogin(): Promise<void>;
9898
pouches: PouchManager;
99-
reset(): Promise<void>;
10099
/**
101100
* Receives PouchDB updates (documents grouped by doctype).
102101
* Normalizes the data (.id -> ._id, .rev -> _rev).

0 commit comments

Comments
 (0)