@@ -58,7 +58,7 @@ export class SyncClientImpl extends BaseObserver<SyncClientListener> implements
5858 this . openStreamFn = options . streamOpener ?? openHttpStream ;
5959 }
6060
61- protected get bucketStorage ( ) : BucketStorage {
61+ get bucketStorage ( ) : BucketStorage {
6262 return this . options . storage ;
6363 }
6464
@@ -123,9 +123,9 @@ export class SyncClientImpl extends BaseObserver<SyncClientListener> implements
123123 async checkpoint ( customCheckpoint ?: string ) : Promise < CreateCheckpointResponse > {
124124 let targetCheckpoint : string | undefined = customCheckpoint ;
125125 // FIXME, could this be optimized?
126- // If there are no crud items, we set the target to the custom checkpoint or the max op id
127- // We then set the local target to the new checkpoint
128- await this . bucketStorage . handleCrudUploaded ( customCheckpoint ) ;
126+ // We essentially set the target op to the max_id then if there is no crud we set it to the target later
127+ // Don't pass in `customCheckpoint` here, that makes it difficult to test if we applied it later
128+ await this . bucketStorage . handleCrudUploaded ( ) ;
129129 const targetUpdated = await this . bucketStorage . updateLocalTarget ( async ( ) => {
130130 if ( targetCheckpoint ) {
131131 return targetCheckpoint ;
@@ -317,7 +317,7 @@ export class SyncClientImpl extends BaseObserver<SyncClientListener> implements
317317
318318 // Handle various sync line types
319319 if ( `checkpoint` in line ) {
320- this . options . debugMode && console . debug ( `Received checkpoint` , line . checkpoint ) ;
320+ this . options . debugMode && console . debug ( `Received checkpoint` , JSON . stringify ( line , null , '\t' ) ) ;
321321 const bucketsToDelete = new Set < string > ( syncState . bucketMap . keys ( ) ) ;
322322 const newBuckets = new Map < string , BucketDescription > ( ) ;
323323 for ( const checksum of line . checkpoint . buckets ) {
@@ -337,7 +337,8 @@ export class SyncClientImpl extends BaseObserver<SyncClientListener> implements
337337 downloading : true
338338 } ) ;
339339 } else if ( `checkpoint_complete` in line ) {
340- this . options . debugMode && console . debug ( `Received checkpoint complete` , syncState . targetCheckpoint ) ;
340+ this . options . debugMode &&
341+ console . debug ( `Received checkpoint complete` , JSON . stringify ( line , null , '\t' ) , syncState . targetCheckpoint ) ;
341342 const result = await this . applyCheckpoint ( syncState . targetCheckpoint ! ) ;
342343 if ( result . endIteration ) {
343344 return ;
@@ -348,7 +349,12 @@ export class SyncClientImpl extends BaseObserver<SyncClientListener> implements
348349 // Status updated in applyCheckpoint when applied successfully
349350 }
350351 } else if ( `partial_checkpoint_complete` in line ) {
351- this . options . debugMode && console . debug ( `Received partial checkpoint complete` , syncState . targetCheckpoint ) ;
352+ this . options . debugMode &&
353+ console . debug (
354+ `Received partial checkpoint complete` ,
355+ JSON . stringify ( line , null , '\t' ) ,
356+ syncState . targetCheckpoint
357+ ) ;
352358 const priority = line . partial_checkpoint_complete . priority ;
353359 const result = await this . bucketStorage . syncLocalDatabase ( syncState . targetCheckpoint ! , priority ) ;
354360 if ( ! result . checkpointValid ) {
@@ -363,7 +369,8 @@ export class SyncClientImpl extends BaseObserver<SyncClientListener> implements
363369 // We'll keep on downloading, but can report that this priority is synced now.
364370 }
365371 } else if ( `checkpoint_diff` in line ) {
366- this . options . debugMode && console . debug ( `Received checkpoint diff` , syncState . targetCheckpoint ) ;
372+ this . options . debugMode &&
373+ console . debug ( `Received checkpoint diff` , JSON . stringify ( line , null , '\t' ) , syncState . targetCheckpoint ) ;
367374 // TODO: It may be faster to just keep track of the diff, instead of the entire checkpoint
368375 if ( syncState . targetCheckpoint == null ) {
369376 throw new Error ( `Checkpoint diff without previous checkpoint` ) ;
@@ -406,7 +413,7 @@ export class SyncClientImpl extends BaseObserver<SyncClientListener> implements
406413 }
407414 await this . bucketStorage . removeBuckets ( bucketsToDelete ) ;
408415 } else if ( `data` in line ) {
409- this . options . debugMode && console . debug ( `Received data` , line . data ) ;
416+ this . options . debugMode && console . debug ( `Received data` , JSON . stringify ( line , null , '\t' ) ) ;
410417 const { data } = line ;
411418 // Update status to indicate we're downloading data
412419 this . updateSyncStatus ( {
0 commit comments