@raf-query/core 0.12.0 → 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 +30 -2
- package/dist/client.d.mts +38 -5
- package/dist/client.mjs +37 -6
- package/dist/entry.d.mts +7 -0
- package/dist/entry.mjs +16 -2
- package/dist/features/focus-refetch/focus-refetch.d.mts +2 -0
- package/dist/features/focus-refetch/focus-refetch.mjs +2 -0
- package/dist/features/polling/polling.d.mts +5 -1
- package/dist/features/polling/polling.mjs +5 -1
- package/dist/features/reconnect-refetch/reconnect-refetch.d.mts +2 -0
- package/dist/features/reconnect-refetch/reconnect-refetch.mjs +2 -0
- package/dist/hydration/hydration.d.mts +38 -3
- package/dist/hydration/hydration.mjs +16 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +2 -1
- package/dist/infinite/infinite.d.mts +27 -15
- package/dist/infinite/infinite.mjs +40 -8
- package/dist/infinite/paging.d.mts +71 -0
- package/dist/infinite/paging.mjs +62 -0
- package/dist/internal.d.mts +3 -3
- package/dist/internal.mjs +3 -3
- package/dist/keys/keys.d.mts +9 -1
- package/dist/keys/targets.d.mts +8 -2
- package/dist/links/retry/retry.d.mts +7 -0
- package/dist/links/retry/retry.mjs +2 -0
- package/dist/links/timeout/timeout.d.mts +10 -2
- package/dist/links/timeout/timeout.mjs +10 -2
- package/dist/load.d.mts +28 -3
- package/dist/load.mjs +17 -3
- package/dist/options.d.mts +77 -9
- package/dist/options.mjs +7 -3
- package/dist/presets.d.mts +7 -1
- package/dist/presets.mjs +2 -0
- package/dist/root.d.mts +5 -1
- package/dist/thenable.d.mts +2 -0
- package/dist/verbs.d.mts +56 -15
- package/dist/verbs.mjs +34 -6
- package/package.json +1 -1
package/dist/options.d.mts
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import { QueryKey } from "./keys/keys.mjs";
|
|
2
2
|
import { AnyRoot, DefaultTypes, RootOf, RootTag, RootTypes } from "./root.mjs";
|
|
3
|
+
import { QueryClient } from "./client.mjs";
|
|
3
4
|
//#region src/options.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* What a `queryFn` gets: the client making the request, the query's key,
|
|
7
|
+
* `meta` and abort `signal`.
|
|
8
|
+
*
|
|
9
|
+
* @see https://raf-query.katt.dev/docs/query-functions#the-query-function-context
|
|
10
|
+
*/
|
|
4
11
|
export interface QueryFunctionContext<TKey extends QueryKey = QueryKey> {
|
|
12
|
+
/**
|
|
13
|
+
* The client making the request. A server makes one per request, so it
|
|
14
|
+
* keys per-request services, such as an API client with the request's
|
|
15
|
+
* cookies.
|
|
16
|
+
*/
|
|
17
|
+
readonly client: QueryClient;
|
|
5
18
|
/** The query's `meta`, typed by its root where the query is defined. */
|
|
6
19
|
readonly meta: object;
|
|
7
20
|
readonly queryKey: TKey;
|
|
@@ -9,6 +22,7 @@ export interface QueryFunctionContext<TKey extends QueryKey = QueryKey> {
|
|
|
9
22
|
readonly signal: AbortSignal;
|
|
10
23
|
}
|
|
11
24
|
declare const dataTag: unique symbol;
|
|
25
|
+
declare const queryFnDataTag: unique symbol;
|
|
12
26
|
/** Options every query takes. */
|
|
13
27
|
export interface BaseOptions<TKey extends QueryKey, TTypes extends RootTypes = RootTypes> {
|
|
14
28
|
/** How long an entry with no reader stays cached. Default 5 minutes; never on the server. */
|
|
@@ -21,12 +35,25 @@ export interface BaseOptions<TKey extends QueryKey, TTypes extends RootTypes = R
|
|
|
21
35
|
readonly meta?: NoInfer<Partial<TTypes["meta"]>>;
|
|
22
36
|
/** A plain array, usually built by a `group()`. Handles keep its literal type. */
|
|
23
37
|
readonly queryKey: TKey;
|
|
38
|
+
/**
|
|
39
|
+
* `false` for a query only a browser can run (a permission, the service
|
|
40
|
+
* worker, `localStorage`): a server client never starts it, never sends
|
|
41
|
+
* it, and reads it as not loaded yet, so the browser runs it once it
|
|
42
|
+
* renders. Default `true`.
|
|
43
|
+
*
|
|
44
|
+
* @see https://raf-query.katt.dev/docs/ssr-and-hydration#browser-only-queries
|
|
45
|
+
*/
|
|
46
|
+
readonly ssr?: boolean;
|
|
24
47
|
/** How long data stays fresh, in ms. Default `0`. */
|
|
25
48
|
readonly staleTime?: number;
|
|
26
49
|
/** Keep the deeply equal parts of new data, so they keep their identity. Default `true`. */
|
|
27
50
|
readonly structuralSharing?: boolean;
|
|
28
51
|
}
|
|
29
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* What `queryOptions` and `infiniteQueryOptions` return.
|
|
54
|
+
*
|
|
55
|
+
* @see https://raf-query.katt.dev/docs/api-reference#query-factories
|
|
56
|
+
*/
|
|
30
57
|
export interface QueryOptions<TKey extends QueryKey = QueryKey, TQueryFnData = unknown, TData = TQueryFnData, TTypes extends RootTypes = RootTypes> extends BaseOptions<TKey, TTypes> {
|
|
31
58
|
/** Phantom: the root the builder is bound to. Never set at runtime. */
|
|
32
59
|
readonly "~root"?: RootTag<TTypes>;
|
|
@@ -34,9 +61,20 @@ export interface QueryOptions<TKey extends QueryKey = QueryKey, TQueryFnData = u
|
|
|
34
61
|
readonly "~run"?: (op: never) => Promise<unknown>;
|
|
35
62
|
readonly [dataTag]?: TData;
|
|
36
63
|
readonly queryFn: (context: never) => unknown;
|
|
64
|
+
/**
|
|
65
|
+
* Phantom: the `queryFn`'s data, before `select`. What `setData` writes,
|
|
66
|
+
* read from a property rather than `select`'s parameter, so a factory
|
|
67
|
+
* built inline by a generic maker still infers where it's passed.
|
|
68
|
+
*/
|
|
69
|
+
readonly [queryFnDataTag]?: TQueryFnData;
|
|
37
70
|
readonly select?: (data: TQueryFnData) => TData;
|
|
38
71
|
readonly stream?: StreamOptions<TQueryFnData, never>;
|
|
39
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* How a `queryFn` that returns an async iterable folds its chunks into data.
|
|
75
|
+
*
|
|
76
|
+
* @see https://raf-query.katt.dev/docs/query-functions#streaming
|
|
77
|
+
*/
|
|
40
78
|
export interface StreamOptions<TData, TChunk> {
|
|
41
79
|
/** The data before the first chunk. */
|
|
42
80
|
readonly initial: TData;
|
|
@@ -50,7 +88,11 @@ type Awaitable<T> = PromiseLike<T> | T;
|
|
|
50
88
|
* doesn't widen it.
|
|
51
89
|
*/
|
|
52
90
|
export type FromQueryFn<T> = T extends unknown ? T : never;
|
|
53
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* `queryOptions`, with `meta` checked against the root `TTypes`.
|
|
93
|
+
*
|
|
94
|
+
* @see https://raf-query.katt.dev/docs/links-and-features#typing-meta-by-its-root
|
|
95
|
+
*/
|
|
54
96
|
export interface QueryOptionsBuilder<TTypes extends RootTypes> {
|
|
55
97
|
<const TKey extends QueryKey, TChunk, TData>(options: BaseOptions<TKey, TTypes> & {
|
|
56
98
|
readonly queryFn: (context: QueryFunctionContext<TKey>) => AsyncIterable<TChunk>;
|
|
@@ -65,10 +107,10 @@ export interface QueryOptionsBuilder<TTypes extends RootTypes> {
|
|
|
65
107
|
* Typed options for a query factory:
|
|
66
108
|
*
|
|
67
109
|
* ```ts
|
|
68
|
-
* export const
|
|
110
|
+
* export const postQuery = (input: { slug: string }) =>
|
|
69
111
|
* queryOptions({
|
|
70
|
-
* queryKey:
|
|
71
|
-
* queryFn: ({ signal }) =>
|
|
112
|
+
* queryKey: posts(input.slug),
|
|
113
|
+
* queryFn: ({ signal }) => getPost(input.slug, { signal }),
|
|
72
114
|
* });
|
|
73
115
|
* ```
|
|
74
116
|
*
|
|
@@ -78,6 +120,8 @@ export interface QueryOptionsBuilder<TTypes extends RootTypes> {
|
|
|
78
120
|
*
|
|
79
121
|
* Its `meta` is any record. To check `meta` against a client's links and
|
|
80
122
|
* features, use the builder {@link bindQueryOptions} returns.
|
|
123
|
+
*
|
|
124
|
+
* @see https://raf-query.katt.dev/docs/query-factories
|
|
81
125
|
*/
|
|
82
126
|
export declare const queryOptions: QueryOptionsBuilder<DefaultTypes>;
|
|
83
127
|
/**
|
|
@@ -91,6 +135,8 @@ export declare const queryOptions: QueryOptionsBuilder<DefaultTypes>;
|
|
|
91
135
|
* ```
|
|
92
136
|
*
|
|
93
137
|
* It returns `queryOptions` itself; only the types change.
|
|
138
|
+
*
|
|
139
|
+
* @see https://raf-query.katt.dev/docs/links-and-features#typing-meta-by-its-root
|
|
94
140
|
*/
|
|
95
141
|
export declare function bindQueryOptions<T>(): QueryOptionsBuilder<RootOf<T>>;
|
|
96
142
|
/**
|
|
@@ -99,6 +145,8 @@ export declare function bindQueryOptions<T>(): QueryOptionsBuilder<RootOf<T>>;
|
|
|
99
145
|
* every factory fits, and an inline generic factory maker passed where a
|
|
100
146
|
* `QueryFactory` is expected infers its own type parameters instead of
|
|
101
147
|
* `never`.
|
|
148
|
+
*
|
|
149
|
+
* @see https://raf-query.katt.dev/docs/query-factories
|
|
102
150
|
*/
|
|
103
151
|
export type QueryFactory = {
|
|
104
152
|
factory(input: unknown): {
|
|
@@ -106,23 +154,43 @@ export type QueryFactory = {
|
|
|
106
154
|
readonly queryKey: QueryKey;
|
|
107
155
|
};
|
|
108
156
|
}["factory"];
|
|
109
|
-
/**
|
|
157
|
+
/**
|
|
158
|
+
* A factory whose query has one value, not pages: what `useQuery` reads.
|
|
159
|
+
*
|
|
160
|
+
* @see https://raf-query.katt.dev/docs/query-factories
|
|
161
|
+
*/
|
|
110
162
|
export type SingleQueryFactory = {
|
|
111
163
|
factory(input: unknown): ReturnType<QueryFactory> & {
|
|
112
164
|
readonly getNextPageParam?: never;
|
|
113
165
|
};
|
|
114
166
|
}["factory"];
|
|
115
|
-
/**
|
|
167
|
+
/**
|
|
168
|
+
* A factory of paged queries (`infiniteQueryOptions`): what `useInfiniteQuery` reads.
|
|
169
|
+
*
|
|
170
|
+
* @see https://raf-query.katt.dev/docs/query-factories
|
|
171
|
+
*/
|
|
116
172
|
export type InfiniteQueryFactory = {
|
|
117
173
|
factory(input: unknown): ReturnType<QueryFactory> & {
|
|
118
174
|
readonly getNextPageParam: (...args: never) => unknown;
|
|
119
175
|
};
|
|
120
176
|
}["factory"];
|
|
121
|
-
/**
|
|
177
|
+
/** The `queryFn`'s data, before `select`: what `setData` writes and `getData` reads. */
|
|
178
|
+
export type QueryFnDataOf<TFactory extends QueryFactory> = ReturnType<TFactory> extends {
|
|
179
|
+
readonly [queryFnDataTag]?: infer TData;
|
|
180
|
+
} ? TData : unknown;
|
|
181
|
+
/**
|
|
182
|
+
* What a reader gets: the `select`ed data, or else the `queryFn`'s.
|
|
183
|
+
*
|
|
184
|
+
* @see https://raf-query.katt.dev/docs/query-factories#type-inference
|
|
185
|
+
*/
|
|
122
186
|
export type DataOf<TFactory extends QueryFactory> = ReturnType<TFactory> extends {
|
|
123
187
|
readonly [dataTag]?: infer TData;
|
|
124
188
|
} ? TData : never;
|
|
125
|
-
/**
|
|
189
|
+
/**
|
|
190
|
+
* A factory's input: its first parameter, or `undefined` if it takes none.
|
|
191
|
+
*
|
|
192
|
+
* @see https://raf-query.katt.dev/docs/query-factories#type-inference
|
|
193
|
+
*/
|
|
126
194
|
export type InputOf<TFactory extends QueryFactory> = Parameters<TFactory> extends [] ? undefined : Parameters<TFactory>[0];
|
|
127
195
|
/** The input arguments of a factory: none, or its input. */
|
|
128
196
|
export type InputArgs<TFactory extends QueryFactory> = Parameters<TFactory> extends [] ? [] : Parameters<TFactory> extends [infer TInput, ...Array<unknown>] ? [input: TInput] : [input?: Parameters<TFactory>[0]];
|
package/dist/options.mjs
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* Typed options for a query factory:
|
|
4
4
|
*
|
|
5
5
|
* ```ts
|
|
6
|
-
* export const
|
|
6
|
+
* export const postQuery = (input: { slug: string }) =>
|
|
7
7
|
* queryOptions({
|
|
8
|
-
* queryKey:
|
|
9
|
-
* queryFn: ({ signal }) =>
|
|
8
|
+
* queryKey: posts(input.slug),
|
|
9
|
+
* queryFn: ({ signal }) => getPost(input.slug, { signal }),
|
|
10
10
|
* });
|
|
11
11
|
* ```
|
|
12
12
|
*
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
*
|
|
17
17
|
* Its `meta` is any record. To check `meta` against a client's links and
|
|
18
18
|
* features, use the builder {@link bindQueryOptions} returns.
|
|
19
|
+
*
|
|
20
|
+
* @see https://raf-query.katt.dev/docs/query-factories
|
|
19
21
|
*/
|
|
20
22
|
const queryOptions = (options) => options;
|
|
21
23
|
/**
|
|
@@ -29,6 +31,8 @@ const queryOptions = (options) => options;
|
|
|
29
31
|
* ```
|
|
30
32
|
*
|
|
31
33
|
* It returns `queryOptions` itself; only the types change.
|
|
34
|
+
*
|
|
35
|
+
* @see https://raf-query.katt.dev/docs/links-and-features#typing-meta-by-its-root
|
|
32
36
|
*/
|
|
33
37
|
function bindQueryOptions() {
|
|
34
38
|
return queryOptions;
|
package/dist/presets.d.mts
CHANGED
|
@@ -4,7 +4,11 @@ import { ReconnectRefetchMeta } from "./features/reconnect-refetch/reconnect-ref
|
|
|
4
4
|
import { PollingMeta } from "./features/polling/polling.mjs";
|
|
5
5
|
import { RetryMeta } from "./links/retry/retry.mjs";
|
|
6
6
|
//#region src/presets.d.ts
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* What `recommended()` returns: its parts keep the `meta` they declare.
|
|
9
|
+
*
|
|
10
|
+
* @see https://raf-query.katt.dev/docs/important-defaults
|
|
11
|
+
*/
|
|
8
12
|
export interface Recommended {
|
|
9
13
|
readonly features: readonly [Feature<{
|
|
10
14
|
readonly meta: FocusRefetchMeta;
|
|
@@ -24,6 +28,8 @@ export interface Recommended {
|
|
|
24
28
|
* ```ts
|
|
25
29
|
* createQueryClient({ ...recommended(), staleTime: 30_000 });
|
|
26
30
|
* ```
|
|
31
|
+
*
|
|
32
|
+
* @see https://raf-query.katt.dev/docs/important-defaults
|
|
27
33
|
*/
|
|
28
34
|
export declare function recommended(): Recommended;
|
|
29
35
|
//#endregion
|
package/dist/presets.mjs
CHANGED
package/dist/root.d.mts
CHANGED
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
* parts declare, and builders bound to a root (`bindQueryOptions`) carry it
|
|
6
6
|
* as a phantom on the options they build.
|
|
7
7
|
*/
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* A query's `meta` when its builder isn't bound to a root.
|
|
10
|
+
*
|
|
11
|
+
* @see https://raf-query.katt.dev/docs/links-and-features
|
|
12
|
+
*/
|
|
9
13
|
export type QueryMeta = Readonly<Record<string, unknown>>;
|
|
10
14
|
/** What a link or feature declares: the `meta` fields it reads. */
|
|
11
15
|
export interface Decl {
|
package/dist/thenable.d.mts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* Promises that carry their own result in the fields React's `use()` reads
|
|
4
4
|
* before suspending (`status`, `value`, `reason`). A settled one is read
|
|
5
5
|
* synchronously, so React renders it without a fallback.
|
|
6
|
+
*
|
|
7
|
+
* @see https://raf-query.katt.dev/docs/reading-queries
|
|
6
8
|
*/
|
|
7
9
|
export type Thenable<T> = Promise<T> & ({
|
|
8
10
|
readonly reason: unknown;
|
package/dist/verbs.d.mts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { Group } from "./keys/keys.mjs";
|
|
2
2
|
import { IsAnyRoot, RootTypes } from "./root.mjs";
|
|
3
3
|
import { AnyInvalidation, AnyTarget, ParamArgs, Target } from "./keys/targets.mjs";
|
|
4
|
-
import { InputArgs, InputOf, QueryFactory, RootOfFactory } from "./options.mjs";
|
|
4
|
+
import { InputArgs, InputOf, QueryFactory, QueryFnDataOf, RootOfFactory } from "./options.mjs";
|
|
5
5
|
import { QueryClient } from "./client.mjs";
|
|
6
|
-
import { InfiniteData } from "./infinite/infinite.mjs";
|
|
7
6
|
//#region src/verbs.d.ts
|
|
8
7
|
type DeepPartial<T> = T extends object ? { readonly [TName in keyof T]?: DeepPartial<T[TName]>; } : T;
|
|
9
8
|
/**
|
|
10
9
|
* What `invalidateMany(factory, partial)` takes: part of the factory's
|
|
11
10
|
* input, whatever its key looks like.
|
|
11
|
+
*
|
|
12
|
+
* @see https://raf-query.katt.dev/docs/query-invalidation
|
|
12
13
|
*/
|
|
13
14
|
export type PartialInput<TFactory extends QueryFactory> = DeepPartial<InputOf<TFactory>>;
|
|
14
15
|
/**
|
|
15
16
|
* The clients a factory's verbs take: its root's, or any client for a
|
|
16
17
|
* factory from an unbound builder.
|
|
18
|
+
*
|
|
19
|
+
* @see https://raf-query.katt.dev/docs/links-and-features#typing-meta-by-its-root
|
|
17
20
|
*/
|
|
18
21
|
export type ClientFor<TFactory extends QueryFactory> = QueryClient<RootOfFactory<TFactory>>;
|
|
19
22
|
/**
|
|
@@ -42,12 +45,12 @@ type Item<TTypes extends RootTypes, TItem> = TItem extends Group ? Group : TItem
|
|
|
42
45
|
*/
|
|
43
46
|
export type TargetList<TTypes extends RootTypes, TItems extends ReadonlyArray<unknown>> = { readonly [TIndex in keyof TItems]: Item<TTypes, TItems[TIndex]>; };
|
|
44
47
|
/** The data `setData` writes: plain for a query, paged for an infinite one. */
|
|
45
|
-
type WritableData<TFactory extends QueryFactory> =
|
|
46
|
-
readonly select?: (data: infer TData) => unknown;
|
|
47
|
-
} ? TData : InfiniteData<unknown>;
|
|
48
|
+
type WritableData<TFactory extends QueryFactory> = QueryFnDataOf<TFactory>;
|
|
48
49
|
/**
|
|
49
50
|
* Mark one query stale: a factory and its full input. If it's read, it
|
|
50
51
|
* refetches; resolves when that settles.
|
|
52
|
+
*
|
|
53
|
+
* @see https://raf-query.katt.dev/docs/query-invalidation
|
|
51
54
|
*/
|
|
52
55
|
export declare function invalidateOne<TFactory extends QueryFactory>(client: ClientFor<TFactory>, factory: TFactory, ...input: InputArgs<TFactory>): Promise<void>;
|
|
53
56
|
/**
|
|
@@ -62,35 +65,63 @@ export declare function invalidateOne<TFactory extends QueryFactory>(client: Cli
|
|
|
62
65
|
* call after another runs them one after another instead.
|
|
63
66
|
*
|
|
64
67
|
* ```ts
|
|
65
|
-
* await invalidateMany(client, [
|
|
68
|
+
* await invalidateMany(client, [authors, [commentsQuery, { slug }], [ownedBy, "editorial"]]);
|
|
66
69
|
* ```
|
|
70
|
+
*
|
|
71
|
+
* @see https://raf-query.katt.dev/docs/query-invalidation#several-targets
|
|
67
72
|
*/
|
|
68
73
|
export declare function invalidateMany<TFactory extends QueryFactory>(client: ClientFor<TFactory>, factory: TFactory, partial?: PartialInput<TFactory>): Promise<void>;
|
|
69
74
|
export declare function invalidateMany(client: QueryClient, group: Group): Promise<void>;
|
|
70
75
|
export declare function invalidateMany<TTypes extends RootTypes, TParam = never>(client: QueryClient<TTypes>, target: TargetFor<TTypes, TParam>, ...param: ParamArgs<NoInfer<TParam>>): Promise<void>;
|
|
71
76
|
export declare function invalidateMany<TTypes extends RootTypes, const TItems extends ReadonlyArray<unknown>>(client: QueryClient<TTypes>, targets: TargetList<TTypes, TItems>): Promise<void>;
|
|
72
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* Mark every query stale; read ones refetch. For sign-out, or after any write.
|
|
79
|
+
*
|
|
80
|
+
* @see https://raf-query.katt.dev/docs/query-invalidation
|
|
81
|
+
*/
|
|
73
82
|
export declare function invalidateAll(client: QueryClient): Promise<void>;
|
|
74
83
|
/**
|
|
75
84
|
* Drop one query's data and error. If it's read, it suspends and refetches;
|
|
76
85
|
* resolves when that settles.
|
|
86
|
+
*
|
|
87
|
+
* @see https://raf-query.katt.dev/docs/query-invalidation#invalidate-reset-or-remove
|
|
77
88
|
*/
|
|
78
89
|
export declare function resetOne<TFactory extends QueryFactory>(client: ClientFor<TFactory>, factory: TFactory, ...input: InputArgs<TFactory>): Promise<void>;
|
|
79
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* {@link resetOne} for every query a target, or a list of them, covers.
|
|
92
|
+
*
|
|
93
|
+
* @see https://raf-query.katt.dev/docs/query-invalidation#invalidate-reset-or-remove
|
|
94
|
+
*/
|
|
80
95
|
export declare function resetMany<TFactory extends QueryFactory>(client: ClientFor<TFactory>, factory: TFactory, partial?: PartialInput<TFactory>): Promise<void>;
|
|
81
96
|
export declare function resetMany(client: QueryClient, group: Group): Promise<void>;
|
|
82
97
|
export declare function resetMany<TTypes extends RootTypes, TParam = never>(client: QueryClient<TTypes>, target: TargetFor<TTypes, TParam>, ...param: ParamArgs<NoInfer<TParam>>): Promise<void>;
|
|
83
98
|
export declare function resetMany<TTypes extends RootTypes, const TItems extends ReadonlyArray<unknown>>(client: QueryClient<TTypes>, targets: TargetList<TTypes, TItems>): Promise<void>;
|
|
84
|
-
/**
|
|
99
|
+
/**
|
|
100
|
+
* {@link resetOne} for every query.
|
|
101
|
+
*
|
|
102
|
+
* @see https://raf-query.katt.dev/docs/query-invalidation#invalidate-reset-or-remove
|
|
103
|
+
*/
|
|
85
104
|
export declare function resetAll(client: QueryClient): Promise<void>;
|
|
86
|
-
/**
|
|
105
|
+
/**
|
|
106
|
+
* Remove one query from the cache, aborting its request.
|
|
107
|
+
*
|
|
108
|
+
* @see https://raf-query.katt.dev/docs/query-invalidation#invalidate-reset-or-remove
|
|
109
|
+
*/
|
|
87
110
|
export declare function removeOne<TFactory extends QueryFactory>(client: ClientFor<TFactory>, factory: TFactory, ...input: InputArgs<TFactory>): void;
|
|
88
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* {@link removeOne} for every query a target, or a list of them, covers.
|
|
113
|
+
*
|
|
114
|
+
* @see https://raf-query.katt.dev/docs/query-invalidation#invalidate-reset-or-remove
|
|
115
|
+
*/
|
|
89
116
|
export declare function removeMany<TFactory extends QueryFactory>(client: ClientFor<TFactory>, factory: TFactory, partial?: PartialInput<TFactory>): void;
|
|
90
117
|
export declare function removeMany(client: QueryClient, group: Group): void;
|
|
91
118
|
export declare function removeMany<TTypes extends RootTypes, TParam = never>(client: QueryClient<TTypes>, target: TargetFor<TTypes, TParam>, ...param: ParamArgs<NoInfer<TParam>>): void;
|
|
92
119
|
export declare function removeMany<TTypes extends RootTypes, const TItems extends ReadonlyArray<unknown>>(client: QueryClient<TTypes>, targets: TargetList<TTypes, TItems>): void;
|
|
93
|
-
/**
|
|
120
|
+
/**
|
|
121
|
+
* Remove every query, aborting their requests.
|
|
122
|
+
*
|
|
123
|
+
* @see https://raf-query.katt.dev/docs/query-invalidation#invalidate-reset-or-remove
|
|
124
|
+
*/
|
|
94
125
|
export declare function removeAll(client: QueryClient): void;
|
|
95
126
|
/** New data for `setData`, or a function from the current data to it. */
|
|
96
127
|
type Updater<TFactory extends QueryFactory> = ((previous: WritableData<TFactory> | undefined) => WritableData<TFactory>) | WritableData<TFactory>;
|
|
@@ -98,12 +129,22 @@ type Updater<TFactory extends QueryFactory> = ((previous: WritableData<TFactory>
|
|
|
98
129
|
* Write a query's data, as if a request had just returned it. `updater`
|
|
99
130
|
* gets the current data, or `undefined` if there is none. A factory that
|
|
100
131
|
* takes no input (or an optional one) skips the input:
|
|
101
|
-
* `setData(client,
|
|
132
|
+
* `setData(client, feedQuery, updater)`.
|
|
133
|
+
*
|
|
134
|
+
* @see https://raf-query.katt.dev/docs/mutations#updates-from-mutation-responses
|
|
102
135
|
*/
|
|
103
136
|
export declare function setData<TFactory extends QueryFactory>(client: ClientFor<TFactory>, factory: TFactory, ...updater: [] extends Parameters<TFactory> ? [updater: Updater<TFactory>] : never): void;
|
|
104
137
|
export declare function setData<TFactory extends QueryFactory>(client: ClientFor<TFactory>, factory: TFactory, input: Parameters<TFactory> extends [] ? never : Parameters<TFactory>[0], updater: Updater<TFactory>): void;
|
|
105
|
-
/**
|
|
138
|
+
/**
|
|
139
|
+
* A query's cached data (before `select`), or `undefined`.
|
|
140
|
+
*
|
|
141
|
+
* @see https://raf-query.katt.dev/docs/api-reference#changing-the-cache
|
|
142
|
+
*/
|
|
106
143
|
export declare function getData<TFactory extends QueryFactory>(client: ClientFor<TFactory>, factory: TFactory, ...input: InputArgs<TFactory>): WritableData<TFactory> | undefined;
|
|
107
|
-
/**
|
|
144
|
+
/**
|
|
145
|
+
* How many queries have a request in flight, optionally only a factory's, a group's or a target's.
|
|
146
|
+
*
|
|
147
|
+
* @see https://raf-query.katt.dev/docs/background-fetching-indicators
|
|
148
|
+
*/
|
|
108
149
|
export declare function isFetching(client: QueryClient, target?: AnyInvalidation): number;
|
|
109
150
|
//#endregion
|
package/dist/verbs.mjs
CHANGED
|
@@ -20,6 +20,8 @@ function settle(outcomes) {
|
|
|
20
20
|
/**
|
|
21
21
|
* Mark one query stale: a factory and its full input. If it's read, it
|
|
22
22
|
* refetches; resolves when that settles.
|
|
23
|
+
*
|
|
24
|
+
* @see https://raf-query.katt.dev/docs/query-invalidation
|
|
23
25
|
*/
|
|
24
26
|
function invalidateOne(client, factory, ...input) {
|
|
25
27
|
return invalidate(client, (at) => [entryStamp(hashOf(factory, input[0]), at)]);
|
|
@@ -27,7 +29,11 @@ function invalidateOne(client, factory, ...input) {
|
|
|
27
29
|
function invalidateMany(client, target, partial) {
|
|
28
30
|
return invalidate(client, (at) => stampsOf(target, partial, at));
|
|
29
31
|
}
|
|
30
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Mark every query stale; read ones refetch. For sign-out, or after any write.
|
|
34
|
+
*
|
|
35
|
+
* @see https://raf-query.katt.dev/docs/query-invalidation
|
|
36
|
+
*/
|
|
31
37
|
function invalidateAll(client) {
|
|
32
38
|
return invalidate(client, (at) => [{
|
|
33
39
|
at,
|
|
@@ -40,6 +46,8 @@ function oneEntry(client, factory, input) {
|
|
|
40
46
|
/**
|
|
41
47
|
* Drop one query's data and error. If it's read, it suspends and refetches;
|
|
42
48
|
* resolves when that settles.
|
|
49
|
+
*
|
|
50
|
+
* @see https://raf-query.katt.dev/docs/query-invalidation#invalidate-reset-or-remove
|
|
43
51
|
*/
|
|
44
52
|
function resetOne(client, factory, ...input) {
|
|
45
53
|
const entry = oneEntry(client, factory, input[0]);
|
|
@@ -48,11 +56,19 @@ function resetOne(client, factory, ...input) {
|
|
|
48
56
|
function resetMany(client, target, partial) {
|
|
49
57
|
return settle(entriesMatching(client, stampsOf(target, partial, 0)).map(reset));
|
|
50
58
|
}
|
|
51
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* {@link resetOne} for every query.
|
|
61
|
+
*
|
|
62
|
+
* @see https://raf-query.katt.dev/docs/query-invalidation#invalidate-reset-or-remove
|
|
63
|
+
*/
|
|
52
64
|
function resetAll(client) {
|
|
53
65
|
return settle([...client["~entries"].values()].map(reset));
|
|
54
66
|
}
|
|
55
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* Remove one query from the cache, aborting its request.
|
|
69
|
+
*
|
|
70
|
+
* @see https://raf-query.katt.dev/docs/query-invalidation#invalidate-reset-or-remove
|
|
71
|
+
*/
|
|
56
72
|
function removeOne(client, factory, ...input) {
|
|
57
73
|
const entry = oneEntry(client, factory, input[0]);
|
|
58
74
|
if (entry) remove(entry);
|
|
@@ -60,7 +76,11 @@ function removeOne(client, factory, ...input) {
|
|
|
60
76
|
function removeMany(client, target, partial) {
|
|
61
77
|
for (const entry of entriesMatching(client, stampsOf(target, partial, 0))) remove(entry);
|
|
62
78
|
}
|
|
63
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* Remove every query, aborting their requests.
|
|
81
|
+
*
|
|
82
|
+
* @see https://raf-query.katt.dev/docs/query-invalidation#invalidate-reset-or-remove
|
|
83
|
+
*/
|
|
64
84
|
function removeAll(client) {
|
|
65
85
|
for (const entry of client["~entries"].values()) remove(entry);
|
|
66
86
|
}
|
|
@@ -71,12 +91,20 @@ function setData(client, factory, ...args) {
|
|
|
71
91
|
const data = isFunction(updater) ? updater(previous) : updater;
|
|
72
92
|
write(entry, data, client.clock.now(), ++client["~seq"]);
|
|
73
93
|
}
|
|
74
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* A query's cached data (before `select`), or `undefined`.
|
|
96
|
+
*
|
|
97
|
+
* @see https://raf-query.katt.dev/docs/api-reference#changing-the-cache
|
|
98
|
+
*/
|
|
75
99
|
function getData(client, factory, ...input) {
|
|
76
100
|
const entry = oneEntry(client, factory, input[0]);
|
|
77
101
|
return entry?.state.hasData ? entry.state.data : void 0;
|
|
78
102
|
}
|
|
79
|
-
/**
|
|
103
|
+
/**
|
|
104
|
+
* How many queries have a request in flight, optionally only a factory's, a group's or a target's.
|
|
105
|
+
*
|
|
106
|
+
* @see https://raf-query.katt.dev/docs/background-fetching-indicators
|
|
107
|
+
*/
|
|
80
108
|
function isFetching(client, target) {
|
|
81
109
|
return entriesMatching(client, [target === void 0 ? {
|
|
82
110
|
at: 0,
|