@raf-query/core 0.13.2 → 0.14.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 +11 -1
- package/README.md +8 -5
- package/dist/client.d.mts +99 -72
- package/dist/client.mjs +19 -36
- package/dist/entry.mjs +18 -9
- package/dist/features/focus-refetch/focus-refetch.d.mts +13 -9
- package/dist/features/focus-refetch/focus-refetch.mjs +4 -4
- package/dist/features/polling/polling.d.mts +13 -9
- package/dist/features/polling/polling.mjs +6 -6
- package/dist/features/reconnect-refetch/reconnect-refetch.d.mts +13 -9
- package/dist/features/reconnect-refetch/reconnect-refetch.mjs +4 -4
- package/dist/features/shared.mjs +8 -6
- package/dist/index.d.mts +8 -8
- package/dist/index.mjs +2 -2
- package/dist/infinite/infinite.d.mts +17 -15
- package/dist/infinite/infinite.mjs +5 -4
- package/dist/internal.d.mts +3 -7
- package/dist/keys/targets.d.mts +7 -8
- package/dist/keys/targets.mjs +6 -5
- package/dist/links/retry/retry.d.mts +14 -10
- package/dist/links/retry/retry.mjs +5 -5
- package/dist/links/timeout/timeout.d.mts +2 -2
- package/dist/links/timeout/timeout.mjs +3 -2
- package/dist/load.d.mts +9 -2
- package/dist/options.d.mts +61 -39
- package/dist/options.mjs +15 -6
- package/dist/presets.d.mts +9 -20
- package/dist/presets.mjs +8 -10
- package/dist/root.d.mts +86 -40
- package/dist/verbs.d.mts +8 -9
- package/package.json +1 -1
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
|
-
*
|
|
18
|
-
*
|
|
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:
|
|
25
|
-
*
|
|
26
|
-
* client's type, or the type of a
|
|
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-
|
|
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;
|
package/dist/presets.d.mts
CHANGED
|
@@ -1,32 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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
|
|
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
|
|
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.
|
|
15
|
+
* and polling. Pass it as the client's parts, or spread it among your own:
|
|
27
16
|
*
|
|
28
17
|
* ```ts
|
|
29
|
-
* createQueryClient({
|
|
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.
|
|
8
|
+
* and polling. Pass it as the client's parts, or spread it among your own:
|
|
9
9
|
*
|
|
10
10
|
* ```ts
|
|
11
|
-
* createQueryClient({
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
4
|
-
*
|
|
5
|
-
* parts declare, and builders bound
|
|
6
|
-
* as a phantom on the options they
|
|
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
|
-
*
|
|
11
|
+
* What a part declares: the per-query `options` it reads, and the `context`
|
|
12
|
+
* it gives every `queryFn`.
|
|
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
|
|
17
|
+
readonly context?: object;
|
|
18
|
+
readonly options?: object;
|
|
17
19
|
}
|
|
18
|
-
/**
|
|
19
|
-
export interface
|
|
20
|
-
readonly
|
|
20
|
+
/** What a part that reads no option and gives no context declares. */
|
|
21
|
+
export interface NoDecl {
|
|
22
|
+
readonly options?: object;
|
|
21
23
|
}
|
|
22
|
-
/**
|
|
23
|
-
export interface
|
|
24
|
-
readonly
|
|
25
|
-
readonly
|
|
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
|
-
*
|
|
29
|
-
*
|
|
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
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
46
|
-
export interface
|
|
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
|
+
type ContextOfDecl<TDecl> = TDecl extends {
|
|
67
|
+
readonly context?: infer TContext extends object;
|
|
68
|
+
} ? TContext : unknown;
|
|
52
69
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
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
|
-
|
|
58
|
-
|
|
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
|
-
*
|
|
62
|
-
*
|
|
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
|
|
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
|
-
|
|
73
|
-
|
|
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
|
|
81
|
-
|
|
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:
|
|
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
|
|
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-
|
|
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
|
|
24
|
-
*
|
|
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> =
|
|
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
|
|
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];
|