@@ -123,7 +123,9 @@ export interface StreamingSyncImplementationListener extends BaseListener {
123123 * Configurable options to be used when connecting to the PowerSync
124124 * backend instance.
125125 */
126- export interface PowerSyncConnectionOptions extends BaseConnectionOptions , AdditionalConnectionOptions { }
126+ export type PowerSyncConnectionOptions = Omit < InternalConnectionOptions , 'serializedSchema' > ;
127+
128+ export interface InternalConnectionOptions extends BaseConnectionOptions , AdditionalConnectionOptions { }
127129
128130/** @internal */
129131export interface BaseConnectionOptions {
@@ -152,6 +154,11 @@ export interface BaseConnectionOptions {
152154 * These parameters are passed to the sync rules, and will be available under the`user_parameters` object.
153155 */
154156 params ?: Record < string , StreamingSyncRequestParameterType > ;
157+
158+ /**
159+ * The serialized schema - mainly used to forward information about raw tables to the sync client.
160+ */
161+ serializedSchema ?: any ;
155162}
156163
157164/** @internal */
@@ -176,7 +183,7 @@ export interface StreamingSyncImplementation extends BaseObserver<StreamingSyncI
176183 /**
177184 * Connects to the sync service
178185 */
179- connect ( options ?: PowerSyncConnectionOptions ) : Promise < void > ;
186+ connect ( options ?: InternalConnectionOptions ) : Promise < void > ;
180187 /**
181188 * Disconnects from the sync services.
182189 * @throws if not connected or if abort is not controlled internally
@@ -208,7 +215,8 @@ export const DEFAULT_STREAM_CONNECTION_OPTIONS: RequiredPowerSyncConnectionOptio
208215 connectionMethod : SyncStreamConnectionMethod . WEB_SOCKET ,
209216 clientImplementation : DEFAULT_SYNC_CLIENT_IMPLEMENTATION ,
210217 fetchStrategy : FetchStrategy . Buffered ,
211- params : { }
218+ params : { } ,
219+ serializedSchema : undefined
212220} ;
213221
214222// The priority we assume when we receive checkpoint lines where no priority is set.
@@ -621,6 +629,10 @@ The next upload iteration will be delayed.`);
621629 }
622630
623631 private async legacyStreamingSyncIteration ( signal : AbortSignal , resolvedOptions : RequiredPowerSyncConnectionOptions ) {
632+ if ( resolvedOptions . serializedSchema ?. raw_tables != null ) {
633+ this . logger . warn ( 'Raw tables require the Rust-based sync client. The JS client will ignore them.' ) ;
634+ }
635+
624636 this . logger . debug ( 'Streaming sync iteration started' ) ;
625637 this . options . adapter . startSession ( ) ;
626638 let [ req , bucketMap ] = await this . collectLocalBucketState ( ) ;
@@ -714,6 +726,8 @@ The next upload iteration will be delayed.`);
714726
715727 if ( isStreamingSyncCheckpoint ( line ) ) {
716728 targetCheckpoint = line . checkpoint ;
729+ // New checkpoint - existing validated checkpoint is no longer valid
730+ pendingValidatedCheckpoint = null ;
717731 const bucketsToDelete = new Set < string > ( bucketMap . keys ( ) ) ;
718732 const newBuckets = new Map < string , BucketDescription > ( ) ;
719733 for ( const checksum of line . checkpoint . buckets ) {
@@ -735,7 +749,13 @@ The next upload iteration will be delayed.`);
735749 if ( result . endIteration ) {
736750 return ;
737751 } else if ( ! result . applied ) {
752+ // "Could not apply checkpoint due to local data". We need to retry after
753+ // finishing uploads.
738754 pendingValidatedCheckpoint = targetCheckpoint ;
755+ } else {
756+ // Nothing to retry later. This would likely already be null from the last
757+ // checksum or checksum_diff operation, but we make sure.
758+ pendingValidatedCheckpoint = null ;
739759 }
740760 } else if ( isStreamingSyncCheckpointPartiallyComplete ( line ) ) {
741761 const priority = line . partial_checkpoint_complete . priority ;
@@ -771,6 +791,8 @@ The next upload iteration will be delayed.`);
771791 if ( targetCheckpoint == null ) {
772792 throw new Error ( 'Checkpoint diff without previous checkpoint' ) ;
773793 }
794+ // New checkpoint - existing validated checkpoint is no longer valid
795+ pendingValidatedCheckpoint = null ;
774796 const diff = line . checkpoint_diff ;
775797 const newBuckets = new Map < string , BucketChecksum > ( ) ;
776798 for ( const checksum of targetCheckpoint . buckets ) {
@@ -1025,12 +1047,12 @@ The next upload iteration will be delayed.`);
10251047 }
10261048
10271049 try {
1028- await control (
1029- PowerSyncControlCommand . START ,
1030- JSON . stringify ( {
1031- parameters : resolvedOptions . params
1032- } )
1033- ) ;
1050+ const options : any = { parameters : resolvedOptions . params } ;
1051+ if ( resolvedOptions . serializedSchema ) {
1052+ options . schema = resolvedOptions . serializedSchema ;
1053+ }
1054+
1055+ await control ( PowerSyncControlCommand . START , JSON . stringify ( options ) ) ;
10341056
10351057 this . notifyCompletedUploads = ( ) => {
10361058 controlInvocations ?. enqueueData ( { command : PowerSyncControlCommand . NOTIFY_CRUD_UPLOAD_COMPLETED } ) ;
0 commit comments