@@ -188,14 +188,24 @@ const dataProxy: DataProxyWorker = {
188188 return queryRes
189189 } ,
190190
191- forceSyncPouch : ( ) => {
191+ forceSyncPouch : async (
192+ options : { clean : boolean } = { clean : false }
193+ ) : Promise < void > => {
192194 if ( ! client ) {
193195 throw new Error (
194196 'Client is required to execute a forceSyncPouch, please initialize CozyClient'
195197 )
196198 }
197199 const pouchLink = getPouchLink ( client )
198200 if ( pouchLink ) {
201+ if ( options . clean ) {
202+ await pouchLink . reset ( )
203+ await pouchLink . registerClient ( client ) // because reset also resets the client
204+ await pouchLink . onLogin ( )
205+ } else {
206+ await pouchLink . pouches . waitForCurrentReplications ( )
207+ }
208+
199209 pouchLink . startReplication ( )
200210 }
201211 } ,
@@ -221,7 +231,7 @@ const dataProxy: DataProxyWorker = {
221231 const replicationOptions = { strategy : 'fromRemote' , driveId }
222232 const options = { shouldStartReplication : true }
223233 if ( pouchLink . addDoctype ) {
224- pouchLink . addDoctype ( doctype , replicationOptions , options )
234+ await pouchLink . addDoctype ( doctype , replicationOptions , options )
225235 }
226236 }
227237
@@ -232,15 +242,15 @@ const dataProxy: DataProxyWorker = {
232242 searchEngine . addSharedDrive ( driveId )
233243 } ,
234244
235- removeSharedDrive : ( driveId : string ) => {
245+ removeSharedDrive : async ( driveId : string ) => {
236246 log . debug ( `Worker: Removing shared drive ${ driveId } ` )
237247 if ( ! client ) {
238248 throw new Error ( 'Client is required to remove a shared drive' )
239249 }
240250 const pouchLink = getPouchLink ( client )
241251 if ( pouchLink ) {
242252 const doctype = `${ SHARED_DRIVE_FILE_DOCTYPE } -${ driveId } `
243- pouchLink . removeDoctype ( doctype )
253+ await pouchLink . removeDoctype ( doctype )
244254 }
245255
246256 if ( ! searchEngine ) {
0 commit comments