@falcondev-oss/trpc-vue-query 0.5.4 → 0.7.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 +89 -0
- package/dist/index.cjs +129 -176
- package/dist/index.d.cts +81 -60
- package/dist/index.d.mts +99 -0
- package/dist/index.mjs +124 -155
- package/package.json +39 -33
- package/dist/index.d.ts +0 -78
package/README.md
CHANGED
|
@@ -110,6 +110,95 @@ const { mutate: updateGreeting } = useTRPC().hello.update.useMutation({
|
|
|
110
110
|
</template>
|
|
111
111
|
```
|
|
112
112
|
|
|
113
|
+
### 5. Reactive parameters
|
|
114
|
+
|
|
115
|
+
Input parameters can be refs — the query refetches when they change.
|
|
116
|
+
|
|
117
|
+
```vue
|
|
118
|
+
<script lang="ts" setup>
|
|
119
|
+
const productId = ref(1)
|
|
120
|
+
const { data: product } = useTRPC().product.getById.useQuery(productId)
|
|
121
|
+
</script>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Helpers
|
|
125
|
+
|
|
126
|
+
### `invalidate()`
|
|
127
|
+
|
|
128
|
+
Invalidate and refetch a query.
|
|
129
|
+
|
|
130
|
+
```vue
|
|
131
|
+
<script lang="ts" setup>
|
|
132
|
+
const trpc = useTRPC()
|
|
133
|
+
const { mutate: addToCart } = trpc.cart.addProduct.useMutation({
|
|
134
|
+
onSuccess: () => {
|
|
135
|
+
// this will invalidate and refetch the `cart.get` query
|
|
136
|
+
trpc.cart.get.invalidate()
|
|
137
|
+
},
|
|
138
|
+
})
|
|
139
|
+
</script>
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### `setQueryData()`
|
|
143
|
+
|
|
144
|
+
Update the query data manually.
|
|
145
|
+
|
|
146
|
+
```vue
|
|
147
|
+
<script lang="ts" setup>
|
|
148
|
+
const trpc = useTRPC()
|
|
149
|
+
const { mutate: addToCart } = trpc.cart.addProduct.useMutation({
|
|
150
|
+
onSuccess: (newCart) => {
|
|
151
|
+
// this will update the `cart.get` query data
|
|
152
|
+
trpc.cart.get.setQueryData(newCart)
|
|
153
|
+
},
|
|
154
|
+
})
|
|
155
|
+
</script>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### `key()`
|
|
159
|
+
|
|
160
|
+
Get the query key. With the key you can access all the other TanStack Query features.
|
|
161
|
+
|
|
162
|
+
```vue
|
|
163
|
+
<script lang="ts" setup>
|
|
164
|
+
const trpc = useTRPC()
|
|
165
|
+
const cartKey = trpc.cart.get.key()
|
|
166
|
+
|
|
167
|
+
const productKey = trpc.product.getById.key(1)
|
|
168
|
+
|
|
169
|
+
// eg. cancel queries by key:
|
|
170
|
+
const queryClient = useQueryClient()
|
|
171
|
+
await queryClient.cancelQueries({ queryKey: cartKey })
|
|
172
|
+
</script>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Operation context
|
|
176
|
+
|
|
177
|
+
Every request made through a vue-query composable (`useQuery`, `useQueries`, `useInfiniteQuery`, `useMutation`, `queryOptions`) is marked with the exported `vueQueryContext` symbol in the tRPC [operation context](https://trpc.io/docs/client/links#managing-context). Plain `query()` / `mutate()` calls are not.
|
|
178
|
+
|
|
179
|
+
The symbol is declaration-merged into tRPC's `OperationContext` interface, so `op.context[vueQueryContext]` is typed inside links.
|
|
180
|
+
|
|
181
|
+
Links can use this to skip handling that vue-query already does, e.g. error toasts coming from the query/mutation cache:
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
import { vueQueryContext } from '@falcondev-oss/trpc-vue-query'
|
|
185
|
+
|
|
186
|
+
const errorToastLink: TRPCLink<AppRouter> =
|
|
187
|
+
() =>
|
|
188
|
+
({ op, next }) =>
|
|
189
|
+
observable((observer) =>
|
|
190
|
+
next(op).subscribe({
|
|
191
|
+
next: (value) => observer.next(value),
|
|
192
|
+
complete: () => observer.complete(),
|
|
193
|
+
error(err) {
|
|
194
|
+
// vue-query requests are toasted by the query/mutation cache instead
|
|
195
|
+
if (!(vueQueryContext in op.context)) toast.error(err.message)
|
|
196
|
+
observer.error(err)
|
|
197
|
+
},
|
|
198
|
+
}),
|
|
199
|
+
)
|
|
200
|
+
```
|
|
201
|
+
|
|
113
202
|
## Usage with `trpc-nuxt`
|
|
114
203
|
|
|
115
204
|
Setup `trpc-nuxt` as described in their [documentation](https://trpc-nuxt.vercel.app/get-started/usage/recommended). Then update the `plugins/client.ts` file:
|
package/dist/index.cjs
CHANGED
|
@@ -1,182 +1,135 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
createTRPCVueQueryClient: () => createTRPCVueQueryClient
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(index_exports);
|
|
26
|
-
var import_vue_query = require("@tanstack/vue-query");
|
|
27
|
-
var import_client = require("@trpc/client");
|
|
28
|
-
var import_server = require("@trpc/server");
|
|
29
|
-
var import_unstable_core_do_not_import = require("@trpc/server/unstable-core-do-not-import");
|
|
30
|
-
var import_core = require("@vueuse/core");
|
|
31
|
-
var import_vue = require("vue");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _tanstack_vue_query = require("@tanstack/vue-query");
|
|
3
|
+
let _trpc_client = require("@trpc/client");
|
|
4
|
+
let _trpc_server = require("@trpc/server");
|
|
5
|
+
let _trpc_server_unstable_core_do_not_import = require("@trpc/server/unstable-core-do-not-import");
|
|
6
|
+
let _vueuse_core = require("@vueuse/core");
|
|
7
|
+
let vue = require("vue");
|
|
8
|
+
//#region src/index.ts
|
|
32
9
|
function getQueryKey(path, input, type) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
{
|
|
40
|
-
...input !== void 0 && input !== import_vue_query.skipToken && { input },
|
|
41
|
-
...type && { type }
|
|
42
|
-
}
|
|
43
|
-
];
|
|
10
|
+
const splitPath = path.flatMap((part) => part.split("."));
|
|
11
|
+
if (input === void 0 && !type) return splitPath.length > 0 ? [splitPath] : [];
|
|
12
|
+
return [splitPath, {
|
|
13
|
+
...input !== void 0 && input !== _tanstack_vue_query.skipToken && { input },
|
|
14
|
+
...type && { type }
|
|
15
|
+
}];
|
|
44
16
|
}
|
|
45
|
-
|
|
46
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Operation context key marking a request as vue-query-driven.
|
|
19
|
+
* Registered globally via `Symbol.for()`, so it also works across duplicate installs.
|
|
20
|
+
*/
|
|
21
|
+
const vueQueryContext = Symbol.for("trpc-vue-query.vueQueryContext");
|
|
22
|
+
function withVueQueryContext(trpcOptions) {
|
|
23
|
+
return {
|
|
24
|
+
...trpcOptions,
|
|
25
|
+
context: {
|
|
26
|
+
...trpcOptions?.context,
|
|
27
|
+
[vueQueryContext]: {}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function splitTRPCOptions(opts) {
|
|
32
|
+
const { trpc: trpcOptions, ...options } = (0, vue.toValue)(opts) || {};
|
|
33
|
+
return {
|
|
34
|
+
trpcOptions,
|
|
35
|
+
options
|
|
36
|
+
};
|
|
47
37
|
}
|
|
48
38
|
function createVueQueryProxyDecoration(name, trpc, queryClient) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
subscription.value?.unsubscribe();
|
|
137
|
-
subscription.value = trpc.subscription(joinedPath, inputData.value, {
|
|
138
|
-
...opts
|
|
139
|
-
});
|
|
140
|
-
},
|
|
141
|
-
{ immediate: true }
|
|
142
|
-
);
|
|
143
|
-
(0, import_vue.onScopeDispose)(() => {
|
|
144
|
-
subscription.value?.unsubscribe();
|
|
145
|
-
}, true);
|
|
146
|
-
return subscription.value;
|
|
147
|
-
}
|
|
148
|
-
if (prop === "useInfiniteQuery") {
|
|
149
|
-
const { trpc: trpcOptions, ...queryOptions } = opts;
|
|
150
|
-
return (0, import_vue_query.useInfiniteQuery)({
|
|
151
|
-
queryKey: (0, import_vue.computed)(() => getQueryKey(path, (0, import_vue.toValue)(firstArg), "infinite")),
|
|
152
|
-
queryFn: async ({ queryKey, pageParam, signal }) => trpc.query(
|
|
153
|
-
joinedPath,
|
|
154
|
-
{
|
|
155
|
-
...queryKey[1]?.input,
|
|
156
|
-
cursor: pageParam
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
signal,
|
|
160
|
-
...trpcOptions
|
|
161
|
-
}
|
|
162
|
-
),
|
|
163
|
-
...maybeToRefs(queryOptions)
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
throw new Error(`Method '.${prop}()' not supported`);
|
|
167
|
-
});
|
|
39
|
+
return (0, _trpc_server_unstable_core_do_not_import.createRecursiveProxy)(({ args, path: _path }) => {
|
|
40
|
+
const path = [name, ..._path];
|
|
41
|
+
const prop = path.pop();
|
|
42
|
+
if (prop === "_def") return { path };
|
|
43
|
+
const joinedPath = path.join(".");
|
|
44
|
+
const [firstArg, ...rest] = args;
|
|
45
|
+
const opts = rest[0] || {};
|
|
46
|
+
if (prop === "query") return trpc.query(joinedPath, firstArg, opts);
|
|
47
|
+
function createQuery(_input, _opts, { type = "query" } = {}) {
|
|
48
|
+
return (0, _tanstack_vue_query.queryOptions)(() => {
|
|
49
|
+
const input = (0, vue.toValue)(_input);
|
|
50
|
+
const { trpcOptions, options } = splitTRPCOptions(_opts);
|
|
51
|
+
return {
|
|
52
|
+
queryKey: getQueryKey(path, input, type),
|
|
53
|
+
queryFn: input === _tanstack_vue_query.skipToken ? _tanstack_vue_query.skipToken : async ({ signal }) => {
|
|
54
|
+
const output = await trpc.query(joinedPath, input, {
|
|
55
|
+
signal,
|
|
56
|
+
...withVueQueryContext(trpcOptions)
|
|
57
|
+
});
|
|
58
|
+
if (type === "queries") return {
|
|
59
|
+
output,
|
|
60
|
+
input
|
|
61
|
+
};
|
|
62
|
+
return output;
|
|
63
|
+
},
|
|
64
|
+
...options
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (prop === "useQuery") return (0, _tanstack_vue_query.useQuery)(createQuery(firstArg, opts));
|
|
69
|
+
if (prop === "queryOptions") return createQuery(firstArg, opts);
|
|
70
|
+
if (prop === "useQueries") {
|
|
71
|
+
const inputs = firstArg;
|
|
72
|
+
const { combine, shallow } = (0, vue.toValue)(opts) || {};
|
|
73
|
+
const queryOpts = () => {
|
|
74
|
+
const { combine: _, shallow: __, ...perQueryOptions } = (0, vue.toValue)(opts) || {};
|
|
75
|
+
return perQueryOptions;
|
|
76
|
+
};
|
|
77
|
+
return (0, _tanstack_vue_query.useQueries)({
|
|
78
|
+
queries: (0, vue.computed)(() => (0, vue.toValue)(inputs).map((i) => createQuery(i, queryOpts, { type: "queries" })())),
|
|
79
|
+
combine,
|
|
80
|
+
shallow
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (prop === "invalidate") return queryClient.invalidateQueries({ queryKey: getQueryKey(path, (0, vue.toValue)(firstArg), "query") });
|
|
84
|
+
if (prop === "setQueryData") return queryClient.setQueryData(getQueryKey(path, (0, vue.toValue)(opts), "query"), firstArg);
|
|
85
|
+
if (prop === "key") return getQueryKey(path, (0, vue.toValue)(firstArg), "query");
|
|
86
|
+
if (prop === "mutate") return trpc.mutation(joinedPath, firstArg, opts);
|
|
87
|
+
if (prop === "useMutation") return (0, _tanstack_vue_query.useMutation)(() => {
|
|
88
|
+
const { trpcOptions, options } = splitTRPCOptions(firstArg);
|
|
89
|
+
return {
|
|
90
|
+
mutationKey: getQueryKey(path, void 0),
|
|
91
|
+
mutationFn: async (payload) => trpc.mutation(joinedPath, payload, withVueQueryContext(trpcOptions)),
|
|
92
|
+
...options
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
if (prop === "subscribe") return trpc.subscription(joinedPath, firstArg, opts);
|
|
96
|
+
if (prop === "useSubscription") {
|
|
97
|
+
const inputData = (0, _vueuse_core.toRef)(firstArg);
|
|
98
|
+
const subscription = (0, vue.shallowRef)();
|
|
99
|
+
(0, vue.watch)(inputData, () => {
|
|
100
|
+
if (inputData.value === _tanstack_vue_query.skipToken) return;
|
|
101
|
+
subscription.value?.unsubscribe();
|
|
102
|
+
subscription.value = trpc.subscription(joinedPath, inputData.value, { ...opts });
|
|
103
|
+
}, { immediate: true });
|
|
104
|
+
(0, vue.onScopeDispose)(() => {
|
|
105
|
+
subscription.value?.unsubscribe();
|
|
106
|
+
}, true);
|
|
107
|
+
return subscription.value;
|
|
108
|
+
}
|
|
109
|
+
if (prop === "useInfiniteQuery") return (0, _tanstack_vue_query.useInfiniteQuery)(() => {
|
|
110
|
+
const input = (0, vue.toValue)(firstArg);
|
|
111
|
+
const { trpcOptions, options } = splitTRPCOptions(opts);
|
|
112
|
+
return {
|
|
113
|
+
queryKey: getQueryKey(path, input, "infinite"),
|
|
114
|
+
queryFn: async ({ pageParam, signal }) => trpc.query(joinedPath, {
|
|
115
|
+
...input,
|
|
116
|
+
cursor: pageParam
|
|
117
|
+
}, {
|
|
118
|
+
signal,
|
|
119
|
+
...withVueQueryContext(trpcOptions)
|
|
120
|
+
}),
|
|
121
|
+
...options
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
throw new Error(`Method '.${prop}()' not supported`);
|
|
125
|
+
});
|
|
168
126
|
}
|
|
169
|
-
function createTRPCVueQueryClient({
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const decoratedClient = (0, import_server.createTRPCFlatProxy)((key) => {
|
|
175
|
-
return createVueQueryProxyDecoration(key.toString(), client, queryClient);
|
|
176
|
-
});
|
|
177
|
-
return decoratedClient;
|
|
127
|
+
function createTRPCVueQueryClient({ trpc, queryClient }) {
|
|
128
|
+
const client = (0, _trpc_client.createTRPCUntypedClient)(trpc);
|
|
129
|
+
return (0, _trpc_server.createTRPCFlatProxy)((key) => {
|
|
130
|
+
return createVueQueryProxyDecoration(key.toString(), client, queryClient);
|
|
131
|
+
});
|
|
178
132
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
});
|
|
133
|
+
//#endregion
|
|
134
|
+
exports.createTRPCVueQueryClient = createTRPCVueQueryClient;
|
|
135
|
+
exports.vueQueryContext = vueQueryContext;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,78 +1,99 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Unsubscribable } from
|
|
5
|
-
import {
|
|
6
|
-
|
|
1
|
+
import { InfiniteData, InfiniteQueryObserverOptions, InitialPageParam, MutationOptions, QueryClient, QueryKey, QueryOptions, SkipToken, UseInfiniteQueryReturnType, UseMutationReturnType, UseQueriesResults, UseQueryReturnType } from "@tanstack/vue-query";
|
|
2
|
+
import { CreateTRPCClientOptions, OperationContext, TRPCClientErrorLike, TRPCRequestOptions } from "@trpc/client";
|
|
3
|
+
import { AnyTRPCMutationProcedure, AnyTRPCProcedure, AnyTRPCQueryProcedure, AnyTRPCRouter, AnyTRPCSubscriptionProcedure, inferProcedureInput, inferProcedureOutput, inferTransformedProcedureOutput } from "@trpc/server";
|
|
4
|
+
import { Unsubscribable } from "@trpc/server/observable";
|
|
5
|
+
import { MaybeRefOrGetter, Ref } from "vue";
|
|
6
|
+
//#region src/types.d.ts
|
|
7
7
|
type inferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : T;
|
|
8
|
+
/** Not re-exported from vue-query's root, so we restate it. */
|
|
9
|
+
type ShallowOption = {
|
|
10
|
+
shallow?: boolean;
|
|
11
|
+
};
|
|
12
|
+
/** vue-query's plain `QueryOptions` minus the key, which we build from the procedure path. */
|
|
13
|
+
type KeylessQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey> = Omit<QueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, 'queryKey'>;
|
|
14
|
+
/**
|
|
15
|
+
* vue-query has no plain `QueryOptions` counterpart for infinite queries, so we assemble one the
|
|
16
|
+
* same way it does: core observer options, whose `queryKey` is already plain, with `enabled`
|
|
17
|
+
* widened to a ref or getter.
|
|
18
|
+
*/
|
|
19
|
+
type PlainKeyInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey extends QueryKey, TPageParam> = { [Property in keyof InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>]: Property extends 'enabled' ? MaybeRefOrGetter<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>[Property]> : InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>[Property]; } & ShallowOption;
|
|
8
20
|
type TRPCSubscriptionObserver<TValue, TError> = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
onStarted: (opts: {
|
|
22
|
+
context: OperationContext | undefined;
|
|
23
|
+
}) => void;
|
|
24
|
+
onData: (value: inferAsyncIterableYield<TValue>) => void;
|
|
25
|
+
onError: (err: TError) => void;
|
|
26
|
+
onStopped: () => void;
|
|
27
|
+
onComplete: () => void;
|
|
16
28
|
};
|
|
17
29
|
type ArrayElement<T> = T extends readonly unknown[] ? T[number] : never;
|
|
18
30
|
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
19
|
-
type Exact<Shape, T extends Shape> = Shape extends Primitive ? Shape : Shape extends object ? {
|
|
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;
|
|
21
|
-
} : Shape;
|
|
31
|
+
type Exact<Shape, T extends Shape> = Shape extends Primitive ? Shape : Shape extends object ? { [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; } : Shape;
|
|
22
32
|
type DecorateProcedure<TProcedure extends AnyTRPCProcedure, TRouter extends AnyTRPCRouter> = TProcedure extends AnyTRPCQueryProcedure ? {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
useQuery: <TQueryFnData extends inferTransformedProcedureOutput<TRouter, TProcedure>, TError extends TRPCClientErrorLike<TRouter>, TQueryData extends TQueryFnData, TQueryKey extends QueryKey, TInput extends inferProcedureInput<TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure> extends void ? inferProcedureInput<TProcedure> | Ref<inferProcedureInput<TProcedure> | SkipToken> | (() => inferProcedureInput<TProcedure> | SkipToken) : Ref<Exact<inferProcedureInput<TProcedure>, TInput> | SkipToken> | (() => Exact<inferProcedureInput<TProcedure>, TInput> | SkipToken), opts?: MaybeRefOrGetter<KeylessQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> & {
|
|
34
|
+
trpc?: TRPCRequestOptions;
|
|
35
|
+
queryKey?: TQueryKey;
|
|
36
|
+
}>) => UseQueryReturnType<TData, TError>;
|
|
37
|
+
useQueries: <TQueryFnData extends {
|
|
38
|
+
output: inferTransformedProcedureOutput<TRouter, TProcedure>;
|
|
39
|
+
input: inferProcedureInput<TProcedure>;
|
|
40
|
+
}, TError extends TRPCClientErrorLike<TRouter>, TQueryData extends TQueryFnData, TQueryKey extends QueryKey, TInput extends inferProcedureInput<TProcedure>, TQueries extends KeylessQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, TData = TQueryFnData, TCombinedResult = UseQueriesResults<TQueries[]>>(inputs: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>[]>, opts?: MaybeRefOrGetter<TQueries & {
|
|
41
|
+
trpc?: TRPCRequestOptions;
|
|
42
|
+
queryKey?: never;
|
|
43
|
+
combine?: (result: UseQueriesResults<TQueries[]>) => TCombinedResult;
|
|
44
|
+
shallow?: boolean;
|
|
45
|
+
}>) => Readonly<Ref<TCombinedResult>>;
|
|
46
|
+
queryOptions: <TQueryFnData extends inferTransformedProcedureOutput<TRouter, TProcedure>, TError extends TRPCClientErrorLike<TRouter>, TQueryData extends TQueryFnData, TQueryKey extends QueryKey, TInput extends inferProcedureInput<TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure> extends void ? inferProcedureInput<TProcedure> | Ref<inferProcedureInput<TProcedure> | SkipToken> | (() => inferProcedureInput<TProcedure> | SkipToken) : Ref<Exact<inferProcedureInput<TProcedure>, TInput> | SkipToken> | (() => Exact<inferProcedureInput<TProcedure>, TInput> | SkipToken), opts?: MaybeRefOrGetter<KeylessQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> & {
|
|
47
|
+
trpc?: TRPCRequestOptions;
|
|
48
|
+
queryKey?: TQueryKey;
|
|
49
|
+
}>) => () => KeylessQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> & {
|
|
50
|
+
queryKey: TQueryKey;
|
|
51
|
+
};
|
|
52
|
+
query: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts?: TRPCRequestOptions) => Promise<inferTransformedProcedureOutput<TRouter, TProcedure>>;
|
|
53
|
+
invalidate: <TInput extends inferProcedureInput<TProcedure>>(input?: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>) => Promise<void>;
|
|
54
|
+
setQueryData: <TInput extends inferProcedureInput<TProcedure>>(updater: inferTransformedProcedureOutput<TRouter, TProcedure>, input?: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>) => ReturnType<QueryClient['setQueryData']>;
|
|
55
|
+
key: <TInput extends inferProcedureInput<TProcedure>>(input?: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>) => QueryKey;
|
|
44
56
|
} & (TProcedure['_def']['$types']['input'] extends {
|
|
45
|
-
|
|
57
|
+
cursor?: infer CursorType;
|
|
46
58
|
} ? {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
59
|
+
useInfiniteQuery: <TQueryFnData extends inferTransformedProcedureOutput<TRouter, TProcedure>, TError extends TRPCClientErrorLike<TRouter>, TQueryKey extends QueryKey, TInput extends inferProcedureInput<TProcedure>, TData extends InfiniteData<any> = InfiniteData<TQueryFnData>>(input: MaybeRefOrGetter<Exact<Omit<inferProcedureInput<TProcedure>, 'cursor'>, TInput>>, opts?: MaybeRefOrGetter<Omit<PlainKeyInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, CursorType>, 'queryKey' | keyof InitialPageParam> & {
|
|
60
|
+
trpc?: TRPCRequestOptions;
|
|
61
|
+
queryKey?: TQueryKey;
|
|
62
|
+
} & (undefined extends TProcedure['_def']['$types']['input']['cursor'] ? Partial<InitialPageParam<CursorType>> : InitialPageParam<CursorType>)>) => UseInfiniteQueryReturnType<TData, TError>;
|
|
51
63
|
} : object) : TProcedure extends AnyTRPCMutationProcedure ? {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
64
|
+
mutate: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts?: TRPCRequestOptions) => Promise<inferTransformedProcedureOutput<TRouter, TProcedure>>;
|
|
65
|
+
useMutation: <TData = inferTransformedProcedureOutput<TRouter, TProcedure>, TError = TRPCClientErrorLike<TRouter>, TVariables = inferProcedureInput<TProcedure>, TContext = unknown>(opts?: MaybeRefOrGetter<MutationOptions<TData, TError, TVariables, TContext> & {
|
|
66
|
+
trpc?: TRPCRequestOptions;
|
|
67
|
+
}>) => UseMutationReturnType<TData, TError, TVariables, TContext>;
|
|
56
68
|
} : TProcedure extends AnyTRPCSubscriptionProcedure ? {
|
|
57
|
-
|
|
58
|
-
|
|
69
|
+
subscribe: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts: TRPCRequestOptions & Partial<TRPCSubscriptionObserver<inferProcedureOutput<TProcedure>, TRPCClientErrorLike<TRouter>>>) => Unsubscribable;
|
|
70
|
+
useSubscription: <TInput extends inferProcedureInput<TProcedure>>(input: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>, opts: TRPCRequestOptions & Partial<TRPCSubscriptionObserver<inferProcedureOutput<TProcedure>, TRPCClientErrorLike<TRouter>>>) => Unsubscribable;
|
|
59
71
|
} : never;
|
|
60
72
|
/**
|
|
61
73
|
* @internal
|
|
62
74
|
*/
|
|
63
|
-
type DecoratedProcedureRecord<TProcedures extends Record<string, any>, TRouter extends AnyTRPCRouter> = {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
75
|
+
type DecoratedProcedureRecord<TProcedures extends Record<string, any>, TRouter extends AnyTRPCRouter> = { [K in keyof TProcedures]: TProcedures[K] extends AnyTRPCProcedure ? DecorateProcedure<TProcedures[K], TRouter> : DecoratedProcedureRecord<TProcedures[K], TRouter>; };
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/index.d.ts
|
|
67
78
|
type QueryType = 'query' | 'queries' | 'infinite';
|
|
68
79
|
type TRPCQueryKey = [readonly string[], {
|
|
69
|
-
|
|
70
|
-
|
|
80
|
+
input?: unknown;
|
|
81
|
+
type?: QueryType;
|
|
71
82
|
}?];
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Operation context key marking a request as vue-query-driven.
|
|
85
|
+
* Registered globally via `Symbol.for()`, so it also works across duplicate installs.
|
|
86
|
+
*/
|
|
87
|
+
declare const vueQueryContext: unique symbol;
|
|
88
|
+
interface VueQueryContext {}
|
|
89
|
+
declare module '@trpc/client' {
|
|
90
|
+
interface OperationContext {
|
|
91
|
+
[vueQueryContext]?: VueQueryContext;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
declare function createTRPCVueQueryClient<TRouter extends AnyTRPCRouter>({ trpc, queryClient }: {
|
|
95
|
+
queryClient: QueryClient;
|
|
96
|
+
trpc: CreateTRPCClientOptions<TRouter>;
|
|
76
97
|
}): DecoratedProcedureRecord<TRouter["_def"]["record"], TRouter>;
|
|
77
|
-
|
|
78
|
-
export { type Exact,
|
|
98
|
+
//#endregion
|
|
99
|
+
export { type Exact, TRPCQueryKey, VueQueryContext, createTRPCVueQueryClient, vueQueryContext };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { InfiniteData, InfiniteQueryObserverOptions, InitialPageParam, MutationOptions, QueryClient, QueryKey, QueryOptions, SkipToken, UseInfiniteQueryReturnType, UseMutationReturnType, UseQueriesResults, UseQueryReturnType } from "@tanstack/vue-query";
|
|
2
|
+
import { CreateTRPCClientOptions, OperationContext, TRPCClientErrorLike, TRPCRequestOptions } from "@trpc/client";
|
|
3
|
+
import { AnyTRPCMutationProcedure, AnyTRPCProcedure, AnyTRPCQueryProcedure, AnyTRPCRouter, AnyTRPCSubscriptionProcedure, inferProcedureInput, inferProcedureOutput, inferTransformedProcedureOutput } from "@trpc/server";
|
|
4
|
+
import { MaybeRefOrGetter, Ref } from "vue";
|
|
5
|
+
import { Unsubscribable } from "@trpc/server/observable";
|
|
6
|
+
//#region src/types.d.ts
|
|
7
|
+
type inferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : T;
|
|
8
|
+
/** Not re-exported from vue-query's root, so we restate it. */
|
|
9
|
+
type ShallowOption = {
|
|
10
|
+
shallow?: boolean;
|
|
11
|
+
};
|
|
12
|
+
/** vue-query's plain `QueryOptions` minus the key, which we build from the procedure path. */
|
|
13
|
+
type KeylessQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey> = Omit<QueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, 'queryKey'>;
|
|
14
|
+
/**
|
|
15
|
+
* vue-query has no plain `QueryOptions` counterpart for infinite queries, so we assemble one the
|
|
16
|
+
* same way it does: core observer options, whose `queryKey` is already plain, with `enabled`
|
|
17
|
+
* widened to a ref or getter.
|
|
18
|
+
*/
|
|
19
|
+
type PlainKeyInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey extends QueryKey, TPageParam> = { [Property in keyof InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>]: Property extends 'enabled' ? MaybeRefOrGetter<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>[Property]> : InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>[Property]; } & ShallowOption;
|
|
20
|
+
type TRPCSubscriptionObserver<TValue, TError> = {
|
|
21
|
+
onStarted: (opts: {
|
|
22
|
+
context: OperationContext | undefined;
|
|
23
|
+
}) => void;
|
|
24
|
+
onData: (value: inferAsyncIterableYield<TValue>) => void;
|
|
25
|
+
onError: (err: TError) => void;
|
|
26
|
+
onStopped: () => void;
|
|
27
|
+
onComplete: () => void;
|
|
28
|
+
};
|
|
29
|
+
type ArrayElement<T> = T extends readonly unknown[] ? T[number] : never;
|
|
30
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
31
|
+
type Exact<Shape, T extends Shape> = Shape extends Primitive ? Shape : Shape extends object ? { [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; } : Shape;
|
|
32
|
+
type DecorateProcedure<TProcedure extends AnyTRPCProcedure, TRouter extends AnyTRPCRouter> = TProcedure extends AnyTRPCQueryProcedure ? {
|
|
33
|
+
useQuery: <TQueryFnData extends inferTransformedProcedureOutput<TRouter, TProcedure>, TError extends TRPCClientErrorLike<TRouter>, TQueryData extends TQueryFnData, TQueryKey extends QueryKey, TInput extends inferProcedureInput<TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure> extends void ? inferProcedureInput<TProcedure> | Ref<inferProcedureInput<TProcedure> | SkipToken> | (() => inferProcedureInput<TProcedure> | SkipToken) : Ref<Exact<inferProcedureInput<TProcedure>, TInput> | SkipToken> | (() => Exact<inferProcedureInput<TProcedure>, TInput> | SkipToken), opts?: MaybeRefOrGetter<KeylessQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> & {
|
|
34
|
+
trpc?: TRPCRequestOptions;
|
|
35
|
+
queryKey?: TQueryKey;
|
|
36
|
+
}>) => UseQueryReturnType<TData, TError>;
|
|
37
|
+
useQueries: <TQueryFnData extends {
|
|
38
|
+
output: inferTransformedProcedureOutput<TRouter, TProcedure>;
|
|
39
|
+
input: inferProcedureInput<TProcedure>;
|
|
40
|
+
}, TError extends TRPCClientErrorLike<TRouter>, TQueryData extends TQueryFnData, TQueryKey extends QueryKey, TInput extends inferProcedureInput<TProcedure>, TQueries extends KeylessQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, TData = TQueryFnData, TCombinedResult = UseQueriesResults<TQueries[]>>(inputs: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>[]>, opts?: MaybeRefOrGetter<TQueries & {
|
|
41
|
+
trpc?: TRPCRequestOptions;
|
|
42
|
+
queryKey?: never;
|
|
43
|
+
combine?: (result: UseQueriesResults<TQueries[]>) => TCombinedResult;
|
|
44
|
+
shallow?: boolean;
|
|
45
|
+
}>) => Readonly<Ref<TCombinedResult>>;
|
|
46
|
+
queryOptions: <TQueryFnData extends inferTransformedProcedureOutput<TRouter, TProcedure>, TError extends TRPCClientErrorLike<TRouter>, TQueryData extends TQueryFnData, TQueryKey extends QueryKey, TInput extends inferProcedureInput<TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure> extends void ? inferProcedureInput<TProcedure> | Ref<inferProcedureInput<TProcedure> | SkipToken> | (() => inferProcedureInput<TProcedure> | SkipToken) : Ref<Exact<inferProcedureInput<TProcedure>, TInput> | SkipToken> | (() => Exact<inferProcedureInput<TProcedure>, TInput> | SkipToken), opts?: MaybeRefOrGetter<KeylessQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> & {
|
|
47
|
+
trpc?: TRPCRequestOptions;
|
|
48
|
+
queryKey?: TQueryKey;
|
|
49
|
+
}>) => () => KeylessQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> & {
|
|
50
|
+
queryKey: TQueryKey;
|
|
51
|
+
};
|
|
52
|
+
query: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts?: TRPCRequestOptions) => Promise<inferTransformedProcedureOutput<TRouter, TProcedure>>;
|
|
53
|
+
invalidate: <TInput extends inferProcedureInput<TProcedure>>(input?: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>) => Promise<void>;
|
|
54
|
+
setQueryData: <TInput extends inferProcedureInput<TProcedure>>(updater: inferTransformedProcedureOutput<TRouter, TProcedure>, input?: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>) => ReturnType<QueryClient['setQueryData']>;
|
|
55
|
+
key: <TInput extends inferProcedureInput<TProcedure>>(input?: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>) => QueryKey;
|
|
56
|
+
} & (TProcedure['_def']['$types']['input'] extends {
|
|
57
|
+
cursor?: infer CursorType;
|
|
58
|
+
} ? {
|
|
59
|
+
useInfiniteQuery: <TQueryFnData extends inferTransformedProcedureOutput<TRouter, TProcedure>, TError extends TRPCClientErrorLike<TRouter>, TQueryKey extends QueryKey, TInput extends inferProcedureInput<TProcedure>, TData extends InfiniteData<any> = InfiniteData<TQueryFnData>>(input: MaybeRefOrGetter<Exact<Omit<inferProcedureInput<TProcedure>, 'cursor'>, TInput>>, opts?: MaybeRefOrGetter<Omit<PlainKeyInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, CursorType>, 'queryKey' | keyof InitialPageParam> & {
|
|
60
|
+
trpc?: TRPCRequestOptions;
|
|
61
|
+
queryKey?: TQueryKey;
|
|
62
|
+
} & (undefined extends TProcedure['_def']['$types']['input']['cursor'] ? Partial<InitialPageParam<CursorType>> : InitialPageParam<CursorType>)>) => UseInfiniteQueryReturnType<TData, TError>;
|
|
63
|
+
} : object) : TProcedure extends AnyTRPCMutationProcedure ? {
|
|
64
|
+
mutate: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts?: TRPCRequestOptions) => Promise<inferTransformedProcedureOutput<TRouter, TProcedure>>;
|
|
65
|
+
useMutation: <TData = inferTransformedProcedureOutput<TRouter, TProcedure>, TError = TRPCClientErrorLike<TRouter>, TVariables = inferProcedureInput<TProcedure>, TContext = unknown>(opts?: MaybeRefOrGetter<MutationOptions<TData, TError, TVariables, TContext> & {
|
|
66
|
+
trpc?: TRPCRequestOptions;
|
|
67
|
+
}>) => UseMutationReturnType<TData, TError, TVariables, TContext>;
|
|
68
|
+
} : TProcedure extends AnyTRPCSubscriptionProcedure ? {
|
|
69
|
+
subscribe: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts: TRPCRequestOptions & Partial<TRPCSubscriptionObserver<inferProcedureOutput<TProcedure>, TRPCClientErrorLike<TRouter>>>) => Unsubscribable;
|
|
70
|
+
useSubscription: <TInput extends inferProcedureInput<TProcedure>>(input: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>, opts: TRPCRequestOptions & Partial<TRPCSubscriptionObserver<inferProcedureOutput<TProcedure>, TRPCClientErrorLike<TRouter>>>) => Unsubscribable;
|
|
71
|
+
} : never;
|
|
72
|
+
/**
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
type DecoratedProcedureRecord<TProcedures extends Record<string, any>, TRouter extends AnyTRPCRouter> = { [K in keyof TProcedures]: TProcedures[K] extends AnyTRPCProcedure ? DecorateProcedure<TProcedures[K], TRouter> : DecoratedProcedureRecord<TProcedures[K], TRouter>; };
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/index.d.ts
|
|
78
|
+
type QueryType = 'query' | 'queries' | 'infinite';
|
|
79
|
+
type TRPCQueryKey = [readonly string[], {
|
|
80
|
+
input?: unknown;
|
|
81
|
+
type?: QueryType;
|
|
82
|
+
}?];
|
|
83
|
+
/**
|
|
84
|
+
* Operation context key marking a request as vue-query-driven.
|
|
85
|
+
* Registered globally via `Symbol.for()`, so it also works across duplicate installs.
|
|
86
|
+
*/
|
|
87
|
+
declare const vueQueryContext: unique symbol;
|
|
88
|
+
interface VueQueryContext {}
|
|
89
|
+
declare module '@trpc/client' {
|
|
90
|
+
interface OperationContext {
|
|
91
|
+
[vueQueryContext]?: VueQueryContext;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
declare function createTRPCVueQueryClient<TRouter extends AnyTRPCRouter>({ trpc, queryClient }: {
|
|
95
|
+
queryClient: QueryClient;
|
|
96
|
+
trpc: CreateTRPCClientOptions<TRouter>;
|
|
97
|
+
}): DecoratedProcedureRecord<TRouter["_def"]["record"], TRouter>;
|
|
98
|
+
//#endregion
|
|
99
|
+
export { type Exact, TRPCQueryKey, VueQueryContext, createTRPCVueQueryClient, vueQueryContext };
|
package/dist/index.mjs
CHANGED
|
@@ -1,164 +1,133 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
queryOptions as defineQueryOptions,
|
|
4
|
-
skipToken,
|
|
5
|
-
useInfiniteQuery,
|
|
6
|
-
useMutation,
|
|
7
|
-
useQueries,
|
|
8
|
-
useQuery
|
|
9
|
-
} from "@tanstack/vue-query";
|
|
1
|
+
import { queryOptions, skipToken, useInfiniteQuery, useMutation, useQueries, useQuery } from "@tanstack/vue-query";
|
|
10
2
|
import { createTRPCUntypedClient } from "@trpc/client";
|
|
11
3
|
import { createTRPCFlatProxy } from "@trpc/server";
|
|
12
4
|
import { createRecursiveProxy } from "@trpc/server/unstable-core-do-not-import";
|
|
13
|
-
import { toRef
|
|
14
|
-
import { computed,
|
|
5
|
+
import { toRef } from "@vueuse/core";
|
|
6
|
+
import { computed, onScopeDispose, shallowRef, toValue, watch } from "vue";
|
|
7
|
+
//#region src/index.ts
|
|
15
8
|
function getQueryKey(path, input, type) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
{
|
|
23
|
-
...input !== void 0 && input !== skipToken && { input },
|
|
24
|
-
...type && { type }
|
|
25
|
-
}
|
|
26
|
-
];
|
|
9
|
+
const splitPath = path.flatMap((part) => part.split("."));
|
|
10
|
+
if (input === void 0 && !type) return splitPath.length > 0 ? [splitPath] : [];
|
|
11
|
+
return [splitPath, {
|
|
12
|
+
...input !== void 0 && input !== skipToken && { input },
|
|
13
|
+
...type && { type }
|
|
14
|
+
}];
|
|
27
15
|
}
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Operation context key marking a request as vue-query-driven.
|
|
18
|
+
* Registered globally via `Symbol.for()`, so it also works across duplicate installs.
|
|
19
|
+
*/
|
|
20
|
+
const vueQueryContext = Symbol.for("trpc-vue-query.vueQueryContext");
|
|
21
|
+
function withVueQueryContext(trpcOptions) {
|
|
22
|
+
return {
|
|
23
|
+
...trpcOptions,
|
|
24
|
+
context: {
|
|
25
|
+
...trpcOptions?.context,
|
|
26
|
+
[vueQueryContext]: {}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function splitTRPCOptions(opts) {
|
|
31
|
+
const { trpc: trpcOptions, ...options } = toValue(opts) || {};
|
|
32
|
+
return {
|
|
33
|
+
trpcOptions,
|
|
34
|
+
options
|
|
35
|
+
};
|
|
30
36
|
}
|
|
31
37
|
function createVueQueryProxyDecoration(name, trpc, queryClient) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
subscription.value?.unsubscribe();
|
|
120
|
-
subscription.value = trpc.subscription(joinedPath, inputData.value, {
|
|
121
|
-
...opts
|
|
122
|
-
});
|
|
123
|
-
},
|
|
124
|
-
{ immediate: true }
|
|
125
|
-
);
|
|
126
|
-
onScopeDispose(() => {
|
|
127
|
-
subscription.value?.unsubscribe();
|
|
128
|
-
}, true);
|
|
129
|
-
return subscription.value;
|
|
130
|
-
}
|
|
131
|
-
if (prop === "useInfiniteQuery") {
|
|
132
|
-
const { trpc: trpcOptions, ...queryOptions } = opts;
|
|
133
|
-
return useInfiniteQuery({
|
|
134
|
-
queryKey: computed(() => getQueryKey(path, toValue(firstArg), "infinite")),
|
|
135
|
-
queryFn: async ({ queryKey, pageParam, signal }) => trpc.query(
|
|
136
|
-
joinedPath,
|
|
137
|
-
{
|
|
138
|
-
...queryKey[1]?.input,
|
|
139
|
-
cursor: pageParam
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
signal,
|
|
143
|
-
...trpcOptions
|
|
144
|
-
}
|
|
145
|
-
),
|
|
146
|
-
...maybeToRefs(queryOptions)
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
throw new Error(`Method '.${prop}()' not supported`);
|
|
150
|
-
});
|
|
38
|
+
return createRecursiveProxy(({ args, path: _path }) => {
|
|
39
|
+
const path = [name, ..._path];
|
|
40
|
+
const prop = path.pop();
|
|
41
|
+
if (prop === "_def") return { path };
|
|
42
|
+
const joinedPath = path.join(".");
|
|
43
|
+
const [firstArg, ...rest] = args;
|
|
44
|
+
const opts = rest[0] || {};
|
|
45
|
+
if (prop === "query") return trpc.query(joinedPath, firstArg, opts);
|
|
46
|
+
function createQuery(_input, _opts, { type = "query" } = {}) {
|
|
47
|
+
return queryOptions(() => {
|
|
48
|
+
const input = toValue(_input);
|
|
49
|
+
const { trpcOptions, options } = splitTRPCOptions(_opts);
|
|
50
|
+
return {
|
|
51
|
+
queryKey: getQueryKey(path, input, type),
|
|
52
|
+
queryFn: input === skipToken ? skipToken : async ({ signal }) => {
|
|
53
|
+
const output = await trpc.query(joinedPath, input, {
|
|
54
|
+
signal,
|
|
55
|
+
...withVueQueryContext(trpcOptions)
|
|
56
|
+
});
|
|
57
|
+
if (type === "queries") return {
|
|
58
|
+
output,
|
|
59
|
+
input
|
|
60
|
+
};
|
|
61
|
+
return output;
|
|
62
|
+
},
|
|
63
|
+
...options
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (prop === "useQuery") return useQuery(createQuery(firstArg, opts));
|
|
68
|
+
if (prop === "queryOptions") return createQuery(firstArg, opts);
|
|
69
|
+
if (prop === "useQueries") {
|
|
70
|
+
const inputs = firstArg;
|
|
71
|
+
const { combine, shallow } = toValue(opts) || {};
|
|
72
|
+
const queryOpts = () => {
|
|
73
|
+
const { combine: _, shallow: __, ...perQueryOptions } = toValue(opts) || {};
|
|
74
|
+
return perQueryOptions;
|
|
75
|
+
};
|
|
76
|
+
return useQueries({
|
|
77
|
+
queries: computed(() => toValue(inputs).map((i) => createQuery(i, queryOpts, { type: "queries" })())),
|
|
78
|
+
combine,
|
|
79
|
+
shallow
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (prop === "invalidate") return queryClient.invalidateQueries({ queryKey: getQueryKey(path, toValue(firstArg), "query") });
|
|
83
|
+
if (prop === "setQueryData") return queryClient.setQueryData(getQueryKey(path, toValue(opts), "query"), firstArg);
|
|
84
|
+
if (prop === "key") return getQueryKey(path, toValue(firstArg), "query");
|
|
85
|
+
if (prop === "mutate") return trpc.mutation(joinedPath, firstArg, opts);
|
|
86
|
+
if (prop === "useMutation") return useMutation(() => {
|
|
87
|
+
const { trpcOptions, options } = splitTRPCOptions(firstArg);
|
|
88
|
+
return {
|
|
89
|
+
mutationKey: getQueryKey(path, void 0),
|
|
90
|
+
mutationFn: async (payload) => trpc.mutation(joinedPath, payload, withVueQueryContext(trpcOptions)),
|
|
91
|
+
...options
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
if (prop === "subscribe") return trpc.subscription(joinedPath, firstArg, opts);
|
|
95
|
+
if (prop === "useSubscription") {
|
|
96
|
+
const inputData = toRef(firstArg);
|
|
97
|
+
const subscription = shallowRef();
|
|
98
|
+
watch(inputData, () => {
|
|
99
|
+
if (inputData.value === skipToken) return;
|
|
100
|
+
subscription.value?.unsubscribe();
|
|
101
|
+
subscription.value = trpc.subscription(joinedPath, inputData.value, { ...opts });
|
|
102
|
+
}, { immediate: true });
|
|
103
|
+
onScopeDispose(() => {
|
|
104
|
+
subscription.value?.unsubscribe();
|
|
105
|
+
}, true);
|
|
106
|
+
return subscription.value;
|
|
107
|
+
}
|
|
108
|
+
if (prop === "useInfiniteQuery") return useInfiniteQuery(() => {
|
|
109
|
+
const input = toValue(firstArg);
|
|
110
|
+
const { trpcOptions, options } = splitTRPCOptions(opts);
|
|
111
|
+
return {
|
|
112
|
+
queryKey: getQueryKey(path, input, "infinite"),
|
|
113
|
+
queryFn: async ({ pageParam, signal }) => trpc.query(joinedPath, {
|
|
114
|
+
...input,
|
|
115
|
+
cursor: pageParam
|
|
116
|
+
}, {
|
|
117
|
+
signal,
|
|
118
|
+
...withVueQueryContext(trpcOptions)
|
|
119
|
+
}),
|
|
120
|
+
...options
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
throw new Error(`Method '.${prop}()' not supported`);
|
|
124
|
+
});
|
|
151
125
|
}
|
|
152
|
-
function createTRPCVueQueryClient({
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const decoratedClient = createTRPCFlatProxy((key) => {
|
|
158
|
-
return createVueQueryProxyDecoration(key.toString(), client, queryClient);
|
|
159
|
-
});
|
|
160
|
-
return decoratedClient;
|
|
126
|
+
function createTRPCVueQueryClient({ trpc, queryClient }) {
|
|
127
|
+
const client = createTRPCUntypedClient(trpc);
|
|
128
|
+
return createTRPCFlatProxy((key) => {
|
|
129
|
+
return createVueQueryProxyDecoration(key.toString(), client, queryClient);
|
|
130
|
+
});
|
|
161
131
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
};
|
|
132
|
+
//#endregion
|
|
133
|
+
export { createTRPCVueQueryClient, vueQueryContext };
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@falcondev-oss/trpc-vue-query",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"description": "A tRPC wrapper around '@tanstack/vue-query'",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"repository":
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "github:falcondev-oss/trpc-vue-query"
|
|
10
|
+
},
|
|
8
11
|
"bugs": {
|
|
9
12
|
"url": "https://github.com/falcondev-oss/trpc-vue-query/issues"
|
|
10
13
|
},
|
|
@@ -17,7 +20,7 @@
|
|
|
17
20
|
],
|
|
18
21
|
"exports": {
|
|
19
22
|
"import": {
|
|
20
|
-
"types": "./dist/index.d.
|
|
23
|
+
"types": "./dist/index.d.mts",
|
|
21
24
|
"default": "./dist/index.mjs"
|
|
22
25
|
},
|
|
23
26
|
"require": {
|
|
@@ -27,55 +30,58 @@
|
|
|
27
30
|
},
|
|
28
31
|
"main": "dist/index.cjs",
|
|
29
32
|
"module": "dist/index.mjs",
|
|
30
|
-
"types": "dist/index.d.
|
|
33
|
+
"types": "dist/index.d.cts",
|
|
31
34
|
"files": [
|
|
32
35
|
"dist"
|
|
33
36
|
],
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
+
"devEngines": {
|
|
38
|
+
"runtime": {
|
|
39
|
+
"name": "node",
|
|
40
|
+
"version": ">=24"
|
|
41
|
+
},
|
|
42
|
+
"packageManager": {
|
|
43
|
+
"name": "pnpm",
|
|
44
|
+
"version": "12",
|
|
45
|
+
"onFail": "warn"
|
|
46
|
+
}
|
|
37
47
|
},
|
|
38
48
|
"peerDependencies": {
|
|
39
|
-
"@tanstack/vue-query": "^5.
|
|
49
|
+
"@tanstack/vue-query": "^5.102.0",
|
|
40
50
|
"@trpc/client": "^11.13.4",
|
|
41
51
|
"@trpc/server": "^11.13.4",
|
|
42
52
|
"vue": "^3.5.30"
|
|
43
53
|
},
|
|
44
54
|
"dependencies": {
|
|
45
|
-
"@vueuse/core": "^14.
|
|
55
|
+
"@vueuse/core": "^14.4.0"
|
|
46
56
|
},
|
|
47
57
|
"devDependencies": {
|
|
48
|
-
"@commitlint/cli": "^
|
|
49
|
-
"@
|
|
50
|
-
"@
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"@louishaftmann/prettier-config": "^4.3.1",
|
|
54
|
-
"@tanstack/vue-query": "^5.83.0",
|
|
55
|
-
"@trpc/client": "11.4.3",
|
|
56
|
-
"@trpc/server": "11.4.3",
|
|
57
|
-
"@types/eslint": "^9.6.1",
|
|
58
|
+
"@commitlint/cli": "^21.2.2",
|
|
59
|
+
"@falcondev-oss/configs": "^6.0.6",
|
|
60
|
+
"@tanstack/vue-query": "^5.103.2",
|
|
61
|
+
"@trpc/client": "11.18.0",
|
|
62
|
+
"@trpc/server": "11.18.0",
|
|
58
63
|
"@types/ws": "^8.18.1",
|
|
59
|
-
"@vitest/ui": "^
|
|
60
|
-
"eslint": "^9.
|
|
64
|
+
"@vitest/ui": "^4.1.11",
|
|
65
|
+
"eslint": "^10.9.0",
|
|
61
66
|
"husky": "^9.1.7",
|
|
62
|
-
"lint-staged": "^
|
|
63
|
-
"prettier": "^3.
|
|
64
|
-
"start-server-and-test": "^
|
|
65
|
-
"
|
|
66
|
-
"tsx": "^4.
|
|
67
|
-
"type-fest": "^
|
|
68
|
-
"typescript": "^
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
67
|
+
"lint-staged": "^17.3.0",
|
|
68
|
+
"prettier": "^3.9.6",
|
|
69
|
+
"start-server-and-test": "^3.0.12",
|
|
70
|
+
"tsdown": "^0.22.14",
|
|
71
|
+
"tsx": "^4.23.12",
|
|
72
|
+
"type-fest": "^5.8.0",
|
|
73
|
+
"typescript": "^6.0.3",
|
|
74
|
+
"typescript-eslint": "^8.67.0",
|
|
75
|
+
"vitest": "^4.1.11",
|
|
76
|
+
"vue": "^3.5.41",
|
|
77
|
+
"ws": "^8.21.3",
|
|
78
|
+
"zod": "^4.4.3"
|
|
73
79
|
},
|
|
74
80
|
"changelogithub": {
|
|
75
81
|
"extends": "gh:falcondev-it/configs/changelogithub"
|
|
76
82
|
},
|
|
77
83
|
"scripts": {
|
|
78
|
-
"build": "
|
|
84
|
+
"build": "tsdown",
|
|
79
85
|
"lint": "eslint --cache . && prettier --check --cache .",
|
|
80
86
|
"lint:ci": "eslint --cache --cache-strategy content . && prettier --check --cache --cache-strategy content .",
|
|
81
87
|
"lint:fix": "eslint --fix --cache . && prettier --write --cache .",
|
package/dist/index.d.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { QueryKey, SkipToken, UseQueryOptions, UseQueryReturnType, UseQueriesResults, QueryClient, InfiniteData, UseInfiniteQueryOptions, InitialPageParam, UseInfiniteQueryReturnType, UseMutationOptions, UseMutationReturnType } from '@tanstack/vue-query';
|
|
2
|
-
import { TRPCClientErrorLike, TRPCRequestOptions, OperationContext, CreateTRPCClientOptions } from '@trpc/client';
|
|
3
|
-
import { AnyTRPCRouter, AnyTRPCProcedure, AnyTRPCQueryProcedure, inferTransformedProcedureOutput, inferProcedureInput, AnyTRPCMutationProcedure, AnyTRPCSubscriptionProcedure, inferProcedureOutput } from '@trpc/server';
|
|
4
|
-
import { Unsubscribable } from '@trpc/server/observable';
|
|
5
|
-
import { Ref, MaybeRefOrGetter, UnwrapRef } from 'vue';
|
|
6
|
-
|
|
7
|
-
type inferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : T;
|
|
8
|
-
type TRPCSubscriptionObserver<TValue, TError> = {
|
|
9
|
-
onStarted: (opts: {
|
|
10
|
-
context: OperationContext | undefined;
|
|
11
|
-
}) => void;
|
|
12
|
-
onData: (value: inferAsyncIterableYield<TValue>) => void;
|
|
13
|
-
onError: (err: TError) => void;
|
|
14
|
-
onStopped: () => void;
|
|
15
|
-
onComplete: () => void;
|
|
16
|
-
};
|
|
17
|
-
type ArrayElement<T> = T extends readonly unknown[] ? T[number] : never;
|
|
18
|
-
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
19
|
-
type Exact<Shape, T extends Shape> = Shape extends Primitive ? Shape : Shape extends object ? {
|
|
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;
|
|
21
|
-
} : Shape;
|
|
22
|
-
type DecorateProcedure<TProcedure extends AnyTRPCProcedure, TRouter extends AnyTRPCRouter> = TProcedure extends AnyTRPCQueryProcedure ? {
|
|
23
|
-
useQuery: <TQueryFnData extends inferTransformedProcedureOutput<TRouter, TProcedure>, TError extends TRPCClientErrorLike<TRouter>, TQueryData extends TQueryFnData, TQueryKey extends QueryKey, TInput extends inferProcedureInput<TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure> extends void ? inferProcedureInput<TProcedure> | Ref<inferProcedureInput<TProcedure> | SkipToken> | (() => inferProcedureInput<TProcedure> | SkipToken) : Ref<Exact<inferProcedureInput<TProcedure>, TInput> | SkipToken> | (() => Exact<inferProcedureInput<TProcedure>, TInput> | SkipToken), opts?: MaybeRefOrGetter<Omit<UnwrapRef<UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>>, 'queryKey'> & {
|
|
24
|
-
trpc?: TRPCRequestOptions;
|
|
25
|
-
queryKey?: TQueryKey;
|
|
26
|
-
}>) => UseQueryReturnType<TData, TError>;
|
|
27
|
-
useQueries: <TQueryFnData extends {
|
|
28
|
-
output: inferTransformedProcedureOutput<TRouter, TProcedure>;
|
|
29
|
-
input: inferProcedureInput<TProcedure>;
|
|
30
|
-
}, TError extends TRPCClientErrorLike<TRouter>, TQueryData extends TQueryFnData, TQueryKey extends QueryKey, TInput extends inferProcedureInput<TProcedure>, TQueries extends UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, TData = TQueryFnData, TCombinedResult = UseQueriesResults<TQueries[]>>(inputs: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>[]>, opts?: MaybeRefOrGetter<Omit<UnwrapRef<TQueries>, 'queryKey'> & {
|
|
31
|
-
trpc?: TRPCRequestOptions;
|
|
32
|
-
queryKey?: never;
|
|
33
|
-
combine?: (result: UseQueriesResults<TQueries[]>) => TCombinedResult;
|
|
34
|
-
shallow?: boolean;
|
|
35
|
-
}>) => Readonly<Ref<TCombinedResult>>;
|
|
36
|
-
queryOptions: <TQueryFnData extends inferTransformedProcedureOutput<TRouter, TProcedure>, TError extends TRPCClientErrorLike<TRouter>, TQueryData extends TQueryFnData, TQueryKey extends QueryKey, TInput extends inferProcedureInput<TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure> extends void ? inferProcedureInput<TProcedure> | Ref<inferProcedureInput<TProcedure> | SkipToken> | (() => inferProcedureInput<TProcedure> | SkipToken) : Ref<Exact<inferProcedureInput<TProcedure>, TInput> | SkipToken> | (() => Exact<inferProcedureInput<TProcedure>, TInput> | SkipToken), opts?: MaybeRefOrGetter<Omit<UnwrapRef<UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>>, 'queryKey'> & {
|
|
37
|
-
trpc?: TRPCRequestOptions;
|
|
38
|
-
queryKey?: TQueryKey;
|
|
39
|
-
}>) => UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>;
|
|
40
|
-
query: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts?: TRPCRequestOptions) => Promise<inferTransformedProcedureOutput<TRouter, TProcedure>>;
|
|
41
|
-
invalidate: <TInput extends inferProcedureInput<TProcedure>>(input?: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>) => Promise<void>;
|
|
42
|
-
setQueryData: <TInput extends inferProcedureInput<TProcedure>>(updater: inferTransformedProcedureOutput<TRouter, TProcedure>, input?: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>) => ReturnType<QueryClient['setQueryData']>;
|
|
43
|
-
key: <TInput extends inferProcedureInput<TProcedure>>(input?: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>) => QueryKey;
|
|
44
|
-
} & (TProcedure['_def']['$types']['input'] extends {
|
|
45
|
-
cursor?: infer CursorType;
|
|
46
|
-
} ? {
|
|
47
|
-
useInfiniteQuery: <TQueryFnData extends inferTransformedProcedureOutput<TRouter, TProcedure>, TError extends TRPCClientErrorLike<TRouter>, TQueryKey extends QueryKey, TInput extends inferProcedureInput<TProcedure>, TData extends InfiniteData<any> = InfiniteData<TQueryFnData>>(input: MaybeRefOrGetter<Exact<Omit<inferProcedureInput<TProcedure>, 'cursor'>, TInput>>, opts?: MaybeRefOrGetter<Omit<UnwrapRef<UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, CursorType>>, 'queryKey' | keyof InitialPageParam> & {
|
|
48
|
-
trpc?: TRPCRequestOptions;
|
|
49
|
-
queryKey?: TQueryKey;
|
|
50
|
-
} & (undefined extends TProcedure['_def']['$types']['input']['cursor'] ? Partial<InitialPageParam<CursorType>> : InitialPageParam<CursorType>)>) => UseInfiniteQueryReturnType<TData, TError>;
|
|
51
|
-
} : object) : TProcedure extends AnyTRPCMutationProcedure ? {
|
|
52
|
-
mutate: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts?: TRPCRequestOptions) => Promise<inferTransformedProcedureOutput<TRouter, TProcedure>>;
|
|
53
|
-
useMutation: <TData = inferTransformedProcedureOutput<TRouter, TProcedure>, TError = TRPCClientErrorLike<TRouter>, TVariables = inferProcedureInput<TProcedure>, TContext = unknown>(opts?: MaybeRefOrGetter<UseMutationOptions<TData, TError, TVariables, TContext> & {
|
|
54
|
-
trpc?: TRPCRequestOptions;
|
|
55
|
-
}>) => UseMutationReturnType<TData, TError, TVariables, TContext>;
|
|
56
|
-
} : TProcedure extends AnyTRPCSubscriptionProcedure ? {
|
|
57
|
-
subscribe: <TInput extends inferProcedureInput<TProcedure>>(input: Exact<inferProcedureInput<TProcedure>, TInput>, opts: TRPCRequestOptions & Partial<TRPCSubscriptionObserver<inferProcedureOutput<TProcedure>, TRPCClientErrorLike<TRouter>>>) => Unsubscribable;
|
|
58
|
-
useSubscription: <TInput extends inferProcedureInput<TProcedure>>(input: MaybeRefOrGetter<Exact<inferProcedureInput<TProcedure>, TInput>>, opts: TRPCRequestOptions & Partial<TRPCSubscriptionObserver<inferProcedureOutput<TProcedure>, TRPCClientErrorLike<TRouter>>>) => Unsubscribable;
|
|
59
|
-
} : never;
|
|
60
|
-
/**
|
|
61
|
-
* @internal
|
|
62
|
-
*/
|
|
63
|
-
type DecoratedProcedureRecord<TProcedures extends Record<string, any>, TRouter extends AnyTRPCRouter> = {
|
|
64
|
-
[K in keyof TProcedures]: TProcedures[K] extends AnyTRPCProcedure ? DecorateProcedure<TProcedures[K], TRouter> : DecoratedProcedureRecord<TProcedures[K], TRouter>;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
type QueryType = 'query' | 'queries' | 'infinite';
|
|
68
|
-
type TRPCQueryKey = [readonly string[], {
|
|
69
|
-
input?: unknown;
|
|
70
|
-
type?: QueryType;
|
|
71
|
-
}?];
|
|
72
|
-
|
|
73
|
-
declare function createTRPCVueQueryClient<TRouter extends AnyTRPCRouter>({ trpc, queryClient, }: {
|
|
74
|
-
queryClient: QueryClient;
|
|
75
|
-
trpc: CreateTRPCClientOptions<TRouter>;
|
|
76
|
-
}): DecoratedProcedureRecord<TRouter["_def"]["record"], TRouter>;
|
|
77
|
-
|
|
78
|
-
export { type Exact, type TRPCQueryKey, createTRPCVueQueryClient };
|