Skip to content

Commit

Permalink
feat: Improve CozyLink typing and add reset() method
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ldoppea committed Sep 23, 2024
1 parent 09c2314 commit 2c06aea
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
28 changes: 26 additions & 2 deletions packages/cozy-client/src/CozyLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,37 @@ export default class CozyLink {
}
}

request(operation, result, forward) {
/**
* Request the given operation from the link
*
* @param {any} operation - The operation to request
* @param {any} result - The result from the previous request of the chain
* @param {any} forward - The next request of the chain
* @returns {Promise<any>}
*/
async request(operation, result, forward) {
throw new Error('request is not implemented')
}

persistCozyData(data, forward) {
/**
* Persist the given data into the links storage
*
* @param {any} data - The document to persist
* @param {any} forward - The next persistCozyData of the chain
* @returns {Promise<any>}
*/
async persistCozyData(data, forward) {
throw new Error('persistCozyData is not implemented')
}

/**
* Reset the link data
*
* @returns {Promise<any>}
*/
async reset() {
throw new Error('reset is not implemented')
}
}

const toLink = handler =>
Expand Down
2 changes: 1 addition & 1 deletion packages/cozy-client/src/FlagshipLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class FlagshipLink extends CozyLink {
// does nothing, we don't need any client for this kind of link
}

reset() {
async reset() {
// does nothing, we don't need any client for this kind of link
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cozy-client/src/StackLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class StackLink extends CozyLink {
this.stackClient = client.stackClient || client.client
}

reset() {
async reset() {
this.stackClient = null
}

Expand Down

0 comments on commit 2c06aea

Please sign in to comment.