@orpc/vue-query 0.0.0-next.fd117b2 → 0.0.0-next.fd13879

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 />
2
+ <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
3
3
  </div>
4
4
 
5
5
  <h1></h1>
@@ -21,28 +21,24 @@
21
21
 
22
22
  <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
23
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, ensuring a smooth and enjoyable developer experience.
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
25
 
26
26
  ---
27
27
 
28
28
  ## Highlights
29
29
 
30
- - **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
31
- - **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
32
- - **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
33
- - **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
34
- - **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
35
- - **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue), Pinia Colada, and more.
36
- - **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
37
- - **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
38
- - **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
39
- - **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
40
- - **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
41
- - **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
42
- - **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
43
- - **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
44
- - **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
45
- - **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
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
+ - **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
34
+ - **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
35
+ - **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
36
+ - **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
37
+ - **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
38
+ - **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
39
+ - **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
40
+ - **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
41
+ - **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
46
42
 
47
43
  ## Documentation
48
44
 
@@ -53,11 +49,17 @@ You can find the full documentation [here](https://orpc.unnoq.com).
53
49
  - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
50
  - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
51
  - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
52
+ - [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with NestJS.
53
+ - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
56
54
  - [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
57
55
  - [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
56
+ - [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
57
+ - [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
58
58
  - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
59
59
  - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
60
60
  - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
61
+ - [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
62
+ - [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
61
63
 
62
64
  ## `@orpc/vue-query`
63
65
 
@@ -105,6 +107,14 @@ export function Setup() {
105
107
  }
106
108
  ```
107
109
 
110
+ ## Sponsors
111
+
112
+ <p align="center">
113
+ <a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
114
+ <img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
115
+ </a>
116
+ </p>
117
+
108
118
  ## License
109
119
 
110
120
  Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
@@ -0,0 +1,131 @@
1
+ import { ClientContext, Client, NestedClient } from '@orpc/client';
2
+ import { QueryKey, SkipToken, QueryObserverOptions, QueryFunctionContext, InfiniteQueryObserverOptions, MutationObserverOptions, InfiniteData } from '@tanstack/vue-query';
3
+ import { PartialDeep, AnyFunction, MaybeOptionalOptions } from '@orpc/shared';
4
+ import { MaybeRef, MaybeRefOrGetter, ComputedRef, Ref } from 'vue';
5
+
6
+ type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
7
+ interface BuildKeyOptions<TType extends KeyType, TInput> {
8
+ type?: TType;
9
+ input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
10
+ }
11
+ declare function buildKey<TType extends KeyType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
12
+
13
+ interface GeneralUtils<TInput> {
14
+ /**
15
+ * Generate a query/mutation key for checking status, invalidate, set, get, etc.
16
+ *
17
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
18
+ */
19
+ key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
20
+ }
21
+ declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
22
+
23
+ /**
24
+ * Since `@tanstack/vue-query` is not exporting the type `MaybeRefDeep` we need to copy it from the source code.
25
+ * https://github.com/TanStack/query/blob/7ff544e12e79388e513b1cd886aeb946f80f0153/packages/vue-query/src/types.ts#L19C1-L27C2
26
+ */
27
+ type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
28
+ [Property in keyof T]: MaybeRefDeep<T[Property]>;
29
+ } : T>;
30
+ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
31
+ input?: MaybeRefDeep<TInput | SkipToken>;
32
+ } : {
33
+ input: MaybeRefDeep<TInput | SkipToken>;
34
+ }) & (Record<never, never> extends TClientContext ? {
35
+ context?: MaybeRefDeep<TClientContext>;
36
+ } : {
37
+ context: MaybeRefDeep<TClientContext>;
38
+ }) & {
39
+ [P in keyof Omit<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>, 'queryKey' | 'enabled'>]: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>[P]>;
40
+ } & {
41
+ enabled?: MaybeRefOrGetter<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['enabled']>;
42
+ queryKey?: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['queryKey']>;
43
+ shallow?: boolean;
44
+ };
45
+ interface QueryOptionsBase<TOutput, TError> {
46
+ queryKey: ComputedRef<QueryKey>;
47
+ queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
48
+ retry?(failureCount: number, error: TError): boolean;
49
+ enabled: ComputedRef<boolean>;
50
+ }
51
+ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = (Record<never, never> extends TClientContext ? {
52
+ context?: MaybeRefDeep<TClientContext>;
53
+ } : {
54
+ context: MaybeRefDeep<TClientContext>;
55
+ }) & {
56
+ [Property in keyof Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey' | 'enabled'>]: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>[Property]>;
57
+ } & {
58
+ input: MaybeRef<((pageParam: TPageParam) => MaybeRefDeep<TInput>) | SkipToken>;
59
+ enabled?: MaybeRefOrGetter<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>['enabled']>;
60
+ queryKey?: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>['queryKey']>;
61
+ shallow?: boolean;
62
+ };
63
+ interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
64
+ queryKey: ComputedRef<QueryKey>;
65
+ queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
66
+ retry?(failureCount: number, error: TError): boolean;
67
+ enabled: ComputedRef<boolean>;
68
+ }
69
+ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
70
+ context?: TClientContext;
71
+ } : {
72
+ context: TClientContext;
73
+ }) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
74
+ type MutationOptions<TInput, TOutput, TError, TMutationContext> = {
75
+ [P in keyof MutationObserverOptions<TOutput, TError, TInput, TMutationContext>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput, TMutationContext>[P]>;
76
+ } & {
77
+ shallow?: MaybeRef<boolean>;
78
+ };
79
+
80
+ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
81
+ /**
82
+ * Calling corresponding procedure client
83
+ *
84
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
85
+ */
86
+ call: Client<TClientContext, TInput, TOutput, TError>;
87
+ /**
88
+ * Generate options used for useQuery/prefetchQuery/...
89
+ *
90
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-options-utility Tanstack Query Options Utility Docs}
91
+ */
92
+ queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
93
+ /**
94
+ * Generate options used for useInfiniteQuery/prefetchInfiniteQuery/...
95
+ *
96
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
97
+ */
98
+ 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>>;
99
+ /**
100
+ * Generate options used for useMutation/...
101
+ *
102
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#mutation-options Tanstack Mutation Options Docs}
103
+ */
104
+ mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
105
+ }
106
+ interface CreateProcedureUtilsOptions {
107
+ path: string[];
108
+ }
109
+ declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
110
+
111
+ type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
112
+ [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
113
+ } & GeneralUtils<unknown>;
114
+ interface CreateRouterUtilsOptions {
115
+ path?: string[];
116
+ }
117
+ /**
118
+ * Create a router utils from a client.
119
+ *
120
+ * @info Both client-side and server-side clients are supported.
121
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/vue Tanstack Query Vue Docs}
122
+ */
123
+ declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
124
+
125
+ type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunction ? T : T extends object ? {
126
+ [K in keyof T]: UnrefDeep<T[K]>;
127
+ } : T;
128
+ declare function unrefDeep<T>(value: T): UnrefDeep<T>;
129
+
130
+ export { buildKey, createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
131
+ export type { BuildKeyOptions, CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, KeyType, MaybeRefDeep, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, UnrefDeep };
@@ -0,0 +1,131 @@
1
+ import { ClientContext, Client, NestedClient } from '@orpc/client';
2
+ import { QueryKey, SkipToken, QueryObserverOptions, QueryFunctionContext, InfiniteQueryObserverOptions, MutationObserverOptions, InfiniteData } from '@tanstack/vue-query';
3
+ import { PartialDeep, AnyFunction, MaybeOptionalOptions } from '@orpc/shared';
4
+ import { MaybeRef, MaybeRefOrGetter, ComputedRef, Ref } from 'vue';
5
+
6
+ type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
7
+ interface BuildKeyOptions<TType extends KeyType, TInput> {
8
+ type?: TType;
9
+ input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
10
+ }
11
+ declare function buildKey<TType extends KeyType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
12
+
13
+ interface GeneralUtils<TInput> {
14
+ /**
15
+ * Generate a query/mutation key for checking status, invalidate, set, get, etc.
16
+ *
17
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
18
+ */
19
+ key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
20
+ }
21
+ declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
22
+
23
+ /**
24
+ * Since `@tanstack/vue-query` is not exporting the type `MaybeRefDeep` we need to copy it from the source code.
25
+ * https://github.com/TanStack/query/blob/7ff544e12e79388e513b1cd886aeb946f80f0153/packages/vue-query/src/types.ts#L19C1-L27C2
26
+ */
27
+ type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
28
+ [Property in keyof T]: MaybeRefDeep<T[Property]>;
29
+ } : T>;
30
+ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
31
+ input?: MaybeRefDeep<TInput | SkipToken>;
32
+ } : {
33
+ input: MaybeRefDeep<TInput | SkipToken>;
34
+ }) & (Record<never, never> extends TClientContext ? {
35
+ context?: MaybeRefDeep<TClientContext>;
36
+ } : {
37
+ context: MaybeRefDeep<TClientContext>;
38
+ }) & {
39
+ [P in keyof Omit<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>, 'queryKey' | 'enabled'>]: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>[P]>;
40
+ } & {
41
+ enabled?: MaybeRefOrGetter<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['enabled']>;
42
+ queryKey?: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['queryKey']>;
43
+ shallow?: boolean;
44
+ };
45
+ interface QueryOptionsBase<TOutput, TError> {
46
+ queryKey: ComputedRef<QueryKey>;
47
+ queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
48
+ retry?(failureCount: number, error: TError): boolean;
49
+ enabled: ComputedRef<boolean>;
50
+ }
51
+ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = (Record<never, never> extends TClientContext ? {
52
+ context?: MaybeRefDeep<TClientContext>;
53
+ } : {
54
+ context: MaybeRefDeep<TClientContext>;
55
+ }) & {
56
+ [Property in keyof Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey' | 'enabled'>]: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>[Property]>;
57
+ } & {
58
+ input: MaybeRef<((pageParam: TPageParam) => MaybeRefDeep<TInput>) | SkipToken>;
59
+ enabled?: MaybeRefOrGetter<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>['enabled']>;
60
+ queryKey?: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>['queryKey']>;
61
+ shallow?: boolean;
62
+ };
63
+ interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
64
+ queryKey: ComputedRef<QueryKey>;
65
+ queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
66
+ retry?(failureCount: number, error: TError): boolean;
67
+ enabled: ComputedRef<boolean>;
68
+ }
69
+ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
70
+ context?: TClientContext;
71
+ } : {
72
+ context: TClientContext;
73
+ }) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
74
+ type MutationOptions<TInput, TOutput, TError, TMutationContext> = {
75
+ [P in keyof MutationObserverOptions<TOutput, TError, TInput, TMutationContext>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput, TMutationContext>[P]>;
76
+ } & {
77
+ shallow?: MaybeRef<boolean>;
78
+ };
79
+
80
+ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
81
+ /**
82
+ * Calling corresponding procedure client
83
+ *
84
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
85
+ */
86
+ call: Client<TClientContext, TInput, TOutput, TError>;
87
+ /**
88
+ * Generate options used for useQuery/prefetchQuery/...
89
+ *
90
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-options-utility Tanstack Query Options Utility Docs}
91
+ */
92
+ queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
93
+ /**
94
+ * Generate options used for useInfiniteQuery/prefetchInfiniteQuery/...
95
+ *
96
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
97
+ */
98
+ 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>>;
99
+ /**
100
+ * Generate options used for useMutation/...
101
+ *
102
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#mutation-options Tanstack Mutation Options Docs}
103
+ */
104
+ mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
105
+ }
106
+ interface CreateProcedureUtilsOptions {
107
+ path: string[];
108
+ }
109
+ declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
110
+
111
+ type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
112
+ [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
113
+ } & GeneralUtils<unknown>;
114
+ interface CreateRouterUtilsOptions {
115
+ path?: string[];
116
+ }
117
+ /**
118
+ * Create a router utils from a client.
119
+ *
120
+ * @info Both client-side and server-side clients are supported.
121
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/vue Tanstack Query Vue Docs}
122
+ */
123
+ declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
124
+
125
+ type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunction ? T : T extends object ? {
126
+ [K in keyof T]: UnrefDeep<T[K]>;
127
+ } : T;
128
+ declare function unrefDeep<T>(value: T): UnrefDeep<T>;
129
+
130
+ export { buildKey, createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
131
+ export type { BuildKeyOptions, CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, KeyType, MaybeRefDeep, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, UnrefDeep };
package/dist/index.mjs ADDED
@@ -0,0 +1,112 @@
1
+ import { skipToken } from '@tanstack/vue-query';
2
+ import { isRef, computed } from 'vue';
3
+ import { isObject } from '@orpc/shared';
4
+
5
+ function buildKey(path, options) {
6
+ const withInput = options?.input !== void 0 ? { input: options?.input } : {};
7
+ const withType = options?.type !== void 0 ? { type: options?.type } : {};
8
+ return [path, {
9
+ ...withInput,
10
+ ...withType
11
+ }];
12
+ }
13
+
14
+ function createGeneralUtils(path) {
15
+ return {
16
+ key(options) {
17
+ return buildKey(path, options);
18
+ }
19
+ };
20
+ }
21
+
22
+ function unrefDeep(value) {
23
+ if (isRef(value)) {
24
+ return unrefDeep(value.value);
25
+ }
26
+ if (Array.isArray(value)) {
27
+ return value.map(unrefDeep);
28
+ }
29
+ if (isObject(value)) {
30
+ return Object.keys(value).reduce((acc, key) => {
31
+ acc[key] = unrefDeep(value[key]);
32
+ return acc;
33
+ }, {});
34
+ }
35
+ return value;
36
+ }
37
+
38
+ function createProcedureUtils(client, options) {
39
+ return {
40
+ call: client,
41
+ queryOptions(...[optionsIn = {}]) {
42
+ return {
43
+ queryKey: computed(() => buildKey(options.path, { type: "query", input: unrefDeep(optionsIn.input) })),
44
+ queryFn: ({ signal }) => {
45
+ const input = unrefDeep(optionsIn.input);
46
+ if (input === skipToken) {
47
+ throw new Error("queryFn should not be called with skipToken used as input");
48
+ }
49
+ return client(input, { signal, context: unrefDeep(optionsIn.context) });
50
+ },
51
+ enabled: computed(() => unrefDeep(optionsIn.input) !== skipToken),
52
+ ...optionsIn
53
+ };
54
+ },
55
+ infiniteOptions(optionsIn) {
56
+ return {
57
+ queryKey: computed(() => {
58
+ const input = unrefDeep(optionsIn.input);
59
+ return buildKey(options.path, {
60
+ type: "infinite",
61
+ input: input === skipToken ? skipToken : unrefDeep(input(unrefDeep(optionsIn.initialPageParam)))
62
+ });
63
+ }),
64
+ queryFn: ({ pageParam, signal }) => {
65
+ const input = unrefDeep(optionsIn.input);
66
+ if (input === skipToken) {
67
+ throw new Error("queryFn should not be called with skipToken used as input");
68
+ }
69
+ return client(unrefDeep(input(pageParam)), { signal, context: unrefDeep(optionsIn.context) });
70
+ },
71
+ enabled: computed(() => unrefDeep(optionsIn.input) !== skipToken),
72
+ ...optionsIn
73
+ };
74
+ },
75
+ mutationOptions(...[optionsIn = {}]) {
76
+ return {
77
+ mutationKey: buildKey(options.path, { type: "mutation" }),
78
+ mutationFn: (input) => client(input, { context: unrefDeep(optionsIn.context) }),
79
+ ...optionsIn
80
+ };
81
+ }
82
+ };
83
+ }
84
+
85
+ function createRouterUtils(client, options = {}) {
86
+ const path = options.path ?? [];
87
+ const generalUtils = createGeneralUtils(path);
88
+ const procedureUtils = createProcedureUtils(client, { path });
89
+ const recursive = new Proxy({
90
+ ...generalUtils,
91
+ ...procedureUtils
92
+ }, {
93
+ get(target, prop) {
94
+ const value = Reflect.get(target, prop);
95
+ if (typeof prop !== "string") {
96
+ return value;
97
+ }
98
+ const nextUtils = createRouterUtils(client[prop], { ...options, path: [...path, prop] });
99
+ if (typeof value !== "function") {
100
+ return nextUtils;
101
+ }
102
+ return new Proxy(value, {
103
+ get(_, prop2) {
104
+ return Reflect.get(nextUtils, prop2);
105
+ }
106
+ });
107
+ }
108
+ });
109
+ return recursive;
110
+ }
111
+
112
+ export { buildKey, 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.fd117b2",
4
+ "version": "0.0.0-next.fd13879",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -18,29 +18,25 @@
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.55.0",
36
31
  "vue": ">=3.3.0",
37
- "@orpc/client": "0.0.0-next.fd117b2"
32
+ "@orpc/client": "0.0.0-next.fd13879"
38
33
  },
39
34
  "dependencies": {
40
- "@orpc/shared": "0.0.0-next.fd117b2"
35
+ "@tanstack/vue-query": "^5.72.3",
36
+ "@orpc/shared": "0.0.0-next.fd13879"
41
37
  },
42
38
  "scripts": {
43
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
39
+ "build": "unbuild",
44
40
  "build:watch": "pnpm run build --watch",
45
41
  "type:check": "tsc -b"
46
42
  }
package/dist/index.js DELETED
@@ -1,110 +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 [path, {
6
- ...withInput,
7
- ...withType
8
- }];
9
- }
10
-
11
- // src/general-utils.ts
12
- function createGeneralUtils(path) {
13
- return {
14
- key(options) {
15
- return buildKey(path, options);
16
- }
17
- };
18
- }
19
-
20
- // src/procedure-utils.ts
21
- import { computed } from "vue";
22
-
23
- // src/utils.ts
24
- import { isObject } from "@orpc/shared";
25
- import { isRef } from "vue";
26
- function unrefDeep(value) {
27
- if (isRef(value)) {
28
- return unrefDeep(value.value);
29
- }
30
- if (Array.isArray(value)) {
31
- return value.map(unrefDeep);
32
- }
33
- if (isObject(value)) {
34
- return Object.keys(value).reduce((acc, key) => {
35
- acc[key] = unrefDeep(value[key]);
36
- return acc;
37
- }, {});
38
- }
39
- return value;
40
- }
41
-
42
- // src/procedure-utils.ts
43
- function createProcedureUtils(client, path) {
44
- return {
45
- call: client,
46
- queryOptions(...[{ input, context, ...rest } = {}]) {
47
- return {
48
- queryKey: computed(() => buildKey(path, { type: "query", input: unrefDeep(input) })),
49
- queryFn: ({ signal }) => client(unrefDeep(input), { signal, context: unrefDeep(context) }),
50
- ...rest
51
- };
52
- },
53
- infiniteOptions({ input, context, ...rest }) {
54
- return {
55
- queryKey: computed(() => {
56
- return buildKey(path, { type: "infinite", input: unrefDeep(input(unrefDeep(rest.initialPageParam))) });
57
- }),
58
- queryFn: ({ pageParam, signal }) => {
59
- return client(unrefDeep(input(pageParam)), { signal, context: unrefDeep(context) });
60
- },
61
- ...rest
62
- };
63
- },
64
- mutationOptions(...[{ context, ...rest } = {}]) {
65
- return {
66
- mutationKey: buildKey(path, { type: "mutation" }),
67
- mutationFn: (input) => client(input, { context: unrefDeep(context) }),
68
- ...rest
69
- };
70
- }
71
- };
72
- }
73
-
74
- // src/router-utils.ts
75
- function createRouterUtils(client, path = []) {
76
- const generalUtils = createGeneralUtils(path);
77
- const procedureUtils = createProcedureUtils(client, path);
78
- const recursive = new Proxy({
79
- ...generalUtils,
80
- ...procedureUtils
81
- }, {
82
- get(target, prop) {
83
- const value = Reflect.get(target, prop);
84
- if (typeof prop !== "string") {
85
- return value;
86
- }
87
- const nextUtils = createRouterUtils(client[prop], [...path, prop]);
88
- if (typeof value !== "function") {
89
- return nextUtils;
90
- }
91
- return new Proxy(value, {
92
- get(_, prop2) {
93
- return Reflect.get(nextUtils, prop2);
94
- }
95
- });
96
- }
97
- });
98
- return recursive;
99
- }
100
-
101
- // src/index.ts
102
- var createORPCVueQueryUtils = createRouterUtils;
103
- export {
104
- buildKey,
105
- createGeneralUtils,
106
- createORPCVueQueryUtils,
107
- createProcedureUtils,
108
- createRouterUtils
109
- };
110
- //# sourceMappingURL=index.js.map
@@ -1,7 +0,0 @@
1
- import type { QueryKey } from '@tanstack/vue-query';
2
- import type { BuildKeyOptions, KeyType } from './key';
3
- export interface GeneralUtils<TInput> {
4
- key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
5
- }
6
- export declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
7
- //# sourceMappingURL=general-utils.d.ts.map
@@ -1,8 +0,0 @@
1
- import { createRouterUtils } from './router-utils';
2
- export * from './general-utils';
3
- export * from './key';
4
- export * from './procedure-utils';
5
- export * from './router-utils';
6
- export * from './types';
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,12 +0,0 @@
1
- import type { Client, ClientContext } from '@orpc/client';
2
- import type { MaybeOptionalOptions } from '@orpc/shared';
3
- import type { InfiniteData } from '@tanstack/vue-query';
4
- import type { InfiniteOptionsBase, InfiniteOptionsIn, MutationOptionsBase, MutationOptionsIn, QueryOptionsBase, QueryOptionsIn } from './types';
5
- export interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
6
- call: Client<TClientContext, TInput, TOutput, TError>;
7
- queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & QueryOptionsBase<TOutput, TError>>;
8
- infiniteOptions<U, UPageParam, USelectData = InfiniteData<TOutput, UPageParam>>(options: U & InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UPageParam>): NoInfer<U & InfiniteOptionsBase<TOutput, TError, UPageParam>>;
9
- mutationOptions<U>(...rest: MaybeOptionalOptions<U & MutationOptionsIn<TClientContext, TInput, TOutput, TError>>): NoInfer<U & MutationOptionsBase<TInput, TOutput, TError>>;
10
- }
11
- export declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, path: string[]): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
12
- //# sourceMappingURL=procedure-utils.d.ts.map
@@ -1,12 +0,0 @@
1
- import type { Client, NestedClient } from '@orpc/client';
2
- import { type GeneralUtils } from './general-utils';
3
- import { type ProcedureUtils } from './procedure-utils';
4
- export type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
5
- [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
6
- } & GeneralUtils<unknown>;
7
- /**
8
- * @param client - Any kind of oRPC clients: `createRouterClient`, `createORPCClient`, ...
9
- * @param path - The base path for query key, when it it will be prefix to all keys
10
- */
11
- export declare function createRouterUtils<T extends NestedClient<any>>(client: T, path?: string[]): RouterUtils<T>;
12
- //# sourceMappingURL=router-utils.d.ts.map
@@ -1,58 +0,0 @@
1
- import type { ClientContext } from '@orpc/client';
2
- import type { AnyFunction, SetOptional } from '@orpc/shared';
3
- import type { Enabled, MutationObserverOptions, QueryFunctionContext, QueryKey, QueryObserverOptions, UseInfiniteQueryOptions } from '@tanstack/vue-query';
4
- import type { ComputedRef, MaybeRef, MaybeRefOrGetter } from 'vue';
5
- /**
6
- * Since `@tanstack/vue-query` is not exporting the type `MaybeRefDeep` we need to copy it from the source code.
7
- * https://github.com/TanStack/query/blob/7ff544e12e79388e513b1cd886aeb946f80f0153/packages/vue-query/src/types.ts#L19C1-L27C2
8
- */
9
- export type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
10
- [Property in keyof T]: MaybeRefDeep<T[Property]>;
11
- } : T>;
12
- export type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData> = (undefined extends TInput ? {
13
- input?: MaybeRefDeep<TInput>;
14
- } : {
15
- input: MaybeRefDeep<TInput>;
16
- }) & (Record<never, never> extends TClientContext ? {
17
- context?: MaybeRefDeep<TClientContext>;
18
- } : {
19
- context: MaybeRefDeep<TClientContext>;
20
- }) & {
21
- [P in keyof Omit<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>, 'queryKey' | 'enabled'>]: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>[P]>;
22
- } & {
23
- enabled?: MaybeRefOrGetter<Enabled<TOutput, TError, TSelectData>>;
24
- queryKey?: MaybeRefDeep<QueryKey>;
25
- shallow?: boolean;
26
- };
27
- export interface QueryOptionsBase<TOutput, TError extends Error> {
28
- queryKey: ComputedRef<QueryKey>;
29
- queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
30
- retry?(failureCount: number, error: TError): boolean;
31
- }
32
- export type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData, TPageParam> = {
33
- input: (pageParam: TPageParam) => MaybeRefDeep<TInput>;
34
- } & (Record<never, never> extends TClientContext ? {
35
- context?: MaybeRefDeep<TClientContext>;
36
- } : {
37
- context: MaybeRefDeep<TClientContext>;
38
- }) & SetOptional<UseInfiniteQueryOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey'>;
39
- export interface InfiniteOptionsBase<TOutput, TError extends Error, TPageParam> {
40
- queryKey: ComputedRef<QueryKey>;
41
- queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
42
- retry?(failureCount: number, error: TError): boolean;
43
- }
44
- export type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> = (Record<never, never> extends TClientContext ? {
45
- context?: TClientContext;
46
- } : {
47
- context: TClientContext;
48
- }) & {
49
- [P in keyof MutationObserverOptions<TOutput, TError, TInput>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput>[P]>;
50
- } & {
51
- shallow?: MaybeRef<boolean>;
52
- };
53
- export interface MutationOptionsBase<TInput, TOutput, TError extends Error> {
54
- mutationKey: QueryKey;
55
- mutationFn(input: TInput): Promise<TOutput>;
56
- retry?(failureCount: number, error: TError): boolean;
57
- }
58
- //# sourceMappingURL=types.d.ts.map
@@ -1,7 +0,0 @@
1
- import type { Ref } from 'vue';
2
- import { type AnyFunction } from '@orpc/shared';
3
- export type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunction ? T : T extends object ? {
4
- [K in keyof T]: UnrefDeep<T[K]>;
5
- } : T;
6
- export declare function unrefDeep<T>(value: T): UnrefDeep<T>;
7
- //# sourceMappingURL=utils.d.ts.map