Skip to content

fix: inline GetGenericDatabaseWithOptions #637

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

Merged
merged 5 commits into from
Aug 21, 2025
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/preview-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
(
github.event_name == 'workflow_dispatch' ||
github.event_name == 'push' ||
(github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'trigger: preview'))
(github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'trigger: preview'))
)
runs-on: ubuntu-latest
outputs:
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.CROSS_REPO_APP_ID }}
app-id: ${{ secrets.CROSS_REPO_APP_ID }}
private-key: ${{ secrets.CROSS_REPO_APP_PRIVATE_KEY }}
owner: supabase
repositories: postgrest-js,supabase-js
Expand Down
27 changes: 17 additions & 10 deletions src/PostgrestClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PostgrestQueryBuilder from './PostgrestQueryBuilder'
import PostgrestFilterBuilder from './PostgrestFilterBuilder'
import { Fetch, GenericSchema, ClientServerOptions, GetGenericDatabaseWithOptions } from './types'
import { Fetch, GenericSchema, ClientServerOptions } from './types'

/**
* PostgREST client.
Expand All @@ -14,16 +14,23 @@ import { Fetch, GenericSchema, ClientServerOptions, GetGenericDatabaseWithOption
*/
export default class PostgrestClient<
Database = any,
ClientOptions extends ClientServerOptions = GetGenericDatabaseWithOptions<
Database,
{ PostgrestVersion: '12' }
>['options'],
ClientOptions extends ClientServerOptions = Database extends {
__InternalSupabase: infer I extends ClientServerOptions
}
? I
: {},
SchemaName extends string &
keyof GetGenericDatabaseWithOptions<Database>['db'] = 'public' extends keyof GetGenericDatabaseWithOptions<Database>['db']
keyof Omit<Database, '__InternalSupabase'> = 'public' extends keyof Omit<
Database,
'__InternalSupabase'
>
? 'public'
: string & keyof GetGenericDatabaseWithOptions<Database>['db'],
Schema extends GenericSchema = GetGenericDatabaseWithOptions<Database>['db'][SchemaName] extends GenericSchema
? GetGenericDatabaseWithOptions<Database>['db'][SchemaName]
: string & keyof Omit<Database, '__InternalSupabase'>,
Schema extends GenericSchema = Omit<
Database,
'__InternalSupabase'
>[SchemaName] extends GenericSchema
? Omit<Database, '__InternalSupabase'>[SchemaName]
: any
> {
url: string
Expand Down Expand Up @@ -86,7 +93,7 @@ export default class PostgrestClient<
*
* @param schema - The schema to query
*/
schema<DynamicSchema extends string & keyof GetGenericDatabaseWithOptions<Database>['db']>(
schema<DynamicSchema extends string & keyof Omit<Database, '__InternalSupabase'>>(
schema: DynamicSchema
): PostgrestClient<
Database,
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export type {
PostgrestResponseSuccess,
PostgrestSingleResponse,
PostgrestMaybeSingleResponse,
ClientServerOptions,
GetGenericDatabaseWithOptions,
ClientServerOptions as PostgrestClientOptions,
} from './types'
// https://github.com/supabase/postgrest-js/issues/551
// To be replaced with a helper type that only uses public types
Expand Down
16 changes: 0 additions & 16 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,6 @@ export type DatabaseWithOptions<Database, Options extends ClientServerOptions> =
options: Options
}

const INTERNAL_SUPABASE_OPTIONS = '__InternalSupabase'

export type GetGenericDatabaseWithOptions<
Database,
Opts extends ClientServerOptions = { PostgrestVersion: '12' }
> = IsAny<Database> extends true
? DatabaseWithOptions<Database, Opts>
: typeof INTERNAL_SUPABASE_OPTIONS extends keyof Database
? Database[typeof INTERNAL_SUPABASE_OPTIONS] extends ClientServerOptions
? DatabaseWithOptions<
Omit<Database, typeof INTERNAL_SUPABASE_OPTIONS>,
Database[typeof INTERNAL_SUPABASE_OPTIONS]
>
: DatabaseWithOptions<Omit<Database, typeof INTERNAL_SUPABASE_OPTIONS>, Opts>
: DatabaseWithOptions<Database, Opts>

export type MaxAffectedEnabled<PostgrestVersion extends string | undefined> =
PostgrestVersion extends `13${string}` ? true : false

Expand Down