11import  { 
2+   CollectionConfigurationError , 
23  CollectionIsInErrorStateError , 
34  DuplicateKeySyncError , 
45  NoPendingSyncTransactionCommitError , 
@@ -33,6 +34,7 @@ export class CollectionSyncManager<
3334  private  _events ! : CollectionEventsManager 
3435  private  config ! : CollectionConfig < TOutput ,  TKey ,  TSchema > 
3536  private  id : string 
37+   private  syncMode : `eager` |  `on-demand`
3638
3739  public  preloadPromise : Promise < void >  |  null  =  null 
3840  public  syncCleanupFn : ( ( )  =>  void )  |  null  =  null 
@@ -48,6 +50,7 @@ export class CollectionSyncManager<
4850  constructor ( config : CollectionConfig < TOutput ,  TKey ,  TSchema > ,  id : string )  { 
4951    this . config  =  config 
5052    this . id  =  id 
53+     this . syncMode  =  config . syncMode  ??  `eager` 
5154  } 
5255
5356  setDeps ( deps : { 
@@ -197,6 +200,14 @@ export class CollectionSyncManager<
197200
198201      // Store loadSubset function if provided 
199202      this . syncLoadSubsetFn  =  syncRes ?. loadSubset  ??  null 
203+ 
204+       // Validate: on-demand mode requires a loadSubset function 
205+       if  ( this . syncMode  ===  `on-demand`  &&  ! this . syncLoadSubsetFn )  { 
206+         throw  new  CollectionConfigurationError ( 
207+           `Collection "${ this . id }  " is configured with syncMode "on-demand" but the sync function did not return a loadSubset handler. `  + 
208+             `Either provide a loadSubset handler or use syncMode "eager".` 
209+         ) 
210+       } 
200211    }  catch  ( error )  { 
201212      this . lifecycle . setStatus ( `error` ) 
202213      throw  error 
@@ -292,9 +303,14 @@ export class CollectionSyncManager<
292303   * @param  options Options to control what data is being loaded 
293304   * @returns  If data loading is asynchronous, this method returns a promise that resolves when the data is loaded. 
294305   *          If data loading is synchronous, the data is loaded when the method returns. 
295-    *          Returns undefined if no sync function is configured. 
306+    *          Returns undefined if no sync function is configured or if syncMode is 'eager' . 
296307   */ 
297308  public  loadSubset ( options : LoadSubsetOptions ) : Promise < void >  |  undefined  { 
309+     // Bypass loadSubset when syncMode is 'eager' 
310+     if  ( this . syncMode  ===  `eager` )  { 
311+       return  undefined 
312+     } 
313+ 
298314    if  ( this . syncLoadSubsetFn )  { 
299315      const  result  =  this . syncLoadSubsetFn ( options ) 
300316
0 commit comments