@orpc/tanstack-query 1.6.2 → 1.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +20 -4
- package/dist/index.d.ts +20 -4
- package/dist/index.mjs +52 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -3,8 +3,9 @@ import { SetOptional, PartialDeep, MaybeOptionalOptions } from '@orpc/shared';
|
|
|
3
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>;
|
|
@@ -108,12 +109,27 @@ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput,
|
|
|
108
109
|
*/
|
|
109
110
|
experimental_streamedKey(...rest: MaybeOptionalOptions<experimental_StreamedKeyOptions<TInput>>): DataTag<QueryKey, experimental_StreamedQueryOutput<TOutput>, TError>;
|
|
110
111
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
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`.
|
|
113
115
|
*
|
|
114
116
|
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#streamed-query-options Tanstack Streamed Query Options Utility Docs}
|
|
115
117
|
*/
|
|
116
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>>;
|
|
117
133
|
/**
|
|
118
134
|
* Generate a **full matching** key for [Infinite Query Options](https://orpc.unnoq.com/docs/integrations/tanstack-query#infinite-query-options).
|
|
119
135
|
*
|
|
@@ -159,4 +175,4 @@ interface CreateRouterUtilsOptions {
|
|
|
159
175
|
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
|
160
176
|
|
|
161
177
|
export { OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createGeneralUtils, createProcedureUtils, createRouterUtils, createRouterUtils as createTanstackQueryUtils, generateOperationKey };
|
|
162
|
-
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, OperationContext, OperationKey, OperationKeyOptions, OperationType, ProcedureUtils, QueryKeyOptions, QueryOptionsBase, QueryOptionsIn, RouterUtils, OperationContext as TanstackQueryOperationContext, experimental_StreamedKeyOptions, 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
|
@@ -3,8 +3,9 @@ import { SetOptional, PartialDeep, MaybeOptionalOptions } from '@orpc/shared';
|
|
|
3
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>;
|
|
@@ -108,12 +109,27 @@ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput,
|
|
|
108
109
|
*/
|
|
109
110
|
experimental_streamedKey(...rest: MaybeOptionalOptions<experimental_StreamedKeyOptions<TInput>>): DataTag<QueryKey, experimental_StreamedQueryOutput<TOutput>, TError>;
|
|
110
111
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
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`.
|
|
113
115
|
*
|
|
114
116
|
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#streamed-query-options Tanstack Streamed Query Options Utility Docs}
|
|
115
117
|
*/
|
|
116
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>>;
|
|
117
133
|
/**
|
|
118
134
|
* Generate a **full matching** key for [Infinite Query Options](https://orpc.unnoq.com/docs/integrations/tanstack-query#infinite-query-options).
|
|
119
135
|
*
|
|
@@ -159,4 +175,4 @@ interface CreateRouterUtilsOptions {
|
|
|
159
175
|
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
|
160
176
|
|
|
161
177
|
export { OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createGeneralUtils, createProcedureUtils, createRouterUtils, createRouterUtils as createTanstackQueryUtils, generateOperationKey };
|
|
162
|
-
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, OperationContext, OperationKey, OperationKeyOptions, OperationType, ProcedureUtils, QueryKeyOptions, QueryOptionsBase, QueryOptionsIn, RouterUtils, OperationContext as TanstackQueryOperationContext, experimental_StreamedKeyOptions, 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,6 +17,26 @@ 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) {
|
|
@@ -83,6 +103,37 @@ function createProcedureUtils(client, options) {
|
|
|
83
103
|
queryKey
|
|
84
104
|
};
|
|
85
105
|
},
|
|
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
|
+
enabled: optionsIn.input !== skipToken,
|
|
114
|
+
queryFn: experimental_liveQuery(async ({ signal }) => {
|
|
115
|
+
if (optionsIn.input === skipToken) {
|
|
116
|
+
throw new Error("queryFn should not be called with skipToken used as input");
|
|
117
|
+
}
|
|
118
|
+
const output = await client(optionsIn.input, {
|
|
119
|
+
signal,
|
|
120
|
+
context: {
|
|
121
|
+
[OPERATION_CONTEXT_SYMBOL]: {
|
|
122
|
+
key: queryKey,
|
|
123
|
+
type: "live"
|
|
124
|
+
},
|
|
125
|
+
...optionsIn.context
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
if (!isAsyncIteratorObject(output)) {
|
|
129
|
+
throw new Error("liveQuery requires an event iterator output");
|
|
130
|
+
}
|
|
131
|
+
return output;
|
|
132
|
+
}),
|
|
133
|
+
...optionsIn,
|
|
134
|
+
queryKey
|
|
135
|
+
};
|
|
136
|
+
},
|
|
86
137
|
infiniteKey(optionsIn) {
|
|
87
138
|
const queryKey = optionsIn.queryKey ?? generateOperationKey(options.path, {
|
|
88
139
|
type: "infinite",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/tanstack-query",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.6.
|
|
4
|
+
"version": "1.6.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
],
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@tanstack/query-core": ">=5.80.2",
|
|
28
|
-
"@orpc/client": "1.6.
|
|
28
|
+
"@orpc/client": "1.6.4"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@orpc/shared": "1.6.
|
|
31
|
+
"@orpc/shared": "1.6.4"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@angular/core": "^20.0.6",
|