Skip to content

Commit

Permalink
feat: add query result type helpers.
Browse files Browse the repository at this point in the history
  • Loading branch information
thorwebdev committed Nov 23, 2023
1 parent 3bc5723 commit 31eb0ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ export {
} from '@supabase/functions-js'
export * from '@supabase/realtime-js'
export { default as SupabaseClient } from './SupabaseClient'
export type { SupabaseClientOptions } from './lib/types'
export type {
SupabaseClientOptions,
QueryResult,
QueryResultData,
QueryResultError,
} from './lib/types'

/**
* Creates a new Supabase Client.
Expand Down
8 changes: 8 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { GoTrueClient } from '@supabase/gotrue-js'
import { RealtimeClientOptions } from '@supabase/realtime-js'
import { PostgrestError } from '@supabase/postgrest-js'

type GoTrueClientOptions = ConstructorParameters<typeof GoTrueClient>[0]

Expand Down Expand Up @@ -95,3 +96,10 @@ export type GenericSchema = {
Views: Record<string, GenericView>
Functions: Record<string, GenericFunction>
}

/**
* Helper types for query results.
*/
export type QueryResult<T> = T extends PromiseLike<infer U> ? U : never
export type QueryResultData<T> = T extends PromiseLike<{ data: infer U }> ? Exclude<U, null> : never
export type QueryResultError = PostgrestError

0 comments on commit 31eb0ff

Please sign in to comment.