@raf-query/core 0.4.4 → 0.5.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/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, Of, Query, State, query_d_exports } from "./query.mjs";
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<Of<TFactory>, never, ServicesOf<TFactory>>;
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>): Of<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<TData, TFactory extends QueryFactory, TError>(query: Query<TData, TFactory, TError>): Entry;
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;
@@ -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<TData, TFactory extends QueryFactory, TError>(query: Query<TData, TFactory, TError>): boolean;
79
+ export declare function canDehydrate<TFactory extends QueryFactory>(query: Query<TFactory>): boolean;
80
80
  /** Snapshot one entry for transfer. */
81
- export declare function dehydrateQuery<TData, TFactory extends QueryFactory, TError>(query: Query<TData, TFactory, TError>, options?: DehydrateOptions): Effect.Effect<DehydratedQuery>;
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 };
@@ -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
- export interface QueryObserver<TData = unknown, TFactory extends QueryFactory = QueryFactory> extends Pipeable.Pipeable {
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<TData, TFactory>;
65
+ readonly query: Query<TFactory>;
65
66
  readonly [TypeId]: {
66
- readonly _A: (_: never) => TData;
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<TData, TFactory extends QueryFactory>(query: Query<TData, TFactory>, options?: Options): QueryObserver<TData, TFactory>;
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<TData, TFactory extends QueryFactory>(query: Query<TData, TFactory>, options?: Options): Effect.Effect<QueryObserver<TData, TFactory>>;
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<TData, TFactory extends QueryFactory>(self: QueryObserver<TData, TFactory>): Result<TData>;
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<TData, TFactory extends QueryFactory>(self: QueryObserver<TData, TFactory>): Effect.Effect<Result<TData>>;
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<TData, TFactory extends QueryFactory>(self: QueryObserver<TData, TFactory>, query: Query<TData, TFactory>, options: Options): Result<TData>;
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<TData, TFactory extends QueryFactory>(self: QueryObserver<TData, TFactory>, query: Query<TData, TFactory>, options: Options): void;
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<TData, TFactory extends QueryFactory>(self: QueryObserver<TData, TFactory>, listener: () => void): () => void;
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<TData, TFactory extends QueryFactory>(self: QueryObserver<TData, TFactory>): Stream.Stream<Result<TData>>;
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<TData, TFactory extends QueryFactory, TResult extends Result<TData>>(self: QueryObserver<TData, TFactory>, result: TResult): TResult;
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<TData, TFactory extends QueryFactory>(self: QueryObserver<TData, TFactory>, name: ResultKey): void;
100
+ export declare function trackProp<TFactory extends QueryFactory>(self: QueryObserver<TFactory>, name: ResultKey): void;
100
101
  //#endregion
101
102
  export { observer_d_exports };
@@ -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<TData, TError = unknown, TServices = never> = TData | PromiseLike<TData> | Effect.Effect<TData, TError, TServices>;
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<TData, TError = unknown, TServices = never> extends QueryBehavior, ServicesField<TServices> {
118
+ export interface QueryOptions<TTypes extends QueryTypes> extends QueryBehavior, ServicesField<ServicesIn<TTypes>> {
87
119
  readonly kind: "query";
88
- queryFn(context: QueryFunctionContext): QueryFnResult<TData, TError, TServices>;
120
+ queryFn(context: QueryFunctionContext): QueryFnResult<TTypes>;
89
121
  readonly queryKey: QueryKey;
90
122
  }
91
- export interface InfiniteQueryOptions<TPage, TPageParam, TError = unknown, TServices = never> extends QueryBehavior, ServicesField<TServices> {
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
- readonly initialPageParam: TPageParam;
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<TPage, TPageParam = unknown> {
105
- readonly pageParams: ReadonlyArray<TPageParam>;
106
- readonly pages: ReadonlyArray<TPage>;
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<unknown, unknown, unknown> | InfiniteQueryOptions<unknown, unknown, unknown, unknown>;
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<TData, TError, TServices>, "kind">): QueryOptions<TData, TError, TServices>;
125
- /** Typed options for a paged query factory. */
126
- export declare function infiniteQueryOptions<TPage, TPageParam, TError = unknown, TServices = never>(options: Omit<InfiniteQueryOptions<TPage, TPageParam, TError, TServices>, "kind">): InfiniteQueryOptions<TPage, TPageParam, TError, TServices>;
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
- /** The data a factory's query resolves to. */
151
- export type DataOf<TFactory extends QueryFactory> = ReturnType<TFactory> extends InfiniteQueryOptions<infer TPage, infer TPageParam, infer _TError, infer _TServices> ? InfiniteData<TPage, TPageParam> : ReturnType<TFactory> extends QueryOptions<infer TData, infer _TError, infer _TServices> ? TData : never;
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 _TPage, infer _TPageParam, infer TError, infer _TServices> ? TError : ReturnType<TFactory> extends QueryOptions<infer _TData, infer TError, infer _TServices> ? TError : unknown;
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 _TPage, infer _TPageParam, infer _TError, infer TServices> ? TServices : ReturnType<TFactory> extends QueryOptions<infer _TData, infer _TError, infer TServices> ? TServices : never;
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 TPage, unknown, infer _TError, infer _TServices> ? TPage : never;
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
- /** Typed options for a paged query factory. */
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, Of, Query, State, SubscribeOptions, TypeId, changes, fetch, fetchNextPage, fetchPreviousPage, get, getUnsafe, hasNextPageUnsafe, hasPreviousPageUnsafe, invalidate, isQuery, isStaleUnsafe, metaUnsafe, observerCountUnsafe, readUnsafe, refetch, reset, revalidateUnsafe, subscribeUnsafe };
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
- export interface Query<TData = unknown, TFactory extends QueryFactory = QueryFactory, TError = unknown> extends Pipeable.Pipeable {
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) => TData;
22
- readonly _E: (_: never) => TError;
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): <TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>) => Effect.Effect<TData, TError | CancelledError, ServicesOf<TFactory>>;
77
- <TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>, request?: FetchRequest): Effect.Effect<TData, TError | CancelledError, ServicesOf<TFactory>>;
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<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): Effect.Effect<void>;
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<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): Effect.Effect<void>;
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<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): Effect.Effect<void>;
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<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): Effect.Effect<void>;
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<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): Effect.Effect<void>;
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<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): QueryMeta | undefined;
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<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): Effect.Effect<State<TData>>;
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<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): State<TData>;
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<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): Stream.Stream<State<TData>>;
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<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): Thenable<TData>;
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<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): void;
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<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>, listener: () => void, options?: SubscribeOptions): () => void;
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<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): boolean;
121
- export declare function hasNextPageUnsafe<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): boolean;
122
- export declare function hasPreviousPageUnsafe<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): boolean;
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<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): number;
126
+ export declare function observerCountUnsafe<TFactory extends QueryFactory>(self: Query<TFactory>): number;
125
127
  //#endregion
126
128
  export { query_d_exports };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raf-query/core",
3
- "version": "0.4.4",
3
+ "version": "0.5.0",
4
4
  "description": "Framework-agnostic core of raf-query, a render-as-you-fetch query library",
5
5
  "keywords": [
6
6
  "query",
@@ -18,7 +18,7 @@
18
18
  "url": "git+https://github.com/KATT/raf-query.git",
19
19
  "directory": "packages/core"
20
20
  },
21
- "homepage": "https://github.com/KATT/raf-query#readme",
21
+ "homepage": "https://raf-query.katt.dev",
22
22
  "bugs": {
23
23
  "url": "https://github.com/KATT/raf-query/issues"
24
24
  },