@orpc/vue-query 0.0.0-next.e361acd → 0.0.0-next.e39a46e

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 ADDED
@@ -0,0 +1,123 @@
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
+ <a href="https://deepwiki.com/unnoq/orpc">
21
+ <img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki">
22
+ </a>
23
+ </div>
24
+
25
+ <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
26
+
27
+ **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
28
+
29
+ ---
30
+
31
+ ## Highlights
32
+
33
+ - **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
34
+ - **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
35
+ - **📝 Contract-First Development**: Optionally define your API contract before implementation.
36
+ - **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
37
+ - **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
38
+ - **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
39
+ - **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
40
+ - **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
41
+ - **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
42
+ - **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
43
+ - **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
44
+ - **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
45
+
46
+ ## Documentation
47
+
48
+ You can find the full documentation [here](https://orpc.unnoq.com).
49
+
50
+ ## Packages
51
+
52
+ - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
53
+ - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
54
+ - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
55
+ - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
56
+ - [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
57
+ - [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
58
+ - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
59
+ - [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
60
+ - [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
61
+ - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
62
+ - [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
63
+ - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
64
+ - [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
65
+ - [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
66
+
67
+ ## `@orpc/vue-query`
68
+
69
+ 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.
70
+
71
+ ```ts
72
+ export function Setup() {
73
+ const query = useQuery(orpc.planet.find.queryOptions({
74
+ input: { id: 123 }, // Specify input if needed
75
+ context: { cache: true }, // Provide client context if needed
76
+ // additional options...
77
+ }))
78
+
79
+ const query = useInfiniteQuery(orpc.planet.list.infiniteOptions({
80
+ input: (pageParam: number | undefined) => ({ limit: 10, offset: pageParam }),
81
+ context: { cache: true }, // Provide client context if needed
82
+ initialPageParam: undefined,
83
+ getNextPageParam: lastPage => lastPage.nextPageParam,
84
+ // additional options...
85
+ }))
86
+
87
+ const mutation = useMutation(orpc.planet.create.mutationOptions({
88
+ context: { cache: true }, // Provide client context if needed
89
+ // additional options...
90
+ }))
91
+
92
+ mutation.mutate({ name: 'Earth' })
93
+
94
+ const queryClient = useQueryClient()
95
+
96
+ // Invalidate all planet queries
97
+ queryClient.invalidateQueries({
98
+ queryKey: orpc.planet.key(),
99
+ })
100
+
101
+ // Invalidate only regular (non-infinite) planet queries
102
+ queryClient.invalidateQueries({
103
+ queryKey: orpc.planet.key({ type: 'query' })
104
+ })
105
+
106
+ // Invalidate the planet find query with id 123
107
+ queryClient.invalidateQueries({
108
+ queryKey: orpc.planet.find.key({ input: { id: 123 } })
109
+ })
110
+ }
111
+ ```
112
+
113
+ ## Sponsors
114
+
115
+ <p align="center">
116
+ <a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
117
+ <img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
118
+ </a>
119
+ </p>
120
+
121
+ ## License
122
+
123
+ Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
@@ -0,0 +1,128 @@
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, 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 InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = (Record<never, never> extends TClientContext ? {
48
+ context?: MaybeRefDeep<TClientContext>;
49
+ } : {
50
+ context: MaybeRefDeep<TClientContext>;
51
+ }) & {
52
+ [Property in keyof Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey' | 'enabled'>]: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>[Property]>;
53
+ } & {
54
+ input: MaybeRef<((pageParam: TPageParam) => MaybeRefDeep<TInput>) | SkipToken>;
55
+ enabled?: MaybeRefOrGetter<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>['enabled']>;
56
+ queryKey?: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>['queryKey']>;
57
+ shallow?: boolean;
58
+ };
59
+ interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
60
+ queryKey: ComputedRef<QueryKey>;
61
+ queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
62
+ throwOnError?(error: TError): boolean;
63
+ retryDelay?: (count: number, error: TError) => number;
64
+ enabled: ComputedRef<boolean | undefined>;
65
+ }
66
+ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
67
+ context?: TClientContext;
68
+ } : {
69
+ context: TClientContext;
70
+ }) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
71
+ type MutationOptions<TInput, TOutput, TError, TMutationContext> = {
72
+ [P in keyof MutationObserverOptions<TOutput, TError, TInput, TMutationContext>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput, TMutationContext>[P]>;
73
+ } & {
74
+ shallow?: MaybeRef<boolean>;
75
+ };
76
+
77
+ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
78
+ /**
79
+ * Calling corresponding procedure client
80
+ *
81
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
82
+ */
83
+ call: Client<TClientContext, TInput, TOutput, TError>;
84
+ /**
85
+ * Generate options used for useQuery/prefetchQuery/...
86
+ *
87
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-options-utility Tanstack Query Options Utility Docs}
88
+ */
89
+ queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
90
+ /**
91
+ * Generate options used for useInfiniteQuery/prefetchInfiniteQuery/...
92
+ *
93
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
94
+ */
95
+ 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>>;
96
+ /**
97
+ * Generate options used for useMutation/...
98
+ *
99
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#mutation-options Tanstack Mutation Options Docs}
100
+ */
101
+ mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
102
+ }
103
+ interface CreateProcedureUtilsOptions {
104
+ path: string[];
105
+ }
106
+ declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
107
+
108
+ type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
109
+ [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
110
+ } & GeneralUtils<unknown>;
111
+ interface CreateRouterUtilsOptions {
112
+ path?: string[];
113
+ }
114
+ /**
115
+ * Create a router utils from a client.
116
+ *
117
+ * @info Both client-side and server-side clients are supported.
118
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/vue Tanstack Query Vue Docs}
119
+ */
120
+ declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
121
+
122
+ type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunction ? T : T extends object ? {
123
+ [K in keyof T]: UnrefDeep<T[K]>;
124
+ } : T;
125
+ declare function unrefDeep<T>(value: T): UnrefDeep<T>;
126
+
127
+ export { createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
128
+ export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MaybeRefDeep, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, UnrefDeep };
@@ -0,0 +1,128 @@
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, 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 InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = (Record<never, never> extends TClientContext ? {
48
+ context?: MaybeRefDeep<TClientContext>;
49
+ } : {
50
+ context: MaybeRefDeep<TClientContext>;
51
+ }) & {
52
+ [Property in keyof Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey' | 'enabled'>]: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>[Property]>;
53
+ } & {
54
+ input: MaybeRef<((pageParam: TPageParam) => MaybeRefDeep<TInput>) | SkipToken>;
55
+ enabled?: MaybeRefOrGetter<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>['enabled']>;
56
+ queryKey?: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>['queryKey']>;
57
+ shallow?: boolean;
58
+ };
59
+ interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
60
+ queryKey: ComputedRef<QueryKey>;
61
+ queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
62
+ throwOnError?(error: TError): boolean;
63
+ retryDelay?: (count: number, error: TError) => number;
64
+ enabled: ComputedRef<boolean | undefined>;
65
+ }
66
+ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
67
+ context?: TClientContext;
68
+ } : {
69
+ context: TClientContext;
70
+ }) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
71
+ type MutationOptions<TInput, TOutput, TError, TMutationContext> = {
72
+ [P in keyof MutationObserverOptions<TOutput, TError, TInput, TMutationContext>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput, TMutationContext>[P]>;
73
+ } & {
74
+ shallow?: MaybeRef<boolean>;
75
+ };
76
+
77
+ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
78
+ /**
79
+ * Calling corresponding procedure client
80
+ *
81
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
82
+ */
83
+ call: Client<TClientContext, TInput, TOutput, TError>;
84
+ /**
85
+ * Generate options used for useQuery/prefetchQuery/...
86
+ *
87
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-options-utility Tanstack Query Options Utility Docs}
88
+ */
89
+ queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
90
+ /**
91
+ * Generate options used for useInfiniteQuery/prefetchInfiniteQuery/...
92
+ *
93
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
94
+ */
95
+ 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>>;
96
+ /**
97
+ * Generate options used for useMutation/...
98
+ *
99
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#mutation-options Tanstack Mutation Options Docs}
100
+ */
101
+ mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
102
+ }
103
+ interface CreateProcedureUtilsOptions {
104
+ path: string[];
105
+ }
106
+ declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
107
+
108
+ type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
109
+ [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
110
+ } & GeneralUtils<unknown>;
111
+ interface CreateRouterUtilsOptions {
112
+ path?: string[];
113
+ }
114
+ /**
115
+ * Create a router utils from a client.
116
+ *
117
+ * @info Both client-side and server-side clients are supported.
118
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/vue Tanstack Query Vue Docs}
119
+ */
120
+ declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
121
+
122
+ type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunction ? T : T extends object ? {
123
+ [K in keyof T]: UnrefDeep<T[K]>;
124
+ } : T;
125
+ declare function unrefDeep<T>(value: T): UnrefDeep<T>;
126
+
127
+ export { createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
128
+ export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MaybeRefDeep, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, UnrefDeep };
package/dist/index.mjs ADDED
@@ -0,0 +1,105 @@
1
+ import { generateOperationKey } from '@orpc/tanstack-query';
2
+ export { generateOperationKey as buildKey } from '@orpc/tanstack-query';
3
+ import { skipToken } from '@tanstack/vue-query';
4
+ import { isRef, computed } from 'vue';
5
+ import { isObject } from '@orpc/shared';
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
+ infiniteOptions(optionsIn) {
49
+ return {
50
+ queryKey: computed(() => {
51
+ const input = unrefDeep(optionsIn.input);
52
+ return generateOperationKey(options.path, {
53
+ type: "infinite",
54
+ input: input === skipToken ? skipToken : unrefDeep(input(unrefDeep(optionsIn.initialPageParam)))
55
+ });
56
+ }),
57
+ queryFn: ({ pageParam, signal }) => {
58
+ const input = unrefDeep(optionsIn.input);
59
+ if (input === skipToken) {
60
+ throw new Error("queryFn should not be called with skipToken used as input");
61
+ }
62
+ return client(unrefDeep(input(pageParam)), { signal, context: unrefDeep(optionsIn.context) });
63
+ },
64
+ enabled: computed(() => unrefDeep(optionsIn.input) === skipToken ? false : void 0),
65
+ ...optionsIn
66
+ };
67
+ },
68
+ mutationOptions(...[optionsIn = {}]) {
69
+ return {
70
+ mutationKey: generateOperationKey(options.path, { type: "mutation" }),
71
+ mutationFn: (input) => client(input, { context: unrefDeep(optionsIn.context) }),
72
+ ...optionsIn
73
+ };
74
+ }
75
+ };
76
+ }
77
+
78
+ function createRouterUtils(client, options = {}) {
79
+ const path = options.path ?? [];
80
+ const generalUtils = createGeneralUtils(path);
81
+ const procedureUtils = createProcedureUtils(client, { path });
82
+ const recursive = new Proxy({
83
+ ...generalUtils,
84
+ ...procedureUtils
85
+ }, {
86
+ get(target, prop) {
87
+ const value = Reflect.get(target, prop);
88
+ if (typeof prop !== "string") {
89
+ return value;
90
+ }
91
+ const nextUtils = createRouterUtils(client[prop], { ...options, path: [...path, prop] });
92
+ if (typeof value !== "function") {
93
+ return nextUtils;
94
+ }
95
+ return new Proxy(value, {
96
+ get(_, prop2) {
97
+ return Reflect.get(nextUtils, prop2);
98
+ }
99
+ });
100
+ }
101
+ });
102
+ return recursive;
103
+ }
104
+
105
+ export { createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/vue-query",
3
3
  "type": "module",
4
- "version": "0.0.0-next.e361acd",
4
+ "version": "0.0.0-next.e39a46e",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -18,28 +18,28 @@
18
18
  ],
19
19
  "exports": {
20
20
  ".": {
21
- "types": "./dist/src/index.d.ts",
22
- "import": "./dist/index.js",
23
- "default": "./dist/index.js"
24
- },
25
- "./🔒/*": {
26
- "types": "./dist/src/*.d.ts"
21
+ "types": "./dist/index.d.mts",
22
+ "import": "./dist/index.mjs",
23
+ "default": "./dist/index.mjs"
27
24
  }
28
25
  },
29
26
  "files": [
30
- "!**/*.map",
31
- "!**/*.tsbuildinfo",
32
27
  "dist"
33
28
  ],
34
29
  "peerDependencies": {
35
- "@tanstack/vue-query": ">=5.50.0",
30
+ "@tanstack/vue-query": ">=5.80.2",
36
31
  "vue": ">=3.3.0",
37
- "@orpc/client": "0.0.0-next.e361acd",
38
- "@orpc/contract": "0.0.0-next.e361acd",
39
- "@orpc/server": "0.0.0-next.e361acd"
32
+ "@orpc/client": "0.0.0-next.e39a46e"
33
+ },
34
+ "dependencies": {
35
+ "@orpc/tanstack-query": "0.0.0-next.e39a46e",
36
+ "@orpc/shared": "0.0.0-next.e39a46e"
37
+ },
38
+ "devDependencies": {
39
+ "@tanstack/vue-query": "^5.90.2"
40
40
  },
41
41
  "scripts": {
42
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
42
+ "build": "unbuild",
43
43
  "build:watch": "pnpm run build --watch",
44
44
  "type:check": "tsc -b"
45
45
  }
package/dist/index.js DELETED
@@ -1,108 +0,0 @@
1
- // src/key.ts
2
- function buildKey(path, options) {
3
- const withInput = options?.input !== void 0 ? { input: options?.input } : {};
4
- const withType = options?.type !== void 0 ? { type: options?.type } : {};
5
- return [
6
- "__ORPC__",
7
- path,
8
- {
9
- ...withInput,
10
- ...withType
11
- }
12
- ];
13
- }
14
-
15
- // src/utils.ts
16
- import { isRef } from "vue";
17
- function deepUnref(value) {
18
- if (isRef(value)) {
19
- return deepUnref(value.value);
20
- }
21
- if (Array.isArray(value)) {
22
- return value.map(deepUnref);
23
- }
24
- if (value && typeof value === "object") {
25
- return Object.keys(value).reduce((acc, key) => {
26
- acc[key] = deepUnref(value[key]);
27
- return acc;
28
- }, {});
29
- }
30
- return value;
31
- }
32
-
33
- // src/utils-general.ts
34
- function createGeneralUtils(path) {
35
- return {
36
- key(options) {
37
- return buildKey(path, deepUnref(options));
38
- }
39
- };
40
- }
41
-
42
- // src/utils-procedure.ts
43
- import { computed } from "vue";
44
- function createProcedureUtils(client, path) {
45
- return {
46
- queryOptions(...[options]) {
47
- const input = options?.input;
48
- return {
49
- queryKey: computed(() => buildKey(path, { type: "query", input: deepUnref(input) })),
50
- queryFn: ({ signal }) => client(deepUnref(input), { signal }),
51
- ...options
52
- };
53
- },
54
- infiniteOptions(options) {
55
- const input = options.input;
56
- return {
57
- queryKey: computed(() => buildKey(path, { type: "infinite", input: deepUnref(input) })),
58
- queryFn: ({ pageParam, signal }) => client({ ...deepUnref(input), cursor: pageParam }, { signal }),
59
- ...options
60
- };
61
- },
62
- mutationOptions(options) {
63
- return {
64
- mutationKey: buildKey(path, { type: "mutation" }),
65
- mutationFn: (input) => client(input),
66
- ...options
67
- };
68
- }
69
- };
70
- }
71
-
72
- // src/utils-router.ts
73
- function createRouterUtils(client, path = []) {
74
- const generalUtils = createGeneralUtils(path);
75
- const procedureUtils = createProcedureUtils(client, path);
76
- const recursive = new Proxy({
77
- ...generalUtils,
78
- ...procedureUtils
79
- }, {
80
- get(target, prop) {
81
- const value = Reflect.get(target, prop);
82
- if (typeof prop !== "string") {
83
- return value;
84
- }
85
- const nextUtils = createRouterUtils(client[prop], [...path, prop]);
86
- if (typeof value !== "function") {
87
- return nextUtils;
88
- }
89
- return new Proxy(value, {
90
- get(_, prop2) {
91
- return Reflect.get(nextUtils, prop2);
92
- }
93
- });
94
- }
95
- });
96
- return recursive;
97
- }
98
-
99
- // src/index.ts
100
- var createORPCVueQueryUtils = createRouterUtils;
101
- export {
102
- buildKey,
103
- createGeneralUtils,
104
- createORPCVueQueryUtils,
105
- createProcedureUtils,
106
- createRouterUtils
107
- };
108
- //# sourceMappingURL=index.js.map
@@ -1,8 +0,0 @@
1
- import { createRouterUtils } from './utils-router';
2
- export * from './key';
3
- export * from './types';
4
- export * from './utils-general';
5
- export * from './utils-procedure';
6
- export * from './utils-router';
7
- export declare const createORPCVueQueryUtils: typeof createRouterUtils;
8
- //# sourceMappingURL=index.d.ts.map
package/dist/src/key.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import type { PartialDeep } from '@orpc/shared';
2
- import type { QueryKey } from '@tanstack/vue-query';
3
- export type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
4
- export interface BuildKeyOptions<TType extends KeyType, TInput> {
5
- type?: TType;
6
- input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
7
- }
8
- export declare function buildKey<TType extends KeyType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
9
- //# sourceMappingURL=key.d.ts.map
@@ -1,31 +0,0 @@
1
- import type { AnyFunction, SetOptional } from '@orpc/shared';
2
- import type { DefaultError, MutationObserverOptions, QueryKey, QueryObserverOptions, UseInfiniteQueryOptions } from '@tanstack/vue-query';
3
- import type { MaybeRef, MaybeRefOrGetter } from 'vue';
4
- export type MaybeDeepRef<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
5
- [K in keyof T]: MaybeDeepRef<T[K]>;
6
- } : T>;
7
- export type NonUndefinedGuard<T> = T extends undefined ? never : T;
8
- export type InferCursor<T> = T extends {
9
- cursor?: any;
10
- } ? T['cursor'] : never;
11
- export type QueryOptions<TInput, TOutput, TSelectData> = (undefined extends TInput ? {
12
- input?: MaybeDeepRef<TInput>;
13
- } : {
14
- input: MaybeDeepRef<TInput>;
15
- }) & SetOptional<{
16
- [P in keyof QueryObserverOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey>]: P extends 'enabled' ? MaybeRefOrGetter<QueryObserverOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey>[P]> : MaybeDeepRef<QueryObserverOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey>[P]>;
17
- }, 'queryKey'> & {
18
- shallow?: MaybeRef<boolean>;
19
- initialData?: NonUndefinedGuard<TOutput> | (() => NonUndefinedGuard<TOutput>) | undefined;
20
- };
21
- export type InfiniteOptions<TInput, TOutput, TSelectData> = (undefined extends TInput ? {
22
- input?: MaybeDeepRef<Omit<TInput, 'cursor'>>;
23
- } : {
24
- input: MaybeDeepRef<Omit<TInput, 'cursor'>>;
25
- }) & SetOptional<UseInfiniteQueryOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey, InferCursor<TInput>>, 'queryKey' | (undefined extends InferCursor<TInput> ? 'initialPageParam' : never)>;
26
- export type MutationOptions<TInput, TOutput> = {
27
- [P in keyof MutationObserverOptions<TOutput, DefaultError, TInput, unknown>]: MaybeDeepRef<MutationObserverOptions<TOutput, DefaultError, TInput, unknown>[P]>;
28
- } & {
29
- shallow?: MaybeRef<boolean>;
30
- };
31
- //# sourceMappingURL=types.d.ts.map
@@ -1,11 +0,0 @@
1
- import type { QueryKey } from '@tanstack/vue-query';
2
- import type { BuildKeyOptions, KeyType } from './key';
3
- import type { MaybeDeepRef } from './types';
4
- /**
5
- * Utils at any level (procedure or router)
6
- */
7
- export interface GeneralUtils<TInput> {
8
- key: <UType extends KeyType = undefined>(options?: MaybeDeepRef<BuildKeyOptions<UType, TInput>>) => QueryKey;
9
- }
10
- export declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
11
- //# sourceMappingURL=utils-general.d.ts.map
@@ -1,31 +0,0 @@
1
- import type { ProcedureClient } from '@orpc/server';
2
- import type { IsEqual } from '@orpc/shared';
3
- import type { QueryKey } from '@tanstack/vue-query';
4
- import type { ComputedRef } from 'vue';
5
- import type { InfiniteOptions, MutationOptions, QueryOptions } from './types';
6
- /**
7
- * Utils at procedure level
8
- */
9
- export interface ProcedureUtils<TInput, TOutput> {
10
- queryOptions: <U extends QueryOptions<TInput, TOutput, any>>(...options: [U] | (undefined extends TInput ? [] : never)) => IsEqual<U, QueryOptions<TInput, TOutput, any>> extends true ? {
11
- queryKey: QueryKey;
12
- queryFn: () => Promise<TOutput>;
13
- } : Omit<{
14
- queryKey: ComputedRef<QueryKey>;
15
- queryFn: () => Promise<TOutput>;
16
- }, keyof U> & U;
17
- infiniteOptions: <U extends InfiniteOptions<TInput, TOutput, any>>(options: U) => Omit<{
18
- queryKey: ComputedRef<QueryKey>;
19
- queryFn: () => Promise<TOutput>;
20
- initialPageParam: undefined;
21
- }, keyof U> & U;
22
- mutationOptions: <U extends MutationOptions<TInput, TOutput>>(options?: U) => IsEqual<U, MutationOptions<TInput, TOutput>> extends true ? {
23
- mutationKey: QueryKey;
24
- mutationFn: (input: TInput) => Promise<TOutput>;
25
- } : Omit<{
26
- mutationKey: QueryKey;
27
- mutationFn: (input: TInput) => Promise<TOutput>;
28
- }, keyof U> & U;
29
- }
30
- export declare function createProcedureUtils<TInput, TOutput>(client: ProcedureClient<TInput, TOutput>, path: string[]): ProcedureUtils<TInput, TOutput>;
31
- //# sourceMappingURL=utils-procedure.d.ts.map
@@ -1,12 +0,0 @@
1
- import type { ProcedureClient, RouterClient } from '@orpc/server';
2
- import { type GeneralUtils } from './utils-general';
3
- import { type ProcedureUtils } from './utils-procedure';
4
- export type RouterUtils<T extends RouterClient<any>> = T extends ProcedureClient<infer TInput, infer TOutput> ? ProcedureUtils<TInput, TOutput> & GeneralUtils<TInput> : {
5
- [K in keyof T]: T[K] extends RouterClient<any> ? RouterUtils<T[K]> : never;
6
- } & GeneralUtils<unknown>;
7
- /**
8
- * @param client - The client create form `@orpc/client`
9
- * @param path - The base path for query key
10
- */
11
- export declare function createRouterUtils<T extends RouterClient<any>>(client: T, path?: string[]): RouterUtils<T>;
12
- //# sourceMappingURL=utils-router.d.ts.map
@@ -1,7 +0,0 @@
1
- import type { AnyFunction } from '@orpc/shared';
2
- import type { Ref } from 'vue';
3
- export type DeepUnref<T> = T extends Ref<infer U> ? DeepUnref<U> : T extends AnyFunction ? T : T extends object ? {
4
- [K in keyof T]: DeepUnref<T[K]>;
5
- } : T;
6
- export declare function deepUnref<T>(value: T): DeepUnref<T>;
7
- //# sourceMappingURL=utils.d.ts.map