@@ -291,15 +291,38 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
291291 protected async initialize ( ) {
292292 await this . _initialize ( ) ;
293293 await this . bucketStorageAdapter . init ( ) ;
294- const version = await this . database . execute ( 'SELECT powersync_rs_version()' ) ;
295- this . sdkVersion = version . rows ?. item ( 0 ) [ 'powersync_rs_version()' ] ?? '' ;
294+ await this . _loadVersion ( ) ;
296295 await this . updateSchema ( this . options . schema ) ;
297296 await this . updateHasSynced ( ) ;
298297 await this . database . execute ( 'PRAGMA RECURSIVE_TRIGGERS=TRUE' ) ;
299298 this . ready = true ;
300299 this . iterateListeners ( ( cb ) => cb . initialized ?.( ) ) ;
301300 }
302301
302+ private async _loadVersion ( ) {
303+ try {
304+ const { version } = await this . database . get < { version : string } > ( 'SELECT powersync_rs_version() as version' ) ;
305+ this . sdkVersion = version ;
306+ } catch ( e ) {
307+ throw new Error ( `The powersync extension is not loaded correctly. Details: ${ e . message } ` ) ;
308+ }
309+ let versionInts : number [ ] ;
310+ try {
311+ versionInts = this . sdkVersion ! . split ( / [ . \/ ] / )
312+ . slice ( 0 , 3 )
313+ . map ( ( n ) => parseInt ( n ) ) ;
314+ } catch ( e ) {
315+ throw new Error (
316+ `Unsupported powersync extension version. Need ^0.2.0, got: ${ this . sdkVersion } . Details: ${ e . message } `
317+ ) ;
318+ }
319+
320+ // Validate ^0.2.0
321+ if ( versionInts [ 0 ] != 0 || versionInts [ 1 ] != 2 || versionInts [ 2 ] < 0 ) {
322+ throw new Error ( `Unsupported powersync extension version. Need ^0.2.0, got: ${ this . sdkVersion } ` ) ;
323+ }
324+ }
325+
303326 protected async updateHasSynced ( ) {
304327 const result = await this . database . get < { synced_at : string | null } > (
305328 'SELECT powersync_last_synced_at() as synced_at'
0 commit comments