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

feat: add query result type helpers. #918

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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