fuery_core 1.6.0
fuery_core: ^1.6.0 copied to clipboard
Server data caching for Dart: cache API responses, deduplicate requests, refetch in the background, paginate, and mutate with optimistic updates.
1.6.0 #
- Add
Mutation.mutate(variables, [client])andMutation.mutateAsync(variables, [client]), which run a mutation from its definition.NoVariablesMutationruns withmutate()andmutateAsync(). They useFuery.clientunless given a client, as inlogout.mutate(null, client). - A run started from a definition belongs to the client's cache, not to a widget or an observer. A
MutationStateSlotandQueryClient.isMutatingfind it by itsmutationKey, and it leaves the cachegcTimeafter it settles.
1.5.1 #
- Speed up reading a mutation's runs when many are cached: a run keeps its converted key while the key holds the same content. With 1,000 runs in the cache, a
MutationStateSlotreads the runs of aMutation7 times faster, and ofMutationFilters1.3 times. Its flush after a run changes is 5 to 6 times faster over aMutation, and 3 times withsubscribeToRuns, whichMutationStateListeneranduseOnMutationStateChangeuse.MutationFiltersinfind,findAll, andisMutatingare faster too. This holds for keys of strings, ints, bools, enums, lists, and maps with string keys, and other keys are still converted on every read. - Speed up giving an observer a definition built again with the same key, as a widget's
builddoes: the observer no longer hashes the key.QueryObserver.setOptionsis 2.3 to 3.5 times faster,QuerySlot.update1.9 to 3 times,QueriesSlot.update1.7 to 2 times, andMutationObserver.setOptions, which hashed the key four times, 17 times. This holds for keys of strings, ints, bools, enums, lists, and maps with string keys, and other keys are still hashed. - Speed up subscribing and unsubscribing an observer: both take the same time however many observers watch the query. With 10,000 on one query, they were 40 and 175 times slower.
- Fix: when an observer subclass overrides
==, two equal observers of one query both hear its changes. Before, the second heard none of them, and unsubscribing it detached the first. A query now keeps its observers by identity, not by==.
1.5.0 #
- Add
MutationStateSlot, which lists the state of every run of a mutation, oldest first, wherever the run was started. It is anObserverSlotover the mutation cache. AMutationfinds its runs by itsmutationKey, typed like the definition.MutationFiltersfind every matching run, typedObject?. Itssubscribelisteners run in a microtask, once per batch, and only when the list changed. A definition without a key fails an assert. A run of other types under the key is left out and reported once toonUncaughtError. - Add
MutationStateSlot.subscribeToRuns((previous, current) {...})for side effects of any run. It reports each later change of each run, with that run's state before it. It never reports a state a run had when the listener was added, or a run the cache removed. - Add the sealed
MutationStateSource, whichMutationandMutationFiltersimplement. - Add
QueryResult.observerandMutationResult.observer, the observer that reported a result, so an adapter given only a result can listen to it.InfiniteQueryResult.observeris anInfiniteQueryObserver. AQueryResultbuilt with its constructor has none. - Add
ObserverSlot.listen((previous, current) {...})on every slot, for side effects. It reports each later change in a microtask, with the result before it, never the result it starts from. When the slot moves to another observer, it starts over without a call and drops what the old one had queued. A listener that throws is reported to the client'sonUncaughtError, or without it to the zone. - Add
FueryFocusManager, the new name of the class offocusManager. Flutter has aFocusManagerclass too, so a file that imported Flutter and Fuery could name neither.focusManageris the same object. - Deprecate
FocusManager, now an alias ofFueryFocusManager.dart fix --applyreplaces it, whether the file importsfuery_coreorfuery. - Deprecate
GetNextPageParamandGetPreviousPageParam, which no API takes.InfiniteQuerytakesObject? Function(InfiniteData<TPage, TParam> data). - Fix: a
QueriesSlotsubscribelistener that throws no longer stops the slot's other listeners. Its error goes to the client'sonUncaughtError.
1.4.4 #
- Add
QueryObserver.clientandMutationObserver.client, the client an observer reads and writes. - Fix: a listener that throws no longer stops the other notifications of its batch, or the other listeners of its observer or slot. Before, it could freeze
QueryClient.watchstreams,QueriesSlot, and persistence for the rest of the session. - Fix:
restore(mutations:)no longer runs a persisted mutation again while it is still running or paused, or while its stored entry is waiting to be deleted. - Fix: a query whose function throws a
CancelledErrorof its own, for example from awaiting a query that was cancelled or removed, fails like any other error instead of staying in a fetching state. - Fix: a page param function or an observer callback (
refetchWhile,placeholderData) that throws while a result is built is reported toonUncaughtError. Before, it could leave observers loading, fail a successful fetch, or skip the other observers. - Fix:
fetchNextPageandfetchPreviousPagekeep cache writes made while the page loads, such as an item updated withmapPages. - Fix:
maxPagestrims cached pages above the cap when a page loads, and a refetch, orpagesabovemaxPages, loads only the firstmaxPagespages. - Fix:
clear()fails a mutation paused offline or waiting for its turn in a scope with aCancelledError, instead of leaving it pending forever, and runs none of its callbacks, so anonErrorrollback can't write the cleared data back. A mutation already sending still finishes. - Fix: when something deletes stored data while
restore(mutations:)reads, it reads again, up to three times, instead of skipping the stored mutations. - Fix: a running mutation keeps the scope it was queued in when its options change, and
submittedAtno longer changes whenonMutatereturns a context. - Fix:
refetchQueriesandinvalidateQueriesskip queries that onlysetQueryDatawrote, which have no query function yet. Before, they retried for about 7 seconds and left the query in an error. - Fix: reading a key that holds another data type with
getData,updateData, orgetQueryDatathrows the explainedStateErrorinstead of a cast error. - Fix:
isFetchedAfterMountis true again once a reset query has loaded. - Fix: the default retry delay stays at 30 seconds however many times a query or mutation retries. After about 54 failures it overflowed.
- A query that paused while loading its first data resumes as soon as the app is back online or in the foreground, without waiting for paused mutations. Refetches of queries with data still wait for them.
- Structural sharing compares maps key by key, which is much faster for JSON-shaped data. Filters convert their key once per call, and
findandexact: truefilters look the query up by its hash instead of scanning the cache.
1.4.3 #
- Released together with the first version of
fuery_hooks. No changes infuery_core.
1.4.2 #
- Add
QueryClient.onUncaughtError, which receives the errors no caller can: errors thrown byQueryCacheConfigandMutateOptionscallbacks or byonErrorandonSettledof a failed mutation, and mistakes Fuery finds while running, such as a page param of the wrong type. Without it, they go to the current zone as before. - Fix: a
QueryCacheConfigcallback that throws no longer turns a successful fetch into an error, and anonErrorthat throws no longer skipsonSettled. - A mistake Fuery finds while running is reported once per client.
1.4.1 #
- Fix: persisted data is stored under a key that is the same in every build. The stored key included the type name of an enum in the query key, which obfuscated and minified builds rename, so such a query wasn't restored after an app update. Keys in memory are unchanged. Queries an earlier version stored under keys with enums are fetched again once, and
restore()deletes their old entries once they expire. - Fix: a persisted mutation whose key holds an enum or a
DateTimeis stored. A key that can't be stored is reported once instead of skipped without a word, and it no longer makesrestoredrop other mutations' runs.restorereports two mutations whose keys differ only in enum types and restores neither.
1.4.0 #
- Add
QueriesSlot, which renders a list of queries of one data type, keeps each query's observer while its key stays in the list, and gives their results in order, for adapters such as auseQuerieshook. - Add
QueryClient.updateQueriesData, which updates every query under a key that holds the updater's type, such as a post in every cached search result. It skips queries of other types and queries without data. - Add
InfiniteData.mapPages, which replaces every page and keeps the params, for optimistic updates of infinite queries. MutateOptionscallbacks run once theirmutatecall settles, whether or not the observer has listeners. A later call on the same observer orreset()still drops them, andMutationSlotresets the observer it owns when disposed. Before, an observer without listeners dropped them silently.
1.3.0 #
This release has breaking changes in a minor version. Each Breaking entry says what to write instead.
- Breaking: a query or mutation is now a definition you build anywhere and pass around.
QueryOptions,InfiniteQueryOptions, andMutationOptionsare renamedQuery,InfiniteQuery, andMutation; the old names stay as deprecated typedefs.observe()on a definition returns its observer.Query(...)needsqueryFn, andMutation(...)needsmutationFn. - Breaking: the cache entries formerly named
QueryandMutationareCachedQueryandCachedMutation, andAnyMutationisAnyCachedMutation.AnyMutationnow names any mutation definition, asQueryClient.restoretakes them. - Breaking: removed
Query.observe/use,InfiniteQuery.observe/use,Mutation.observe/use,Mutation.noVariables/noParam, andNoParamMutationObserver. WriteQuery(...).observe(),InfiniteQuery(...).observe(),Mutation(...).observe(), andNoVariablesMutation(...).observe().infiniteQueryOptions()is deprecated: theInfiniteQueryconstructor infers the same types. - Breaking: mutation callbacks and
MutateOptionscallbacks receive the client that runs the mutation as their last argument, such asonSuccess: (data, variables, context, client).placeholderDatareceives the client as its second argument;keepPreviousDatastill fits. - Breaking:
MutationObserver.resultandstreamreport aMutationResult, aMutationStatewithmutate,mutateAsync, andreset. QueryResult.refetch(), andInfiniteQueryResult.fetchNextPage()andfetchPreviousPage(), act on the query of the observer that reported the result.QuerySlot,InfiniteQuerySlot, andMutationSlothold the observer for a query or mutation that an adapter, such as a widget or a hook, renders on every build.QuerySource,InfiniteQuerySource, andMutationSourceare what they take: a definition or an observer.InfiniteQuery.getNextPageParamandgetPreviousPageParamreturnObject?so the constructor infers its types. A param of another type is reported as an error and counts as no page.- Options built again, with new closures, no longer notify cache watchers when nothing a watcher can see changed.
1.2.0 #
- Define a query once as options:
QueryOptions,InfiniteQueryOptions, andMutationOptionshaveobserve(), which returns their observer, andQueryClient.getData,setData, andupdateDataread and write a query's data with the type taken from its options. A query thatsetDatacreates gets all of the options, so it persists its data and can refetch. Query.observe,InfiniteQuery.observe, andMutation.observereplaceQuery.use,InfiniteQuery.use, andMutation.use, andMutation.noVariableswithNoVariablesMutationObserverreplacesMutation.noParamwithNoParamMutationObserver. The old names are deprecated and keep working until 2.0.- Fix:
MutationOptions(...)infers its types without type arguments in apps that enablestrict-inference.
1.1.1 #
- Fix:
fetchNextPage()andfetchPreviousPage()do nothing when there is no such page, instead of cancelling a refetch in flight and marking the old pages as fresh. A call while that page is already loading waits for it instead of fetching it again. - Fix:
isFetchedAfterMountcounts from when the observer gets its first listener, and starts over when it is listened to again, instead of from when the observer was created. - Fix:
restore()deletes stored queries that have expired, so data of keys the app no longer uses doesn't stay in the storage. Entries now record when they expire.
1.1.0 #
- No changes. Released together with
fuery1.1.0.
1.0.0 #
- The public API is stable: from here, a breaking change bumps the major version. No changes since 0.10.0.
0.10.0 #
- Add persisted mutations: give a mutation with a
mutationKeyapersist: MutationPersist(...), andclient.restore(mutations: [...])runs the ones that were paused or in flight when the app closed. QueryClient.restoretakesmutations, andAnyMutationOptionsnames their type.
0.9.0 #
- Breaking: boolean reads are getters. Drop the
()fromQuery.isStale,isActive,isDisabled,isFetched,isStatic,focusManager.isFocused,onlineManager.isOnline, andhasListeners. - Breaking: the listeners of an observer,
focusManager, andonlineManagercan no longer be replaced or changed from outside. Usesubscribe. - Breaking: removed API that only the package called:
QueryClient.defaultQueryOptions,QueryClient.defaultMutationOptions, andNotifyManager.setScheduler,setNotifyFunction, andsetBatchNotifyFunction.
0.8.3 #
- Documentation only: a description and topics that match what people search for, and a new page on server state in Flutter.
0.8.2 #
- Documentation only: the README and the persistence guide narrow decoded JSON once in the codec, and the storage examples no longer use a class that doesn't exist.
0.8.1 #
- Fix: entry points no longer report an inference failure in apps that enable
strict-inference, such as those usingvery_good_analysis.
0.8.0 #
- Breaking: after
removeQueriesorclear(), observers that are still subscribed move to a new query and load again, instead of keeping the removed data. Cancel subscriptions before callingclear()in tests and CLIs. - Cancelling a fetch updates its state right away, and cancel errors are no longer reported to
QueryCacheConfig.onError. pagesininfiniteQueryOptionsonly applies when nothing is cached.- Fix many cache, cancellation, retry, persistence, and mutation edge cases, including leftover retry timers, mutations that were never garbage collected, and restores racing with resets.
- Persisted infinite queries infer their page param type.
0.7.0 #
- Breaking: the public API only covers what apps use. Queries and mutations in the caches are read-only: change them through
QueryClient, and watch them withQueryClient.watch. - Breaking: removed the cache events and
QueryCache.subscribe/MutationCache.subscribe. UseQueryClient.watch. - Breaking: made internal types and members private, including the state action classes,
FetchOptions,FetchMeta,QueryState.fetchMeta,partialMatchKey, and methods likeQuery.fetch,Query.setState,QueryCache.build, andMutationCache.runNext.
0.6.0 #
- Breaking:
Fuery.instanceis renamed toFuery.client. Assigning it mounts the new client and unmounts the previous one. - Fix: removed queries and mutations no longer start garbage collection timers, which kept Dart processes alive and failed widget tests after
clear().
0.5.0 #
- Add persistence: give
QueryClientaQueryStorage, and addpersist: QueryPersist(...)(orInfiniteQueryPersist) to queries whose data should survive restarts. - Add
QueryClient.restoreto read persisted data ahead of time. removeQueries,resetQueries, andclearalso delete persisted data.
0.4.0 #
- Add
refetchWhileto poll withrefetchIntervalonly while a condition holds. - Add
QueryClient.watchto watch any value computed from the client as aStream. - Add
streamedQueryto fold aStreaminto query data as it arrives.
0.3.2 #
- No changes. Released together with
fuery0.3.2.
0.3.1 #
- Link the documentation site at https://galaxykhh.github.io/fuery/.
0.3.0 #
- Rewrite the core around
QueryClient,QueryCache, and observers. Most APIs changed; see the README. - Add retries with backoff, cancellation, pausing while offline, placeholder data, structural sharing, mutation scopes,
client.query, andclient.infiniteQuery. - Replace
rxdartwithclock,collection, andmeta.
0.2.2 #
- fix: The type error for
getQueryDatahas been resolved.
0.2.1 #
- fix: include export
QueryStatus,MutationStatusandFetchStatus
0.2.0 #
- feat:
QueryStatusgetters added inQueryResultisSuccess,isPending,isFetching,isLoading,isRefetching,isError - test: Tests for the following items have been added.
FetchStatus,QueryStatus,MutationStatus,Cacheable,QueryState,QueryResult
0.1.0 #
- docs: utils documentations
- fix: export typedefs
0.0.5 #
- docs: add examples.
0.0.4 #
- docs: update some basic descriptions.
0.0.3 #
- feat:
InfiniteQuery - docs:
InfiniteQueryusage
0.0.2 #
- docs: update dependencies and license.
0.0.1 #
- chore: Fuery core pre release.