@@ -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.
@@ -708,6 +716,8 @@ The next upload iteration will be delayed.`);
708716
709717 if ( isStreamingSyncCheckpoint ( line ) ) {
710718 targetCheckpoint = line . checkpoint ;
719+ // New checkpoint - existing validated checkpoint is no longer valid
720+ pendingValidatedCheckpoint = null ;
711721 const bucketsToDelete = new Set < string > ( bucketMap . keys ( ) ) ;
712722 const newBuckets = new Map < string , BucketDescription > ( ) ;
713723 for ( const checksum of line . checkpoint . buckets ) {
@@ -729,7 +739,13 @@ The next upload iteration will be delayed.`);
729739 if ( result . endIteration ) {
730740 return ;
731741 } else if ( ! result . applied ) {
742+ // "Could not apply checkpoint due to local data". We need to retry after
743+ // finishing uploads.
732744 pendingValidatedCheckpoint = targetCheckpoint ;
745+ } else {
746+ // Nothing to retry later. This would likely already be null from the last
747+ // checksum or checksum_diff operation, but we make sure.
748+ pendingValidatedCheckpoint = null ;
733749 }
734750 } else if ( isStreamingSyncCheckpointPartiallyComplete ( line ) ) {
735751 const priority = line . partial_checkpoint_complete . priority ;
@@ -765,6 +781,8 @@ The next upload iteration will be delayed.`);
765781 if ( targetCheckpoint == null ) {
766782 throw new Error ( 'Checkpoint diff without previous checkpoint' ) ;
767783 }
784+ // New checkpoint - existing validated checkpoint is no longer valid
785+ pendingValidatedCheckpoint = null ;
768786 const diff = line . checkpoint_diff ;
769787 const newBuckets = new Map < string , BucketChecksum > ( ) ;
770788 for ( const checksum of targetCheckpoint . buckets ) {
@@ -1019,12 +1037,12 @@ The next upload iteration will be delayed.`);
10191037 }
10201038
10211039 try {
1022- await control (
1023- PowerSyncControlCommand . START ,
1024- JSON . stringify ( {
1025- parameters : resolvedOptions . params
1026- } )
1027- ) ;
1040+ const options : any = { parameters : resolvedOptions . params } ;
1041+ if ( resolvedOptions . serializedSchema ) {
1042+ options . schema = resolvedOptions . serializedSchema ;
1043+ }
1044+
1045+ await control ( PowerSyncControlCommand . START , JSON . stringify ( options ) ) ;
10281046
10291047 this . notifyCompletedUploads = ( ) => {
10301048 controlInvocations ?. enqueueData ( { command : PowerSyncControlCommand . NOTIFY_CRUD_UPLOAD_COMPLETED } ) ;
0 commit comments