@@ -14,6 +14,7 @@ import { JSONBig } from '@powersync/service-jsonbig';
1414import { BucketParameterQuerier } from '@powersync/service-sync-rules/src/BucketParameterQuerier.js' ;
1515import { SyncContext } from './SyncContext.js' ;
1616import { getIntersection , hasIntersection } from './util.js' ;
17+ import { SqlBucketDescriptor , SqlBucketDescriptorType } from '@powersync/service-sync-rules/src/SqlBucketDescriptor.js' ;
1718
1819export interface BucketChecksumStateOptions {
1920 syncContext : SyncContext ;
@@ -102,7 +103,9 @@ export class BucketChecksumState {
102103 const { buckets : allBuckets , updatedBuckets } = update ;
103104
104105 /** Set of all buckets in this checkpoint. */
105- const bucketDescriptionMap = new Map ( allBuckets . map ( ( b ) => [ b . bucket , b ] ) ) ;
106+ const bucketDescriptionMap = new Map (
107+ allBuckets . map ( ( b ) => [ b . bucket , this . parameterState . overrideBucketDescription ( b ) ] )
108+ ) ;
106109
107110 if ( bucketDescriptionMap . size > this . context . maxBuckets ) {
108111 throw new ServiceError (
@@ -223,14 +226,27 @@ export class BucketChecksumState {
223226 this . logger . info ( message , { checkpoint : base . checkpoint , user_id : user_id , buckets : allBuckets . length } ) ;
224227 } ;
225228 bucketsToFetch = allBuckets ;
229+ this . parameterState . syncRules . bucketDescriptors ;
230+
231+ const subscriptions : util . SubscribedStream [ ] = [ ] ;
232+ for ( const desc of this . parameterState . syncRules . bucketDescriptors ) {
233+ if ( desc . type == SqlBucketDescriptorType . STREAM && this . parameterState . isSubscribedToStream ( desc ) ) {
234+ subscriptions . push ( {
235+ name : desc . name ,
236+ is_default : desc . subscribedToByDefault
237+ } ) ;
238+ }
239+ }
240+
226241 checkpointLine = {
227242 checkpoint : {
228243 last_op_id : util . internalToExternalOpId ( base . checkpoint ) ,
229244 write_checkpoint : writeCheckpoint ? String ( writeCheckpoint ) : undefined ,
230245 buckets : [ ...checksumMap . values ( ) ] . map ( ( e ) => ( {
231246 ...e ,
232247 ...bucketDescriptionMap . get ( e . bucket ) !
233- } ) )
248+ } ) ) ,
249+ included_subscriptions : subscriptions
234250 }
235251 } satisfies util . StreamingSyncCheckpoint ;
236252 }
@@ -338,6 +354,7 @@ export class BucketParameterState {
338354 public readonly syncParams : RequestParameters ;
339355 private readonly querier : BucketParameterQuerier ;
340356 private readonly staticBuckets : Map < string , BucketDescription > ;
357+ private readonly includeDefaultStreams : boolean ;
341358 private readonly explicitStreamSubscriptions : Record < string , util . StreamSubscription > ;
342359 private readonly logger : Logger ;
343360 private cachedDynamicBuckets : BucketDescription [ ] | null = null ;
@@ -366,11 +383,12 @@ export class BucketParameterState {
366383 explicitStreamSubscriptions [ subscription . stream ] = subscription ;
367384 }
368385 }
386+ this . includeDefaultStreams = subscriptions ?. include_defaults ?? true ;
369387 this . explicitStreamSubscriptions = explicitStreamSubscriptions ;
370388
371389 this . querier = syncRules . getBucketParameterQuerier ( {
372390 globalParameters : this . syncParams ,
373- hasDefaultSubscriptions : subscriptions ?. include_defaults ?? true ,
391+ hasDefaultSubscriptions : this . includeDefaultStreams ,
374392 resolveSubscription ( name ) {
375393 const subscription = explicitStreamSubscriptions [ name ] ;
376394 if ( subscription ) {
@@ -401,6 +419,10 @@ export class BucketParameterState {
401419 }
402420 }
403421
422+ isSubscribedToStream ( desc : SqlBucketDescriptor ) : boolean {
423+ return ( desc . subscribedToByDefault && this . includeDefaultStreams ) || desc . name in this . explicitStreamSubscriptions ;
424+ }
425+
404426 async getCheckpointUpdate ( checkpoint : storage . StorageCheckpointUpdate ) : Promise < CheckpointUpdate > {
405427 const querier = this . querier ;
406428 let update : CheckpointUpdate ;
0 commit comments