@falcondev-oss/trpc-vue-query 0.5.0-rc.9 → 0.5.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/dist/index.cjs +25 -18
- package/dist/index.d.cts +12 -10
- package/dist/index.d.ts +12 -10
- package/dist/index.mjs +21 -16
- package/package.json +40 -31
package/dist/index.cjs
CHANGED
|
@@ -18,11 +18,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
23
|
createTRPCVueQueryClient: () => createTRPCVueQueryClient
|
|
24
24
|
});
|
|
25
|
-
module.exports = __toCommonJS(
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
26
|
var import_vue_query = require("@tanstack/vue-query");
|
|
27
27
|
var import_client = require("@trpc/client");
|
|
28
28
|
var import_server = require("@trpc/server");
|
|
@@ -58,17 +58,21 @@ function createVueQueryProxyDecoration(name, trpc, queryClient) {
|
|
|
58
58
|
if (prop === "query") {
|
|
59
59
|
return trpc.query(joinedPath, firstArg, opts);
|
|
60
60
|
}
|
|
61
|
-
function createQuery(_input, { trpcOptions, queryOptions }) {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
output: await trpc.query(joinedPath, input, {
|
|
61
|
+
function createQuery(_input, { trpcOptions, queryOptions }, { type = "query" } = {}) {
|
|
62
|
+
const queryFn = (0, import_vue.computed)(
|
|
63
|
+
() => (0, import_vue.toValue)(_input) === import_vue_query.skipToken ? import_vue_query.skipToken : async ({ signal }) => {
|
|
64
|
+
const input = (0, import_vue.toValue)(_input);
|
|
65
|
+
const output = await trpc.query(joinedPath, input, {
|
|
67
66
|
signal,
|
|
68
67
|
...trpcOptions
|
|
69
|
-
})
|
|
70
|
-
input
|
|
71
|
-
|
|
68
|
+
});
|
|
69
|
+
if (type === "queries") return { output, input };
|
|
70
|
+
return output;
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
return (0, import_vue_query.queryOptions)({
|
|
74
|
+
queryKey: (0, import_vue.computed)(() => getQueryKey(path, (0, import_vue.toValue)(_input), type)),
|
|
75
|
+
queryFn,
|
|
72
76
|
...maybeToRefs(queryOptions)
|
|
73
77
|
});
|
|
74
78
|
}
|
|
@@ -82,7 +86,9 @@ function createVueQueryProxyDecoration(name, trpc, queryClient) {
|
|
|
82
86
|
const inputs = firstArg;
|
|
83
87
|
return (0, import_vue_query.useQueries)({
|
|
84
88
|
queries: (0, import_vue.computed)(
|
|
85
|
-
() => (0,
|
|
89
|
+
() => (0, import_vue.toValue)(inputs).map(
|
|
90
|
+
(i) => createQuery(i, { trpcOptions, queryOptions }, { type: "queries" })
|
|
91
|
+
)
|
|
86
92
|
),
|
|
87
93
|
combine,
|
|
88
94
|
...maybeToRefs({ shallow })
|
|
@@ -90,14 +96,14 @@ function createVueQueryProxyDecoration(name, trpc, queryClient) {
|
|
|
90
96
|
}
|
|
91
97
|
if (prop === "invalidate") {
|
|
92
98
|
return queryClient.invalidateQueries({
|
|
93
|
-
queryKey: getQueryKey(path, (0,
|
|
99
|
+
queryKey: getQueryKey(path, (0, import_vue.toValue)(firstArg), "query")
|
|
94
100
|
});
|
|
95
101
|
}
|
|
96
102
|
if (prop === "setQueryData") {
|
|
97
|
-
return queryClient.setQueryData(getQueryKey(path, (0,
|
|
103
|
+
return queryClient.setQueryData(getQueryKey(path, (0, import_vue.toValue)(opts), "query"), firstArg);
|
|
98
104
|
}
|
|
99
105
|
if (prop === "key") {
|
|
100
|
-
return getQueryKey(path, (0,
|
|
106
|
+
return getQueryKey(path, (0, import_vue.toValue)(firstArg), "query");
|
|
101
107
|
}
|
|
102
108
|
if (prop === "mutate") {
|
|
103
109
|
return trpc.mutation(joinedPath, firstArg, opts);
|
|
@@ -121,6 +127,7 @@ function createVueQueryProxyDecoration(name, trpc, queryClient) {
|
|
|
121
127
|
(0, import_vue.watch)(
|
|
122
128
|
inputData,
|
|
123
129
|
() => {
|
|
130
|
+
if (inputData.value === import_vue_query.skipToken) return;
|
|
124
131
|
subscription.value?.unsubscribe();
|
|
125
132
|
subscription.value = trpc.subscription(joinedPath, inputData.value, {
|
|
126
133
|
...opts
|
|
@@ -136,7 +143,7 @@ function createVueQueryProxyDecoration(name, trpc, queryClient) {
|
|
|
136
143
|
if (prop === "useInfiniteQuery") {
|
|
137
144
|
const { trpc: trpcOptions, ...queryOptions } = opts;
|
|
138
145
|
return (0, import_vue_query.useInfiniteQuery)({
|
|
139
|
-
queryKey: (0, import_vue.computed)(() => getQueryKey(path, (0,
|
|
146
|
+
queryKey: (0, import_vue.computed)(() => getQueryKey(path, (0, import_vue.toValue)(firstArg), "infinite")),
|
|
140
147
|
queryFn: async ({ queryKey, pageParam, signal }) => trpc.query(
|
|
141
148
|
joinedPath,
|
|
142
149
|
{
|
|
@@ -160,7 +167,7 @@ function createTRPCVueQueryClient({
|
|
|
160
167
|
}) {
|
|
161
168
|
const client = (0, import_client.createTRPCUntypedClient)(trpc);
|
|
162
169
|
const decoratedClient = (0, import_server.createTRPCFlatProxy)((key) => {
|
|
163
|
-
return createVueQueryProxyDecoration(key, client, queryClient);
|
|
170
|
+
return createVueQueryProxyDecoration(key.toString(), client, queryClient);
|
|
164
171
|
});
|
|
165
172
|
return decoratedClient;
|
|
166
173
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { QueryKey, UseQueryOptions, UseQueryReturnType, UseQueriesResults, QueryClient, InfiniteData, UseInfiniteQueryOptions, InitialPageParam, UseInfiniteQueryReturnType, UseMutationOptions, UseMutationReturnType } from '@tanstack/vue-query';
|
|
1
|
+
import { QueryKey, SkipToken, UseQueryOptions, UseQueryReturnType, UseQueriesResults, QueryClient, InfiniteData, UseInfiniteQueryOptions, InitialPageParam, UseInfiniteQueryReturnType, UseMutationOptions, UseMutationReturnType } from '@tanstack/vue-query';
|
|
2
2
|
import { TRPCClientErrorLike, TRPCRequestOptions, OperationContext, CreateTRPCClientOptions } from '@trpc/client';
|
|
3
3
|
import { AnyTRPCRouter, AnyTRPCProcedure, AnyTRPCQueryProcedure, inferTransformedProcedureOutput, inferProcedureInput, AnyTRPCMutationProcedure, AnyTRPCSubscriptionProcedure, inferProcedureOutput } from '@trpc/server';
|
|
4
4
|
import { Unsubscribable } from '@trpc/server/observable';
|
|
5
|
-
import {
|
|
6
|
-
import { MaybeRefOrGetter, UnwrapRef, Ref } from 'vue';
|
|
5
|
+
import { Ref, MaybeRefOrGetter, UnwrapRef } from 'vue';
|
|
7
6
|
|
|
8
7
|
type inferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : T;
|
|
9
8
|
type TRPCSubscriptionObserver<TValue, TError> = {
|
|
@@ -21,17 +20,20 @@ type Exact<Shape, T extends Shape> = Shape extends Primitive ? Shape : Shape ext
|
|
|
21
20
|
[Key in keyof T]: Key extends keyof Shape ? T[Key] extends Date ? T[Key] : T[Key] extends unknown[] ? Array<Exact<ArrayElement<Shape[Key]>, ArrayElement<T[Key]>>> : T[Key] extends readonly unknown[] ? ReadonlyArray<Exact<ArrayElement<Shape[Key]>, ArrayElement<T[Key]>>> : T[Key] extends object ? Exact<Shape[Key], T[Key]> : T[Key] : never;
|
|
22
21
|
} : Shape;
|
|
23
22
|
type DecorateProcedure<TProcedure extends AnyTRPCProcedure, TRouter extends AnyTRPCRouter> = TProcedure extends AnyTRPCQueryProcedure ? {
|
|
24
|
-
useQuery: <TQueryFnData extends inferTransformedProcedureOutput<TRouter, TProcedure>, TError extends TRPCClientErrorLike<TRouter>, TData extends TQueryFnData, TQueryData extends TQueryFnData, TQueryKey extends QueryKey, TInput extends inferProcedureInput<TProcedure>>(input:
|
|
23
|
+
useQuery: <TQueryFnData extends inferTransformedProcedureOutput<TRouter, TProcedure>, TError extends TRPCClientErrorLike<TRouter>, TData extends TQueryFnData, TQueryData extends TQueryFnData, TQueryKey extends QueryKey, TInput extends inferProcedureInput<TProcedure>>(input: inferProcedureInput<TProcedure> extends void ? inferProcedureInput<TProcedure> : Ref<Exact<inferProcedureInput<TProcedure>, TInput> | SkipToken> | (() => Exact<inferProcedureInput<TProcedure>, TInput> | SkipToken), opts?: MaybeRefOrGetter<Omit<UnwrapRef<UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>>, 'queryKey'> & {
|
|
25
24
|
trpc?: TRPCRequestOptions;
|
|
26
25
|
queryKey?: TQueryKey;
|
|
27
26
|
}>) => UseQueryReturnType<TData, TError>;
|
|
28
|
-
useQueries: <TQueryFnData extends
|
|
27
|
+
useQueries: <TQueryFnData extends {
|
|
28
|
+
output: inferTransformedProcedureOutput<TRouter, TProcedure>;
|
|
29
|
+
input: inferProcedureInput<TProcedure>;
|
|
30
|
+
}, TError extends TRPCClientErrorLike<TRouter>, TData extends TQueryFnData, TQueryData extends TQueryFnData, TQueryKey extends QueryKey, TInput extends inferProcedureInput<TProcedure>, TQueries extends UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, TCombinedResult = UseQueriesResults<TQueries[]>>(inputs: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>[]>, opts?: MaybeRefOrGetter<Omit<UnwrapRef<TQueries>, 'queryKey'> & {
|
|
29
31
|
trpc?: TRPCRequestOptions;
|
|
30
32
|
queryKey?: never;
|
|
31
33
|
combine?: (result: UseQueriesResults<TQueries[]>) => TCombinedResult;
|
|
32
34
|
shallow?: boolean;
|
|
33
35
|
}>) => Readonly<Ref<TCombinedResult>>;
|
|
34
|
-
query: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts?:
|
|
36
|
+
query: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts?: TRPCRequestOptions) => Promise<inferTransformedProcedureOutput<TRouter, TProcedure>>;
|
|
35
37
|
invalidate: <TInput extends inferProcedureInput<TProcedure>>(input?: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>) => Promise<void>;
|
|
36
38
|
setQueryData: <TInput extends inferProcedureInput<TProcedure>>(updater: inferTransformedProcedureOutput<TRouter, TProcedure>, input?: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>) => ReturnType<QueryClient['setQueryData']>;
|
|
37
39
|
key: <TInput extends inferProcedureInput<TProcedure>>(input?: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>) => QueryKey;
|
|
@@ -43,13 +45,13 @@ type DecorateProcedure<TProcedure extends AnyTRPCProcedure, TRouter extends AnyT
|
|
|
43
45
|
queryKey?: TQueryKey;
|
|
44
46
|
} & (undefined extends TProcedure['_def']['$types']['input']['cursor'] ? Partial<InitialPageParam<CursorType>> : InitialPageParam<CursorType>)>) => UseInfiniteQueryReturnType<TData, TError>;
|
|
45
47
|
} : object) : TProcedure extends AnyTRPCMutationProcedure ? {
|
|
46
|
-
mutate: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts?:
|
|
48
|
+
mutate: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts?: TRPCRequestOptions) => Promise<inferTransformedProcedureOutput<TRouter, TProcedure>>;
|
|
47
49
|
useMutation: <TData = inferTransformedProcedureOutput<TRouter, TProcedure>, TError = TRPCClientErrorLike<TRouter>, TVariables = inferProcedureInput<TProcedure>, TContext = unknown>(opts?: MaybeRefOrGetter<UseMutationOptions<TData, TError, TVariables, TContext> & {
|
|
48
50
|
trpc?: TRPCRequestOptions;
|
|
49
51
|
}>) => UseMutationReturnType<TData, TError, TVariables, TContext>;
|
|
50
52
|
} : TProcedure extends AnyTRPCSubscriptionProcedure ? {
|
|
51
|
-
subscribe: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts:
|
|
52
|
-
useSubscription: <TInput extends inferProcedureInput<TProcedure>>(input: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>, opts:
|
|
53
|
+
subscribe: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts: TRPCRequestOptions & Partial<TRPCSubscriptionObserver<inferProcedureOutput<TProcedure>, TRPCClientErrorLike<TRouter>>>) => Unsubscribable;
|
|
54
|
+
useSubscription: <TInput extends inferProcedureInput<TProcedure>>(input: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>, opts: TRPCRequestOptions & Partial<TRPCSubscriptionObserver<inferProcedureOutput<TProcedure>, TRPCClientErrorLike<TRouter>>>) => Unsubscribable;
|
|
53
55
|
} : never;
|
|
54
56
|
/**
|
|
55
57
|
* @internal
|
|
@@ -58,7 +60,7 @@ type DecoratedProcedureRecord<TProcedures extends Record<string, any>, TRouter e
|
|
|
58
60
|
[K in keyof TProcedures]: TProcedures[K] extends AnyTRPCProcedure ? DecorateProcedure<TProcedures[K], TRouter> : DecoratedProcedureRecord<TProcedures[K], TRouter>;
|
|
59
61
|
};
|
|
60
62
|
|
|
61
|
-
type QueryType = 'query' | 'infinite';
|
|
63
|
+
type QueryType = 'query' | 'queries' | 'infinite';
|
|
62
64
|
type TRPCQueryKey = [readonly string[], {
|
|
63
65
|
input?: unknown;
|
|
64
66
|
type?: QueryType;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { QueryKey, UseQueryOptions, UseQueryReturnType, UseQueriesResults, QueryClient, InfiniteData, UseInfiniteQueryOptions, InitialPageParam, UseInfiniteQueryReturnType, UseMutationOptions, UseMutationReturnType } from '@tanstack/vue-query';
|
|
1
|
+
import { QueryKey, SkipToken, UseQueryOptions, UseQueryReturnType, UseQueriesResults, QueryClient, InfiniteData, UseInfiniteQueryOptions, InitialPageParam, UseInfiniteQueryReturnType, UseMutationOptions, UseMutationReturnType } from '@tanstack/vue-query';
|
|
2
2
|
import { TRPCClientErrorLike, TRPCRequestOptions, OperationContext, CreateTRPCClientOptions } from '@trpc/client';
|
|
3
3
|
import { AnyTRPCRouter, AnyTRPCProcedure, AnyTRPCQueryProcedure, inferTransformedProcedureOutput, inferProcedureInput, AnyTRPCMutationProcedure, AnyTRPCSubscriptionProcedure, inferProcedureOutput } from '@trpc/server';
|
|
4
4
|
import { Unsubscribable } from '@trpc/server/observable';
|
|
5
|
-
import {
|
|
6
|
-
import { MaybeRefOrGetter, UnwrapRef, Ref } from 'vue';
|
|
5
|
+
import { Ref, MaybeRefOrGetter, UnwrapRef } from 'vue';
|
|
7
6
|
|
|
8
7
|
type inferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : T;
|
|
9
8
|
type TRPCSubscriptionObserver<TValue, TError> = {
|
|
@@ -21,17 +20,20 @@ type Exact<Shape, T extends Shape> = Shape extends Primitive ? Shape : Shape ext
|
|
|
21
20
|
[Key in keyof T]: Key extends keyof Shape ? T[Key] extends Date ? T[Key] : T[Key] extends unknown[] ? Array<Exact<ArrayElement<Shape[Key]>, ArrayElement<T[Key]>>> : T[Key] extends readonly unknown[] ? ReadonlyArray<Exact<ArrayElement<Shape[Key]>, ArrayElement<T[Key]>>> : T[Key] extends object ? Exact<Shape[Key], T[Key]> : T[Key] : never;
|
|
22
21
|
} : Shape;
|
|
23
22
|
type DecorateProcedure<TProcedure extends AnyTRPCProcedure, TRouter extends AnyTRPCRouter> = TProcedure extends AnyTRPCQueryProcedure ? {
|
|
24
|
-
useQuery: <TQueryFnData extends inferTransformedProcedureOutput<TRouter, TProcedure>, TError extends TRPCClientErrorLike<TRouter>, TData extends TQueryFnData, TQueryData extends TQueryFnData, TQueryKey extends QueryKey, TInput extends inferProcedureInput<TProcedure>>(input:
|
|
23
|
+
useQuery: <TQueryFnData extends inferTransformedProcedureOutput<TRouter, TProcedure>, TError extends TRPCClientErrorLike<TRouter>, TData extends TQueryFnData, TQueryData extends TQueryFnData, TQueryKey extends QueryKey, TInput extends inferProcedureInput<TProcedure>>(input: inferProcedureInput<TProcedure> extends void ? inferProcedureInput<TProcedure> : Ref<Exact<inferProcedureInput<TProcedure>, TInput> | SkipToken> | (() => Exact<inferProcedureInput<TProcedure>, TInput> | SkipToken), opts?: MaybeRefOrGetter<Omit<UnwrapRef<UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>>, 'queryKey'> & {
|
|
25
24
|
trpc?: TRPCRequestOptions;
|
|
26
25
|
queryKey?: TQueryKey;
|
|
27
26
|
}>) => UseQueryReturnType<TData, TError>;
|
|
28
|
-
useQueries: <TQueryFnData extends
|
|
27
|
+
useQueries: <TQueryFnData extends {
|
|
28
|
+
output: inferTransformedProcedureOutput<TRouter, TProcedure>;
|
|
29
|
+
input: inferProcedureInput<TProcedure>;
|
|
30
|
+
}, TError extends TRPCClientErrorLike<TRouter>, TData extends TQueryFnData, TQueryData extends TQueryFnData, TQueryKey extends QueryKey, TInput extends inferProcedureInput<TProcedure>, TQueries extends UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, TCombinedResult = UseQueriesResults<TQueries[]>>(inputs: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>[]>, opts?: MaybeRefOrGetter<Omit<UnwrapRef<TQueries>, 'queryKey'> & {
|
|
29
31
|
trpc?: TRPCRequestOptions;
|
|
30
32
|
queryKey?: never;
|
|
31
33
|
combine?: (result: UseQueriesResults<TQueries[]>) => TCombinedResult;
|
|
32
34
|
shallow?: boolean;
|
|
33
35
|
}>) => Readonly<Ref<TCombinedResult>>;
|
|
34
|
-
query: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts?:
|
|
36
|
+
query: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts?: TRPCRequestOptions) => Promise<inferTransformedProcedureOutput<TRouter, TProcedure>>;
|
|
35
37
|
invalidate: <TInput extends inferProcedureInput<TProcedure>>(input?: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>) => Promise<void>;
|
|
36
38
|
setQueryData: <TInput extends inferProcedureInput<TProcedure>>(updater: inferTransformedProcedureOutput<TRouter, TProcedure>, input?: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>) => ReturnType<QueryClient['setQueryData']>;
|
|
37
39
|
key: <TInput extends inferProcedureInput<TProcedure>>(input?: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>) => QueryKey;
|
|
@@ -43,13 +45,13 @@ type DecorateProcedure<TProcedure extends AnyTRPCProcedure, TRouter extends AnyT
|
|
|
43
45
|
queryKey?: TQueryKey;
|
|
44
46
|
} & (undefined extends TProcedure['_def']['$types']['input']['cursor'] ? Partial<InitialPageParam<CursorType>> : InitialPageParam<CursorType>)>) => UseInfiniteQueryReturnType<TData, TError>;
|
|
45
47
|
} : object) : TProcedure extends AnyTRPCMutationProcedure ? {
|
|
46
|
-
mutate: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts?:
|
|
48
|
+
mutate: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts?: TRPCRequestOptions) => Promise<inferTransformedProcedureOutput<TRouter, TProcedure>>;
|
|
47
49
|
useMutation: <TData = inferTransformedProcedureOutput<TRouter, TProcedure>, TError = TRPCClientErrorLike<TRouter>, TVariables = inferProcedureInput<TProcedure>, TContext = unknown>(opts?: MaybeRefOrGetter<UseMutationOptions<TData, TError, TVariables, TContext> & {
|
|
48
50
|
trpc?: TRPCRequestOptions;
|
|
49
51
|
}>) => UseMutationReturnType<TData, TError, TVariables, TContext>;
|
|
50
52
|
} : TProcedure extends AnyTRPCSubscriptionProcedure ? {
|
|
51
|
-
subscribe: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts:
|
|
52
|
-
useSubscription: <TInput extends inferProcedureInput<TProcedure>>(input: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>, opts:
|
|
53
|
+
subscribe: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts: TRPCRequestOptions & Partial<TRPCSubscriptionObserver<inferProcedureOutput<TProcedure>, TRPCClientErrorLike<TRouter>>>) => Unsubscribable;
|
|
54
|
+
useSubscription: <TInput extends inferProcedureInput<TProcedure>>(input: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>, opts: TRPCRequestOptions & Partial<TRPCSubscriptionObserver<inferProcedureOutput<TProcedure>, TRPCClientErrorLike<TRouter>>>) => Unsubscribable;
|
|
53
55
|
} : never;
|
|
54
56
|
/**
|
|
55
57
|
* @internal
|
|
@@ -58,7 +60,7 @@ type DecoratedProcedureRecord<TProcedures extends Record<string, any>, TRouter e
|
|
|
58
60
|
[K in keyof TProcedures]: TProcedures[K] extends AnyTRPCProcedure ? DecorateProcedure<TProcedures[K], TRouter> : DecoratedProcedureRecord<TProcedures[K], TRouter>;
|
|
59
61
|
};
|
|
60
62
|
|
|
61
|
-
type QueryType = 'query' | 'infinite';
|
|
63
|
+
type QueryType = 'query' | 'queries' | 'infinite';
|
|
62
64
|
type TRPCQueryKey = [readonly string[], {
|
|
63
65
|
input?: unknown;
|
|
64
66
|
type?: QueryType;
|
package/dist/index.mjs
CHANGED
|
@@ -7,13 +7,11 @@ import {
|
|
|
7
7
|
useQueries,
|
|
8
8
|
useQuery
|
|
9
9
|
} from "@tanstack/vue-query";
|
|
10
|
-
import {
|
|
11
|
-
createTRPCUntypedClient
|
|
12
|
-
} from "@trpc/client";
|
|
10
|
+
import { createTRPCUntypedClient } from "@trpc/client";
|
|
13
11
|
import { createTRPCFlatProxy } from "@trpc/server";
|
|
14
12
|
import { createRecursiveProxy } from "@trpc/server/unstable-core-do-not-import";
|
|
15
|
-
import { toRef, toRefs
|
|
16
|
-
import { computed, isReactive, onScopeDispose, shallowRef, watch } from "vue";
|
|
13
|
+
import { toRef, toRefs } from "@vueuse/core";
|
|
14
|
+
import { computed, isReactive, onScopeDispose, shallowRef, toValue, watch } from "vue";
|
|
17
15
|
function getQueryKey(path, input, type) {
|
|
18
16
|
const splitPath = path.flatMap((part) => part.split("."));
|
|
19
17
|
if (input === void 0 && !type) {
|
|
@@ -43,17 +41,21 @@ function createVueQueryProxyDecoration(name, trpc, queryClient) {
|
|
|
43
41
|
if (prop === "query") {
|
|
44
42
|
return trpc.query(joinedPath, firstArg, opts);
|
|
45
43
|
}
|
|
46
|
-
function createQuery(_input, { trpcOptions, queryOptions }) {
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
output: await trpc.query(joinedPath, input, {
|
|
44
|
+
function createQuery(_input, { trpcOptions, queryOptions }, { type = "query" } = {}) {
|
|
45
|
+
const queryFn = computed(
|
|
46
|
+
() => toValue(_input) === skipToken ? skipToken : async ({ signal }) => {
|
|
47
|
+
const input = toValue(_input);
|
|
48
|
+
const output = await trpc.query(joinedPath, input, {
|
|
52
49
|
signal,
|
|
53
50
|
...trpcOptions
|
|
54
|
-
})
|
|
55
|
-
input
|
|
56
|
-
|
|
51
|
+
});
|
|
52
|
+
if (type === "queries") return { output, input };
|
|
53
|
+
return output;
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
return defineQueryOptions({
|
|
57
|
+
queryKey: computed(() => getQueryKey(path, toValue(_input), type)),
|
|
58
|
+
queryFn,
|
|
57
59
|
...maybeToRefs(queryOptions)
|
|
58
60
|
});
|
|
59
61
|
}
|
|
@@ -67,7 +69,9 @@ function createVueQueryProxyDecoration(name, trpc, queryClient) {
|
|
|
67
69
|
const inputs = firstArg;
|
|
68
70
|
return useQueries({
|
|
69
71
|
queries: computed(
|
|
70
|
-
() => toValue(inputs).map(
|
|
72
|
+
() => toValue(inputs).map(
|
|
73
|
+
(i) => createQuery(i, { trpcOptions, queryOptions }, { type: "queries" })
|
|
74
|
+
)
|
|
71
75
|
),
|
|
72
76
|
combine,
|
|
73
77
|
...maybeToRefs({ shallow })
|
|
@@ -106,6 +110,7 @@ function createVueQueryProxyDecoration(name, trpc, queryClient) {
|
|
|
106
110
|
watch(
|
|
107
111
|
inputData,
|
|
108
112
|
() => {
|
|
113
|
+
if (inputData.value === skipToken) return;
|
|
109
114
|
subscription.value?.unsubscribe();
|
|
110
115
|
subscription.value = trpc.subscription(joinedPath, inputData.value, {
|
|
111
116
|
...opts
|
|
@@ -145,7 +150,7 @@ function createTRPCVueQueryClient({
|
|
|
145
150
|
}) {
|
|
146
151
|
const client = createTRPCUntypedClient(trpc);
|
|
147
152
|
const decoratedClient = createTRPCFlatProxy((key) => {
|
|
148
|
-
return createVueQueryProxyDecoration(key, client, queryClient);
|
|
153
|
+
return createVueQueryProxyDecoration(key.toString(), client, queryClient);
|
|
149
154
|
});
|
|
150
155
|
return decoratedClient;
|
|
151
156
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@falcondev-oss/trpc-vue-query",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.0
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"description": "A tRPC wrapper around '@tanstack/vue-query'",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:falcondev-oss/trpc-vue-query",
|
|
@@ -15,6 +15,16 @@
|
|
|
15
15
|
"tanstack-query",
|
|
16
16
|
"typescript"
|
|
17
17
|
],
|
|
18
|
+
"exports": {
|
|
19
|
+
"import": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.mjs"
|
|
22
|
+
},
|
|
23
|
+
"require": {
|
|
24
|
+
"types": "./dist/index.d.cts",
|
|
25
|
+
"default": "./dist/index.cjs"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
18
28
|
"main": "dist/index.cjs",
|
|
19
29
|
"module": "dist/index.mjs",
|
|
20
30
|
"types": "dist/index.d.ts",
|
|
@@ -22,45 +32,44 @@
|
|
|
22
32
|
"dist"
|
|
23
33
|
],
|
|
24
34
|
"engines": {
|
|
25
|
-
"node": "
|
|
26
|
-
"pnpm": "
|
|
35
|
+
"node": "22",
|
|
36
|
+
"pnpm": "10"
|
|
27
37
|
},
|
|
28
38
|
"peerDependencies": {
|
|
29
39
|
"@tanstack/vue-query": "^5.22.2",
|
|
30
|
-
"@trpc/client": "
|
|
31
|
-
"@trpc/server": "
|
|
40
|
+
"@trpc/client": "^11",
|
|
41
|
+
"@trpc/server": "^11",
|
|
32
42
|
"vue": "^3.4.19"
|
|
33
43
|
},
|
|
34
44
|
"dependencies": {
|
|
35
|
-
"@vueuse/core": "^
|
|
45
|
+
"@vueuse/core": "^13.0.0"
|
|
36
46
|
},
|
|
37
47
|
"devDependencies": {
|
|
38
|
-
"@commitlint/cli": "^19.
|
|
39
|
-
"@eslint/eslintrc": "^3.1
|
|
40
|
-
"@louishaftmann/commitlint-config": "^4.0
|
|
41
|
-
"@louishaftmann/eslint-config": "^4.0
|
|
42
|
-
"@louishaftmann/lintstaged-config": "^4.0
|
|
43
|
-
"@louishaftmann/prettier-config": "^4.0
|
|
44
|
-
"@tanstack/vue-query": "^5.
|
|
45
|
-
"@trpc/client": "11.0.
|
|
46
|
-
"@trpc/server": "11.0.
|
|
48
|
+
"@commitlint/cli": "^19.8.0",
|
|
49
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
50
|
+
"@louishaftmann/commitlint-config": "^4.2.0",
|
|
51
|
+
"@louishaftmann/eslint-config": "^4.2.0",
|
|
52
|
+
"@louishaftmann/lintstaged-config": "^4.2.0",
|
|
53
|
+
"@louishaftmann/prettier-config": "^4.2.0",
|
|
54
|
+
"@tanstack/vue-query": "^5.71.10",
|
|
55
|
+
"@trpc/client": "11.0.2",
|
|
56
|
+
"@trpc/server": "11.0.2",
|
|
47
57
|
"@types/eslint": "^9.6.1",
|
|
48
|
-
"@types/
|
|
49
|
-
"@
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"zod": "^3.23.8"
|
|
58
|
+
"@types/ws": "^8.18.1",
|
|
59
|
+
"@vitest/ui": "^3.1.1",
|
|
60
|
+
"eslint": "^9.24.0",
|
|
61
|
+
"husky": "^9.1.7",
|
|
62
|
+
"lint-staged": "^15.5.0",
|
|
63
|
+
"prettier": "^3.5.3",
|
|
64
|
+
"start-server-and-test": "^2.0.11",
|
|
65
|
+
"tsup": "^8.4.0",
|
|
66
|
+
"tsx": "^4.19.3",
|
|
67
|
+
"type-fest": "^4.39.1",
|
|
68
|
+
"typescript": "^5.8.3",
|
|
69
|
+
"vitest": "^3.1.1",
|
|
70
|
+
"vue": "^3.5.13",
|
|
71
|
+
"ws": "^8.18.1",
|
|
72
|
+
"zod": "^3.24.2"
|
|
64
73
|
},
|
|
65
74
|
"changelogithub": {
|
|
66
75
|
"extends": "gh:falcondev-it/configs/changelogithub"
|