Skip to content

Commit b5a7248

Browse files
caseybaggzmandarini
authored andcommitted
chore: improve types for functions and cookies
1 parent bcf502f commit b5a7248

File tree

3 files changed

+36
-71
lines changed

3 files changed

+36
-71
lines changed

src/createBrowserClient.ts

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import {
77
import { VERSION } from "./version";
88
import { isBrowser } from "./utils";
99

10-
import type {
11-
CookieMethodsBrowser,
12-
CookieMethodsBrowserDeprecated,
13-
CookieOptionsWithName,
14-
} from "./types";
10+
import type { CookieMethodsBrowser, CookieOptionsWithName } from "./types";
1511

1612
import { createStorageFromOptions } from "./cookies";
1713

@@ -47,36 +43,11 @@ export function createBrowserClient<
4743
supabaseUrl: string,
4844
supabaseKey: string,
4945
options?: SupabaseClientOptions<SchemaName> & {
50-
cookies?: CookieMethodsBrowser;
51-
cookieOptions?: CookieOptionsWithName;
52-
cookieEncoding?: "raw" | "base64url";
53-
isSingleton?: boolean;
54-
},
55-
): SupabaseClient<Database, SchemaName>;
56-
57-
/**
58-
* @deprecated Please specify `getAll` and `setAll` cookie methods instead of
59-
* the `get`, `set` and `remove`. These will not be supported in the next major
60-
* version.
61-
*/
62-
export function createBrowserClient<
63-
Database = any,
64-
SchemaName extends string &
65-
keyof Omit<Database, "__InternalSupabase"> = "public" extends keyof Omit<
66-
Database,
67-
"__InternalSupabase"
68-
>
69-
? "public"
70-
: string & keyof Omit<Database, "__InternalSupabase">,
71-
>(
72-
supabaseUrl: string,
73-
supabaseKey: string,
74-
options?: SupabaseClientOptions<SchemaName> & {
75-
cookies: CookieMethodsBrowserDeprecated;
46+
cookies: CookieMethodsBrowser;
7647
cookieOptions?: CookieOptionsWithName;
7748
cookieEncoding?: "raw" | "base64url";
7849
isSingleton?: boolean;
79-
},
50+
}
8051
): SupabaseClient<Database, SchemaName>;
8152

8253
export function createBrowserClient<
@@ -92,11 +63,11 @@ export function createBrowserClient<
9263
supabaseUrl: string,
9364
supabaseKey: string,
9465
options?: SupabaseClientOptions<SchemaName> & {
95-
cookies?: CookieMethodsBrowser | CookieMethodsBrowserDeprecated;
66+
cookies?: CookieMethodsBrowser;
9667
cookieOptions?: CookieOptionsWithName;
9768
cookieEncoding?: "raw" | "base64url";
9869
isSingleton?: boolean;
99-
},
70+
}
10071
): SupabaseClient<Database, SchemaName> {
10172
// singleton client is created only if isSingleton is set to true, or if isSingleton is not defined and we detect a browser
10273
const shouldUseSingleton =
@@ -109,7 +80,7 @@ export function createBrowserClient<
10980

11081
if (!supabaseUrl || !supabaseKey) {
11182
throw new Error(
112-
`@supabase/ssr: Your project's URL and API key are required to create a Supabase client!\n\nCheck your Supabase project's API settings to find these values\n\nhttps://supabase.com/dashboard/project/_/settings/api`,
83+
`@supabase/ssr: Your project's URL and API key are required to create a Supabase client!\n\nCheck your Supabase project's API settings to find these values\n\nhttps://supabase.com/dashboard/project/_/settings/api`
11384
);
11485
}
11586

@@ -118,7 +89,7 @@ export function createBrowserClient<
11889
...options,
11990
cookieEncoding: options?.cookieEncoding ?? "base64url",
12091
},
121-
false,
92+
false
12293
);
12394

