@orpc/vue-query 0.0.0-next.df024bb → 0.0.0-next.df70448
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 +34 -21
- package/dist/index.d.mts +73 -32
- package/dist/index.d.ts +73 -32
- package/dist/index.mjs +38 -29
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -17,32 +17,31 @@
|
|
|
17
17
|
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
18
|
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
19
|
</a>
|
|
20
|
+
<a href="https://deepwiki.com/unnoq/orpc">
|
|
21
|
+
<img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki">
|
|
22
|
+
</a>
|
|
20
23
|
</div>
|
|
21
24
|
|
|
22
25
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
23
26
|
|
|
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
|
|
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
|
|
25
28
|
|
|
26
29
|
---
|
|
27
30
|
|
|
28
31
|
## Highlights
|
|
29
32
|
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
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.
|
|
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.
|
|
46
45
|
|
|
47
46
|
## Documentation
|
|
48
47
|
|
|
@@ -53,15 +52,21 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
53
52
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
54
53
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
55
54
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
56
|
-
- [@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
|
-
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
58
|
-
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
59
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.
|
|
60
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/).
|
|
61
66
|
|
|
62
67
|
## `@orpc/vue-query`
|
|
63
68
|
|
|
64
|
-
Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview). Read the [documentation](https://orpc.unnoq.com/docs/tanstack-query/vue) for more information.
|
|
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.
|
|
65
70
|
|
|
66
71
|
```ts
|
|
67
72
|
export function Setup() {
|
|
@@ -105,6 +110,14 @@ export function Setup() {
|
|
|
105
110
|
}
|
|
106
111
|
```
|
|
107
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
|
+
|
|
108
121
|
## License
|
|
109
122
|
|
|
110
123
|
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
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;
|
|
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';
|
|
12
7
|
|
|
13
8
|
interface GeneralUtils<TInput> {
|
|
14
|
-
|
|
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
15
|
}
|
|
16
16
|
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
|
17
17
|
|
|
@@ -22,10 +22,10 @@ declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput
|
|
|
22
22
|
type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
|
|
23
23
|
[Property in keyof T]: MaybeRefDeep<T[Property]>;
|
|
24
24
|
} : T>;
|
|
25
|
-
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError
|
|
26
|
-
input?: MaybeRefDeep<TInput>;
|
|
25
|
+
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
|
|
26
|
+
input?: MaybeRefDeep<TInput | SkipToken>;
|
|
27
27
|
} : {
|
|
28
|
-
input: MaybeRefDeep<TInput>;
|
|
28
|
+
input: MaybeRefDeep<TInput | SkipToken>;
|
|
29
29
|
}) & (Record<never, never> extends TClientContext ? {
|
|
30
30
|
context?: MaybeRefDeep<TClientContext>;
|
|
31
31
|
} : {
|
|
@@ -35,53 +35,94 @@ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TErro
|
|
|
35
35
|
} & {
|
|
36
36
|
enabled?: MaybeRefOrGetter<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['enabled']>;
|
|
37
37
|
queryKey?: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['queryKey']>;
|
|
38
|
-
shallow?:
|
|
38
|
+
shallow?: boolean;
|
|
39
39
|
};
|
|
40
|
-
interface QueryOptionsBase<TOutput, TError
|
|
40
|
+
interface QueryOptionsBase<TOutput, TError> {
|
|
41
41
|
queryKey: ComputedRef<QueryKey>;
|
|
42
42
|
queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
|
|
43
|
-
|
|
43
|
+
throwOnError?(error: TError): boolean;
|
|
44
|
+
retryDelay?: (count: number, error: TError) => number;
|
|
45
|
+
enabled: ComputedRef<boolean | undefined>;
|
|
44
46
|
}
|
|
45
|
-
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError
|
|
46
|
-
input: (pageParam: TPageParam) => MaybeRefDeep<TInput>;
|
|
47
|
-
} & (Record<never, never> extends TClientContext ? {
|
|
47
|
+
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = (Record<never, never> extends TClientContext ? {
|
|
48
48
|
context?: MaybeRefDeep<TClientContext>;
|
|
49
49
|
} : {
|
|
50
50
|
context: MaybeRefDeep<TClientContext>;
|
|
51
|
-
}) &
|
|
52
|
-
|
|
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> {
|
|
53
60
|
queryKey: ComputedRef<QueryKey>;
|
|
54
61
|
queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
|
|
55
|
-
|
|
62
|
+
throwOnError?(error: TError): boolean;
|
|
63
|
+
retryDelay?: (count: number, error: TError) => number;
|
|
64
|
+
enabled: ComputedRef<boolean | undefined>;
|
|
56
65
|
}
|
|
57
|
-
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError
|
|
66
|
+
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
|
58
67
|
context?: TClientContext;
|
|
59
68
|
} : {
|
|
60
69
|
context: TClientContext;
|
|
61
70
|
}) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
|
|
62
|
-
type MutationOptions<TInput, TOutput, TError
|
|
71
|
+
type MutationOptions<TInput, TOutput, TError, TMutationContext> = {
|
|
63
72
|
[P in keyof MutationObserverOptions<TOutput, TError, TInput, TMutationContext>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput, TMutationContext>[P]>;
|
|
64
73
|
} & {
|
|
65
74
|
shallow?: MaybeRef<boolean>;
|
|
66
75
|
};
|
|
67
76
|
|
|
68
|
-
interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError
|
|
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
|
+
*/
|
|
69
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
|
+
*/
|
|
70
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
|
+
*/
|
|
71
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
|
+
*/
|
|
72
101
|
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
|
|
73
102
|
}
|
|
74
|
-
|
|
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>;
|
|
75
107
|
|
|
76
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> : {
|
|
77
109
|
[K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
|
|
78
110
|
} & GeneralUtils<unknown>;
|
|
111
|
+
interface CreateRouterUtilsOptions {
|
|
112
|
+
path?: string[];
|
|
113
|
+
}
|
|
79
114
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
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}
|
|
82
119
|
*/
|
|
83
|
-
declare function createRouterUtils<T extends NestedClient<any>>(client: T,
|
|
120
|
+
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
|
84
121
|
|
|
85
|
-
|
|
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>;
|
|
86
126
|
|
|
87
|
-
export {
|
|
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.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
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;
|
|
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';
|
|
12
7
|
|
|
13
8
|
interface GeneralUtils<TInput> {
|
|
14
|
-
|
|
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
15
|
}
|
|
16
16
|
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
|
17
17
|
|
|
@@ -22,10 +22,10 @@ declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput
|
|
|
22
22
|
type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
|
|
23
23
|
[Property in keyof T]: MaybeRefDeep<T[Property]>;
|
|
24
24
|
} : T>;
|
|
25
|
-
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError
|
|
26
|
-
input?: MaybeRefDeep<TInput>;
|
|
25
|
+
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
|
|
26
|
+
input?: MaybeRefDeep<TInput | SkipToken>;
|
|
27
27
|
} : {
|
|
28
|
-
input: MaybeRefDeep<TInput>;
|
|
28
|
+
input: MaybeRefDeep<TInput | SkipToken>;
|
|
29
29
|
}) & (Record<never, never> extends TClientContext ? {
|
|
30
30
|
context?: MaybeRefDeep<TClientContext>;
|
|
31
31
|
} : {
|
|
@@ -35,53 +35,94 @@ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TErro
|
|
|
35
35
|
} & {
|
|
36
36
|
enabled?: MaybeRefOrGetter<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['enabled']>;
|
|
37
37
|
queryKey?: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['queryKey']>;
|
|
38
|
-
shallow?:
|
|
38
|
+
shallow?: boolean;
|
|
39
39
|
};
|
|
40
|
-
interface QueryOptionsBase<TOutput, TError
|
|
40
|
+
interface QueryOptionsBase<TOutput, TError> {
|
|
41
41
|
queryKey: ComputedRef<QueryKey>;
|
|
42
42
|
queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
|
|
43
|
-
|
|
43
|
+
throwOnError?(error: TError): boolean;
|
|
44
|
+
retryDelay?: (count: number, error: TError) => number;
|
|
45
|
+
enabled: ComputedRef<boolean | undefined>;
|
|
44
46
|
}
|
|
45
|
-
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError
|
|
46
|
-
input: (pageParam: TPageParam) => MaybeRefDeep<TInput>;
|
|
47
|
-
} & (Record<never, never> extends TClientContext ? {
|
|
47
|
+
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = (Record<never, never> extends TClientContext ? {
|
|
48
48
|
context?: MaybeRefDeep<TClientContext>;
|
|
49
49
|
} : {
|
|
50
50
|
context: MaybeRefDeep<TClientContext>;
|
|
51
|
-
}) &
|
|
52
|
-
|
|
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> {
|
|
53
60
|
queryKey: ComputedRef<QueryKey>;
|
|
54
61
|
queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
|
|
55
|
-
|
|
62
|
+
throwOnError?(error: TError): boolean;
|
|
63
|
+
retryDelay?: (count: number, error: TError) => number;
|
|
64
|
+
enabled: ComputedRef<boolean | undefined>;
|
|
56
65
|
}
|
|
57
|
-
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError
|
|
66
|
+
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
|
58
67
|
context?: TClientContext;
|
|
59
68
|
} : {
|
|
60
69
|
context: TClientContext;
|
|
61
70
|
}) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
|
|
62
|
-
type MutationOptions<TInput, TOutput, TError
|
|
71
|
+
type MutationOptions<TInput, TOutput, TError, TMutationContext> = {
|
|
63
72
|
[P in keyof MutationObserverOptions<TOutput, TError, TInput, TMutationContext>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput, TMutationContext>[P]>;
|
|
64
73
|
} & {
|
|
65
74
|
shallow?: MaybeRef<boolean>;
|
|
66
75
|
};
|
|
67
76
|
|
|
68
|
-
interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError
|
|
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
|
+
*/
|
|
69
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
|
+
*/
|
|
70
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
|
+
*/
|
|
71
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
|
+
*/
|
|
72
101
|
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
|
|
73
102
|
}
|
|
74
|
-
|
|
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>;
|
|
75
107
|
|
|
76
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> : {
|
|
77
109
|
[K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
|
|
78
110
|
} & GeneralUtils<unknown>;
|
|
111
|
+
interface CreateRouterUtilsOptions {
|
|
112
|
+
path?: string[];
|
|
113
|
+
}
|
|
79
114
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
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}
|
|
82
119
|
*/
|
|
83
|
-
declare function createRouterUtils<T extends NestedClient<any>>(client: T,
|
|
120
|
+
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
|
84
121
|
|
|
85
|
-
|
|
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>;
|
|
86
126
|
|
|
87
|
-
export {
|
|
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
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
|
+
import { generateOperationKey } from '@orpc/tanstack-query';
|
|
2
|
+
export { generateOperationKey as buildKey } from '@orpc/tanstack-query';
|
|
3
|
+
import { skipToken } from '@tanstack/vue-query';
|
|
1
4
|
import { isRef, computed } from 'vue';
|
|
2
5
|
import { isObject } from '@orpc/shared';
|
|
3
6
|
|
|
4
|
-
function buildKey(path, options) {
|
|
5
|
-
const withInput = options?.input !== void 0 ? { input: options?.input } : {};
|
|
6
|
-
const withType = options?.type !== void 0 ? { type: options?.type } : {};
|
|
7
|
-
return [path, {
|
|
8
|
-
...withInput,
|
|
9
|
-
...withType
|
|
10
|
-
}];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
7
|
function createGeneralUtils(path) {
|
|
14
8
|
return {
|
|
15
9
|
key(options) {
|
|
16
|
-
return
|
|
10
|
+
return generateOperationKey(path, options);
|
|
17
11
|
}
|
|
18
12
|
};
|
|
19
13
|
}
|
|
@@ -34,40 +28,57 @@ function unrefDeep(value) {
|
|
|
34
28
|
return value;
|
|
35
29
|
}
|
|
36
30
|
|
|
37
|
-
function createProcedureUtils(client,
|
|
31
|
+
function createProcedureUtils(client, options) {
|
|
38
32
|
return {
|
|
39
33
|
call: client,
|
|
40
|
-
queryOptions(...[
|
|
34
|
+
queryOptions(...[optionsIn = {}]) {
|
|
41
35
|
return {
|
|
42
|
-
queryKey: computed(() =>
|
|
43
|
-
queryFn: ({ signal }) =>
|
|
44
|
-
|
|
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
|
|
45
46
|
};
|
|
46
47
|
},
|
|
47
|
-
infiniteOptions(
|
|
48
|
+
infiniteOptions(optionsIn) {
|
|
48
49
|
return {
|
|
49
50
|
queryKey: computed(() => {
|
|
50
|
-
|
|
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
|
+
});
|
|
51
56
|
}),
|
|
52
57
|
queryFn: ({ pageParam, signal }) => {
|
|
53
|
-
|
|
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) });
|
|
54
63
|
},
|
|
55
|
-
|
|
64
|
+
enabled: computed(() => unrefDeep(optionsIn.input) === skipToken ? false : void 0),
|
|
65
|
+
...optionsIn
|
|
56
66
|
};
|
|
57
67
|
},
|
|
58
|
-
mutationOptions(...[
|
|
68
|
+
mutationOptions(...[optionsIn = {}]) {
|
|
59
69
|
return {
|
|
60
|
-
mutationKey:
|
|
61
|
-
mutationFn: (input) => client(input, { context: unrefDeep(
|
|
62
|
-
...
|
|
70
|
+
mutationKey: generateOperationKey(options.path, { type: "mutation" }),
|
|
71
|
+
mutationFn: (input) => client(input, { context: unrefDeep(optionsIn.context) }),
|
|
72
|
+
...optionsIn
|
|
63
73
|
};
|
|
64
74
|
}
|
|
65
75
|
};
|
|
66
76
|
}
|
|
67
77
|
|
|
68
|
-
function createRouterUtils(client,
|
|
78
|
+
function createRouterUtils(client, options = {}) {
|
|
79
|
+
const path = options.path ?? [];
|
|
69
80
|
const generalUtils = createGeneralUtils(path);
|
|
70
|
-
const procedureUtils = createProcedureUtils(client, path);
|
|
81
|
+
const procedureUtils = createProcedureUtils(client, { path });
|
|
71
82
|
const recursive = new Proxy({
|
|
72
83
|
...generalUtils,
|
|
73
84
|
...procedureUtils
|
|
@@ -77,7 +88,7 @@ function createRouterUtils(client, path = []) {
|
|
|
77
88
|
if (typeof prop !== "string") {
|
|
78
89
|
return value;
|
|
79
90
|
}
|
|
80
|
-
const nextUtils = createRouterUtils(client[prop], [...path, prop]);
|
|
91
|
+
const nextUtils = createRouterUtils(client[prop], { ...options, path: [...path, prop] });
|
|
81
92
|
if (typeof value !== "function") {
|
|
82
93
|
return nextUtils;
|
|
83
94
|
}
|
|
@@ -91,6 +102,4 @@ function createRouterUtils(client, path = []) {
|
|
|
91
102
|
return recursive;
|
|
92
103
|
}
|
|
93
104
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
export { buildKey, createGeneralUtils, createORPCVueQueryUtils, createProcedureUtils, createRouterUtils };
|
|
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.
|
|
4
|
+
"version": "0.0.0-next.df70448",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -27,12 +27,16 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@tanstack/vue-query": ">=5.
|
|
30
|
+
"@tanstack/vue-query": ">=5.80.2",
|
|
31
31
|
"vue": ">=3.3.0",
|
|
32
|
-
"@orpc/client": "0.0.0-next.
|
|
32
|
+
"@orpc/client": "0.0.0-next.df70448"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@orpc/shared": "0.0.0-next.
|
|
35
|
+
"@orpc/shared": "0.0.0-next.df70448",
|
|
36
|
+
"@orpc/tanstack-query": "0.0.0-next.df70448"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@tanstack/vue-query": "^5.90.2"
|
|
36
40
|
},
|
|
37
41
|
"scripts": {
|
|
38
42
|
"build": "unbuild",
|