-
-
Notifications
You must be signed in to change notification settings - Fork 396
fix(types): export type utils for ssr use #1491
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
Open
avallete
wants to merge
5
commits into
next
Choose a base branch
from
fix/export-type-utils-for-ssr-use
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d63063e
fix(types): export utils types for ssr uses
avallete 4928724
fix(types): export CreateClientHelper and GenericSupabaseClient types
avallete 9c51cee
test: add type testing for ssr package in next
avallete 21e55ed
chore: skip ssr types testing until new release
avallete 5ce8a59
chore: add some more tests
avallete File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { Metadata } from 'next' | ||
|
||
export const metadata: Metadata = { | ||
title: 'Supabase Integration Test', | ||
description: 'Testing Supabase integration with Next.js', | ||
} | ||
|
||
export default function RootLayout({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<html lang="en"> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
import { expectType } from 'tsd' | ||
import { createServerClient, createBrowserClient } from '@supabase/ssr' | ||
|
||
type Database = { | ||
public: { | ||
Tables: { | ||
shops: { | ||
Row: { | ||
address: string | null | ||
id: number | ||
shop_geom: unknown | null | ||
} | ||
Insert: { | ||
address?: string | null | ||
id: number | ||
shop_geom?: unknown | null | ||
} | ||
Update: { | ||
address?: string | null | ||
id?: number | ||
shop_geom?: unknown | null | ||
} | ||
Relationships: [] | ||
} | ||
} | ||
Views: { | ||
[_ in never]: never | ||
} | ||
Functions: { | ||
[_ in never]: never | ||
} | ||
Enums: { | ||
[_ in never]: never | ||
} | ||
CompositeTypes: { | ||
[_ in never]: never | ||
} | ||
} | ||
} | ||
|
||
type DatabaseWithInternals = { | ||
__InternalSupabase: { | ||
PostgrestVersion: '13' | ||
} | ||
public: { | ||
Tables: { | ||
shops: { | ||
Row: { | ||
address: string | null | ||
id: number | ||
shop_geom: unknown | null | ||
} | ||
Insert: { | ||
address?: string | null | ||
id: number | ||
shop_geom?: unknown | null | ||
} | ||
Update: { | ||
address?: string | null | ||
id?: number | ||
shop_geom?: unknown | null | ||
} | ||
Relationships: [] | ||
} | ||
} | ||
Views: { | ||
[_ in never]: never | ||
} | ||
Functions: { | ||
[_ in never]: never | ||
} | ||
Enums: { | ||
[_ in never]: never | ||
} | ||
CompositeTypes: { | ||
[_ in never]: never | ||
} | ||
} | ||
} | ||
|
||
{ | ||
// createBrowserClient should be able discriminate postgrest version | ||
const pg13Client = createBrowserClient<DatabaseWithInternals>('HTTP://localhost:3000', '') | ||
const pg12Client = createBrowserClient<Database>('HTTP://localhost:3000', '') | ||
const res13 = await pg13Client.from('shops').update({ id: 21 }).maxAffected(1) | ||
const res12 = await pg12Client.from('shops').update({ id: 21 }).maxAffected(1) | ||
expectType<typeof res13.data>(null) | ||
expectType<typeof res12.Error>('maxAffected method only available on postgrest 13+') | ||
} | ||
|
||
{ | ||
// createBrowserClient should return a typed client | ||
const pg12Client = createBrowserClient<Database>('HTTP://localhost:3000', '') | ||
const res12 = await pg12Client.from('shops').select('*') | ||
expectType< | ||
| { | ||
address: string | null | ||
id: number | ||
shop_geom: unknown | null | ||
}[] | ||
| null | ||
>(res12.data) | ||
} | ||
|
||
{ | ||
// createBrowserClient should infer everything to any without types provided | ||
const pg12Client = createBrowserClient('HTTP://localhost:3000', '') | ||
const res12 = await pg12Client.from('shops').select('address, id, relation(field)') | ||
expectType< | ||
| { | ||
address: any | ||
id: any | ||
relation: { | ||
field: any | ||
}[] | ||
}[] | ||
| null | ||
>(res12.data) | ||
} | ||
|
||
{ | ||
// createServerClient should be able discriminate postgrest version | ||
const pg13Client = createServerClient<DatabaseWithInternals>('HTTP://localhost:3000', '') | ||
const pg12Client = createServerClient<Database>('HTTP://localhost:3000', '') | ||
const res13 = await pg13Client.from('shops').update({ id: 21 }).maxAffected(1) | ||
const res12 = await pg12Client.from('shops').update({ id: 21 }).maxAffected(1) | ||
expectType<typeof res13.data>(null) | ||
expectType<typeof res12.Error>('maxAffected method only available on postgrest 13+') | ||
} | ||
|
||
{ | ||
// createServerClient should return a typed client | ||
const pg12Client = createServerClient<Database>('HTTP://localhost:3000', '') | ||
const res12 = await pg12Client.from('shops').select('*') | ||
expectType< | ||
| { | ||
address: string | null | ||
id: number | ||
shop_geom: unknown | null | ||
}[] | ||
| null | ||
>(res12.data) | ||
} | ||
|
||
{ | ||
// createServerClient should infer everything to any without types provided | ||
const pg12Client = createServerClient('HTTP://localhost:3000', '') | ||
const res12 = await pg12Client.from('shops').select('address, id, relation(field)') | ||
expectType< | ||
| { | ||
address: any | ||
id: any | ||
relation: { | ||
field: any | ||
}[] | ||
}[] | ||
| null | ||
>(res12.data) | ||
} | ||
|
||
// should default to postgrest 12 for untyped client | ||
{ | ||
const pg12ServerClient = createServerClient('HTTP://localhost:3000', '') | ||
const res12Server = await pg12ServerClient.from('shops').update({ id: 21 }).maxAffected(1) | ||
const pg12BrowserClient = createBrowserClient('HTTP://localhost:3000', '') | ||
const res12Browser = await pg12BrowserClient.from('shops').update({ id: 21 }).maxAffected(1) | ||
expectType<typeof res12Server.Error>('maxAffected method only available on postgrest 13+') | ||
expectType<typeof res12Browser.Error>('maxAffected method only available on postgrest 13+') | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
introduce basics typing tests for the
@supabase/ssr
context. Since it depends ofsupabase-js
as peer deps, it'll help detect uncaught breaking change that would break compatibility betweenssr
andsupabase-js
previous verison.