12495
const client = createClient<Database, SchemaName>(supabaseUrl, supabaseKey, {

src/createServerClient.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,9 @@ import { createStorageFromOptions, applyServerStorage } from "./cookies";
1010
import type {
1111
CookieOptionsWithName,
1212
CookieMethodsServer,
13-
CookieMethodsServerDeprecated,
1413
} from "./types";
1514
import { memoryLocalStorageAdapter } from "./utils/helpers";
1615

17-
/**
18-
* @deprecated Please specify `getAll` and `setAll` cookie methods instead of
19-
* the `get`, `set` and `remove`. These will not be supported in the next major
20-
* version.
21-
*/
22-
export function createServerClient<
23-
Database = any,
24-
SchemaName extends string &
25-
keyof Omit<Database, "__InternalSupabase"> = "public" extends keyof Omit<
26-
Database,
27-
"__InternalSupabase"
28-
>
29-
? "public"
30-
: string & keyof Omit<Database, "__InternalSupabase">,
31-
>(
32-
supabaseUrl: string,
33-
supabaseKey: string,
34-
options: SupabaseClientOptions<SchemaName> & {
35-
cookieOptions?: CookieOptionsWithName;
36-
cookies: CookieMethodsServerDeprecated;
37-
cookieEncoding?: "raw" | "base64url";
38-
},
39-
): SupabaseClient<Database, SchemaName>;
40-
4116
/**
4217
* Creates a Supabase Client for use on the server-side of a server-side
4318
* rendering (SSR) framework.
@@ -132,7 +107,7 @@ export function createServerClient<
132107
supabaseKey: string,
133108
options: SupabaseClientOptions<SchemaName> & {
134109
cookieOptions?: CookieOptionsWithName;
135-
cookies: CookieMethodsServer | CookieMethodsServerDeprecated;
110+
cookies: CookieMethodsServer;
136111
cookieEncoding?: "raw" | "base64url";
137112
},
138113
): SupabaseClient<Database, SchemaName> {

src/types.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ export type SetAllCookies = (
2626
cookies: { name: string; value: string; options: CookieOptions }[],
2727
) => Promise<void> | void;
2828

29-
export type CookieMethodsBrowserDeprecated = {
30-
get: GetCookie;
31-
set: SetCookie;
32-
remove: RemoveCookie;
33-
};
3429

3530
export type CookieMethodsBrowser = {
3631
/**
@@ -44,11 +39,20 @@ export type CookieMethodsBrowser = {
4439

4540
getAll: GetAllCookies;
4641
setAll: SetAllCookies;
47-
};
48-
49-
export type CookieMethodsServerDeprecated = {
50-
get: GetCookie;
42+
/**
43+
* @deprecated Please specify `getAll` methods instead of `get`. This will
44+
* not be supported in the next major version.
45+
*/
46+
get?: GetCookie;
47+
/**
48+
* @deprecated Please specify `setAll` methods instead of `set`. This will
49+
* not be supported in the next major version.
50+
*/
5151
set?: SetCookie;
52+
/**
53+
* @deprecated Please specify `setAll` methods instead of `remove`. This will
54+
* not be supported in the next major version.
55+
*/
5256
remove?: RemoveCookie;
5357
};
5458

@@ -64,4 +68,19 @@ export type CookieMethodsServer = {
6468

6569
getAll: GetAllCookies;
6670
setAll?: SetAllCookies;
71+
/**
72+
* @deprecated Please specify `getAll` methods instead of `get`. This will
73+
* not be supported in the next major version.
74+
*/
75+
get?: GetCookie;
76+
/**
77+
* @deprecated Please specify `setAll` methods instead of `set`. This will
78+
* not be supported in the next major version.
79+
*/
80+
set?: SetCookie;
81+
/**
82+
* @deprecated Please specify `setAll` methods instead of `remove`. This will
83+
* not be supported in the next major version.
84+
*/
85+
remove?: RemoveCookie;
6786
};

0 commit comments

Comments
 (0)