@@ -114,7 +114,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
114114 super ( ) ;
115115 this . bucketStorageAdapter = this . generateBucketStorageAdapter ( ) ;
116116 this . closed = true ;
117- this . currentStatus = null ;
117+ this . currentStatus = undefined ;
118118 this . options = { ...DEFAULT_POWERSYNC_DB_OPTIONS , ...options } ;
119119 this . _schema = options . schema ;
120120 this . ready = false ;
@@ -201,7 +201,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
201201 try {
202202 schema . validate ( ) ;
203203 } catch ( ex ) {
204- this . options . logger . warn ( 'Schema validation failed. Unexpected behaviour could occur' , ex ) ;
204+ this . options . logger ? .warn ( 'Schema validation failed. Unexpected behaviour could occur' , ex ) ;
205205 }
206206 this . _schema = schema ;
207207 await this . database . execute ( 'SELECT powersync_replace_schema(?)' , [ JSON . stringify ( this . schema . toJSON ( ) ) ] ) ;
@@ -291,7 +291,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
291291 [ tableGlob ]
292292 ) ;
293293
294- if ( ! existingTableRows . rows . length ) {
294+ if ( ! existingTableRows . rows ? .length ) {
295295 return ;
296296 }
297297 for ( const row of existingTableRows . rows . _array ) {
@@ -325,11 +325,11 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
325325 `SELECT SUM(cast(data as blob) + 20) as size, count(*) as count FROM ${ PSInternalTable . CRUD } `
326326 ) ;
327327
328- const row = result . rows . item ( 0 ) ;
328+ const row = result . rows ! . item ( 0 ) ;
329329 return new UploadQueueStats ( row ?. count ?? 0 , row ?. size ?? 0 ) ;
330330 } else {
331331 const result = await tx . execute ( `SELECT count(*) as count FROM ${ PSInternalTable . CRUD } ` ) ;
332- const row = result . rows . item ( 0 ) ;
332+ const row = result . rows ! . item ( 0 ) ;
333333 return new UploadQueueStats ( row ?. count ?? 0 ) ;
334334 }
335335 } ) ;
@@ -388,7 +388,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
388388 * Unlike {@link getCrudBatch}, this only returns data from a single transaction at a time.
389389 * All data for the transaction is loaded into memory.
390390 */
391- async getNextCrudTransaction ( ) : Promise < CrudTransaction > {
391+ async getNextCrudTransaction ( ) : Promise < CrudTransaction | null > {
392392 return await this . readTransaction ( async ( tx ) => {
393393 const first = await tx . getOptional < CrudEntryJSON > (
394394 `SELECT id, tx_id, data FROM ${ PSInternalTable . CRUD } ORDER BY id ASC LIMIT 1`
@@ -543,7 +543,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
543543
544544 const resolvedTables = options ?. tables ?? [ ] ;
545545 if ( ! options ?. tables ) {
546- const explained = await this . getAll ( `EXPLAIN ${ sql } ` , parameters ) ;
546+ const explained = await this . getAll < { opcode : string ; p3 : number ; p2 : number } > ( `EXPLAIN ${ sql } ` , parameters ) ;
547547 const rootPages = _ . chain ( explained )
548548 . filter ( ( row ) => row [ 'opcode' ] == 'OpenRead' && row [ 'p3' ] == 0 && _ . isNumber ( row [ 'p2' ] ) )
549549 . map ( ( row ) => row [ 'p2' ] )
@@ -571,10 +571,11 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
571571 * Note, do not declare this as `async *onChange` as it will not work in React Native
572572 */
573573 onChange ( options ?: SQLWatchOptions ) : AsyncIterable < WatchOnChangeEvent > {
574- const watchedTables = options . tables ?? [ ] ;
574+ const resolvedOptions = options ?? { } ;
575+ const watchedTables = resolvedOptions . tables ?? [ ] ;
575576
576577 let throttledTableUpdates : string [ ] = [ ] ;
577- const throttleMs = options . throttleMs ?? DEFAULT_WATCH_THROTTLE_MS ;
578+ const throttleMs = resolvedOptions . throttleMs ?? DEFAULT_WATCH_THROTTLE_MS ;
578579
579580 return new EventIterator < WatchOnChangeEvent > ( ( eventOptions ) => {
580581 const flushTableUpdates = _ . throttle (
@@ -593,7 +594,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
593594
594595 const dispose = this . database . registerListener ( {
595596 tablesUpdated : async ( update ) => {
596- const { rawTableNames } = options ;
597+ const { rawTableNames } = resolvedOptions ;
597598
598599 const tables = isBatchedUpdateNotification ( update ) ? update . tables : [ update . table ] ;
599600
@@ -613,7 +614,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
613614 }
614615 } ) ;
615616
616- options . signal ?. addEventListener ( 'abort' , ( ) => {
617+ resolvedOptions . signal ?. addEventListener ( 'abort' , ( ) => {
617618 dispose ( ) ;
618619 eventOptions . stop ( ) ;
619620 // Maybe fail?
@@ -626,7 +627,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
626627 /**
627628 * @ignore
628629 */
629- private async executeReadOnly ( sql : string , params : any [ ] ) {
630+ private async executeReadOnly ( sql : string , params ? : any [ ] ) {
630631 await this . waitForReady ( ) ;
631632 return this . database . readLock ( ( tx ) => tx . execute ( sql , params ) ) ;
632633 }
0 commit comments