From 6c2e676217f004a20ebb309346a5ed7cc2f8fd4f Mon Sep 17 00:00:00 2001 From: Div Arora Date: Tue, 1 Mar 2022 08:15:23 +0800 Subject: [PATCH] feat: support throwing errors by default --- package-lock.json | 6 +++--- package.json | 2 +- src/SupabaseClient.ts | 7 ++++++- src/lib/SupabaseQueryBuilder.ts | 4 +++- src/lib/types.ts | 7 ++++++- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index eca22cfa..fb661d65 100644 --- a/package-lock.json +++ b/package-lock.json @@ -764,9 +764,9 @@ } }, "@supabase/postgrest-js": { - "version": "0.36.2", - "resolved": "https://registry.npmjs.org/@supabase/postgrest-js/-/postgrest-js-0.36.2.tgz", - "integrity": "sha512-ZKQT+5ISWdsiSPDoVLnt/fiY82fUFw3lYLc2aMhx5tS3Zj6cChsWlK7NxH6ZZzo9Re/Pa/h4EoOzDZiDPywqxQ==", + "version": "0.37.0", + "resolved": "https://registry.npmjs.org/@supabase/postgrest-js/-/postgrest-js-0.37.0.tgz", + "integrity": "sha512-fkQqKV1mMols2YqnUcwhHL88ZJWo19lvvoV7cgKfW7eksMZyEXp6merP6v5OlmYOxsUla6nRzZJ6zGd8xmaokQ==", "requires": { "cross-fetch": "^3.0.6" } diff --git a/package.json b/package.json index 66f1b6f7..c3eb8e6a 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@supabase/gotrue-js": "^1.22.3", - "@supabase/postgrest-js": "^0.36.2", + "@supabase/postgrest-js": "^0.37.0", "@supabase/realtime-js": "^1.3.6", "@supabase/storage-js": "^1.6.4" }, diff --git a/src/SupabaseClient.ts b/src/SupabaseClient.ts index 410f58f3..2d65f778 100644 --- a/src/SupabaseClient.ts +++ b/src/SupabaseClient.ts @@ -5,7 +5,7 @@ import { SupabaseAuthClient } from './lib/SupabaseAuthClient' import { SupabaseQueryBuilder } from './lib/SupabaseQueryBuilder' import { SupabaseStorageClient } from '@supabase/storage-js' import { PostgrestClient } from '@supabase/postgrest-js' -import { AuthChangeEvent, Session, Subscription } from '@supabase/gotrue-js' +import { AuthChangeEvent } from '@supabase/gotrue-js' import { RealtimeClient, RealtimeSubscription, RealtimeClientOptions } from '@supabase/realtime-js' const DEFAULT_OPTIONS = { @@ -37,6 +37,8 @@ export default class SupabaseClient { protected multiTab: boolean protected fetch?: Fetch protected changedAccessToken: string | undefined + protected shouldThrowOnError: boolean + protected headers: { [key: string]: string } @@ -73,6 +75,7 @@ export default class SupabaseClient { this.multiTab = settings.multiTab this.fetch = settings.fetch this.headers = { ...DEFAULT_HEADERS, ...options?.headers } + this.shouldThrowOnError = settings.shouldThrowOnError || false this.auth = this._initSupabaseAuthClient(settings) this.realtime = this._initRealtimeClient({ headers: this.headers, ...settings.realtime }) @@ -106,6 +109,7 @@ export default class SupabaseClient { realtime: this.realtime, table, fetch: this.fetch, + shouldThrowOnError: this.shouldThrowOnError, }) } @@ -235,6 +239,7 @@ export default class SupabaseClient { headers: this._getAuthHeaders(), schema: this.schema, fetch: this.fetch, + throwOnError: this.shouldThrowOnError, }) } diff --git a/src/lib/SupabaseQueryBuilder.ts b/src/lib/SupabaseQueryBuilder.ts index cb65d14c..bdf24b9c 100644 --- a/src/lib/SupabaseQueryBuilder.ts +++ b/src/lib/SupabaseQueryBuilder.ts @@ -18,15 +18,17 @@ export class SupabaseQueryBuilder extends PostgrestQueryBuilder { realtime, table, fetch, + shouldThrowOnError, }: { headers?: GenericObject schema: string realtime: RealtimeClient table: string fetch?: Fetch + shouldThrowOnError?: boolean } ) { - super(url, { headers, schema, fetch }) + super(url, { headers, schema, fetch, shouldThrowOnError }) this._realtime = realtime this._headers = headers diff --git a/src/lib/types.ts b/src/lib/types.ts index ba15dab5..aac8002b 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -3,7 +3,7 @@ import { RealtimeClientOptions } from '@supabase/realtime-js' type GoTrueClientOptions = ConstructorParameters[0] -export interface SupabaseAuthClientOptions extends GoTrueClientOptions {} +export interface SupabaseAuthClientOptions extends GoTrueClientOptions { } export type GenericObject = { [key: string]: string } @@ -44,6 +44,11 @@ export type SupabaseClientOptions = { * A custom `fetch` implementation. */ fetch?: Fetch + + /** + * Throw errors, instead of returning them. + */ + shouldThrowOnError?: boolean } export type SupabaseRealtimePayload = {