@orpc/vue-query 0.0.0-next.0021fba

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 oRPC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,119 @@
1
+ <div align="center">
2
+ <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
3
+ </div>
4
+
5
+ <h1></h1>
6
+
7
+ <div align="center">
8
+ <a href="https://codecov.io/gh/unnoq/orpc">
9
+ <img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
10
+ </a>
11
+ <a href="https://www.npmjs.com/package/@orpc/vue-query">
12
+ <img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fvue-query?logo=npm" />
13
+ </a>
14
+ <a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
15
+ <img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
16
+ </a>
17
+ <a href="https://discord.gg/TXEbwRBvQn">
18
+ <img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
19
+ </a>
20
+ </div>
21
+
22
+ <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
23
+
24
+ **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
25
+
26
+ ---
27
+
28
+ ## Highlights
29
+
30
+ - **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
31
+ - **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
32
+ - **📝 Contract-First Development**: Optionally define your API contract before implementation.
33
+ - **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
34
+ - **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), Pinia Colada, and more.
35
+ - **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
36
+ - **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
37
+ - **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
38
+ - **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
39
+ - **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
40
+ - **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
41
+ - **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
42
+
43
+ ## Documentation
44
+
45
+ You can find the full documentation [here](https://orpc.unnoq.com).
46
+
47
+ ## Packages
48
+
49
+ - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
50
+ - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
51
+ - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
52
+ - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
53
+ - [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
54
+ - [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
55
+ - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
56
+ - [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
57
+ - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
58
+ - [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
59
+ - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
60
+ - [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
61
+ - [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
62
+
63
+ ## `@orpc/vue-query`
64
+
65
+ 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
+ ```ts
68
+ export function Setup() {
69
+ const query = useQuery(orpc.planet.find.queryOptions({
70
+ input: { id: 123 }, // Specify input if needed
71
+ context: { cache: true }, // Provide client context if needed
72
+ // additional options...
73
+ }))
74
+
75
+ const query = useInfiniteQuery(orpc.planet.list.infiniteOptions({
76
+ input: (pageParam: number | undefined) => ({ limit: 10, offset: pageParam }),
77
+ context: { cache: true }, // Provide client context if needed
78
+ initialPageParam: undefined,
79
+ getNextPageParam: lastPage => lastPage.nextPageParam,
80
+ // additional options...
81
+ }))
82
+
83
+ const mutation = useMutation(orpc.planet.create.mutationOptions({
84
+ context: { cache: true }, // Provide client context if needed
85
+ // additional options...
86
+ }))
87
+
88
+ mutation.mutate({ name: 'Earth' })
89
+
90
+ const queryClient = useQueryClient()
91
+
92
+ // Invalidate all planet queries
93
+ queryClient.invalidateQueries({
94
+ queryKey: orpc.planet.key(),
95
+ })
96
+
97
+ // Invalidate only regular (non-infinite) planet queries
98
+ queryClient.invalidateQueries({
99
+ queryKey: orpc.planet.key({ type: 'query' })
100
+ })
101
+
102
+ // Invalidate the planet find query with id 123
103
+ queryClient.invalidateQueries({
104
+ queryKey: orpc.planet.find.key({ input: { id: 123 } })
105
+ })
106
+ }
107
+ ```
108
+
109
+ ## Sponsors
110
+
111
+ <p align="center">
112
+ <a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
113
+ <img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
114
+ </a>
115
+ </p>
116
+
117
+ ## License
118
+
119
+ Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
@@ -0,0 +1,142 @@
1
+ import { ClientContext, Client, NestedClient } from '@orpc/client';
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';
6
+ import { MaybeRef, MaybeRefOrGetter, ComputedRef, Ref } from 'vue';
7
+
8
+ interface GeneralUtils<TInput> {
9
+ /**
10
+ * Generate a query/mutation key for checking status, invalidate, set, get, etc.
11
+ *
12
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
13
+ */
14
+ key<UType extends OperationType>(options?: OperationKeyOptions<UType, TInput>): QueryKey;
15
+ }
16
+ declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
17
+
18
+ /**
19
+ * Since `@tanstack/vue-query` is not exporting the type `MaybeRefDeep` we need to copy it from the source code.
20
+ * https://github.com/TanStack/query/blob/7ff544e12e79388e513b1cd886aeb946f80f0153/packages/vue-query/src/types.ts#L19C1-L27C2
21
+ */
22
+ type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
23
+ [Property in keyof T]: MaybeRefDeep<T[Property]>;
24
+ } : T>;
25
+ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
26
+ input?: MaybeRefDeep<TInput | SkipToken>;
27
+ } : {
28
+ input: MaybeRefDeep<TInput | SkipToken>;
29
+ }) & (Record<never, never> extends TClientContext ? {
30
+ context?: MaybeRefDeep<TClientContext>;
31
+ } : {
32
+ context: MaybeRefDeep<TClientContext>;
33
+ }) & {
34
+ [P in keyof Omit<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>, 'queryKey' | 'enabled'>]: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>[P]>;
35
+ } & {
36
+ enabled?: MaybeRefOrGetter<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['enabled']>;
37
+ queryKey?: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['queryKey']>;
38
+ shallow?: boolean;
39
+ };
40
+ interface QueryOptionsBase<TOutput, TError> {
41
+ queryKey: ComputedRef<QueryKey>;
42
+ queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
43
+ throwOnError?(error: TError): boolean;
44
+ retryDelay?: (count: number, error: TError) => number;
45
+ enabled: ComputedRef<boolean | undefined>;
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> {
53
+ }
54
+ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = (Record<never, never> extends TClientContext ? {
55
+ context?: MaybeRefDeep<TClientContext>;
56
+ } : {
57
+ context: MaybeRefDeep<TClientContext>;
58
+ }) & {
59
+ [Property in keyof Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey' | 'enabled'>]: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>[Property]>;
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']>;
64
+ shallow?: boolean;
65
+ };
66
+ interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
67
+ queryKey: ComputedRef<QueryKey>;
68
+ queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
69
+ throwOnError?(error: TError): boolean;
70
+ retryDelay?: (count: number, error: TError) => number;
71
+ enabled: ComputedRef<boolean | undefined>;
72
+ }
73
+ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
74
+ context?: TClientContext;
75
+ } : {
76
+ context: TClientContext;
77
+ }) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
78
+ type MutationOptions<TInput, TOutput, TError, TMutationContext> = {
79
+ [P in keyof MutationObserverOptions<TOutput, TError, TInput, TMutationContext>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput, TMutationContext>[P]>;
80
+ } & {
81
+ shallow?: MaybeRef<boolean>;
82
+ };
83
+
84
+ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
85
+ /**
86
+ * Calling corresponding procedure client
87
+ *
88
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
89
+ */
90
+ call: Client<TClientContext, TInput, TOutput, TError>;
91
+ /**
92
+ * Generate options used for useQuery/prefetchQuery/...
93
+ *
94
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-options-utility Tanstack Query Options Utility Docs}
95
+ */
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>>;
104
+ /**
105
+ * Generate options used for useInfiniteQuery/prefetchInfiniteQuery/...
106
+ *
107
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
108
+ */
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>>;
110
+ /**
111
+ * Generate options used for useMutation/...
112
+ *
113
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#mutation-options Tanstack Mutation Options Docs}
114
+ */
115
+ mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
116
+ }
117
+ interface CreateProcedureUtilsOptions {
118
+ path: string[];
119
+ }
120
+ declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
121
+
122
+ type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
123
+ [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
124
+ } & GeneralUtils<unknown>;
125
+ interface CreateRouterUtilsOptions {
126
+ path?: string[];
127
+ }
128
+ /**
129
+ * Create a router utils from a client.
130
+ *
131
+ * @info Both client-side and server-side clients are supported.
132
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/vue Tanstack Query Vue Docs}
133
+ */
134
+ declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
135
+
136
+ type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunction ? T : T extends object ? {
137
+ [K in keyof T]: UnrefDeep<T[K]>;
138
+ } : T;
139
+ declare function unrefDeep<T>(value: T): UnrefDeep<T>;
140
+
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 };
@@ -0,0 +1,142 @@
1
+ import { ClientContext, Client, NestedClient } from '@orpc/client';
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';
6
+ import { MaybeRef, MaybeRefOrGetter, ComputedRef, Ref } from 'vue';
7
+
8
+ interface GeneralUtils<TInput> {
9
+ /**
10
+ * Generate a query/mutation key for checking status, invalidate, set, get, etc.
11
+ *
12
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
13
+ */
14
+ key<UType extends OperationType>(options?: OperationKeyOptions<UType, TInput>): QueryKey;
15
+ }
16
+ declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
17
+
18
+ /**
19
+ * Since `@tanstack/vue-query` is not exporting the type `MaybeRefDeep` we need to copy it from the source code.
20
+ * https://github.com/TanStack/query/blob/7ff544e12e79388e513b1cd886aeb946f80f0153/packages/vue-query/src/types.ts#L19C1-L27C2
21
+ */
22
+ type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
23
+ [Property in keyof T]: MaybeRefDeep<T[Property]>;
24
+ } : T>;
25
+ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
26
+ input?: MaybeRefDeep<TInput | SkipToken>;
27
+ } : {
28
+ input: MaybeRefDeep<TInput | SkipToken>;
29
+ }) & (Record<never, never> extends TClientContext ? {
30
+ context?: MaybeRefDeep<TClientContext>;
31
+ } : {
32
+ context: MaybeRefDeep<TClientContext>;
33
+ }) & {
34
+ [P in keyof Omit<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>, 'queryKey' | 'enabled'>]: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>[P]>;
35
+ } & {
36
+ enabled?: MaybeRefOrGetter<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['enabled']>;
37
+ queryKey?: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['queryKey']>;
38
+ shallow?: boolean;
39
+ };
40
+ interface QueryOptionsBase<TOutput, TError> {
41
+ queryKey: ComputedRef<QueryKey>;
42
+ queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
43
+ throwOnError?(error: TError): boolean;
44
+ retryDelay?: (count: number, error: TError) => number;
45
+ enabled: ComputedRef<boolean | undefined>;
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> {
53
+ }
54
+ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = (Record<never, never> extends TClientContext ? {
55
+ context?: MaybeRefDeep<TClientContext>;
56
+ } : {
57
+ context: MaybeRefDeep<TClientContext>;
58
+ }) & {
59
+ [Property in keyof Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey' | 'enabled'>]: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>[Property]>;
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']>;
64
+ shallow?: boolean;
65
+ };
66
+ interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
67
+ queryKey: ComputedRef<QueryKey>;
68
+ queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
69
+ throwOnError?(error: TError): boolean;
70
+ retryDelay?: (count: number, error: TError) => number;
71
+ enabled: ComputedRef<boolean | undefined>;
72
+ }
73
+ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
74
+ context?: TClientContext;
75
+ } : {
76
+ context: TClientContext;
77
+ }) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
78
+ type MutationOptions<TInput, TOutput, TError, TMutationContext> = {
79
+ [P in keyof MutationObserverOptions<TOutput, TError, TInput, TMutationContext>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput, TMutationContext>[P]>;
80
+ } & {
81
+ shallow?: MaybeRef<boolean>;
82
+ };
83
+
84
+ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
85
+ /**
86
+ * Calling corresponding procedure client
87
+ *
88
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
89
+ */
90
+ call: Client<TClientContext, TInput, TOutput, TError>;
91
+ /**
92
+ * Generate options used for useQuery/prefetchQuery/...
93
+ *
94
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-options-utility Tanstack Query Options Utility Docs}
95
+ */
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>>;
104
+ /**
105
+ * Generate options used for useInfiniteQuery/prefetchInfiniteQuery/...
106
+ *
107
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
108
+ */
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>>;
110
+ /**
111
+ * Generate options used for useMutation/...
112
+ *
113
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#mutation-options Tanstack Mutation Options Docs}
114
+ */
115
+ mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
116
+ }
117
+ interface CreateProcedureUtilsOptions {
118
+ path: string[];
119
+ }
120
+ declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
121
+
122
+ type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
123
+ [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
124
+ } & GeneralUtils<unknown>;
125
+ interface CreateRouterUtilsOptions {
126
+ path?: string[];
127
+ }
128
+ /**
129
+ * Create a router utils from a client.
130
+ *
131
+ * @info Both client-side and server-side clients are supported.
132
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/vue Tanstack Query Vue Docs}
133
+ */
134
+ declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
135
+
136
+ type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunction ? T : T extends object ? {
137
+ [K in keyof T]: UnrefDeep<T[K]>;
138
+ } : T;
139
+ declare function unrefDeep<T>(value: T): UnrefDeep<T>;
140
+
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 ADDED
@@ -0,0 +1,126 @@
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';
5
+ import { isRef, computed } from 'vue';
6
+
7
+ function createGeneralUtils(path) {
8
+ return {
9
+ key(options) {
10
+ return generateOperationKey(path, options);
11
+ }
12
+ };
13
+ }
14
+
15
+ function unrefDeep(value) {
16
+ if (isRef(value)) {
17
+ return unrefDeep(value.value);
18
+ }
19
+ if (Array.isArray(value)) {
20
+ return value.map(unrefDeep);
21
+ }
22
+ if (isObject(value)) {
23
+ return Object.keys(value).reduce((acc, key) => {
24
+ acc[key] = unrefDeep(value[key]);
25
+ return acc;
26
+ }, {});
27
+ }
28
+ return value;
29
+ }
30
+
31
+ function createProcedureUtils(client, options) {
32
+ return {
33
+ call: client,
34
+ queryOptions(...[optionsIn = {}]) {
35
+ return {
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 ? false : void 0),
45
+ ...optionsIn
46
+ };
47
+ },
48
+ experimental_streamedOptions(...[optionsIn = {}]) {
49
+ return {
50
+ enabled: computed(() => unrefDeep(optionsIn.input) === skipToken ? false : void 0),
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
+ }),
66
+ ...optionsIn
67
+ };
68
+ },
69
+ infiniteOptions(optionsIn) {
70
+ return {
71
+ queryKey: computed(() => {
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
+ });
77
+ }),
78
+ queryFn: ({ pageParam, signal }) => {
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) });
84
+ },
85
+ enabled: computed(() => unrefDeep(optionsIn.input) === skipToken ? false : void 0),
86
+ ...optionsIn
87
+ };
88
+ },
89
+ mutationOptions(...[optionsIn = {}]) {
90
+ return {
91
+ mutationKey: generateOperationKey(options.path, { type: "mutation" }),
92
+ mutationFn: (input) => client(input, { context: unrefDeep(optionsIn.context) }),
93
+ ...optionsIn
94
+ };
95
+ }
96
+ };
97
+ }
98
+
99
+ function createRouterUtils(client, options = {}) {
100
+ const path = options.path ?? [];
101
+ const generalUtils = createGeneralUtils(path);
102
+ const procedureUtils = createProcedureUtils(client, { path });
103
+ const recursive = new Proxy({
104
+ ...generalUtils,
105
+ ...procedureUtils
106
+ }, {
107
+ get(target, prop) {
108
+ const value = Reflect.get(target, prop);
109
+ if (typeof prop !== "string") {
110
+ return value;
111
+ }
112
+ const nextUtils = createRouterUtils(client[prop], { ...options, path: [...path, prop] });
113
+ if (typeof value !== "function") {
114
+ return nextUtils;
115
+ }
116
+ return new Proxy(value, {
117
+ get(_, prop2) {
118
+ return Reflect.get(nextUtils, prop2);
119
+ }
120
+ });
121
+ }
122
+ });
123
+ return recursive;
124
+ }
125
+
126
+ export { createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@orpc/vue-query",
3
+ "type": "module",
4
+ "version": "0.0.0-next.0021fba",
5
+ "license": "MIT",
6
+ "homepage": "https://orpc.unnoq.com",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/unnoq/orpc.git",
10
+ "directory": "packages/vue-query"
11
+ },
12
+ "keywords": [
13
+ "unnoq",
14
+ "orpc",
15
+ "vue",
16
+ "vue-query",
17
+ "tanstack"
18
+ ],
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.mts",
22
+ "import": "./dist/index.mjs",
23
+ "default": "./dist/index.mjs"
24
+ }
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "peerDependencies": {
30
+ "@tanstack/vue-query": ">=5.80.2",
31
+ "vue": ">=3.3.0",
32
+ "@orpc/client": "0.0.0-next.0021fba"
33
+ },
34
+ "dependencies": {
35
+ "@orpc/shared": "0.0.0-next.0021fba",
36
+ "@orpc/tanstack-query": "0.0.0-next.0021fba"
37
+ },
38
+ "devDependencies": {
39
+ "@tanstack/vue-query": "^5.83.0"
40
+ },
41
+ "scripts": {
42
+ "build": "unbuild",
43
+ "build:watch": "pnpm run build --watch",
44
+ "type:check": "tsc -b"
45
+ }
46
+ }