@orpc/tanstack-query 0.0.0-next.343cede → 0.0.0-next.347f023
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 +4 -2
- package/dist/index.d.mts +65 -19
- package/dist/index.d.ts +65 -19
- package/dist/index.mjs +77 -9
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
31
31
|
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
32
|
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
33
|
-
-
|
|
33
|
+
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
|
34
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
|
34
35
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
35
36
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
36
37
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
@@ -38,7 +39,6 @@
|
|
|
38
39
|
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
39
40
|
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
40
41
|
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
41
|
-
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
|
42
42
|
|
|
43
43
|
## Documentation
|
|
44
44
|
|
|
@@ -50,9 +50,11 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
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
52
|
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
53
|
+
- [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
|
|
53
54
|
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
54
55
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
55
56
|
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
57
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
|
56
58
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
57
59
|
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
58
60
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
|
2
2
|
import { SetOptional, PartialDeep, MaybeOptionalOptions } from '@orpc/shared';
|
|
3
|
-
import { SkipToken, QueryObserverOptions,
|
|
3
|
+
import { SkipToken, QueryKey, QueryObserverOptions, DataTag, QueryFunction, experimental_streamedQuery, InfiniteQueryObserverOptions, InfiniteData, MutationObserverOptions } from '@tanstack/query-core';
|
|
4
4
|
|
|
5
5
|
type experimental_StreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
6
|
+
type experimental_LiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
|
|
6
7
|
type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
|
|
7
|
-
type OperationType = 'query' | 'streamed' | 'infinite' | 'mutation';
|
|
8
|
+
type OperationType = 'query' | 'streamed' | 'live' | 'infinite' | 'mutation';
|
|
8
9
|
type OperationKeyOptions<TType extends OperationType, TInput> = {
|
|
9
10
|
type?: TType;
|
|
10
11
|
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
|
@@ -18,22 +19,28 @@ interface OperationContext {
|
|
|
18
19
|
type: OperationType;
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
|
-
type
|
|
22
|
+
type QueryKeyOptions<TInput> = (undefined extends TInput ? {
|
|
22
23
|
input?: TInput | SkipToken;
|
|
23
24
|
} : {
|
|
24
25
|
input: TInput | SkipToken;
|
|
25
|
-
}) &
|
|
26
|
+
}) & {
|
|
27
|
+
queryKey?: QueryKey;
|
|
28
|
+
};
|
|
29
|
+
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryKeyOptions<TInput> & (Record<never, never> extends TClientContext ? {
|
|
26
30
|
context?: TClientContext;
|
|
27
31
|
} : {
|
|
28
32
|
context: TClientContext;
|
|
29
|
-
}) &
|
|
33
|
+
}) & Omit<QueryObserverOptions<TOutput, TError, TSelectData>, 'queryKey'>;
|
|
30
34
|
interface QueryOptionsBase<TOutput, TError> {
|
|
31
|
-
queryKey: QueryKey
|
|
35
|
+
queryKey: DataTag<QueryKey, TOutput, TError>;
|
|
32
36
|
queryFn: QueryFunction<TOutput>;
|
|
33
37
|
throwOnError?: (error: TError) => boolean;
|
|
34
38
|
retryDelay?: (count: number, error: TError) => number;
|
|
35
|
-
enabled
|
|
39
|
+
enabled?: boolean;
|
|
36
40
|
}
|
|
41
|
+
type experimental_StreamedKeyOptions<TInput> = QueryKeyOptions<TInput> & {
|
|
42
|
+
queryFnOptions?: experimental_StreamedQueryOptions;
|
|
43
|
+
};
|
|
37
44
|
type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & {
|
|
38
45
|
queryFnOptions?: experimental_StreamedQueryOptions;
|
|
39
46
|
};
|
|
@@ -47,12 +54,12 @@ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
|
|
|
47
54
|
context: TClientContext;
|
|
48
55
|
}) & SetOptional<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey'>;
|
|
49
56
|
interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
|
|
50
|
-
queryKey: QueryKey
|
|
57
|
+
queryKey: DataTag<QueryKey, InfiniteData<TOutput, TPageParam>, TError>;
|
|
51
58
|
queryFn: QueryFunction<TOutput, QueryKey, TPageParam>;
|
|
52
59
|
select?(): InfiniteData<TOutput, TPageParam>;
|
|
53
60
|
throwOnError?: (error: TError) => boolean;
|
|
54
61
|
retryDelay?: (count: number, error: TError) => number;
|
|
55
|
-
enabled
|
|
62
|
+
enabled?: boolean;
|
|
56
63
|
}
|
|
57
64
|
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
|
58
65
|
context?: TClientContext;
|
|
@@ -66,9 +73,9 @@ type MutationOptions<TInput, TOutput, TError, TMutationContext> = MutationObserv
|
|
|
66
73
|
*/
|
|
67
74
|
interface GeneralUtils<TInput> {
|
|
68
75
|
/**
|
|
69
|
-
* Generate a
|
|
76
|
+
* Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
|
|
70
77
|
*
|
|
71
|
-
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query
|
|
78
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
72
79
|
*/
|
|
73
80
|
key<TType extends OperationType>(options?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
|
|
74
81
|
}
|
|
@@ -80,32 +87,71 @@ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput,
|
|
|
80
87
|
/**
|
|
81
88
|
* Calling corresponding procedure client
|
|
82
89
|
*
|
|
83
|
-
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query
|
|
90
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#calling-clients Tanstack Calling Procedure Client Docs}
|
|
84
91
|
*/
|
|
85
92
|
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
93
|
+
/**
|
|
94
|
+
* Generate a **full matching** key for [Query Options](https://orpc.unnoq.com/docs/integrations/tanstack-query#query-options).
|
|
95
|
+
*
|
|
96
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
97
|
+
*/
|
|
98
|
+
queryKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): DataTag<QueryKey, TOutput, TError>;
|
|
86
99
|
/**
|
|
87
100
|
* Generate options used for useQuery/useSuspenseQuery/prefetchQuery/...
|
|
88
101
|
*
|
|
89
|
-
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query
|
|
102
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-options Tanstack Query Options Utility Docs}
|
|
90
103
|
*/
|
|
91
104
|
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
|
92
105
|
/**
|
|
93
|
-
* Generate [
|
|
94
|
-
* Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
|
106
|
+
* Generate a **full matching** key for [Streamed Query Options](https://orpc.unnoq.com/docs/integrations/tanstack-query#streamed-query-options).
|
|
95
107
|
*
|
|
96
|
-
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query
|
|
108
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
109
|
+
*/
|
|
110
|
+
experimental_streamedKey(...rest: MaybeOptionalOptions<experimental_StreamedKeyOptions<TInput>>): DataTag<QueryKey, experimental_StreamedQueryOutput<TOutput>, TError>;
|
|
111
|
+
/**
|
|
112
|
+
* Configure queries for [Event Iterator](https://orpc.unnoq.com/docs/event-iterator).
|
|
113
|
+
* This is built on [TanStack Query streamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
|
114
|
+
* and works with hooks like `useQuery`, `useSuspenseQuery`, or `prefetchQuery`.
|
|
115
|
+
*
|
|
116
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#streamed-query-options Tanstack Streamed Query Options Utility Docs}
|
|
97
117
|
*/
|
|
98
118
|
experimental_streamedOptions<U, USelectData = experimental_StreamedQueryOutput<TOutput>>(...rest: MaybeOptionalOptions<U & experimental_StreamedOptionsIn<TClientContext, TInput, experimental_StreamedQueryOutput<TOutput>, TError, USelectData>>): NoInfer<U & Omit<experimental_StreamedOptionsBase<experimental_StreamedQueryOutput<TOutput>, TError>, keyof U>>;
|
|
119
|
+
/**
|
|
120
|
+
* Generate a **full matching** key for [Live Query Options](https://orpc.unnoq.com/docs/integrations/tanstack-query#live-query-options).
|
|
121
|
+
*
|
|
122
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
123
|
+
*/
|
|
124
|
+
experimental_liveKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): DataTag<QueryKey, experimental_LiveQueryOutput<TOutput>, TError>;
|
|
125
|
+
/**
|
|
126
|
+
* Configure live queries for [Event Iterator](https://orpc.unnoq.com/docs/event-iterator).
|
|
127
|
+
* Unlike `.streamedOptions` which accumulates chunks, live queries replace the entire result with each new chunk received.
|
|
128
|
+
* Works with hooks like `useQuery`, `useSuspenseQuery`, or `prefetchQuery`.
|
|
129
|
+
*
|
|
130
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#live-query-options Tanstack Live Query Options Utility Docs}
|
|
131
|
+
*/
|
|
132
|
+
experimental_liveOptions<U, USelectData = experimental_LiveQueryOutput<TOutput>>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, experimental_LiveQueryOutput<TOutput>, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<experimental_LiveQueryOutput<TOutput>, TError>, keyof U>>;
|
|
133
|
+
/**
|
|
134
|
+
* Generate a **full matching** key for [Infinite Query Options](https://orpc.unnoq.com/docs/integrations/tanstack-query#infinite-query-options).
|
|
135
|
+
*
|
|
136
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
137
|
+
*/
|
|
138
|
+
infiniteKey<UPageParam>(options: Pick<InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, InfiniteData<TOutput, UPageParam>, UPageParam>, 'input' | 'initialPageParam' | 'queryKey'>): DataTag<QueryKey, InfiniteData<TOutput, UPageParam>, TError>;
|
|
99
139
|
/**
|
|
100
140
|
* Generate options used for useInfiniteQuery/useSuspenseInfiniteQuery/prefetchInfiniteQuery/...
|
|
101
141
|
*
|
|
102
|
-
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query
|
|
142
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#infinite-query-options Tanstack Infinite Query Options Utility Docs}
|
|
103
143
|
*/
|
|
104
144
|
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>>;
|
|
145
|
+
/**
|
|
146
|
+
* Generate a **full matching** key for [Mutation Options](https://orpc.unnoq.com/docs/integrations/tanstack-query#mutation-options).
|
|
147
|
+
*
|
|
148
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
149
|
+
*/
|
|
150
|
+
mutationKey(options?: Pick<MutationOptionsIn<TClientContext, TInput, TOutput, TError, any>, 'mutationKey'>): DataTag<QueryKey, TOutput, TError>;
|
|
105
151
|
/**
|
|
106
152
|
* Generate options used for useMutation/...
|
|
107
153
|
*
|
|
108
|
-
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query
|
|
154
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#mutation-options Tanstack Mutation Options Docs}
|
|
109
155
|
*/
|
|
110
156
|
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptions<TInput, TOutput, TError, UMutationContext>>;
|
|
111
157
|
}
|
|
@@ -129,4 +175,4 @@ interface CreateRouterUtilsOptions {
|
|
|
129
175
|
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
|
130
176
|
|
|
131
177
|
export { OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createGeneralUtils, createProcedureUtils, createRouterUtils, createRouterUtils as createTanstackQueryUtils, generateOperationKey };
|
|
132
|
-
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, OperationContext, OperationKey, OperationKeyOptions, OperationType, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, OperationContext as TanstackQueryOperationContext, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn, experimental_StreamedQueryOutput };
|
|
178
|
+
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, OperationContext, OperationKey, OperationKeyOptions, OperationType, ProcedureUtils, QueryKeyOptions, QueryOptionsBase, QueryOptionsIn, RouterUtils, OperationContext as TanstackQueryOperationContext, experimental_LiveQueryOutput, experimental_StreamedKeyOptions, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn, experimental_StreamedQueryOutput };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
|
2
2
|
import { SetOptional, PartialDeep, MaybeOptionalOptions } from '@orpc/shared';
|
|
3
|
-
import { SkipToken, QueryObserverOptions,
|
|
3
|
+
import { SkipToken, QueryKey, QueryObserverOptions, DataTag, QueryFunction, experimental_streamedQuery, InfiniteQueryObserverOptions, InfiniteData, MutationObserverOptions } from '@tanstack/query-core';
|
|
4
4
|
|
|
5
5
|
type experimental_StreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
6
|
+
type experimental_LiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
|
|
6
7
|
type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
|
|
7
|
-
type OperationType = 'query' | 'streamed' | 'infinite' | 'mutation';
|
|
8
|
+
type OperationType = 'query' | 'streamed' | 'live' | 'infinite' | 'mutation';
|
|
8
9
|
type OperationKeyOptions<TType extends OperationType, TInput> = {
|
|
9
10
|
type?: TType;
|
|
10
11
|
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
|
@@ -18,22 +19,28 @@ interface OperationContext {
|
|
|
18
19
|
type: OperationType;
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
|
-
type
|
|
22
|
+
type QueryKeyOptions<TInput> = (undefined extends TInput ? {
|
|
22
23
|
input?: TInput | SkipToken;
|
|
23
24
|
} : {
|
|
24
25
|
input: TInput | SkipToken;
|
|
25
|
-
}) &
|
|
26
|
+
}) & {
|
|
27
|
+
queryKey?: QueryKey;
|
|
28
|
+
};
|
|
29
|
+
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryKeyOptions<TInput> & (Record<never, never> extends TClientContext ? {
|
|
26
30
|
context?: TClientContext;
|
|
27
31
|
} : {
|
|
28
32
|
context: TClientContext;
|
|
29
|
-
}) &
|
|
33
|
+
}) & Omit<QueryObserverOptions<TOutput, TError, TSelectData>, 'queryKey'>;
|
|
30
34
|
interface QueryOptionsBase<TOutput, TError> {
|
|
31
|
-
queryKey: QueryKey
|
|
35
|
+
queryKey: DataTag<QueryKey, TOutput, TError>;
|
|
32
36
|
queryFn: QueryFunction<TOutput>;
|
|
33
37
|
throwOnError?: (error: TError) => boolean;
|
|
34
38
|
retryDelay?: (count: number, error: TError) => number;
|
|
35
|
-
enabled
|
|
39
|
+
enabled?: boolean;
|
|
36
40
|
}
|
|
41
|
+
type experimental_StreamedKeyOptions<TInput> = QueryKeyOptions<TInput> & {
|
|
42
|
+
queryFnOptions?: experimental_StreamedQueryOptions;
|
|
43
|
+
};
|
|
37
44
|
type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & {
|
|
38
45
|
queryFnOptions?: experimental_StreamedQueryOptions;
|
|
39
46
|
};
|
|
@@ -47,12 +54,12 @@ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
|
|
|
47
54
|
context: TClientContext;
|
|
48
55
|
}) & SetOptional<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey'>;
|
|
49
56
|
interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
|
|
50
|
-
queryKey: QueryKey
|
|
57
|
+
queryKey: DataTag<QueryKey, InfiniteData<TOutput, TPageParam>, TError>;
|
|
51
58
|
queryFn: QueryFunction<TOutput, QueryKey, TPageParam>;
|
|
52
59
|
select?(): InfiniteData<TOutput, TPageParam>;
|
|
53
60
|
throwOnError?: (error: TError) => boolean;
|
|
54
61
|
retryDelay?: (count: number, error: TError) => number;
|
|
55
|
-
enabled
|
|
62
|
+
enabled?: boolean;
|
|
56
63
|
}
|
|
57
64
|
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
|
58
65
|
context?: TClientContext;
|
|
@@ -66,9 +73,9 @@ type MutationOptions<TInput, TOutput, TError, TMutationContext> = MutationObserv
|
|
|
66
73
|
*/
|
|
67
74
|
interface GeneralUtils<TInput> {
|
|
68
75
|
/**
|
|
69
|
-
* Generate a
|
|
76
|
+
* Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
|
|
70
77
|
*
|
|
71
|
-
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query
|
|
78
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
72
79
|
*/
|
|
73
80
|
key<TType extends OperationType>(options?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
|
|
74
81
|
}
|
|
@@ -80,32 +87,71 @@ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput,
|
|
|
80
87
|
/**
|
|
81
88
|
* Calling corresponding procedure client
|
|
82
89
|
*
|
|
83
|
-
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query
|
|
90
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#calling-clients Tanstack Calling Procedure Client Docs}
|
|
84
91
|
*/
|
|
85
92
|
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
93
|
+
/**
|
|
94
|
+
* Generate a **full matching** key for [Query Options](https://orpc.unnoq.com/docs/integrations/tanstack-query#query-options).
|
|
95
|
+
*
|
|
96
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
97
|
+
*/
|
|
98
|
+
queryKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): DataTag<QueryKey, TOutput, TError>;
|
|
86
99
|
/**
|
|
87
100
|
* Generate options used for useQuery/useSuspenseQuery/prefetchQuery/...
|
|
88
101
|
*
|
|
89
|
-
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query
|
|
102
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-options Tanstack Query Options Utility Docs}
|
|
90
103
|
*/
|
|
91
104
|
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
|
92
105
|
/**
|
|
93
|
-
* Generate [
|
|
94
|
-
* Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
|
106
|
+
* Generate a **full matching** key for [Streamed Query Options](https://orpc.unnoq.com/docs/integrations/tanstack-query#streamed-query-options).
|
|
95
107
|
*
|
|
96
|
-
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query
|
|
108
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
109
|
+
*/
|
|
110
|
+
experimental_streamedKey(...rest: MaybeOptionalOptions<experimental_StreamedKeyOptions<TInput>>): DataTag<QueryKey, experimental_StreamedQueryOutput<TOutput>, TError>;
|
|
111
|
+
/**
|
|
112
|
+
* Configure queries for [Event Iterator](https://orpc.unnoq.com/docs/event-iterator).
|
|
113
|
+
* This is built on [TanStack Query streamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
|
114
|
+
* and works with hooks like `useQuery`, `useSuspenseQuery`, or `prefetchQuery`.
|
|
115
|
+
*
|
|
116
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#streamed-query-options Tanstack Streamed Query Options Utility Docs}
|
|
97
117
|
*/
|
|
98
118
|
experimental_streamedOptions<U, USelectData = experimental_StreamedQueryOutput<TOutput>>(...rest: MaybeOptionalOptions<U & experimental_StreamedOptionsIn<TClientContext, TInput, experimental_StreamedQueryOutput<TOutput>, TError, USelectData>>): NoInfer<U & Omit<experimental_StreamedOptionsBase<experimental_StreamedQueryOutput<TOutput>, TError>, keyof U>>;
|
|
119
|
+
/**
|
|
120
|
+
* Generate a **full matching** key for [Live Query Options](https://orpc.unnoq.com/docs/integrations/tanstack-query#live-query-options).
|
|
121
|
+
*
|
|
122
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
123
|
+
*/
|
|
124
|
+
experimental_liveKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): DataTag<QueryKey, experimental_LiveQueryOutput<TOutput>, TError>;
|
|
125
|
+
/**
|
|
126
|
+
* Configure live queries for [Event Iterator](https://orpc.unnoq.com/docs/event-iterator).
|
|
127
|
+
* Unlike `.streamedOptions` which accumulates chunks, live queries replace the entire result with each new chunk received.
|
|
128
|
+
* Works with hooks like `useQuery`, `useSuspenseQuery`, or `prefetchQuery`.
|
|
129
|
+
*
|
|
130
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#live-query-options Tanstack Live Query Options Utility Docs}
|
|
131
|
+
*/
|
|
132
|
+
experimental_liveOptions<U, USelectData = experimental_LiveQueryOutput<TOutput>>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, experimental_LiveQueryOutput<TOutput>, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<experimental_LiveQueryOutput<TOutput>, TError>, keyof U>>;
|
|
133
|
+
/**
|
|
134
|
+
* Generate a **full matching** key for [Infinite Query Options](https://orpc.unnoq.com/docs/integrations/tanstack-query#infinite-query-options).
|
|
135
|
+
*
|
|
136
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
137
|
+
*/
|
|
138
|
+
infiniteKey<UPageParam>(options: Pick<InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, InfiniteData<TOutput, UPageParam>, UPageParam>, 'input' | 'initialPageParam' | 'queryKey'>): DataTag<QueryKey, InfiniteData<TOutput, UPageParam>, TError>;
|
|
99
139
|
/**
|
|
100
140
|
* Generate options used for useInfiniteQuery/useSuspenseInfiniteQuery/prefetchInfiniteQuery/...
|
|
101
141
|
*
|
|
102
|
-
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query
|
|
142
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#infinite-query-options Tanstack Infinite Query Options Utility Docs}
|
|
103
143
|
*/
|
|
104
144
|
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>>;
|
|
145
|
+
/**
|
|
146
|
+
* Generate a **full matching** key for [Mutation Options](https://orpc.unnoq.com/docs/integrations/tanstack-query#mutation-options).
|
|
147
|
+
*
|
|
148
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
149
|
+
*/
|
|
150
|
+
mutationKey(options?: Pick<MutationOptionsIn<TClientContext, TInput, TOutput, TError, any>, 'mutationKey'>): DataTag<QueryKey, TOutput, TError>;
|
|
105
151
|
/**
|
|
106
152
|
* Generate options used for useMutation/...
|
|
107
153
|
*
|
|
108
|
-
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query
|
|
154
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#mutation-options Tanstack Mutation Options Docs}
|
|
109
155
|
*/
|
|
110
156
|
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptions<TInput, TOutput, TError, UMutationContext>>;
|
|
111
157
|
}
|
|
@@ -129,4 +175,4 @@ interface CreateRouterUtilsOptions {
|
|
|
129
175
|
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
|
130
176
|
|
|
131
177
|
export { OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createGeneralUtils, createProcedureUtils, createRouterUtils, createRouterUtils as createTanstackQueryUtils, generateOperationKey };
|
|
132
|
-
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, OperationContext, OperationKey, OperationKeyOptions, OperationType, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, OperationContext as TanstackQueryOperationContext, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn, experimental_StreamedQueryOutput };
|
|
178
|
+
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, OperationContext, OperationKey, OperationKeyOptions, OperationType, ProcedureUtils, QueryKeyOptions, QueryOptionsBase, QueryOptionsIn, RouterUtils, OperationContext as TanstackQueryOperationContext, experimental_LiveQueryOutput, experimental_StreamedKeyOptions, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn, experimental_StreamedQueryOutput };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isAsyncIteratorObject, toArray } from '@orpc/shared';
|
|
1
|
+
import { stringifyJSON, isAsyncIteratorObject, toArray } from '@orpc/shared';
|
|
2
2
|
import { skipToken, experimental_streamedQuery } from '@tanstack/query-core';
|
|
3
3
|
|
|
4
4
|
function generateOperationKey(path, state = {}) {
|
|
@@ -17,13 +17,37 @@ function createGeneralUtils(path) {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
function experimental_liveQuery(queryFn) {
|
|
21
|
+
return async (context) => {
|
|
22
|
+
const stream = await queryFn(context);
|
|
23
|
+
let last;
|
|
24
|
+
for await (const chunk of stream) {
|
|
25
|
+
if (context.signal.aborted) {
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
last = { chunk };
|
|
29
|
+
context.client.setQueryData(context.queryKey, chunk);
|
|
30
|
+
}
|
|
31
|
+
if (!last) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`Live query for ${stringifyJSON(context.queryKey)} did not yield any data. Ensure the query function returns an AsyncIterable with at least one chunk.`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return last.chunk;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
20
40
|
const OPERATION_CONTEXT_SYMBOL = Symbol("ORPC_OPERATION_CONTEXT");
|
|
21
41
|
|
|
22
42
|
function createProcedureUtils(client, options) {
|
|
23
|
-
|
|
43
|
+
const utils = {
|
|
24
44
|
call: client,
|
|
25
|
-
|
|
45
|
+
queryKey(...[optionsIn = {}]) {
|
|
26
46
|
const queryKey = optionsIn.queryKey ?? generateOperationKey(options.path, { type: "query", input: optionsIn.input });
|
|
47
|
+
return queryKey;
|
|
48
|
+
},
|
|
49
|
+
queryOptions(...[optionsIn = {}]) {
|
|
50
|
+
const queryKey = utils.queryKey(optionsIn);
|
|
27
51
|
return {
|
|
28
52
|
queryFn: ({ signal }) => {
|
|
29
53
|
if (optionsIn.input === skipToken) {
|
|
@@ -40,15 +64,18 @@ function createProcedureUtils(client, options) {
|
|
|
40
64
|
}
|
|
41
65
|
});
|
|
42
66
|
},
|
|
43
|
-
|
|
67
|
+
...optionsIn.input === skipToken ? { enabled: false } : {},
|
|
44
68
|
...optionsIn,
|
|
45
69
|
queryKey
|
|
46
70
|
};
|
|
47
71
|
},
|
|
48
|
-
|
|
72
|
+
experimental_streamedKey(...[optionsIn = {}]) {
|
|
49
73
|
const queryKey = optionsIn.queryKey ?? generateOperationKey(options.path, { type: "streamed", input: optionsIn.input, fnOptions: optionsIn.queryFnOptions });
|
|
74
|
+
return queryKey;
|
|
75
|
+
},
|
|
76
|
+
experimental_streamedOptions(...[optionsIn = {}]) {
|
|
77
|
+
const queryKey = utils.experimental_streamedKey(optionsIn);
|
|
50
78
|
return {
|
|
51
|
-
enabled: optionsIn.input !== skipToken,
|
|
52
79
|
queryFn: experimental_streamedQuery({
|
|
53
80
|
queryFn: async ({ signal }) => {
|
|
54
81
|
if (optionsIn.input === skipToken) {
|
|
@@ -71,15 +98,51 @@ function createProcedureUtils(client, options) {
|
|
|
71
98
|
},
|
|
72
99
|
...optionsIn.queryFnOptions
|
|
73
100
|
}),
|
|
101
|
+
...optionsIn.input === skipToken ? { enabled: false } : {},
|
|
74
102
|
...optionsIn,
|
|
75
103
|
queryKey
|
|
76
104
|
};
|
|
77
105
|
},
|
|
78
|
-
|
|
106
|
+
experimental_liveKey(...[optionsIn = {}]) {
|
|
107
|
+
const queryKey = optionsIn.queryKey ?? generateOperationKey(options.path, { type: "live", input: optionsIn.input });
|
|
108
|
+
return queryKey;
|
|
109
|
+
},
|
|
110
|
+
experimental_liveOptions(...[optionsIn = {}]) {
|
|
111
|
+
const queryKey = utils.experimental_liveKey(optionsIn);
|
|
112
|
+
return {
|
|
113
|
+
queryFn: experimental_liveQuery(async ({ signal }) => {
|
|
114
|
+
if (optionsIn.input === skipToken) {
|
|
115
|
+
throw new Error("queryFn should not be called with skipToken used as input");
|
|
116
|
+
}
|
|
117
|
+
const output = await client(optionsIn.input, {
|
|
118
|
+
signal,
|
|
119
|
+
context: {
|
|
120
|
+
[OPERATION_CONTEXT_SYMBOL]: {
|
|
121
|
+
key: queryKey,
|
|
122
|
+
type: "live"
|
|
123
|
+
},
|
|
124
|
+
...optionsIn.context
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
if (!isAsyncIteratorObject(output)) {
|
|
128
|
+
throw new Error("liveQuery requires an event iterator output");
|
|
129
|
+
}
|
|
130
|
+
return output;
|
|
131
|
+
}),
|
|
132
|
+
...optionsIn.input === skipToken ? { enabled: false } : {},
|
|
133
|
+
...optionsIn,
|
|
134
|
+
queryKey
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
infiniteKey(optionsIn) {
|
|
79
138
|
const queryKey = optionsIn.queryKey ?? generateOperationKey(options.path, {
|
|
80
139
|
type: "infinite",
|
|
81
140
|
input: optionsIn.input === skipToken ? skipToken : optionsIn.input(optionsIn.initialPageParam)
|
|
82
141
|
});
|
|
142
|
+
return queryKey;
|
|
143
|
+
},
|
|
144
|
+
infiniteOptions(optionsIn) {
|
|
145
|
+
const queryKey = utils.infiniteKey(optionsIn);
|
|
83
146
|
return {
|
|
84
147
|
queryFn: ({ pageParam, signal }) => {
|
|
85
148
|
if (optionsIn.input === skipToken) {
|
|
@@ -96,13 +159,17 @@ function createProcedureUtils(client, options) {
|
|
|
96
159
|
}
|
|
97
160
|
});
|
|
98
161
|
},
|
|
99
|
-
|
|
162
|
+
...optionsIn.input === skipToken ? { enabled: false } : {},
|
|
100
163
|
...optionsIn,
|
|
101
164
|
queryKey
|
|
102
165
|
};
|
|
103
166
|
},
|
|
104
|
-
|
|
167
|
+
mutationKey(...[optionsIn = {}]) {
|
|
105
168
|
const mutationKey = optionsIn.mutationKey ?? generateOperationKey(options.path, { type: "mutation" });
|
|
169
|
+
return mutationKey;
|
|
170
|
+
},
|
|
171
|
+
mutationOptions(...[optionsIn = {}]) {
|
|
172
|
+
const mutationKey = utils.mutationKey(optionsIn);
|
|
106
173
|
return {
|
|
107
174
|
mutationFn: (input) => client(input, {
|
|
108
175
|
context: {
|
|
@@ -118,6 +185,7 @@ function createProcedureUtils(client, options) {
|
|
|
118
185
|
};
|
|
119
186
|
}
|
|
120
187
|
};
|
|
188
|
+
return utils;
|
|
121
189
|
}
|
|
122
190
|
|
|
123
191
|
function createRouterUtils(client, options = {}) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/tanstack-query",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.347f023",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -25,22 +25,22 @@
|
|
|
25
25
|
],
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@tanstack/query-core": ">=5.80.2",
|
|
28
|
-
"@orpc/client": "0.0.0-next.
|
|
28
|
+
"@orpc/client": "0.0.0-next.347f023"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@orpc/shared": "0.0.0-next.
|
|
31
|
+
"@orpc/shared": "0.0.0-next.347f023"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@angular/core": "^20.
|
|
35
|
-
"@tanstack/angular-query-experimental": "^5.
|
|
36
|
-
"@tanstack/query-core": "^5.
|
|
37
|
-
"@tanstack/react-query": "^5.
|
|
38
|
-
"@tanstack/solid-query": "^5.
|
|
39
|
-
"@tanstack/svelte-query": "^5.
|
|
40
|
-
"@tanstack/vue-query": "^5.
|
|
41
|
-
"svelte": "^5.
|
|
42
|
-
"vue": "^3.5.
|
|
43
|
-
"zod": "^
|
|
34
|
+
"@angular/core": "^20.1.7",
|
|
35
|
+
"@tanstack/angular-query-experimental": "^5.85.5",
|
|
36
|
+
"@tanstack/query-core": "^5.85.5",
|
|
37
|
+
"@tanstack/react-query": "^5.85.5",
|
|
38
|
+
"@tanstack/solid-query": "^5.85.5",
|
|
39
|
+
"@tanstack/svelte-query": "^5.85.5",
|
|
40
|
+
"@tanstack/vue-query": "^5.85.5",
|
|
41
|
+
"svelte": "^5.38.2",
|
|
42
|
+
"vue": "^3.5.18",
|
|
43
|
+
"zod": "^4.1.1"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "unbuild",
|