@orpc/tanstack-query 0.0.0-next.dd4e882 → 0.0.0-next.dd705fc

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 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
- - **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
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
 
@@ -49,14 +49,14 @@ 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
+ - [@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.
54
+ - [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
53
55
  - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
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).
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).
56
- - [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
57
- - [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
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.
58
58
  - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
59
- - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
59
+ - [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
60
60
  - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
61
61
  - [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
62
62
  - [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
package/dist/index.d.mts CHANGED
@@ -1,24 +1,11 @@
1
- import { OperationType as OperationType$1, OperationKeyOptions as OperationKeyOptions$1, OperationKey as OperationKey$1 } from '@orpc/tanstack-query';
2
1
  import { ClientContext, Client, NestedClient } from '@orpc/client';
3
2
  import { SetOptional, PartialDeep, MaybeOptionalOptions } from '@orpc/shared';
4
- import { SkipToken, QueryObserverOptions, QueryKey, QueryFunction, experimental_streamedQuery, InfiniteQueryObserverOptions, InfiniteData, MutationObserverOptions } from '@tanstack/query-core';
5
-
6
- /**
7
- * Utils at any level (procedure or router)
8
- */
9
- interface GeneralUtils<TInput> {
10
- /**
11
- * Generate a query/mutation key for checking status, invalidate, set, get, etc.
12
- *
13
- * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
14
- */
15
- key<TType extends OperationType$1>(options?: OperationKeyOptions$1<TType, TInput>): OperationKey$1<TType, TInput>;
16
- }
17
- declare function createGeneralUtils<TInput>(path: readonly string[]): GeneralUtils<TInput>;
3
+ import { SkipToken, QueryKey, QueryObserverOptions, DataTag, QueryFunction, experimental_streamedQuery, InfiniteQueryObserverOptions, InfiniteData, MutationObserverOptions } from '@tanstack/query-core';
18
4
 
19
5
  type experimental_StreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
6
+ type experimental_LiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
20
7
  type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
21
- type OperationType = 'query' | 'streamed' | 'infinite' | 'mutation';
8
+ type OperationType = 'query' | 'streamed' | 'live' | 'infinite' | 'mutation';
22
9
  type OperationKeyOptions<TType extends OperationType, TInput> = {
23
10
  type?: TType;
24
11
  input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
@@ -32,22 +19,28 @@ interface OperationContext {
32
19
  type: OperationType;
33
20
  };
34
21
  }
35
- type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
22
+ type QueryKeyOptions<TInput> = (undefined extends TInput ? {
36
23
  input?: TInput | SkipToken;
37
24
  } : {
38
25
  input: TInput | SkipToken;
39
- }) & (Record<never, never> extends TClientContext ? {
26
+ }) & {
27
+ queryKey?: QueryKey;
28
+ };
29
+ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryKeyOptions<TInput> & (Record<never, never> extends TClientContext ? {
40
30
  context?: TClientContext;
41
31
  } : {
42
32
  context: TClientContext;
43
- }) & SetOptional<QueryObserverOptions<TOutput, TError, TSelectData>, 'queryKey'>;
33
+ }) & Omit<QueryObserverOptions<TOutput, TError, TSelectData>, 'queryKey'>;
44
34
  interface QueryOptionsBase<TOutput, TError> {
45
- queryKey: QueryKey;
35
+ queryKey: DataTag<QueryKey, TOutput, TError>;
46
36
  queryFn: QueryFunction<TOutput>;
47
37
  throwOnError?: (error: TError) => boolean;
48
38
  retryDelay?: (count: number, error: TError) => number;
49
- enabled: boolean;
39
+ enabled?: boolean;
50
40
  }
41
+ type experimental_StreamedKeyOptions<TInput> = QueryKeyOptions<TInput> & {
42
+ queryFnOptions?: experimental_StreamedQueryOptions;
43
+ };
51
44
  type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & {
52
45
  queryFnOptions?: experimental_StreamedQueryOptions;
53
46
  };
@@ -61,12 +54,12 @@ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
61
54
  context: TClientContext;
62
55
  }) & SetOptional<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey'>;
63
56
  interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
64
- queryKey: QueryKey;
57
+ queryKey: DataTag<QueryKey, InfiniteData<TOutput, TPageParam>, TError>;
65
58
  queryFn: QueryFunction<TOutput, QueryKey, TPageParam>;
66
59
  select?(): InfiniteData<TOutput, TPageParam>;
67
60
  throwOnError?: (error: TError) => boolean;
68
61
  retryDelay?: (count: number, error: TError) => number;
69
- enabled: boolean;
62
+ enabled?: boolean;
70
63
  }
