@raf-query/core 0.4.5 → 0.5.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 +17 -1
- package/dist/cache.d.mts +3 -3
- package/dist/entry.d.mts +1 -1
- package/dist/hydration.d.mts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/observer.d.mts +15 -14
- package/dist/options.d.mts +101 -18
- package/dist/options.mjs +7 -1
- package/dist/query.d.mts +26 -24
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.5.1](https://github.com/KATT/raf-query/compare/0.5.0...0.5.1) (2026-10-14)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* raf-query logo, brand colors, and a system / light / dark switcher ([#68](https://github.com/KATT/raf-query/issues/68)) ([9ae09c6](https://github.com/KATT/raf-query/commit/9ae09c63b4f60f4109a8fa6389b8b4f7adfd2ab8))
|
|
8
|
+
|
|
9
|
+
## [0.5.0](https://github.com/KATT/raf-query/compare/0.4.5...0.5.0) (2026-10-14)
|
|
10
|
+
|
|
11
|
+
### ⚠ BREAKING CHANGES
|
|
12
|
+
|
|
13
|
+
- type options by a bag instead of positional type arguments ([#69](https://github.com/KATT/raf-query/issues/69))
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
- type options by a bag instead of positional type arguments ([#69](https://github.com/KATT/raf-query/issues/69)) ([df7ef81](https://github.com/KATT/raf-query/commit/df7ef816d33039166686cfe1113333bb6c444a27))
|
|
18
|
+
|
|
3
19
|
## [0.4.5](https://github.com/KATT/raf-query/compare/0.4.4...0.4.5) (2026-10-14)
|
|
4
20
|
|
|
5
|
-
|
|
21
|
+
- trim the READMEs, give each package its own, and warn that raf-query is early on the docs site ([#70](https://github.com/KATT/raf-query/issues/70)) ([2c06462](https://github.com/KATT/raf-query/commit/2c0646291f5fc45d2d64bc43c52f3e089c46ce05))
|
|
6
22
|
|
|
7
23
|
## [0.4.4](https://github.com/KATT/raf-query/compare/0.4.3...0.4.4) (2026-10-14)
|
|
8
24
|
|
package/dist/cache.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { QueryKey } from "./key.mjs";
|
|
2
2
|
import { DataOf, EnsuredQueryHandle, ErrorOf, InputArgs, InputOf, LoadOptions, QueryBehavior, QueryFactory, QueryHandle, ServicesOf } from "./options.mjs";
|
|
3
3
|
import { DehydrateOptions, DehydratedState, DehydratedStream, HydrateOptions } from "./hydration.mjs";
|
|
4
|
-
import { CancelledError,
|
|
4
|
+
import { CancelledError, Query, State, query_d_exports } from "./query.mjs";
|
|
5
5
|
import { Context, Effect, Layer, Option, Scope, Stream } from "effect";
|
|
6
6
|
declare namespace cache_d_exports {
|
|
7
7
|
export { Config, Event, Filter, LoadArgs, QueryCache, Target, TypeId, Updater, isQueryCache, layer, make };
|
|
@@ -94,12 +94,12 @@ export interface QueryCache {
|
|
|
94
94
|
* but its requests run with this fiber's services from now on. For
|
|
95
95
|
* bindings; apps use the verbs.
|
|
96
96
|
*/
|
|
97
|
-
getQuery<TFactory extends QueryFactory>(factory: TFactory, ...args: InputArgs<TFactory>): Effect.Effect<
|
|
97
|
+
getQuery<TFactory extends QueryFactory>(factory: TFactory, ...args: InputArgs<TFactory>): Effect.Effect<Query<TFactory>, never, ServicesOf<TFactory>>;
|
|
98
98
|
/**
|
|
99
99
|
* `getQuery`, synchronously, for renders. Leaves the entry's services as
|
|
100
100
|
* they are: the cache's, or the latest verb caller's.
|
|
101
101
|
*/
|
|
102
|
-
getQueryUnsafe<TFactory extends QueryFactory>(factory: TFactory, ...args: InputArgs<TFactory>):
|
|
102
|
+
getQueryUnsafe<TFactory extends QueryFactory>(factory: TFactory, ...args: InputArgs<TFactory>): Query<TFactory>;
|
|
103
103
|
/**
|
|
104
104
|
* Write dehydrated entries. Existing entries only take newer data; pending
|
|
105
105
|
* entries resume the sender's request.
|
package/dist/entry.d.mts
CHANGED
|
@@ -83,7 +83,7 @@ export interface Entry extends Query {
|
|
|
83
83
|
readonly tasks: Tasks;
|
|
84
84
|
}
|
|
85
85
|
export declare function isQuery(value: unknown): value is Query;
|
|
86
|
-
export declare function entryOf<
|
|
86
|
+
export declare function entryOf<TFactory extends QueryFactory>(query: Query<TFactory>): Entry;
|
|
87
87
|
export declare function emit(cache: CacheState, event: Event): void;
|
|
88
88
|
export declare function make(cache: CacheState, key: QueryKey, hash: string): Entry;
|
|
89
89
|
export declare function now(entry: Entry): number;
|
package/dist/hydration.d.mts
CHANGED
|
@@ -76,7 +76,7 @@ export declare class RedactedError extends RedactedError_base<{
|
|
|
76
76
|
get message(): string;
|
|
77
77
|
}
|
|
78
78
|
/** The default dehydrate filter: entries with data or a request in flight. */
|
|
79
|
-
export declare function canDehydrate<
|
|
79
|
+
export declare function canDehydrate<TFactory extends QueryFactory>(query: Query<TFactory>): boolean;
|
|
80
80
|
/** Snapshot one entry for transfer. */
|
|
81
|
-
export declare function dehydrateQuery<
|
|
81
|
+
export declare function dehydrateQuery<TFactory extends QueryFactory>(query: Query<TFactory>, options?: DehydrateOptions): Effect.Effect<DehydratedQuery>;
|
|
82
82
|
//#endregion
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { platform_d_exports } from "./platform.mjs";
|
|
2
2
|
import { QueryKey, hashKey, matchesKey } from "./key.mjs";
|
|
3
|
-
import { AnyQueryOptions, DataOf, EnsuredQueryHandle, ErrorOf, InfiniteData, InfiniteQueryOptions, InputArgs, InputOf, IsPaged, LoadOptions, PageFunctionContext, PageOf, QueryBehavior, QueryFactory, QueryFnResult, QueryFunctionContext, QueryHandle, QueryMeta, QueryOptions, Register, RetryPolicy, ServicesOf, infiniteQueryOptions, queryOptions } from "./options.mjs";
|
|
3
|
+
import { AnyQueryOptions, DataOf, EnsuredQueryHandle, ErrorOf, InfiniteData, InfiniteQueryOptions, InfiniteQueryTypes, InputArgs, InputOf, IsPaged, LoadOptions, PageFunctionContext, PageOf, QueryBehavior, QueryFactory, QueryFnResult, QueryFunctionContext, QueryHandle, QueryMeta, QueryOptions, QueryTypes, Register, RetryPolicy, ServicesOf, infiniteQueryOptions, queryOptions } from "./options.mjs";
|
|
4
4
|
import { DehydrateOptions, DehydratedQuery, DehydratedResult, DehydratedState, DehydratedStream, HydrateOptions, RedactedError, canDehydrate, dehydrateQuery } from "./hydration.mjs";
|
|
5
5
|
import { cache_d_exports } from "./cache.mjs";
|
|
6
6
|
import { Thenable } from "./thenable.mjs";
|
|
7
7
|
import { query_d_exports } from "./query.mjs";
|
|
8
8
|
import { observer_d_exports } from "./observer.mjs";
|
|
9
|
-
export { type AnyQueryOptions, type DataOf, type DehydrateOptions, type DehydratedQuery, type DehydratedResult, type DehydratedState, type DehydratedStream, type EnsuredQueryHandle, type ErrorOf, type HydrateOptions, type InfiniteData, type InfiniteQueryOptions, type InputArgs, type InputOf, type IsPaged, type LoadOptions, type PageFunctionContext, type PageOf, platform_d_exports as Platform, query_d_exports as Query, type QueryBehavior, cache_d_exports as QueryCache, type QueryFactory, type QueryFnResult, type QueryFunctionContext, type QueryHandle, type QueryKey, type QueryMeta, observer_d_exports as QueryObserver, type QueryOptions, RedactedError, type Register, type RetryPolicy, type ServicesOf, type Thenable, canDehydrate, dehydrateQuery, hashKey, infiniteQueryOptions, matchesKey, queryOptions };
|
|
9
|
+
export { type AnyQueryOptions, type DataOf, type DehydrateOptions, type DehydratedQuery, type DehydratedResult, type DehydratedState, type DehydratedStream, type EnsuredQueryHandle, type ErrorOf, type HydrateOptions, type InfiniteData, type InfiniteQueryOptions, type InfiniteQueryTypes, type InputArgs, type InputOf, type IsPaged, type LoadOptions, type PageFunctionContext, type PageOf, platform_d_exports as Platform, query_d_exports as Query, type QueryBehavior, cache_d_exports as QueryCache, type QueryFactory, type QueryFnResult, type QueryFunctionContext, type QueryHandle, type QueryKey, type QueryMeta, observer_d_exports as QueryObserver, type QueryOptions, type QueryTypes, RedactedError, type Register, type RetryPolicy, type ServicesOf, type Thenable, canDehydrate, dehydrateQuery, hashKey, infiniteQueryOptions, matchesKey, queryOptions };
|
package/dist/observer.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { QueryKey } from "./key.mjs";
|
|
2
|
-
import { QueryFactory } from "./options.mjs";
|
|
2
|
+
import { DataOf, QueryFactory } from "./options.mjs";
|
|
3
3
|
import { Thenable } from "./thenable.mjs";
|
|
4
4
|
import { Query, query_d_exports } from "./query.mjs";
|
|
5
5
|
import { Effect, Pipeable, Stream } from "effect";
|
|
@@ -57,45 +57,46 @@ export interface Result<TData = unknown> {
|
|
|
57
57
|
readonly updatedAt: number;
|
|
58
58
|
}
|
|
59
59
|
export type ResultKey = keyof Result;
|
|
60
|
-
|
|
60
|
+
/** An observer of a factory's queries; its results hold the factory's {@link DataOf}. */
|
|
61
|
+
export interface QueryObserver<TFactory extends QueryFactory = QueryFactory> extends Pipeable.Pipeable {
|
|
61
62
|
/** The options set by the latest `make` or {@link setOptionsUnsafe}. */
|
|
62
63
|
readonly options: Options;
|
|
63
64
|
/** The observed query. */
|
|
64
|
-
readonly query: Query<
|
|
65
|
+
readonly query: Query<TFactory>;
|
|
65
66
|
readonly [TypeId]: {
|
|
66
|
-
readonly _A: (_: never) =>
|
|
67
|
+
readonly _A: (_: never) => DataOf<TFactory>;
|
|
67
68
|
};
|
|
68
69
|
}
|
|
69
70
|
export declare function isQueryObserver(value: unknown): value is QueryObserver;
|
|
70
71
|
/** Observe `query`. Doesn't subscribe to it until the observer has a listener. */
|
|
71
|
-
export declare function makeUnsafe<
|
|
72
|
+
export declare function makeUnsafe<TFactory extends QueryFactory>(query: Query<TFactory>, options?: Options): QueryObserver<TFactory>;
|
|
72
73
|
/** {@link makeUnsafe}, as an Effect. */
|
|
73
|
-
export declare function make<
|
|
74
|
+
export declare function make<TFactory extends QueryFactory>(query: Query<TFactory>, options?: Options): Effect.Effect<QueryObserver<TFactory>>;
|
|
74
75
|
/** The current result. */
|
|
75
|
-
export declare function getUnsafe<
|
|
76
|
+
export declare function getUnsafe<TFactory extends QueryFactory>(self: QueryObserver<TFactory>): Result<DataOf<TFactory>>;
|
|
76
77
|
/** {@link getUnsafe}, as an Effect. */
|
|
77
|
-
export declare function get<
|
|
78
|
+
export declare function get<TFactory extends QueryFactory>(self: QueryObserver<TFactory>): Effect.Effect<Result<DataOf<TFactory>>>;
|
|
78
79
|
/**
|
|
79
80
|
* The result for `query` with `options` right now, without switching to
|
|
80
81
|
* them. Bindings call this during render, before `setOptionsUnsafe` commits.
|
|
81
82
|
*/
|
|
82
|
-
export declare function getOptimisticResultUnsafe<
|
|
83
|
+
export declare function getOptimisticResultUnsafe<TFactory extends QueryFactory>(self: QueryObserver<TFactory>, query: Query<TFactory>, options: Options): Result<DataOf<TFactory>>;
|
|
83
84
|
/** Observe `query` with `options` from now on. */
|
|
84
|
-
export declare function setOptionsUnsafe<
|
|
85
|
+
export declare function setOptionsUnsafe<TFactory extends QueryFactory>(self: QueryObserver<TFactory>, query: Query<TFactory>, options: Options): void;
|
|
85
86
|
/** Listen for result changes. The first listener subscribes to the query. */
|
|
86
|
-
export declare function subscribeUnsafe<
|
|
87
|
+
export declare function subscribeUnsafe<TFactory extends QueryFactory>(self: QueryObserver<TFactory>, listener: () => void): () => void;
|
|
87
88
|
/**
|
|
88
89
|
* The current result, then every change listeners are notified of. Counts
|
|
89
90
|
* as a listener while the stream runs, so the query counts as read.
|
|
90
91
|
*/
|
|
91
|
-
export declare function changes<
|
|
92
|
+
export declare function changes<TFactory extends QueryFactory>(self: QueryObserver<TFactory>): Stream.Stream<Result<DataOf<TFactory>>>;
|
|
92
93
|
/**
|
|
93
94
|
* Wrap `result` so that reading a property marks it tracked. Once any
|
|
94
95
|
* property is tracked, listeners are only notified when a tracked one
|
|
95
96
|
* changes.
|
|
96
97
|
*/
|
|
97
|
-
export declare function trackResult<
|
|
98
|
+
export declare function trackResult<TFactory extends QueryFactory, TResult extends Result<DataOf<TFactory>>>(self: QueryObserver<TFactory>, result: TResult): TResult;
|
|
98
99
|
/** Mark `name` as read, for bindings that track access themselves. */
|
|
99
|
-
export declare function trackProp<
|
|
100
|
+
export declare function trackProp<TFactory extends QueryFactory>(self: QueryObserver<TFactory>, name: ResultKey): void;
|
|
100
101
|
//#endregion
|
|
101
102
|
export { observer_d_exports };
|
package/dist/options.d.mts
CHANGED
|
@@ -1,12 +1,44 @@
|
|
|
1
1
|
import { QueryKey } from "./key.mjs";
|
|
2
2
|
import { Effect, Schedule } from "effect";
|
|
3
3
|
//#region src/options.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The types of a plain query: what its `queryFn` resolves to, and for an
|
|
6
|
+
* Effect `queryFn`, its error and the services it needs. `error` defaults to
|
|
7
|
+
* `unknown` (promises reject with anything), `services` to `never`.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* type PostOptions = QueryOptions<{ data: Post }>;
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export interface QueryTypes {
|
|
14
|
+
readonly data: unknown;
|
|
15
|
+
readonly error?: unknown;
|
|
16
|
+
readonly services?: unknown;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The types of a paged query: one page, the param that loads it, and as in
|
|
20
|
+
* {@link QueryTypes}, an Effect `queryFn`'s error and services.
|
|
21
|
+
*/
|
|
22
|
+
export interface InfiniteQueryTypes {
|
|
23
|
+
readonly error?: unknown;
|
|
24
|
+
readonly page: unknown;
|
|
25
|
+
readonly pageParam: unknown;
|
|
26
|
+
readonly services?: unknown;
|
|
27
|
+
}
|
|
28
|
+
/** `error` of a types bag, `unknown` when it has none. */
|
|
29
|
+
type ErrorIn<TTypes> = TTypes extends {
|
|
30
|
+
readonly error: infer TError;
|
|
31
|
+
} ? TError : unknown;
|
|
32
|
+
/** `services` of a types bag, `never` when it has none. */
|
|
33
|
+
type ServicesIn<TTypes> = TTypes extends {
|
|
34
|
+
readonly services: infer TServices;
|
|
35
|
+
} ? TServices : never;
|
|
4
36
|
/**
|
|
5
37
|
* What a `queryFn` may return: a value, a promise, or an `Effect`. An
|
|
6
38
|
* Effect's error type becomes the query's (promises reject with `unknown`),
|
|
7
39
|
* and the services it needs become requirements of the verbs that start it.
|
|
8
40
|
*/
|
|
9
|
-
export type QueryFnResult<
|
|
41
|
+
export type QueryFnResult<TTypes extends QueryTypes> = TTypes["data"] | PromiseLike<TTypes["data"]> | Effect.Effect<TTypes["data"], ErrorIn<TTypes>, ServicesIn<TTypes>>;
|
|
10
42
|
/**
|
|
11
43
|
* App-wide types, filled in by module augmentation. Declare `queryMeta` to
|
|
12
44
|
* type every query's `meta`. Augment the package you import from;
|
|
@@ -83,29 +115,50 @@ interface ServicesField<TServices> {
|
|
|
83
115
|
*/
|
|
84
116
|
readonly [servicesType]?: () => TServices;
|
|
85
117
|
}
|
|
86
|
-
export interface QueryOptions<
|
|
118
|
+
export interface QueryOptions<TTypes extends QueryTypes> extends QueryBehavior, ServicesField<ServicesIn<TTypes>> {
|
|
87
119
|
readonly kind: "query";
|
|
88
|
-
queryFn(context: QueryFunctionContext): QueryFnResult<
|
|
120
|
+
queryFn(context: QueryFunctionContext): QueryFnResult<TTypes>;
|
|
89
121
|
readonly queryKey: QueryKey;
|
|
90
122
|
}
|
|
91
|
-
|
|
123
|
+
/**
|
|
124
|
+
* The functions of paged options, typed by the page and page param types
|
|
125
|
+
* themselves. Typed through the bag, inference breaks: TypeScript fixes
|
|
126
|
+
* every type parameter a contextually typed parameter's type mentions, so
|
|
127
|
+
* `context` would fix the page type before `queryFn`'s return could infer it.
|
|
128
|
+
*/
|
|
129
|
+
interface PageFunctions<TPage, TPageParam, TResult> {
|
|
92
130
|
/** Param for the page after `lastPage`, or `null` / `undefined` at the end. */
|
|
93
131
|
getNextPageParam(lastPage: TPage, pages: ReadonlyArray<TPage>, lastPageParam: TPageParam, pageParams: ReadonlyArray<TPageParam>): TPageParam | null | undefined;
|
|
94
132
|
/** Param for the page before `firstPage`, or `null` / `undefined` at the start. */
|
|
95
133
|
getPreviousPageParam?(firstPage: TPage, pages: ReadonlyArray<TPage>, firstPageParam: TPageParam, pageParams: ReadonlyArray<TPageParam>): TPageParam | null | undefined;
|
|
96
|
-
|
|
134
|
+
queryFn(context: PageFunctionContext<TPageParam>): TResult;
|
|
135
|
+
}
|
|
136
|
+
export interface InfiniteQueryOptions<TTypes extends InfiniteQueryTypes> extends PageFunctions<TTypes["page"], TTypes["pageParam"], QueryFnResult<{
|
|
137
|
+
data: TTypes["page"];
|
|
138
|
+
error: ErrorIn<TTypes>;
|
|
139
|
+
services: ServicesIn<TTypes>;
|
|
140
|
+
}>>, QueryBehavior, ServicesField<ServicesIn<TTypes>> {
|
|
141
|
+
readonly initialPageParam: TTypes["pageParam"];
|
|
97
142
|
readonly kind: "infinite";
|
|
98
143
|
/** Keep at most this many pages; the far end is dropped when paging. */
|
|
99
144
|
readonly maxPages?: number;
|
|
100
|
-
queryFn(context: PageFunctionContext<TPageParam>): QueryFnResult<TPage, TError, TServices>;
|
|
101
145
|
readonly queryKey: QueryKey;
|
|
102
146
|
}
|
|
103
147
|
/** Data of a paged query. */
|
|
104
|
-
export interface InfiniteData<
|
|
105
|
-
readonly pageParams: ReadonlyArray<
|
|
106
|
-
readonly pages: ReadonlyArray<
|
|
148
|
+
export interface InfiniteData<TTypes extends Pick<InfiniteQueryTypes, "page" | "pageParam">> {
|
|
149
|
+
readonly pageParams: ReadonlyArray<TTypes["pageParam"]>;
|
|
150
|
+
readonly pages: ReadonlyArray<TTypes["page"]>;
|
|
107
151
|
}
|
|
108
|
-
export type AnyQueryOptions = QueryOptions<
|
|
152
|
+
export type AnyQueryOptions = QueryOptions<{
|
|
153
|
+
data: unknown;
|
|
154
|
+
error: unknown;
|
|
155
|
+
services: unknown;
|
|
156
|
+
}> | InfiniteQueryOptions<{
|
|
157
|
+
error: unknown;
|
|
158
|
+
page: unknown;
|
|
159
|
+
pageParam: unknown;
|
|
160
|
+
services: unknown;
|
|
161
|
+
}>;
|
|
109
162
|
/**
|
|
110
163
|
* Typed options for a query factory:
|
|
111
164
|
*
|
|
@@ -120,10 +173,34 @@ export type AnyQueryOptions = QueryOptions<unknown, unknown, unknown> | Infinite
|
|
|
120
173
|
*
|
|
121
174
|
* A `queryFn` Effect may need services; they're inferred, and every verb
|
|
122
175
|
* that can start the query requires them.
|
|
176
|
+
*
|
|
177
|
+
* The type parameters are only there for TypeScript to infer the types bag
|
|
178
|
+
* from `queryFn`; it can't infer a bag's members.
|
|
123
179
|
*/
|
|
124
|
-
export declare function queryOptions<TData, TError = unknown, TServices = never>(options: Omit<QueryOptions<
|
|
125
|
-
|
|
126
|
-
|
|
180
|
+
export declare function queryOptions<TData, TError = unknown, TServices = never>(options: Omit<QueryOptions<{
|
|
181
|
+
data: TData;
|
|
182
|
+
error: TError;
|
|
183
|
+
services: TServices;
|
|
184
|
+
}>, "kind">): QueryOptions<{
|
|
185
|
+
data: TData;
|
|
186
|
+
error: TError;
|
|
187
|
+
services: TServices;
|
|
188
|
+
}>;
|
|
189
|
+
/**
|
|
190
|
+
* Typed options for a paged query factory. The page type is inferred from
|
|
191
|
+
* `queryFn`, as in {@link queryOptions}.
|
|
192
|
+
*/
|
|
193
|
+
export declare function infiniteQueryOptions<TPage, TPageParam, TError = unknown, TServices = never>(options: Omit<InfiniteQueryOptions<{
|
|
194
|
+
error: TError;
|
|
195
|
+
page: TPage;
|
|
196
|
+
pageParam: TPageParam;
|
|
197
|
+
services: TServices;
|
|
198
|
+
}>, "kind">): InfiniteQueryOptions<{
|
|
199
|
+
error: TError;
|
|
200
|
+
page: TPage;
|
|
201
|
+
pageParam: TPageParam;
|
|
202
|
+
services: TServices;
|
|
203
|
+
}>;
|
|
127
204
|
interface FactoryResult {
|
|
128
205
|
readonly kind: "infinite" | "query";
|
|
129
206
|
readonly queryKey: QueryKey;
|
|
@@ -147,21 +224,27 @@ export type InputArgs<TFactory extends QueryFactory> = [] extends Parameters<TFa
|
|
|
147
224
|
export type IsPaged<TFactory extends QueryFactory> = ReturnType<TFactory> extends {
|
|
148
225
|
readonly kind: "infinite";
|
|
149
226
|
} ? true : false;
|
|
150
|
-
/**
|
|
151
|
-
|
|
227
|
+
/**
|
|
228
|
+
* The data a factory's query resolves to; `unknown` for a factory of no
|
|
229
|
+
* particular query.
|
|
230
|
+
*/
|
|
231
|
+
export type DataOf<TFactory extends QueryFactory> = ReturnType<TFactory> extends InfiniteQueryOptions<infer TTypes> ? InfiniteData<{
|
|
232
|
+
page: TTypes["page"];
|
|
233
|
+
pageParam: TTypes["pageParam"];
|
|
234
|
+
}> : ReturnType<TFactory> extends QueryOptions<infer TTypes> ? TTypes["data"] : unknown;
|
|
152
235
|
/**
|
|
153
236
|
* The error a factory's request fails with: the `queryFn`'s Effect error
|
|
154
237
|
* type, or `unknown` for promises and plain values.
|
|
155
238
|
*/
|
|
156
|
-
export type ErrorOf<TFactory extends QueryFactory> = ReturnType<TFactory> extends InfiniteQueryOptions<infer
|
|
239
|
+
export type ErrorOf<TFactory extends QueryFactory> = ReturnType<TFactory> extends InfiniteQueryOptions<infer TTypes> ? ErrorIn<TTypes> : ReturnType<TFactory> extends QueryOptions<infer TTypes> ? ErrorIn<TTypes> : unknown;
|
|
157
240
|
/**
|
|
158
241
|
* The services a factory's `queryFn` Effect needs: what `ensure`, `fetch`,
|
|
159
242
|
* `prefetch`, `getQuery` and `watch` require. `never` for promises and plain
|
|
160
243
|
* values, and for a factory of no particular query.
|
|
161
244
|
*/
|
|
162
|
-
export type ServicesOf<TFactory extends QueryFactory> = ReturnType<TFactory> extends InfiniteQueryOptions<infer
|
|
245
|
+
export type ServicesOf<TFactory extends QueryFactory> = ReturnType<TFactory> extends InfiniteQueryOptions<infer TTypes> ? ServicesIn<TTypes> : ReturnType<TFactory> extends QueryOptions<infer TTypes> ? ServicesIn<TTypes> : never;
|
|
163
246
|
/** Page type of a paged factory. */
|
|
164
|
-
export type PageOf<TFactory extends QueryFactory> = ReturnType<TFactory> extends InfiniteQueryOptions<infer
|
|
247
|
+
export type PageOf<TFactory extends QueryFactory> = ReturnType<TFactory> extends InfiniteQueryOptions<infer TTypes> ? TTypes["page"] : never;
|
|
165
248
|
/** `ensure` / `fetch` options. Only paged factories accept `pages`. */
|
|
166
249
|
export type LoadOptions<TFactory extends QueryFactory> = IsPaged<TFactory> extends true ? {
|
|
167
250
|
/** Load this many pages up front (default 1). */
|
package/dist/options.mjs
CHANGED
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
*
|
|
14
14
|
* A `queryFn` Effect may need services; they're inferred, and every verb
|
|
15
15
|
* that can start the query requires them.
|
|
16
|
+
*
|
|
17
|
+
* The type parameters are only there for TypeScript to infer the types bag
|
|
18
|
+
* from `queryFn`; it can't infer a bag's members.
|
|
16
19
|
*/
|
|
17
20
|
function queryOptions(options) {
|
|
18
21
|
return {
|
|
@@ -20,7 +23,10 @@ function queryOptions(options) {
|
|
|
20
23
|
kind: "query"
|
|
21
24
|
};
|
|
22
25
|
}
|
|
23
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Typed options for a paged query factory. The page type is inferred from
|
|
28
|
+
* `queryFn`, as in {@link queryOptions}.
|
|
29
|
+
*/
|
|
24
30
|
function infiniteQueryOptions(options) {
|
|
25
31
|
return {
|
|
26
32
|
...options,
|
package/dist/query.d.mts
CHANGED
|
@@ -5,11 +5,15 @@ import { CancelledError as CancelledError$1, TypeId as TypeId$1, entry_d_exports
|
|
|
5
5
|
import { Direction } from "./infinite.mjs";
|
|
6
6
|
import { Effect, Pipeable, Stream } from "effect";
|
|
7
7
|
declare namespace query_d_exports {
|
|
8
|
-
export { CancelledError, FetchRequest,
|
|
8
|
+
export { CancelledError, FetchRequest, Query, State, SubscribeOptions, TypeId, changes, fetch, fetchNextPage, fetchPreviousPage, get, getUnsafe, hasNextPageUnsafe, hasPreviousPageUnsafe, invalidate, isQuery, isStaleUnsafe, metaUnsafe, observerCountUnsafe, readUnsafe, refetch, reset, revalidateUnsafe, subscribeUnsafe };
|
|
9
9
|
}
|
|
10
10
|
export declare const TypeId: typeof TypeId$1;
|
|
11
11
|
export type TypeId = typeof TypeId;
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* A cache entry, typed by the factory whose calls fill it: its data is the
|
|
14
|
+
* factory's {@link DataOf}, its error the factory's {@link ErrorOf}.
|
|
15
|
+
*/
|
|
16
|
+
export interface Query<TFactory extends QueryFactory = QueryFactory> extends Pipeable.Pipeable {
|
|
13
17
|
/** The serializable handle for this entry's factory call. */
|
|
14
18
|
readonly handle: QueryHandle<TFactory>;
|
|
15
19
|
/** Stable string form of `key`. */
|
|
@@ -18,12 +22,10 @@ export interface Query<TData = unknown, TFactory extends QueryFactory = QueryFac
|
|
|
18
22
|
/** Options from the latest factory call; `undefined` for an entry only hydrated so far. */
|
|
19
23
|
readonly options: AnyQueryOptions | undefined;
|
|
20
24
|
readonly [TypeId]: {
|
|
21
|
-
readonly _A: (_: never) =>
|
|
22
|
-
readonly _E: (_: never) =>
|
|
25
|
+
readonly _A: (_: never) => DataOf<TFactory>;
|
|
26
|
+
readonly _E: (_: never) => ErrorOf<TFactory>;
|
|
23
27
|
};
|
|
24
28
|
}
|
|
25
|
-
/** The entry of a factory call, typed by the factory. */
|
|
26
|
-
export type Of<TFactory extends QueryFactory> = Query<DataOf<TFactory>, TFactory, ErrorOf<TFactory>>;
|
|
27
29
|
/** A snapshot of one cache entry. Replaced, never mutated, on every change. */
|
|
28
30
|
export interface State<TData> {
|
|
29
31
|
/** Last successful data, kept through background errors. */
|
|
@@ -73,54 +75,54 @@ export declare const isQuery: (value: unknown) => value is Query;
|
|
|
73
75
|
* a `QueryCache` verb.
|
|
74
76
|
*/
|
|
75
77
|
export declare const fetch: {
|
|
76
|
-
(request?: FetchRequest): <
|
|
77
|
-
<
|
|
78
|
+
(request?: FetchRequest): <TFactory extends QueryFactory>(self: Query<TFactory>) => Effect.Effect<DataOf<TFactory>, ErrorOf<TFactory> | CancelledError, ServicesOf<TFactory>>;
|
|
79
|
+
<TFactory extends QueryFactory>(self: Query<TFactory>, request?: FetchRequest): Effect.Effect<DataOf<TFactory>, ErrorOf<TFactory> | CancelledError, ServicesOf<TFactory>>;
|
|
78
80
|
};
|
|
79
81
|
/** Refetch now; succeeds when the request settles, whatever its outcome. */
|
|
80
|
-
export declare function refetch<
|
|
82
|
+
export declare function refetch<TFactory extends QueryFactory>(self: Query<TFactory>): Effect.Effect<void>;
|
|
81
83
|
/** Load the page after the last one; succeeds once it settles. */
|
|
82
|
-
export declare function fetchNextPage<
|
|
84
|
+
export declare function fetchNextPage<TFactory extends QueryFactory>(self: Query<TFactory>): Effect.Effect<void>;
|
|
83
85
|
/** Load the page before the first one; succeeds once it settles. */
|
|
84
|
-
export declare function fetchPreviousPage<
|
|
86
|
+
export declare function fetchPreviousPage<TFactory extends QueryFactory>(self: Query<TFactory>): Effect.Effect<void>;
|
|
85
87
|
/** Mark stale, and refetch if read; succeeds once that refetch settles. */
|
|
86
|
-
export declare function invalidate<
|
|
88
|
+
export declare function invalidate<TFactory extends QueryFactory>(self: Query<TFactory>): Effect.Effect<void>;
|
|
87
89
|
/**
|
|
88
90
|
* Drop data and errors, back to the state of a new entry. Readers suspend
|
|
89
91
|
* and refetch; succeeds when that refetch settles.
|
|
90
92
|
*/
|
|
91
|
-
export declare function reset<
|
|
93
|
+
export declare function reset<TFactory extends QueryFactory>(self: Query<TFactory>): Effect.Effect<void>;
|
|
92
94
|
/**
|
|
93
95
|
* The query's `meta`: the latest factory call's (the one it was hydrated
|
|
94
96
|
* with, before any), else the cache default's.
|
|
95
97
|
*/
|
|
96
|
-
export declare function metaUnsafe<
|
|
98
|
+
export declare function metaUnsafe<TFactory extends QueryFactory>(self: Query<TFactory>): QueryMeta | undefined;
|
|
97
99
|
/** The entry's current state. */
|
|
98
|
-
export declare function get<
|
|
100
|
+
export declare function get<TFactory extends QueryFactory>(self: Query<TFactory>): Effect.Effect<State<DataOf<TFactory>>>;
|
|
99
101
|
/** {@link get}, synchronously. */
|
|
100
|
-
export declare function getUnsafe<
|
|
102
|
+
export declare function getUnsafe<TFactory extends QueryFactory>(self: Query<TFactory>): State<DataOf<TFactory>>;
|
|
101
103
|
/**
|
|
102
104
|
* The entry's current state, then every change. Counts as a reader while
|
|
103
105
|
* the stream runs, so invalidation and focus refetch it.
|
|
104
106
|
*/
|
|
105
|
-
export declare function changes<
|
|
107
|
+
export declare function changes<TFactory extends QueryFactory>(self: Query<TFactory>): Stream.Stream<State<DataOf<TFactory>>>;
|
|
106
108
|
/**
|
|
107
109
|
* The promise a render should unwrap. Starts the first request if nothing
|
|
108
110
|
* has, and retries a failed first load once its error has been shown.
|
|
109
111
|
*/
|
|
110
|
-
export declare function readUnsafe<
|
|
112
|
+
export declare function readUnsafe<TFactory extends QueryFactory>(self: Query<TFactory>): Thenable<DataOf<TFactory>>;
|
|
111
113
|
/**
|
|
112
114
|
* Refetch cached data in the background if it's stale, as `prefetch` does
|
|
113
115
|
* (on a server cache, only if invalidated). Does nothing without data or
|
|
114
116
|
* while a request is in flight.
|
|
115
117
|
*/
|
|
116
|
-
export declare function revalidateUnsafe<
|
|
118
|
+
export declare function revalidateUnsafe<TFactory extends QueryFactory>(self: Query<TFactory>): void;
|
|
117
119
|
/** Listen for state changes. Subscribed entries count as read. */
|
|
118
|
-
export declare function subscribeUnsafe<
|
|
120
|
+
export declare function subscribeUnsafe<TFactory extends QueryFactory>(self: Query<TFactory>, listener: () => void, options?: SubscribeOptions): () => void;
|
|
119
121
|
/** Staleness as of now; `state.isStale` is only kept current while read. */
|
|
120
|
-
export declare function isStaleUnsafe<
|
|
121
|
-
export declare function hasNextPageUnsafe<
|
|
122
|
-
export declare function hasPreviousPageUnsafe<
|
|
122
|
+
export declare function isStaleUnsafe<TFactory extends QueryFactory>(self: Query<TFactory>): boolean;
|
|
123
|
+
export declare function hasNextPageUnsafe<TFactory extends QueryFactory>(self: Query<TFactory>): boolean;
|
|
124
|
+
export declare function hasPreviousPageUnsafe<TFactory extends QueryFactory>(self: Query<TFactory>): boolean;
|
|
123
125
|
/** Readers currently subscribed. */
|
|
124
|
-
export declare function observerCountUnsafe<
|
|
126
|
+
export declare function observerCountUnsafe<TFactory extends QueryFactory>(self: Query<TFactory>): number;
|
|
125
127
|
//#endregion
|
|
126
128
|
export { query_d_exports };
|