@supabase-cache-helpers/postgrest-core
Version:
A collection of cache utilities for working with the Supabase REST API. It is not meant to be used standalone.
621 lines (584 loc) • 27.7 kB
text/typescript
import { PostgrestSingleResponse, PostgrestMaybeSingleResponse, PostgrestResponse, PostgrestBuilder, PostgrestTransformBuilder, PostgrestQueryBuilder, UnstableGetResult } from '@supabase/postgrest-js';
import { GenericSchema, GenericTable } from '@supabase/postgrest-js/dist/cjs/types';
/**
* A function that validates whether the given input is an object of type Type
* @returns true if obj is of type Type, false if not
*/
type FilterFn<Type extends Record<string, unknown>> = (obj: unknown) => obj is Type;
/**
* The supported value types
*/
type ValueType = number | string | boolean | null | Date | object;
/**
* A function implementing a FilterOperators
* @param columnValue the value of the input object to test the filter against
* @param filterValue the value of the filter, e.g. in .eq('colname', 'filterValue'), 'filterValue' would be the filterValue
* @returns true if the filter applies, false if not
*/
type OperatorFn = (columnValue: any, filterValue: any) => boolean;
/**
* All supported operators of PostgREST
*/
type FilterOperator = 'or' | 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'ilike' | 'is' | 'in' | 'cs' | 'cd' | 'fts' | 'plfts';
/**
* An object describing a selected path of a query
*
*/
type Path = {
/**
* The aliased path if a column or relation name mapping is used within the path
*/
alias?: string;
/**
* The "real" path of a column
*/
path: string;
/**
* The full declaration of a column that includes alias, hints and inner joins
*/
declaration: string;
/**
* The aggregate function applied to the path
*/
aggregate?: string;
};
/**
* A decomposed filter applied to a query
*/
type FilterDefinition = {
/**
* The path to which the filter is applied
*/
path: string;
/**
* The aliased path if a column or relation name mapping is used
*/
alias?: string;
/**
* The operator that is applied
*/
operator: FilterOperator;
/**
* Whether or not to negate the results of the filter, e.g. when .not('name', 'eq', 'Paris') is applied
*/
negate: boolean;
/**
* The value of the filter
*/
value: ValueType;
};
/**
* A json representation of PostgREST filters that are applied to a query
*/
type FilterDefinitions = ({
or: FilterDefinitions;
} | {
and: FilterDefinitions;
} | FilterDefinition)[];
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
declare const isAndFilter: (f: ArrayElement<FilterDefinitions>) => f is {
and: FilterDefinitions;
};
declare const isOrFilter: (f: ArrayElement<FilterDefinitions>) => f is {
or: FilterDefinitions;
};
declare const isFilterDefinition: (f: ArrayElement<FilterDefinitions>) => f is FilterDefinition;
type OrderDefinition = {
column: string;
ascending: boolean;
nullsFirst: boolean;
foreignTable?: string;
};
type NestedPath = {
alias?: string;
path: string;
declaration: string;
paths: (Path | NestedPath)[];
};
type BuildNormalizedQueryOps<Q extends string = '*'> = {
query?: Q | null;
disabled?: boolean;
queriesForTable: () => {
paths: Path[];
filters: FilterDefinitions;
}[];
};
type BuildNormalizedQueryReturn = {
selectQuery: string;
groupedUserQueryPaths: (NestedPath | Path)[] | null;
groupedPaths: (NestedPath | Path)[];
};
/**
* returns select statement that includes the users query + all paths currently loaded into cache to later perform a "smart update"
*
* the select statement does not contain any user-defined aliases. only custom ones to dedupe.
* without deduping, we would not be able to query inbox_id,inbox:inbox_id(name),
* because it will result in a select of inbox_id,inbox_id(name), which does not work.
* to dedupe, we add a custom alias to the query, e.g. dedupe_0:inbox_id,inbox_id(name)
* we then later remove them when normalizing the data
**/
declare const buildNormalizedQuery: <Q extends string = "*">({ query, disabled, queriesForTable, }: BuildNormalizedQueryOps<Q>) => BuildNormalizedQueryReturn | null;
/**
* The parsed response of the mutation fetcher
**/
type MutationFetcherResponse<R> = {
/**
* Normalized response. A flat json object with a depth of 1, where the keys are the full json paths.
**/
normalizedData: R;
/**
* Result of the query passed by the user
**/
userQueryData?: R;
};
declare const buildMutationFetcherResponse: <R>(
/**
* response of the select query built by `buildNormalizedQuery`. contains dedupe aliases.
**/
input: R, { groupedPaths, groupedUserQueryPaths, }: Pick<BuildNormalizedQueryReturn, "groupedPaths" | "groupedUserQueryPaths">) => MutationFetcherResponse<R>;
/**
* Normalize the response by removing the dedupe alias and flattening it
**/
declare const normalizeResponse: <R>(groups: (Path | NestedPath)[], obj: R) => R;
type AnyPostgrestResponse<Result> = PostgrestSingleResponse<Result> | PostgrestMaybeSingleResponse<Result> | PostgrestResponse<Result>;
declare const isAnyPostgrestResponse: <Result>(q: unknown) => q is AnyPostgrestResponse<Result>;
type PostgrestPaginationResponse<Result> = Result[];
declare const isPostgrestPaginationResponse: <Result>(q: unknown) => q is PostgrestPaginationResponse<Result>;
type PostgrestHasMorePaginationResponse<Result> = {
data: Result[];
hasMore: boolean;
};
declare const isPostgrestHasMorePaginationResponse: <Result>(q: unknown) => q is PostgrestHasMorePaginationResponse<Result>;
type MaybeLikePostgrestBuilder<Result> = unknown;
declare const SUPPORTED_OPERATORS: string[];
type PostgrestQueryParserOptions = {
/**
* If defined, will use only filters that apply to the given paths
*/
exclusivePaths?: string[];
};
declare class PostgrestQueryParser {
readonly opts?: PostgrestQueryParserOptions | undefined;
private readonly _params;
private _filters;
private _paths;
constructor(query: string, opts?: PostgrestQueryParserOptions | undefined);
/**
* Getter that returns the paths and their aliases that the query selects. Will do the computation only once.
*
* ```js
* const p = new PostgrestParser(
* supabaseClient.from("test")
* .select(
* `name,
* city:cities (
* test:name
* ),
* countries (
* capital,
* population,
* some_ref (
* test:first,
* second
* )
* )`
* );
* console.log(p.paths);
* // [
* // { alias: undefined, path: "name" },
* // { alias: "city.test", path: "cities.name" },
* // { alias: undefined, path: "countries.capital" },
* // { alias: undefined, path: "countries.population" },
* // {
* // alias: "countries.some_ref.test",
* // path: "countries.some_ref.first",
* // },
* // { alias: undefined, path: "countries.some_ref.second" },
* // ];
* ```
*
* @returns an array of paths that the query selects, containing the columns and aliases
*/
get paths(): Path[];
/**
* Getter that returns the filters that this query applies in a json object.
*
* ```js
* const p = new PostgrestParser(
* supabaseClient.from("test").select('*')
* .or("full_name.eq.20,test.neq.true,and(full_name.eq.Test Name,email.eq.test@mail.com)")
* .eq("id", "123")
* .contains("id", "456")
* );
*
* console.log(p.filters);
*
* // [
* // {
* // or: [
* // {
* // path: "full_name",
* // negate: false,
* // operator: "eq",
* // value: 20,
* // },
* // {
* // path: "test",
* // negate: false,
* // operator: "neq",
* // value: true,
* // },
* // {
* // and: [
* // {
* // path: "full_name",
* // negate: false,
* // operator: "eq",
* // value: "Test Name",
* // },
* // {
* // path: "email",
* // negate: false,
* // operator: "eq",
* // value: "test@mail.com",
* // },
* // ],
* // },
* // ],
* // },
* // {
* // path: "id",
* // negate: false,
* // operator: "eq",
* // value: 123,
* // },
* // {
* // path: "id",
* // negate: false,
* // operator: "cs",
* // value: 456,
* // },
* // ];
* ```
*
* @returns a FilterDefinitions object
*/
get filters(): FilterDefinitions;
private parseFilterString;
}
declare class PostgrestFilter<Result extends Record<string, unknown>> {
readonly params: {
filters: FilterDefinitions;
paths: Path[];
};
private _fn;
private _selectFn;
private _filtersFn;
private _filterPaths;
hasWildcardPath: boolean | undefined;
hasAggregatePath: boolean | undefined;
constructor(params: {
filters: FilterDefinitions;
paths: Path[];
});
static fromQuery(query: string, opts?: PostgrestQueryParserOptions): PostgrestFilter<Record<string, unknown>>;
static fromBuilder<Result extends Record<string, unknown> = Record<string, unknown>>(fb: MaybeLikePostgrestBuilder<Result>, opts?: PostgrestQueryParserOptions): PostgrestFilter<Result>;
denormalize<Type extends Record<string, unknown>>(obj: Type): Type;
apply(obj: unknown): obj is Result;
applyFilters(obj: unknown): obj is Result;
hasFiltersOnPaths(paths: string[]): boolean;
applyFiltersOnPaths(obj: unknown, paths: string[]): obj is Result;
hasPaths(obj: unknown): obj is Result;
private hasPathRecursive;
private applyFilterFn;
private buildFilterFn;
}
type RevalidateRelationOpt<Type> = {
schema?: string;
relation: string;
relationIdColumn: string;
fKeyColumn: keyof Type;
};
type RevalidateRelations<Type extends Record<string, unknown>> = RevalidateRelationOpt<Type>[];
type RevalidateTableOpt = {
schema?: string;
table: string;
};
type RevalidateTables = RevalidateTableOpt[];
type RevalidateOpts<Type extends Record<string, unknown>> = {
revalidateTables?: RevalidateTables;
revalidateRelations?: RevalidateRelations<Type>;
};
type MutatorFn<Type> = (currentData: AnyPostgrestResponse<Type> | PostgrestHasMorePaginationResponse<Type> | unknown) => AnyPostgrestResponse<Type> | PostgrestHasMorePaginationResponse<Type> | unknown;
type DecodedKey = {
bodyKey: string | undefined;
orderByKey: string | undefined;
queryKey: string;
count: string | null;
schema: string | undefined;
table: string;
isHead: boolean | undefined;
limit: number | undefined;
offset: number | undefined;
};
declare const getTable: <Result>(query: MaybeLikePostgrestBuilder<Result>) => string;
type PostgrestPaginationCacheData<Result> = Result[][];
declare const isPostgrestPaginationCacheData: <Result>(q: unknown) => q is PostgrestPaginationCacheData<Result>;
type PostgrestHasMorePaginationCacheData<Result> = PostgrestHasMorePaginationResponse<Result>[];
declare const isPostgrestHasMorePaginationCacheData: <Result>(q: unknown) => q is PostgrestHasMorePaginationCacheData<Result>;
/**
* Encodes an object by url-encoding an ordered lists of all paths and their values.
*/
declare const encodeObject: (obj: Record<string, unknown>) => string;
/**
* Decodes a URL-encoded string back into a nested object.
* This is the reverse operation of encodeObject.
*/
declare const decodeObject: (encodedString: string) => Record<string, unknown>;
declare const isPostgrestBuilder: <Result>(q: unknown) => q is PostgrestBuilder<Result>;
declare const isPostgrestTransformBuilder: <Schema extends GenericSchema, Row extends Record<string, unknown>, Result, RelationName = unknown, Relationships = unknown>(q: unknown) => q is PostgrestTransformBuilder<Schema, Row, Result, RelationName, Relationships>;
declare const get: (obj: any, path: string, defaultValue?: any) => any;
declare const setFilterValue: (searchParams: URLSearchParams, path: string, op: string, value: string) => void;
/**
* Safely parse any value to a ValueType
* @param v Any value
* @returns a ValueType
*/
declare const parseValue: (v: any) => ValueType;
/**
* Parses orderByKey back to OrderDefinition
* @param key generated by PostgrestParser
* @returns The parsed OrderDefinition
*/
declare const parseOrderByKey: (v: string) => OrderDefinition[];
declare const parseOrderBy: (searchParams: URLSearchParams) => OrderDefinition[];
declare const findFilters: (f: FilterDefinitions, by: Partial<FilterDefinition>) => FilterDefinition[];
declare function isPlainObject(value: unknown): value is Record<string, unknown>;
type PostgrestCursorPaginationFetcher<Type, Args> = (args: Args) => Promise<Type>;
type PostgrestCursorPaginationKeyDecoder<Args> = (args: Args) => {
orderBy?: string;
uqOrderBy?: string;
};
declare const createCursorPaginationFetcher: <Schema extends GenericSchema, Row extends Record<string, unknown>, Result, Args, Relationships = unknown>(queryFactory: (() => PostgrestTransformBuilder<Schema, Row, Result[], Relationships>) | null, config: {
decode: PostgrestCursorPaginationKeyDecoder<Args>;
orderBy: string;
uqOrderBy?: string;
rpcArgs?: {
orderBy: string;
uqOrderBy?: string;
};
}) => PostgrestCursorPaginationFetcher<PostgrestPaginationResponse<Result>, Args> | null;
type DeleteFetcher<T extends GenericTable, R> = (input: Partial<T['Row']>[]) => Promise<MutationFetcherResponse<R>[] | null>;
type DeleteFetcherOptions<S extends GenericSchema, T extends GenericTable, Re = T extends {
Relationships: infer R;
} ? R : unknown> = Parameters<PostgrestQueryBuilder<S, T, Re>['delete']>[0];
declare const buildDeleteFetcher: <S extends GenericSchema, T extends GenericTable, RelationName, Re = T extends {
Relationships: infer R_1;
} ? R_1 : unknown, Q extends string = "*", R = UnstableGetResult<S, T["Row"], RelationName, Re, Q extends "*" ? "*" : Q>>(qb: PostgrestQueryBuilder<S, T, R>, primaryKeys: (keyof T["Row"])[], opts: BuildNormalizedQueryOps<Q> & DeleteFetcherOptions<S, T, RelationName>) => DeleteFetcher<T, R>;
type DeleteItemOperation<Type extends Record<string, unknown>> = {
table: string;
schema: string;
input: Type;
primaryKeys: (keyof Type)[];
} & RevalidateOpts<Type>;
type DeleteItemCache<KeyType, Type extends Record<string, unknown>> = {
/**
* The keys currently present in the cache
*/
cacheKeys: KeyType[];
/**
* Should return a PostgrestFilter for the given query.
* This is exposed as a function so results can be cached by the cache library.
*/
getPostgrestFilter: (query: string, opts?: PostgrestQueryParserOptions) => Pick<PostgrestFilter<Type>, 'applyFilters' | 'denormalize'>;
/**
* Decode a key. Should return null if not a PostgREST key.
*/
decode: (k: KeyType) => DecodedKey | null;
/**
* The mutation function from the cache library
*/
mutate: (key: KeyType, fn: MutatorFn<Type>) => Promise<void> | void;
/**
* The revalidation function from the cache library
*/
revalidate: (key: KeyType) => Promise<void> | void;
};
declare const deleteItem: <KeyType, Type extends Record<string, unknown>>(op: DeleteItemOperation<Type>, cache: DeleteItemCache<KeyType, Type>) => Promise<void>;
declare const fetcher: <Result>(q: PromiseLike<AnyPostgrestResponse<Result>>) => Promise<AnyPostgrestResponse<Result>>;
type InsertFetcher<T extends GenericTable, R> = (input: T['Insert'][]) => Promise<MutationFetcherResponse<R>[] | null>;
type InsertFetcherOptions<S extends GenericSchema, T extends GenericTable, Re = T extends {
Relationships: infer R;
} ? R : unknown> = Parameters<PostgrestQueryBuilder<S, T, Re>['insert']>[1];
declare function buildInsertFetcher<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>>(qb: PostgrestQueryBuilder<S, T, Re>, opts: BuildNormalizedQueryOps<Q> & InsertFetcherOptions<S, T, Re>): InsertFetcher<T, R>;
declare const mutateOperation: <Type extends Record<string, unknown>>(input: Partial<Type>, mutate: (current: Type) => Type, currentData: Type[], primaryKeys: (keyof Type)[], filter: Pick<PostgrestFilter<Type>, "apply">, orderBy?: OrderDefinition[]) => Type[];
type MutateItemOperation<Type extends Record<string, unknown>> = {
table: string;
schema: string;
input: Partial<Type>;
mutate: (current: Type) => Type;
primaryKeys: (keyof Type)[];
} & RevalidateOpts<Type>;
type MutateItemCache<KeyType, Type extends Record<string, unknown>> = {
/**
* The keys currently present in the cache
*/
cacheKeys: KeyType[];
/**
* Should return a PostgrestFilter for the given query.
* This is exposed as a function so results can be cached by the cache library.
*/
getPostgrestFilter: (query: string, opts?: PostgrestQueryParserOptions) => Pick<PostgrestFilter<Type>, 'applyFilters' | 'denormalize' | 'hasFiltersOnPaths' | 'applyFiltersOnPaths' | 'apply' | 'hasWildcardPath' | 'hasAggregatePath'>;
/**
* Decode a key. Should return null if not a PostgREST key.
*/
decode: (k: KeyType) => DecodedKey | null;
/**
* The mutation function from the cache library
*/
mutate: (key: KeyType, fn: MutatorFn<Type>) => Promise<void> | void;
/**
* The revalidation function from the cache library
*/
revalidate: (key: KeyType) => Promise<void> | void;
};
declare const mutateItem: <KeyType, Type extends Record<string, unknown>>(op: MutateItemOperation<Type>, cache: MutateItemCache<KeyType, Type>) => Promise<void>;
type PostgrestOffsetPaginationFetcher<Type, Args> = (args: Args) => Promise<Type>;
type PostgrestOffsetPaginationKeyDecoder<Args> = (args: Args) => {
limit?: number;
offset?: number;
};
declare const createOffsetPaginationFetcher: <Schema extends GenericSchema, Row extends Record<string, unknown>, Result, Args, RelationName = unknown, Relationships = unknown>(queryFactory: (() => PostgrestTransformBuilder<Schema, Row, Result[], Relationships>) | null, { decode, pageSize, rpcArgs, }: {
decode: PostgrestOffsetPaginationKeyDecoder<Args>;
pageSize: number;
rpcArgs?: {
limit: string;
offset: string;
};
}) => PostgrestOffsetPaginationFetcher<PostgrestPaginationResponse<Result>, Args> | null;
declare const offsetPaginationFetcher: <Schema extends GenericSchema, Row extends Record<string, unknown>, Result, RelationName = unknown, Relationships = unknown>(query: PostgrestTransformBuilder<Schema, Row, Result[], RelationName, Relationships>, { limit, offset }: {
limit: number;
offset: number;
}) => Promise<Result[]>;
declare const rpcOffsetPaginationFetcher: <Schema extends GenericSchema, Row extends Record<string, unknown>, Result, RelationName = unknown, Relationships = unknown>(query: PostgrestTransformBuilder<Schema, Row, Result[], RelationName, Relationships>, { limit, offset, rpcArgs, }: {
limit: number;
offset: number;
rpcArgs: {
limit: string;
offset: string;
};
}) => Promise<Result[]>;
declare const createOffsetPaginationHasMoreFetcher: <Schema extends GenericSchema, Row extends Record<string, unknown>, Result, Args, RelationName = unknown, Relationships = unknown>(queryFactory: (() => PostgrestTransformBuilder<Schema, Row, Result[], RelationName, Relationships>) | null, { decode, pageSize, rpcArgs, }: {
decode: PostgrestOffsetPaginationKeyDecoder<Args>;
pageSize: number;
rpcArgs?: {
limit: string;
offset: string;
};
}) => PostgrestOffsetPaginationFetcher<PostgrestHasMorePaginationResponse<Result>, Args> | null;
declare const offsetPaginationHasMoreFetcher: <Schema extends GenericSchema, Row extends Record<string, unknown>, Result, RelationName = unknown, Relationships = unknown>(query: PostgrestTransformBuilder<Schema, Row, Result[], RelationName, Relationships>, { limit, offset, pageSize, }: {
limit: number;
offset: number;
pageSize: number;
}) => Promise<{
data: Result[];
hasMore: boolean;
}>;
declare const rpcOffsetPaginationHasMoreFetcher: <Schema extends GenericSchema, Row extends Record<string, unknown>, Result, RelationName = unknown, Relationships = unknown>(query: PostgrestTransformBuilder<Schema, Row, Result[], RelationName, Relationships>, { limit, offset, pageSize, rpcArgs, }: {
limit: number;
offset: number;
pageSize: number;
rpcArgs: {
limit: string;
offset: string;
};
}) => Promise<{
data: Result[];
hasMore: boolean;
}>;
declare class PostgrestParser<Result> extends PostgrestQueryParser {
readonly opts?: PostgrestQueryParserOptions | undefined;
private readonly _url;
private readonly _headers;
private readonly _body;
private readonly _method;
readonly queryKey: string;
readonly bodyKey: string | undefined;
readonly count: string | null;
readonly schema: string;
readonly table: string;
readonly isHead: boolean | undefined;
readonly limit: number | undefined;
readonly offset: number | undefined;
readonly orderBy: OrderDefinition[];
readonly orderByKey: string;
constructor(fb: MaybeLikePostgrestBuilder<Result>, opts?: PostgrestQueryParserOptions | undefined);
}
type UpdateFetcher<T extends GenericTable, R> = (input: Partial<T['Row']>) => Promise<MutationFetcherResponse<R> | null>;
type UpdateFetcherOptions<S extends GenericSchema, T extends GenericTable, Re = T extends {
Relationships: infer R;
} ? R : unknown> = Parameters<PostgrestQueryBuilder<S, T, Re>['update']>[1] & {
stripPrimaryKeys?: boolean;
};
declare const buildUpdateFetcher: <S extends GenericSchema, T extends GenericTable, RelationName, Re = T extends {
Relationships: infer R_1;
} ? R_1 : unknown, Q extends string = "*", R = UnstableGetResult<S, T["Row"], RelationName, Re, Q extends "*" ? "*" : Q>>(qb: PostgrestQueryBuilder<S, T, Re>, primaryKeys: (keyof T["Row"])[], { stripPrimaryKeys, ...opts }: BuildNormalizedQueryOps<Q> & UpdateFetcherOptions<S, T>) => UpdateFetcher<T, R>;
type UpsertFetcher<T extends GenericTable, R> = (input: T['Insert'][]) => Promise<MutationFetcherResponse<R>[] | null>;
type UpsertFetcherOptions<S extends GenericSchema, T extends GenericTable, Re = T extends {
Relationships: infer R;
} ? R : unknown> = Parameters<PostgrestQueryBuilder<S, T, Re>['upsert']>[1];
declare const buildUpsertFetcher: <S extends GenericSchema, T extends GenericTable, RelationName, Re = T extends {
Relationships: infer R_1;
} ? R_1 : unknown, Q extends string = "*", R = UnstableGetResult<S, T["Row"], RelationName, Re, Q extends "*" ? "*" : Q>>(qb: PostgrestQueryBuilder<S, T, Re>, opts: BuildNormalizedQueryOps<Q> & UpsertFetcherOptions<S, T>) => UpsertFetcher<T, R>;
type MergeFn<Type extends Record<string, unknown>> = (current: Type, input: Type) => Type;
declare const upsert: <Type extends Record<string, unknown>>(input: Type, currentData: Type[], primaryKeys: (keyof Type)[], filter: Pick<PostgrestFilter<Type>, "apply">, mergeFn?: MergeFn<Type>, orderBy?: OrderDefinition[]) => Type[];
type UpsertItemOperation<Type extends Record<string, unknown>> = {
table: string;
schema: string;
input: Type;
primaryKeys: (keyof Type)[];
merge?: (current: Type, input: Type) => Type;
} & RevalidateOpts<Type>;
type UpsertItemCache<KeyType, Type extends Record<string, unknown>> = {
/**
* The keys currently present in the cache
*/
cacheKeys: KeyType[];
/**
* Should return a PostgrestFilter for the given query.
* This is exposed as a function so results can be cached by the cache library.
*/
getPostgrestFilter: (query: string, opts?: PostgrestQueryParserOptions) => Pick<PostgrestFilter<Type>, 'applyFilters' | 'denormalize' | 'hasFiltersOnPaths' | 'applyFiltersOnPaths' | 'apply' | 'hasWildcardPath' | 'hasAggregatePath'>;
/**
* Decode a key. Should return null if not a PostgREST key.
*/
decode: (k: KeyType) => DecodedKey | null;
/**
* The mutation function from the cache library
*/
mutate: (key: KeyType, fn: MutatorFn<Type>) => Promise<void> | void;
/**
* The revalidation function from the cache library
*/
revalidate: (key: KeyType) => Promise<void> | void;
};
declare const upsertItem: <KeyType, Type extends Record<string, unknown>>(op: UpsertItemOperation<Type>, cache: UpsertItemCache<KeyType, Type>) => Promise<void>;
type RevalidateTablesOperation = RevalidateTables;
type RevalidateTablesCache<KeyType> = {
/**
* The keys currently present in the cache
*/
cacheKeys: KeyType[];
/**
* Decode a key. Should return null if not a PostgREST key.
*/
decode: (k: KeyType) => DecodedKey | null;
/**
* The revalidation function from the cache library
*/
revalidate: (key: KeyType) => Promise<void> | void;
};
declare const revalidateTables: <KeyType>(tables: RevalidateTablesOperation, cache: RevalidateTablesCache<KeyType>) => Promise<void>;
export { type AnyPostgrestResponse, type BuildNormalizedQueryOps, type BuildNormalizedQueryReturn, type DecodedKey, type DeleteFetcher, type DeleteFetcherOptions, type DeleteItemCache, type DeleteItemOperation, type FilterDefinition, type FilterDefinitions, type FilterFn, type FilterOperator, type InsertFetcher, type InsertFetcherOptions, type MutateItemCache, type MutateItemOperation, type MutationFetcherResponse, type MutatorFn, type OperatorFn, type OrderDefinition, type Path, type PostgrestCursorPaginationFetcher, type PostgrestCursorPaginationKeyDecoder, PostgrestFilter, type PostgrestHasMorePaginationCacheData, type PostgrestHasMorePaginationResponse, type PostgrestOffsetPaginationFetcher, type PostgrestOffsetPaginationKeyDecoder, type PostgrestPaginationCacheData, type PostgrestPaginationResponse, PostgrestParser, PostgrestQueryParser, type PostgrestQueryParserOptions, type RevalidateOpts, type RevalidateTablesCache, type RevalidateTablesOperation, SUPPORTED_OPERATORS, type UpdateFetcher, type UpdateFetcherOptions, type UpsertFetcher, type UpsertFetcherOptions, type UpsertItemCache, type UpsertItemOperation, type ValueType, buildDeleteFetcher, buildInsertFetcher, buildMutationFetcherResponse, buildNormalizedQuery, buildUpdateFetcher, buildUpsertFetcher, createCursorPaginationFetcher, createOffsetPaginationFetcher, createOffsetPaginationHasMoreFetcher, decodeObject, deleteItem, encodeObject, fetcher, findFilters, get, getTable, isAndFilter, isAnyPostgrestResponse, isFilterDefinition, isOrFilter, isPlainObject, isPostgrestBuilder, isPostgrestHasMorePaginationCacheData, isPostgrestHasMorePaginationResponse, isPostgrestPaginationCacheData, isPostgrestPaginationResponse, isPostgrestTransformBuilder, mutateItem, mutateOperation, normalizeResponse, offsetPaginationFetcher, offsetPaginationHasMoreFetcher, parseOrderBy, parseOrderByKey, parseValue, revalidateTables, rpcOffsetPaginationFetcher, rpcOffsetPaginationHasMoreFetcher, setFilterValue, upsert, upsertItem };