@orpc/vue-query 0.0.0-next.fea68c1 → 0.0.0-next.ff41b3a
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 +27 -18
- package/dist/index.d.mts +130 -0
- package/dist/index.d.ts +130 -0
- package/dist/{index.js → index.mjs} +21 -36
- package/package.json +9 -13
- package/dist/src/general-utils.d.ts +0 -7
- package/dist/src/index.d.ts +0 -8
- package/dist/src/key.d.ts +0 -9
- package/dist/src/procedure-utils.d.ts +0 -12
- package/dist/src/router-utils.d.ts +0 -12
- package/dist/src/types.d.ts +0 -58
- package/dist/src/utils.d.ts +0 -7
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
|
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
|
-
-
|
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.
|
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,16 @@ 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/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
56
53
|
- [@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
54
|
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
55
|
+
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
56
|
+
- [@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
57
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
59
58
|
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
60
59
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
60
|
+
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
61
|
+
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
61
62
|
|
62
63
|
## `@orpc/vue-query`
|
63
64
|
|
@@ -105,6 +106,14 @@ export function Setup() {
|
|
105
106
|
}
|
106
107
|
```
|
107
108
|
|
109
|
+
## Sponsors
|
110
|
+
|
111
|
+
<p align="center">
|
112
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
113
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
114
|
+
</a>
|
115
|
+
</p>
|
116
|
+
|
108
117
|
## License
|
109
118
|
|
110
119
|
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.d.mts
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
2
|
+
import { QueryKey, 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>;
|
32
|
+
} : {
|
33
|
+
input: MaybeRefDeep<TInput>;
|
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
|
+
}
|
50
|
+
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = {
|
51
|
+
input: (pageParam: TPageParam) => MaybeRefDeep<TInput>;
|
52
|
+
} & (Record<never, never> extends TClientContext ? {
|
53
|
+
context?: MaybeRefDeep<TClientContext>;
|
54
|
+
} : {
|
55
|
+
context: MaybeRefDeep<TClientContext>;
|
56
|
+
}) & {
|
57
|
+
[Property in keyof Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey' | 'enabled'>]: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>[Property]>;
|
58
|
+
} & {
|
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
|
+
}
|
68
|
+
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
69
|
+
context?: TClientContext;
|
70
|
+
} : {
|
71
|
+
context: TClientContext;
|
72
|
+
}) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
|
73
|
+
type MutationOptions<TInput, TOutput, TError, TMutationContext> = {
|
74
|
+
[P in keyof MutationObserverOptions<TOutput, TError, TInput, TMutationContext>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput, TMutationContext>[P]>;
|
75
|
+
} & {
|
76
|
+
shallow?: MaybeRef<boolean>;
|
77
|
+
};
|
78
|
+
|
79
|
+
interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
80
|
+
/**
|
81
|
+
* Calling corresponding procedure client
|
82
|
+
*
|
83
|
+
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
|
84
|
+
*/
|
85
|
+
call: Client<TClientContext, TInput, TOutput, TError>;
|
86
|
+
/**
|
87
|
+
* Generate options used for useQuery/prefetchQuery/...
|
88
|
+
*
|
89
|
+
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-options-utility Tanstack Query Options Utility Docs}
|
90
|
+
*/
|
91
|
+
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
92
|
+
/**
|
93
|
+
* Generate options used for useInfiniteQuery/prefetchInfiniteQuery/...
|
94
|
+
*
|
95
|
+
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
|
96
|
+
*/
|
97
|
+
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>>;
|
98
|
+
/**
|
99
|
+
* Generate options used for useMutation/...
|
100
|
+
*
|
101
|
+
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#mutation-options Tanstack Mutation Options Docs}
|
102
|
+
*/
|
103
|
+
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
|
104
|
+
}
|
105
|
+
interface CreateProcedureUtilsOptions {
|
106
|
+
path: string[];
|
107
|
+
}
|
108
|
+
declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
109
|
+
|
110
|
+
type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
|
111
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
|
112
|
+
} & GeneralUtils<unknown>;
|
113
|
+
interface CreateRouterUtilsOptions {
|
114
|
+
path?: string[];
|
115
|
+
}
|
116
|
+
/**
|
117
|
+
* Create a router utils from a client.
|
118
|
+
*
|
119
|
+
* @info Both client-side and server-side clients are supported.
|
120
|
+
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/vue Tanstack Query Vue Docs}
|
121
|
+
*/
|
122
|
+
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
123
|
+
|
124
|
+
type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunction ? T : T extends object ? {
|
125
|
+
[K in keyof T]: UnrefDeep<T[K]>;
|
126
|
+
} : T;
|
127
|
+
declare function unrefDeep<T>(value: T): UnrefDeep<T>;
|
128
|
+
|
129
|
+
export { buildKey, createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
|
130
|
+
export type { BuildKeyOptions, CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, KeyType, MaybeRefDeep, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, UnrefDeep };
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
2
|
+
import { QueryKey, 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>;
|
32
|
+
} : {
|
33
|
+
input: MaybeRefDeep<TInput>;
|
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
|
+
}
|
50
|
+
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = {
|
51
|
+
input: (pageParam: TPageParam) => MaybeRefDeep<TInput>;
|
52
|
+
} & (Record<never, never> extends TClientContext ? {
|
53
|
+
context?: MaybeRefDeep<TClientContext>;
|
54
|
+
} : {
|
55
|
+
context: MaybeRefDeep<TClientContext>;
|
56
|
+
}) & {
|
57
|
+
[Property in keyof Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey' | 'enabled'>]: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>[Property]>;
|
58
|
+
} & {
|
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
|
+
}
|
68
|
+
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
69
|
+
context?: TClientContext;
|
70
|
+
} : {
|
71
|
+
context: TClientContext;
|
72
|
+
}) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
|
73
|
+
type MutationOptions<TInput, TOutput, TError, TMutationContext> = {
|
74
|
+
[P in keyof MutationObserverOptions<TOutput, TError, TInput, TMutationContext>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput, TMutationContext>[P]>;
|
75
|
+
} & {
|
76
|
+
shallow?: MaybeRef<boolean>;
|
77
|
+
};
|
78
|
+
|
79
|
+
interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
80
|
+
/**
|
81
|
+
* Calling corresponding procedure client
|
82
|
+
*
|
83
|
+
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
|
84
|
+
*/
|
85
|
+
call: Client<TClientContext, TInput, TOutput, TError>;
|
86
|
+
/**
|
87
|
+
* Generate options used for useQuery/prefetchQuery/...
|
88
|
+
*
|
89
|
+
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-options-utility Tanstack Query Options Utility Docs}
|
90
|
+
*/
|
91
|
+
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
92
|
+
/**
|
93
|
+
* Generate options used for useInfiniteQuery/prefetchInfiniteQuery/...
|
94
|
+
*
|
95
|
+
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
|
96
|
+
*/
|
97
|
+
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>>;
|
98
|
+
/**
|
99
|
+
* Generate options used for useMutation/...
|
100
|
+
*
|
101
|
+
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#mutation-options Tanstack Mutation Options Docs}
|
102
|
+
*/
|
103
|
+
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
|
104
|
+
}
|
105
|
+
interface CreateProcedureUtilsOptions {
|
106
|
+
path: string[];
|
107
|
+
}
|
108
|
+
declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
109
|
+
|
110
|
+
type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
|
111
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
|
112
|
+
} & GeneralUtils<unknown>;
|
113
|
+
interface CreateRouterUtilsOptions {
|
114
|
+
path?: string[];
|
115
|
+
}
|
116
|
+
/**
|
117
|
+
* Create a router utils from a client.
|
118
|
+
*
|
119
|
+
* @info Both client-side and server-side clients are supported.
|
120
|
+
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/vue Tanstack Query Vue Docs}
|
121
|
+
*/
|
122
|
+
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
123
|
+
|
124
|
+
type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunction ? T : T extends object ? {
|
125
|
+
[K in keyof T]: UnrefDeep<T[K]>;
|
126
|
+
} : T;
|
127
|
+
declare function unrefDeep<T>(value: T): UnrefDeep<T>;
|
128
|
+
|
129
|
+
export { buildKey, createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
|
130
|
+
export type { BuildKeyOptions, CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, KeyType, MaybeRefDeep, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, UnrefDeep };
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
import { isRef, computed } from 'vue';
|
2
|
+
import { isObject } from '@orpc/shared';
|
3
|
+
|
2
4
|
function buildKey(path, options) {
|
3
5
|
const withInput = options?.input !== void 0 ? { input: options?.input } : {};
|
4
6
|
const withType = options?.type !== void 0 ? { type: options?.type } : {};
|
@@ -8,7 +10,6 @@ function buildKey(path, options) {
|
|
8
10
|
}];
|
9
11
|
}
|
10
12
|
|
11
|
-
// src/general-utils.ts
|
12
13
|
function createGeneralUtils(path) {
|
13
14
|
return {
|
14
15
|
key(options) {
|
@@ -17,12 +18,6 @@ function createGeneralUtils(path) {
|
|
17
18
|
};
|
18
19
|
}
|
19
20
|
|
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
21
|
function unrefDeep(value) {
|
27
22
|
if (isRef(value)) {
|
28
23
|
return unrefDeep(value.value);
|
@@ -39,42 +34,41 @@ function unrefDeep(value) {
|
|
39
34
|
return value;
|
40
35
|
}
|
41
36
|
|
42
|
-
|
43
|
-
function createProcedureUtils(client, path) {
|
37
|
+
function createProcedureUtils(client, options) {
|
44
38
|
return {
|
45
39
|
call: client,
|
46
|
-
queryOptions(...[
|
40
|
+
queryOptions(...[optionsIn = {}]) {
|
47
41
|
return {
|
48
|
-
queryKey: computed(() => buildKey(path, { type: "query", input: unrefDeep(input) })),
|
49
|
-
queryFn: ({ signal }) => client(unrefDeep(input), { signal, context: unrefDeep(context) }),
|
50
|
-
...
|
42
|
+
queryKey: computed(() => buildKey(options.path, { type: "query", input: unrefDeep(optionsIn.input) })),
|
43
|
+
queryFn: ({ signal }) => client(unrefDeep(optionsIn.input), { signal, context: unrefDeep(optionsIn.context) }),
|
44
|
+
...optionsIn
|
51
45
|
};
|
52
46
|
},
|
53
|
-
infiniteOptions(
|
47
|
+
infiniteOptions(optionsIn) {
|
54
48
|
return {
|
55
49
|
queryKey: computed(() => {
|
56
|
-
return buildKey(path, { type: "infinite", input: unrefDeep(input(unrefDeep(
|
50
|
+
return buildKey(options.path, { type: "infinite", input: unrefDeep(optionsIn.input(unrefDeep(optionsIn.initialPageParam))) });
|
57
51
|
}),
|
58
52
|
queryFn: ({ pageParam, signal }) => {
|
59
|
-
return client(unrefDeep(input(pageParam)), { signal, context: unrefDeep(context) });
|
53
|
+
return client(unrefDeep(optionsIn.input(pageParam)), { signal, context: unrefDeep(optionsIn.context) });
|
60
54
|
},
|
61
|
-
...
|
55
|
+
...optionsIn
|
62
56
|
};
|
63
57
|
},
|
64
|
-
mutationOptions(...[
|
58
|
+
mutationOptions(...[optionsIn = {}]) {
|
65
59
|
return {
|
66
|
-
mutationKey: buildKey(path, { type: "mutation" }),
|
67
|
-
mutationFn: (input) => client(input, { context: unrefDeep(context) }),
|
68
|
-
...
|
60
|
+
mutationKey: buildKey(options.path, { type: "mutation" }),
|
61
|
+
mutationFn: (input) => client(input, { context: unrefDeep(optionsIn.context) }),
|
62
|
+
...optionsIn
|
69
63
|
};
|
70
64
|
}
|
71
65
|
};
|
72
66
|
}
|
73
67
|
|
74
|
-
|
75
|
-
|
68
|
+
function createRouterUtils(client, options = {}) {
|
69
|
+
const path = options.path ?? [];
|
76
70
|
const generalUtils = createGeneralUtils(path);
|
77
|
-
const procedureUtils = createProcedureUtils(client, path);
|
71
|
+
const procedureUtils = createProcedureUtils(client, { path });
|
78
72
|
const recursive = new Proxy({
|
79
73
|
...generalUtils,
|
80
74
|
...procedureUtils
|
@@ -84,7 +78,7 @@ function createRouterUtils(client, path = []) {
|
|
84
78
|
if (typeof prop !== "string") {
|
85
79
|
return value;
|
86
80
|
}
|
87
|
-
const nextUtils = createRouterUtils(client[prop], [...path, prop]);
|
81
|
+
const nextUtils = createRouterUtils(client[prop], { ...options, path: [...path, prop] });
|
88
82
|
if (typeof value !== "function") {
|
89
83
|
return nextUtils;
|
90
84
|
}
|
@@ -98,13 +92,4 @@ function createRouterUtils(client, path = []) {
|
|
98
92
|
return recursive;
|
99
93
|
}
|
100
94
|
|
101
|
-
|
102
|
-
var createORPCVueQueryUtils = createRouterUtils;
|
103
|
-
export {
|
104
|
-
buildKey,
|
105
|
-
createGeneralUtils,
|
106
|
-
createORPCVueQueryUtils,
|
107
|
-
createProcedureUtils,
|
108
|
-
createRouterUtils
|
109
|
-
};
|
110
|
-
//# sourceMappingURL=index.js.map
|
95
|
+
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.
|
4
|
+
"version": "0.0.0-next.ff41b3a",
|
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/
|
22
|
-
"import": "./dist/index.
|
23
|
-
"default": "./dist/index.
|
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.
|
30
|
+
"@tanstack/vue-query": ">=5.55.0",
|
36
31
|
"vue": ">=3.3.0",
|
37
|
-
"@orpc/client": "0.0.0-next.
|
32
|
+
"@orpc/client": "0.0.0-next.ff41b3a"
|
38
33
|
},
|
39
34
|
"dependencies": {
|
40
|
-
"@
|
35
|
+
"@tanstack/vue-query": "^5.72.2",
|
36
|
+
"@orpc/shared": "0.0.0-next.ff41b3a"
|
41
37
|
},
|
42
38
|
"scripts": {
|
43
|
-
"build": "
|
39
|
+
"build": "unbuild",
|
44
40
|
"build:watch": "pnpm run build --watch",
|
45
41
|
"type:check": "tsc -b"
|
46
42
|
}
|
@@ -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
|
package/dist/src/index.d.ts
DELETED
@@ -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
|
package/dist/src/types.d.ts
DELETED
@@ -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
|
package/dist/src/utils.d.ts
DELETED
@@ -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
|