@raf-query/core 0.11.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -1
- package/README.md +28 -18
- package/dist/client.d.mts +163 -119
- package/dist/client.mjs +90 -162
- package/dist/entry.d.mts +73 -147
- package/dist/entry.mjs +314 -471
- package/dist/features/focus-refetch/focus-refetch.d.mts +17 -0
- package/dist/features/focus-refetch/focus-refetch.mjs +20 -0
- package/dist/features/polling/polling.d.mts +16 -0
- package/dist/features/polling/polling.mjs +39 -0
- package/dist/features/reconnect-refetch/reconnect-refetch.d.mts +17 -0
- package/dist/features/reconnect-refetch/reconnect-refetch.mjs +16 -0
- package/dist/features/shared.mjs +13 -0
- package/dist/guards.mjs +23 -0
- package/dist/hydration/hydration.d.mts +108 -0
- package/dist/hydration/hydration.mjs +142 -0
- package/dist/index.d.mts +19 -13
- package/dist/index.mjs +16 -13
- package/dist/infinite/infinite.d.mts +83 -0
- package/dist/infinite/infinite.mjs +120 -0
- package/dist/infinite/paging.d.mts +71 -0
- package/dist/infinite/paging.mjs +62 -0
- package/dist/internal.d.mts +13 -0
- package/dist/internal.mjs +7 -0
- package/dist/keys/keys.d.mts +54 -0
- package/dist/keys/keys.mjs +53 -0
- package/dist/keys/targets.d.mts +62 -0
- package/dist/keys/targets.mjs +85 -0
- package/dist/links/retry/retry.d.mts +33 -0
- package/dist/links/retry/retry.mjs +53 -0
- package/dist/links/timeout/timeout.d.mts +17 -0
- package/dist/links/timeout/timeout.mjs +35 -0
- package/dist/load.d.mts +149 -0
- package/dist/load.mjs +179 -0
- package/dist/options.d.mts +161 -332
- package/dist/options.mjs +28 -40
- package/dist/presets.d.mts +35 -0
- package/dist/presets.mjs +27 -0
- package/dist/root.d.mts +86 -0
- package/dist/structural-sharing/structural-sharing.mjs +32 -0
- package/dist/subscribe.d.mts +15 -0
- package/dist/subscribe.mjs +29 -0
- package/dist/thenable.d.mts +15 -17
- package/dist/thenable.mjs +25 -6
- package/dist/verbs.d.mts +150 -0
- package/dist/verbs.mjs +115 -0
- package/package.json +13 -9
- package/dist/_virtual/_rolldown/runtime.mjs +0 -13
- package/dist/all-keyed.d.mts +0 -18
- package/dist/all-keyed.mjs +0 -19
- package/dist/binding.d.mts +0 -92
- package/dist/binding.mjs +0 -186
- package/dist/cache.d.mts +0 -164
- package/dist/cache.mjs +0 -184
- package/dist/controls.d.mts +0 -95
- package/dist/controls.mjs +0 -70
- package/dist/hydration.d.mts +0 -84
- package/dist/hydration.mjs +0 -148
- package/dist/infinite.d.mts +0 -5
- package/dist/infinite.mjs +0 -103
- package/dist/key.d.mts +0 -18
- package/dist/key.mjs +0 -36
- package/dist/listen.mjs +0 -19
- package/dist/notify.mjs +0 -21
- package/dist/observer.d.mts +0 -110
- package/dist/observer.mjs +0 -300
- package/dist/platform.d.mts +0 -27
- package/dist/platform.mjs +0 -44
- package/dist/query.d.mts +0 -137
- package/dist/query.mjs +0 -147
- package/dist/request.mjs +0 -47
- package/dist/retry.mjs +0 -25
- package/dist/share.mjs +0 -40
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,48 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.13.0](https://github.com/KATT/raf-query/compare/0.12.0...0.13.0) (2026-11-10)
|
|
4
|
+
|
|
5
|
+
### ⚠ BREAKING CHANGES
|
|
6
|
+
|
|
7
|
+
* **core:** paging lives in core; useInfiniteQuery reads core's PageControls ([#246](https://github.com/KATT/raf-query/issues/246))
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **core:** paging lives in core; useInfiniteQuery reads core's PageControls ([#246](https://github.com/KATT/raf-query/issues/246)) ([f6b4ed2](https://github.com/KATT/raf-query/commit/f6b4ed210340b4b25bf3316ef08a9c8ceb9ed112))
|
|
12
|
+
* **core:** pass the client making the request to queryFn ([#241](https://github.com/KATT/raf-query/issues/241)) ([8c85746](https://github.com/KATT/raf-query/commit/8c85746c230bc3d8a426b32a130a260fa7e8ca62))
|
|
13
|
+
* **core:** replay cached entries to a new client subscriber ([#243](https://github.com/KATT/raf-query/issues/243)) ([1455eed](https://github.com/KATT/raf-query/commit/1455eed2612fe69f0f10bfec08cfd552ef90c786))
|
|
14
|
+
* **core:** ssr: false for queries only a browser can run ([#240](https://github.com/KATT/raf-query/issues/240)) ([077de62](https://github.com/KATT/raf-query/commit/077de6223a92b8bd8d35f7df043d1efe147ca403))
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* **core:** infer factories built inline by a generic maker in setData ([#244](https://github.com/KATT/raf-query/issues/244)) ([da87c07](https://github.com/KATT/raf-query/commit/da87c07a3463a919c154ac3ac5fba3d546b3231e))
|
|
19
|
+
* **core:** keep data written while a request ran ([#239](https://github.com/KATT/raf-query/issues/239)) ([4cb7cc0](https://github.com/KATT/raf-query/commit/4cb7cc0605a2d4637591eb365153c5e955eb41a8))
|
|
20
|
+
* **core:** start features once for providers that share a client ([#242](https://github.com/KATT/raf-query/issues/242)) ([d5968fb](https://github.com/KATT/raf-query/commit/d5968fb140429a1b2e7fb94662c266a52e877cc0))
|
|
21
|
+
|
|
22
|
+
### Documentation
|
|
23
|
+
|
|
24
|
+
* every example is the blog's posts, comments and authors ([#236](https://github.com/KATT/raf-query/issues/236)) ([2551e97](https://github.com/KATT/raf-query/commit/2551e9710aa7b149be333a1675dae31d9d1f5efd)), references [#230](https://github.com/KATT/raf-query/issues/230)
|
|
25
|
+
|
|
26
|
+
### Miscellaneous Chores
|
|
27
|
+
|
|
28
|
+
* **lint:** require a docs link on every public export ([#237](https://github.com/KATT/raf-query/issues/237)) ([b5c8133](https://github.com/KATT/raf-query/commit/b5c8133c129e0412e82cd2f24da6a2516b4a2012))
|
|
29
|
+
* unblock CI: [@see](https://github.com/see) links and the RSC test's build ([#245](https://github.com/KATT/raf-query/issues/245)) ([84927e4](https://github.com/KATT/raf-query/commit/84927e4a900f7608e1e17b022e28afadbe00e4ae)), references [#243](https://github.com/KATT/raf-query/issues/243) [#246](https://github.com/KATT/raf-query/issues/246) [#240](https://github.com/KATT/raf-query/issues/240) [#238](https://github.com/KATT/raf-query/issues/238)
|
|
30
|
+
|
|
31
|
+
## [0.12.0](https://github.com/KATT/raf-query/compare/0.11.1...0.12.0) (2026-11-08)
|
|
32
|
+
|
|
33
|
+
### ⚠ BREAKING CHANGES
|
|
34
|
+
|
|
35
|
+
- greenfield rewrite on a promise kernel, with load() handles and opt-in behaviors ([#230](https://github.com/KATT/raf-query/issues/230))
|
|
36
|
+
|
|
37
|
+
### Features
|
|
38
|
+
|
|
39
|
+
- greenfield rewrite on a promise kernel, with load() handles and opt-in behaviors ([#230](https://github.com/KATT/raf-query/issues/230)) ([e2a6f85](https://github.com/KATT/raf-query/commit/e2a6f85297992dc8a5cdd3f871a54452393ae978))
|
|
40
|
+
|
|
3
41
|
## [0.11.1](https://github.com/KATT/raf-query/compare/0.11.0...0.11.1) (2026-10-17)
|
|
4
42
|
|
|
5
43
|
### Features
|
|
6
44
|
|
|
7
|
-
|
|
45
|
+
- **core:** take throwOnError from the query's options (2/2) ([#214](https://github.com/KATT/raf-query/issues/214)) ([ef1f0fd](https://github.com/KATT/raf-query/commit/ef1f0fd8eda2a73f4c4c268e8a3a5cf91a0ba0d8)), references [#448](https://github.com/KATT/raf-query/issues/448)
|
|
8
46
|
|
|
9
47
|
## [0.11.0](https://github.com/KATT/raf-query/compare/0.10.4...0.11.0) (2026-10-16)
|
|
10
48
|
|
package/README.md
CHANGED
|
@@ -1,47 +1,57 @@
|
|
|
1
1
|
# @raf-query/core
|
|
2
2
|
|
|
3
|
-
The framework-agnostic
|
|
3
|
+
The framework-agnostic query client behind [raf-query](https://raf-query.katt.dev): a small cache that dedupes requests, keeps entries fresh, and hands out serializable handles. Retries, timeouts, refetch on focus or reconnect, polling and hydration are opt-in links, features and exports, so a client bundles only what it turns on.
|
|
4
4
|
|
|
5
|
-
**[Documentation](https://raf-query.katt.dev
|
|
5
|
+
**[Documentation](https://raf-query.katt.dev)** · [API reference](https://raf-query.katt.dev/docs/api-reference#raf-querycore) · [GitHub](https://github.com/KATT/raf-query)
|
|
6
6
|
|
|
7
7
|
> [!NOTE]
|
|
8
8
|
> raf-query is early. The API can still change between minor releases, and you use it at your own risk.
|
|
9
9
|
|
|
10
|
-
React apps install [`@raf-query/react`](https://www.npmjs.com/package/@raf-query/react) instead: it re-exports this package, so you never import core directly. Install core on its own for
|
|
10
|
+
React apps install [`@raf-query/react`](https://www.npmjs.com/package/@raf-query/react) instead: it re-exports this package, so you never import core directly. Install core on its own for scripts, tests and bindings to other frameworks.
|
|
11
11
|
|
|
12
12
|
## Install
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
npm install @raf-query/core
|
|
15
|
+
npm install @raf-query/core
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
## Usage
|
|
19
19
|
|
|
20
20
|
```ts
|
|
21
|
-
import {
|
|
22
|
-
|
|
21
|
+
import {
|
|
22
|
+
createQueryClient,
|
|
23
|
+
group,
|
|
24
|
+
invalidateOne,
|
|
25
|
+
load,
|
|
26
|
+
queryOptions,
|
|
27
|
+
retry,
|
|
28
|
+
revalidate,
|
|
29
|
+
} from "@raf-query/core";
|
|
30
|
+
|
|
31
|
+
const issues = group("issues");
|
|
23
32
|
|
|
24
33
|
export function issueQuery(input: { id: number }) {
|
|
25
34
|
return queryOptions({
|
|
26
|
-
queryKey:
|
|
27
|
-
queryFn: () =>
|
|
28
|
-
retry: Schedule.exponential("200 millis").pipe(Schedule.upTo({ times: 3 })),
|
|
35
|
+
queryKey: issues("byId", input.id),
|
|
36
|
+
queryFn: () => getIssue(input.id),
|
|
29
37
|
});
|
|
30
38
|
}
|
|
31
39
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
Stream.map((state) => state.data?.title),
|
|
37
|
-
Stream.runForEach((title) => Effect.log(title)),
|
|
38
|
-
);
|
|
40
|
+
const queryClient = createQueryClient({ links: [retry()], staleTime: 5000 });
|
|
41
|
+
|
|
42
|
+
const [, data] = await load(queryClient, {
|
|
43
|
+
issue: revalidate(issueQuery, { id: 1 }),
|
|
39
44
|
});
|
|
45
|
+
console.log(data.issue.title);
|
|
40
46
|
|
|
41
|
-
|
|
47
|
+
await invalidateOne(queryClient, issueQuery, { id: 1 });
|
|
42
48
|
```
|
|
43
49
|
|
|
44
|
-
|
|
50
|
+
## Entry points
|
|
51
|
+
|
|
52
|
+
| Import | Use |
|
|
53
|
+
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
|
54
|
+
| `@raf-query/core` | `createQueryClient`, query factories, `load`, the verbs, the built-in links and features, `group`, `dehydrate` and `hydrate` |
|
|
45
55
|
|
|
46
56
|
## License
|
|
47
57
|
|
package/dist/client.d.mts
CHANGED
|
@@ -1,130 +1,174 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { QueryKey } from "./keys/keys.mjs";
|
|
2
|
+
import { AnyPart, AnyRoot, Decl, Declares, MetaOf, MetaOfDecl, RootTypes } from "./root.mjs";
|
|
3
|
+
import { Stamp } from "./keys/targets.mjs";
|
|
4
|
+
import { QueryOptions } from "./options.mjs";
|
|
5
|
+
import { Listeners, SubscribeOptions } from "./subscribe.mjs";
|
|
6
|
+
import { Entry } from "./entry.mjs";
|
|
6
7
|
//#region src/client.d.ts
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* the flags say: reads tell them apart by what the `queryFn` returned
|
|
23
|
-
* ({@link Query.returnsEffectUnsafe}).
|
|
24
|
-
*/
|
|
25
|
-
readonly throwOnError?: boolean;
|
|
8
|
+
type LinkFunction = (op: Operation, next: (op: Operation) => Promise<unknown>) => Promise<unknown>;
|
|
9
|
+
type FeatureFunction = (client: QueryClient, signal: AbortSignal) => void;
|
|
10
|
+
/** Any link, whatever `meta` it reads. */
|
|
11
|
+
export type AnyLink = LinkFunction & AnyPart;
|
|
12
|
+
/** Any feature, whatever `meta` it reads. */
|
|
13
|
+
export type AnyFeature = FeatureFunction & AnyPart;
|
|
14
|
+
/**
|
|
15
|
+
* Time and timers, injectable so tests control them without patching globals.
|
|
16
|
+
*
|
|
17
|
+
* @see https://raf-query.katt.dev/docs/testing#time
|
|
18
|
+
*/
|
|
19
|
+
export interface Clock {
|
|
20
|
+
clearTimeout(handle: unknown): void;
|
|
21
|
+
now(): number;
|
|
22
|
+
setTimeout(callback: () => void, ms: number): unknown;
|
|
26
23
|
}
|
|
24
|
+
export declare const systemClock: Clock;
|
|
27
25
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* services of `config.layer`.
|
|
26
|
+
* One request, as links see it. `TMeta` is what the link declares.
|
|
27
|
+
*
|
|
28
|
+
* @see https://raf-query.katt.dev/docs/links-and-features#links-and-features
|
|
32
29
|
*/
|
|
33
|
-
export
|
|
34
|
-
|
|
35
|
-
/** The
|
|
36
|
-
readonly
|
|
30
|
+
export interface Operation<TMeta extends object = object> {
|
|
31
|
+
readonly client: QueryClient;
|
|
32
|
+
/** The entry's data when the request started (paged queries extend it). */
|
|
33
|
+
readonly data: unknown;
|
|
34
|
+
/** For paged queries: which page to add. */
|
|
35
|
+
readonly direction: "next" | "previous" | undefined;
|
|
36
|
+
readonly hasData: boolean;
|
|
37
|
+
readonly hash: string;
|
|
38
|
+
readonly input: unknown;
|
|
39
|
+
/** The query's `meta`, `{}` when it has none. */
|
|
40
|
+
readonly meta: TMeta;
|
|
41
|
+
readonly options: QueryOptions;
|
|
42
|
+
/** For paged queries: how many pages a first load fetches. */
|
|
43
|
+
readonly pages: number | undefined;
|
|
44
|
+
readonly queryKey: QueryKey;
|
|
45
|
+
readonly signal: AbortSignal;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Wraps every request, like a tRPC link. Call `next(op)` to run the rest of
|
|
49
|
+
* the chain; the last link is the query's own `queryFn`. `TDecl` is the
|
|
50
|
+
* `meta` it reads: see {@link link}.
|
|
51
|
+
*
|
|
52
|
+
* @see https://raf-query.katt.dev/docs/links-and-features#links-and-features
|
|
53
|
+
*/
|
|
54
|
+
export type Link<TDecl extends Decl = Decl> = LinkFunction & Declares<TDecl>;
|
|
55
|
+
/**
|
|
56
|
+
* A cache-wide behavior, started when a provider mounts the client and
|
|
57
|
+
* stopped by `signal`. `TDecl` is the `meta` it reads: see {@link feature}.
|
|
58
|
+
*
|
|
59
|
+
* @see https://raf-query.katt.dev/docs/links-and-features#links-and-features
|
|
60
|
+
*/
|
|
61
|
+
export type Feature<TDecl extends Decl = Decl> = FeatureFunction & Declares<TDecl>;
|
|
62
|
+
/**
|
|
63
|
+
* A link that declares the `meta` fields it reads. A root's queries take
|
|
64
|
+
* those fields only when the root has the link.
|
|
65
|
+
*
|
|
66
|
+
* ```ts
|
|
67
|
+
* const traced = link<{ meta: { traceId?: string } }>((op, next) =>
|
|
68
|
+
* withTrace(op.meta.traceId, () => next(op)),
|
|
69
|
+
* );
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @see https://raf-query.katt.dev/docs/links-and-features#links-and-features
|
|
73
|
+
*/
|
|
74
|
+
export declare function link<TDecl extends Decl = Decl>(run: (op: Operation<MetaOfDecl<TDecl> & object>, next: (op: Operation) => Promise<unknown>) => Promise<unknown>): Link<TDecl>;
|
|
75
|
+
/**
|
|
76
|
+
* A feature that declares the `meta` fields it reads. Without `setup`, it
|
|
77
|
+
* only declares them: a root's own fields, such as an `owner` its targets
|
|
78
|
+
* match on.
|
|
79
|
+
*
|
|
80
|
+
* ```ts
|
|
81
|
+
* const ownership = feature<{ meta: { owner?: "posts-team" | "users-team" } }>();
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @see https://raf-query.katt.dev/docs/links-and-features#links-and-features
|
|
85
|
+
*/
|
|
86
|
+
export declare function feature<TDecl extends Decl = Decl>(setup?: FeatureFunction): Feature<TDecl>;
|
|
87
|
+
export type ClientEvent = {
|
|
88
|
+
readonly entry: Entry;
|
|
89
|
+
readonly type: "added" | "removed" | "updated";
|
|
90
|
+
} | {
|
|
91
|
+
readonly entry: Entry;
|
|
92
|
+
readonly type: "readers";
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* What `createQueryClient` takes: links, features and the cache-wide defaults.
|
|
96
|
+
*
|
|
97
|
+
* @see https://raf-query.katt.dev/docs/important-defaults#changing-the-defaults
|
|
98
|
+
*/
|
|
99
|
+
export interface QueryClientConfig {
|
|
100
|
+
readonly clock?: Clock;
|
|
101
|
+
/** Behaviors started while a provider has the client mounted. */
|
|
102
|
+
readonly features?: ReadonlyArray<AnyFeature>;
|
|
103
|
+
/** Default `gcTime`: 5 minutes. Server clients never gc. */
|
|
104
|
+
readonly gcTime?: number;
|
|
105
|
+
/** Default: no `window`. Server clients never gc and never revalidate cached data. */
|
|
106
|
+
readonly isServer?: boolean;
|
|
107
|
+
/** Wrap every request, outermost first. */
|
|
108
|
+
readonly links?: ReadonlyArray<AnyLink>;
|
|
109
|
+
/** Default `staleTime`: `0`. */
|
|
110
|
+
readonly staleTime?: number;
|
|
111
|
+
/** Default `structuralSharing`: `true`. */
|
|
112
|
+
readonly structuralSharing?: boolean;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* A query cache. `TTypes` is its root's types, which factories built with
|
|
116
|
+
* `bindQueryOptions<typeof makeQueryClient>()` are checked against. The bare
|
|
117
|
+
* `QueryClient` type takes a client of any root.
|
|
118
|
+
*
|
|
119
|
+
* @see https://raf-query.katt.dev/docs/api-reference#the-client
|
|
120
|
+
*/
|
|
121
|
+
export interface QueryClient<TTypes extends RootTypes = AnyRoot> {
|
|
122
|
+
/** Entries changed since the last notification. */
|
|
123
|
+
readonly "~changed": Set<Entry>;
|
|
124
|
+
readonly "~entries": Map<string, Entry>;
|
|
125
|
+
readonly "~events": Listeners<ClientEvent>;
|
|
126
|
+
/** Orders requests and invalidations. */
|
|
127
|
+
"~seq": number;
|
|
128
|
+
/** Invalidations not yet older than every entry's data. */
|
|
129
|
+
"~stamps": Array<Stamp>;
|
|
130
|
+
/** Phantom: the root's types, invariant. `undefined` at runtime. */
|
|
131
|
+
readonly "~types"?: {
|
|
132
|
+
readonly root: (types: TTypes) => TTypes;
|
|
133
|
+
};
|
|
134
|
+
readonly clock: Clock;
|
|
135
|
+
readonly config: QueryClientConfig;
|
|
37
136
|
readonly isServer: boolean;
|
|
38
137
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
constructor(config?: QueryClientConfig<TServices>);
|
|
44
|
-
/**
|
|
45
|
-
* The cache entry for a factory call, created if missing. Doesn't fetch.
|
|
46
|
-
* For bindings; apps use the verbs.
|
|
47
|
-
*/
|
|
48
|
-
getQuery<TFactory extends QueryFactory<TServices>>(factory: TFactory, ...args: InputArgs<TFactory>): Query<TFactory>;
|
|
49
|
-
/**
|
|
50
|
-
* Start a query without waiting and return its handle. Fresh data is
|
|
51
|
-
* reused; stale data refetches in the background (in the browser only).
|
|
52
|
-
* Errors surface where the data is read, never here.
|
|
53
|
-
*/
|
|
54
|
-
prefetch<TFactory extends QueryFactory<TServices>>(factory: TFactory, ...args: InputArgs<TFactory>): QueryHandle<TFactory>;
|
|
55
|
-
/**
|
|
56
|
-
* {@link fetch} without waiting on stale data: start a query and wait for
|
|
57
|
-
* it on a cache miss. Stale cached data resolves immediately and
|
|
58
|
-
* revalidates in the browser. Rejects if that request fails.
|
|
59
|
-
*/
|
|
60
|
-
ensure<TFactory extends QueryFactory<TServices>>(factory: TFactory, ...args: InputArgs<TFactory>): Promise<QueryHandleWithData<TFactory>>;
|
|
61
|
-
/** {@link ensure}, loading `options.pages` pages of a paged query. */
|
|
62
|
-
ensure<TFactory extends PagedQueryFactory<TServices>>(factory: TFactory, input: InputOf<TFactory>, options: LoadOptions): Promise<QueryHandleWithData<TFactory>>;
|
|
63
|
-
/**
|
|
64
|
-
* Start a query and resolve to a handle holding its data. Waits on a cache
|
|
65
|
-
* miss and on stale data (on the server, only invalidated data), so the
|
|
66
|
-
* data is fresh. Rejects if that request fails.
|
|
67
|
-
*/
|
|
68
|
-
fetch<TFactory extends QueryFactory<TServices>>(factory: TFactory, ...args: InputArgs<TFactory>): Promise<QueryHandleWithData<TFactory>>;
|
|
69
|
-
/** {@link fetch}, loading `options.pages` pages of a paged query. */
|
|
70
|
-
fetch<TFactory extends PagedQueryFactory<TServices>>(factory: TFactory, input: InputOf<TFactory>, options: LoadOptions): Promise<QueryHandleWithData<TFactory>>;
|
|
71
|
-
/**
|
|
72
|
-
* Mark queries stale and refetch the ones being read. Resolves once those
|
|
73
|
-
* refetches settle, so an action stays pending until fresh data is on
|
|
74
|
-
* screen. Takes a factory and its input, or a {@link QueryCache.Filter}.
|
|
75
|
-
*/
|
|
76
|
-
invalidate<TFactory extends QueryFactory<TServices>>(...target: Target<TFactory>): Promise<void>;
|
|
77
|
-
/**
|
|
78
|
-
* Drop queries' data and errors, as if they were never fetched. Read ones
|
|
79
|
-
* suspend and refetch; resolves once those refetches settle.
|
|
138
|
+
* Cache events: entries added, updated, removed, or gaining and losing
|
|
139
|
+
* readers. With `replay: true`, the listener first gets an `added` event
|
|
140
|
+
* for every entry the cache already holds, so a feature that keeps
|
|
141
|
+
* entries in sync starts from what's there.
|
|
80
142
|
*/
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
* removed entry until they render again.
|
|
85
|
-
*/
|
|
86
|
-
remove<TFactory extends QueryFactory<TServices>>(...target: Target<TFactory>): void;
|
|
87
|
-
/** Write data for a factory call. Readers re-render without suspending. */
|
|
88
|
-
setData<TFactory extends QueryFactory<TServices>>(factory: TFactory, input: InputOf<TFactory>, updater: Updater<DataOf<TFactory>>): void;
|
|
89
|
-
/**
|
|
90
|
-
* Cached data for a factory call, or `undefined` if there is none. Data can
|
|
91
|
-
* itself be `undefined`; `Query.getUnsafe(getQuery(...)).hasData` tells
|
|
92
|
-
* them apart.
|
|
93
|
-
*/
|
|
94
|
-
getData<TFactory extends QueryFactory<TServices>>(factory: TFactory, ...args: InputArgs<TFactory>): DataOf<TFactory> | undefined;
|
|
95
|
-
/** Every entry, for devtools and integrations. */
|
|
96
|
-
getAll(): ReadonlyArray<Query>;
|
|
97
|
-
/**
|
|
98
|
-
* How many entries have a request in flight: all of them, or those
|
|
99
|
-
* matching `filter`. For global loading indicators.
|
|
100
|
-
*/
|
|
101
|
-
isFetching(filter?: Filter): number;
|
|
102
|
-
/** Listen to entries being added, updated, and removed. */
|
|
103
|
-
subscribe(listener: (event: Event) => void): () => void;
|
|
104
|
-
/** Drop every entry and abort in-flight requests. */
|
|
105
|
-
clear(): void;
|
|
106
|
-
/**
|
|
107
|
-
* Start refetching read, stale queries on window focus and reconnect.
|
|
108
|
-
* Returns the matching unmount. Providers call this; mounts are counted.
|
|
109
|
-
*/
|
|
110
|
-
mount(): () => void;
|
|
111
|
-
/**
|
|
112
|
-
* Run an Effect with the cache (`QueryCache`) and the services of
|
|
113
|
-
* `config.layer`, as `Effect.runPromise` does: it rejects with the
|
|
114
|
-
* Effect's failure, or its defect. For an app's loaders and actions.
|
|
115
|
-
*/
|
|
116
|
-
runPromise<A, E>(effect: Effect.Effect<A, E, QueryCache | TServices>): Promise<A>;
|
|
117
|
-
/**
|
|
118
|
-
* Close the client: interrupt every request and timer, and release the
|
|
119
|
-
* layer's services. Resolves once the layer's finalizers have run.
|
|
120
|
-
*/
|
|
121
|
-
dispose(): Promise<void>;
|
|
143
|
+
subscribe(listener: (event: ClientEvent) => void, options?: SubscribeOptions & {
|
|
144
|
+
readonly replay?: boolean;
|
|
145
|
+
}): () => void;
|
|
122
146
|
}
|
|
123
|
-
/** Snapshot the cache for transfer to another client (server → browser). */
|
|
124
|
-
export declare function dehydrate(client: QueryClient, options?: DehydrateOptions): DehydratedState;
|
|
125
147
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
148
|
+
* Create a query client. Behaviors are opt-in: pass `links` and `features`,
|
|
149
|
+
* or spread `recommended()`. The client's `meta` type is what they declare.
|
|
150
|
+
*
|
|
151
|
+
* ```ts
|
|
152
|
+
* const ownership = feature<{ meta: { owner?: "posts-team" | "users-team" } }>();
|
|
153
|
+
* export const makeQueryClient = () =>
|
|
154
|
+
* createQueryClient({ links: [retry()], features: [ownership], staleTime: 30_000 });
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* Make one per request on the server (in a loader or a request-scoped
|
|
158
|
+
* cache), never at module level.
|
|
159
|
+
*
|
|
160
|
+
* @see https://raf-query.katt.dev/docs/important-defaults
|
|
161
|
+
*/
|
|
162
|
+
export declare function createQueryClient<const TLinks extends ReadonlyArray<AnyLink> = [], const TFeatures extends ReadonlyArray<AnyFeature> = []>(config?: QueryClientConfig & {
|
|
163
|
+
readonly features?: TFeatures;
|
|
164
|
+
readonly links?: TLinks;
|
|
165
|
+
}): QueryClient<{
|
|
166
|
+
readonly meta: MetaOf<[...TLinks, ...TFeatures]>;
|
|
167
|
+
}>;
|
|
168
|
+
/**
|
|
169
|
+
* Start the client's features. Providers call it while mounted; the
|
|
170
|
+
* returned function stops them. Mounts are counted, so features start once
|
|
171
|
+
* however many providers share the client, and stop with the last.
|
|
128
172
|
*/
|
|
129
|
-
export declare function
|
|
173
|
+
export declare function mount(client: QueryClient): () => void;
|
|
130
174
|
//#endregion
|