@raf-query/core 0.9.1 → 0.9.2

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 CHANGED
@@ -1,14 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.9.2](https://github.com/KATT/raf-query/compare/0.9.1...0.9.2) (2026-10-15)
4
+
5
+ ### Bug Fixes
6
+
7
+ * **core:** keep handles of factories with the same signature apart ([#167](https://github.com/KATT/raf-query/issues/167)) ([5894bcb](https://github.com/KATT/raf-query/commit/5894bcbcc382c60e9c04768c0e178bf0996f4b45))
8
+
3
9
  ## [0.9.1](https://github.com/KATT/raf-query/compare/0.9.0...0.9.1) (2026-10-15)
4
10
 
5
11
  ### Features
6
12
 
7
- * **react:** add @raf-query/react/react-router for React Router Framework Mode ([#146](https://github.com/KATT/raf-query/issues/146)) ([4e02c80](https://github.com/KATT/raf-query/commit/4e02c809d8be1eea33935c9f0b6abc38cbdce25c)), references [#130](https://github.com/KATT/raf-query/issues/130) [#148](https://github.com/KATT/raf-query/issues/148) [#148](https://github.com/KATT/raf-query/issues/148)
13
+ - **react:** add @raf-query/react/react-router for React Router Framework Mode ([#146](https://github.com/KATT/raf-query/issues/146)) ([4e02c80](https://github.com/KATT/raf-query/commit/4e02c809d8be1eea33935c9f0b6abc38cbdce25c)), references [#130](https://github.com/KATT/raf-query/issues/130) [#148](https://github.com/KATT/raf-query/issues/148) [#148](https://github.com/KATT/raf-query/issues/148)
8
14
 
9
15
  ### Miscellaneous Chores
10
16
 
11
- * **lint:** ban member access on use(), in code and Markdown fences ([#155](https://github.com/KATT/raf-query/issues/155)) ([b7b37b4](https://github.com/KATT/raf-query/commit/b7b37b4f6d83c0a232697d05b177c33bdea11df1)), references [#140](https://github.com/KATT/raf-query/issues/140)
17
+ - **lint:** ban member access on use(), in code and Markdown fences ([#155](https://github.com/KATT/raf-query/issues/155)) ([b7b37b4](https://github.com/KATT/raf-query/commit/b7b37b4f6d83c0a232697d05b177c33bdea11df1)), references [#140](https://github.com/KATT/raf-query/issues/140)
12
18
 
13
19
  ## [0.9.0](https://github.com/KATT/raf-query/compare/0.8.0...0.9.0) (2026-10-15)
14
20
 
@@ -2,10 +2,11 @@ import { QueryKey } from "./key.mjs";
2
2
  import { Effect, Schedule } from "effect";
3
3
  //#region src/options.d.ts
4
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. Leave `error` out
7
- * and it is `unknown` (promises reject with anything); leave `services` out
8
- * and it is `never`.
5
+ * The types of a plain query: what its `queryFn` resolves to, for an Effect
6
+ * `queryFn` its error and the services it needs, and the shape of its key.
7
+ * Leave `error` out and it is `unknown` (promises reject with anything);
8
+ * leave `services` out and it is `never`; leave `key` out and it is any
9
+ * {@link QueryKey}.
9
10
  *
10
11
  * ```ts
11
12
  * type PostOptions = QueryOptions<{ data: Post }>;
@@ -14,14 +15,16 @@ import { Effect, Schedule } from "effect";
14
15
  export interface QueryTypes {
15
16
  readonly data: unknown;
16
17
  readonly error?: unknown;
18
+ readonly key?: QueryKey;
17
19
  readonly services?: unknown;
18
20
  }
19
21
  /**
20
22
  * The types of a paged query: one page, the param that loads it, and as in
21
- * {@link QueryTypes}, an Effect `queryFn`'s error and services.
23
+ * {@link QueryTypes}, an Effect `queryFn`'s error and services and the key.
22
24
  */
23
25
  export interface InfiniteQueryTypes {
24
26
  readonly error?: unknown;
27
+ readonly key?: QueryKey;
25
28
  readonly page: unknown;
26
29
  readonly pageParam: unknown;
27
30
  readonly services?: unknown;
@@ -34,39 +37,52 @@ type ErrorIn<TTypes> = TTypes extends {
34
37
  type ServicesIn<TTypes> = TTypes extends {
35
38
  readonly services: infer TServices;
36
39
  } ? TServices : never;
40
+ /** `key` of a types bag, any {@link QueryKey} when it has none. */
41
+ type KeyIn<TTypes> = TTypes extends {
42
+ readonly key: infer TKey extends QueryKey;
43
+ } ? TKey : QueryKey;
37
44
  /**
38
45
  * The bag `queryOptions` returns. `error` is left out when the `queryFn`
39
46
  * doesn't name one (`unknown`: a promise or a plain value). `services` is
40
47
  * left out when the `queryFn` needs none (`never`). An Effect's error,
41
- * including `never` when it can't fail, stays.
48
+ * including `never` when it can't fail, stays. `key` is always there, so two
49
+ * factories with different key shapes have different types.
42
50
  */
43
- type QueryTypesOf<TData, TError, TServices> = unknown extends TError ? [TServices] extends [never] ? {
51
+ type QueryTypesOf<TData, TError, TServices, TKey> = unknown extends TError ? [TServices] extends [never] ? {
44
52
  data: TData;
53
+ key: TKey;
45
54
  } : {
46
55
  data: TData;
56
+ key: TKey;
47
57
  services: TServices;
48
58
  } : [TServices] extends [never] ? {
49
59
  data: TData;
50
60
  error: TError;
61
+ key: TKey;
51
62
  } : {
52
63
  data: TData;
53
64
  error: TError;
65
+ key: TKey;
54
66
  services: TServices;
55
67
  };
56
68
  /** As {@link QueryTypesOf}, for a paged query. */
57
- type InfiniteQueryTypesOf<TPage, TPageParam, TError, TServices> = unknown extends TError ? [TServices] extends [never] ? {
69
+ type InfiniteQueryTypesOf<TPage, TPageParam, TError, TServices, TKey> = unknown extends TError ? [TServices] extends [never] ? {
70
+ key: TKey;
58
71
  page: TPage;
59
72
  pageParam: TPageParam;
60
73
  } : {
74
+ key: TKey;
61
75
  page: TPage;
62
76
  pageParam: TPageParam;
63
77
  services: TServices;
64
78
  } : [TServices] extends [never] ? {
65
79
  error: TError;
80
+ key: TKey;
66
81
  page: TPage;
67
82
  pageParam: TPageParam;
68
83
  } : {
69
84
  error: TError;
85
+ key: TKey;
70
86
  page: TPage;
71
87
  pageParam: TPageParam;
72
88
  services: TServices;
@@ -165,7 +181,7 @@ interface ServicesField<TServices> {
165
181
  export interface QueryOptions<TTypes extends QueryTypes> extends QueryBehavior, ServicesField<ServicesIn<TTypes>> {
166
182
  readonly kind: "query";
167
183
  queryFn(context: QueryFunctionContext): QueryFnResult<TTypes>;
168
- readonly queryKey: QueryKey;
184
+ readonly queryKey: KeyIn<TTypes>;
169
185
  }
170
186
  /**
171
187
  * The functions of paged options, typed by the page and page param types
@@ -189,7 +205,7 @@ export interface InfiniteQueryOptions<TTypes extends InfiniteQueryTypes> extends
189
205
  readonly kind: "infinite";
190
206
  /** Keep at most this many pages; the far end is dropped when paging. */
191
207
  readonly maxPages?: number;
192
- readonly queryKey: QueryKey;
208
+ readonly queryKey: KeyIn<TTypes>;
193
209
  }
194
210
  /** Data of a paged query. */
195
211
  export interface InfiniteData<TTypes extends Pick<InfiniteQueryTypes, "page" | "pageParam">> {
@@ -223,25 +239,32 @@ export type AnyQueryOptions = QueryOptions<{
223
239
  * type. A promise or a plain value has no error to infer, so the type leaves
224
240
  * `error` out (`ErrorOf` is `unknown`).
225
241
  *
242
+ * The key's literal type is kept too (`readonly ["post", string]`), so two
243
+ * factories with the same input and data but different keys have different
244
+ * types, and a handle of one doesn't type-check where the other's goes.
245
+ *
226
246
  * The type parameters are only there for TypeScript to infer the types bag
227
- * from `queryFn`; it can't infer a bag's members.
247
+ * from `queryFn` and `queryKey`; it can't infer a bag's members.
228
248
  */
229
- export declare function queryOptions<TData, TError = unknown, TServices = never>(options: Omit<QueryOptions<{
249
+ export declare function queryOptions<TData, TError = unknown, TServices = never, const TKey extends QueryKey = QueryKey>(options: Omit<QueryOptions<{
230
250
  data: TData;
231
251
  error: TError;
252
+ key: TKey;
232
253
  services: TServices;
233
- }>, "kind">): QueryOptions<QueryTypesOf<TData, TError, TServices>>;
254
+ }>, "kind">): QueryOptions<QueryTypesOf<TData, TError, TServices, TKey>>;
234
255
  /**
235
256
  * Typed options for a paged query factory. The page type is inferred from
236
257
  * `queryFn`, as in {@link queryOptions}. So is an Effect `queryFn`'s error;
237
- * a promise or a plain value leaves `error` out.
258
+ * a promise or a plain value leaves `error` out. The key's literal type is
259
+ * kept, as in {@link queryOptions}.
238
260
  */
239
- export declare function infiniteQueryOptions<TPage, TPageParam, TError = unknown, TServices = never>(options: Omit<InfiniteQueryOptions<{
261
+ export declare function infiniteQueryOptions<TPage, TPageParam, TError = unknown, TServices = never, const TKey extends QueryKey = QueryKey>(options: Omit<InfiniteQueryOptions<{
240
262
  error: TError;
263
+ key: TKey;
241
264
  page: TPage;
242
265
  pageParam: TPageParam;
243
266
  services: TServices;
244
- }>, "kind">): InfiniteQueryOptions<InfiniteQueryTypesOf<TPage, TPageParam, TError, TServices>>;
267
+ }>, "kind">): InfiniteQueryOptions<InfiniteQueryTypesOf<TPage, TPageParam, TError, TServices, TKey>>;
245
268
  interface FactoryResult {
246
269
  readonly kind: "infinite" | "query";
247
270
  readonly queryKey: QueryKey;
package/dist/options.mjs CHANGED
@@ -16,8 +16,12 @@
16
16
  * type. A promise or a plain value has no error to infer, so the type leaves
17
17
  * `error` out (`ErrorOf` is `unknown`).
18
18
  *
19
+ * The key's literal type is kept too (`readonly ["post", string]`), so two
20
+ * factories with the same input and data but different keys have different
21
+ * types, and a handle of one doesn't type-check where the other's goes.
22
+ *
19
23
  * The type parameters are only there for TypeScript to infer the types bag
20
- * from `queryFn`; it can't infer a bag's members.
24
+ * from `queryFn` and `queryKey`; it can't infer a bag's members.
21
25
  */
22
26
  function queryOptions(options) {
23
27
  return {
@@ -28,7 +32,8 @@ function queryOptions(options) {
28
32
  /**
29
33
  * Typed options for a paged query factory. The page type is inferred from
30
34
  * `queryFn`, as in {@link queryOptions}. So is an Effect `queryFn`'s error;
31
- * a promise or a plain value leaves `error` out.
35
+ * a promise or a plain value leaves `error` out. The key's literal type is
36
+ * kept, as in {@link queryOptions}.
32
37
  */
33
38
  function infiniteQueryOptions(options) {
34
39
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raf-query/core",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "description": "Framework-agnostic core of raf-query, a render-as-you-fetch query library",
5
5
  "keywords": [
6
6
  "query",