{"version":3,"sources":["../src/index.ts","../src/lib/use-postgrest-filter-cache.ts","../src/lib/key.ts","../src/lib/use-queries-for-table-loader.ts","../src/cache/use-delete-item.ts","../src/cache/use-mutate-item.ts","../src/cache/use-revalidate-tables.ts","../src/cache/use-upsert-item.ts","../src/mutate/use-delete-many-mutation.ts","../src/mutate/use-delete-mutation.ts","../src/mutate/get-user-response.ts","../src/mutate/use-insert-mutation.ts","../src/mutate/use-update-mutation.ts","../src/mutate/use-upsert-mutation.ts","../src/query/build-query-opts.ts","../src/query/fetch.ts","../src/query/prefetch.ts","../src/query/use-query.ts","../src/subscribe/use-subscription-query.ts","../src/subscribe/use-subscription.ts"],"sourcesContent":["export type {\n  PostgrestHasMorePaginationCacheData,\n  PostgrestPaginationCacheData,\n} from '@supabase-cache-helpers/postgrest-core';\n\nexport * from './cache';\nexport * from './lib';\nexport * from './mutate';\nexport * from './query';\nexport * from './subscribe';\n","import {\n  PostgrestFilter,\n  type PostgrestQueryParserOptions,\n  encodeObject,\n} from '@supabase-cache-helpers/postgrest-core';\nimport { useQueryClient } from '@tanstack/react-query';\n\nexport const POSTGREST_FILTER_KEY_PREFIX = 'postgrest-filter';\n\nexport const usePostgrestFilterCache = <\n  R extends Record<string, unknown>,\n>() => {\n  const queryClient = useQueryClient();\n\n  return (query: string, opts?: PostgrestQueryParserOptions) => {\n    const key = [\n      POSTGREST_FILTER_KEY_PREFIX,\n      query,\n      opts ? encodeObject(opts) : null,\n    ];\n    const cacheData = queryClient.getQueryData(key);\n    if (cacheData instanceof PostgrestFilter) {\n      return cacheData;\n    }\n    const filter = PostgrestFilter.fromQuery(query, opts);\n    queryClient.setQueryData(key, filter);\n    return filter as PostgrestFilter<R>;\n  };\n};\n","import {\n  type DecodedKey,\n  PostgrestParser,\n  isPostgrestBuilder,\n} from '@supabase-cache-helpers/postgrest-core';\n\nexport const KEY_PREFIX = 'postgrest';\nexport const INFINITE_KEY_PREFIX = 'page';\n\nexport type DecodedReactQueryKey = DecodedKey & {\n  isInfinite: boolean;\n  key: string[];\n};\n\nexport const encode = <Result>(key: unknown, isInfinite: boolean): string[] => {\n  if (!isPostgrestBuilder<Result>(key)) {\n    throw new Error('Key is not a PostgrestBuilder');\n  }\n\n  const parser = new PostgrestParser<Result>(key);\n  return [\n    KEY_PREFIX,\n    isInfinite ? INFINITE_KEY_PREFIX : 'null',\n    parser.schema,\n    parser.table,\n    parser.queryKey,\n    parser.bodyKey ?? 'null',\n    `count=${parser.count}`,\n    `head=${parser.isHead}`,\n    parser.orderByKey,\n  ];\n};\n\nexport const decode = (key: unknown): DecodedReactQueryKey | null => {\n  if (!Array.isArray(key)) return null;\n\n  const [\n    prefix,\n    infinitePrefix,\n    schema,\n    table,\n    queryKey,\n    bodyKey,\n    count,\n    head,\n    orderByKey,\n  ] = key;\n\n  // Exit early if not a postgrest key\n  if (prefix !== KEY_PREFIX) return null;\n\n  const params = new URLSearchParams(queryKey);\n  const limit = params.get('limit');\n  const offset = params.get('offset');\n\n  const countValue = count.replace('count=', '');\n\n  return {\n    limit: limit ? Number(limit) : undefined,\n    offset: offset ? Number(offset) : undefined,\n    bodyKey,\n    count: countValue === 'null' ? null : countValue,\n    isHead: head === 'head=true',\n    isInfinite: infinitePrefix === INFINITE_KEY_PREFIX,\n    key,\n    queryKey,\n    schema,\n    table,\n    orderByKey,\n  };\n};\n","import { decode } from './key';\nimport { usePostgrestFilterCache } from './use-postgrest-filter-cache';\nimport type { BuildNormalizedQueryOps } from '@supabase-cache-helpers/postgrest-core';\nimport { useQueryClient } from '@tanstack/react-query';\n\nexport const useQueriesForTableLoader = (table: string) => {\n  const queryClient = useQueryClient();\n  const getPostgrestFilter = usePostgrestFilterCache();\n\n  return () =>\n    queryClient\n      .getQueryCache()\n      .getAll()\n      .map((c) => c.queryKey)\n      .reduce<ReturnType<BuildNormalizedQueryOps['queriesForTable']>>(\n        (prev, curr) => {\n          const decodedKey = decode(curr);\n          if (decodedKey?.table === table) {\n            prev.push(getPostgrestFilter(decodedKey.queryKey).params);\n          }\n          return prev;\n        },\n        [],\n      );\n};\n","import { decode, usePostgrestFilterCache } from '../lib';\nimport {\n  type DeleteItemOperation,\n  deleteItem,\n} from '@supabase-cache-helpers/postgrest-core';\nimport { useQueryClient } from '@tanstack/react-query';\nimport { flatten } from 'flat';\n\n/**\n * Convenience hook to delete an item from the react query cache. Does not make any http requests, and is supposed to be used for custom cache updates.\n * @param opts The mutation options\n * @returns void\n */\nexport function useDeleteItem<Type extends Record<string, unknown>>(\n  opts: Omit<DeleteItemOperation<Type>, 'input'>,\n) {\n  const queryClient = useQueryClient();\n  const getPostgrestFilter = usePostgrestFilterCache();\n\n  return async (input: Type) =>\n    await deleteItem(\n      {\n        input: flatten(input) as Type,\n        ...opts,\n      },\n      {\n        cacheKeys: queryClient\n          .getQueryCache()\n          .getAll()\n          .map((c) => c.queryKey),\n        getPostgrestFilter,\n        revalidate: (key) => queryClient.invalidateQueries({ queryKey: key }),\n        mutate: (key, fn) => {\n          queryClient.setQueriesData({ queryKey: key }, fn);\n        },\n        decode,\n      },\n    );\n}\n","import { decode, usePostgrestFilterCache } from '../lib';\nimport {\n  type MutateItemOperation,\n  mutateItem,\n} from '@supabase-cache-helpers/postgrest-core';\nimport { useQueryClient } from '@tanstack/react-query';\nimport { flatten } from 'flat';\n\n/**\n * Convenience hook to mutate an item within the react query cache. Does not make any http requests, and is supposed to be used for custom cache updates.\n * @param opts The mutation options\n * @returns void\n */\nexport function useMutateItem<Type extends Record<string, unknown>>(\n  opts: Omit<MutateItemOperation<Type>, 'input' | 'mutate'>,\n): (input: Partial<Type>, mutateFn: (current: Type) => Type) => Promise<void> {\n  const queryClient = useQueryClient();\n  const getPostgrestFilter = usePostgrestFilterCache();\n\n  return async (input: Partial<Type>, mutateFn: (current: Type) => Type) =>\n    await mutateItem(\n      {\n        input: flatten(input) as Partial<Type>,\n        mutate: mutateFn,\n        ...opts,\n      },\n      {\n        cacheKeys: queryClient\n          .getQueryCache()\n          .getAll()\n          .map((c) => c.queryKey),\n        getPostgrestFilter,\n        revalidate: (key) => queryClient.invalidateQueries({ queryKey: key }),\n        mutate: (key, fn) => {\n          queryClient.setQueriesData({ queryKey: key }, fn);\n        },\n        decode,\n      },\n    );\n}\n","import { decode } from '../lib';\nimport {\n  type RevalidateTablesOperation,\n  revalidateTables,\n} from '@supabase-cache-helpers/postgrest-core';\nimport { useQueryClient } from '@tanstack/react-query';\n\n/**\n * Returns a function that can be used to revalidate all queries in the cache that match the tables provided in the `RevalidateTablesOperation`\n * This hook does not make any HTTP requests and is intended to be used for custom cache revalidations.\n *\n * @param opts - The tables to revalidate\n *\n * @returns A function that will revalidate all defined tables when called.\n * **/\nexport function useRevalidateTables(\n  tables: RevalidateTablesOperation,\n): () => Promise<void> {\n  const queryClient = useQueryClient();\n\n  return async () =>\n    await revalidateTables(tables, {\n      cacheKeys: queryClient\n        .getQueryCache()\n        .getAll()\n        .map((c) => c.queryKey),\n      revalidate: (key) => queryClient.invalidateQueries({ queryKey: key }),\n      decode,\n    });\n}\n","import { decode, usePostgrestFilterCache } from '../lib';\nimport {\n  type UpsertItemOperation,\n  upsertItem,\n} from '@supabase-cache-helpers/postgrest-core';\nimport { useQueryClient } from '@tanstack/react-query';\nimport { flatten } from 'flat';\n\n/**\n * Convenience hook to upsert an item into the react query cache. Does not make any http requests, and is supposed to be used for custom cache updates.\n * @param opts The mutation options\n * @returns void\n */\nexport function useUpsertItem<Type extends Record<string, unknown>>(\n  opts: Omit<UpsertItemOperation<Type>, 'input'>,\n) {\n  const queryClient = useQueryClient();\n  const getPostgrestFilter = usePostgrestFilterCache();\n\n  return async (input: Type) =>\n    await upsertItem(\n      {\n        input: flatten(input) as Type,\n        ...opts,\n      },\n      {\n        cacheKeys: queryClient\n          .getQueryCache()\n          .getAll()\n          .map((c) => c.queryKey),\n        getPostgrestFilter,\n        revalidate: (key) => queryClient.invalidateQueries({ queryKey: key }),\n        mutate: (key, fn) => {\n          queryClient.setQueriesData({ queryKey: key }, fn);\n        },\n        decode,\n      },\n    );\n}\n","import { useDeleteItem } from '../cache';\nimport { useQueriesForTableLoader } from '../lib';\nimport type { UsePostgrestMutationOpts } from './types';\nimport {\n  buildDeleteFetcher,\n  getTable,\n} from '@supabase-cache-helpers/postgrest-core';\nimport {\n  GenericSchema,\n  GenericTable,\n} from '@supabase-cache-helpers/postgrest-core';\nimport type {\n  PostgrestClientOptions,\n  PostgrestQueryBuilder,\n} from '@supabase/postgrest-js';\nimport { UnstableGetResult as GetResult } from '@supabase/postgrest-js';\nimport { useMutation } from '@tanstack/react-query';\n\n/**\n * Hook to execute a DELETE mutation\n *\n * @param {PostgrestQueryBuilder<S, T>} qb PostgrestQueryBuilder instance for the table\n * @param {Array<keyof T['Row']>} primaryKeys Array of primary keys of the table\n * @param {string | null} query Optional PostgREST query string for the DELETE mutation\n * @param {Omit<UsePostgrestMutationOpts<S, T, 'DeleteOne', Q, R>, 'mutationFn'>} [opts] Options to configure the hook\n */\nfunction useDeleteManyMutation<\n  O extends PostgrestClientOptions,\n  S extends GenericSchema,\n  T extends GenericTable,\n  RelationName extends string,\n  Re = T extends { Relationships: infer R } ? R : unknown,\n  Q extends string = '*',\n  R = GetResult<S, T['Row'], RelationName, Re, Q extends '*' ? '*' : Q, O>,\n>(\n  qb: PostgrestQueryBuilder<O, S, T, RelationName, Re>,\n  primaryKeys: (keyof T['Row'])[],\n  query?: Q | null,\n  opts?: Omit<\n    UsePostgrestMutationOpts<'DeleteMany', S, T, RelationName, Re, Q, R>,\n    'mutationFn'\n  >,\n) {\n  const queriesForTable = useQueriesForTableLoader(getTable(qb));\n  const deleteItem = useDeleteItem({\n    ...opts,\n    primaryKeys,\n    table: getTable(qb),\n    schema: qb.schema as string,\n  });\n\n  return useMutation({\n    mutationFn: async (input) => {\n      const result = await buildDeleteFetcher<O, S, T, RelationName, Re, Q, R>(\n        qb,\n        primaryKeys,\n        {\n          query: query ?? undefined,\n          queriesForTable,\n          disabled: opts?.disableAutoQuery,\n          ...opts,\n        },\n      )(input);\n\n      if (result) {\n        for (const r of result) {\n          deleteItem(r.normalizedData as T['Row']);\n        }\n      }\n\n      if (!result || result.every((r) => !r.userQueryData)) return null;\n\n      return result.map((r) => r.userQueryData as R);\n    },\n    ...opts,\n  });\n}\n\nexport { useDeleteManyMutation };\n","import { useDeleteItem } from '../cache';\nimport { useQueriesForTableLoader } from '../lib';\nimport type { UsePostgrestMutationOpts } from './types';\nimport {\n  buildDeleteFetcher,\n  getTable,\n} from '@supabase-cache-helpers/postgrest-core';\nimport {\n  GenericSchema,\n  GenericTable,\n} from '@supabase-cache-helpers/postgrest-core';\nimport type {\n  PostgrestClientOptions,\n  PostgrestQueryBuilder,\n} from '@supabase/postgrest-js';\nimport { UnstableGetResult as GetResult } from '@supabase/postgrest-js';\nimport { useMutation } from '@tanstack/react-query';\n\n/**\n * Hook to execute a DELETE mutation\n *\n * @param {PostgrestQueryBuilder<S, T>} qb PostgrestQueryBuilder instance for the table\n * @param {Array<keyof T['Row']>} primaryKeys Array of primary keys of the table\n * @param {string | null} query Optional PostgREST query string for the DELETE mutation\n * @param {Omit<UsePostgrestMutationOpts<S, T, 'DeleteOne', Q, R>, 'mutationFn'>} [opts] Options to configure the hook\n */\nfunction useDeleteMutation<\n  O extends PostgrestClientOptions,\n  S extends GenericSchema,\n  T extends GenericTable,\n  RelationName extends string,\n  Re = T extends { Relationships: infer R } ? R : unknown,\n  Q extends string = '*',\n  R = GetResult<S, T['Row'], RelationName, Re, Q extends '*' ? '*' : Q, O>,\n>(\n  qb: PostgrestQueryBuilder<O, S, T, RelationName, Re>,\n  primaryKeys: (keyof T['Row'])[],\n  query?: Q | null,\n  opts?: Omit<\n    UsePostgrestMutationOpts<'DeleteOne', S, T, RelationName, Re, Q, R>,\n    'mutationFn'\n  >,\n) {\n  const queriesForTable = useQueriesForTableLoader(getTable(qb));\n  const deleteItem = useDeleteItem({\n    ...opts,\n    primaryKeys,\n    table: getTable(qb),\n    schema: qb.schema as string,\n  });\n\n  return useMutation({\n    mutationFn: async (input) => {\n      const r = await buildDeleteFetcher<O, S, T, RelationName, Re, Q, R>(\n        qb,\n        primaryKeys,\n        {\n          query: query ?? undefined,\n          queriesForTable,\n          disabled: opts?.disableAutoQuery,\n          ...opts,\n        },\n      )([input]);\n\n      if (!r) return null;\n\n      const result = r[0];\n\n      if (result) {\n        await deleteItem(result.normalizedData as T['Row']);\n      }\n      return result?.userQueryData ?? null;\n    },\n    ...opts,\n  });\n}\n\nexport { useDeleteMutation };\n","import type { MutationFetcherResponse } from '@supabase-cache-helpers/postgrest-core';\n\ntype Truthy<T> = T extends false | '' | 0 | null | undefined ? never : T; // from lodash\n\nexport function truthy<T>(value: T): value is Truthy<T> {\n  return !!value;\n}\n\nexport const getUserResponse = <R>(\n  d: MutationFetcherResponse<R>[] | null | undefined,\n) => {\n  if (!d) return d;\n  return d.map((r) => r.userQueryData).filter(truthy);\n};\n","import { useUpsertItem } from '../cache';\nimport { useQueriesForTableLoader } from '../lib';\nimport { getUserResponse } from './get-user-response';\nimport type { UsePostgrestMutationOpts } from './types';\nimport {\n  buildInsertFetcher,\n  getTable,\n} from '@supabase-cache-helpers/postgrest-core';\nimport {\n  GenericSchema,\n  GenericTable,\n} from '@supabase-cache-helpers/postgrest-core';\nimport type {\n  PostgrestClientOptions,\n  PostgrestQueryBuilder,\n} from '@supabase/postgrest-js';\nimport { UnstableGetResult as GetResult } from '@supabase/postgrest-js';\nimport { useMutation } from '@tanstack/react-query';\n\n/**\n * Hook to execute a INSERT mutation\n *\n * @param {PostgrestQueryBuilder<S, T>} qb PostgrestQueryBuilder instance for the table\n * @param {Array<keyof T['Row']>} primaryKeys Array of primary keys of the table\n * @param {string | null} query Optional PostgREST query string for the INSERT mutation\n * @param {Omit<UsePostgrestMutationOpts<S, T, 'Insert', Q, R>, 'mutationFn'>} [opts] Options to configure the hook\n */\nfunction useInsertMutation<\n  O extends PostgrestClientOptions,\n  S extends GenericSchema,\n  T extends GenericTable,\n  RelationName extends string,\n  Re = T extends { Relationships: infer R } ? R : unknown,\n  Q extends string = '*',\n  R = GetResult<S, T['Row'], RelationName, Re, Q extends '*' ? '*' : Q, O>,\n>(\n  qb: PostgrestQueryBuilder<O, S, T, RelationName, Re>,\n  primaryKeys: (keyof T['Row'])[],\n  query?: Q | null,\n  opts?: Omit<\n    UsePostgrestMutationOpts<'Insert', S, T, RelationName, Re, Q, R>,\n    'mutationFn'\n  >,\n) {\n  const queriesForTable = useQueriesForTableLoader(getTable(qb));\n  const upsertItem = useUpsertItem({\n    ...opts,\n    primaryKeys,\n    table: getTable(qb),\n    schema: qb.schema as string,\n  });\n\n  return useMutation({\n    mutationFn: async (input) => {\n      const result = await buildInsertFetcher<O, S, T, RelationName, Re, Q, R>(\n        qb,\n        {\n          query: query ?? undefined,\n          queriesForTable,\n          disabled: opts?.disableAutoQuery,\n          ...opts,\n        },\n      )(input);\n\n      if (result) {\n        await Promise.all(\n          result.map(\n            async (d) => await upsertItem(d.normalizedData as T['Row']),\n          ),\n        );\n      }\n      return getUserResponse(result) ?? null;\n    },\n    ...opts,\n  });\n}\n\nexport { useInsertMutation };\n","import { useUpsertItem } from '../cache';\nimport { useQueriesForTableLoader } from '../lib';\nimport type { UsePostgrestMutationOpts } from './types';\nimport {\n  buildUpdateFetcher,\n  getTable,\n} from '@supabase-cache-helpers/postgrest-core';\nimport {\n  GenericSchema,\n  GenericTable,\n} from '@supabase-cache-helpers/postgrest-core';\nimport {\n  PostgrestClientOptions,\n  PostgrestQueryBuilder,\n} from '@supabase/postgrest-js';\nimport { UnstableGetResult as GetResult } from '@supabase/postgrest-js';\nimport { useMutation } from '@tanstack/react-query';\n\n/**\n * Hook to execute a UPDATE mutation\n *\n * @param {PostgrestQueryBuilder<S, T>} qb PostgrestQueryBuilder instance for the table\n * @param {Array<keyof T['Row']>} primaryKeys Array of primary keys of the table\n * @param {string | null} query Optional PostgREST query string for the UPDATE mutation\n * @param {Omit<UsePostgrestMutationOpts<S, T, 'UpdateOne', Q, R>, 'mutationFn'>} [opts] Options to configure the hook\n */\nfunction useUpdateMutation<\n  O extends PostgrestClientOptions,\n  S extends GenericSchema,\n  T extends GenericTable,\n  RelationName extends string,\n  Relationships = T extends { Relationships: infer R } ? R : unknown,\n  Q extends string = '*',\n  R = GetResult<\n    S,\n    T['Row'],\n    RelationName,\n    Relationships,\n    Q extends '*' ? '*' : Q,\n    O\n  >,\n>(\n  qb: PostgrestQueryBuilder<O, S, T, RelationName, Relationships>,\n  primaryKeys: (keyof T['Row'])[],\n  query?: Q | null,\n  opts?: Omit<\n    UsePostgrestMutationOpts<\n      'UpdateOne',\n      S,\n      T,\n      RelationName,\n      Relationships,\n      Q,\n      R\n    >,\n    'mutationFn'\n  >,\n) {\n  const queriesForTable = useQueriesForTableLoader(getTable(qb));\n  const upsertItem = useUpsertItem({\n    ...opts,\n    primaryKeys,\n    table: getTable(qb),\n    schema: qb.schema as string,\n  });\n\n  return useMutation({\n    mutationFn: async (input) => {\n      const result = await buildUpdateFetcher<\n        O,\n        S,\n        T,\n        RelationName,\n        Relationships,\n        Q,\n        R\n      >(qb, primaryKeys, {\n        query: query ?? undefined,\n        queriesForTable,\n        disabled: opts?.disableAutoQuery,\n        ...opts,\n      })(input);\n      if (result) {\n        await upsertItem(result.normalizedData as T['Row']);\n      }\n      return result?.userQueryData ?? null;\n    },\n    ...opts,\n  });\n}\n\nexport { useUpdateMutation };\n","import { useUpsertItem } from '../cache';\nimport { useQueriesForTableLoader } from '../lib';\nimport { getUserResponse } from './get-user-response';\nimport type { UsePostgrestMutationOpts } from './types';\nimport {\n  buildUpsertFetcher,\n  getTable,\n} from '@supabase-cache-helpers/postgrest-core';\nimport {\n  GenericSchema,\n  GenericTable,\n} from '@supabase-cache-helpers/postgrest-core';\nimport type {\n  PostgrestClientOptions,\n  PostgrestQueryBuilder,\n} from '@supabase/postgrest-js';\nimport { UnstableGetResult as GetResult } from '@supabase/postgrest-js';\nimport { useMutation } from '@tanstack/react-query';\n\n/**\n * Hook to execute a UPSERT mutation\n *\n * @param {PostgrestQueryBuilder<S, T>} qb PostgrestQueryBuilder instance for the table\n * @param {Array<keyof T['Row']>} primaryKeys Array of primary keys of the table\n * @param {string | null} query Optional PostgREST query string for the UPSERT mutation\n * @param {Omit<UsePostgrestMutationOpts<S, T, 'Upsert', Q, R>, 'mutationFn'>} [opts] Options to configure the hook\n */\nfunction useUpsertMutation<\n  O extends PostgrestClientOptions,\n  S extends GenericSchema,\n  T extends GenericTable,\n  RelationName extends string,\n  Re = T extends { Relationships: infer R } ? R : unknown,\n  Q extends string = '*',\n  R = GetResult<S, T['Row'], RelationName, Re, Q extends '*' ? '*' : Q, O>,\n>(\n  qb: PostgrestQueryBuilder<O, S, T, RelationName, Re>,\n  primaryKeys: (keyof T['Row'])[],\n  query?: Q | null,\n  opts?: Omit<\n    UsePostgrestMutationOpts<'Upsert', S, T, RelationName, Re, Q, R>,\n    'mutationFn'\n  >,\n) {\n  const queriesForTable = useQueriesForTableLoader(getTable(qb));\n  const upsertItem = useUpsertItem({\n    ...opts,\n    primaryKeys,\n    table: getTable(qb),\n    schema: qb.schema as string,\n  });\n\n  return useMutation({\n    mutationFn: async (input: T['Insert'][]) => {\n      const data = await buildUpsertFetcher<O, S, T, RelationName, Re, Q, R>(\n        qb,\n        {\n          query: query ?? undefined,\n          queriesForTable,\n          disabled: opts?.disableAutoQuery,\n          ...opts,\n        },\n      )(input);\n      if (data) {\n        await Promise.all(\n          data.map(async (d) => await upsertItem(d.normalizedData as T['Row'])),\n        );\n      }\n      return getUserResponse(data) ?? null;\n    },\n    ...opts,\n  });\n}\n\nexport { useUpsertMutation };\n","import { encode } from '../lib/key';\nimport {\n  type AnyPostgrestResponse,\n  isPostgrestBuilder,\n  isPostgrestTransformBuilder,\n} from '@supabase-cache-helpers/postgrest-core';\nimport type { PostgrestError } from '@supabase/postgrest-js';\nimport type { UseQueryOptions as UseReactQueryOptions } from '@tanstack/react-query';\n\nexport function buildQueryOpts<Result>(\n  query: PromiseLike<AnyPostgrestResponse<Result>>,\n  config?: Omit<\n    UseReactQueryOptions<AnyPostgrestResponse<Result>, PostgrestError>,\n    'queryKey' | 'queryFn'\n  >,\n): UseReactQueryOptions<AnyPostgrestResponse<Result>, PostgrestError> {\n  return {\n    queryKey: encode<Result>(query, false),\n    queryFn: async ({ signal }) => {\n      if (isPostgrestTransformBuilder(query)) {\n        query = query.abortSignal(signal);\n      }\n      if (isPostgrestBuilder(query)) {\n        query = query.throwOnError();\n      }\n      return await query;\n    },\n    ...config,\n  };\n}\n","import { buildQueryOpts } from './build-query-opts';\nimport type { AnyPostgrestResponse } from '@supabase-cache-helpers/postgrest-core';\nimport type {\n  PostgrestError,\n  PostgrestMaybeSingleResponse,\n  PostgrestResponse,\n  PostgrestSingleResponse,\n} from '@supabase/postgrest-js';\nimport type { FetchQueryOptions, QueryClient } from '@tanstack/react-query';\n\nfunction fetchQuery<Result>(\n  queryClient: QueryClient,\n  query: PromiseLike<PostgrestSingleResponse<Result>>,\n  config?: Omit<\n    FetchQueryOptions<PostgrestSingleResponse<Result>, PostgrestError>,\n    'queryKey' | 'queryFn'\n  >,\n): Promise<PostgrestSingleResponse<Result>>;\nfunction fetchQuery<Result>(\n  queryClient: QueryClient,\n  query: PromiseLike<PostgrestMaybeSingleResponse<Result>>,\n  config?: Omit<\n    FetchQueryOptions<PostgrestMaybeSingleResponse<Result>, PostgrestError>,\n    'queryKey' | 'queryFn'\n  >,\n): Promise<PostgrestMaybeSingleResponse<Result>>;\nfunction fetchQuery<Result>(\n  queryClient: QueryClient,\n  query: PromiseLike<PostgrestResponse<Result>>,\n  config?: Omit<\n    FetchQueryOptions<PostgrestResponse<Result>, PostgrestError>,\n    'queryKey' | 'queryFn'\n  >,\n): Promise<PostgrestResponse<Result>>;\n\nasync function fetchQuery<Result>(\n  queryClient: QueryClient,\n  query: PromiseLike<AnyPostgrestResponse<Result>>,\n  config?: Omit<\n    FetchQueryOptions<AnyPostgrestResponse<Result>, PostgrestError>,\n    'queryKey' | 'queryFn'\n  >,\n): Promise<AnyPostgrestResponse<Result>> {\n  return await queryClient.fetchQuery<\n    AnyPostgrestResponse<Result>,\n    PostgrestError\n  >(buildQueryOpts(query, config));\n}\n\nexport { fetchQuery };\n","import { encode } from '../lib';\nimport { buildQueryOpts } from './build-query-opts';\nimport {\n  type AnyPostgrestResponse,\n  isPostgrestBuilder,\n} from '@supabase-cache-helpers/postgrest-core';\nimport type {\n  PostgrestError,\n  PostgrestMaybeSingleResponse,\n  PostgrestResponse,\n  PostgrestSingleResponse,\n} from '@supabase/postgrest-js';\nimport type { FetchQueryOptions, QueryClient } from '@tanstack/react-query';\n\nfunction prefetchQuery<Result>(\n  queryClient: QueryClient,\n  query: PromiseLike<PostgrestSingleResponse<Result>>,\n  config?: Omit<\n    FetchQueryOptions<PostgrestSingleResponse<Result>, PostgrestError>,\n    'queryKey' | 'queryFn'\n  >,\n): Promise<void>;\nfunction prefetchQuery<Result>(\n  queryClient: QueryClient,\n  query: PromiseLike<PostgrestMaybeSingleResponse<Result>>,\n  config?: Omit<\n    FetchQueryOptions<PostgrestMaybeSingleResponse<Result>, PostgrestError>,\n    'queryKey' | 'queryFn'\n  >,\n): Promise<void>;\nfunction prefetchQuery<Result>(\n  queryClient: QueryClient,\n  query: PromiseLike<PostgrestResponse<Result>>,\n  config?: Omit<\n    FetchQueryOptions<PostgrestResponse<Result>, PostgrestError>,\n    'queryKey' | 'queryFn'\n  >,\n): Promise<void>;\n\nasync function prefetchQuery<Result>(\n  queryClient: QueryClient,\n  query: PromiseLike<AnyPostgrestResponse<Result>>,\n  config?: Omit<\n    FetchQueryOptions<AnyPostgrestResponse<Result>, PostgrestError>,\n    'queryKey' | 'queryFn'\n  >,\n) {\n  await queryClient.prefetchQuery<AnyPostgrestResponse<Result>, PostgrestError>(\n    buildQueryOpts(query, config),\n  );\n}\n\nfunction fetchQueryInitialData<Result>(\n  query: PromiseLike<PostgrestSingleResponse<Result>>,\n): Promise<[string[], PostgrestSingleResponse<Result>]>;\n\nfunction fetchQueryInitialData<Result>(\n  query: PromiseLike<PostgrestMaybeSingleResponse<Result>>,\n): Promise<[string[], PostgrestMaybeSingleResponse<Result>]>;\n\nfunction fetchQueryInitialData<Result>(\n  query: PromiseLike<PostgrestResponse<Result>>,\n): Promise<[string[], PostgrestResponse<Result>]>;\n\nasync function fetchQueryInitialData<Result>(\n  query: PromiseLike<AnyPostgrestResponse<Result>>,\n): Promise<[string[], AnyPostgrestResponse<Result>]> {\n  if (!isPostgrestBuilder<Result>(query)) {\n    throw new Error('Query is not a PostgrestBuilder');\n  }\n\n  return [encode(query, false), await query.throwOnError()];\n}\n\nexport { prefetchQuery, fetchQueryInitialData };\n","import { buildQueryOpts } from './build-query-opts';\nimport type { AnyPostgrestResponse } from '@supabase-cache-helpers/postgrest-core';\nimport type {\n  PostgrestError,\n  PostgrestMaybeSingleResponse,\n  PostgrestResponse,\n  PostgrestSingleResponse,\n} from '@supabase/postgrest-js';\nimport {\n  type UseQueryOptions as UseReactQueryOptions,\n  type UseQueryResult as UseReactQueryResult,\n  useQuery as useReactQuery,\n} from '@tanstack/react-query';\n\n/**\n * Applies Omit over a union, while preserving its union-ness.\n */\ntype DistributiveOmit<T, K extends keyof any> = T extends any\n  ? Omit<T, K>\n  : never;\n\n/**\n * Represents the return value of the `useQuery` hook when `query` is expected to return\n * a single row.\n */\nexport type UseQuerySingleReturn<Result> = DistributiveOmit<\n  UseReactQueryResult<PostgrestSingleResponse<Result>['data'], PostgrestError>,\n  'refetch'\n> &\n  Pick<\n    UseReactQueryResult<PostgrestSingleResponse<Result>, PostgrestError>,\n    'refetch'\n  > &\n  Pick<PostgrestSingleResponse<Result>, 'count'>;\n\n/**\n * Represents the return value of the `useQuery` hook when `query` is expected to return\n * either a single row or an empty response.\n */\nexport type UseQueryMaybeSingleReturn<Result> = DistributiveOmit<\n  UseReactQueryResult<\n    PostgrestMaybeSingleResponse<Result>['data'],\n    PostgrestError\n  >,\n  'refetch'\n> &\n  Pick<\n    UseReactQueryResult<PostgrestMaybeSingleResponse<Result>, PostgrestError>,\n    'refetch'\n  > &\n  Pick<PostgrestMaybeSingleResponse<Result>, 'count'>;\n\n/**\n * Represents the return value of the `useQuery` hook when `query` is expected to return\n * one or more rows.\n */\nexport type UseQueryReturn<Result> = DistributiveOmit<\n  UseReactQueryResult<PostgrestResponse<Result>['data'], PostgrestError>,\n  'refetch'\n> &\n  Pick<\n    UseReactQueryResult<PostgrestResponse<Result>, PostgrestError>,\n    'refetch'\n  > &\n  Pick<PostgrestResponse<Result>, 'count'>;\n\n/**\n * Represents the return value of the `useQuery` hook when the type of the query response\n * is not known.\n */\nexport type UseQueryAnyReturn<Result> = DistributiveOmit<\n  UseReactQueryResult<AnyPostgrestResponse<Result>['data'], PostgrestError>,\n  'refetch'\n> &\n  Pick<\n    UseReactQueryResult<AnyPostgrestResponse<Result>, PostgrestError>,\n    'refetch'\n  > &\n  Pick<AnyPostgrestResponse<Result>, 'count'>;\n\n/**\n * React hook to execute a PostgREST query and return a single item response.\n *\n * @param {PromiseLike<PostgrestSingleResponse<Result>>} query A promise that resolves to a PostgREST single item response.\n * @param {Omit<UseReactQueryOptions<PostgrestSingleResponse<Result>, PostgrestError>, 'queryKey' | 'queryFn'>} [config] The React Query options.\n * @returns {UseQuerySingleReturn<Result>} The hook result containing the single item response data.\n */\nfunction useQuery<Result>(\n  query: PromiseLike<PostgrestSingleResponse<Result>>,\n  config?: Omit<\n    UseReactQueryOptions<PostgrestSingleResponse<Result>, PostgrestError>,\n    'queryKey' | 'queryFn'\n  >,\n): UseQuerySingleReturn<Result>;\n/**\n * React hook to execute a PostgREST query and return a maybe single item response.\n *\n * @param {PromiseLike<PostgrestMaybeSingleResponse<Result>>} query A promise that resolves to a PostgREST maybe single item response.\n * @param {Omit<UseReactQueryOptions<PostgrestMaybeSingleResponse<Result>, PostgrestError>, 'queryKey' | 'queryFn'>} [config] The React Query options.\n * @returns {UseQueryMaybeSingleReturn<Result>} The hook result containing the maybe single item response data.\n */\nfunction useQuery<Result>(\n  query: PromiseLike<PostgrestMaybeSingleResponse<Result>>,\n  config?: Omit<\n    UseReactQueryOptions<PostgrestMaybeSingleResponse<Result>, PostgrestError>,\n    'queryKey' | 'queryFn'\n  >,\n): UseQueryMaybeSingleReturn<Result>;\n/**\n * React hook to execute a PostgREST query.\n *\n * @template Result The expected response data type.\n * @param {PromiseLike<PostgrestResponse<Result>>} query A promise that resolves to a PostgREST response.\n * @param {Omit<UseReactQueryOptions<PostgrestResponse<Result>, PostgrestError>, 'queryKey' | 'queryFn'>} [config] The React Query options.\n * @returns {UseQueryReturn<Result>} The hook result containing the response data.\n */\nfunction useQuery<Result>(\n  query: PromiseLike<PostgrestResponse<Result>>,\n  config?: Omit<\n    UseReactQueryOptions<PostgrestResponse<Result>, PostgrestError>,\n    'queryKey' | 'queryFn'\n  >,\n): UseQueryReturn<Result>;\n\n/**\n * React hook to execute a PostgREST query.\n *\n * @template Result The expected response data type.\n * @param {PromiseLike<AnyPostgrestResponse<Result>>} query A promise that resolves to a PostgREST response of any kind.\n * @param {Omit<UseReactQueryOptions<AnyPostgrestResponse<Result>, PostgrestError>, 'queryKey' | 'queryFn'>} [config] The React Query options.\n * @returns {UseQueryAnyReturn<Result>} The hook result containing the response data.\n */\nfunction useQuery<Result>(\n  query: PromiseLike<AnyPostgrestResponse<Result>>,\n  config?: Omit<\n    UseReactQueryOptions<AnyPostgrestResponse<Result>, PostgrestError>,\n    'queryKey' | 'queryFn'\n  >,\n): UseQueryAnyReturn<Result> {\n  const result = useReactQuery<AnyPostgrestResponse<Result>, PostgrestError>(\n    buildQueryOpts<Result>(query, config),\n  );\n\n  // isPending and isLoadingError are the only cases in which no data is present\n  if (result.isPending || result.isLoadingError) {\n    return {\n      ...result,\n      data: undefined,\n      count: null,\n    } as UseQueryAnyReturn<Result>;\n  }\n\n  return {\n    ...result,\n    data: result.data?.data,\n    count: result.data?.count,\n  } as UseQueryAnyReturn<Result>;\n}\n\nexport { useQuery };\n","import { useDeleteItem, useUpsertItem } from '../cache';\nimport { useQueriesForTableLoader } from '../lib';\nimport {\n  type RevalidateOpts,\n  buildNormalizedQuery,\n  normalizeResponse,\n} from '@supabase-cache-helpers/postgrest-core';\nimport {\n  GenericSchema,\n  GenericTable,\n} from '@supabase-cache-helpers/postgrest-core';\nimport {\n  UnstableGetResult as GetResult,\n  PostgrestClientOptions,\n} from '@supabase/postgrest-js';\nimport {\n  REALTIME_LISTEN_TYPES,\n  REALTIME_POSTGRES_CHANGES_LISTEN_EVENT,\n  type RealtimeChannel,\n  type RealtimePostgresChangesFilter,\n  type RealtimePostgresChangesPayload,\n  type SupabaseClient,\n} from '@supabase/supabase-js';\nimport type { MutationOptions as ReactQueryMutatorOptions } from '@tanstack/react-query';\nimport { useEffect, useState } from 'react';\n\n/**\n * Options for `useSubscriptionQuery` hook\n */\nexport type UseSubscriptionQueryOpts<\n  S extends GenericSchema,\n  T extends GenericTable,\n  RelationName extends string,\n  Re = T extends { Relationships: infer R } ? R : unknown,\n  Q extends string = '*',\n  R = GetResult<\n    S,\n    T['Row'],\n    RelationName,\n    Re,\n    Q extends '*' ? '*' : Q,\n    PostgrestClientOptions\n  >,\n> = RevalidateOpts<T['Row']> &\n  ReactQueryMutatorOptions & {\n    /**\n     * A callback that will be called whenever a realtime event occurs for the given channel.\n     * The callback will receive the event payload with an additional \"data\" property, which will be\n     * the affected row of the event (or a modified version of it, if a select query is provided).\n     */\n    callback?: (\n      event: RealtimePostgresChangesPayload<T['Row']> & { data: T['Row'] | R },\n    ) => void | Promise<void>;\n  };\n\n/**\n * A hook for subscribing to realtime Postgres events on a given channel.\n *\n * The subscription will automatically update the cache for the specified table in response\n * to incoming Postgres events, and optionally run a user-provided callback function with the\n * event and the updated data.\n *\n * This hook works by creating a Supabase Realtime channel for the specified table and\n * subscribing to Postgres changes on that channel. When an event is received, the hook\n * fetches the updated data from the database (using a `select` query generated from the cache\n * configuration), and then updates the cache accordingly.\n *\n * @param client - The Supabase client instance.\n * @param channelName - The name of the channel to subscribe to.\n * @param filter - The filter object to use when listening for changes.\n * @param primaryKeys - An array of the primary keys for the table being listened to.\n * @param query - An optional PostgREST query to use when selecting data for an event.\n * @param opts - Additional options to pass to the hook.\n * @returns An object containing the RealtimeChannel and the current status of the subscription.\n */\nfunction useSubscriptionQuery<\n  S extends GenericSchema,\n  T extends GenericTable,\n  RelationName extends string,\n  Re = T extends { Relationships: infer R } ? R : unknown,\n  Q extends string = '*',\n  R = GetResult<\n    S,\n    T['Row'],\n    RelationName,\n    Re,\n    Q extends '*' ? '*' : Q,\n    PostgrestClientOptions\n  >,\n>(\n  client: SupabaseClient | null,\n  channelName: string,\n  filter: Omit<\n    RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.ALL}`>,\n    'table'\n  > & {\n    table: RelationName;\n  },\n  primaryKeys: (keyof T['Row'])[],\n  query?: Q extends '*' ? \"'*' is not allowed\" : Q | null,\n  opts?: UseSubscriptionQueryOpts<S, T, RelationName, Re, Q, R>,\n) {\n  const [status, setStatus] = useState<string>();\n  const [channel, setChannel] = useState<RealtimeChannel>();\n  const queriesForTable = useQueriesForTableLoader(filter.table);\n  const deleteItem = useDeleteItem({\n    ...opts,\n    primaryKeys,\n    table: filter.table,\n    schema: filter.schema,\n  });\n  const upsertItem = useUpsertItem({\n    ...opts,\n    primaryKeys,\n    table: filter.table,\n    schema: filter.schema,\n  });\n\n  useEffect(() => {\n    if (!client) return;\n\n    const c = client\n      .channel(channelName)\n      .on<T['Row']>(\n        REALTIME_LISTEN_TYPES.POSTGRES_CHANGES,\n        filter,\n        async (payload) => {\n          let data: T['Row'] | R = payload.new ?? payload.old;\n          const selectQuery = buildNormalizedQuery({ queriesForTable, query });\n          if (\n            payload.eventType !==\n              REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE &&\n            selectQuery\n          ) {\n            const qb = client\n              .from(payload.table)\n              .select(selectQuery.selectQuery);\n            for (const pk of primaryKeys) {\n              qb.eq(pk.toString(), data[pk]);\n            }\n            const res = await qb.single();\n            if (res.data) {\n              data = normalizeResponse(selectQuery.groupedPaths, res.data) as R;\n            }\n          }\n\n          if (\n            payload.eventType ===\n              REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.INSERT ||\n            payload.eventType === REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.UPDATE\n          ) {\n            await upsertItem(data as Record<string, unknown>);\n          } else if (\n            payload.eventType === REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE\n          ) {\n            await deleteItem(payload.old);\n          }\n          if (opts?.callback) {\n            opts.callback({\n              ...payload,\n              data,\n            });\n          }\n        },\n      )\n      .subscribe((status: string) => setStatus(status));\n\n    setChannel(c);\n\n    return () => {\n      if (c) c.unsubscribe();\n    };\n  }, []);\n\n  return { channel, status };\n}\n\nexport { useSubscriptionQuery };\n","import { useDeleteItem, useUpsertItem } from '../cache';\nimport type { RevalidateOpts } from '@supabase-cache-helpers/postgrest-core';\nimport type { GenericTable } from '@supabase-cache-helpers/postgrest-core';\nimport {\n  REALTIME_LISTEN_TYPES,\n  REALTIME_POSTGRES_CHANGES_LISTEN_EVENT,\n  type RealtimePostgresChangesFilter,\n  type RealtimePostgresChangesPayload,\n  type SupabaseClient,\n} from '@supabase/supabase-js';\nimport type { MutationOptions as ReactQueryMutatorOptions } from '@tanstack/react-query';\nimport { useEffect, useState } from 'react';\n\n/**\n * Options for the `useSubscription` hook.\n */\nexport type UseSubscriptionOpts<T extends GenericTable> = RevalidateOpts<\n  T['Row']\n> &\n  ReactQueryMutatorOptions & {\n    callback?: (\n      event: RealtimePostgresChangesPayload<T['Row']>,\n    ) => void | Promise<void>;\n  };\n\n/**\n * Hook that sets up a real-time subscription to a Postgres database table.\n *\n * @param channel - The real-time channel to subscribe to.\n * @param filter - A filter that specifies the table and conditions for the subscription.\n * @param primaryKeys - An array of primary key column names for the table.\n * @param opts - Options for the mutation function used to upsert or delete rows in the cache.\n *\n * @returns An object containing the current status of the subscription.\n */\nfunction useSubscription<T extends GenericTable>(\n  client: SupabaseClient | null,\n  channelName: string,\n  filter: Omit<\n    RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.ALL}`>,\n    'table'\n  > & {\n    table: string;\n  },\n  primaryKeys: (keyof T['Row'])[],\n  opts?: UseSubscriptionOpts<T>,\n) {\n  const [status, setStatus] = useState<string>();\n  const deleteItem = useDeleteItem({\n    ...opts,\n    primaryKeys,\n    table: filter.table,\n    schema: filter.schema,\n  });\n  const upsertItem = useUpsertItem({\n    ...opts,\n    primaryKeys,\n    table: filter.table,\n    schema: filter.schema,\n  });\n\n  useEffect(() => {\n    if (!client) return;\n\n    const c = client\n      .channel(channelName)\n      .on<T['Row']>(\n        REALTIME_LISTEN_TYPES.POSTGRES_CHANGES,\n        filter,\n        async (payload) => {\n          if (\n            payload.eventType ===\n              REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.INSERT ||\n            payload.eventType === REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.UPDATE\n          ) {\n            await upsertItem(payload.new);\n          } else if (\n            payload.eventType === REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE\n          ) {\n            await deleteItem(payload.old);\n          }\n          if (opts?.callback) {\n            opts.callback({\n              ...payload,\n            });\n          }\n        },\n      )\n      .subscribe((status: string) => setStatus(status));\n\n    return () => {\n      if (c) c.unsubscribe();\n    };\n  }, []);\n\n  return { status };\n}\n\nexport { useSubscription };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,4BAIO;AACP,yBAA+B;AAExB,IAAM,8BAA8B;AAEpC,IAAM,0BAA0B,MAEhC;AACL,QAAM,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react_query","import_postgrest_core","import_react_query","import_flat","import_postgrest_core","import_react_query","import_postgrest_core","import_react_query","import_flat","import_postgrest_core","import_react_query","deleteItem","import_postgrest_core","import_react_query","deleteItem","import_postgrest_core","import_react_query","upsertItem","import_postgrest_core","import_react_query","upsertItem","import_postgrest_core","import_react_query","upsertItem","import_postgrest_core","import_postgrest_core","import_react_query","useReactQuery","import_postgrest_core","deleteItem","upsertItem","status","import_supabase_js","import_react","deleteItem","upsertItem","status"]}