@raf-query/core 0.12.0 → 0.13.1

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +36 -2
  2. package/dist/client.d.mts +38 -5
  3. package/dist/client.mjs +37 -6
  4. package/dist/entry.d.mts +7 -0
  5. package/dist/entry.mjs +16 -2
  6. package/dist/features/focus-refetch/focus-refetch.d.mts +2 -0
  7. package/dist/features/focus-refetch/focus-refetch.mjs +2 -0
  8. package/dist/features/polling/polling.d.mts +5 -1
  9. package/dist/features/polling/polling.mjs +5 -1
  10. package/dist/features/reconnect-refetch/reconnect-refetch.d.mts +2 -0
  11. package/dist/features/reconnect-refetch/reconnect-refetch.mjs +2 -0
  12. package/dist/hydration/hydration.d.mts +38 -3
  13. package/dist/hydration/hydration.mjs +16 -2
  14. package/dist/index.d.mts +3 -2
  15. package/dist/index.mjs +2 -1
  16. package/dist/infinite/infinite.d.mts +37 -15
  17. package/dist/infinite/infinite.mjs +41 -8
  18. package/dist/infinite/paging.d.mts +71 -0
  19. package/dist/infinite/paging.mjs +62 -0
  20. package/dist/internal.d.mts +3 -3
  21. package/dist/internal.mjs +3 -3
  22. package/dist/keys/keys.d.mts +9 -1
  23. package/dist/keys/targets.d.mts +8 -2
  24. package/dist/links/retry/retry.d.mts +7 -0
  25. package/dist/links/retry/retry.mjs +2 -0
  26. package/dist/links/timeout/timeout.d.mts +10 -2
  27. package/dist/links/timeout/timeout.mjs +10 -2
  28. package/dist/load.d.mts +28 -3
  29. package/dist/load.mjs +26 -3
  30. package/dist/options.d.mts +79 -9
  31. package/dist/options.mjs +7 -3
  32. package/dist/presets.d.mts +7 -1
  33. package/dist/presets.mjs +2 -0
  34. package/dist/root.d.mts +5 -1
  35. package/dist/thenable.d.mts +2 -0
  36. package/dist/verbs.d.mts +56 -15
  37. package/dist/verbs.mjs +34 -6
  38. package/package.json +1 -1
package/dist/load.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { hashKey } from "./keys/keys.mjs";
2
2
  import { optionsOf } from "./options.mjs";
3
- import { entryOf, fetchEntry, isInvalidated, isStale } from "./entry.mjs";
3
+ import { entryOf, fetchEntry, isBrowserOnly, isInvalidated, isStale, reset } from "./entry.mjs";
4
4
  //#region src/load.ts
