@raf-query/core 0.13.2 → 0.15.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.
@@ -1,40 +1,35 @@
1
1
  import { QueryKey } from "./keys/keys.mjs";
2
- import { AnyRoot, DefaultTypes, RootOf, RootTag, RootTypes } from "./root.mjs";
2
+ import { NoParts, RootOf, RootTag, RootTypes, SetsOf } from "./root.mjs";
3
3
  import { QueryClient } from "./client.mjs";
4
4
  //#region src/options.d.ts
5
5
  /**
6
- * What a `queryFn` gets: the client making the request, the query's key,
7
- * `meta` and abort `signal`.
6
+ * What a `queryFn` gets: the client making the request, the query's key and
7
+ * abort `signal`, and what the client's parts give every `queryFn`.
8
8
  *
9
9
  * @see https://raf-query.katt.dev/docs/query-functions#the-query-function-context
10
10
  */
11
- export interface QueryFunctionContext<TKey extends QueryKey = QueryKey> {
11
+ export type QueryFunctionContext<TKey extends QueryKey = QueryKey, TTypes extends RootTypes = NoParts> = TTypes["context"] & {
12
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.
13
+ * The client making the request. A server makes one per request, so
14
+ * what its parts give the context belongs to that request, such as an
15
+ * API client with the request's cookies.
16
16
  */
17
- readonly client: QueryClient;
18
- /** The query's `meta`, typed by its root where the query is defined. */
19
- readonly meta: object;
17
+ readonly client: QueryClient<TTypes>;
20
18
  readonly queryKey: TKey;
21
19
  /** Aborted when the request is restarted or its entry is removed. */
22
20
  readonly signal: AbortSignal;
23
- }
21
+ };
24
22
  declare const dataTag: unique symbol;
25
23
  declare const queryFnDataTag: unique symbol;
