@supabase-cache-helpers/postgrest-swr
Version:
A collection of SWR utilities for working with Supabase.
411 lines (384 loc) • 28.7 kB
TypeScript
import * as _supabase_cache_helpers_postgrest_core from '@supabase-cache-helpers/postgrest-core';
import { DeleteItemOperation, MutateItemOperation, RevalidateTablesOperation, UpsertItemOperation, PostgrestHasMorePaginationResponse, PostgrestPaginationResponse, DecodedKey, PostgrestParser, PostgrestQueryParserOptions, PostgrestFilter, InsertFetcherOptions, UpdateFetcherOptions, UpsertFetcherOptions, DeleteFetcherOptions, RevalidateOpts, PostgrestPaginationCacheData, PostgrestHasMorePaginationCacheData, AnyPostgrestResponse } from '@supabase-cache-helpers/postgrest-core';
export { PostgrestHasMorePaginationCacheData, PostgrestPaginationCacheData } from '@supabase-cache-helpers/postgrest-core';
import { MutatorOptions, Key, SWRConfiguration, SWRResponse } from 'swr';
import { PostgrestClientOptions, PostgrestTransformBuilder, UnstableGetResult, PostgrestQueryBuilder, PostgrestError as PostgrestError$1, PostgrestResponse, PostgrestSingleResponse, PostgrestMaybeSingleResponse } from '@supabase/postgrest-js';
import { GenericSchema, GenericTable } from '@supabase/postgrest-js/dist/cjs/types';
import * as swr_infinite from 'swr/infinite';
import { SWRInfiniteHook, SWRInfiniteKeyLoader, SWRInfiniteFetcher, SWRInfiniteConfiguration, SWRInfiniteResponse } from 'swr/infinite';
import { PostgrestError, SupabaseClient, RealtimePostgresChangesFilter, REALTIME_POSTGRES_CHANGES_LISTEN_EVENT, RealtimePostgresChangesPayload, RealtimeChannel } from '@supabase/supabase-js';
export { PostgrestError } from '@supabase/supabase-js';
import { SWRMutationConfiguration, SWRMutationResponse } from 'swr/mutation';
export { SWRMutationConfiguration } from 'swr/mutation';
export { fetchOffsetPaginationFallbackData, fetchOffsetPaginationHasMoreFallbackData, fetchQueryFallbackData } from './index.react-server.js';
/**
* Returns a function that can be used to delete an item into the SWR cache.
* This hook does not make any HTTP requests and is intended to be used for custom cache updates.
*
* @param opts - Options for the delete operation, excluding the input record.
*
* @returns A function that takes a record of type `Type` and returns a promise that resolves once the record has been deleted from the cache.
* **/
declare function useDeleteItem<Type extends Record<string, unknown>>(opts: Omit<DeleteItemOperation<Type>, 'input'> & MutatorOptions<Type>): (input: Type) => Promise<void>;
/**
* Returns a function that can be used to mutate an item by primary key(s) in the SWR cache.
* This hook does not make any HTTP requests and is intended to be used for custom cache updates.
*
* @param opts - Options for the mutate operation, excluding the input and the mutate function.
*
* @returns A function that takes a record that should contain a value for all primary keys of `Type` as well as a mutate function and returns a promise that resolves once the record has been upserted into the cache.
* **/
declare function useMutateItem<Type extends Record<string, unknown>>(opts: Omit<MutateItemOperation<Type>, 'input' | 'mutate'> & MutatorOptions<Type>): (input: Partial<Type>, mutateFn: (current: Type) => Type) => Promise<void>;
/**
* Returns a function that can be used to revalidate all queries in the cache that match the tables provided in the `RevalidateTablesOperation`
* This hook does not make any HTTP requests and is intended to be used for custom cache revalidations.
*
* @param tables - The tables to revalidate
*
* @returns A function that will revalidate all defined tables when called.
* **/
declare function useRevalidateTables(tables: RevalidateTablesOperation): () => Promise<void>;
/**
* Returns a function that can be used to upsert an item into the SWR cache.
* This hook does not make any HTTP requests and is intended to be used for custom cache updates.
*
* @param opts - Options for the upsert operation, excluding the input record.
*
* @returns A function that takes a record of type `Type` and returns a promise that resolves once the record has been upserted into the cache.
* **/
declare function useUpsertItem<Type extends Record<string, unknown>>(opts: Omit<UpsertItemOperation<Type>, 'input'> & MutatorOptions<Type>): (input: Type) => Promise<void>;
declare const KEY_PREFIX = "postgrest";
declare const POSTGREST_FILTER_KEY_PREFIX = "postgrest-filter";
declare const KEY_SEPARATOR = "$";
declare const INFINITE_PREFIX = "$inf$";
declare const INFINITE_KEY_PREFIX = "page";
declare const createOffsetKeyGetter: <Options extends PostgrestClientOptions, Schema extends GenericSchema, Table extends Record<string, unknown>, Result, RelationName = unknown, Relationships = unknown>(queryFactory: (() => PostgrestTransformBuilder<Options, Schema, Table, Result, RelationName, Relationships>) | null, { pageSize, rpcArgs, }: {
pageSize: number;
rpcArgs?: {
limit: string;
offset: string;
};
}) => (pageIndex: number, previousPageData: (PostgrestHasMorePaginationResponse<Result> | PostgrestPaginationResponse<Result>)[]) => PostgrestTransformBuilder<Options, Schema, Table, Result, RelationName, Relationships, unknown> | null;
declare const createCursorKeyGetter: <Options extends PostgrestClientOptions, Schema extends GenericSchema, Table extends Record<string, unknown>, Result, RelationName = unknown, Relationships = unknown>(queryFactory: (() => PostgrestTransformBuilder<Options, Schema, Table, Result, RelationName, Relationships>) | null, { orderBy, uqOrderBy: uqColumn, rpcArgs, }: {
orderBy: string;
uqOrderBy?: string;
rpcArgs?: {
orderBy: string;
uqOrderBy?: string;
};
}) => (_pageIndex: number, previousPageData: (PostgrestHasMorePaginationResponse<Result> | PostgrestPaginationResponse<Result>)[]) => PostgrestTransformBuilder<Options, Schema, Table, Result, RelationName, Relationships, unknown> | null;
type DecodedSWRKey = DecodedKey & {
isInfinite: boolean;
key: string;
isInfiniteKey: boolean;
};
declare const decode: (key: Key) => DecodedSWRKey | null;
declare const encode: <Result>(parser: PostgrestParser<Result>, isInfinite: boolean) => string;
declare const infiniteMiddleware: <Result>(useSWRInfiniteNext: SWRInfiniteHook) => (keyFn: SWRInfiniteKeyLoader, fetcher: SWRInfiniteFetcher, config: SWRInfiniteConfiguration) => swr_infinite.SWRInfiniteResponse<any, any>;
declare const usePostgrestFilterCache: <R extends Record<string, unknown>>() => (query: string, opts?: PostgrestQueryParserOptions) => PostgrestFilter<any>;
declare const useQueriesForTableLoader: (table: string) => () => {
paths: _supabase_cache_helpers_postgrest_core.Path[];
filters: _supabase_cache_helpers_postgrest_core.FilterDefinitions;
}[];
type Operation = 'Insert' | 'UpdateOne' | 'Upsert' | 'DeleteOne' | 'DeleteMany';
type GetFetcherOptions<ClientOptions extends PostgrestClientOptions, S extends GenericSchema, T extends GenericTable, O extends Operation, Relationships = T extends {
Relationships: infer R;
} ? R : unknown> = O extends 'Insert' ? InsertFetcherOptions<ClientOptions, S, T, Relationships> : O extends 'UpdateOne' ? UpdateFetcherOptions<ClientOptions, S, T, Relationships> : O extends 'Upsert' ? UpsertFetcherOptions<ClientOptions, S, T, Relationships> : O extends 'DeleteOne' | 'DeleteMany' ? DeleteFetcherOptions<ClientOptions, S, T, Relationships> : never;
type GetInputType<T extends GenericTable, O extends Operation> = O extends 'DeleteOne' ? Partial<T['Row']> : O extends 'DeleteMany' ? Partial<T['Row']>[] : O extends 'Insert' | 'Upsert' ? T['Insert'][] : O extends 'UpdateOne' ? T['Update'] : never;
type GetReturnType<O extends Operation, S extends GenericSchema, T extends GenericTable, RelationName, Relationships = T extends {
Relationships: infer R;
} ? R : unknown, Q extends string = '*', R = UnstableGetResult<S, T['Row'], RelationName, Relationships, Q extends '*' ? '*' : Q, PostgrestClientOptions>> = O extends 'UpdateOne' ? R | null : O extends 'DeleteOne' ? R | null : O extends 'Insert' | 'Upsert' | 'DeleteMany' ? R[] | null : never;
type UsePostgrestSWRMutationOpts<O extends Operation, S extends GenericSchema, T extends GenericTable, RelationName extends string, Relationships = T extends {
Relationships: infer R;
} ? R : unknown, Q extends string = '*', R = UnstableGetResult<S, T['Row'], RelationName, Relationships, Q extends '*' ? '*' : Q, PostgrestClientOptions>> = RevalidateOpts<T['Row']> & Pick<MutatorOptions, 'throwOnError' | 'revalidate'> & SWRMutationConfiguration<GetReturnType<O, S, T, RelationName, Relationships, Q, R>, PostgrestError, string, GetInputType<T, O>> & {
disableAutoQuery?: boolean;
} & GetFetcherOptions<PostgrestClientOptions, S, T, O, Relationships>;
/**
* Hook for performing a DELETE mutation on a PostgREST resource.
*
* @param qb - The PostgrestQueryBuilder instance for the resource.
* @param primaryKeys - An array of primary key column names for the table.
* @param query - An optional query string.
* @param opts - An optional object of options to configure the mutation.
* @returns A SWRMutationResponse object containing the mutation response data, error, and mutation function.
*/
declare function useDeleteManyMutation<O extends PostgrestClientOptions, S extends GenericSchema, T extends GenericTable, RelationName extends string, Re = T extends {
Relationships: infer R;
} ? R : unknown, Q extends string = '*', R = UnstableGetResult<S, T['Row'], RelationName, Re, Q extends '*' ? '*' : Q, O>>(qb: PostgrestQueryBuilder<O, S, T, RelationName, Re>, primaryKeys: (keyof T['Row'])[], query?: Q | null, opts?: UsePostgrestSWRMutationOpts<'DeleteMany', S, T, RelationName, Re, Q, R>): SWRMutationResponse<R[] | null, PostgrestError$1, string, Partial<T['Row']>[]>;
/**
* Hook for performing a DELETE mutation on a PostgREST resource.
*
* @param qb - The PostgrestQueryBuilder instance for the resource.
* @param primaryKeys - An array of primary key column names for the table.
* @param query - An optional query string.
* @param opts - An optional object of options to configure the mutation.
* @returns A SWRMutationResponse object containing the mutation response data, error, and mutation function.
*/
declare function useDeleteMutation<O extends PostgrestClientOptions, S extends GenericSchema, T extends GenericTable, RelationName extends string, Re = T extends {
Relationships: infer R;
} ? R : unknown, Q extends string = '*', R = UnstableGetResult<S, T['Row'], RelationName, Re, Q extends '*' ? '*' : Q, O>>(qb: PostgrestQueryBuilder<O, S, T, RelationName, Re>, primaryKeys: (keyof T['Row'])[], query?: Q | null, opts?: UsePostgrestSWRMutationOpts<'DeleteOne', S, T, RelationName, Re, Q, R>): SWRMutationResponse<R | null, PostgrestError$1, string, Partial<T['Row']>>;
/**
* Hook for performing an INSERT mutation on a PostgREST resource.
*
* @param qb - The PostgrestQueryBuilder instance for the resource.
* @param primaryKeys - An array of primary key column names for the table.
* @param query - An optional query string.
* @param opts - An optional object of options to configure the mutation.
* @returns A SWRMutationResponse object containing the mutation response data, error, and mutation function.
*/
declare function useInsertMutation<O extends PostgrestClientOptions, S extends GenericSchema, T extends GenericTable, RelationName extends string, Re = T extends {
Relationships: infer R;
} ? R : unknown, Q extends string = '*', R = UnstableGetResult<S, T['Row'], RelationName, Re, Q extends '*' ? '*' : Q, O>>(qb: PostgrestQueryBuilder<O, S, T, RelationName, Re>, primaryKeys: (keyof T['Row'])[], query?: Q | null, opts?: UsePostgrestSWRMutationOpts<'Insert', S, T, RelationName, Re, Q, R>): SWRMutationResponse<R[] | null, PostgrestError$1, string, T['Insert'][]>;
/**
* Hook for performing an UPDATE mutation on a PostgREST resource.
*
* @param qb - The PostgrestQueryBuilder instance for the resource.
* @param primaryKeys - An array of primary key column names for the table.
* @param query - An optional query string.
* @param opts - An optional object of options to configure the mutation.
* @returns A SWRMutationResponse object containing the mutation response data, error, and mutation function.
*/
declare function useUpdateMutation<O extends PostgrestClientOptions, S extends GenericSchema, T extends GenericTable, RelationName extends string, Re = T extends {
Relationships: infer R;
} ? R : unknown, Q extends string = '*', R = UnstableGetResult<S, T['Row'], RelationName, Re, Q extends '*' ? '*' : Q, O>>(qb: PostgrestQueryBuilder<O, S, T, RelationName, Re>, primaryKeys: (keyof T['Row'])[], query?: Q | null, opts?: UsePostgrestSWRMutationOpts<'UpdateOne', S, T, RelationName, Re, Q, R>): SWRMutationResponse<R | null, PostgrestError$1, string, T['Update']>;
/**
* Hook for performing an UPSERT mutation on a PostgREST resource.
*
* @param qb - The PostgrestQueryBuilder instance for the resource.
* @param primaryKeys - An array of primary key column names for the table.
* @param query - An optional query string.
* @param opts - An optional object of options to configure the mutation.
* @returns A SWRMutationResponse object containing the mutation response data, error, and mutation function.
*/
declare function useUpsertMutation<O extends PostgrestClientOptions, S extends GenericSchema, T extends GenericTable, RelationName extends string, Re = T extends {
Relationships: infer R;
} ? R : unknown, Q extends string = '*', R = UnstableGetResult<S, T['Row'], RelationName, Re, Q extends '*' ? '*' : Q, O>>(qb: PostgrestQueryBuilder<O, S, T, RelationName, Re>, primaryKeys: (keyof T['Row'])[], query?: Q | null, opts?: UsePostgrestSWRMutationOpts<'Upsert', S, T, RelationName, Re, Q, R>): SWRMutationResponse<R[] | null, PostgrestError$1, string, T['Insert'][]>;
type SWRCursorInfiniteScrollPostgrestResponse<Result> = Omit<SWRInfiniteResponse<PostgrestPaginationCacheData<Result>, PostgrestError$1>, 'data'> & {
loadMore: null | (() => void);
data: Result[] | undefined;
};
/**
* The return value of useInfiniteScrollQuery hook.
*/
type UseCursorInfiniteScrollQueryReturn<Result extends Record<string, unknown>> = Omit<SWRInfiniteResponse<PostgrestPaginationResponse<Result>, PostgrestError$1>, 'data'> & {
loadMore: null | (() => void);
data: Result[] | undefined;
};
type CursorConfig<Table extends Record<string, unknown>, ColumnName extends string & keyof Table> = {
orderBy: ColumnName;
uqOrderBy?: ColumnName;
rpcArgs?: {
limit: string;
orderBy: string;
uqOrderBy?: string;
};
};
/**
* A hook that provides infinite scroll capabilities to PostgREST queries using SWR.
*
* @param {PostgrestTransformBuilder<Schema, Table, Result[]> | null} query - The PostgREST query.
* @param {SWRInfiniteConfiguration & { pageSize?: number }} [config] - The SWRInfinite configuration.
* @returns {UseInfiniteScrollQueryReturn<Result>} - The infinite scroll query result.
*/
declare function useCursorInfiniteScrollQuery<Options extends PostgrestClientOptions, Schema extends GenericSchema, Table extends Record<string, unknown>, Result extends Record<string, unknown>, ColumnName extends string & keyof Table, RelationName, Relationships = unknown>(queryFactory: (() => PostgrestTransformBuilder<Options, Schema, Table, Result[], RelationName, Relationships>) | null, config: SWRInfiniteConfiguration<PostgrestPaginationResponse<Result>, PostgrestError$1> & CursorConfig<Table, ColumnName>): UseCursorInfiniteScrollQueryReturn<Result>;
/**
* The return type of the `useInfiniteQuery` hook
*/
type UseOffsetInfiniteQueryReturn<Result extends Record<string, unknown>> = SWRInfiniteResponse<Exclude<PostgrestResponse<Result>['data'], null>, PostgrestError$1>;
/**
* @deprecated Use UseOffsetInfiniteQueryReturn instead.
*/
type UseInfiniteQueryReturn<Result extends Record<string, unknown>> = UseOffsetInfiniteQueryReturn<Result>;
/**
* A hook to perform an infinite postgrest query
* @param query The postgrest query builder
* @param config Optional SWRInfiniteConfiguration options to configure the hook
* @returns An object containing the query results and other SWR-related properties
*/
declare function useOffsetInfiniteQuery<Options extends PostgrestClientOptions, Schema extends GenericSchema, Table extends Record<string, unknown>, Result extends Record<string, unknown>, RelationName = unknown, Relationships = unknown>(queryFactory: (() => PostgrestTransformBuilder<Options, Schema, Table, Result[], RelationName, Relationships>) | null, config?: SWRInfiniteConfiguration<Exclude<PostgrestResponse<Result>['data'], null>, PostgrestError$1> & {
pageSize?: number;
rpcArgs?: {
limit: string;
offset: string;
};
}): UseOffsetInfiniteQueryReturn<Result>;
type SWROffsetInfiniteScrollPostgrestResponse<Result> = Omit<SWRInfiniteResponse<PostgrestHasMorePaginationCacheData<Result>, PostgrestError$1>, 'data'> & {
loadMore: null | (() => void);
data: Result[] | undefined;
};
/**
* @deprecated Use SWROffsetInfiniteScrollPostgrestResponse instead.
*/
type SWRInfinityScrollPostgrestResponse<Result> = SWROffsetInfiniteScrollPostgrestResponse<Result>;
/**
* The return value of useInfiniteScrollQuery hook.
*/
type UseOffsetInfiniteScrollQueryReturn<Result extends Record<string, unknown>> = Omit<SWRInfiniteResponse<PostgrestHasMorePaginationResponse<Result>, PostgrestError$1>, 'data'> & {
loadMore: null | (() => void);
data: Result[] | undefined;
};
/**
* @deprecated Use UseOffsetInfiniteScrollQueryReturn instead.
*/
type UseInfiniteScrollQueryReturn<Result extends Record<string, unknown>> = UseOffsetInfiniteScrollQueryReturn<Result>;
/**
* A hook that provides infinite scroll capabilities to PostgREST queries using SWR.
*
* @param {PostgrestTransformBuilder<Schema, Table, Result[]> | null} queryFactory - The PostgREST query.
* @param {SWRInfiniteConfiguration & { pageSize?: number }} [config] - The SWRInfinite configuration.
* @returns {UseInfiniteScrollQueryReturn<Result>} - The infinite scroll query result.
*/
declare function useOffsetInfiniteScrollQuery<Options extends PostgrestClientOptions, Schema extends GenericSchema, Table extends Record<string, unknown>, Result extends Record<string, unknown>, RelationName = unknown, Relationships = unknown>(queryFactory: (() => PostgrestTransformBuilder<Options, Schema, Table, Result[], RelationName, Relationships>) | null, config?: SWRInfiniteConfiguration<PostgrestHasMorePaginationResponse<Result>, PostgrestError$1> & {
pageSize?: number;
rpcArgs?: {
limit: string;
offset: string;
};
}): UseOffsetInfiniteScrollQueryReturn<Result>;
type SWRInfiniteOffsetPaginationPostgrestResponse<Result> = Omit<SWRInfiniteResponse<PostgrestHasMorePaginationResponse<Result>, PostgrestError$1>, 'data' | 'size' | 'setSize'> & {
pages: SWRInfiniteResponse<Result[], PostgrestError$1>['data'];
currentPage: null | Result[];
pageIndex: number;
setPage: (idx: number) => void;
nextPage: null | (() => void);
previousPage: null | (() => void);
};
/**
* @deprecated Use SWROffsetInfinitePaginationPostgrestResponse instead.
*/
type SWRInfinitePaginationPostgrestResponse<Result> = SWRInfiniteOffsetPaginationPostgrestResponse<Result>;
/**
* The return value of the `usePaginationQuery` hook.
*/
type UseInfiniteOffsetPaginationQueryReturn<Result extends Record<string, unknown>> = SWRInfiniteOffsetPaginationPostgrestResponse<Result>;
/**
* @deprecated Use SWROffsetInfinitePaginationPostgrestResponse instead.
*/
type UsePaginationQueryReturn<Result extends Record<string, unknown>> = UseInfiniteOffsetPaginationQueryReturn<Result>;
/**
* A hook for paginating through a PostgREST response.
*
* @param query - A PostgREST query builder.
* @param config - A SWR configuration object.
* @param config.pageSize - The number of items per page.
* @returns An object containing the paginated data and various functions to manipulate the pagination state.
*/
declare function useInfiniteOffsetPaginationQuery<Options extends PostgrestClientOptions, Schema extends GenericSchema, Table extends Record<string, unknown>, Result extends Record<string, unknown>, RelationName = unknown, Relationships = unknown>(queryFactory: (() => PostgrestTransformBuilder<Options, Schema, Table, Result[], RelationName, Relationships>) | null, config?: SWRInfiniteConfiguration<PostgrestHasMorePaginationResponse<Result>, PostgrestError$1> & {
pageSize?: number;
rpcArgs?: {
limit: string;
offset: string;
};
}): UseInfiniteOffsetPaginationQueryReturn<Result>;
/**
* The return type of `useQuery` for `.single()` record results
*/
type UseQuerySingleReturn<Result> = Omit<SWRResponse<PostgrestSingleResponse<Result>['data'], PostgrestError$1>, 'mutate'> & Pick<SWRResponse<PostgrestSingleResponse<Result>, PostgrestError$1>, 'mutate'> & Pick<PostgrestSingleResponse<Result>, 'count'>;
/**
* The return type of `useQuery` for `.maybeSingle()` queries
*/
type UseQueryMaybeSingleReturn<Result> = Omit<SWRResponse<PostgrestMaybeSingleResponse<Result>['data'], PostgrestError$1>, 'mutate'> & Pick<SWRResponse<PostgrestMaybeSingleResponse<Result>, PostgrestError$1>, 'mutate'> & Pick<PostgrestMaybeSingleResponse<Result>, 'count'>;
/**
* The default return type of `useQuery` queries
*/
type UseQueryReturn<Result> = Omit<SWRResponse<PostgrestResponse<Result>['data'], PostgrestError$1>, 'mutate'> & Pick<SWRResponse<PostgrestResponse<Result>, PostgrestError$1>, 'mutate'> & Pick<PostgrestResponse<Result>, 'count'>;
/**
* The return type of `useQuery` for any type of result
*/
type UseQueryAnyReturn<Result> = Omit<SWRResponse<AnyPostgrestResponse<Result>['data'], PostgrestError$1>, 'mutate'> & Pick<SWRResponse<AnyPostgrestResponse<Result>, PostgrestError$1>, 'mutate'> & Pick<AnyPostgrestResponse<Result>, 'count'>;
/**
* Perform a postgrest query using `useSWR`.
*
* @param {PromiseLike<PostgrestSingleResponse<Result>> | null} query - The query to perform
* @param {SWRConfiguration} [config] - The configuration for `useSWR`
* @returns {UseQuerySingleReturn<Result>} - The query result
*/
declare function useQuery<Result>(query: PromiseLike<PostgrestSingleResponse<Result>> | null, config?: SWRConfiguration<PostgrestSingleResponse<Result>, PostgrestError$1>): UseQuerySingleReturn<Result>;
/**
* Perform a postgrest query using `useSWR`.
*
* @param {PromiseLike<PostgrestMaybeSingleResponse<Result>> | null} query - The query to perform
* @param {SWRConfiguration} [config] - The configuration for `useSWR`
* @returns {UseQueryMaybeSingleReturn<Result>} - The query result
*/
declare function useQuery<Result>(query: PromiseLike<PostgrestMaybeSingleResponse<Result>> | null, config?: SWRConfiguration<PostgrestMaybeSingleResponse<Result>, PostgrestError$1>): UseQueryMaybeSingleReturn<Result>;
/**
* Perform a postgrest query using `useSWR`.
*
* @param {PromiseLike<PostgrestResponse<Result>> | null} query - The query to perform
* @param {SWRConfiguration} [config] - The configuration for `useSWR`
* @returns {UseQueryReturn<Result>} - The query result
*/
declare function useQuery<Result>(query: PromiseLike<PostgrestResponse<Result>> | null, config?: SWRConfiguration<PostgrestResponse<Result>, PostgrestError$1>): UseQueryReturn<Result>;
/**
* Options for the useSubscriptionQuery hook.
*/
type UseSubscriptionQueryOpts<O extends PostgrestClientOptions, S extends GenericSchema, T extends GenericTable, RelationName, Re = T extends {
Relationships: infer R;
} ? R : unknown, Q extends string = '*', R = UnstableGetResult<S, T['Row'], RelationName, Re, Q extends '*' ? '*' : Q, O>> = RevalidateOpts<T['Row']> & MutatorOptions & {
/**
* A callback that will be called whenever a realtime event occurs for the given channel.
* The callback will receive the event payload with an additional "data" property, which will be
* the affected row of the event (or a modified version of it, if a select query is provided).
*/
callback?: (event: RealtimePostgresChangesPayload<T['Row']> & {
data: T['Row'] | R;
}) => void | Promise<void>;
};
/**
* A hook for subscribing to realtime Postgres events on a given channel.
*
* The subscription will automatically update the cache for the specified table in response
* to incoming Postgres events, and optionally run a user-provided callback function with the
* event and the updated data.
*
* This hook works by creating a Supabase Realtime channel for the specified table and
* subscribing to Postgres changes on that channel. When an event is received, the hook
* fetches the updated data from the database (using a `select` query generated from the cache
* configuration), and then updates the cache accordingly.
*
* @param client - The Supabase client instance.
* @param channelName - The name of the channel to subscribe to.
* @param filter - The filter object to use when listening for changes.
* @param primaryKeys - An array of the primary keys for the table being listened to.
* @param query - An optional PostgREST query to use when selecting data for an event.
* @param opts - Additional options to pass to the hook.
* @returns An object containing the RealtimeChannel and the current status of the subscription.
*/
declare function useSubscriptionQuery<O extends PostgrestClientOptions, S extends GenericSchema, T extends GenericTable, RelationName extends string, Re = T extends {
Relationships: infer R;
} ? R : unknown, Q extends string = '*', R = UnstableGetResult<S, T['Row'], RelationName, Re, Q extends '*' ? '*' : Q, O>>(client: SupabaseClient | null, channelName: string, filter: Omit<RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.ALL}`>, 'table'> & {
table: RelationName;
}, primaryKeys: (keyof T['Row'])[], query?: Q | null, opts?: UseSubscriptionQueryOpts<O, S, T, RelationName, Re, Q, R>): {
status: string | null;
error: Error | null;
channel: RealtimeChannel | undefined;
};
/**
* Options for `useSubscription` hook.
*/
type UseSubscriptionOpts<T extends GenericTable> = RevalidateOpts<T['Row']> & MutatorOptions & {
/**
* A callback that will be invoked whenever a new change event is received.
*
* @param event - The change event payload.
* @returns Optionally returns a Promise.
*/
callback?: (event: RealtimePostgresChangesPayload<T['Row']>) => void | Promise<void>;
};
/**
* A custom React hook for subscribing to a Supabase Realtime subscription.
*
* @param channel - The Realtime subscription channel to listen to.
* @param filter - The filter to apply on the table. Must include the table name.
* @param primaryKeys - An array of primary key column names for the table.
* @param opts - Additional options for the hook.
* @returns An object containing the subscription status.
*/
declare function useSubscription<T extends GenericTable>(client: SupabaseClient | null, channelName: string, filter: Omit<RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.ALL}`>, 'table'> & {
table: string;
}, primaryKeys: (keyof T['Row'])[], opts?: UseSubscriptionOpts<T>): {
status: string | null;
error: Error | null;
};
export { type CursorConfig, type DecodedSWRKey, type GetFetcherOptions, type GetInputType, type GetReturnType, INFINITE_KEY_PREFIX, INFINITE_PREFIX, KEY_PREFIX, KEY_SEPARATOR, type Operation, POSTGREST_FILTER_KEY_PREFIX, type SWRCursorInfiniteScrollPostgrestResponse, type SWRInfiniteOffsetPaginationPostgrestResponse, type SWRInfinitePaginationPostgrestResponse, type SWRInfinityScrollPostgrestResponse, type SWROffsetInfiniteScrollPostgrestResponse, type UseCursorInfiniteScrollQueryReturn, type UseInfiniteOffsetPaginationQueryReturn, type UseInfiniteQueryReturn, type UseInfiniteScrollQueryReturn, type UseOffsetInfiniteQueryReturn, type UseOffsetInfiniteScrollQueryReturn, type UsePaginationQueryReturn, type UsePostgrestSWRMutationOpts, type UseQueryAnyReturn, type UseQueryMaybeSingleReturn, type UseQueryReturn, type UseQuerySingleReturn, type UseSubscriptionOpts, type UseSubscriptionQueryOpts, createCursorKeyGetter, createOffsetKeyGetter, decode, encode, infiniteMiddleware, useCursorInfiniteScrollQuery, useDeleteItem, useDeleteManyMutation, useDeleteMutation, useInfiniteOffsetPaginationQuery, useInsertMutation, useMutateItem, useOffsetInfiniteQuery, useOffsetInfiniteScrollQuery, usePostgrestFilterCache, useQueriesForTableLoader, useQuery, useRevalidateTables, useSubscription, useSubscriptionQuery, useUpdateMutation, useUpsertItem, useUpsertMutation };