|
1 | 1 | import { expectError, expectType } from 'tsd' |
2 | | -import { PostgrestSingleResponse, SupabaseClient, createClient } from '../../src/index' |
| 2 | +import { |
| 3 | + PostgrestSingleResponse, |
| 4 | + SupabaseClient, |
| 5 | + createClient, |
| 6 | + DatabaseWithoutInternals, |
| 7 | +} from '../../src/index' |
3 | 8 | import { Database, Json } from '../types' |
4 | 9 |
|
5 | 10 | const URL = 'http://localhost:3000' |
@@ -265,3 +270,42 @@ const supabase = createClient<Database>(URL, KEY) |
265 | 270 | // @ts-expect-error should raise error if providing table name not in the schema |
266 | 271 | pg13CustomSchemaClient.from('channels_details') |
267 | 272 | } |
| 273 | + |
| 274 | +// DatabaseWithoutInternals utility type |
| 275 | +{ |
| 276 | + type TestDatabaseWithInternals = { |
| 277 | + __InternalSupabase: { |
| 278 | + PostgrestVersion: '14' |
| 279 | + } |
| 280 | + public: { |
| 281 | + Tables: { |
| 282 | + users: { |
| 283 | + Row: { id: number } |
| 284 | + Insert: { id: number } |
| 285 | + Update: { id?: number } |
| 286 | + Relationships: [] |
| 287 | + } |
| 288 | + } |
| 289 | + Views: { [_ in never]: never } |
| 290 | + Functions: { [_ in never]: never } |
| 291 | + Enums: { [_ in never]: never } |
| 292 | + CompositeTypes: { [_ in never]: never } |
| 293 | + } |
| 294 | + } |
| 295 | + |
| 296 | + type CleanedDatabase = DatabaseWithoutInternals<TestDatabaseWithInternals> |
| 297 | + |
| 298 | + // Should have 'public' schema |
| 299 | + expectType<CleanedDatabase['public']>({} as TestDatabaseWithInternals['public']) |
| 300 | + |
| 301 | + // Should not have '__InternalSupabase' key |
| 302 | + type HasInternalKey = '__InternalSupabase' extends keyof CleanedDatabase ? true : false |
| 303 | + expectType<HasInternalKey>(false) |
| 304 | + |
| 305 | + // Should work with databases that don't have __InternalSupabase |
| 306 | + type PlainDatabase = { |
| 307 | + public: { Tables: {}; Views: {}; Functions: {}; Enums: {}; CompositeTypes: {} } |
| 308 | + } |
| 309 | + type CleanedPlainDatabase = DatabaseWithoutInternals<PlainDatabase> |
| 310 | + expectType<CleanedPlainDatabase>({} as PlainDatabase) |
| 311 | +} |
0 commit comments