@raf-query/core 0.11.0 → 0.11.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.
- package/CHANGELOG.md +8 -2
- package/dist/binding.mjs +2 -2
- package/dist/client.d.mts +4 -2
- package/dist/controls.d.mts +13 -11
- package/dist/controls.mjs +6 -5
- package/dist/index.d.mts +2 -2
- package/dist/options.d.mts +56 -43
- package/dist/options.mjs +6 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.11.1](https://github.com/KATT/raf-query/compare/0.11.0...0.11.1) (2026-10-17)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* **core:** take throwOnError from the query's options (2/2) ([#214](https://github.com/KATT/raf-query/issues/214)) ([ef1f0fd](https://github.com/KATT/raf-query/commit/ef1f0fd8eda2a73f4c4c268e8a3a5cf91a0ba0d8)), references [#448](https://github.com/KATT/raf-query/issues/448)
|
|
8
|
+
|
|
3
9
|
## [0.11.0](https://github.com/KATT/raf-query/compare/0.10.4...0.11.0) (2026-10-16)
|
|
4
10
|
|
|
5
11
|
### ⚠ BREAKING CHANGES
|
|
6
12
|
|
|
7
|
-
|
|
13
|
+
- **core:** enabled replaces ssr, as a boolean like TanStack Query's ([#204](https://github.com/KATT/raf-query/issues/204))
|
|
8
14
|
|
|
9
15
|
### Features
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
- **core:** enabled replaces ssr, as a boolean like TanStack Query's ([#204](https://github.com/KATT/raf-query/issues/204)) ([b7e543b](https://github.com/KATT/raf-query/commit/b7e543b9d1d34e02061740f749f2ddabcdee2ad2))
|
|
12
18
|
|
|
13
19
|
## [0.10.4](https://github.com/KATT/raf-query/compare/0.10.3...0.10.4) (2026-10-16)
|
|
14
20
|
|
package/dist/binding.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.mjs";
|
|
2
2
|
import { hashKey } from "./key.mjs";
|
|
3
3
|
import { readUnsafe } from "./query.mjs";
|
|
4
|
-
import { promiseControls, resultThenable } from "./controls.mjs";
|
|
4
|
+
import { promiseControls, resultThenable, throwsOnError } from "./controls.mjs";
|
|
5
5
|
import { getOptimisticResultUnsafe, getUnsafe, makeUnsafe as makeUnsafe$1, setOptionsUnsafe, subscribeUnsafe as subscribeUnsafe$1, trackProp } from "./observer.mjs";
|
|
6
6
|
import { Result } from "effect";
|
|
7
7
|
//#region src/binding.ts
|
|
@@ -113,7 +113,7 @@ function resultOf(impl) {
|
|
|
113
113
|
return impl.client.isServer ? getOptimisticResultUnsafe(observer, impl.query, impl.options) : getUnsafe(observer);
|
|
114
114
|
}
|
|
115
115
|
function throwOnError() {
|
|
116
|
-
return impl.source.options().throwOnError
|
|
116
|
+
return throwsOnError(impl.query, impl.source.options().throwOnError, impl.client.throwOnError);
|
|
117
117
|
}
|
|
118
118
|
function shown() {
|
|
119
119
|
const promise = read("promise").promise;
|
package/dist/client.d.mts
CHANGED
|
@@ -17,8 +17,10 @@ export interface QueryClientConfig<TServices = never> extends Config {
|
|
|
17
17
|
* When `false`, `useQuery` for an Effect `queryFn` (a typed `ErrorOf`)
|
|
18
18
|
* returns a `Result` in the first tuple slot instead of a promise that
|
|
19
19
|
* rejects. Defaults to `false` when `layer` is set, `true` otherwise.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* A query's own `throwOnError` (in `queryOptions`) and a read's win over
|
|
21
|
+
* it; types only see those two. Promise `queryFn`s always throw, whatever
|
|
22
|
+
* the flags say: reads tell them apart by what the `queryFn` returned
|
|
23
|
+
* ({@link Query.returnsEffectUnsafe}).
|
|
22
24
|
*/
|
|
23
25
|
readonly throwOnError?: boolean;
|
|
24
26
|
}
|
package/dist/controls.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { QueryKey } from "./key.mjs";
|
|
2
|
-
import { DataOf, ErrorOf, InputOf, IsPaged, QueryFactory } from "./options.mjs";
|
|
2
|
+
import { DataOf, ErrorOf, InputOf, IsPaged, QueryFactory, ThrowOnErrorOf } from "./options.mjs";
|
|
3
3
|
import { Thenable } from "./thenable.mjs";
|
|
4
4
|
import { Query, query_d_exports } from "./query.mjs";
|
|
5
5
|
import { Options, Result as Result$1, observer_d_exports } from "./observer.mjs";
|
|
@@ -14,8 +14,8 @@ export type UseQueryOptions = Options;
|
|
|
14
14
|
export type UseQueryThrowOptions<TFactory extends QueryFactory> = HasTypedError<TFactory> extends true ? {
|
|
15
15
|
/**
|
|
16
16
|
* When `false`, the data is a `Result` instead of a rejecting
|
|
17
|
-
* promise. Omit to use the
|
|
18
|
-
* `layer`, `true` without).
|
|
17
|
+
* promise. Omit to use the query's `throwOnError`, else the
|
|
18
|
+
* client's default (`false` with a `layer`, `true` without).
|
|
19
19
|
*/
|
|
20
20
|
readonly throwOnError?: boolean;
|
|
21
21
|
} : {
|
|
@@ -61,18 +61,20 @@ export type UseQueryControls<TFactory extends QueryFactory> = IsPaged<TFactory>
|
|
|
61
61
|
export type HasTypedError<TFactory extends QueryFactory> = unknown extends ErrorOf<TFactory> ? false : true;
|
|
62
62
|
/**
|
|
63
63
|
* Whether this read throws on failure. Untyped errors always throw. Typed
|
|
64
|
-
* errors follow `
|
|
65
|
-
*
|
|
66
|
-
*
|
|
64
|
+
* errors follow the read's `throwOnError`, else the query's
|
|
65
|
+
* ({@link ThrowOnErrorOf}), else the client's default (`false` with a
|
|
66
|
+
* `layer`, `true` without). Types can't see the client's, so they treat it
|
|
67
|
+
* as `false` (Result), matching a client with a `layer`.
|
|
67
68
|
*/
|
|
68
|
-
export type ThrowsOnError<TFactory extends QueryFactory, TThrow extends boolean | undefined> = HasTypedError<TFactory> extends false ? true : TThrow extends boolean ? TThrow : false;
|
|
69
|
+
export type ThrowsOnError<TFactory extends QueryFactory, TThrow extends boolean | undefined> = HasTypedError<TFactory> extends false ? true : TThrow extends boolean ? TThrow : ThrowOnErrorOf<TFactory> extends boolean ? ThrowOnErrorOf<TFactory> : false;
|
|
69
70
|
/**
|
|
70
71
|
* {@link ThrowsOnError} at runtime, for bindings: a read of `query` throws
|
|
71
|
-
* when `
|
|
72
|
-
*
|
|
73
|
-
*
|
|
72
|
+
* when its `queryFn` returns a promise or plain value, whose error isn't
|
|
73
|
+
* typed. Otherwise it follows the read's `throwOnError`, else the query's
|
|
74
|
+
* options', else `clientDefault` (pass the client's `throwOnError`). A query
|
|
75
|
+
* whose `queryFn` hasn't run yet follows the flags.
|
|
74
76
|
*/
|
|
75
|
-
export declare function throwsOnError<TFactory extends QueryFactory>(query: Query<TFactory>, throwOnError: boolean): boolean;
|
|
77
|
+
export declare function throwsOnError<TFactory extends QueryFactory>(query: Query<TFactory>, throwOnError: boolean | undefined, clientDefault?: boolean): boolean;
|
|
76
78
|
/** What a read settles with: the data, or a `Result` when it doesn't throw. */
|
|
77
79
|
export type ReadValue<TFactory extends QueryFactory, TThrow extends boolean | undefined = undefined> = ThrowsOnError<TFactory, TThrow> extends true ? DataOf<TFactory> : Result.Result<DataOf<TFactory>, ErrorOf<TFactory>>;
|
|
78
80
|
type Command = "fetchNextPage" | "fetchPreviousPage" | "refetch";
|
package/dist/controls.mjs
CHANGED
|
@@ -9,12 +9,13 @@ import { Effect, Result } from "effect";
|
|
|
9
9
|
*/
|
|
10
10
|
/**
|
|
11
11
|
* {@link ThrowsOnError} at runtime, for bindings: a read of `query` throws
|
|
12
|
-
* when `
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* when its `queryFn` returns a promise or plain value, whose error isn't
|
|
13
|
+
* typed. Otherwise it follows the read's `throwOnError`, else the query's
|
|
14
|
+
* options', else `clientDefault` (pass the client's `throwOnError`). A query
|
|
15
|
+
* whose `queryFn` hasn't run yet follows the flags.
|
|
15
16
|
*/
|
|
16
|
-
function throwsOnError(query, throwOnError) {
|
|
17
|
-
return
|
|
17
|
+
function throwsOnError(query, throwOnError, clientDefault = false) {
|
|
18
|
+
return returnsEffectUnsafe(query) === false || (throwOnError ?? query.options?.throwOnError ?? clientDefault);
|
|
18
19
|
}
|
|
19
20
|
const commands = /* @__PURE__ */ new WeakMap();
|
|
20
21
|
/** One stable Promise function per command Effect, so identities track the query's. */
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Settled, allKeyed } from "./all-keyed.mjs";
|
|
2
2
|
import { QueryKey, hashKey, matchesKey } from "./key.mjs";
|
|
3
|
-
import { AnyQueryOptions, DataOf, ErrorOf, InfiniteData, InfiniteQueryOptions, InfiniteQueryTypes, InputArgs, InputOf, IsPaged, LoadOptions, PageFunctionContext, PageOf, PagedQueryFactory, QueryBehavior, QueryFactory, QueryFnResult, QueryFunctionContext, QueryHandle, QueryHandleWithData, QueryMeta, QueryOptions, QueryTypes, Register, RetryPolicy, ServicesOf, infiniteQueryOptions, queryOptions } from "./options.mjs";
|
|
3
|
+
import { AnyQueryOptions, DataOf, ErrorOf, InfiniteData, InfiniteQueryOptions, InfiniteQueryTypes, InputArgs, InputOf, IsPaged, LoadOptions, PageFunctionContext, PageOf, PagedQueryFactory, QueryBehavior, QueryFactory, QueryFnResult, QueryFunctionContext, QueryHandle, QueryHandleWithData, QueryMeta, QueryOptions, QueryTypes, Register, RetryPolicy, ServicesOf, ThrowOnErrorOf, infiniteQueryOptions, queryOptions } from "./options.mjs";
|
|
4
4
|
import { platform_d_exports } from "./platform.mjs";
|
|
5
5
|
import { Pending, Thenable, fulfilled, pending } from "./thenable.mjs";
|
|
6
6
|
import { query_d_exports } from "./query.mjs";
|
|
@@ -10,4 +10,4 @@ import { QueryClient, QueryClientConfig, dehydrate, hydrate } from "./client.mjs
|
|
|
10
10
|
import { observer_d_exports } from "./observer.mjs";
|
|
11
11
|
import { HasTypedError, PagingControls, PromiseControls, QueryControls, ReadValue, ThrowsOnError, UseQueryControls, UseQueryOptions, UseQueryThrowOptions, promiseControls, resultThenable, throwsOnError } from "./controls.mjs";
|
|
12
12
|
import { binding_d_exports } from "./binding.mjs";
|
|
13
|
-
export { type AnyQueryOptions, type DataOf, type DehydrateOptions, type DehydratedQuery, type DehydratedResult, type DehydratedState, type DehydratedStream, type ErrorOf, type HasTypedError, type HydrateOptions, type InfiniteData, type InfiniteQueryOptions, type InfiniteQueryTypes, type InputArgs, type InputOf, type IsPaged, type LoadOptions, type PageFunctionContext, type PageOf, type PagedQueryFactory, type PagingControls, type Pending, platform_d_exports as Platform, type PromiseControls, query_d_exports as Query, type QueryBehavior, binding_d_exports as QueryBinding, cache_d_exports as QueryCache, QueryClient, type QueryClientConfig, type QueryControls, type QueryFactory, type QueryFnResult, type QueryFunctionContext, type QueryHandle, type QueryHandleWithData, type QueryKey, type QueryMeta, observer_d_exports as QueryObserver, type QueryOptions, type QueryTypes, type ReadValue, RedactedError, type Register, type RetryPolicy, type ServicesOf, type Settled, type Thenable, type ThrowsOnError, type UseQueryControls, type UseQueryOptions, type UseQueryThrowOptions, allKeyed, canDehydrate, dehydrate, dehydrateQuery, fulfilled, hashKey, hydrate, infiniteQueryOptions, matchesKey, pending, promiseControls, queryOptions, resultThenable, throwsOnError };
|
|
13
|
+
export { type AnyQueryOptions, type DataOf, type DehydrateOptions, type DehydratedQuery, type DehydratedResult, type DehydratedState, type DehydratedStream, type ErrorOf, type HasTypedError, type HydrateOptions, type InfiniteData, type InfiniteQueryOptions, type InfiniteQueryTypes, type InputArgs, type InputOf, type IsPaged, type LoadOptions, type PageFunctionContext, type PageOf, type PagedQueryFactory, type PagingControls, type Pending, platform_d_exports as Platform, type PromiseControls, query_d_exports as Query, type QueryBehavior, binding_d_exports as QueryBinding, cache_d_exports as QueryCache, QueryClient, type QueryClientConfig, type QueryControls, type QueryFactory, type QueryFnResult, type QueryFunctionContext, type QueryHandle, type QueryHandleWithData, type QueryKey, type QueryMeta, observer_d_exports as QueryObserver, type QueryOptions, type QueryTypes, type ReadValue, RedactedError, type Register, type RetryPolicy, type ServicesOf, type Settled, type Thenable, type ThrowOnErrorOf, type ThrowsOnError, type UseQueryControls, type UseQueryOptions, type UseQueryThrowOptions, allKeyed, canDehydrate, dehydrate, dehydrateQuery, fulfilled, hashKey, hydrate, infiniteQueryOptions, matchesKey, pending, promiseControls, queryOptions, resultThenable, throwsOnError };
|
package/dist/options.d.mts
CHANGED
|
@@ -6,7 +6,8 @@ import { Effect, Schedule } from "effect";
|
|
|
6
6
|
* `queryFn` its error and the services it needs, and the shape of its key.
|
|
7
7
|
* Leave `error` out and it is `unknown` (promises reject with anything);
|
|
8
8
|
* leave `services` out and it is `never`; leave `key` out and it is any
|
|
9
|
-
* {@link QueryKey}.
|
|
9
|
+
* {@link QueryKey}. `throwOnError` is the query's `throwOnError` option;
|
|
10
|
+
* leave it out when the query doesn't set one.
|
|
10
11
|
*
|
|
11
12
|
* ```ts
|
|
12
13
|
* type PostOptions = QueryOptions<{ data: Post }>;
|
|
@@ -17,10 +18,12 @@ export interface QueryTypes {
|
|
|
17
18
|
readonly error?: unknown;
|
|
18
19
|
readonly key?: QueryKey;
|
|
19
20
|
readonly services?: unknown;
|
|
21
|
+
readonly throwOnError?: boolean;
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
24
|
* The types of a paged query: one page, the param that loads it, and as in
|
|
23
|
-
* {@link QueryTypes}, an Effect `queryFn`'s error and services
|
|
25
|
+
* {@link QueryTypes}, an Effect `queryFn`'s error and services, the key and
|
|
26
|
+
* `throwOnError`.
|
|
24
27
|
*/
|
|
25
28
|
export interface InfiniteQueryTypes {
|
|
26
29
|
readonly error?: unknown;
|
|
@@ -28,6 +31,7 @@ export interface InfiniteQueryTypes {
|
|
|
28
31
|
readonly page: unknown;
|
|
29
32
|
readonly pageParam: unknown;
|
|
30
33
|
readonly services?: unknown;
|
|
34
|
+
readonly throwOnError?: boolean;
|
|
31
35
|
}
|
|
32
36
|
/** `error` of a types bag, `unknown` when it has none. */
|
|
33
37
|
type ErrorIn<TTypes> = TTypes extends {
|
|
@@ -41,52 +45,39 @@ type ServicesIn<TTypes> = TTypes extends {
|
|
|
41
45
|
type KeyIn<TTypes> = TTypes extends {
|
|
42
46
|
readonly key: infer TKey extends QueryKey;
|
|
43
47
|
} ? TKey : QueryKey;
|
|
48
|
+
/** `throwOnError` of a types bag, `undefined` when it has none. */
|
|
49
|
+
type ThrowIn<TTypes> = TTypes extends {
|
|
50
|
+
readonly throwOnError: infer TThrow extends boolean;
|
|
51
|
+
} ? TThrow : undefined;
|
|
52
|
+
/** One object type for an intersection, so bags read as written. */
|
|
53
|
+
type Flat<T> = { [K in keyof T]: T[K]; };
|
|
54
|
+
type ErrorPart<TError> = unknown extends TError ? unknown : {
|
|
55
|
+
error: TError;
|
|
56
|
+
};
|
|
57
|
+
type ServicesPart<TServices> = [TServices] extends [never] ? unknown : {
|
|
58
|
+
services: TServices;
|
|
59
|
+
};
|
|
60
|
+
type ThrowPart<TThrow> = [TThrow] extends [boolean] ? {
|
|
61
|
+
throwOnError: TThrow;
|
|
62
|
+
} : unknown;
|
|
44
63
|
/**
|
|
45
64
|
* The bag `queryOptions` returns. `error` is left out when the `queryFn`
|
|
46
65
|
* doesn't name one (`unknown`: a promise or a plain value). `services` is
|
|
47
66
|
* left out when the `queryFn` needs none (`never`). An Effect's error,
|
|
48
67
|
* including `never` when it can't fail, stays. `key` is always there, so two
|
|
49
|
-
* factories with different key shapes have different types.
|
|
68
|
+
* factories with different key shapes have different types. `throwOnError`
|
|
69
|
+
* is there when the options set it.
|
|
50
70
|
*/
|
|
51
|
-
type QueryTypesOf<TData, TError, TServices, TKey> =
|
|
52
|
-
data: TData;
|
|
53
|
-
key: TKey;
|
|
54
|
-
} : {
|
|
55
|
-
data: TData;
|
|
56
|
-
key: TKey;
|
|
57
|
-
services: TServices;
|
|
58
|
-
} : [TServices] extends [never] ? {
|
|
71
|
+
type QueryTypesOf<TData, TError, TServices, TKey, TThrow> = Flat<{
|
|
59
72
|
data: TData;
|
|
60
|
-
error: TError;
|
|
61
73
|
key: TKey;
|
|
62
|
-
}
|
|
63
|
-
data: TData;
|
|
64
|
-
error: TError;
|
|
65
|
-
key: TKey;
|
|
66
|
-
services: TServices;
|
|
67
|
-
};
|
|
74
|
+
} & ErrorPart<TError> & ServicesPart<TServices> & ThrowPart<TThrow>>;
|
|
68
75
|
/** As {@link QueryTypesOf}, for a paged query. */
|
|
69
|
-
type InfiniteQueryTypesOf<TPage, TPageParam, TError, TServices, TKey> =
|
|
70
|
-
key: TKey;
|
|
71
|
-
page: TPage;
|
|
72
|
-
pageParam: TPageParam;
|
|
73
|
-
} : {
|
|
76
|
+
type InfiniteQueryTypesOf<TPage, TPageParam, TError, TServices, TKey, TThrow> = Flat<{
|
|
74
77
|
key: TKey;
|
|
75
78
|
page: TPage;
|
|
76
79
|
pageParam: TPageParam;
|
|
77
|
-
|
|
78
|
-
} : [TServices] extends [never] ? {
|
|
79
|
-
error: TError;
|
|
80
|
-
key: TKey;
|
|
81
|
-
page: TPage;
|
|
82
|
-
pageParam: TPageParam;
|
|
83
|
-
} : {
|
|
84
|
-
error: TError;
|
|
85
|
-
key: TKey;
|
|
86
|
-
page: TPage;
|
|
87
|
-
pageParam: TPageParam;
|
|
88
|
-
services: TServices;
|
|
89
|
-
};
|
|
80
|
+
} & ErrorPart<TError> & ServicesPart<TServices> & ThrowPart<TThrow>>;
|
|
90
81
|
/**
|
|
91
82
|
* What a `queryFn` may return: a value, a promise, or an `Effect`. An
|
|
92
83
|
* Effect's error type becomes the query's (promises reject with `unknown`),
|
|
@@ -183,7 +174,17 @@ interface ServicesField<TServices> {
|
|
|
183
174
|
*/
|
|
184
175
|
readonly [servicesType]?: () => TServices;
|
|
185
176
|
}
|
|
186
|
-
|
|
177
|
+
interface ThrowOnErrorField<TThrow> {
|
|
178
|
+
/**
|
|
179
|
+
* How reads of this query settle on failure when they don't set
|
|
180
|
+
* `throwOnError` themselves: `true` rejects (to an error boundary),
|
|
181
|
+
* `false` settles with a `Result`. Omit it for the client's default.
|
|
182
|
+
* Only an Effect `queryFn`'s typed error reads as a `Result`; a promise
|
|
183
|
+
* `queryFn` always rejects.
|
|
184
|
+
*/
|
|
185
|
+
readonly throwOnError?: TThrow;
|
|
186
|
+
}
|
|
187
|
+
export interface QueryOptions<TTypes extends QueryTypes> extends QueryBehavior, ServicesField<ServicesIn<TTypes>>, ThrowOnErrorField<ThrowIn<TTypes>> {
|
|
187
188
|
readonly kind: "query";
|
|
188
189
|
queryFn(context: QueryFunctionContext): QueryFnResult<TTypes>;
|
|
189
190
|
readonly queryKey: KeyIn<TTypes>;
|
|
@@ -205,7 +206,7 @@ export interface InfiniteQueryOptions<TTypes extends InfiniteQueryTypes> extends
|
|
|
205
206
|
data: TTypes["page"];
|
|
206
207
|
error: ErrorIn<TTypes>;
|
|
207
208
|
services: ServicesIn<TTypes>;
|
|
208
|
-
}>>, QueryBehavior, ServicesField<ServicesIn<TTypes>> {
|
|
209
|
+
}>>, QueryBehavior, ServicesField<ServicesIn<TTypes>>, ThrowOnErrorField<ThrowIn<TTypes>> {
|
|
209
210
|
readonly initialPageParam: TTypes["pageParam"];
|
|
210
211
|
readonly kind: "infinite";
|
|
211
212
|
/** Keep at most this many pages; the far end is dropped when paging. */
|
|
@@ -221,11 +222,13 @@ export type AnyQueryOptions = QueryOptions<{
|
|
|
221
222
|
data: unknown;
|
|
222
223
|
error: unknown;
|
|
223
224
|
services: unknown;
|
|
225
|
+
throwOnError: boolean;
|
|
224
226
|
}> | InfiniteQueryOptions<{
|
|
225
227
|
error: unknown;
|
|
226
228
|
page: unknown;
|
|
227
229
|
pageParam: unknown;
|
|
228
230
|
services: unknown;
|
|
231
|
+
throwOnError: boolean;
|
|
229
232
|
}>;
|
|
230
233
|
/**
|
|
231
234
|
* Typed options for a query factory:
|
|
@@ -248,28 +251,33 @@ export type AnyQueryOptions = QueryOptions<{
|
|
|
248
251
|
* factories with the same input and data but different keys have different
|
|
249
252
|
* types, and a handle of one doesn't type-check where the other's goes.
|
|
250
253
|
*
|
|
254
|
+
* `throwOnError: true` or `false` is kept as a literal too, so reads that
|
|
255
|
+
* don't set their own follow it in their types.
|
|
256
|
+
*
|
|
251
257
|
* The type parameters are only there for TypeScript to infer the types bag
|
|
252
|
-
* from `queryFn` and `
|
|
258
|
+
* from `queryFn`, `queryKey` and `throwOnError`; it can't infer a bag's
|
|
259
|
+
* members. Passing them explicitly, pass `TThrow` too when setting
|
|
260
|
+
* `throwOnError`.
|
|
253
261
|
*/
|
|
254
|
-
export declare function queryOptions<TData, TError = unknown, TServices = never, const TKey extends QueryKey = QueryKey>(options: Omit<QueryOptions<{
|
|
262
|
+
export declare function queryOptions<TData, TError = unknown, TServices = never, const TKey extends QueryKey = QueryKey, TThrow extends boolean | undefined = undefined>(options: Omit<QueryOptions<{
|
|
255
263
|
data: TData;
|
|
256
264
|
error: TError;
|
|
257
265
|
key: TKey;
|
|
258
266
|
services: TServices;
|
|
259
|
-
}>, "kind">): QueryOptions<QueryTypesOf<TData, TError, TServices, TKey>>;
|
|
267
|
+
}>, "kind" | "throwOnError"> & ThrowOnErrorField<TThrow>): QueryOptions<QueryTypesOf<TData, TError, TServices, TKey, TThrow>>;
|
|
260
268
|
/**
|
|
261
269
|
* Typed options for a paged query factory. The page type is inferred from
|
|
262
270
|
* `queryFn`, as in {@link queryOptions}. So is an Effect `queryFn`'s error;
|
|
263
271
|
* a promise or a plain value leaves `error` out. The key's literal type is
|
|
264
272
|
* kept, as in {@link queryOptions}.
|
|
265
273
|
*/
|
|
266
|
-
export declare function infiniteQueryOptions<TPage, TPageParam, TError = unknown, TServices = never, const TKey extends QueryKey = QueryKey>(options: Omit<InfiniteQueryOptions<{
|
|
274
|
+
export declare function infiniteQueryOptions<TPage, TPageParam, TError = unknown, TServices = never, const TKey extends QueryKey = QueryKey, TThrow extends boolean | undefined = undefined>(options: Omit<InfiniteQueryOptions<{
|
|
267
275
|
error: TError;
|
|
268
276
|
key: TKey;
|
|
269
277
|
page: TPage;
|
|
270
278
|
pageParam: TPageParam;
|
|
271
279
|
services: TServices;
|
|
272
|
-
}>, "kind">): InfiniteQueryOptions<InfiniteQueryTypesOf<TPage, TPageParam, TError, TServices, TKey>>;
|
|
280
|
+
}>, "kind" | "throwOnError"> & ThrowOnErrorField<TThrow>): InfiniteQueryOptions<InfiniteQueryTypesOf<TPage, TPageParam, TError, TServices, TKey, TThrow>>;
|
|
273
281
|
interface FactoryResult {
|
|
274
282
|
readonly kind: "infinite" | "query";
|
|
275
283
|
readonly queryKey: QueryKey;
|
|
@@ -327,6 +335,11 @@ export type ErrorOf<TFactory extends QueryFactory> = ReturnType<TFactory> extend
|
|
|
327
335
|
* values, and for a factory of no particular query.
|
|
328
336
|
*/
|
|
329
337
|
export type ServicesOf<TFactory extends QueryFactory> = ReturnType<TFactory> extends InfiniteQueryOptions<infer TTypes> ? ServicesIn<TTypes> : ReturnType<TFactory> extends QueryOptions<infer TTypes> ? ServicesIn<TTypes> : never;
|
|
338
|
+
/**
|
|
339
|
+
* The `throwOnError` a factory's options set, `undefined` when they set
|
|
340
|
+
* none (or for a factory of no particular query).
|
|
341
|
+
*/
|
|
342
|
+
export type ThrowOnErrorOf<TFactory extends QueryFactory> = ReturnType<TFactory> extends InfiniteQueryOptions<infer TTypes> ? ThrowIn<TTypes> : ReturnType<TFactory> extends QueryOptions<infer TTypes> ? ThrowIn<TTypes> : undefined;
|
|
330
343
|
/** Page type of a paged factory. */
|
|
331
344
|
export type PageOf<TFactory extends QueryFactory> = ReturnType<TFactory> extends InfiniteQueryOptions<infer TTypes> ? TTypes["page"] : never;
|
|
332
345
|
/**
|
package/dist/options.mjs
CHANGED
|
@@ -20,8 +20,13 @@
|
|
|
20
20
|
* factories with the same input and data but different keys have different
|
|
21
21
|
* types, and a handle of one doesn't type-check where the other's goes.
|
|
22
22
|
*
|
|
23
|
+
* `throwOnError: true` or `false` is kept as a literal too, so reads that
|
|
24
|
+
* don't set their own follow it in their types.
|
|
25
|
+
*
|
|
23
26
|
* The type parameters are only there for TypeScript to infer the types bag
|
|
24
|
-
* from `queryFn` and `
|
|
27
|
+
* from `queryFn`, `queryKey` and `throwOnError`; it can't infer a bag's
|
|
28
|
+
* members. Passing them explicitly, pass `TThrow` too when setting
|
|
29
|
+
* `throwOnError`.
|
|
25
30
|
*/
|
|
26
31
|
function queryOptions(options) {
|
|
27
32
|
return {
|