@orpc/react-query 1.2.0 → 1.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/README.md +2 -1
- package/dist/index.d.mts +37 -24
- package/dist/index.d.ts +37 -24
- package/dist/index.mjs +43 -14
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -49,6 +49,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
49
49
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
50
50
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
51
51
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
52
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with NestJS.
|
|
52
53
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
53
54
|
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
54
55
|
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
@@ -62,7 +63,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
62
63
|
|
|
63
64
|
## `@orpc/react-query`
|
|
64
65
|
|
|
65
|
-
Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview). Read the [documentation](https://orpc.unnoq.com/docs/tanstack-query/react) for more information.
|
|
66
|
+
Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview). Read the [documentation](https://orpc.unnoq.com/docs/integrations/tanstack-query-old/react) for more information.
|
|
66
67
|
|
|
67
68
|
```ts
|
|
68
69
|
export function Example() {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
interface BuildKeyOptions<TType extends KeyType, TInput> {
|
|
7
|
-
type?: TType;
|
|
8
|
-
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
|
9
|
-
}
|
|
10
|
-
declare function buildKey<TType extends KeyType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
|
|
2
|
+
import { OperationType, OperationKeyOptions } from '@orpc/tanstack-query';
|
|
3
|
+
export { OperationKeyOptions as BuildKeyOptions, OperationType as KeyType, generateOperationKey as buildKey } from '@orpc/tanstack-query';
|
|
4
|
+
import { QueryKey, SkipToken, UseQueryOptions, QueryFunctionContext, experimental_streamedQuery, UseInfiniteQueryOptions, UseMutationOptions, InfiniteData } from '@tanstack/react-query';
|
|
5
|
+
import { SetOptional, MaybeOptionalOptions } from '@orpc/shared';
|
|
11
6
|
|
|
12
7
|
/**
|
|
13
8
|
* Utils at any level (procedure or router)
|
|
@@ -16,16 +11,16 @@ interface GeneralUtils<TInput> {
|
|
|
16
11
|
/**
|
|
17
12
|
* Generate a query/mutation key for checking status, invalidate, set, get, etc.
|
|
18
13
|
*
|
|
19
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
14
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
20
15
|
*/
|
|
21
|
-
key<UType extends
|
|
16
|
+
key<UType extends OperationType>(options?: OperationKeyOptions<UType, TInput>): QueryKey;
|
|
22
17
|
}
|
|
23
18
|
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
|
24
19
|
|
|
25
20
|
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
|
|
26
|
-
input?: TInput;
|
|
21
|
+
input?: TInput | SkipToken;
|
|
27
22
|
} : {
|
|
28
|
-
input: TInput;
|
|
23
|
+
input: TInput | SkipToken;
|
|
29
24
|
}) & (Record<never, never> extends TClientContext ? {
|
|
30
25
|
context?: TClientContext;
|
|
31
26
|
} : {
|
|
@@ -34,19 +29,30 @@ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TErro
|
|
|
34
29
|
interface QueryOptionsBase<TOutput, TError> {
|
|
35
30
|
queryKey: QueryKey;
|
|
36
31
|
queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
|
|
37
|
-
|
|
32
|
+
throwOnError?(error: TError): boolean;
|
|
33
|
+
retryDelay?: (count: number, error: TError) => number;
|
|
34
|
+
enabled: boolean;
|
|
35
|
+
}
|
|
36
|
+
type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
|
|
37
|
+
type experimental_InferStreamedOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
38
|
+
type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & {
|
|
39
|
+
queryFnOptions?: experimental_StreamedQueryOptions;
|
|
40
|
+
};
|
|
41
|
+
interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
|
|
38
42
|
}
|
|
39
43
|
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = {
|
|
40
|
-
input: (pageParam: TPageParam) => TInput;
|
|
44
|
+
input: ((pageParam: TPageParam) => TInput) | SkipToken;
|
|
41
45
|
} & (Record<never, never> extends TClientContext ? {
|
|
42
46
|
context?: TClientContext;
|
|
43
47
|
} : {
|
|
44
48
|
context: TClientContext;
|
|
45
|
-
}) & SetOptional<UseInfiniteQueryOptions<TOutput, TError, TSelectData,
|
|
49
|
+
}) & SetOptional<UseInfiniteQueryOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey'>;
|
|
46
50
|
interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
|
|
47
51
|
queryKey: QueryKey;
|
|
48
52
|
queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
|
|
49
|
-
|
|
53
|
+
throwOnError?(error: TError): boolean;
|
|
54
|
+
retryDelay?: (count: number, error: TError) => number;
|
|
55
|
+
enabled: boolean;
|
|
50
56
|
}
|
|
51
57
|
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
|
52
58
|
context?: TClientContext;
|
|
@@ -59,25 +65,32 @@ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput,
|
|
|
59
65
|
/**
|
|
60
66
|
* Calling corresponding procedure client
|
|
61
67
|
*
|
|
62
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
|
|
68
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
|
|
63
69
|
*/
|
|
64
70
|
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
65
71
|
/**
|
|
66
72
|
* Generate options used for useQuery/useSuspenseQuery/prefetchQuery/...
|
|
67
73
|
*
|
|
68
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-options-utility Tanstack Query Options Utility Docs}
|
|
74
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-options-utility Tanstack Query Options Utility Docs}
|
|
69
75
|
*/
|
|
70
76
|
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
|
77
|
+
/**
|
|
78
|
+
* Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/useSuspenseQuery/prefetchQuery/...
|
|
79
|
+
* Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
|
80
|
+
*
|
|
81
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
|
|
82
|
+
*/
|
|
83
|
+
experimental_streamedOptions<U, USelectData = experimental_InferStreamedOutput<TOutput>>(...rest: MaybeOptionalOptions<U & experimental_StreamedOptionsIn<TClientContext, TInput, experimental_InferStreamedOutput<TOutput>, TError, USelectData>>): NoInfer<U & Omit<experimental_StreamedOptionsBase<experimental_InferStreamedOutput<TOutput>, TError>, keyof U>>;
|
|
71
84
|
/**
|
|
72
85
|
* Generate options used for useInfiniteQuery/useSuspenseInfiniteQuery/prefetchInfiniteQuery/...
|
|
73
86
|
*
|
|
74
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
|
|
87
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
|
|
75
88
|
*/
|
|
76
89
|
infiniteOptions<U, UPageParam, USelectData = InfiniteData<TOutput, UPageParam>>(options: U & InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UPageParam>): NoInfer<U & Omit<InfiniteOptionsBase<TOutput, TError, UPageParam>, keyof U>>;
|
|
77
90
|
/**
|
|
78
91
|
* Generate options used for useMutation/...
|
|
79
92
|
*
|
|
80
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#mutation-options Tanstack Mutation Options Docs}
|
|
93
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#mutation-options Tanstack Mutation Options Docs}
|
|
81
94
|
*/
|
|
82
95
|
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
|
|
83
96
|
}
|
|
@@ -96,9 +109,9 @@ interface CreateRouterUtilsOptions {
|
|
|
96
109
|
* Create a router utils from a client.
|
|
97
110
|
*
|
|
98
111
|
* @info Both client-side and server-side clients are supported.
|
|
99
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/react Tanstack Query React Docs}
|
|
112
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/react Tanstack Query React Docs}
|
|
100
113
|
*/
|
|
101
114
|
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
|
102
115
|
|
|
103
|
-
export {
|
|
104
|
-
export type {
|
|
116
|
+
export { createGeneralUtils, createRouterUtils as createORPCReactQueryUtils, createProcedureUtils, createRouterUtils };
|
|
117
|
+
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, experimental_InferStreamedOutput, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
interface BuildKeyOptions<TType extends KeyType, TInput> {
|
|
7
|
-
type?: TType;
|
|
8
|
-
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
|
9
|
-
}
|
|
10
|
-
declare function buildKey<TType extends KeyType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
|
|
2
|
+
import { OperationType, OperationKeyOptions } from '@orpc/tanstack-query';
|
|
3
|
+
export { OperationKeyOptions as BuildKeyOptions, OperationType as KeyType, generateOperationKey as buildKey } from '@orpc/tanstack-query';
|
|
4
|
+
import { QueryKey, SkipToken, UseQueryOptions, QueryFunctionContext, experimental_streamedQuery, UseInfiniteQueryOptions, UseMutationOptions, InfiniteData } from '@tanstack/react-query';
|
|
5
|
+
import { SetOptional, MaybeOptionalOptions } from '@orpc/shared';
|
|
11
6
|
|
|
12
7
|
/**
|
|
13
8
|
* Utils at any level (procedure or router)
|
|
@@ -16,16 +11,16 @@ interface GeneralUtils<TInput> {
|
|
|
16
11
|
/**
|
|
17
12
|
* Generate a query/mutation key for checking status, invalidate, set, get, etc.
|
|
18
13
|
*
|
|
19
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
14
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
20
15
|
*/
|
|
21
|
-
key<UType extends
|
|
16
|
+
key<UType extends OperationType>(options?: OperationKeyOptions<UType, TInput>): QueryKey;
|
|
22
17
|
}
|
|
23
18
|
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
|
24
19
|
|
|
25
20
|
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
|
|
26
|
-
input?: TInput;
|
|
21
|
+
input?: TInput | SkipToken;
|
|
27
22
|
} : {
|
|
28
|
-
input: TInput;
|
|
23
|
+
input: TInput | SkipToken;
|
|
29
24
|
}) & (Record<never, never> extends TClientContext ? {
|
|
30
25
|
context?: TClientContext;
|
|
31
26
|
} : {
|
|
@@ -34,19 +29,30 @@ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TErro
|
|
|
34
29
|
interface QueryOptionsBase<TOutput, TError> {
|
|
35
30
|
queryKey: QueryKey;
|
|
36
31
|
queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
|
|
37
|
-
|
|
32
|
+
throwOnError?(error: TError): boolean;
|
|
33
|
+
retryDelay?: (count: number, error: TError) => number;
|
|
34
|
+
enabled: boolean;
|
|
35
|
+
}
|
|
36
|
+
type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
|
|
37
|
+
type experimental_InferStreamedOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
38
|
+
type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & {
|
|
39
|
+
queryFnOptions?: experimental_StreamedQueryOptions;
|
|
40
|
+
};
|
|
41
|
+
interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
|
|
38
42
|
}
|
|
39
43
|
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = {
|
|
40
|
-
input: (pageParam: TPageParam) => TInput;
|
|
44
|
+
input: ((pageParam: TPageParam) => TInput) | SkipToken;
|
|
41
45
|
} & (Record<never, never> extends TClientContext ? {
|
|
42
46
|
context?: TClientContext;
|
|
43
47
|
} : {
|
|
44
48
|
context: TClientContext;
|
|
45
|
-
}) & SetOptional<UseInfiniteQueryOptions<TOutput, TError, TSelectData,
|
|
49
|
+
}) & SetOptional<UseInfiniteQueryOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey'>;
|
|
46
50
|
interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
|
|
47
51
|
queryKey: QueryKey;
|
|
48
52
|
queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
|
|
49
|
-
|
|
53
|
+
throwOnError?(error: TError): boolean;
|
|
54
|
+
retryDelay?: (count: number, error: TError) => number;
|
|
55
|
+
enabled: boolean;
|
|
50
56
|
}
|
|
51
57
|
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
|
52
58
|
context?: TClientContext;
|
|
@@ -59,25 +65,32 @@ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput,
|
|
|
59
65
|
/**
|
|
60
66
|
* Calling corresponding procedure client
|
|
61
67
|
*
|
|
62
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
|
|
68
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
|
|
63
69
|
*/
|
|
64
70
|
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
65
71
|
/**
|
|
66
72
|
* Generate options used for useQuery/useSuspenseQuery/prefetchQuery/...
|
|
67
73
|
*
|
|
68
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-options-utility Tanstack Query Options Utility Docs}
|
|
74
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-options-utility Tanstack Query Options Utility Docs}
|
|
69
75
|
*/
|
|
70
76
|
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
|
77
|
+
/**
|
|
78
|
+
* Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/useSuspenseQuery/prefetchQuery/...
|
|
79
|
+
* Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
|
80
|
+
*
|
|
81
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
|
|
82
|
+
*/
|
|
83
|
+
experimental_streamedOptions<U, USelectData = experimental_InferStreamedOutput<TOutput>>(...rest: MaybeOptionalOptions<U & experimental_StreamedOptionsIn<TClientContext, TInput, experimental_InferStreamedOutput<TOutput>, TError, USelectData>>): NoInfer<U & Omit<experimental_StreamedOptionsBase<experimental_InferStreamedOutput<TOutput>, TError>, keyof U>>;
|
|
71
84
|
/**
|
|
72
85
|
* Generate options used for useInfiniteQuery/useSuspenseInfiniteQuery/prefetchInfiniteQuery/...
|
|
73
86
|
*
|
|
74
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
|
|
87
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
|
|
75
88
|
*/
|
|
76
89
|
infiniteOptions<U, UPageParam, USelectData = InfiniteData<TOutput, UPageParam>>(options: U & InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UPageParam>): NoInfer<U & Omit<InfiniteOptionsBase<TOutput, TError, UPageParam>, keyof U>>;
|
|
77
90
|
/**
|
|
78
91
|
* Generate options used for useMutation/...
|
|
79
92
|
*
|
|
80
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#mutation-options Tanstack Mutation Options Docs}
|
|
93
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#mutation-options Tanstack Mutation Options Docs}
|
|
81
94
|
*/
|
|
82
95
|
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
|
|
83
96
|
}
|
|
@@ -96,9 +109,9 @@ interface CreateRouterUtilsOptions {
|
|
|
96
109
|
* Create a router utils from a client.
|
|
97
110
|
*
|
|
98
111
|
* @info Both client-side and server-side clients are supported.
|
|
99
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/react Tanstack Query React Docs}
|
|
112
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/react Tanstack Query React Docs}
|
|
100
113
|
*/
|
|
101
114
|
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
|
102
115
|
|
|
103
|
-
export {
|
|
104
|
-
export type {
|
|
116
|
+
export { createGeneralUtils, createRouterUtils as createORPCReactQueryUtils, createProcedureUtils, createRouterUtils };
|
|
117
|
+
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, experimental_InferStreamedOutput, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn };
|
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
...withInput,
|
|
6
|
-
...withType
|
|
7
|
-
}];
|
|
8
|
-
}
|
|
1
|
+
import { generateOperationKey } from '@orpc/tanstack-query';
|
|
2
|
+
export { generateOperationKey as buildKey } from '@orpc/tanstack-query';
|
|
3
|
+
import { isAsyncIteratorObject } from '@orpc/shared';
|
|
4
|
+
import { skipToken, experimental_streamedQuery } from '@tanstack/react-query';
|
|
9
5
|
|
|
10
6
|
function createGeneralUtils(path) {
|
|
11
7
|
return {
|
|
12
8
|
key(options) {
|
|
13
|
-
return
|
|
9
|
+
return generateOperationKey(path, options);
|
|
14
10
|
}
|
|
15
11
|
};
|
|
16
12
|
}
|
|
@@ -20,23 +16,56 @@ function createProcedureUtils(client, options) {
|
|
|
20
16
|
call: client,
|
|
21
17
|
queryOptions(...[optionsIn = {}]) {
|
|
22
18
|
return {
|
|
23
|
-
queryKey:
|
|
24
|
-
queryFn: ({ signal }) =>
|
|
19
|
+
queryKey: generateOperationKey(options.path, { type: "query", input: optionsIn.input }),
|
|
20
|
+
queryFn: ({ signal }) => {
|
|
21
|
+
if (optionsIn.input === skipToken) {
|
|
22
|
+
throw new Error("queryFn should not be called with skipToken used as input");
|
|
23
|
+
}
|
|
24
|
+
return client(optionsIn.input, { signal, context: optionsIn.context });
|
|
25
|
+
},
|
|
26
|
+
enabled: optionsIn.input !== skipToken,
|
|
27
|
+
...optionsIn
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
experimental_streamedOptions(...[optionsIn = {}]) {
|
|
31
|
+
return {
|
|
32
|
+
enabled: optionsIn.input !== skipToken,
|
|
33
|
+
queryKey: generateOperationKey(options.path, { type: "streamed", input: optionsIn.input, fnOptions: optionsIn.queryFnOptions }),
|
|
34
|
+
queryFn: experimental_streamedQuery({
|
|
35
|
+
queryFn: async ({ signal }) => {
|
|
36
|
+
if (optionsIn.input === skipToken) {
|
|
37
|
+
throw new Error("queryFn should not be called with skipToken used as input");
|
|
38
|
+
}
|
|
39
|
+
const output = await client(optionsIn.input, { signal, context: optionsIn.context });
|
|
40
|
+
if (!isAsyncIteratorObject(output)) {
|
|
41
|
+
throw new Error("streamedQuery requires an event iterator output");
|
|
42
|
+
}
|
|
43
|
+
return output;
|
|
44
|
+
},
|
|
45
|
+
...optionsIn.queryFnOptions
|
|
46
|
+
}),
|
|
25
47
|
...optionsIn
|
|
26
48
|
};
|
|
27
49
|
},
|
|
28
50
|
infiniteOptions(optionsIn) {
|
|
29
51
|
return {
|
|
30
|
-
queryKey:
|
|
52
|
+
queryKey: generateOperationKey(options.path, {
|
|
53
|
+
type: "infinite",
|
|
54
|
+
input: optionsIn.input === skipToken ? skipToken : optionsIn.input(optionsIn.initialPageParam)
|
|
55
|
+
}),
|
|
31
56
|
queryFn: ({ pageParam, signal }) => {
|
|
57
|
+
if (optionsIn.input === skipToken) {
|
|
58
|
+
throw new Error("queryFn should not be called with skipToken used as input");
|
|
59
|
+
}
|
|
32
60
|
return client(optionsIn.input(pageParam), { signal, context: optionsIn.context });
|
|
33
61
|
},
|
|
62
|
+
enabled: optionsIn.input !== skipToken,
|
|
34
63
|
...optionsIn
|
|
35
64
|
};
|
|
36
65
|
},
|
|
37
66
|
mutationOptions(...[optionsIn = {}]) {
|
|
38
67
|
return {
|
|
39
|
-
mutationKey:
|
|
68
|
+
mutationKey: generateOperationKey(options.path, { type: "mutation" }),
|
|
40
69
|
mutationFn: (input) => client(input, { context: optionsIn.context }),
|
|
41
70
|
...optionsIn
|
|
42
71
|
};
|
|
@@ -71,4 +100,4 @@ function createRouterUtils(client, options = {}) {
|
|
|
71
100
|
return recursive;
|
|
72
101
|
}
|
|
73
102
|
|
|
74
|
-
export {
|
|
103
|
+
export { createGeneralUtils, createRouterUtils as createORPCReactQueryUtils, createProcedureUtils, createRouterUtils };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/react-query",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -27,17 +27,18 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@tanstack/react-query": ">=5.
|
|
30
|
+
"@tanstack/react-query": ">=5.80.2",
|
|
31
31
|
"react": ">=18.3.0",
|
|
32
|
-
"@orpc/client": "1.
|
|
32
|
+
"@orpc/client": "1.4.0"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@orpc/shared": "1.
|
|
35
|
+
"@orpc/shared": "1.4.0",
|
|
36
|
+
"@orpc/tanstack-query": "1.4.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@tanstack/
|
|
39
|
+
"@tanstack/react-query": "^5.80.2",
|
|
39
40
|
"react": "^19.1.0",
|
|
40
|
-
"zod": "^3.
|
|
41
|
+
"zod": "^3.25.49"
|
|
41
42
|
},
|
|
42
43
|
"scripts": {
|
|
43
44
|
"build": "unbuild",
|