26
- /** Options every query takes. */
27
- export interface BaseOptions<TKey extends QueryKey, TTypes extends RootTypes = RootTypes> {
24
+ /**
25
+ * The per-query options the core reads, whatever parts the client has. A
26
+ * client's `defaults` set them for every query.
27
+ *
28
+ * @see https://raf-query.katt.dev/docs/important-defaults#changing-the-defaults
29
+ */
30
+ export interface CoreOptions {
28
31
  /** How long an entry with no reader stays cached. Default 5 minutes; never on the server. */
29
32
  readonly gcTime?: number;
30
- /**
31
- * Settings for the root's links and features, and data for targets: the
32
- * fields the root's parts declare, such as `retry` with the `retry()`
33
- * link.
34
- */
35
- readonly meta?: NoInfer<Partial<TTypes["meta"]>>;
36
- /** A plain array, usually built by a `group()`. Handles keep its literal type. */
37
- readonly queryKey: TKey;
38
33
  /**
39
34
  * `false` for a query only a browser can run (a permission, the service
40
35
  * worker, `localStorage`): a server client never starts it, never sends
@@ -49,12 +44,29 @@ export interface BaseOptions<TKey extends QueryKey, TTypes extends RootTypes = R
49
44
  /** Keep the deeply equal parts of new data, so they keep their identity. Default `true`. */
50
45
  readonly structuralSharing?: boolean;
51
46
  }
47
+ /** Options every query takes. */
48
+ export interface BaseOptions<TKey extends QueryKey> extends CoreOptions {
49
+ /** A plain array, usually built by a `group()`. Handles keep its literal type. */
50
+ readonly queryKey: TKey;
51
+ }
52
+ /**
53
+ * The options a builder bound to `T` lets a query set, beside its key and
54
+ * `queryFn`: the core's, and those `T`'s parts declare. For a fragment
55
+ * several factories share:
56
+ *
57
+ * ```ts
58
+ * const pinned = { retry: false, staleTime: Infinity } satisfies OptionsOf<typeof makeQueryClient>;
59
+ * ```
60
+ *
61
+ * @see https://raf-query.katt.dev/docs/links-and-features#typing-options-by-the-client
62
+ */
63
+ export type OptionsOf<T> = CoreOptions & Partial<SetsOf<T>["options"]>;
52
64
  /**
53
65
  * What `queryOptions` and `infiniteQueryOptions` return.
54
66
  *
55
67
  * @see https://raf-query.katt.dev/docs/api-reference#query-factories
56
68
  */
57
- export interface QueryOptions<TKey extends QueryKey = QueryKey, TQueryFnData = unknown, TData = TQueryFnData, TTypes extends RootTypes = RootTypes> extends BaseOptions<TKey, TTypes> {
69
+ export interface QueryOptions<TKey extends QueryKey = QueryKey, TQueryFnData = unknown, TData = TQueryFnData, TTypes extends RootTypes = RootTypes> extends BaseOptions<TKey> {
58
70
  /** Set by `infiniteQueryOptions` from `keepPages`: whether `load` keeps the cached pages. */
59
71
  readonly "~keep"?: (data: never) => boolean;
60
72
  /** Phantom: the root the builder is bound to. Never set at runtime. */
@@ -91,17 +103,18 @@ type Awaitable<T> = PromiseLike<T> | T;
91
103
  */
92
104
  export type FromQueryFn<T> = T extends unknown ? T : never;
93
105
  /**
94
- * `queryOptions`, with `meta` checked against the root `TTypes`.
106
+ * `queryOptions` for a root: `TTypes` is what the factories it builds need
107
+ * of a client, and `TSets` the options they can set.
95
108
  *
96
- * @see https://raf-query.katt.dev/docs/links-and-features#typing-meta-by-its-root
109
+ * @see https://raf-query.katt.dev/docs/links-and-features#typing-options-by-the-client
97
110
  */
98
- export interface QueryOptionsBuilder<TTypes extends RootTypes> {
99
- <const TKey extends QueryKey, TChunk, TData>(options: BaseOptions<TKey, TTypes> & {
100
- readonly queryFn: (context: QueryFunctionContext<TKey>) => AsyncIterable<TChunk>;
111
+ export interface QueryOptionsBuilder<TTypes extends RootTypes, TSets extends RootTypes = TTypes> {
112
+ <const TKey extends QueryKey, TChunk, TData>(options: BaseOptions<TKey> & Partial<TSets["options"]> & {
113
+ readonly queryFn: (context: QueryFunctionContext<TKey, TTypes>) => AsyncIterable<TChunk>;
101
114
  readonly stream: StreamOptions<TData, TChunk>;
102
115
  }): QueryOptions<TKey, TData, TData, TTypes>;
103
- <const TKey extends QueryKey, TQueryFnData, TData = TQueryFnData>(options: BaseOptions<TKey, TTypes> & {
104
- readonly queryFn: (context: QueryFunctionContext<TKey>) => Awaitable<TQueryFnData>;
116
+ <const TKey extends QueryKey, TQueryFnData, TData = TQueryFnData>(options: BaseOptions<TKey> & Partial<TSets["options"]> & {
117
+ readonly queryFn: (context: QueryFunctionContext<TKey, TTypes>) => Awaitable<TQueryFnData>;
105
118
  readonly select?: (data: FromQueryFn<TQueryFnData>) => TData;
106
119
  }): QueryOptions<TKey, TQueryFnData, TData, TTypes>;
107
120
  }
@@ -120,27 +133,36 @@ export interface QueryOptionsBuilder<TTypes extends RootTypes> {
120
133
  * fold its chunks into the data. Readers get the data after the first chunk,
121
134
  * and every later chunk updates it in place.
122
135
  *
123
- * Its `meta` is any record. To check `meta` against a client's links and
124
- * features, use the builder {@link bindQueryOptions} returns.
136
+ * It takes the core's options only, and its factories run on any client.
137
+ * For the options and the `queryFn` context a client's parts declare, use
138
+ * the builder {@link bindQueryOptions} returns.
125
139
  *
126
140
  * @see https://raf-query.katt.dev/docs/query-factories
127
141
  */
128
- export declare const queryOptions: QueryOptionsBuilder<DefaultTypes>;
142
+ export declare const queryOptions: QueryOptionsBuilder<NoParts>;
129
143
  /**
130
- * `queryOptions` bound to a root: `meta` takes the fields the root's links
131
- * and features declare, and verbs take only that root's clients. `T` is the
132
- * client's type, or the type of a function that makes it. Bind once per app:
144
+ * `queryOptions` bound to a root: it takes the options the root's parts
145
+ * declare, its `queryFn`s get their context, and its factories run on the
146
+ * clients that have those parts. `T` is the client's type, or the type of a
147
+ * function that makes it. Bind once per client:
133
148
  *
134
149
  * ```ts
135
150
  * // raf.ts
136
151
  * export const queryOptions = bindQueryOptions<typeof makeQueryClient>();
137
152
  * ```
138
153
  *
154
+ * A library names the parts its factories need by their declarations, and
155
+ * as `Optional` the ones whose options it sets where the client has them:
156
+ *
157
+ * ```ts
158
+ * const queryOptions = bindQueryOptions<Convex & Optional<Retry>>();
159
+ * ```
160
+ *
139
161
  * It returns `queryOptions` itself; only the types change.
140
162
  *
141
- * @see https://raf-query.katt.dev/docs/links-and-features#typing-meta-by-its-root
163
+ * @see https://raf-query.katt.dev/docs/links-and-features#typing-options-by-the-client
142
164
  */
143
- export declare function bindQueryOptions<T>(): QueryOptionsBuilder<RootOf<T>>;
165
+ export declare function bindQueryOptions<T>(): QueryOptionsBuilder<RootOf<T>, SetsOf<T>>;
144
166
  /**
145
167
  * A function of the query's input that returns its options. The input is a
146
168
  * method parameter typed `unknown`, which TypeScript checks bivariantly:
@@ -198,8 +220,8 @@ export type InputOf<TFactory extends QueryFactory> = Parameters<TFactory> extend
198
220
  export type InputArgs<TFactory extends QueryFactory> = Parameters<TFactory> extends [] ? [] : Parameters<TFactory> extends [infer TInput, ...Array<unknown>] ? [input: TInput] : [input?: Parameters<TFactory>[0]];
199
221
  /** A factory's key type, the way handles carry it. */
200
222
  export type KeyOf<TFactory extends QueryFactory> = ReturnType<TFactory>["queryKey"];
201
- /** The root a factory's builder is bound to; any root for an unbound one. */
223
+ /** The root a factory's builder is bound to: what the factory needs of a client. */
202
224
  export type RootOfFactory<TFactory extends QueryFactory> = ReturnType<TFactory> extends {
203
225
  readonly "~root"?: RootTag<infer TTypes>;
204
- } ? TTypes extends DefaultTypes ? AnyRoot : TTypes : AnyRoot;
226
+ } ? TTypes : NoParts;
205
227
  //#endregion
package/dist/options.mjs CHANGED
@@ -14,25 +14,34 @@
14
14
  * fold its chunks into the data. Readers get the data after the first chunk,
15
15
  * and every later chunk updates it in place.
16
16
  *
17
- * Its `meta` is any record. To check `meta` against a client's links and
18
- * features, use the builder {@link bindQueryOptions} returns.
17
+ * It takes the core's options only, and its factories run on any client.
18
+ * For the options and the `queryFn` context a client's parts declare, use
19
+ * the builder {@link bindQueryOptions} returns.
19
20
  *
20
21
  * @see https://raf-query.katt.dev/docs/query-factories
21
22
  */
22
23
  const queryOptions = (options) => options;
23
24
  /**
24
- * `queryOptions` bound to a root: `meta` takes the fields the root's links
25
- * and features declare, and verbs take only that root's clients. `T` is the
26
- * client's type, or the type of a function that makes it. Bind once per app:
25
+ * `queryOptions` bound to a root: it takes the options the root's parts
26
+ * declare, its `queryFn`s get their context, and its factories run on the
27
+ * clients that have those parts. `T` is the client's type, or the type of a
28
+ * function that makes it. Bind once per client:
27
29
  *
28
30
  * ```ts
29
31
  * // raf.ts
30
32
  * export const queryOptions = bindQueryOptions<typeof makeQueryClient>();
31
33
  * ```
32
34
  *
35
+ * A library names the parts its factories need by their declarations, and
36
+ * as `Optional` the ones whose options it sets where the client has them:
37
+ *
38
+ * ```ts
39
+ * const queryOptions = bindQueryOptions<Convex & Optional<Retry>>();
40
+ * ```
41
+ *
33
42
  * It returns `queryOptions` itself; only the types change.
34
43
  *
35
- * @see https://raf-query.katt.dev/docs/links-and-features#typing-meta-by-its-root
44
+ * @see https://raf-query.katt.dev/docs/links-and-features#typing-options-by-the-client
36
45
  */
37
46
  function bindQueryOptions() {
38
47
  return queryOptions;
@@ -1,32 +1,21 @@
1
- import { Feature, Link } from "./client.mjs";
2
- import { FocusRefetchMeta } from "./features/focus-refetch/focus-refetch.mjs";
3
- import { ReconnectRefetchMeta } from "./features/reconnect-refetch/reconnect-refetch.mjs";
4
- import { PollingMeta } from "./features/polling/polling.mjs";
5
- import { RetryMeta } from "./links/retry/retry.mjs";
1
+ import { Part } from "./client.mjs";
2
+ import { FocusRefetch } from "./features/focus-refetch/focus-refetch.mjs";
3
+ import { ReconnectRefetch } from "./features/reconnect-refetch/reconnect-refetch.mjs";
4
+ import { Polling } from "./features/polling/polling.mjs";
5
+ import { Retry } 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.
8
+ * What `recommended()` returns: its parts keep what they declare.
9
9
  *
10
10
  * @see https://raf-query.katt.dev/docs/important-defaults
11
11
  */
12
- export interface Recommended {
13
- readonly features: readonly [Feature<{
14
- readonly meta: FocusRefetchMeta;
15
- }>, Feature<{
16
- readonly meta: ReconnectRefetchMeta;
17
- }>, Feature<{
18
- readonly meta: PollingMeta;
19
- }>];
20
- readonly links: readonly [Link<{
21
- readonly meta: RetryMeta;
22
- }>];
23
- }
12
+ export type Recommended = readonly [Part<Retry>, Part<FocusRefetch>, Part<ReconnectRefetch>, Part<Polling>];
24
13
  /**
25
14
  * The behaviors most apps want: retries, refetching on focus and reconnect,
26
- * and polling. Spread it into the config:
15
+ * and polling. Pass it as the client's parts, or spread it among your own:
27
16
  *
28
17
  * ```ts
29
- * createQueryClient({ ...recommended(), staleTime: 30_000 });
18
+ * createQueryClient({ parts: recommended(), defaults: { staleTime: 30_000 } });
30
19
  * ```
31
20
  *
32
21
  * @see https://raf-query.katt.dev/docs/important-defaults
package/dist/presets.mjs CHANGED
@@ -5,23 +5,21 @@ import { retry } from "./links/retry/retry.mjs";
5
5
  //#region src/presets.ts
6
6
  /**
7
7
  * The behaviors most apps want: retries, refetching on focus and reconnect,
8
- * and polling. Spread it into the config:
8
+ * and polling. Pass it as the client's parts, or spread it among your own:
9
9
  *
10
10
  * ```ts
11
- * createQueryClient({ ...recommended(), staleTime: 30_000 });
11
+ * createQueryClient({ parts: recommended(), defaults: { staleTime: 30_000 } });
12
12
  * ```
13
13
  *
14
14
  * @see https://raf-query.katt.dev/docs/important-defaults
15
15
  */
16
16
  function recommended() {
17
- return {
18
- features: [
19
- focusRefetch(),
20
- reconnectRefetch(),
21
- polling()
22
- ],
23
- links: [retry()]
24
- };
17
+ return [
18
+ retry(),
19
+ focusRefetch(),
20
+ reconnectRefetch(),
21
+ polling()
22
+ ];
25
23
  }
26
24
  //#endregion
27
25
  export { recommended };
package/dist/root.d.mts CHANGED
@@ -1,36 +1,45 @@
1
1
  //#region src/root.d.ts
2
2
  /**
3
- * Root types, the way tRPC v12 types a client from its links: each link and
4
- * feature declares the `meta` fields it reads, a client's `meta` is what its
5
- * parts declare, and builders bound to a root (`bindQueryOptions`) carry it
6
- * as a phantom on the options they build.
3
+ * Root types, the way tRPC v12 types a client from its links: each part
4
+ * declares the per-query options it reads and what it gives every
5
+ * `queryFn`, a client's root is what its parts declare, and builders bound
6
+ * to a root (`bindQueryOptions`) carry it as a phantom on the options they
7
+ * build. A client runs a factory when it has at least the parts the
8
+ * factory's builder names.
7
9
  */
8
10
  /**
9
- * A query's `meta` when its builder isn't bound to a root.
11
+ * What a part declares: the per-query `options` it reads, and the `context`
12
+ * it gives every `queryFn`, for the client or per request from its link.
10
13
  *
11
- * @see https://raf-query.katt.dev/docs/links-and-features
14
+ * @see https://raf-query.katt.dev/docs/links-and-features#parts
12
15
  */
13
- export type QueryMeta = Readonly<Record<string, unknown>>;
14
- /** What a link or feature declares: the `meta` fields it reads. */
15
16
  export interface Decl {
16
- readonly meta?: object;
17
+ readonly context?: object;
18
+ readonly options?: object;
17
19
  }
18
- /** A root's types. */
19
- export interface RootTypes {
20
- readonly meta: object;
20
+ /** What a part that reads no option and gives no context declares. */
21
+ export interface NoDecl {
22
+ readonly options?: object;
21
23
  }
22
- /** The root of the unbound builders. A type only, never a value. */
23
- export interface DefaultTypes {
24
- readonly "~default": true;
25
- readonly meta: QueryMeta;
24
+ /** A root's types: what a client's parts declare, together. */
25
+ export interface RootTypes {
26
+ readonly context: object;
27
+ readonly options: object;
26
28
  }
29
+ declare const optionalDecl: unique symbol;
27
30
  /**
28
- * The root of a client typed only as `QueryClient`: any root. The one way
29
- * an invariant phantom takes every root.
31
+ * In a library's binding: a part whose options its queries set where the
32
+ * client has it, without needing it.
33
+ *
34
+ * ```ts
35
+ * const queryOptions = bindQueryOptions<Convex & Optional<Retry>>();
36
+ * ```
37
+ *
38
+ * @see https://raf-query.katt.dev/docs/links-and-features#binding-a-library-to-parts
30
39
  */
31
- export type AnyRoot = any;
32
- /** Whether `TTypes` is {@link AnyRoot}. */
33
- export type IsAnyRoot<TTypes> = 0 extends 1 & TTypes ? true : false;
40
+ export interface Optional<TDecl extends Decl> {
41
+ readonly [optionalDecl]?: TDecl;
42
+ }
34
43
  /**
35
44
  * Phantom carrier of a part's declaration, `undefined` at runtime.
36
45
  * Invariant, so a part that declares nothing doesn't absorb the
@@ -42,45 +51,82 @@ export interface Declares<TDecl extends Decl> {
42
51
  readonly out: TDecl;
43
52
  };
44
53
  }
45
- /** Any link or feature, whatever it declares. */
46
- export interface AnyPart {
54
+ /** Any part's phantom, whatever it declares. */
55
+ export interface AnyDeclares {
47
56
  readonly "~decl"?: {
48
57
  readonly in: (decl: never) => void;
49
58
  readonly out: unknown;
50
59
  };
51
60
  }
61
+ /** The options a declaration adds to its root. */
62
+ export type OptionsOfDecl<TDecl> = TDecl extends {
63
+ readonly options?: infer TOptions extends object;
64
+ } ? TOptions : unknown;
65
+ /** The `queryFn` context a declaration adds to its root. */
66
+ export type ContextOfDecl<TDecl> = TDecl extends {
67
+ readonly context?: infer TContext extends object;
68
+ } ? TContext : unknown;
52
69
  /**
53
- * The `meta` a declaration adds to its root. Every declared key is present
54
- * and may be `undefined`: roots of all-optional metas would be assignable to
55
- * one another. Queries pass a `Partial` of it.
70
+ * Every key of `T` required, its value possibly `undefined`: a root whose
71
+ * options were all optional would be assignable from a root without them.
72
+ * Mapping over `Exclude<keyof T, never>` rather than `keyof T` drops the
73
+ * modifiers without dropping `undefined`, which `-?` would.
74
+ *
75
+ * A conditional type, like {@link Plain} and {@link Root}, so the result is
76
+ * a plain object type that TypeScript compares field by field. As an alias
77
+ * of a mapped type, it compares `Root<A>` with `Root<A & B>` by a variance
78
+ * it measures wrong, and takes a client that lacks a part for one that has it.
56
79
  */
57
- export type MetaOfDecl<TDecl> = TDecl extends {
58
- readonly meta?: infer TMeta extends object;
59
- } ? Present<TMeta> : unknown;
80
+ type Present<T> = T extends unknown ? { readonly [K in Exclude<keyof T, never>]: T[K] | undefined; } : never;
81
+ type Plain<T> = T extends unknown ? { readonly [K in keyof T]: T[K]; } : never;
60
82
  /**
61
- * Every key of `T` required, its value possibly `undefined`. Mapping over
62
- * `Exclude<keyof T, never>` rather than `keyof T` drops the modifiers
63
- * without dropping `undefined`, which `-?` would.
83
+ * The root of a declaration, or of several intersected. Every declared
84
+ * option is present and may be `undefined`; queries set a `Partial` of them.
64
85
  */
65
- type Present<T> = { readonly [K in Exclude<keyof T, never>]: T[K] | undefined; };
86
+ export type Root<TDecl> = TDecl extends unknown ? {
87
+ readonly context: Plain<ContextOfDecl<TDecl>>;
88
+ readonly options: Present<OptionsOfDecl<TDecl>>;
89
+ } : never;
90
+ /**
91
+ * The root of a client with no parts, and of the unbound builders. Every
92
+ * client has it, so the bare `QueryClient` type takes any client.
93
+ */
94
+ export type NoParts = Root<unknown>;
66
95
  type DeclOf<TPart> = TPart extends {
67
96
  readonly "~decl"?: {
68
97
  readonly out: infer TDecl;
69
98
  };
70
99
  } ? TDecl : never;
71
100
  type Intersect<TUnion> = (TUnion extends unknown ? (value: TUnion) => void : never) extends ((value: infer TIntersection) => void) ? TIntersection : never;
72
- type Flat<T> = { readonly [K in keyof T]: T[K]; };
73
- /** A root's `meta`: what its links and features declare. */
74
- export type MetaOf<TParts extends ReadonlyArray<AnyPart>> = [DeclOf<TParts[number]>] extends [never] ? Flat<unknown> : Flat<Intersect<MetaOfDecl<DeclOf<TParts[number]>>>>;
101
+ /** A client's root: what its parts declare. */
102
+ export type RootOfParts<TParts extends ReadonlyArray<AnyDeclares>> = [DeclOf<TParts[number]>] extends [never] ? NoParts : Root<Intersect<DeclOf<TParts[number]>>>;
75
103
  declare const rootBrand: unique symbol;
76
104
  /** Phantom carrier of the root a factory's builder is bound to. Never set at runtime. */
77
105
  export interface RootTag<TTypes extends RootTypes> {
78
106
  readonly [rootBrand]: TTypes;
79
107
  }
80
- /** A root's types, from a client or from a function that makes one. */
81
- export type RootOf<T> = T extends ((...args: never) => infer TClient) ? RootOf<TClient> : T extends {
108
+ /** A client's root, from the client or from a function that makes one. `never` for anything else. */
109
+ type RootOfClient<T> = T extends ((...args: never) => infer TClient) ? RootOfClient<TClient> : T extends {
82
110
  readonly "~types"?: {
83
- readonly root: (types: infer TTypes extends RootTypes) => unknown;
111
+ readonly root: infer TTypes;
84
112
  };
85
- } ? TTypes : never;
113
+ } ? TTypes extends RootTypes ? TTypes : never : never;
114
+ type WithoutOptional<T> = Omit<T, typeof optionalDecl>;
115
+ type OptionalOf<T> = T extends {
116
+ readonly [optionalDecl]?: infer TDecl;
117
+ } ? TDecl : unknown;
118
+ /**
119
+ * The root a builder is bound to: a client's, the root of a function that
120
+ * makes one, or the root of the parts a library names by their
121
+ * declarations. `QueryClient<RootOf<Convex>>` is a client that has the part
122
+ * that declares `Convex`.
123
+ *
124
+ * @see https://raf-query.katt.dev/docs/links-and-features#binding-a-library-to-parts
125
+ */
126
+ export type RootOf<T> = [RootOfClient<T>] extends [never] ? Root<WithoutOptional<T>> : RootOfClient<T>;
127
+ /**
128
+ * The options a bound builder takes: its root's, and those of the parts a
129
+ * library named as {@link Optional}.
130
+ */
131
+ export type SetsOf<T> = [RootOfClient<T>] extends [never] ? Root<WithoutOptional<T> & OptionalOf<T>> : RootOfClient<T>;
86
132
  //#endregion
package/dist/verbs.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Group } from "./keys/keys.mjs";
2
- import { IsAnyRoot, RootTypes } from "./root.mjs";
3
2
  import { AnyInvalidation, AnyTarget, ParamArgs, Target } from "./keys/targets.mjs";
3
+ import { RootTypes } from "./root.mjs";
4
4
  import { InputArgs, InputOf, QueryFactory, QueryFnDataOf, RootOfFactory } from "./options.mjs";
5
5
  import { QueryClient } from "./client.mjs";
6
6
  //#region src/verbs.d.ts
@@ -13,22 +13,21 @@ type DeepPartial<T> = T extends object ? { readonly [TName in keyof T]?: DeepPar
13
13
  */
14
14
  export type PartialInput<TFactory extends QueryFactory> = DeepPartial<InputOf<TFactory>>;
15
15
  /**
16
- * The clients a factory's verbs take: its root's, or any client for a
17
- * factory from an unbound builder.
16
+ * The clients a factory runs on: those with the parts its builder is bound
17
+ * to, or any client for a factory from an unbound builder.
18
18
  *
19
- * @see https://raf-query.katt.dev/docs/links-and-features#typing-meta-by-its-root
19
+ * @see https://raf-query.katt.dev/docs/links-and-features#typing-options-by-the-client
20
20
  */
21
21
  export type ClientFor<TFactory extends QueryFactory> = QueryClient<RootOfFactory<TFactory>>;
22
22
  /**
23
- * A target a client's root can match: its `where` reads that root's `meta`.
24
- * A client typed only as `QueryClient` (from `useQueryClient()`, say) may
25
- * be of any root, so it takes any target.
23
+ * A target a client's root can match: its `where` reads the options that
24
+ * root's parts declare.
26
25
  */
27
- export type TargetFor<TTypes extends RootTypes, TParam> = IsAnyRoot<TTypes> extends true ? Target<never, TParam> : Target<NoInfer<TTypes["meta"]>, TParam>;
26
+ export type TargetFor<TTypes extends RootTypes, TParam> = Target<NoInfer<TTypes["options"]>, TParam>;
28
27
  type ParamOf<TTarget> = TTarget extends {
29
28
  readonly where: (query: never, param: infer TParam) => boolean;
30
29
  } ? TParam : never;
31
- /** A factory, if the client's root is its root; else nothing fits. */
30
+ /** A factory, if the client has the parts it needs; else nothing fits. */
32
31
  type FactoryFor<TTypes extends RootTypes, TFactory extends QueryFactory> = [QueryClient<TTypes>] extends [ClientFor<TFactory>] ? TFactory : never;
33
32
  /** A target on its own, if it needs no parameter; else with its parameter. */
34
33
  type BareTarget<TTypes extends RootTypes, TParam> = [] extends ParamArgs<TParam> ? TargetFor<TTypes, TParam> : readonly [TargetFor<TTypes, TParam>, TParam];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raf-query/core",
3
- "version": "0.13.2",
3
+ "version": "0.15.0",
4
4
  "description": "Framework-agnostic core of raf-query, a render-as-you-fetch query library",
5
5
  "keywords": [
6
6
  "query",