|
1 | 1 | import { DataProvider, fetchUtils } from 'ra-core';
|
2 |
| -import postgrestRestProvider from '@raphiniert/ra-data-postgrest'; |
| 2 | +import postgrestRestProvider, { |
| 3 | + IDataProviderConfig, |
| 4 | + defaultPrimaryKeys, |
| 5 | + defaultSchema, |
| 6 | +} from '@raphiniert/ra-data-postgrest'; |
3 | 7 | import { SupabaseClient } from '@supabase/supabase-js';
|
4 | 8 |
|
5 | 9 | /**
|
6 | 10 | * A function that returns a dataProvider for Supabase.
|
7 | 11 | * @param instanceUrl The URL of the Supabase instance
|
8 | 12 | * @param apiKey The API key of the Supabase instance. Prefer the anonymous key.
|
9 | 13 | * @param supabaseClient The Supabase client
|
| 14 | + * @param defaultListOp Optional - The default list filter operator. Defaults to 'eq'. |
| 15 | + * @param primaryKeys Optional - The primary keys of the tables. Defaults to 'id'. |
| 16 | + * @param schema Optional - The custom schema to use. Defaults to none. |
10 | 17 | * @returns A dataProvider for Supabase
|
11 | 18 | */
|
12 | 19 | export const supabaseDataProvider = ({
|
13 | 20 | instanceUrl,
|
14 | 21 | apiKey,
|
15 | 22 | supabaseClient,
|
| 23 | + httpClient = supabaseHttpClient({ apiKey, supabaseClient }), |
| 24 | + defaultListOp = 'eq', |
| 25 | + primaryKeys = defaultPrimaryKeys, |
| 26 | + schema = defaultSchema, |
16 | 27 | }: {
|
17 | 28 | instanceUrl: string;
|
18 | 29 | apiKey: string;
|
19 | 30 | supabaseClient: SupabaseClient;
|
20 |
| -}): DataProvider => |
21 |
| - postgrestRestProvider( |
22 |
| - `${instanceUrl}/rest/v1`, |
23 |
| - supabaseHttpClient({ apiKey, supabaseClient }) |
24 |
| - ); |
| 31 | +} & Partial<Omit<IDataProviderConfig, 'apiUrl'>>): DataProvider => { |
| 32 | + const config: IDataProviderConfig = { |
| 33 | + apiUrl: `${instanceUrl}/rest/v1`, |
| 34 | + httpClient, |
| 35 | + defaultListOp, |
| 36 | + primaryKeys, |
| 37 | + schema, |
| 38 | + }; |
| 39 | + return postgrestRestProvider(config); |
| 40 | +}; |
25 | 41 |
|
26 | 42 | /**
|
27 | 43 | * A function that returns a httpClient for Supabase. It handles the authentication.
|
|
0 commit comments