@@ -7,16 +7,18 @@ import { throttleLeadingTrailing } from '../../../utils/throttle.js';
77import { BucketChecksum , BucketStorageAdapter , Checkpoint } from '../bucket/BucketStorageAdapter.js' ;
88import { CrudEntry } from '../bucket/CrudEntry.js' ;
99import { SyncDataBucket } from '../bucket/SyncDataBucket.js' ;
10- import { AbstractRemote , SyncStreamOptions } from './AbstractRemote.js' ;
10+ import { AbstractRemote , SyncStreamOptions , FetchStrategy } from './AbstractRemote.js' ;
1111import {
1212 BucketRequest ,
13+ StreamingSyncLine ,
1314 StreamingSyncRequestParameterType ,
1415 isStreamingKeepalive ,
1516 isStreamingSyncCheckpoint ,
1617 isStreamingSyncCheckpointComplete ,
1718 isStreamingSyncCheckpointDiff ,
1819 isStreamingSyncData
1920} from './streaming-sync-types.js' ;
21+ import { DataStream } from 'src/utils/DataStream.js' ;
2022
2123export enum LockType {
2224 CRUD = 'crud' ,
@@ -67,7 +69,7 @@ export interface StreamingSyncImplementationListener extends BaseListener {
6769 */
6870export interface PowerSyncConnectionOptions extends BaseConnectionOptions , AdditionalConnectionOptions { }
6971
70- /** @internal */
72+ /** @internal */
7173export interface BaseConnectionOptions {
7274 /**
7375 * The connection method to use when streaming updates from
@@ -76,13 +78,18 @@ export interface BaseConnectionOptions {
7678 */
7779 connectionMethod ?: SyncStreamConnectionMethod ;
7880
81+ /**
82+ * The fetch strategy to use when streaming updates from the PowerSync backend instance.
83+ */
84+ fetchStrategy ?: FetchStrategy ;
85+
7986 /**
8087 * These parameters are passed to the sync rules, and will be available under the`user_parameters` object.
8188 */
8289 params ?: Record < string , StreamingSyncRequestParameterType > ;
8390}
8491
85- /** @internal */
92+ /** @internal */
8693export interface AdditionalConnectionOptions {
8794 /**
8895 * Delay for retrying sync streaming operations
@@ -97,9 +104,8 @@ export interface AdditionalConnectionOptions {
97104 crudUploadThrottleMs ?: number ;
98105}
99106
100-
101107/** @internal */
102- export type RequiredAdditionalConnectionOptions = Required < AdditionalConnectionOptions >
108+ export type RequiredAdditionalConnectionOptions = Required < AdditionalConnectionOptions > ;
103109
104110export interface StreamingSyncImplementation extends BaseObserver < StreamingSyncImplementationListener > , Disposable {
105111 /**
@@ -134,6 +140,7 @@ export type RequiredPowerSyncConnectionOptions = Required<BaseConnectionOptions>
134140
135141export const DEFAULT_STREAM_CONNECTION_OPTIONS : RequiredPowerSyncConnectionOptions = {
136142 connectionMethod : SyncStreamConnectionMethod . WEB_SOCKET ,
143+ fetchStrategy : FetchStrategy . Buffered ,
137144 params : { }
138145} ;
139146
@@ -496,10 +503,15 @@ The next upload iteration will be delayed.`);
496503 }
497504 } ;
498505
499- const stream =
500- resolvedOptions ?. connectionMethod == SyncStreamConnectionMethod . HTTP
501- ? await this . options . remote . postStream ( syncOptions )
502- : await this . options . remote . socketStream ( syncOptions ) ;
506+ let stream : DataStream < StreamingSyncLine > ;
507+ if ( resolvedOptions ?. connectionMethod == SyncStreamConnectionMethod . HTTP ) {
508+ stream = await this . options . remote . postStream ( syncOptions ) ;
509+ } else {
510+ stream = await this . options . remote . socketStream ( {
511+ ...syncOptions ,
512+ ...{ fetchStrategy : resolvedOptions . fetchStrategy }
513+ } ) ;
514+ }
503515
504516 this . logger . debug ( 'Stream established. Processing events' ) ;
505517
0 commit comments