Skip to content

Commit 5f125ce

Browse files
soedirgoavallete
andauthored
fix: inline GetGenericDatabaseWithOptions (#637)
* fix: inline `GetGenericDatabaseWithOptions` was causing issues when used together with supabase-js & ssr * chore: trigger release * chore: debug preview * chore: target pull_request_target events * chore: use from secrets instead of vars --------- Co-authored-by: avallete <[email protected]>
1 parent a307b34 commit 5f125ce

File tree

4 files changed

+20
-30
lines changed

4 files changed

+20
-30
lines changed

.github/workflows/preview-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
(
3939
github.event_name == 'workflow_dispatch' ||
4040
github.event_name == 'push' ||
41-
(github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'trigger: preview'))
41+
(github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'trigger: preview'))
4242
)
4343
runs-on: ubuntu-latest
4444
outputs:
@@ -94,7 +94,7 @@ jobs:
9494
id: generate-token
9595
uses: actions/create-github-app-token@v1
9696
with:
97-
app-id: ${{ vars.CROSS_REPO_APP_ID }}
97+
app-id: ${{ secrets.CROSS_REPO_APP_ID }}
9898
private-key: ${{ secrets.CROSS_REPO_APP_PRIVATE_KEY }}
9999
owner: supabase
100100
repositories: postgrest-js,supabase-js

src/PostgrestClient.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import PostgrestQueryBuilder from './PostgrestQueryBuilder'
22
import PostgrestFilterBuilder from './PostgrestFilterBuilder'
3-
import { Fetch, GenericSchema, ClientServerOptions, GetGenericDatabaseWithOptions } from './types'
3+
import { Fetch, GenericSchema, ClientServerOptions } from './types'
44

55
/**
66
* PostgREST client.
@@ -14,16 +14,23 @@ import { Fetch, GenericSchema, ClientServerOptions, GetGenericDatabaseWithOption
1414
*/
1515
export default class PostgrestClient<
1616
Database = any,
17-
ClientOptions extends ClientServerOptions = GetGenericDatabaseWithOptions<
18-
Database,
19-
{ PostgrestVersion: '12' }
20-
>['options'],
17+
ClientOptions extends ClientServerOptions = Database extends {
18+
__InternalSupabase: infer I extends ClientServerOptions
19+
}
20+
? I
21+
: {},
2122
SchemaName extends string &
22-
keyof GetGenericDatabaseWithOptions<Database>['db'] = 'public' extends keyof GetGenericDatabaseWithOptions<Database>['db']
23+
keyof Omit<Database, '__InternalSupabase'> = 'public' extends keyof Omit<
24+
Database,
25+
'__InternalSupabase'
26+
>
2327
? 'public'
24-
: string & keyof GetGenericDatabaseWithOptions<Database>['db'],
25-
Schema extends GenericSchema = GetGenericDatabaseWithOptions<Database>['db'][SchemaName] extends GenericSchema
26-
? GetGenericDatabaseWithOptions<Database>['db'][SchemaName]
28+
: string & keyof Omit<Database, '__InternalSupabase'>,
29+
Schema extends GenericSchema = Omit<
30+
Database,
31+
'__InternalSupabase'
32+
>[SchemaName] extends GenericSchema
33+
? Omit<Database, '__InternalSupabase'>[SchemaName]
2734
: any
2835
> {
2936
url: string
@@ -86,7 +93,7 @@ export default class PostgrestClient<
8693
*
8794
* @param schema - The schema to query
8895
*/
89-
schema<DynamicSchema extends string & keyof GetGenericDatabaseWithOptions<Database>['db']>(
96+
schema<DynamicSchema extends string & keyof Omit<Database, '__InternalSupabase'>>(
9097
schema: DynamicSchema
9198
): PostgrestClient<
9299
Database,

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ export type {
2828
PostgrestResponseSuccess,
2929
PostgrestSingleResponse,
3030
PostgrestMaybeSingleResponse,
31-
ClientServerOptions,
32-
GetGenericDatabaseWithOptions,
31+
ClientServerOptions as PostgrestClientOptions,
3332
} from './types'
3433
// https://github.com/supabase/postgrest-js/issues/551
3534
// To be replaced with a helper type that only uses public types

src/types.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,6 @@ export type DatabaseWithOptions<Database, Options extends ClientServerOptions> =
8080
options: Options
8181
}
8282

83-
const INTERNAL_SUPABASE_OPTIONS = '__InternalSupabase'
84-
85-
export type GetGenericDatabaseWithOptions<
86-
Database,
87-
Opts extends ClientServerOptions = { PostgrestVersion: '12' }
88-
> = IsAny<Database> extends true
89-
? DatabaseWithOptions<Database, Opts>
90-
: typeof INTERNAL_SUPABASE_OPTIONS extends keyof Database
91-
? Database[typeof INTERNAL_SUPABASE_OPTIONS] extends ClientServerOptions
92-
? DatabaseWithOptions<
93-
Omit<Database, typeof INTERNAL_SUPABASE_OPTIONS>,
94-
Database[typeof INTERNAL_SUPABASE_OPTIONS]
95-
>
96-
: DatabaseWithOptions<Omit<Database, typeof INTERNAL_SUPABASE_OPTIONS>, Opts>
97-
: DatabaseWithOptions<Database, Opts>
98-
9983
export type MaxAffectedEnabled<PostgrestVersion extends string | undefined> =
10084
PostgrestVersion extends `13${string}` ? true : false
10185

0 commit comments

Comments
 (0)