5
5
  function loadEntry(kind, factory, args) {
6
6
  return {
@@ -14,6 +14,8 @@ function loadEntry(kind, factory, args) {
14
14
  * Start the query if the cache has no fresh data, and don't wait for it.
15
15
  * It never makes the load reject: errors show up where a component reads
16
16
  * the handle.
17
+ *
18
+ * @see https://raf-query.katt.dev/docs/starting-queries#prefetch-or-swr
17
19
  */
18
20
  function prefetch(factory, ...args) {
19
21
  return loadEntry("prefetch", factory, args);
@@ -24,6 +26,8 @@ function prefetch(factory, ...args) {
24
26
  * HTTP's
25
27
  * [`stale-while-revalidate`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control#stale-while-revalidate)
26
28
  * does. The load rejects if the fetch it waits for fails.
29
+ *
30
+ * @see https://raf-query.katt.dev/docs/starting-queries#prefetch-or-swr
27
31
  */
28
32
  function swr(factory, ...args) {
29
33
  return loadEntry("swr", factory, args);
@@ -35,6 +39,8 @@ function swr(factory, ...args) {
35
39
  * is the max-age); with stale data or none it waits for the fetch. On a
36
40
  * server client, data counts as fresh until a write invalidates it. The
37
41
  * load rejects if the fetch fails.
42
+ *
43
+ * @see https://raf-query.katt.dev/docs/starting-queries#the-three-entries
38
44
  */
39
45
  function revalidate(factory, ...args) {
40
46
  return loadEntry("revalidate", factory, args);
@@ -49,6 +55,8 @@ function revalidate(factory, ...args) {
49
55
  * drafts: user.isAdmin ? prefetch(draftsQuery, { slug }) : skipToken,
50
56
  * });
51
57
  * ```
58
+ *
59
+ * @see https://raf-query.katt.dev/docs/starting-queries#conditional-queries
52
60
  */
53
61
  const skipToken = Symbol("skipToken");
54
62
  const loadRecords = /* @__PURE__ */ new WeakMap();
@@ -73,6 +81,14 @@ function startIfStale(entry) {
73
81
  function isFresh(entry) {
74
82
  return entry.client.isServer ? entry.state.hasData && !isInvalidated(entry) : !isStale(entry);
75
83
  }
84
+ /**
85
+ * Drop pages the entry's `keepPages` turns down for the input it was just
86
+ * loaded with, so they load again from that input's `initialPageParam`.
87
+ */
88
+ function dropUnkeptPages(entry) {
89
+ const keep = entry.options?.["~keep"];
90
+ if (keep && entry.state.hasData && !keep(entry.state.data)) reset(entry);
91
+ }
76
92
  function waitFresh(entry, pages) {
77
93
  if (isFresh(entry)) return Promise.resolve({ ok: true });
78
94
  return fetchEntry(entry, { pages });
@@ -93,10 +109,12 @@ function waitAny(entry, pages) {
93
109
  *
94
110
  * ```ts
95
111
  * const [handles, data] = await load(queryClient, {
96
- * comments: prefetch(commentsQuery, { issueId: id }),
97
- * issue: swr(issueQuery, { id }),
112
+ * comments: prefetch(commentsQuery, { slug }),
113
+ * post: swr(postQuery, { slug }),
98
114
  * });
99
115
  * ```
116
+ *
117
+ * @see https://raf-query.katt.dev/docs/starting-queries
100
118
  */
101
119
  async function load(client, entries) {
102
120
  const started = Object.entries(entries).flatMap(([name, item]) => item === skipToken ? [] : [{
@@ -105,8 +123,13 @@ async function load(client, entries) {
105
123
  }]).map((loaded) => {
106
124
  const item = loaded.item;
107
125
  const cached = entryOf(client, item.factory, item.input);
126
+ dropUnkeptPages(cached);
108
127
  let wait;
109
128
  if (item.kind === "prefetch") startIfStale(cached);
129
+ else if (isBrowserOnly(cached) && !cached.state.hasData) wait = Promise.resolve({
130
+ error: /* @__PURE__ */ new Error(`raf-query: ${cached.hash} has \`ssr: false\`, so the server can't wait for it. Load it with prefetch() instead of ${item.kind}().`),
131
+ ok: false
132
+ });
110
133
  else wait = (item.kind === "revalidate" ? waitFresh : waitAny)(cached, item.pages);
111
134
  return {
112
135
  entry: cached,
@@ -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,22 +35,48 @@ 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
- /** What `queryOptions` and `infiniteQueryOptions` return. */
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> {
58
+ /** Set by `infiniteQueryOptions` from `keepPages`: whether `load` keeps the cached pages. */
59
+ readonly "~keep"?: (data: never) => boolean;
31
60
  /** Phantom: the root the builder is bound to. Never set at runtime. */
32
61
  readonly "~root"?: RootTag<TTypes>;
33
62
  /** Set by `infiniteQueryOptions`: runs the request page by page. */
34
63
  readonly "~run"?: (op: never) => Promise<unknown>;
35
64
  readonly [dataTag]?: TData;
36
65
  readonly queryFn: (context: never) => unknown;
66
+ /**
67
+ * Phantom: the `queryFn`'s data, before `select`. What `setData` writes,
68
+ * read from a property rather than `select`'s parameter, so a factory
69
+ * built inline by a generic maker still infers where it's passed.
70
+ */
71
+ readonly [queryFnDataTag]?: TQueryFnData;
37
72
  readonly select?: (data: TQueryFnData) => TData;
38
73
  readonly stream?: StreamOptions<TQueryFnData, never>;
39
74
  }
75
+ /**
76
+ * How a `queryFn` that returns an async iterable folds its chunks into data.
77
+ *
78
+ * @see https://raf-query.katt.dev/docs/query-functions#streaming
79
+ */
40
80
  export interface StreamOptions<TData, TChunk> {
41
81
  /** The data before the first chunk. */
42
82
  readonly initial: TData;
@@ -50,7 +90,11 @@ type Awaitable<T> = PromiseLike<T> | T;
50
90
  * doesn't widen it.
51
91
  */
52
92
  export type FromQueryFn<T> = T extends unknown ? T : never;
53
- /** `queryOptions`, with `meta` checked against the root `TTypes`. */
93
+ /**
94
+ * `queryOptions`, with `meta` checked against the root `TTypes`.
95
+ *
96
+ * @see https://raf-query.katt.dev/docs/links-and-features#typing-meta-by-its-root
97
+ */
54
98
  export interface QueryOptionsBuilder<TTypes extends RootTypes> {
55
99
  <const TKey extends QueryKey, TChunk, TData>(options: BaseOptions<TKey, TTypes> & {
56
100
  readonly queryFn: (context: QueryFunctionContext<TKey>) => AsyncIterable<TChunk>;
@@ -65,10 +109,10 @@ export interface QueryOptionsBuilder<TTypes extends RootTypes> {
65
109
  * Typed options for a query factory:
66
110
  *
67
111
  * ```ts
68
- * export const issueQuery = (input: { id: number }) =>
112
+ * export const postQuery = (input: { slug: string }) =>
69
113
  * queryOptions({
70
- * queryKey: issues("byId", input),
71
- * queryFn: ({ signal }) => getIssue(input.id, { signal }),
114
+ * queryKey: posts(input.slug),
115
+ * queryFn: ({ signal }) => getPost(input.slug, { signal }),
72
116
  * });
73
117
  * ```
74
118
  *
@@ -78,6 +122,8 @@ export interface QueryOptionsBuilder<TTypes extends RootTypes> {
78
122
  *
79
123
  * Its `meta` is any record. To check `meta` against a client's links and
80
124
  * features, use the builder {@link bindQueryOptions} returns.
125
+ *
126
+ * @see https://raf-query.katt.dev/docs/query-factories
81
127
  */
82
128
  export declare const queryOptions: QueryOptionsBuilder<DefaultTypes>;
83
129
  /**
@@ -91,6 +137,8 @@ export declare const queryOptions: QueryOptionsBuilder<DefaultTypes>;
91
137
  * ```
92
138
  *
93
139
  * It returns `queryOptions` itself; only the types change.
140
+ *
141
+ * @see https://raf-query.katt.dev/docs/links-and-features#typing-meta-by-its-root
94
142
  */
95
143
  export declare function bindQueryOptions<T>(): QueryOptionsBuilder<RootOf<T>>;
96
144
  /**
@@ -99,6 +147,8 @@ export declare function bindQueryOptions<T>(): QueryOptionsBuilder<RootOf<T>>;
99
147
  * every factory fits, and an inline generic factory maker passed where a
100
148
  * `QueryFactory` is expected infers its own type parameters instead of
101
149
  * `never`.
150
+ *
151
+ * @see https://raf-query.katt.dev/docs/query-factories
102
152
  */
103
153
  export type QueryFactory = {
104
154
  factory(input: unknown): {
@@ -106,23 +156,43 @@ export type QueryFactory = {
106
156
  readonly queryKey: QueryKey;
107
157
  };
108
158
  }["factory"];
109
- /** A factory whose query has one value, not pages: what `useQuery` reads. */
159
+ /**
160
+ * A factory whose query has one value, not pages: what `useQuery` reads.
161
+ *
162
+ * @see https://raf-query.katt.dev/docs/query-factories
163
+ */
110
164
  export type SingleQueryFactory = {
111
165
  factory(input: unknown): ReturnType<QueryFactory> & {
112
166
  readonly getNextPageParam?: never;
113
167
  };
114
168
  }["factory"];
115
- /** A factory of paged queries (`infiniteQueryOptions`): what `useInfiniteQuery` reads. */
169
+ /**
170
+ * A factory of paged queries (`infiniteQueryOptions`): what `useInfiniteQuery` reads.
171
+ *
172
+ * @see https://raf-query.katt.dev/docs/query-factories
173
+ */
116
174
  export type InfiniteQueryFactory = {
117
175
  factory(input: unknown): ReturnType<QueryFactory> & {
118
176
  readonly getNextPageParam: (...args: never) => unknown;
119
177
  };
120
178
  }["factory"];
121
- /** What a reader gets: the `select`ed data, or else the `queryFn`'s. */
179
+ /** The `queryFn`'s data, before `select`: what `setData` writes and `getData` reads. */
180
+ export type QueryFnDataOf<TFactory extends QueryFactory> = ReturnType<TFactory> extends {
181
+ readonly [queryFnDataTag]?: infer TData;
182
+ } ? TData : unknown;
183
+ /**
184
+ * What a reader gets: the `select`ed data, or else the `queryFn`'s.
185
+ *
186
+ * @see https://raf-query.katt.dev/docs/query-factories#type-inference
187
+ */
122
188
  export type DataOf<TFactory extends QueryFactory> = ReturnType<TFactory> extends {
123
189
  readonly [dataTag]?: infer TData;
124
190
  } ? TData : never;
125
- /** A factory's input: its first parameter, or `undefined` if it takes none. */
191
+ /**
192
+ * A factory's input: its first parameter, or `undefined` if it takes none.
193
+ *
194
+ * @see https://raf-query.katt.dev/docs/query-factories#type-inference
195
+ */
126
196
  export type InputOf<TFactory extends QueryFactory> = Parameters<TFactory> extends [] ? undefined : Parameters<TFactory>[0];
127
197
  /** The input arguments of a factory: none, or its input. */
128
198
  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 issueQuery = (input: { id: number }) =>
6
+ * export const postQuery = (input: { slug: string }) =>
7
7
  * queryOptions({
8
- * queryKey: issues("byId", input),
9
- * queryFn: ({ signal }) => getIssue(input.id, { 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;
@@ -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
- /** What `recommended()` returns: its parts keep the `meta` they declare. */
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
@@ -10,6 +10,8 @@ import { retry } from "./links/retry/retry.mjs";
10
10
  * ```ts
11
11
  * createQueryClient({ ...recommended(), staleTime: 30_000 });
12
12
  * ```
13
+ *
14
+ * @see https://raf-query.katt.dev/docs/important-defaults
13
15
  */
14
16
  function recommended() {
15
17
  return {
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
- /** A query's `meta` when its builder isn't bound to a root. */
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 {
@@ -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> = ReturnType<TFactory> extends {
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, [todos, [issuesQuery, { status: "open" }], [ownedBy, "billing"]]);
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
- /** Mark every query stale; read ones refetch. For sign-out, or after any write. */
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
- /** {@link resetOne} for every query a target, or a list of them, covers. */
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
- /** {@link resetOne} for every query. */
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
- /** Remove one query from the cache, aborting its request. */
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
- /** {@link removeOne} for every query a target, or a list of them, covers. */
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
- /** Remove every query, aborting their requests. */
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, todosQuery, updater)`.
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
- /** A query's cached data (before `select`), or `undefined`. */
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
- /** How many queries have a request in flight, optionally only a factory's, a group's or a target's. */
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
- /** Mark every query stale; read ones refetch. For sign-out, or after any write. */
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
- /** {@link resetOne} for every query. */
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
- /** Remove one query from the cache, aborting its request. */
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
- /** Remove every query, aborting their requests. */
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
- /** A query's cached data (before `select`), or `undefined`. */
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
- /** How many queries have a request in flight, optionally only a factory's, a group's or a target's. */
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raf-query/core",
3
- "version": "0.12.0",
3
+ "version": "0.13.1",
4
4
  "description": "Framework-agnostic core of raf-query, a render-as-you-fetch query library",
5
5
  "keywords": [
6
6
  "query",