71
64
  type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
72
65
  context?: TClientContext;
@@ -75,38 +68,90 @@ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
75
68
  }) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
76
69
  type MutationOptions<TInput, TOutput, TError, TMutationContext> = MutationObserverOptions<TOutput, TError, TInput, TMutationContext>;
77
70
 
71
+ /**
72
+ * Utils at any level (procedure or router)
73
+ */
74
+ interface GeneralUtils<TInput> {
75
+ /**
76
+ * Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
77
+ *
78
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
79
+ */
80
+ key<TType extends OperationType>(options?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
81
+ }
82
+ declare function createGeneralUtils<TInput>(path: readonly string[]): GeneralUtils<TInput>;
83
+
78
84
  declare function generateOperationKey<TType extends OperationType, TInput>(path: readonly string[], state?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
79
85
 
80
86
  interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
81
87
  /**
82
88
  * Calling corresponding procedure client
83
89
  *
84
- * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
90
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#calling-clients Tanstack Calling Procedure Client Docs}
85
91
  */
86
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>;
87
99
  /**
88
100
  * Generate options used for useQuery/useSuspenseQuery/prefetchQuery/...
89
101
  *
90
- * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-options-utility Tanstack Query Options Utility Docs}
102
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-options Tanstack Query Options Utility Docs}
91
103
  */
92
104
  queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
93
105
  /**
94
- * Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/useSuspenseQuery/prefetchQuery/...
95
- * 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).
96
107
  *
97
- * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
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}
98
117
  */
99
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>;
100
139
  /**
101
140
  * Generate options used for useInfiniteQuery/useSuspenseInfiniteQuery/prefetchInfiniteQuery/...
102
141
  *
103
- * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
142
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#infinite-query-options Tanstack Infinite Query Options Utility Docs}
104
143
  */
105
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>;
106
151
  /**
107
152
  * Generate options used for useMutation/...
108
153
  *
109
- * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#mutation-options Tanstack Mutation Options Docs}
154
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#mutation-options Tanstack Mutation Options Docs}
110
155
  */
111
156
  mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptions<TInput, TOutput, TError, UMutationContext>>;
112
157
  }
@@ -130,4 +175,4 @@ interface CreateRouterUtilsOptions {
130
175
  declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
131
176
 
132
177
  export { OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createGeneralUtils, createProcedureUtils, createRouterUtils, createRouterUtils as createTanstackQueryUtils, generateOperationKey };
133
- 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,24 +1,11 @@
1
- import { OperationType as OperationType$1, OperationKeyOptions as OperationKeyOptions$1, OperationKey as OperationKey$1 } from '@orpc/tanstack-query';
2
1
  import { ClientContext, Client, NestedClient } from '@orpc/client';
3
2
  import { SetOptional, PartialDeep, MaybeOptionalOptions } from '@orpc/shared';
4
- import { SkipToken, QueryObserverOptions, QueryKey, QueryFunction, experimental_streamedQuery, InfiniteQueryObserverOptions, InfiniteData, MutationObserverOptions } from '@tanstack/query-core';
5
-
6
- /**
7
- * Utils at any level (procedure or router)
8
- */
9
- interface GeneralUtils<TInput> {
10
- /**
11
- * Generate a query/mutation key for checking status, invalidate, set, get, etc.
12
- *
13
- * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
14
- */
15
- key<TType extends OperationType$1>(options?: OperationKeyOptions$1<TType, TInput>): OperationKey$1<TType, TInput>;
16
- }
17
- declare function createGeneralUtils<TInput>(path: readonly string[]): GeneralUtils<TInput>;
3
+ import { SkipToken, QueryKey, QueryObserverOptions, DataTag, QueryFunction, experimental_streamedQuery, InfiniteQueryObserverOptions, InfiniteData, MutationObserverOptions } from '@tanstack/query-core';
18
4
 
19
5
  type experimental_StreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
6
+ type experimental_LiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
20
7
  type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
21
- type OperationType = 'query' | 'streamed' | 'infinite' | 'mutation';
8
+ type OperationType = 'query' | 'streamed' | 'live' | 'infinite' | 'mutation';
22
9
  type OperationKeyOptions<TType extends OperationType, TInput> = {
23
10
  type?: TType;
24
11
  input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
@@ -32,22 +19,28 @@ interface OperationContext {
32
19
  type: OperationType;
33
20
  };
34
21
  }
35
- type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
22
+ type QueryKeyOptions<TInput> = (undefined extends TInput ? {
36
23
  input?: TInput | SkipToken;
37
24
  } : {
38
25
  input: TInput | SkipToken;
39
- }) & (Record<never, never> extends TClientContext ? {
26
+ }) & {
27
+ queryKey?: QueryKey;
28
+ };
29
+ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryKeyOptions<TInput> & (Record<never, never> extends TClientContext ? {
40
30
  context?: TClientContext;
41
31
  } : {
42
32
  context: TClientContext;
43
- }) & SetOptional<QueryObserverOptions<TOutput, TError, TSelectData>, 'queryKey'>;
33
+ }) & Omit<QueryObserverOptions<TOutput, TError, TSelectData>, 'queryKey'>;
44
34
  interface QueryOptionsBase<TOutput, TError> {
45
- queryKey: QueryKey;
35
+ queryKey: DataTag<QueryKey, TOutput, TError>;
46
36
  queryFn: QueryFunction<TOutput>;
47
37
  throwOnError?: (error: TError) => boolean;
48
38
  retryDelay?: (count: number, error: TError) => number;
49
- enabled: boolean;
39
+ enabled?: boolean;
50
40
  }
