@orpc/vue-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 +40 -28
- package/dist/index.d.ts +40 -28
- package/dist/index.mjs +48 -17
- package/package.json +8 -5
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/vue-query`
|
64
65
|
|
65
|
-
Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview). Read the [documentation](https://orpc.unnoq.com/docs/tanstack-query/vue) for more information.
|
66
|
+
Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview). Read the [documentation](https://orpc.unnoq.com/docs/integrations/tanstack-query-old/vue) for more information.
|
66
67
|
|
67
68
|
```ts
|
68
69
|
export function Setup() {
|
package/dist/index.d.mts
CHANGED
@@ -1,22 +1,17 @@
|
|
1
1
|
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
2
|
-
import {
|
3
|
-
|
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, QueryObserverOptions, QueryFunctionContext, experimental_streamedQuery, InfiniteQueryObserverOptions, MutationObserverOptions, InfiniteData } from '@tanstack/vue-query';
|
5
|
+
import { AnyFunction, MaybeOptionalOptions } from '@orpc/shared';
|
4
6
|
import { MaybeRef, MaybeRefOrGetter, ComputedRef, Ref } from 'vue';
|
5
7
|
|
6
|
-
type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
|
7
|
-
interface BuildKeyOptions<TType extends KeyType, TInput> {
|
8
|
-
type?: TType;
|
9
|
-
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
10
|
-
}
|
11
|
-
declare function buildKey<TType extends KeyType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
|
12
|
-
|
13
8
|
interface GeneralUtils<TInput> {
|
14
9
|
/**
|
15
10
|
* Generate a query/mutation key for checking status, invalidate, set, get, etc.
|
16
11
|
*
|
17
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
|
12
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
|
18
13
|
*/
|
19
|
-
key<UType extends
|
14
|
+
key<UType extends OperationType>(options?: OperationKeyOptions<UType, TInput>): QueryKey;
|
20
15
|
}
|
21
16
|
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
22
17
|
|
@@ -28,9 +23,9 @@ type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
|
|
28
23
|
[Property in keyof T]: MaybeRefDeep<T[Property]>;
|
29
24
|
} : T>;
|
30
25
|
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
|
31
|
-
input?: MaybeRefDeep<TInput>;
|
26
|
+
input?: MaybeRefDeep<TInput | SkipToken>;
|
32
27
|
} : {
|
33
|
-
input: MaybeRefDeep<TInput>;
|
28
|
+
input: MaybeRefDeep<TInput | SkipToken>;
|
34
29
|
}) & (Record<never, never> extends TClientContext ? {
|
35
30
|
context?: MaybeRefDeep<TClientContext>;
|
36
31
|
} : {
|
@@ -45,25 +40,35 @@ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TErro
|
|
45
40
|
interface QueryOptionsBase<TOutput, TError> {
|
46
41
|
queryKey: ComputedRef<QueryKey>;
|
47
42
|
queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
|
48
|
-
|
43
|
+
throwOnError?(error: TError): boolean;
|
44
|
+
retryDelay?: (count: number, error: TError) => number;
|
45
|
+
enabled: ComputedRef<boolean>;
|
46
|
+
}
|
47
|
+
type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
|
48
|
+
type experimental_InferStreamedOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
49
|
+
type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & {
|
50
|
+
queryFnOptions?: experimental_StreamedQueryOptions;
|
51
|
+
};
|
52
|
+
interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
|
49
53
|
}
|
50
|
-
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = {
|
51
|
-
input: (pageParam: TPageParam) => MaybeRefDeep<TInput>;
|
52
|
-
} & (Record<never, never> extends TClientContext ? {
|
54
|
+
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = (Record<never, never> extends TClientContext ? {
|
53
55
|
context?: MaybeRefDeep<TClientContext>;
|
54
56
|
} : {
|
55
57
|
context: MaybeRefDeep<TClientContext>;
|
56
58
|
}) & {
|
57
|
-
[Property in keyof Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData,
|
59
|
+
[Property in keyof Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey' | 'enabled'>]: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>[Property]>;
|
58
60
|
} & {
|
59
|
-
|
60
|
-
|
61
|
+
input: MaybeRef<((pageParam: TPageParam) => MaybeRefDeep<TInput>) | SkipToken>;
|
62
|
+
enabled?: MaybeRefOrGetter<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>['enabled']>;
|
63
|
+
queryKey?: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>['queryKey']>;
|
61
64
|
shallow?: boolean;
|
62
65
|
};
|
63
66
|
interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
|
64
67
|
queryKey: ComputedRef<QueryKey>;
|
65
68
|
queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
|
66
|
-
|
69
|
+
throwOnError?(error: TError): boolean;
|
70
|
+
retryDelay?: (count: number, error: TError) => number;
|
71
|
+
enabled: ComputedRef<boolean>;
|
67
72
|
}
|
68
73
|
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
69
74
|
context?: TClientContext;
|
@@ -80,25 +85,32 @@ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput,
|
|
80
85
|
/**
|
81
86
|
* Calling corresponding procedure client
|
82
87
|
*
|
83
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
|
88
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
|
84
89
|
*/
|
85
90
|
call: Client<TClientContext, TInput, TOutput, TError>;
|
86
91
|
/**
|
87
92
|
* Generate options used for useQuery/prefetchQuery/...
|
88
93
|
*
|
89
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-options-utility Tanstack Query Options Utility Docs}
|
94
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-options-utility Tanstack Query Options Utility Docs}
|
90
95
|
*/
|
91
96
|
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
97
|
+
/**
|
98
|
+
* Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/prefetchQuery/...
|
99
|
+
* Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
100
|
+
*
|
101
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
|
102
|
+
*/
|
103
|
+
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>>;
|
92
104
|
/**
|
93
105
|
* Generate options used for useInfiniteQuery/prefetchInfiniteQuery/...
|
94
106
|
*
|
95
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
|
107
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
|
96
108
|
*/
|
97
109
|
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>>;
|
98
110
|
/**
|
99
111
|
* Generate options used for useMutation/...
|
100
112
|
*
|
101
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#mutation-options Tanstack Mutation Options Docs}
|
113
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#mutation-options Tanstack Mutation Options Docs}
|
102
114
|
*/
|
103
115
|
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
|
104
116
|
}
|
@@ -117,7 +129,7 @@ interface CreateRouterUtilsOptions {
|
|
117
129
|
* Create a router utils from a client.
|
118
130
|
*
|
119
131
|
* @info Both client-side and server-side clients are supported.
|
120
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/vue Tanstack Query Vue Docs}
|
132
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/vue Tanstack Query Vue Docs}
|
121
133
|
*/
|
122
134
|
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
123
135
|
|
@@ -126,5 +138,5 @@ type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunctio
|
|
126
138
|
} : T;
|
127
139
|
declare function unrefDeep<T>(value: T): UnrefDeep<T>;
|
128
140
|
|
129
|
-
export {
|
130
|
-
export type {
|
141
|
+
export { createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
|
142
|
+
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MaybeRefDeep, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, UnrefDeep, experimental_InferStreamedOutput, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn };
|
package/dist/index.d.ts
CHANGED
@@ -1,22 +1,17 @@
|
|
1
1
|
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
2
|
-
import {
|
3
|
-
|
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, QueryObserverOptions, QueryFunctionContext, experimental_streamedQuery, InfiniteQueryObserverOptions, MutationObserverOptions, InfiniteData } from '@tanstack/vue-query';
|
5
|
+
import { AnyFunction, MaybeOptionalOptions } from '@orpc/shared';
|
4
6
|
import { MaybeRef, MaybeRefOrGetter, ComputedRef, Ref } from 'vue';
|
5
7
|
|
6
|
-
type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
|
7
|
-
interface BuildKeyOptions<TType extends KeyType, TInput> {
|
8
|
-
type?: TType;
|
9
|
-
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
10
|
-
}
|
11
|
-
declare function buildKey<TType extends KeyType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
|
12
|
-
|
13
8
|
interface GeneralUtils<TInput> {
|
14
9
|
/**
|
15
10
|
* Generate a query/mutation key for checking status, invalidate, set, get, etc.
|
16
11
|
*
|
17
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
|
12
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
|
18
13
|
*/
|
19
|
-
key<UType extends
|
14
|
+
key<UType extends OperationType>(options?: OperationKeyOptions<UType, TInput>): QueryKey;
|
20
15
|
}
|
21
16
|
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
22
17
|
|
@@ -28,9 +23,9 @@ type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
|
|
28
23
|
[Property in keyof T]: MaybeRefDeep<T[Property]>;
|
29
24
|
} : T>;
|
30
25
|
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
|
31
|
-
input?: MaybeRefDeep<TInput>;
|
26
|
+
input?: MaybeRefDeep<TInput | SkipToken>;
|
32
27
|
} : {
|
33
|
-
input: MaybeRefDeep<TInput>;
|
28
|
+
input: MaybeRefDeep<TInput | SkipToken>;
|
34
29
|
}) & (Record<never, never> extends TClientContext ? {
|
35
30
|
context?: MaybeRefDeep<TClientContext>;
|
36
31
|
} : {
|
@@ -45,25 +40,35 @@ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TErro
|
|
45
40
|
interface QueryOptionsBase<TOutput, TError> {
|
46
41
|
queryKey: ComputedRef<QueryKey>;
|
47
42
|
queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
|
48
|
-
|
43
|
+
throwOnError?(error: TError): boolean;
|
44
|
+
retryDelay?: (count: number, error: TError) => number;
|
45
|
+
enabled: ComputedRef<boolean>;
|
46
|
+
}
|
47
|
+
type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
|
48
|
+
type experimental_InferStreamedOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
49
|
+
type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & {
|
50
|
+
queryFnOptions?: experimental_StreamedQueryOptions;
|
51
|
+
};
|
52
|
+
interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
|
49
53
|
}
|
50
|
-
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = {
|
51
|
-
input: (pageParam: TPageParam) => MaybeRefDeep<TInput>;
|
52
|
-
} & (Record<never, never> extends TClientContext ? {
|
54
|
+
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = (Record<never, never> extends TClientContext ? {
|
53
55
|
context?: MaybeRefDeep<TClientContext>;
|
54
56
|
} : {
|
55
57
|
context: MaybeRefDeep<TClientContext>;
|
56
58
|
}) & {
|
57
|
-
[Property in keyof Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData,
|
59
|
+
[Property in keyof Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey' | 'enabled'>]: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>[Property]>;
|
58
60
|
} & {
|
59
|
-
|
60
|
-
|
61
|
+
input: MaybeRef<((pageParam: TPageParam) => MaybeRefDeep<TInput>) | SkipToken>;
|
62
|
+
enabled?: MaybeRefOrGetter<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>['enabled']>;
|
63
|
+
queryKey?: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>['queryKey']>;
|
61
64
|
shallow?: boolean;
|
62
65
|
};
|
63
66
|
interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
|
64
67
|
queryKey: ComputedRef<QueryKey>;
|
65
68
|
queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
|
66
|
-
|
69
|
+
throwOnError?(error: TError): boolean;
|
70
|
+
retryDelay?: (count: number, error: TError) => number;
|
71
|
+
enabled: ComputedRef<boolean>;
|
67
72
|
}
|
68
73
|
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
69
74
|
context?: TClientContext;
|
@@ -80,25 +85,32 @@ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput,
|
|
80
85
|
/**
|
81
86
|
* Calling corresponding procedure client
|
82
87
|
*
|
83
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
|
88
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
|
84
89
|
*/
|
85
90
|
call: Client<TClientContext, TInput, TOutput, TError>;
|
86
91
|
/**
|
87
92
|
* Generate options used for useQuery/prefetchQuery/...
|
88
93
|
*
|
89
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-options-utility Tanstack Query Options Utility Docs}
|
94
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-options-utility Tanstack Query Options Utility Docs}
|
90
95
|
*/
|
91
96
|
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
97
|
+
/**
|
98
|
+
* Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/prefetchQuery/...
|
99
|
+
* Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
100
|
+
*
|
101
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
|
102
|
+
*/
|
103
|
+
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>>;
|
92
104
|
/**
|
93
105
|
* Generate options used for useInfiniteQuery/prefetchInfiniteQuery/...
|
94
106
|
*
|
95
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
|
107
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
|
96
108
|
*/
|
97
109
|
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>>;
|
98
110
|
/**
|
99
111
|
* Generate options used for useMutation/...
|
100
112
|
*
|
101
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#mutation-options Tanstack Mutation Options Docs}
|
113
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#mutation-options Tanstack Mutation Options Docs}
|
102
114
|
*/
|
103
115
|
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
|
104
116
|
}
|
@@ -117,7 +129,7 @@ interface CreateRouterUtilsOptions {
|
|
117
129
|
* Create a router utils from a client.
|
118
130
|
*
|
119
131
|
* @info Both client-side and server-side clients are supported.
|
120
|
-
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/vue Tanstack Query Vue Docs}
|
132
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/vue Tanstack Query Vue Docs}
|
121
133
|
*/
|
122
134
|
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
123
135
|
|
@@ -126,5 +138,5 @@ type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunctio
|
|
126
138
|
} : T;
|
127
139
|
declare function unrefDeep<T>(value: T): UnrefDeep<T>;
|
128
140
|
|
129
|
-
export {
|
130
|
-
export type {
|
141
|
+
export { createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
|
142
|
+
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MaybeRefDeep, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, UnrefDeep, experimental_InferStreamedOutput, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn };
|
package/dist/index.mjs
CHANGED
@@ -1,19 +1,13 @@
|
|
1
|
+
import { generateOperationKey } from '@orpc/tanstack-query';
|
2
|
+
export { generateOperationKey as buildKey } from '@orpc/tanstack-query';
|
3
|
+
import { isObject, isAsyncIteratorObject } from '@orpc/shared';
|
4
|
+
import { skipToken, experimental_streamedQuery } from '@tanstack/vue-query';
|
1
5
|
import { isRef, computed } from 'vue';
|
2
|
-
import { isObject } from '@orpc/shared';
|
3
|
-
|
4
|
-
function buildKey(path, options) {
|
5
|
-
const withInput = options?.input !== void 0 ? { input: options?.input } : {};
|
6
|
-
const withType = options?.type !== void 0 ? { type: options?.type } : {};
|
7
|
-
return [path, {
|
8
|
-
...withInput,
|
9
|
-
...withType
|
10
|
-
}];
|
11
|
-
}
|
12
6
|
|
13
7
|
function createGeneralUtils(path) {
|
14
8
|
return {
|
15
9
|
key(options) {
|
16
|
-
return
|
10
|
+
return generateOperationKey(path, options);
|
17
11
|
}
|
18
12
|
};
|
19
13
|
}
|
@@ -39,25 +33,62 @@ function createProcedureUtils(client, options) {
|
|
39
33
|
call: client,
|
40
34
|
queryOptions(...[optionsIn = {}]) {
|
41
35
|
return {
|
42
|
-
queryKey: computed(() =>
|
43
|
-
queryFn: ({ signal }) =>
|
36
|
+
queryKey: computed(() => generateOperationKey(options.path, { type: "query", input: unrefDeep(optionsIn.input) })),
|
37
|
+
queryFn: ({ signal }) => {
|
38
|
+
const input = unrefDeep(optionsIn.input);
|
39
|
+
if (input === skipToken) {
|
40
|
+
throw new Error("queryFn should not be called with skipToken used as input");
|
41
|
+
}
|
42
|
+
return client(input, { signal, context: unrefDeep(optionsIn.context) });
|
43
|
+
},
|
44
|
+
enabled: computed(() => unrefDeep(optionsIn.input) !== skipToken),
|
45
|
+
...optionsIn
|
46
|
+
};
|
47
|
+
},
|
48
|
+
experimental_streamedOptions(...[optionsIn = {}]) {
|
49
|
+
return {
|
50
|
+
enabled: computed(() => unrefDeep(optionsIn.input) !== skipToken),
|
51
|
+
queryKey: computed(() => generateOperationKey(options.path, { type: "streamed", input: unrefDeep(optionsIn.input), fnOptions: optionsIn.queryFnOptions })),
|
52
|
+
queryFn: experimental_streamedQuery({
|
53
|
+
queryFn: async ({ signal }) => {
|
54
|
+
const input = unrefDeep(optionsIn.input);
|
55
|
+
if (input === skipToken) {
|
56
|
+
throw new Error("queryFn should not be called with skipToken used as input");
|
57
|
+
}
|
58
|
+
const output = await client(input, { signal, context: unrefDeep(optionsIn.context) });
|
59
|
+
if (!isAsyncIteratorObject(output)) {
|
60
|
+
throw new Error("streamedQuery requires an event iterator output");
|
61
|
+
}
|
62
|
+
return output;
|
63
|
+
},
|
64
|
+
...optionsIn.queryFnOptions
|
65
|
+
}),
|
44
66
|
...optionsIn
|
45
67
|
};
|
46
68
|
},
|
47
69
|
infiniteOptions(optionsIn) {
|
48
70
|
return {
|
49
71
|
queryKey: computed(() => {
|
50
|
-
|
72
|
+
const input = unrefDeep(optionsIn.input);
|
73
|
+
return generateOperationKey(options.path, {
|
74
|
+
type: "infinite",
|
75
|
+
input: input === skipToken ? skipToken : unrefDeep(input(unrefDeep(optionsIn.initialPageParam)))
|
76
|
+
});
|
51
77
|
}),
|
52
78
|
queryFn: ({ pageParam, signal }) => {
|
53
|
-
|
79
|
+
const input = unrefDeep(optionsIn.input);
|
80
|
+
if (input === skipToken) {
|
81
|
+
throw new Error("queryFn should not be called with skipToken used as input");
|
82
|
+
}
|
83
|
+
return client(unrefDeep(input(pageParam)), { signal, context: unrefDeep(optionsIn.context) });
|
54
84
|
},
|
85
|
+
enabled: computed(() => unrefDeep(optionsIn.input) !== skipToken),
|
55
86
|
...optionsIn
|
56
87
|
};
|
57
88
|
},
|
58
89
|
mutationOptions(...[optionsIn = {}]) {
|
59
90
|
return {
|
60
|
-
mutationKey:
|
91
|
+
mutationKey: generateOperationKey(options.path, { type: "mutation" }),
|
61
92
|
mutationFn: (input) => client(input, { context: unrefDeep(optionsIn.context) }),
|
62
93
|
...optionsIn
|
63
94
|
};
|
@@ -92,4 +123,4 @@ function createRouterUtils(client, options = {}) {
|
|
92
123
|
return recursive;
|
93
124
|
}
|
94
125
|
|
95
|
-
export {
|
126
|
+
export { createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/vue-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,13 +27,16 @@
|
|
27
27
|
"dist"
|
28
28
|
],
|
29
29
|
"peerDependencies": {
|
30
|
-
"@tanstack/vue-query": ">=5.
|
30
|
+
"@tanstack/vue-query": ">=5.80.2",
|
31
31
|
"vue": ">=3.3.0",
|
32
|
-
"@orpc/client": "1.
|
32
|
+
"@orpc/client": "1.4.0"
|
33
33
|
},
|
34
34
|
"dependencies": {
|
35
|
-
"@
|
36
|
-
"@orpc/
|
35
|
+
"@orpc/shared": "1.4.0",
|
36
|
+
"@orpc/tanstack-query": "1.4.0"
|
37
|
+
},
|
38
|
+
"devDependencies": {
|
39
|
+
"@tanstack/vue-query": "^5.80.2"
|
37
40
|
},
|
38
41
|
"scripts": {
|
39
42
|
"build": "unbuild",
|