reactjrx 1.142.4 → 2.0.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.
@@ -1,7 +1,31 @@
1
1
  import { SubscribeSource } from './useSubscribe/types';
2
- interface Option {
3
- retryOnError?: boolean;
2
+ export interface UseSubscribeEffectOptions {
3
+ /**
4
+ * Called on every error of the source, including the ones that are
5
+ * retried.
6
+ */
4
7
  onError?: (error: unknown) => void;
8
+ /**
9
+ * Whether to subscribe to the source again after an error:
10
+ * - `false` (default): the error ends the subscription;
11
+ * - `true`: retry without limit;
12
+ * - a number: retry at most that many times in a row;
13
+ * - a function: given the attempt (0 for the first retry) and the error,
14
+ * returns whether to retry.
15
+ *
16
+ * The attempt count goes back to 0 once the source emits again.
17
+ */
18
+ retry?: boolean | number | ((attempt: number, error: unknown) => boolean);
19
+ /**
20
+ * Time to wait before each retry, in milliseconds, or a function of the
21
+ * attempt and the error. Retries always wait for a timer, so they never
22
+ * run synchronously, even with `0`. Defaults to an exponential backoff:
23
+ * 1 s, 2 s, 4 s… up to 30 s.
24
+ */
25
+ retryDelay?: number | ((attempt: number, error: unknown) => number);
5
26
  }
6
- export declare function useSubscribeEffect<T>(source: SubscribeSource<T>, options?: Option): void;
7
- export {};
27
+ /**
28
+ * Subscribes to `source` while the component is mounted. Options are read
29
+ * at each error, so changing them never subscribes again.
30
+ */
31
+ export declare function useSubscribeEffect<T>(source: SubscribeSource<T>, options?: UseSubscribeEffectOptions): void;
@@ -1,10 +1,15 @@
1
- import { QueryClient, QueryFunctionContext, QueryKey, skipToken } from '@tanstack/react-query';
1
+ import { QueryFunctionContext, QueryKey, skipToken } from '@tanstack/react-query';
2
2
  import { Observable } from 'rxjs';
3
- import { QueryClient$ } from './QueryClientProvider$';
4
3
  export type ObservableQueryFn<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey> = ((context: QueryFunctionContext<TQueryKey>) => Observable<TQueryFnData>) | typeof skipToken | Observable<TQueryFnData>;
5
4
  /**
6
5
  * Bridges an Observable-based `queryFn` to the Promise-based `queryFn`
7
- * expected by TanStack Query. Shared by `useQuery$` and `useQueries$` so
8
- * both rely on the exact same subscription, caching and cancellation logic.
6
+ * expected by TanStack Query. Shared by `useQuery$` and `useQueries$`.
7
+ *
8
+ * As with TanStack's `streamedQuery`, the whole stream is one fetch: every
9
+ * value is written into the query as soon as the stream emits it, the query
10
+ * stays `fetching` until the stream completes, and the fetch then resolves
11
+ * with the last value. Cancelling the fetch (the last observer unmounting,
12
+ * `cancelQueries`, a refetch, the query leaving the cache) unsubscribes from
13
+ * the stream.
9
14
  */
10
- export declare function createObservableQueryFn<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey>(queryClient$: QueryClient$, queryClient: QueryClient | undefined, queryFn: ObservableQueryFn<TQueryFnData, TQueryKey> | undefined): typeof skipToken | ((context: QueryFunctionContext<TQueryKey>) => Promise<TQueryFnData>) | undefined;
15
+ export declare function createObservableQueryFn<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey>(queryFn: ObservableQueryFn<TQueryFnData, TQueryKey> | undefined): typeof skipToken | ((context: QueryFunctionContext<TQueryKey>) => Promise<TQueryFnData>) | undefined;
@@ -2,4 +2,4 @@ import { DefaultError, QueryClient, QueryKey, UseQueryOptions } from '@tanstack/
2
2
  import { ObservableQueryFn } from './createObservableQueryFn';
3
3
  export declare function useQuery$<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>({ queryFn, ...options }: Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, "queryFn"> & {
4
4
  queryFn: ObservableQueryFn<TQueryFnData, TQueryKey>;
5
- }, queryClient?: QueryClient): import('@tanstack/react-query').UseQueryResult<NoInfer<TData>, TError>;
5
+ }, queryClient?: QueryClient): import('@tanstack/react-query').UseQueryResult<TData, TError>;
@@ -0,0 +1 @@
1
+ export {};
@@ -4,6 +4,6 @@ export type SignalContextType = SignalContext;
4
4
  export declare const SignalReactContext: import('react').Context<SignalContext>;
