Skip to content

chore: improve types for functions and cookies #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions src/createBrowserClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { isBrowser } from "./utils";

import type {
CookieMethodsBrowser,
CookieMethodsBrowserDeprecated,
CookieOptionsWithName,
} from "./types";

Expand Down Expand Up @@ -46,31 +45,7 @@ export function createBrowserClient<
supabaseUrl: string,
supabaseKey: string,
options?: SupabaseClientOptions<SchemaName> & {
cookies?: CookieMethodsBrowser;
cookieOptions?: CookieOptionsWithName;
cookieEncoding?: "raw" | "base64url";
isSingleton?: boolean;
},
): SupabaseClient<Database, SchemaName, Schema>;

/**
* @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<SchemaName> & {
cookies: CookieMethodsBrowserDeprecated;
cookies: CookieMethodsBrowser;
cookieOptions?: CookieOptionsWithName;
cookieEncoding?: "raw" | "base64url";
isSingleton?: boolean;
Expand All @@ -89,7 +64,7 @@ export function createBrowserClient<
supabaseUrl: string,
supabaseKey: string,
options?: SupabaseClientOptions<SchemaName> & {
cookies?: CookieMethodsBrowser | CookieMethodsBrowserDeprecated;
cookies?: CookieMethodsBrowser;
cookieOptions?: CookieOptionsWithName;
cookieEncoding?: "raw" | "base64url";
isSingleton?: boolean;
Expand Down
26 changes: 1 addition & 25 deletions src/createServerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SchemaName> & {
cookieOptions?: CookieOptionsWithName;
cookies: CookieMethodsServerDeprecated;
cookieEncoding?: "raw" | "base64url";
},
): SupabaseClient<Database, SchemaName, Schema>;

/**
* Creates a Supabase Client for use on the server-side of a server-side
* rendering (SSR) framework.
Expand Down Expand Up @@ -131,7 +107,7 @@ export function createServerClient<
supabaseKey: string,
options: SupabaseClientOptions<SchemaName> & {
cookieOptions?: CookieOptionsWithName;
cookies: CookieMethodsServer | CookieMethodsServerDeprecated;
cookies: CookieMethodsServer;
cookieEncoding?: "raw" | "base64url";
},
): SupabaseClient<Database, SchemaName, Schema> {
Expand Down
37 changes: 28 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,43 @@ export type SetAllCookies = (
cookies: { name: string; value: string; options: CookieOptions }[],
) => Promise<void> | 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;
};