query_kit 1.1.0
query_kit: ^1.1.0 copied to clipboard
TanStack Query for Dart: a port of query-core with caching, background refetching, retries and mutations, no Flutter needed. AI-coded, not affiliated with TanStack.
Changelog #
1.1.0 #
Typed query definitions. A definition declares a query once, with its key, its input, its data type and its options. Calling it gives a reference to one cache entry, and the reference reads, writes, fetches and invalidates that entry with the declared type, so a call site names no key and no type argument.
The new types
QueryDefinitionandQueryFamilydeclare a query without and with an input.InfiniteQueryDefinitionandInfiniteQueryFamilydo the same for a paged query.QueryRefandInfiniteQueryRefare references to one entry. A family gives one when it is called with an input, and a definition without an input is its own reference.QueryEntryRefis what the two have in common, for a function that needs only the cache.TypedQueryKeyis a reference's key together with its data type.QueryNamespaceis a key prefix with no data type, andQueryTargetis anything that can be invalidated, refetched, cancelled, reset or removed: a namespace, a family or a reference.
A reference's options() are ordinary observer options, so they go
wherever options went before. References and typed keys are values: two
are equal when they address the same entry with the same data type.
What is checked, and when
- The analyzer refuses a misspelled definition, an input of the wrong type, a written value or an updater result of the wrong type, and a read assigned to the wrong type. A namespace and a target have no write.
- Some mistakes are found only when the code runs. Write every
definition's type arguments out: left to inference, a family's input or
an infinite definition's page type can become
Object?, or a key-only definition's data typedynamic, and the analyzer does not always say so. A debug build refuses such a definition with anAssertionError; a release build does not check. A reference assigned to a wider type, a cast, or a list literal of references of different data types compiles a write of the wrong type, and the write throws when it runs, before anything is stored. A typed write into an entry of another type throwsQueryDataTypeError. - Nothing checks a raw call on a definition's key, or two definitions of
one key and one data type with different fetch functions, which are one
entry. A record input that holds a list, a map or a set needs a
keyOf, or every call is a new entry.
The typed queries guide lists every limit, with what each one costs and how to avoid it.
Writes
A typed write stores into the entry the cache holds when the value is
stored, or throws. It throws QueryDataTypeError when an entry of another
type has taken that entry's place, and StateError when a cache listener or
the entry's own structuralSharing removed the entry during the write. It
never reports a value it did not store. A bulk updateAll checks every
updater's result and every entry's type before the first write, but it is
not a transaction: a write that fails after others leaves those in place.
Equal options
The options of a definition without an input, held in a field, are equal
from one options() call to the next once the client has applied its
defaults, so an observer handed them again does not report a change. That
holds as long as configure builds nothing new per call. For an infinite
definition it holds when configure returns the same structuralSharing
function or the same InitialData.compute function each time; a closure
written inside configure is a new function on every call. A family
declared with a fetch function wraps it anew for every reference's
options(), so those options are never equal.
Unchanged
The raw QueryKey API is unchanged and not deprecated. A reference and a
raw key with the same parts are the same cache entry, so an app can move
one query at a time, and both forms can read the same entry. The README's
quick start now leads with a typed definition, and shows the raw form after
it.
1.0.4 #
- Move the documentation to https://query-kit.dev/. Update homepage, documentation and README links. No API or behavior changes.
1.0.3 #
- A fetch or a mutation met from another error zone than the one it began
in now reaches that zone. Dart delivers a future's error only within the
error zone the future was made in, so an
await cancelQueriesfrom another zone waited for good,clear,removeQueriesandresetQueriesreported the cancelled fetch'sCancelledErroras uncaught, a caller who joined a fetch or readQuery.futurenever heard that it failed, andresumePausedMutationswaited for good on a mutation that failed. A Flutter app has two error zones as soon as arunZonedGuardedwrapsrunApp, or a widget test's zone meets the binding's: a refetch on focus is started by a platform callback. Within one zone nothing changes. QueryState,MutationStateandDefaultedMutationOptionscompare equal only to a value of the same type arguments. AQueryState<int>and an equalQueryState<num>used to be equal one way and not the other, so aSetheld one or both depending on the order they went in. A comparison between the same type arguments is unchanged.- The errors reference gave a remedy that does not compile for the
UnsupportedErroranInfiniteQueryObserverthrows for plain options. It now names both that do: the infinite options tosetInfiniteOptions, or whatclient.infiniteObserverOptionsmakes of them tosetOptions.
1.0.2 #
No change to the code. The documentation site moved to its own address, https://query-kit.dev/; the package page's homepage and documentation links, the README and the library's dartdoc name it, and the former address redirects there. The README opens with a title a reader searches for, "TanStack Query for Dart | query_kit", instead of the package name, which pub.dev's own heading above it already shows.
1.0.1 #
No change to the code. The package page now names the documentation site, https://query-kit.dev/, as its homepage and documentation, the README opens with a link to it, the quick start, the examples and the API reference, and the description says what the package is: TanStack Query for Dart.
1.0.0 #
First release. query_kit is a Dart port of TanStack Query's query-core:
a cache for server state with no Flutter dependency. The Flutter binding is
query_kit_flutter. From here
on, a breaking change is a major version.
query_kit is an entirely AI-coded project: all code, tests and documentation were written by AI coding agents (Anthropic's Claude). A human maintainer set the goals and reviews releases, but did not write the code. It is a community port, not affiliated with or endorsed by TanStack.
Queries
QueryClientwith aQueryCache: caching byQueryKey,staleTimeandgcTime, request deduplication, retries with backoff (RetryPolicy,RetryDelay) and cancellation throughQueryCancelToken.QueryObserverfor reactive reads, with sealedQueryResults (QueryPending,QuerySuccess,QueryErrorcarrying the last good data).- Refetching on focus, on reconnect, on an interval (
RefetchInterval) and afterinvalidateQueries;Enabledfor dependent and lazy queries. select,InitialData,PlaceholderData(includingPlaceholderData.keepPrevious()) and structural sharing, extendable to your own classes withStructurallyShareable.QueryClient.queryfor imperative reads — fetch, prefetch, "ensure" and stale-while-revalidate in one method.getQueryData,setQueryData,updateQueryData,cancelQueries,refetchQueries,resetQueries,removeQueries,QueryFilters, and per-key defaults throughsetQueryDefaults.consecutiveErrorCounton every result, so polling can give up after N failures.
Mutations
MutationObserverandMutationCache, withonMutate,onSuccess,onErrorandonSettled, optimistic updates and rollback.MutationOptions.simplefor mutations without an optimistic step;mutationFnWithContextandcancel()for cancellable mutations.MutationScopeto run writes one after another; paused mutations resume when the client is back online (resumePausedMutations).MutationStateObserverfor cache-wide mutation state,isMutating.
Infinite queries
InfiniteQueryObserverwithfetchNextPage,fetchPreviousPage,hasNextPageandmaxPages, over a typedInfinitePageContext.
Collections
QueriesObserverfor a dynamic list of queries, andcombineover a record or a list of results (CombinedResult,CombineMemo,optional(),combineWith).
Dart-first design
- Sealed option values (
StaleTime,GcTime,Enabled,RetryPolicy,RefetchOn,RefetchInterval, …) instead of magic numbers. QueryKeyis a value type; a key is bound to one data type and a mismatched read throwsQueryDataTypeError.AppFocusManager,OnlineManagerandNotifyManagerowned per client; time goes throughpackage:clock, sofake_asynccontrols every timer.
Not in this release: persistence and hydration, streamedQuery,
server-side rendering, devtools.