5
5
  export declare const SignalContextProvider: import('react').MemoExoticComponent<({ children }: {
6
6
  children: React.ReactNode;
7
- }) => import("react/jsx-runtime").JSX.Element>;
7
+ }) => import('react').JSX.Element>;
8
8
  export declare const useSignalContext: () => SignalContext;
9
9
  export declare const useMakeOrRetrieveSignal: (virtualSignal?: VirtualSignal<unknown>) => import('../Signal').Signal<unknown, undefined> | undefined;
@@ -17,4 +17,4 @@ export declare function createLiveQuerySource(initialItems: string[]): {
17
17
  };
18
18
  export declare function createWrapper(queryClient: QueryClient): ({ children }: {
19
19
  children: React.ReactNode;
20
- }) => import("react/jsx-runtime").JSX.Element;
20
+ }) => React.JSX.Element;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "reactjrx",
3
3
  "private": false,
4
- "version": "1.142.4",
4
+ "version": "2.0.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
@@ -33,13 +33,13 @@
33
33
  "format": "npx @biomejs/biome check . --write"
34
34
  },
35
35
  "peerDependencies": {
36
- "@tanstack/react-query": "5.x",
36
+ "@tanstack/react-query": "^5.85.1",
37
37
  "react": "19.x",
38
38
  "react-dom": "19.x",
39
39
  "rxjs": "*"
40
40
  },
41
41
  "devDependencies": {
42
- "@biomejs/biome": "2.4.15",
42
+ "@biomejs/biome": "2.5.15",
43
43
  "@rolldown/plugin-babel": "^0.2.3",
44
44
  "@tanstack/react-query-persist-client": "^5.96.2",
45
45
  "@testing-library/jest-dom": "^7.0.0",
@@ -1,41 +0,0 @@
1
- import { QueryClient, QueryKey } from '@tanstack/react-query';
2
- import { Observable, Subscription } from 'rxjs';
3
- type CacheEntry = {
4
- queryKey: QueryKey;
5
- query$: Observable<unknown>;
6
- signal: AbortSignal;
7
- sub: Subscription | undefined;
8
- isCompleted: boolean;
9
- lastData: {
10
- value: unknown;
11
- } | undefined;
12
- };
13
- export declare class QueryClient$ {
14
- readonly queryClient: QueryClient;
15
- /**
16
- * Keyed by the query's own `queryKey` array: the one TanStack passes to
17
- * `queryFn` and exposes as `query.queryKey`. Entries therefore match their
18
- * query whatever its `queryKeyHashFn`, and nothing is hashed.
19
- */
20
- readonly queryMap: Map<QueryKey, CacheEntry>;
21
- constructor(queryClient: QueryClient);
22
- getQuery(queryKey: QueryKey): CacheEntry | undefined;
23
- setQuery(queryKey: QueryKey, query$: Observable<unknown>, signal: AbortSignal): CacheEntry;
24
- deleteQuery(queryKey: QueryKey, { cancelQuery }?: {
25
- cancelQuery?: boolean;
26
- }): void;
27
- destroy(): void;
28
- }
29
- export declare const Context: import('react').Context<QueryClient$ | undefined>;
30
- /**
31
- * Must render **inside** TanStack `QueryClientProvider` (or equivalent).
32
- * Subscribes to that client's query cache so when a query is removed
33
- * (including via `queryClient.clear()`), matching `useQuery$` observable
34
- * entries are dropped.
35
- */
36
- export declare const QueryClientProvider$: import('react').MemoExoticComponent<({ children, client: _client, }: {
37
- children: React.ReactNode;
38
- client?: QueryClient$;
39
- }) => import("react/jsx-runtime").JSX.Element>;
40
- export declare const useQueryClient$: () => QueryClient$;
41
- export {};