From b5a7248c2440bd79b9217c52e8441e0d4b931a8e Mon Sep 17 00:00:00 2001 From: caseybaggz Date: Wed, 26 Nov 2025 15:55:01 +0200 Subject: [PATCH] chore: improve types for functions and cookies --- src/createBrowserClient.ts | 43 +++++++------------------------------- src/createServerClient.ts | 27 +----------------------- src/types.ts | 37 ++++++++++++++++++++++++-------- 3 files changed, 36 insertions(+), 71 deletions(-) diff --git a/src/createBrowserClient.ts b/src/createBrowserClient.ts index 6608381..eeda0a7 100644 --- a/src/createBrowserClient.ts +++ b/src/createBrowserClient.ts @@ -7,11 +7,7 @@ import { import { VERSION } from "./version"; import { isBrowser } from "./utils"; -import type { - CookieMethodsBrowser, - CookieMethodsBrowserDeprecated, - CookieOptionsWithName, -} from "./types"; +import type { CookieMethodsBrowser, CookieOptionsWithName } from "./types"; import { createStorageFromOptions } from "./cookies"; @@ -47,36 +43,11 @@ export function createBrowserClient< supabaseUrl: string, supabaseKey: string, options?: SupabaseClientOptions & { - cookies?: CookieMethodsBrowser; - cookieOptions?: CookieOptionsWithName; - cookieEncoding?: "raw" | "base64url"; - isSingleton?: boolean; - }, -): SupabaseClient; - -/** - * @deprecated Please specify `getAll` and `setAll` cookie methods instead of - * the `get`, `set` and `remove`. These will not be supported in the next major - * version. - */ -export function createBrowserClient< - Database = any, - SchemaName extends string & - keyof Omit = "public" extends keyof Omit< - Database, - "__InternalSupabase" - > - ? "public" - : string & keyof Omit, ->( - supabaseUrl: string, - supabaseKey: string, - options?: SupabaseClientOptions & { - cookies: CookieMethodsBrowserDeprecated; + cookies: CookieMethodsBrowser; cookieOptions?: CookieOptionsWithName; cookieEncoding?: "raw" | "base64url"; isSingleton?: boolean; - }, + } ): SupabaseClient; export function createBrowserClient< @@ -92,11 +63,11 @@ export function createBrowserClient< supabaseUrl: string, supabaseKey: string, options?: SupabaseClientOptions & { - cookies?: CookieMethodsBrowser | CookieMethodsBrowserDeprecated; + cookies?: CookieMethodsBrowser; cookieOptions?: CookieOptionsWithName; cookieEncoding?: "raw" | "base64url"; isSingleton?: boolean; - }, + } ): SupabaseClient { // singleton client is created only if isSingleton is set to true, or if isSingleton is not defined and we detect a browser const shouldUseSingleton = @@ -109,7 +80,7 @@ export function createBrowserClient< if (!supabaseUrl || !supabaseKey) { throw new Error( - `@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`, + `@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` ); } @@ -118,7 +89,7 @@ export function createBrowserClient< ...options, cookieEncoding: options?.cookieEncoding ?? "base64url", }, - false, + false ); const client = createClient(supabaseUrl, supabaseKey, { diff --git a/src/createServerClient.ts b/src/createServerClient.ts index 9eae3b1..b1bcb49 100644 --- a/src/createServerClient.ts +++ b/src/createServerClient.ts @@ -10,34 +10,9 @@ import { createStorageFromOptions, applyServerStorage } from "./cookies"; import type { CookieOptionsWithName, CookieMethodsServer, - CookieMethodsServerDeprecated, } from "./types"; import { memoryLocalStorageAdapter } from "./utils/helpers"; -/** - * @deprecated Please specify `getAll` and `setAll` cookie methods instead of - * the `get`, `set` and `remove`. These will not be supported in the next major - * version. - */ -export function createServerClient< - Database = any, - SchemaName extends string & - keyof Omit = "public" extends keyof Omit< - Database, - "__InternalSupabase" - > - ? "public" - : string & keyof Omit, ->( - supabaseUrl: string, - supabaseKey: string, - options: SupabaseClientOptions & { - cookieOptions?: CookieOptionsWithName; - cookies: CookieMethodsServerDeprecated; - cookieEncoding?: "raw" | "base64url"; - }, -): SupabaseClient; - /** * Creates a Supabase Client for use on the server-side of a server-side * rendering (SSR) framework. @@ -132,7 +107,7 @@ export function createServerClient< supabaseKey: string, options: SupabaseClientOptions & { cookieOptions?: CookieOptionsWithName; - cookies: CookieMethodsServer | CookieMethodsServerDeprecated; + cookies: CookieMethodsServer; cookieEncoding?: "raw" | "base64url"; }, ): SupabaseClient { diff --git a/src/types.ts b/src/types.ts index ed3f2dd..2eaab00 100644 --- a/src/types.ts +++ b/src/types.ts @@ -26,11 +26,6 @@ export type SetAllCookies = ( cookies: { name: string; value: string; options: CookieOptions }[], ) => Promise | void; -export type CookieMethodsBrowserDeprecated = { - get: GetCookie; - set: SetCookie; - remove: RemoveCookie; -}; export type CookieMethodsBrowser = { /** @@ -44,11 +39,20 @@ export type CookieMethodsBrowser = { getAll: GetAllCookies; setAll: SetAllCookies; -}; - -export type CookieMethodsServerDeprecated = { - get: GetCookie; + /** + * @deprecated Please specify `getAll` methods instead of `get`. This will + * not be supported in the next major version. + */ + get?: GetCookie; + /** + * @deprecated Please specify `setAll` methods instead of `set`. This will + * not be supported in the next major version. + */ set?: SetCookie; + /** + * @deprecated Please specify `setAll` methods instead of `remove`. This will + * not be supported in the next major version. + */ remove?: RemoveCookie; }; @@ -64,4 +68,19 @@ export type CookieMethodsServer = { getAll: GetAllCookies; setAll?: SetAllCookies; + /** + * @deprecated Please specify `getAll` methods instead of `get`. This will + * not be supported in the next major version. + */ + get?: GetCookie; + /** + * @deprecated Please specify `setAll` methods instead of `set`. This will + * not be supported in the next major version. + */ + set?: SetCookie; + /** + * @deprecated Please specify `setAll` methods instead of `remove`. This will + * not be supported in the next major version. + */ + remove?: RemoveCookie; };