@@ -86,78 +86,17 @@ export class SupabaseConnector extends BaseObserver<SupabaseConnectorListener> i
8686 }
8787
8888 async fetchCredentials ( ) {
89- const {
90- data : { session } ,
91- error
92- } = await this . client . auth . getSession ( ) ;
93-
94- if ( ! session || error ) {
95- throw new Error ( `Could not fetch Supabase credentials: ${ error } ` ) ;
96- }
97-
98- console . debug ( 'session expires at' , session . expires_at ) ;
89+ const response = await fetch ( 'http://localhost:6060/api/auth/token' ) ;
90+ const { token } = await response . json ( ) ;
9991
10092 return {
10193 endpoint : this . config . powersyncUrl ,
102- token : session . access_token ?? ''
94+ token,
10395 } satisfies PowerSyncCredentials ;
10496 }
10597
106- async uploadData ( database : AbstractPowerSyncDatabase ) : Promise < void > {
107- const transaction = await database . getNextCrudTransaction ( ) ;
108-
109- if ( ! transaction ) {
110- return ;
111- }
112-
113- let lastOp : CrudEntry | null = null ;
114- try {
115- // Note: If transactional consistency is important, use database functions
116- // or edge functions to process the entire transaction in a single call.
117- for ( const op of transaction . crud ) {
118- lastOp = op ;
119- const table = this . client . from ( op . table ) ;
120- let result : any ;
121- switch ( op . op ) {
122- case UpdateType . PUT :
123- const record = { ...op . opData , id : op . id } ;
124- result = await table . upsert ( record ) ;
125- break ;
126- case UpdateType . PATCH :
127- result = await table . update ( op . opData ) . eq ( 'id' , op . id ) ;
128- break ;
129- case UpdateType . DELETE :
130- result = await table . delete ( ) . eq ( 'id' , op . id ) ;
131- break ;
132- }
133-
134- if ( result . error ) {
135- console . error ( result . error ) ;
136- result . error . message = `Could not update Supabase. Received error: ${ result . error . message } ` ;
137- throw result . error ;
138- }
139- }
140-
141- await transaction . complete ( ) ;
142- } catch ( ex : any ) {
143- console . debug ( ex ) ;
144- if ( typeof ex . code == 'string' && FATAL_RESPONSE_CODES . some ( ( regex ) => regex . test ( ex . code ) ) ) {
145- /**
146- * Instead of blocking the queue with these errors,
147- * discard the (rest of the) transaction.
148- *
149- * Note that these errors typically indicate a bug in the application.
150- * If protecting against data loss is important, save the failing records
151- * elsewhere instead of discarding, and/or notify the user.
152- */
153- console . error ( 'Data upload error - discarding:' , lastOp , ex ) ;
154- await transaction . complete ( ) ;
155- } else {
156- // Error may be retryable - e.g. network error or temporary server error.
157- // Throwing an error here causes this call to be retried after a delay.
158- throw ex ;
159- }
160- }
98+ async uploadData ( ) : Promise < void > {
99+ throw 'unsupported' ;
161100 }
162101
163102 updateSession ( session : Session | null ) {
0 commit comments