@effector-tanstack-query/core 0.2.0 → 0.4.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/createInfiniteQuery.cjs.map +1 -1
- package/dist/createInfiniteQuery.d.cts +3 -3
- package/dist/createInfiniteQuery.d.ts +3 -3
- package/dist/createInfiniteQuery.js.map +1 -1
- package/dist/createQueries.cjs +262 -0
- package/dist/createQueries.cjs.map +1 -0
- package/dist/createQueries.d.cts +32 -0
- package/dist/createQueries.d.ts +32 -0
- package/dist/createQueries.js +260 -0
- package/dist/createQueries.js.map +1 -0
- package/dist/createQuery.cjs +5 -5
- package/dist/createQuery.cjs.map +1 -1
- package/dist/createQuery.d.cts +3 -3
- package/dist/createQuery.d.ts +3 -3
- package/dist/createQuery.js +5 -5
- package/dist/createQuery.js.map +1 -1
- package/dist/index.cjs +5 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/types.d.cts +141 -7
- package/dist/types.d.ts +141 -7
- package/package.json +3 -3
- package/src/createInfiniteQuery.ts +69 -10
- package/src/createQueries.ts +442 -0
- package/src/createQuery.ts +34 -14
- package/src/index.ts +5 -0
- package/src/types.ts +192 -6
package/dist/types.d.cts
CHANGED
|
@@ -11,8 +11,32 @@ type StoreOrValue<T> = Store<T> | T;
|
|
|
11
11
|
* queryKey: ['user', $userId, 'details']
|
|
12
12
|
*/
|
|
13
13
|
type EffectorQueryKey = ReadonlyArray<StoreOrValue<string | number | bigint | boolean | null | undefined | object>>;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Resolves a single `EffectorQueryKey` element to its runtime value type:
|
|
16
|
+
* `Store<T>` → `T`, everything else is left as-is. Used by `ResolvedQueryKey`
|
|
17
|
+
* so `queryFn`'s context can present `queryKey` with stores already unwrapped.
|
|
18
|
+
*/
|
|
19
|
+
type ResolveQueryKeyElement<T> = T extends Store<infer U> ? U : T;
|
|
20
|
+
/**
|
|
21
|
+
* Tuple-aware mapping that walks an `EffectorQueryKey` and replaces each
|
|
22
|
+
* `Store<T>` with `T`, preserving tuple shape (length, readonly-ness, element
|
|
23
|
+
* positions). Drives the `TQueryKey` generic of `CreateQueryOptions` so the
|
|
24
|
+
* `queryFn({ queryKey })` parameter is typed with the resolved values:
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* const $name = createStore<string>('pikachu')
|
|
28
|
+
* createQuery({
|
|
29
|
+
* queryKey: ['pokemon', $name],
|
|
30
|
+
* queryFn: ({ queryKey }) => fetchByName(queryKey[1]),
|
|
31
|
+
* // ^ string — no cast needed
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
type ResolvedQueryKey<T extends ReadonlyArray<unknown>> = {
|
|
36
|
+
readonly [K in keyof T]: ResolveQueryKeyElement<T[K]>;
|
|
37
|
+
};
|
|
38
|
+
interface CreateQueryOptions<TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends EffectorQueryKey = EffectorQueryKey> extends Omit<QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, ResolvedQueryKey<TQueryKey>>, 'queryKey' | 'enabled' | 'refetchInterval'> {
|
|
39
|
+
queryKey: TQueryKey;
|
|
16
40
|
enabled?: StoreOrValue<boolean>;
|
|
17
41
|
/**
|
|
18
42
|
* Polling interval in milliseconds, `false` to disable, or a Store for
|
|
@@ -21,7 +45,7 @@ interface CreateQueryOptions<TQueryFnData = unknown, TError = Error, TData = TQu
|
|
|
21
45
|
* `setOptions` on every store change. The function form (`(query) => …`)
|
|
22
46
|
* from TanStack Query is also still supported.
|
|
23
47
|
*/
|
|
24
|
-
refetchInterval?: QueryObserverOptions<TQueryFnData, TError, TData
|
|
48
|
+
refetchInterval?: QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, ResolvedQueryKey<TQueryKey>>['refetchInterval'] | Store<number | false | undefined>;
|
|
25
49
|
/**
|
|
26
50
|
* Stable name used to derive SIDs for the internal effector stores so that
|
|
27
51
|
* `serialize(scope)` / `fork({ values })` round-trip works for SSR. Without
|
|
@@ -95,11 +119,11 @@ interface QueryResult<TData, TError = Error> {
|
|
|
95
119
|
*/
|
|
96
120
|
$queryClient: Store<QueryClient | null>;
|
|
97
121
|
}
|
|
98
|
-
interface CreateInfiniteQueryOptions<TQueryFnData = unknown, TError = Error, TPageParam = unknown, TData = InfiniteData<TQueryFnData, TPageParam
|
|
99
|
-
queryKey:
|
|
122
|
+
interface CreateInfiniteQueryOptions<TQueryFnData = unknown, TError = Error, TPageParam = unknown, TData = InfiniteData<TQueryFnData, TPageParam>, TQueryKey extends EffectorQueryKey = EffectorQueryKey> extends Omit<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, ResolvedQueryKey<TQueryKey>, TPageParam>, 'queryKey' | 'enabled' | 'refetchInterval'> {
|
|
123
|
+
queryKey: TQueryKey;
|
|
100
124
|
enabled?: StoreOrValue<boolean>;
|
|
101
125
|
/** See {@link CreateQueryOptions.refetchInterval}. */
|
|
102
|
-
refetchInterval?: InfiniteQueryObserverOptions<TQueryFnData, TError, TData,
|
|
126
|
+
refetchInterval?: InfiniteQueryObserverOptions<TQueryFnData, TError, TData, ResolvedQueryKey<TQueryKey>, TPageParam>['refetchInterval'] | Store<number | false | undefined>;
|
|
103
127
|
/** See {@link CreateQueryOptions.name}. */
|
|
104
128
|
name?: string;
|
|
105
129
|
}
|
|
@@ -205,5 +229,115 @@ interface MutationResult<TData = unknown, TError = Error, TVariables = void> {
|
|
|
205
229
|
}>;
|
|
206
230
|
};
|
|
207
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Per-item snapshot inside a `createQueries` family. Parallel to the
|
|
234
|
+
* factory's `source` array — one entry per item, in source order.
|
|
235
|
+
*/
|
|
236
|
+
interface QueryItemState<TItem, TData, TError = Error> {
|
|
237
|
+
/** The source item this entry was derived from. */
|
|
238
|
+
source: TItem;
|
|
239
|
+
data: TData | undefined;
|
|
240
|
+
error: TError | null;
|
|
241
|
+
status: QueryStatus;
|
|
242
|
+
isPending: boolean;
|
|
243
|
+
isFetching: boolean;
|
|
244
|
+
isSuccess: boolean;
|
|
245
|
+
isError: boolean;
|
|
246
|
+
isPlaceholderData: boolean;
|
|
247
|
+
fetchStatus: FetchStatus;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Per-item query options produced by `createQueries({ query })`. A pure
|
|
251
|
+
* function of one source item — no effector stores, no closures over
|
|
252
|
+
* mutable state. Reactivity comes from the source store; whenever it
|
|
253
|
+
* updates, this callback re-runs to compute fresh options.
|
|
254
|
+
*
|
|
255
|
+
* `enabled` is a plain boolean (not a `Store`) for the same reason —
|
|
256
|
+
* it's derived from the item, so reactivity is already covered.
|
|
257
|
+
*/
|
|
258
|
+
interface CreateQueriesItemOptions<TQueryFnData, TError, TData, TQueryKey extends ReadonlyArray<unknown>> extends Omit<QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, 'queryKey' | 'enabled'> {
|
|
259
|
+
queryKey: TQueryKey;
|
|
260
|
+
enabled?: boolean;
|
|
261
|
+
}
|
|
262
|
+
interface CreateQueriesOptions<TItem, TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends ReadonlyArray<unknown> = ReadonlyArray<unknown>> {
|
|
263
|
+
/**
|
|
264
|
+
* Stable name used to derive the SID of the result `$items` store so
|
|
265
|
+
* `serialize(scope)` round-trips it for SSR. Without a name, the
|
|
266
|
+
* QueryClient cache still hydrates via `dehydrate`/`hydrate`, but the
|
|
267
|
+
* `$items` snapshot is silently dropped from `serialize(scope)`.
|
|
268
|
+
*/
|
|
269
|
+
name?: string;
|
|
270
|
+
/**
|
|
271
|
+
* Reactive list of items. Each item becomes one parallel query in the
|
|
272
|
+
* family. Adding / removing items updates the family (spawn / dispose
|
|
273
|
+
* observer). Order is preserved in `$items`.
|
|
274
|
+
*
|
|
275
|
+
* Duplicates in `source` deduplicate observers (same `queryKey` hash)
|
|
276
|
+
* but produce separate `$items` entries — one per occurrence.
|
|
277
|
+
*/
|
|
278
|
+
source: Store<ReadonlyArray<TItem>>;
|
|
279
|
+
/**
|
|
280
|
+
* Per-item options builder. MUST be pure — same item in, same options
|
|
281
|
+
* out. Reactivity is driven by the source store; this callback fires
|
|
282
|
+
* synchronously when source updates.
|
|
283
|
+
*/
|
|
284
|
+
query: (item: TItem) => CreateQueriesItemOptions<TQueryFnData, TError, TData, TQueryKey>;
|
|
285
|
+
/** Shared QueryObserver defaults applied on top of `query(item)`. */
|
|
286
|
+
staleTime?: number;
|
|
287
|
+
gcTime?: number;
|
|
288
|
+
retry?: QueryObserverOptions<TQueryFnData, TError, TData>['retry'];
|
|
289
|
+
retryDelay?: QueryObserverOptions<TQueryFnData, TError, TData>['retryDelay'];
|
|
290
|
+
refetchOnMount?: QueryObserverOptions<TQueryFnData, TError, TData>['refetchOnMount'];
|
|
291
|
+
refetchOnReconnect?: QueryObserverOptions<TQueryFnData, TError, TData>['refetchOnReconnect'];
|
|
292
|
+
refetchOnWindowFocus?: QueryObserverOptions<TQueryFnData, TError, TData>['refetchOnWindowFocus'];
|
|
293
|
+
networkMode?: QueryObserverOptions<TQueryFnData, TError, TData>['networkMode'];
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Result of `createQueries(...)`. A reactive "family" of parallel
|
|
297
|
+
* queries indexed by a source store. Composes naturally with
|
|
298
|
+
* `useUnit($items)` for non-Suspense usage and with
|
|
299
|
+
* `useQueries(family)` / `useSuspenseQueries(family)` for React-style
|
|
300
|
+
* consumption.
|
|
301
|
+
*/
|
|
302
|
+
interface QueriesResult<TItem, TData = unknown, TError = Error> {
|
|
303
|
+
/** Per-item snapshots, parallel to `source`. */
|
|
304
|
+
$items: Store<ReadonlyArray<QueryItemState<TItem, TData, TError>>>;
|
|
305
|
+
/** Just the `data` field of `$items` — shortcut for common UIs. */
|
|
306
|
+
$data: Store<ReadonlyArray<TData | undefined>>;
|
|
307
|
+
/** `true` while **any** query in the family is pending. */
|
|
308
|
+
$isPending: Store<boolean>;
|
|
309
|
+
/** `true` only when **every** query in the family has succeeded. */
|
|
310
|
+
$isSuccess: Store<boolean>;
|
|
311
|
+
/** `true` if **any** query in the family is currently fetching. */
|
|
312
|
+
$isFetching: Store<boolean>;
|
|
313
|
+
/** `true` if **any** query in the family errored. */
|
|
314
|
+
$isError: Store<boolean>;
|
|
315
|
+
/**
|
|
316
|
+
* Triggers a parallel `fetchQuery` for every current source item.
|
|
317
|
+
* SSR-friendly — `await allSettled(family.prefetch, { scope })`
|
|
318
|
+
* returns after every queryFn has resolved (or failed).
|
|
319
|
+
*/
|
|
320
|
+
prefetch: EventCallable<void>;
|
|
321
|
+
/**
|
|
322
|
+
* Increment the per-scope refcount and ensure every observer is
|
|
323
|
+
* subscribed to the QueryClient. Call from `useEffect` (or its
|
|
324
|
+
* effector equivalent). The matching `unmounted()` decrements; when
|
|
325
|
+
* the count hits zero, observers unsubscribe.
|
|
326
|
+
*/
|
|
327
|
+
mounted: EventCallable<void>;
|
|
328
|
+
unmounted: EventCallable<void>;
|
|
329
|
+
/** Invalidates every query in the family — re-fetches in background. */
|
|
330
|
+
refresh: EventCallable<void>;
|
|
331
|
+
/** Invalidates one specific item's query. */
|
|
332
|
+
refreshOne: EventCallable<TItem>;
|
|
333
|
+
/** See {@link QueryResult.$queryClient}. */
|
|
334
|
+
$queryClient: Store<QueryClient | null>;
|
|
335
|
+
/**
|
|
336
|
+
* Discriminator that lets `useQueries` / `useSuspenseQueries` and
|
|
337
|
+
* other helpers distinguish a family from a tuple of factories at
|
|
338
|
+
* runtime. Not part of the public API.
|
|
339
|
+
*/
|
|
340
|
+
readonly __family: true;
|
|
341
|
+
}
|
|
208
342
|
|
|
209
|
-
export type { CreateInfiniteQueryOptions, CreateMutationOptions, CreateQueryOptions, EffectorQueryKey, InfiniteQueryResult, MutationResult, MutationStatus, QueryResult, StoreOrValue };
|
|
343
|
+
export type { CreateInfiniteQueryOptions, CreateMutationOptions, CreateQueriesItemOptions, CreateQueriesOptions, CreateQueryOptions, EffectorQueryKey, InfiniteQueryResult, MutationResult, MutationStatus, QueriesResult, QueryItemState, QueryResult, ResolveQueryKeyElement, ResolvedQueryKey, StoreOrValue };
|
package/dist/types.d.ts
CHANGED
|
@@ -11,8 +11,32 @@ type StoreOrValue<T> = Store<T> | T;
|
|
|
11
11
|
* queryKey: ['user', $userId, 'details']
|
|
12
12
|
*/
|
|
13
13
|
type EffectorQueryKey = ReadonlyArray<StoreOrValue<string | number | bigint | boolean | null | undefined | object>>;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Resolves a single `EffectorQueryKey` element to its runtime value type:
|
|
16
|
+
* `Store<T>` → `T`, everything else is left as-is. Used by `ResolvedQueryKey`
|
|
17
|
+
* so `queryFn`'s context can present `queryKey` with stores already unwrapped.
|
|
18
|
+
*/
|
|
19
|
+
type ResolveQueryKeyElement<T> = T extends Store<infer U> ? U : T;
|
|
20
|
+
/**
|
|
21
|
+
* Tuple-aware mapping that walks an `EffectorQueryKey` and replaces each
|
|
22
|
+
* `Store<T>` with `T`, preserving tuple shape (length, readonly-ness, element
|
|
23
|
+
* positions). Drives the `TQueryKey` generic of `CreateQueryOptions` so the
|
|
24
|
+
* `queryFn({ queryKey })` parameter is typed with the resolved values:
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* const $name = createStore<string>('pikachu')
|
|
28
|
+
* createQuery({
|
|
29
|
+
* queryKey: ['pokemon', $name],
|
|
30
|
+
* queryFn: ({ queryKey }) => fetchByName(queryKey[1]),
|
|
31
|
+
* // ^ string — no cast needed
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
type ResolvedQueryKey<T extends ReadonlyArray<unknown>> = {
|
|
36
|
+
readonly [K in keyof T]: ResolveQueryKeyElement<T[K]>;
|
|
37
|
+
};
|
|
38
|
+
interface CreateQueryOptions<TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends EffectorQueryKey = EffectorQueryKey> extends Omit<QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, ResolvedQueryKey<TQueryKey>>, 'queryKey' | 'enabled' | 'refetchInterval'> {
|
|
39
|
+
queryKey: TQueryKey;
|
|
16
40
|
enabled?: StoreOrValue<boolean>;
|
|
17
41
|
/**
|
|
18
42
|
* Polling interval in milliseconds, `false` to disable, or a Store for
|
|
@@ -21,7 +45,7 @@ interface CreateQueryOptions<TQueryFnData = unknown, TError = Error, TData = TQu
|
|
|
21
45
|
* `setOptions` on every store change. The function form (`(query) => …`)
|
|
22
46
|
* from TanStack Query is also still supported.
|
|
23
47
|
*/
|
|
24
|
-
refetchInterval?: QueryObserverOptions<TQueryFnData, TError, TData
|
|
48
|
+
refetchInterval?: QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, ResolvedQueryKey<TQueryKey>>['refetchInterval'] | Store<number | false | undefined>;
|
|
25
49
|
/**
|
|
26
50
|
* Stable name used to derive SIDs for the internal effector stores so that
|
|
27
51
|
* `serialize(scope)` / `fork({ values })` round-trip works for SSR. Without
|
|
@@ -95,11 +119,11 @@ interface QueryResult<TData, TError = Error> {
|
|
|
95
119
|
*/
|
|
96
120
|
$queryClient: Store<QueryClient | null>;
|
|
97
121
|
}
|
|
98
|
-
interface CreateInfiniteQueryOptions<TQueryFnData = unknown, TError = Error, TPageParam = unknown, TData = InfiniteData<TQueryFnData, TPageParam
|
|
99
|
-
queryKey:
|
|
122
|
+
interface CreateInfiniteQueryOptions<TQueryFnData = unknown, TError = Error, TPageParam = unknown, TData = InfiniteData<TQueryFnData, TPageParam>, TQueryKey extends EffectorQueryKey = EffectorQueryKey> extends Omit<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, ResolvedQueryKey<TQueryKey>, TPageParam>, 'queryKey' | 'enabled' | 'refetchInterval'> {
|
|
123
|
+
queryKey: TQueryKey;
|
|
100
124
|
enabled?: StoreOrValue<boolean>;
|
|
101
125
|
/** See {@link CreateQueryOptions.refetchInterval}. */
|
|
102
|
-
refetchInterval?: InfiniteQueryObserverOptions<TQueryFnData, TError, TData,
|
|
126
|
+
refetchInterval?: InfiniteQueryObserverOptions<TQueryFnData, TError, TData, ResolvedQueryKey<TQueryKey>, TPageParam>['refetchInterval'] | Store<number | false | undefined>;
|
|
103
127
|
/** See {@link CreateQueryOptions.name}. */
|
|
104
128
|
name?: string;
|
|
105
129
|
}
|
|
@@ -205,5 +229,115 @@ interface MutationResult<TData = unknown, TError = Error, TVariables = void> {
|
|
|
205
229
|
}>;
|
|
206
230
|
};
|
|
207
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Per-item snapshot inside a `createQueries` family. Parallel to the
|
|
234
|
+
* factory's `source` array — one entry per item, in source order.
|
|
235
|
+
*/
|
|
236
|
+
interface QueryItemState<TItem, TData, TError = Error> {
|
|
237
|
+
/** The source item this entry was derived from. */
|
|
238
|
+
source: TItem;
|
|
239
|
+
data: TData | undefined;
|
|
240
|
+
error: TError | null;
|
|
241
|
+
status: QueryStatus;
|
|
242
|
+
isPending: boolean;
|
|
243
|
+
isFetching: boolean;
|
|
244
|
+
isSuccess: boolean;
|
|
245
|
+
isError: boolean;
|
|
246
|
+
isPlaceholderData: boolean;
|
|
247
|
+
fetchStatus: FetchStatus;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Per-item query options produced by `createQueries({ query })`. A pure
|
|
251
|
+
* function of one source item — no effector stores, no closures over
|
|
252
|
+
* mutable state. Reactivity comes from the source store; whenever it
|
|
253
|
+
* updates, this callback re-runs to compute fresh options.
|
|
254
|
+
*
|
|
255
|
+
* `enabled` is a plain boolean (not a `Store`) for the same reason —
|
|
256
|
+
* it's derived from the item, so reactivity is already covered.
|
|
257
|
+
*/
|
|
258
|
+
interface CreateQueriesItemOptions<TQueryFnData, TError, TData, TQueryKey extends ReadonlyArray<unknown>> extends Omit<QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, 'queryKey' | 'enabled'> {
|
|
259
|
+
queryKey: TQueryKey;
|
|
260
|
+
enabled?: boolean;
|
|
261
|
+
}
|
|
262
|
+
interface CreateQueriesOptions<TItem, TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends ReadonlyArray<unknown> = ReadonlyArray<unknown>> {
|
|
263
|
+
/**
|
|
264
|
+
* Stable name used to derive the SID of the result `$items` store so
|
|
265
|
+
* `serialize(scope)` round-trips it for SSR. Without a name, the
|
|
266
|
+
* QueryClient cache still hydrates via `dehydrate`/`hydrate`, but the
|
|
267
|
+
* `$items` snapshot is silently dropped from `serialize(scope)`.
|
|
268
|
+
*/
|
|
269
|
+
name?: string;
|
|
270
|
+
/**
|
|
271
|
+
* Reactive list of items. Each item becomes one parallel query in the
|
|
272
|
+
* family. Adding / removing items updates the family (spawn / dispose
|
|
273
|
+
* observer). Order is preserved in `$items`.
|
|
274
|
+
*
|
|
275
|
+
* Duplicates in `source` deduplicate observers (same `queryKey` hash)
|
|
276
|
+
* but produce separate `$items` entries — one per occurrence.
|
|
277
|
+
*/
|
|
278
|
+
source: Store<ReadonlyArray<TItem>>;
|
|
279
|
+
/**
|
|
280
|
+
* Per-item options builder. MUST be pure — same item in, same options
|
|
281
|
+
* out. Reactivity is driven by the source store; this callback fires
|
|
282
|
+
* synchronously when source updates.
|
|
283
|
+
*/
|
|
284
|
+
query: (item: TItem) => CreateQueriesItemOptions<TQueryFnData, TError, TData, TQueryKey>;
|
|
285
|
+
/** Shared QueryObserver defaults applied on top of `query(item)`. */
|
|
286
|
+
staleTime?: number;
|
|
287
|
+
gcTime?: number;
|
|
288
|
+
retry?: QueryObserverOptions<TQueryFnData, TError, TData>['retry'];
|
|
289
|
+
retryDelay?: QueryObserverOptions<TQueryFnData, TError, TData>['retryDelay'];
|
|
290
|
+
refetchOnMount?: QueryObserverOptions<TQueryFnData, TError, TData>['refetchOnMount'];
|
|
291
|
+
refetchOnReconnect?: QueryObserverOptions<TQueryFnData, TError, TData>['refetchOnReconnect'];
|
|
292
|
+
refetchOnWindowFocus?: QueryObserverOptions<TQueryFnData, TError, TData>['refetchOnWindowFocus'];
|
|
293
|
+
networkMode?: QueryObserverOptions<TQueryFnData, TError, TData>['networkMode'];
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Result of `createQueries(...)`. A reactive "family" of parallel
|
|
297
|
+
* queries indexed by a source store. Composes naturally with
|
|
298
|
+
* `useUnit($items)` for non-Suspense usage and with
|
|
299
|
+
* `useQueries(family)` / `useSuspenseQueries(family)` for React-style
|
|
300
|
+
* consumption.
|
|
301
|
+
*/
|
|
302
|
+
interface QueriesResult<TItem, TData = unknown, TError = Error> {
|
|
303
|
+
/** Per-item snapshots, parallel to `source`. */
|
|
304
|
+
$items: Store<ReadonlyArray<QueryItemState<TItem, TData, TError>>>;
|
|
305
|
+
/** Just the `data` field of `$items` — shortcut for common UIs. */
|
|
306
|
+
$data: Store<ReadonlyArray<TData | undefined>>;
|
|
307
|
+
/** `true` while **any** query in the family is pending. */
|
|
308
|
+
$isPending: Store<boolean>;
|
|
309
|
+
/** `true` only when **every** query in the family has succeeded. */
|
|
310
|
+
$isSuccess: Store<boolean>;
|
|
311
|
+
/** `true` if **any** query in the family is currently fetching. */
|
|
312
|
+
$isFetching: Store<boolean>;
|
|
313
|
+
/** `true` if **any** query in the family errored. */
|
|
314
|
+
$isError: Store<boolean>;
|
|
315
|
+
/**
|
|
316
|
+
* Triggers a parallel `fetchQuery` for every current source item.
|
|
317
|
+
* SSR-friendly — `await allSettled(family.prefetch, { scope })`
|
|
318
|
+
* returns after every queryFn has resolved (or failed).
|
|
319
|
+
*/
|
|
320
|
+
prefetch: EventCallable<void>;
|
|
321
|
+
/**
|
|
322
|
+
* Increment the per-scope refcount and ensure every observer is
|
|
323
|
+
* subscribed to the QueryClient. Call from `useEffect` (or its
|
|
324
|
+
* effector equivalent). The matching `unmounted()` decrements; when
|
|
325
|
+
* the count hits zero, observers unsubscribe.
|
|
326
|
+
*/
|
|
327
|
+
mounted: EventCallable<void>;
|
|
328
|
+
unmounted: EventCallable<void>;
|
|
329
|
+
/** Invalidates every query in the family — re-fetches in background. */
|
|
330
|
+
refresh: EventCallable<void>;
|
|
331
|
+
/** Invalidates one specific item's query. */
|
|
332
|
+
refreshOne: EventCallable<TItem>;
|
|
333
|
+
/** See {@link QueryResult.$queryClient}. */
|
|
334
|
+
$queryClient: Store<QueryClient | null>;
|
|
335
|
+
/**
|
|
336
|
+
* Discriminator that lets `useQueries` / `useSuspenseQueries` and
|
|
337
|
+
* other helpers distinguish a family from a tuple of factories at
|
|
338
|
+
* runtime. Not part of the public API.
|
|
339
|
+
*/
|
|
340
|
+
readonly __family: true;
|
|
341
|
+
}
|
|
208
342
|
|
|
209
|
-
export type { CreateInfiniteQueryOptions, CreateMutationOptions, CreateQueryOptions, EffectorQueryKey, InfiniteQueryResult, MutationResult, MutationStatus, QueryResult, StoreOrValue };
|
|
343
|
+
export type { CreateInfiniteQueryOptions, CreateMutationOptions, CreateQueriesItemOptions, CreateQueriesOptions, CreateQueryOptions, EffectorQueryKey, InfiniteQueryResult, MutationResult, MutationStatus, QueriesResult, QueryItemState, QueryResult, ResolveQueryKeyElement, ResolvedQueryKey, StoreOrValue };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effector-tanstack-query/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Effector bindings for TanStack Query — core factories (createQuery, createMutation, createInfiniteQuery)",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Effector bindings for TanStack Query — core factories (createQuery, createMutation, createInfiniteQuery, createQueries)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ilya Agarkov <ilya.al.ag@gmail.com>",
|
|
7
7
|
"repository": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
],
|
|
45
45
|
"sideEffects": false,
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@tanstack/query-core": "^5.
|
|
47
|
+
"@tanstack/query-core": "^5.100.10"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"effector": ">=23.0.0"
|
|
@@ -9,6 +9,7 @@ import { createBaseQuery, sidConfig, warnMissingName } from './createBaseQuery'
|
|
|
9
9
|
import { resolveReactiveRefetchInterval } from './resolve'
|
|
10
10
|
import type {
|
|
11
11
|
CreateInfiniteQueryOptions,
|
|
12
|
+
EffectorQueryKey,
|
|
12
13
|
InfiniteQueryResult,
|
|
13
14
|
} from './types'
|
|
14
15
|
|
|
@@ -29,34 +30,62 @@ export function createInfiniteQuery<
|
|
|
29
30
|
TError = Error,
|
|
30
31
|
TPageParam = unknown,
|
|
31
32
|
TData = InfiniteData<TQueryFnData, TPageParam>,
|
|
33
|
+
const TQueryKey extends EffectorQueryKey = EffectorQueryKey,
|
|
32
34
|
>(
|
|
33
|
-
options: CreateInfiniteQueryOptions<
|
|
35
|
+
options: CreateInfiniteQueryOptions<
|
|
36
|
+
TQueryFnData,
|
|
37
|
+
TError,
|
|
38
|
+
TPageParam,
|
|
39
|
+
TData,
|
|
40
|
+
TQueryKey
|
|
41
|
+
>,
|
|
34
42
|
): InfiniteQueryResult<TData, TError, TPageParam>
|
|
35
43
|
export function createInfiniteQuery<
|
|
36
44
|
TQueryFnData = unknown,
|
|
37
45
|
TError = Error,
|
|
38
46
|
TPageParam = unknown,
|
|
39
47
|
TData = InfiniteData<TQueryFnData, TPageParam>,
|
|
48
|
+
const TQueryKey extends EffectorQueryKey = EffectorQueryKey,
|
|
40
49
|
>(
|
|
41
50
|
queryClient: QueryClient,
|
|
42
|
-
options: CreateInfiniteQueryOptions<
|
|
51
|
+
options: CreateInfiniteQueryOptions<
|
|
52
|
+
TQueryFnData,
|
|
53
|
+
TError,
|
|
54
|
+
TPageParam,
|
|
55
|
+
TData,
|
|
56
|
+
TQueryKey
|
|
57
|
+
>,
|
|
43
58
|
): InfiniteQueryResult<TData, TError, TPageParam>
|
|
44
59
|
export function createInfiniteQuery<
|
|
45
60
|
TQueryFnData = unknown,
|
|
46
61
|
TError = Error,
|
|
47
62
|
TPageParam = unknown,
|
|
48
63
|
TData = InfiniteData<TQueryFnData, TPageParam>,
|
|
64
|
+
const TQueryKey extends EffectorQueryKey = EffectorQueryKey,
|
|
49
65
|
>(
|
|
50
66
|
arg1:
|
|
51
67
|
| QueryClient
|
|
52
|
-
| CreateInfiniteQueryOptions<
|
|
53
|
-
|
|
68
|
+
| CreateInfiniteQueryOptions<
|
|
69
|
+
TQueryFnData,
|
|
70
|
+
TError,
|
|
71
|
+
TPageParam,
|
|
72
|
+
TData,
|
|
73
|
+
TQueryKey
|
|
74
|
+
>,
|
|
75
|
+
arg2?: CreateInfiniteQueryOptions<
|
|
76
|
+
TQueryFnData,
|
|
77
|
+
TError,
|
|
78
|
+
TPageParam,
|
|
79
|
+
TData,
|
|
80
|
+
TQueryKey
|
|
81
|
+
>,
|
|
54
82
|
): InfiniteQueryResult<TData, TError, TPageParam> {
|
|
55
83
|
const [explicitClient, options] = parseInfiniteArgs<
|
|
56
84
|
TQueryFnData,
|
|
57
85
|
TError,
|
|
58
86
|
TPageParam,
|
|
59
|
-
TData
|
|
87
|
+
TData,
|
|
88
|
+
TQueryKey
|
|
60
89
|
>(arg1, arg2)
|
|
61
90
|
const { queryKey, enabled, name, ...restOptions } = options
|
|
62
91
|
|
|
@@ -272,20 +301,50 @@ export function createInfiniteQuery<
|
|
|
272
301
|
return result
|
|
273
302
|
}
|
|
274
303
|
|
|
275
|
-
function parseInfiniteArgs<
|
|
304
|
+
function parseInfiniteArgs<
|
|
305
|
+
TQueryFnData,
|
|
306
|
+
TError,
|
|
307
|
+
TPageParam,
|
|
308
|
+
TData,
|
|
309
|
+
TQueryKey extends EffectorQueryKey,
|
|
310
|
+
>(
|
|
276
311
|
arg1:
|
|
277
312
|
| QueryClient
|
|
278
|
-
| CreateInfiniteQueryOptions<
|
|
279
|
-
|
|
313
|
+
| CreateInfiniteQueryOptions<
|
|
314
|
+
TQueryFnData,
|
|
315
|
+
TError,
|
|
316
|
+
TPageParam,
|
|
317
|
+
TData,
|
|
318
|
+
TQueryKey
|
|
319
|
+
>,
|
|
320
|
+
arg2?: CreateInfiniteQueryOptions<
|
|
321
|
+
TQueryFnData,
|
|
322
|
+
TError,
|
|
323
|
+
TPageParam,
|
|
324
|
+
TData,
|
|
325
|
+
TQueryKey
|
|
326
|
+
>,
|
|
280
327
|
): [
|
|
281
328
|
QueryClient | null,
|
|
282
|
-
CreateInfiniteQueryOptions<
|
|
329
|
+
CreateInfiniteQueryOptions<
|
|
330
|
+
TQueryFnData,
|
|
331
|
+
TError,
|
|
332
|
+
TPageParam,
|
|
333
|
+
TData,
|
|
334
|
+
TQueryKey
|
|
335
|
+
>,
|
|
283
336
|
] {
|
|
284
337
|
if (arg2 !== undefined) {
|
|
285
338
|
return [arg1 as QueryClient, arg2]
|
|
286
339
|
}
|
|
287
340
|
return [
|
|
288
341
|
null,
|
|
289
|
-
arg1 as CreateInfiniteQueryOptions<
|
|
342
|
+
arg1 as CreateInfiniteQueryOptions<
|
|
343
|
+
TQueryFnData,
|
|
344
|
+
TError,
|
|
345
|
+
TPageParam,
|
|
346
|
+
TData,
|
|
347
|
+
TQueryKey
|
|
348
|
+
>,
|
|
290
349
|
]
|
|
291
350
|
}
|