From f4468f60843050ba721876f831a39f68e4c42f81 Mon Sep 17 00:00:00 2001 From: caseybaggz Date: Mon, 17 Mar 2025 08:14:29 -0500 Subject: [PATCH] chore: improve types for functions and cookies --- src/createBrowserClient.ts | 29 ++--------------------------- src/createServerClient.ts | 26 +------------------------- src/types.ts | 37 ++++++++++++++++++++++++++++--------- 3 files changed, 31 insertions(+), 61 deletions(-) diff --git a/src/createBrowserClient.ts b/src/createBrowserClient.ts index 2cfdba6..a2e6c68 100644 --- a/src/createBrowserClient.ts +++ b/src/createBrowserClient.ts @@ -9,7 +9,6 @@ import { isBrowser } from "./utils"; import type { CookieMethodsBrowser, - CookieMethodsBrowserDeprecated, CookieOptionsWithName, } from "./types"; @@ -46,31 +45,7 @@ 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 Database = "public" extends keyof Database - ? "public" - : string & keyof Database, - Schema extends GenericSchema = Database[SchemaName] extends GenericSchema - ? Database[SchemaName] - : any, ->( - supabaseUrl: string, - supabaseKey: string, - options?: SupabaseClientOptions & { - cookies: CookieMethodsBrowserDeprecated; + cookies: CookieMethodsBrowser; cookieOptions?: CookieOptionsWithName; cookieEncoding?: "raw" | "base64url"; isSingleton?: boolean; @@ -89,7 +64,7 @@ export function createBrowserClient< supabaseUrl: string, supabaseKey: string, options?: SupabaseClientOptions & { - cookies?: CookieMethodsBrowser | CookieMethodsBrowserDeprecated; + cookies?: CookieMethodsBrowser; cookieOptions?: CookieOptionsWithName; cookieEncoding?: "raw" | "base64url"; isSingleton?: boolean; diff --git a/src/createServerClient.ts b/src/createServerClient.ts index 796cc10..bdeaefd 100644 --- a/src/createServerClient.ts +++ b/src/createServerClient.ts @@ -13,32 +13,8 @@ import { createStorageFromOptions, applyServerStorage } from "./cookies"; import type { CookieOptionsWithName, CookieMethodsServer, - CookieMethodsServerDeprecated, } from "./types"; -/** - * @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 Database = "public" extends keyof Database - ? "public" - : string & keyof Database, - Schema extends GenericSchema = Database[SchemaName] extends GenericSchema - ? Database[SchemaName] - : any, ->( - 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. @@ -131,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 7a88e64..aa8048f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -26,24 +26,43 @@ export type SetAllCookies = ( cookies: { name: string; value: string; options: CookieOptions }[], ) => Promise | void; -export type CookieMethodsBrowserDeprecated = { - get: GetCookie; - set: SetCookie; - remove: RemoveCookie; -}; 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; }; 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; };