@@ -36,6 +36,12 @@ export interface CreateSyncImplementationOptions extends AdditionalConnectionOpt
3636 subscriptions : SubscribedStream [ ] ;
3737}
3838
39+ export interface InternalSubscriptionAdapter {
40+ firstStatusMatching ( predicate : ( status : SyncStatus ) => any , abort ?: AbortSignal ) : Promise < void > ;
41+ resolveOfflineSyncStatus ( ) : Promise < void > ;
42+ rustSubscriptionsCommand ( payload : any ) : Promise < void > ;
43+ }
44+
3945/**
4046 * @internal
4147 */
@@ -44,9 +50,7 @@ export interface ConnectionManagerOptions {
4450 connector : PowerSyncBackendConnector ,
4551 options : CreateSyncImplementationOptions
4652 ) : Promise < ConnectionManagerSyncImplementationResult > ;
47- firstStatusMatching ( predicate : ( status : SyncStatus ) => any ) : Promise < void > ;
48- resolveOfflineSyncStatus ( ) : Promise < void > ;
49- rustSubscriptionsCommand ( payload : any ) : Promise < void > ;
53+
5054 logger : ILogger ;
5155}
5256
@@ -269,19 +273,19 @@ export class ConnectionManager extends BaseObserver<ConnectionManagerListener> {
269273 await disposer ?.( ) ;
270274 }
271275
272- stream ( name : string , parameters : Record < string , any > | null ) : SyncStream {
276+ stream ( adapter : InternalSubscriptionAdapter , name : string , parameters : Record < string , any > | null ) : SyncStream {
273277 const desc = { name, parameters } satisfies SyncStreamDescription ;
274278
275- const waitForFirstSync = ( ) => {
276- return this . options . firstStatusMatching ( ( s ) => s . statusFor ( desc ) ?. subscription . hasSynced ?? false ) ;
279+ const waitForFirstSync = ( abort ?: AbortSignal ) => {
280+ return adapter . firstStatusMatching ( ( s ) => s . statusFor ( desc ) ?. subscription . hasSynced , abort ) ;
277281 } ;
278282
279283 return {
280284 ...desc ,
281285 subscribe : async ( options ?: SyncStreamSubscribeOptions ) => {
282286 // NOTE: We also run this command if a subscription already exists, because this increases the expiry date
283287 // (relevant if the app is closed before connecting again, where the last subscribe call determines the ttl).
284- await this . options . rustSubscriptionsCommand ( {
288+ await adapter . rustSubscriptionsCommand ( {
285289 subscribe : {
286290 stream : {
287291 name,
@@ -295,7 +299,7 @@ export class ConnectionManager extends BaseObserver<ConnectionManagerListener> {
295299 if ( ! this . syncStreamImplementation ) {
296300 // We're not connected. So, update the offline sync status to reflect the new subscription.
297301 // (With an active iteration, the sync client would include it in its state).
298- await this . options . resolveOfflineSyncStatus ( ) ;
302+ await adapter . resolveOfflineSyncStatus ( ) ;
299303 }
300304
301305 const key = `${ name } |${ JSON . stringify ( parameters ) } ` ;
@@ -314,7 +318,7 @@ export class ConnectionManager extends BaseObserver<ConnectionManagerListener> {
314318 return new SyncStreamSubscriptionHandle ( subscription ) ;
315319 } ,
316320 unsubscribeAll : async ( ) => {
317- await this . options . rustSubscriptionsCommand ( { unsubscribe : { name, params : parameters } } ) ;
321+ await adapter . rustSubscriptionsCommand ( { unsubscribe : { name, params : parameters } } ) ;
318322 this . subscriptionsMayHaveChanged ( ) ;
319323 }
320324 } ;
@@ -337,7 +341,7 @@ class ActiveSubscription {
337341 constructor (
338342 readonly name : string ,
339343 readonly parameters : Record < string , any > | null ,
340- readonly waitForFirstSync : ( ) => Promise < void > ,
344+ readonly waitForFirstSync : ( abort ?: AbortSignal ) => Promise < void > ,
341345 private clearSubscription : ( ) => void
342346 ) { }
343347
@@ -362,8 +366,8 @@ class SyncStreamSubscriptionHandle implements SyncStreamSubscription {
362366 return this . subscription . parameters ;
363367 }
364368
365- waitForFirstSync ( ) : Promise < void > {
366- return this . subscription . waitForFirstSync ( ) ;
369+ waitForFirstSync ( abort ?: AbortSignal ) : Promise < void > {
370+ return this . subscription . waitForFirstSync ( abort ) ;
367371 }
368372
369373 unsubscribe ( ) : void {
0 commit comments