Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type safety to fetchCredentials of PowerSyncBackendConnector in the Typescript examples #358

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions demos/angular-supabase-todolist/src/app/supabase.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
type User
} from '@supabase/supabase-js';
import { environment } from '../environment';
import { type AbstractPowerSyncDatabase, type CrudEntry, UpdateType, PowerSyncBackendConnector } from '@powersync/web';
import { type AbstractPowerSyncDatabase, type CrudEntry, UpdateType, PowerSyncBackendConnector, type PowerSyncCredentials } from '@powersync/web';

/// Postgres Response codes that we cannot recover from by retrying.
const FATAL_RESPONSE_CODES = [
Expand Down Expand Up @@ -65,11 +65,10 @@ export class SupabaseService implements PowerSyncBackendConnector {
}

return {
client: this.supabase,
endpoint: environment.powersyncUrl,
token: session.access_token ?? '',
expiresAt: session.expires_at ? new Date(session.expires_at * 1000) : undefined
};
} satisfies PowerSyncCredentials;
}

authChanges(callback: (event: AuthChangeEvent, session: Session | null) => void) {
Expand Down
6 changes: 2 additions & 4 deletions demos/react-native-supabase-group-chat/src/lib/connector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AbstractPowerSyncDatabase, CrudEntry, PowerSyncBackendConnector, UpdateType } from '@powersync/react-native';
import { AbstractPowerSyncDatabase, CrudEntry, PowerSyncBackendConnector, UpdateType, type PowerSyncCredentials } from '@powersync/react-native';
import type { SupabaseClient } from '@supabase/supabase-js';

import { config } from './config';
Expand Down Expand Up @@ -36,12 +36,10 @@ export class Connector implements PowerSyncBackendConnector {
console.debug('session expires at', session.expires_at);

return {
client: this.supabaseClient,
endpoint: config.powerSyncUrl,
token: session.access_token ?? '',
expiresAt: session.expires_at ? new Date(session.expires_at * 1000) : undefined,
userID: session.user.id
};
} satisfies PowerSyncCredentials;
}

async uploadData(database: AbstractPowerSyncDatabase): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AbstractPowerSyncDatabase, CrudEntry, PowerSyncBackendConnector, UpdateType } from '@powersync/react-native';
import { AbstractPowerSyncDatabase, CrudEntry, PowerSyncBackendConnector, UpdateType, type PowerSyncCredentials } from '@powersync/react-native';

import { SupabaseClient, createClient } from '@supabase/supabase-js';
import { AppConfig } from './AppConfig';
Expand Down Expand Up @@ -58,8 +58,7 @@ export class SupabaseConnector implements PowerSyncBackendConnector {
endpoint: AppConfig.powersyncUrl,
token: session.access_token ?? '',
expiresAt: session.expires_at ? new Date(session.expires_at * 1000) : undefined,
userID: session.user.id
};
} satisfies PowerSyncCredentials;
}

async uploadData(database: AbstractPowerSyncDatabase): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AbstractPowerSyncDatabase, CrudEntry, PowerSyncBackendConnector, UpdateType } from '@powersync/common';
import { type PowerSyncCredentials } from '@powersync/react-native';

import { SupabaseClient, createClient } from '@supabase/supabase-js';
import { AppConfig } from './AppConfig';
Expand Down Expand Up @@ -58,8 +59,7 @@ export class SupabaseConnector implements PowerSyncBackendConnector {
endpoint: AppConfig.powersyncUrl,
token: session.access_token ?? '',
expiresAt: session.expires_at ? new Date(session.expires_at * 1000) : undefined,
userID: session.user.id
};
} satisfies PowerSyncCredentials;
}

async uploadData(database: AbstractPowerSyncDatabase): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
BaseObserver,
CrudEntry,
PowerSyncBackendConnector,
UpdateType
UpdateType,
type PowerSyncCredentials
} from '@powersync/web';

import { Session, SupabaseClient, createClient } from '@supabase/supabase-js';
Expand Down Expand Up @@ -109,7 +110,7 @@ export class SupabaseConnector extends BaseObserver<SupabaseConnectorListener> i
endpoint: this.config.powersyncUrl,
token: session.access_token ?? '',
expiresAt: session.expires_at ? new Date(session.expires_at * 1000) : undefined
};
} satisfies PowerSyncCredentials;
}

async uploadData(database: AbstractPowerSyncDatabase): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
BaseObserver,
CrudEntry,
PowerSyncBackendConnector,
UpdateType
UpdateType,
type PowerSyncCredentials
} from '@powersync/web';

import { Session, SupabaseClient, createClient } from '@supabase/supabase-js';
Expand Down Expand Up @@ -100,7 +101,7 @@ export class SupabaseConnector extends BaseObserver<SupabaseConnectorListener> i
endpoint: this.config.powersyncUrl,
token: session.access_token ?? '',
expiresAt: session.expires_at ? new Date(session.expires_at * 1000) : undefined
};
} satisfies PowerSyncCredentials;
}

async uploadData(database: AbstractPowerSyncDatabase): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
BaseObserver,
CrudEntry,
PowerSyncBackendConnector,
UpdateType
UpdateType,
type PowerSyncCredentials
} from '@powersync/web';

import { Session, SupabaseClient, createClient } from '@supabase/supabase-js';
Expand Down Expand Up @@ -100,7 +101,7 @@ export class SupabaseConnector extends BaseObserver<SupabaseConnectorListener> i
endpoint: this.config.powersyncUrl,
token: session.access_token ?? '',
expiresAt: session.expires_at ? new Date(session.expires_at * 1000) : undefined
};
} satisfies PowerSyncCredentials;
}

async uploadData(database: AbstractPowerSyncDatabase): Promise<void> {
Expand Down