41
+ type experimental_StreamedKeyOptions<TInput> = QueryKeyOptions<TInput> & {
42
+ queryFnOptions?: experimental_StreamedQueryOptions;
43
+ };
51
44
  type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & {
52
45
  queryFnOptions?: experimental_StreamedQueryOptions;
53
46
  };
@@ -61,12 +54,12 @@ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
61
54
  context: TClientContext;
62
55
  }) & SetOptional<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey'>;
63
56
  interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
64
- queryKey: QueryKey;
57
+ queryKey: DataTag<QueryKey, InfiniteData<TOutput, TPageParam>, TError>;
65
58
  queryFn: QueryFunction<TOutput, QueryKey, TPageParam>;
66
59
  select?(): InfiniteData<TOutput, TPageParam>;
67
60
  throwOnError?: (error: TError) => boolean;
68
61
  retryDelay?: (count: number, error: TError) => number;
69
- enabled: boolean;
62
+ enabled?: boolean;
70
63
  }
71
64
  type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
72
65
  context?: TClientContext;
@@ -75,38 +68,90 @@ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
75
68
  }) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
76
69
  type MutationOptions<TInput, TOutput, TError, TMutationContext> = MutationObserverOptions<TOutput, TError, TInput, TMutationContext>;
77
70
 
71
+ /**
72
+ * Utils at any level (procedure or router)
73
+ */
74
+ interface GeneralUtils<TInput> {
75
+ /**
76
+ * Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
77
+ *
78
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
79
+ */
80
+ key<TType extends OperationType>(options?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
81
+ }
82
+ declare function createGeneralUtils<TInput>(path: readonly string[]): GeneralUtils<TInput>;
83
+
78
84
  declare function generateOperationKey<TType extends OperationType, TInput>(path: readonly string[], state?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
79
85
 
80
86
  interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
81
87
  /**
82
88
  * Calling corresponding procedure client
83
89
  *
84
- * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
90
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#calling-clients Tanstack Calling Procedure Client Docs}
85
91
  */
86
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>;
87
99
  /**
88
100
  * Generate options used for useQuery/useSuspenseQuery/prefetchQuery/...
89
101
  *
90
- * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-options-utility Tanstack Query Options Utility Docs}
102
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-options Tanstack Query Options Utility Docs}
91
103
  */
92
104
  queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
93
105
  /**
94
- * Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/useSuspenseQuery/prefetchQuery/...
95
- * 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).
96
107
  *
97
- * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
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}
98
117
  */
99
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>;
100
139
  /**
101
140
  * Generate options used for useInfiniteQuery/useSuspenseInfiniteQuery/prefetchInfiniteQuery/...
102
141
  *
103
- * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
142
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#infinite-query-options Tanstack Infinite Query Options Utility Docs}
104
143
  */
105
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>;
106
151
  /**
107
152
  * Generate options used for useMutation/...
108
153
  *
109
- * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#mutation-options Tanstack Mutation Options Docs}
154
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#mutation-options Tanstack Mutation Options Docs}
110
155
  */
111
156
  mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptions<TInput, TOutput, TError, UMutationContext>>;
112
157
  }
@@ -130,4 +175,4 @@ interface CreateRouterUtilsOptions {
130
175
  declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
131
176
 
132
177
  export { OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createGeneralUtils, createProcedureUtils, createRouterUtils, createRouterUtils as createTanstackQueryUtils, generateOperationKey };
133
- 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,30 +1,53 @@
1
- import { generateOperationKey as generateOperationKey$1 } from '@orpc/tanstack-query';
2
- import { isAsyncIteratorObject, toArray } from '@orpc/shared';
1
+ import { stringifyJSON, isAsyncIteratorObject, toArray } from '@orpc/shared';
3
2
  import { skipToken, experimental_streamedQuery } from '@tanstack/query-core';
4
3
 
4
+ function generateOperationKey(path, state = {}) {
5
+ return [path, {
6
+ ...state.input !== void 0 ? { input: state.input } : {},
7
+ ...state.type !== void 0 ? { type: state.type } : {},
8
+ ...state.fnOptions !== void 0 ? { fnOptions: state.fnOptions } : {}
9
+ }];
10
+ }
11
+
5
12
  function createGeneralUtils(path) {
6
13
  return {
7
14
  key(options) {
8
- return generateOperationKey$1(path, options);
15
+ return generateOperationKey(path, options);
9
16
  }
10
17
  };
11
18
  }
12
19
 
13
- function generateOperationKey(path, state = {}) {
14
- return [path, {
15
- ...state.input !== void 0 ? { input: state.input } : {},
16
- ...state.type !== void 0 ? { type: state.type } : {},
17
- ...state.fnOptions !== void 0 ? { fnOptions: state.fnOptions } : {}
18
- }];
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
+ };
19
38
  }
20
39
 
21
40
  const OPERATION_CONTEXT_SYMBOL = Symbol("ORPC_OPERATION_CONTEXT");
22
41
 
23
42
  function createProcedureUtils(client, options) {
24
- return {
43
+ const utils = {
25
44
  call: client,
26
- queryOptions(...[optionsIn = {}]) {
45
+ queryKey(...[optionsIn = {}]) {
27
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);
28
51
  return {
29
52
  queryFn: ({ signal }) => {
30
53
  if (optionsIn.input === skipToken) {
@@ -41,15 +64,18 @@ function createProcedureUtils(client, options) {
41
64
  }
42
65
  });
43
66
  },
44
- enabled: optionsIn.input !== skipToken,
67
+ ...optionsIn.input === skipToken ? { enabled: false } : {},
45
68
  ...optionsIn,
46
69
  queryKey
47
70
  };
48
71
  },
49
- experimental_streamedOptions(...[optionsIn = {}]) {
72
+ experimental_streamedKey(...[optionsIn = {}]) {
50
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);
51
78
  return {
52
- enabled: optionsIn.input !== skipToken,
53
79
  queryFn: experimental_streamedQuery({
54
80
  queryFn: async ({ signal }) => {
55
81
  if (optionsIn.input === skipToken) {
@@ -72,15 +98,51 @@ function createProcedureUtils(client, options) {
72
98
  },
73
99
  ...optionsIn.queryFnOptions
74
100
  }),
101
+ ...optionsIn.input === skipToken ? { enabled: false } : {},
75
102
  ...optionsIn,
76
103
  queryKey
77
104
  };
78
105
  },
79
- infiniteOptions(optionsIn) {
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) {
80
138
  const queryKey = optionsIn.queryKey ?? generateOperationKey(options.path, {
81
139
  type: "infinite",
82
140
  input: optionsIn.input === skipToken ? skipToken : optionsIn.input(optionsIn.initialPageParam)
83
141
  });
142
+ return queryKey;
143
+ },
144
+ infiniteOptions(optionsIn) {
145
+ const queryKey = utils.infiniteKey(optionsIn);
84
146
  return {
85
147
  queryFn: ({ pageParam, signal }) => {
86
148
  if (optionsIn.input === skipToken) {
@@ -97,13 +159,17 @@ function createProcedureUtils(client, options) {
97
159
  }
98
160
  });
99
161
  },
100
- enabled: optionsIn.input !== skipToken,
162
+ ...optionsIn.input === skipToken ? { enabled: false } : {},
101
163
  ...optionsIn,
102
164
  queryKey
103
165
  };
104
166
  },
105
- mutationOptions(...[optionsIn = {}]) {
167
+ mutationKey(...[optionsIn = {}]) {
106
168
  const mutationKey = optionsIn.mutationKey ?? generateOperationKey(options.path, { type: "mutation" });
169
+ return mutationKey;
170
+ },
171
+ mutationOptions(...[optionsIn = {}]) {
172
+ const mutationKey = utils.mutationKey(optionsIn);
107
173
  return {
108
174
  mutationFn: (input) => client(input, {
109
175
  context: {
@@ -119,6 +185,7 @@ function createProcedureUtils(client, options) {
119
185
  };
120
186
  }
121
187
  };
188
+ return utils;
122
189
  }
123
190
 
124
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.dd4e882",
4
+ "version": "0.0.0-next.dd705fc",
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.dd4e882"
28
+ "@orpc/client": "0.0.0-next.dd705fc"
29
29
  },
30
30
  "dependencies": {
31
- "@orpc/shared": "0.0.0-next.dd4e882"
31
+ "@orpc/shared": "0.0.0-next.dd705fc"
32
32
  },
33
33
  "devDependencies": {
34
- "@angular/core": "^20.0.0",
35
- "@tanstack/angular-query-experimental": "^5.80.2",
36
- "@tanstack/query-core": "^5.80.2",
37
- "@tanstack/react-query": "^5.80.5",
38
- "@tanstack/solid-query": "^5.80.2",
39
- "@tanstack/svelte-query": "^5.80.2",
40
- "@tanstack/vue-query": "^5.80.2",
41
- "svelte": "^5.26.2",
42
- "vue": "^3.5.16",
43
- "zod": "^3.25.49"
34
+ "@angular/core": "^20.2.3",
35
+ "@tanstack/angular-query-experimental": "^5.85.9",
36
+ "@tanstack/query-core": "^5.85.9",
37
+ "@tanstack/react-query": "^5.85.9",
38
+ "@tanstack/solid-query": "^5.85.9",
39
+ "@tanstack/svelte-query": "^5.85.9",
40
+ "@tanstack/vue-query": "^5.85.9",
41
+ "svelte": "^5.38.6",
42
+ "vue": "^3.5.21",
43
+ "zod": "^4.1.5"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "unbuild",