stable

tanstack-query

Framework-free TanStack Query adapter — {queryKey, queryFn}/mutationFn option factories plus bindInvalidation() for auto-invalidation on change events.

@noy-db/in-tanstack-query · pnpm add @noy-db/hub @noy-db/in-tanstack-query TanStack Query adapter for noy-db — framework-agnostic (React / Vue / Solid / Svelte).

What it does

Exports plain option factories, not hooks: collectionListOptions, collectionGetOptions, and collectionQueryOptions each return { queryKey, queryFn } ready for any TanStack framework's useQuery(); collectionPutOptions / collectionDeleteOptions return the useMutation() equivalent. collectionQueryKey(vault, collection, ...extra) builds the canonical key. bindInvalidation() subscribes to a Collection's change stream and calls the query client's invalidateQueries on the matching keys automatically — a drop-in replacement for ad-hoc invalidateQueries calls scattered through mutation callbacks. Because these are factories rather than hooks, the same code works unmodified across every TanStack framework binding.

Usage

import { useQuery } from '@tanstack/react-query'
import { collectionListOptions } from '@noy-db/in-tanstack-query'

const { data } = useQuery(
  collectionListOptions('acme', 'invoices', () => vault.collection('invoices')),
)

See also