@orpc/vue-query 0.0.0-next.e7d7758 → 0.0.0-next.e7ee5a9
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 +110 -0
- package/dist/index.d.mts +91 -0
- package/dist/index.d.ts +91 -0
- package/dist/{index.js → index.mjs} +36 -50
- package/package.json +9 -13
- package/dist/src/index.d.ts +0 -8
- package/dist/src/key.d.ts +0 -9
- package/dist/src/types.d.ts +0 -43
- package/dist/src/utils-general.d.ts +0 -11
- package/dist/src/utils-procedure.d.ts +0 -31
- package/dist/src/utils-router.d.ts +0 -12
- package/dist/src/utils.d.ts +0 -7
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
<h1></h1>
|
|
6
|
+
|
|
7
|
+
<div align="center">
|
|
8
|
+
<a href="https://codecov.io/gh/unnoq/orpc">
|
|
9
|
+
<img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@orpc/vue-query">
|
|
12
|
+
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fvue-query?logo=npm" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
|
|
15
|
+
<img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
|
+
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
|
+
</a>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
23
|
+
|
|
24
|
+
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards, ensuring a smooth and enjoyable developer experience.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Highlights
|
|
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.
|
|
46
|
+
|
|
47
|
+
## Documentation
|
|
48
|
+
|
|
49
|
+
You can find the full documentation [here](https://orpc.unnoq.com).
|
|
50
|
+
|
|
51
|
+
## Packages
|
|
52
|
+
|
|
53
|
+
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
54
|
+
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
55
|
+
- [@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
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
60
|
+
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
61
|
+
|
|
62
|
+
## `@orpc/vue-query`
|
|
63
|
+
|
|
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.
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
export function Setup() {
|
|
68
|
+
const query = useQuery(orpc.planet.find.queryOptions({
|
|
69
|
+
input: { id: 123 }, // Specify input if needed
|
|
70
|
+
context: { cache: true }, // Provide client context if needed
|
|
71
|
+
// additional options...
|
|
72
|
+
}))
|
|
73
|
+
|
|
74
|
+
const query = useInfiniteQuery(orpc.planet.list.infiniteOptions({
|
|
75
|
+
input: (pageParam: number | undefined) => ({ limit: 10, offset: pageParam }),
|
|
76
|
+
context: { cache: true }, // Provide client context if needed
|
|
77
|
+
initialPageParam: undefined,
|
|
78
|
+
getNextPageParam: lastPage => lastPage.nextPageParam,
|
|
79
|
+
// additional options...
|
|
80
|
+
}))
|
|
81
|
+
|
|
82
|
+
const mutation = useMutation(orpc.planet.create.mutationOptions({
|
|
83
|
+
context: { cache: true }, // Provide client context if needed
|
|
84
|
+
// additional options...
|
|
85
|
+
}))
|
|
86
|
+
|
|
87
|
+
mutation.mutate({ name: 'Earth' })
|
|
88
|
+
|
|
89
|
+
const queryClient = useQueryClient()
|
|
90
|
+
|
|
91
|
+
// Invalidate all planet queries
|
|
92
|
+
queryClient.invalidateQueries({
|
|
93
|
+
queryKey: orpc.planet.key(),
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
// Invalidate only regular (non-infinite) planet queries
|
|
97
|
+
queryClient.invalidateQueries({
|
|
98
|
+
queryKey: orpc.planet.key({ type: 'query' })
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
// Invalidate the planet find query with id 123
|
|
102
|
+
queryClient.invalidateQueries({
|
|
103
|
+
queryKey: orpc.planet.find.key({ input: { id: 123 } })
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
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,91 @@
|
|
|
1
|
+
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
|
2
|
+
import { QueryKey, QueryObserverOptions, QueryFunctionContext, UseInfiniteQueryOptions, MutationObserverOptions, InfiniteData } from '@tanstack/vue-query';
|
|
3
|
+
import { PartialDeep, AnyFunction, SetOptional, MaybeOptionalOptions } from '@orpc/shared';
|
|
4
|
+
import { MaybeRef, MaybeRefOrGetter, ComputedRef } 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
|
+
key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
|
|
15
|
+
}
|
|
16
|
+
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Since `@tanstack/vue-query` is not exporting the type `MaybeRefDeep` we need to copy it from the source code.
|
|
20
|
+
* https://github.com/TanStack/query/blob/7ff544e12e79388e513b1cd886aeb946f80f0153/packages/vue-query/src/types.ts#L19C1-L27C2
|
|
21
|
+
*/
|
|
22
|
+
type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
|
|
23
|
+
[Property in keyof T]: MaybeRefDeep<T[Property]>;
|
|
24
|
+
} : T>;
|
|
25
|
+
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData> = (undefined extends TInput ? {
|
|
26
|
+
input?: MaybeRefDeep<TInput>;
|
|
27
|
+
} : {
|
|
28
|
+
input: MaybeRefDeep<TInput>;
|
|
29
|
+
}) & (Record<never, never> extends TClientContext ? {
|
|
30
|
+
context?: MaybeRefDeep<TClientContext>;
|
|
31
|
+
} : {
|
|
32
|
+
context: MaybeRefDeep<TClientContext>;
|
|
33
|
+
}) & {
|
|
34
|
+
[P in keyof Omit<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>, 'queryKey' | 'enabled'>]: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>[P]>;
|
|
35
|
+
} & {
|
|
36
|
+
enabled?: MaybeRefOrGetter<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['enabled']>;
|
|
37
|
+
queryKey?: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['queryKey']>;
|
|
38
|
+
shallow?: MaybeRef<boolean>;
|
|
39
|
+
};
|
|
40
|
+
interface QueryOptionsBase<TOutput, TError extends Error> {
|
|
41
|
+
queryKey: ComputedRef<QueryKey>;
|
|
42
|
+
queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
|
|
43
|
+
retry?(failureCount: number, error: TError): boolean;
|
|
44
|
+
}
|
|
45
|
+
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData, TPageParam> = {
|
|
46
|
+
input: (pageParam: TPageParam) => MaybeRefDeep<TInput>;
|
|
47
|
+
} & (Record<never, never> extends TClientContext ? {
|
|
48
|
+
context?: MaybeRefDeep<TClientContext>;
|
|
49
|
+
} : {
|
|
50
|
+
context: MaybeRefDeep<TClientContext>;
|
|
51
|
+
}) & SetOptional<UseInfiniteQueryOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey'>;
|
|
52
|
+
interface InfiniteOptionsBase<TOutput, TError extends Error, TPageParam> {
|
|
53
|
+
queryKey: ComputedRef<QueryKey>;
|
|
54
|
+
queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
|
|
55
|
+
retry?(failureCount: number, error: TError): boolean;
|
|
56
|
+
}
|
|
57
|
+
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
|
58
|
+
context?: TClientContext;
|
|
59
|
+
} : {
|
|
60
|
+
context: TClientContext;
|
|
61
|
+
}) & {
|
|
62
|
+
[P in keyof MutationObserverOptions<TOutput, TError, TInput, TMutationContext>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput, TMutationContext>[P]>;
|
|
63
|
+
} & {
|
|
64
|
+
shallow?: MaybeRef<boolean>;
|
|
65
|
+
};
|
|
66
|
+
interface MutationOptionsBase<TInput, TOutput, TError extends Error> {
|
|
67
|
+
mutationKey: QueryKey;
|
|
68
|
+
mutationFn(input: TInput): Promise<TOutput>;
|
|
69
|
+
retry?(failureCount: number, error: TError): boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
|
|
73
|
+
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
74
|
+
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
|
75
|
+
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>>;
|
|
76
|
+
mutationOptions<U, UMutationContext>(...rest: MaybeOptionalOptions<U & MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<U & Omit<MutationOptionsBase<TInput, TOutput, TError>, keyof U>>;
|
|
77
|
+
}
|
|
78
|
+
declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, path: string[]): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
|
79
|
+
|
|
80
|
+
type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
|
|
81
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
|
|
82
|
+
} & GeneralUtils<unknown>;
|
|
83
|
+
/**
|
|
84
|
+
* @param client - Any kind of oRPC clients: `createRouterClient`, `createORPCClient`, ...
|
|
85
|
+
* @param path - The base path for query key, when it it will be prefix to all keys
|
|
86
|
+
*/
|
|
87
|
+
declare function createRouterUtils<T extends NestedClient<any>>(client: T, path?: string[]): RouterUtils<T>;
|
|
88
|
+
|
|
89
|
+
declare const createORPCVueQueryUtils: typeof createRouterUtils;
|
|
90
|
+
|
|
91
|
+
export { type BuildKeyOptions, type GeneralUtils, type InfiniteOptionsBase, type InfiniteOptionsIn, type KeyType, type MaybeRefDeep, type MutationOptionsBase, type MutationOptionsIn, type ProcedureUtils, type QueryOptionsBase, type QueryOptionsIn, type RouterUtils, buildKey, createGeneralUtils, createORPCVueQueryUtils, createProcedureUtils, createRouterUtils };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
|
2
|
+
import { QueryKey, QueryObserverOptions, QueryFunctionContext, UseInfiniteQueryOptions, MutationObserverOptions, InfiniteData } from '@tanstack/vue-query';
|
|
3
|
+
import { PartialDeep, AnyFunction, SetOptional, MaybeOptionalOptions } from '@orpc/shared';
|
|
4
|
+
import { MaybeRef, MaybeRefOrGetter, ComputedRef } 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
|
+
key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
|
|
15
|
+
}
|
|
16
|
+
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Since `@tanstack/vue-query` is not exporting the type `MaybeRefDeep` we need to copy it from the source code.
|
|
20
|
+
* https://github.com/TanStack/query/blob/7ff544e12e79388e513b1cd886aeb946f80f0153/packages/vue-query/src/types.ts#L19C1-L27C2
|
|
21
|
+
*/
|
|
22
|
+
type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
|
|
23
|
+
[Property in keyof T]: MaybeRefDeep<T[Property]>;
|
|
24
|
+
} : T>;
|
|
25
|
+
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData> = (undefined extends TInput ? {
|
|
26
|
+
input?: MaybeRefDeep<TInput>;
|
|
27
|
+
} : {
|
|
28
|
+
input: MaybeRefDeep<TInput>;
|
|
29
|
+
}) & (Record<never, never> extends TClientContext ? {
|
|
30
|
+
context?: MaybeRefDeep<TClientContext>;
|
|
31
|
+
} : {
|
|
32
|
+
context: MaybeRefDeep<TClientContext>;
|
|
33
|
+
}) & {
|
|
34
|
+
[P in keyof Omit<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>, 'queryKey' | 'enabled'>]: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>[P]>;
|
|
35
|
+
} & {
|
|
36
|
+
enabled?: MaybeRefOrGetter<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['enabled']>;
|
|
37
|
+
queryKey?: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['queryKey']>;
|
|
38
|
+
shallow?: MaybeRef<boolean>;
|
|
39
|
+
};
|
|
40
|
+
interface QueryOptionsBase<TOutput, TError extends Error> {
|
|
41
|
+
queryKey: ComputedRef<QueryKey>;
|
|
42
|
+
queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
|
|
43
|
+
retry?(failureCount: number, error: TError): boolean;
|
|
44
|
+
}
|
|
45
|
+
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData, TPageParam> = {
|
|
46
|
+
input: (pageParam: TPageParam) => MaybeRefDeep<TInput>;
|
|
47
|
+
} & (Record<never, never> extends TClientContext ? {
|
|
48
|
+
context?: MaybeRefDeep<TClientContext>;
|
|
49
|
+
} : {
|
|
50
|
+
context: MaybeRefDeep<TClientContext>;
|
|
51
|
+
}) & SetOptional<UseInfiniteQueryOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey'>;
|
|
52
|
+
interface InfiniteOptionsBase<TOutput, TError extends Error, TPageParam> {
|
|
53
|
+
queryKey: ComputedRef<QueryKey>;
|
|
54
|
+
queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
|
|
55
|
+
retry?(failureCount: number, error: TError): boolean;
|
|
56
|
+
}
|
|
57
|
+
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
|
58
|
+
context?: TClientContext;
|
|
59
|
+
} : {
|
|
60
|
+
context: TClientContext;
|
|
61
|
+
}) & {
|
|
62
|
+
[P in keyof MutationObserverOptions<TOutput, TError, TInput, TMutationContext>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput, TMutationContext>[P]>;
|
|
63
|
+
} & {
|
|
64
|
+
shallow?: MaybeRef<boolean>;
|
|
65
|
+
};
|
|
66
|
+
interface MutationOptionsBase<TInput, TOutput, TError extends Error> {
|
|
67
|
+
mutationKey: QueryKey;
|
|
68
|
+
mutationFn(input: TInput): Promise<TOutput>;
|
|
69
|
+
retry?(failureCount: number, error: TError): boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
|
|
73
|
+
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
74
|
+
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
|
75
|
+
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>>;
|
|
76
|
+
mutationOptions<U, UMutationContext>(...rest: MaybeOptionalOptions<U & MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<U & Omit<MutationOptionsBase<TInput, TOutput, TError>, keyof U>>;
|
|
77
|
+
}
|
|
78
|
+
declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, path: string[]): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
|
79
|
+
|
|
80
|
+
type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
|
|
81
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
|
|
82
|
+
} & GeneralUtils<unknown>;
|
|
83
|
+
/**
|
|
84
|
+
* @param client - Any kind of oRPC clients: `createRouterClient`, `createORPCClient`, ...
|
|
85
|
+
* @param path - The base path for query key, when it it will be prefix to all keys
|
|
86
|
+
*/
|
|
87
|
+
declare function createRouterUtils<T extends NestedClient<any>>(client: T, path?: string[]): RouterUtils<T>;
|
|
88
|
+
|
|
89
|
+
declare const createORPCVueQueryUtils: typeof createRouterUtils;
|
|
90
|
+
|
|
91
|
+
export { type BuildKeyOptions, type GeneralUtils, type InfiniteOptionsBase, type InfiniteOptionsIn, type KeyType, type MaybeRefDeep, type MutationOptionsBase, type MutationOptionsIn, type ProcedureUtils, type QueryOptionsBase, type QueryOptionsIn, type RouterUtils, buildKey, createGeneralUtils, createORPCVueQueryUtils, createProcedureUtils, createRouterUtils };
|
|
@@ -1,77 +1,70 @@
|
|
|
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 } : {};
|
|
5
|
-
return [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
return [path, {
|
|
8
|
+
...withInput,
|
|
9
|
+
...withType
|
|
10
|
+
}];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function createGeneralUtils(path) {
|
|
14
|
+
return {
|
|
15
|
+
key(options) {
|
|
16
|
+
return buildKey(path, options);
|
|
11
17
|
}
|
|
12
|
-
|
|
18
|
+
};
|
|
13
19
|
}
|
|
14
20
|
|
|
15
|
-
|
|
16
|
-
import { isRef } from "vue";
|
|
17
|
-
function deepUnref(value) {
|
|
21
|
+
function unrefDeep(value) {
|
|
18
22
|
if (isRef(value)) {
|
|
19
|
-
return
|
|
23
|
+
return unrefDeep(value.value);
|
|
20
24
|
}
|
|
21
25
|
if (Array.isArray(value)) {
|
|
22
|
-
return value.map(
|
|
26
|
+
return value.map(unrefDeep);
|
|
23
27
|
}
|
|
24
|
-
if (value
|
|
28
|
+
if (isObject(value)) {
|
|
25
29
|
return Object.keys(value).reduce((acc, key) => {
|
|
26
|
-
acc[key] =
|
|
30
|
+
acc[key] = unrefDeep(value[key]);
|
|
27
31
|
return acc;
|
|
28
32
|
}, {});
|
|
29
33
|
}
|
|
30
34
|
return value;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
// src/utils-general.ts
|
|
34
|
-
function createGeneralUtils(path) {
|
|
35
|
-
return {
|
|
36
|
-
key(options) {
|
|
37
|
-
return buildKey(path, deepUnref(options));
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// src/utils-procedure.ts
|
|
43
|
-
import { computed } from "vue";
|
|
44
37
|
function createProcedureUtils(client, path) {
|
|
45
38
|
return {
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
call: client,
|
|
40
|
+
queryOptions(...[{ input, context, ...rest } = {}]) {
|
|
48
41
|
return {
|
|
49
|
-
queryKey: computed(() => buildKey(path, { type: "query", input:
|
|
50
|
-
queryFn: ({ signal }) => client(
|
|
51
|
-
...
|
|
42
|
+
queryKey: computed(() => buildKey(path, { type: "query", input: unrefDeep(input) })),
|
|
43
|
+
queryFn: ({ signal }) => client(unrefDeep(input), { signal, context: unrefDeep(context) }),
|
|
44
|
+
...rest
|
|
52
45
|
};
|
|
53
46
|
},
|
|
54
|
-
infiniteOptions(
|
|
55
|
-
const input = options.input;
|
|
47
|
+
infiniteOptions({ input, context, ...rest }) {
|
|
56
48
|
return {
|
|
57
|
-
queryKey: computed(() =>
|
|
49
|
+
queryKey: computed(() => {
|
|
50
|
+
return buildKey(path, { type: "infinite", input: unrefDeep(input(unrefDeep(rest.initialPageParam))) });
|
|
51
|
+
}),
|
|
58
52
|
queryFn: ({ pageParam, signal }) => {
|
|
59
|
-
return client(
|
|
53
|
+
return client(unrefDeep(input(pageParam)), { signal, context: unrefDeep(context) });
|
|
60
54
|
},
|
|
61
|
-
...
|
|
55
|
+
...rest
|
|
62
56
|
};
|
|
63
57
|
},
|
|
64
|
-
mutationOptions(...[
|
|
58
|
+
mutationOptions(...[{ context, ...rest } = {}]) {
|
|
65
59
|
return {
|
|
66
60
|
mutationKey: buildKey(path, { type: "mutation" }),
|
|
67
|
-
mutationFn: (input) => client(input, { context:
|
|
68
|
-
...
|
|
61
|
+
mutationFn: (input) => client(input, { context: unrefDeep(context) }),
|
|
62
|
+
...rest
|
|
69
63
|
};
|
|
70
64
|
}
|
|
71
65
|
};
|
|
72
66
|
}
|
|
73
67
|
|
|
74
|
-
// src/utils-router.ts
|
|
75
68
|
function createRouterUtils(client, path = []) {
|
|
76
69
|
const generalUtils = createGeneralUtils(path);
|
|
77
70
|
const procedureUtils = createProcedureUtils(client, path);
|
|
@@ -98,13 +91,6 @@ function createRouterUtils(client, path = []) {
|
|
|
98
91
|
return recursive;
|
|
99
92
|
}
|
|
100
93
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
export {
|
|
104
|
-
buildKey,
|
|
105
|
-
createGeneralUtils,
|
|
106
|
-
createORPCVueQueryUtils,
|
|
107
|
-
createProcedureUtils,
|
|
108
|
-
createRouterUtils
|
|
109
|
-
};
|
|
110
|
-
//# sourceMappingURL=index.js.map
|
|
94
|
+
const createORPCVueQueryUtils = createRouterUtils;
|
|
95
|
+
|
|
96
|
+
export { buildKey, createGeneralUtils, createORPCVueQueryUtils, createProcedureUtils, createRouterUtils };
|
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.e7ee5a9",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -18,28 +18,24 @@
|
|
|
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
30
|
"@tanstack/vue-query": ">=5.50.0",
|
|
36
31
|
"vue": ">=3.3.0",
|
|
37
|
-
"@orpc/
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
"@orpc/client": "0.0.0-next.e7ee5a9"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@orpc/shared": "0.0.0-next.e7ee5a9"
|
|
40
36
|
},
|
|
41
37
|
"scripts": {
|
|
42
|
-
"build": "
|
|
38
|
+
"build": "unbuild",
|
|
43
39
|
"build:watch": "pnpm run build --watch",
|
|
44
40
|
"type:check": "tsc -b"
|
|
45
41
|
}
|
package/dist/src/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { createRouterUtils } from './utils-router';
|
|
2
|
-
export * from './key';
|
|
3
|
-
export * from './types';
|
|
4
|
-
export * from './utils-general';
|
|
5
|
-
export * from './utils-procedure';
|
|
6
|
-
export * from './utils-router';
|
|
7
|
-
export declare const createORPCVueQueryUtils: typeof createRouterUtils;
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/key.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { PartialDeep } from '@orpc/shared';
|
|
2
|
-
import type { QueryKey } from '@tanstack/vue-query';
|
|
3
|
-
export type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
|
|
4
|
-
export interface BuildKeyOptions<TType extends KeyType, TInput> {
|
|
5
|
-
type?: TType;
|
|
6
|
-
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
|
7
|
-
}
|
|
8
|
-
export declare function buildKey<TType extends KeyType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
|
|
9
|
-
//# sourceMappingURL=key.d.ts.map
|
package/dist/src/types.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { AnyFunction, SetOptional } from '@orpc/shared';
|
|
2
|
-
import type { DefaultError, MutationObserverOptions, QueryKey, QueryObserverOptions, UseInfiniteQueryOptions } from '@tanstack/vue-query';
|
|
3
|
-
import type { MaybeRef, MaybeRefOrGetter } from 'vue';
|
|
4
|
-
export type MaybeDeepRef<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
|
|
5
|
-
[K in keyof T]: MaybeDeepRef<T[K]>;
|
|
6
|
-
} : T>;
|
|
7
|
-
export type NonUndefinedGuard<T> = T extends undefined ? never : T;
|
|
8
|
-
export type InferCursor<T> = T extends {
|
|
9
|
-
cursor?: any;
|
|
10
|
-
} ? T['cursor'] : never;
|
|
11
|
-
export type QueryOptions<TInput, TOutput, TClientContext, TSelectData> = (undefined extends TInput ? {
|
|
12
|
-
input?: MaybeDeepRef<TInput>;
|
|
13
|
-
} : {
|
|
14
|
-
input: MaybeDeepRef<TInput>;
|
|
15
|
-
}) & (undefined extends TClientContext ? {
|
|
16
|
-
context?: MaybeDeepRef<TClientContext>;
|
|
17
|
-
} : {
|
|
18
|
-
context: MaybeDeepRef<TClientContext>;
|
|
19
|
-
}) & SetOptional<{
|
|
20
|
-
[P in keyof QueryObserverOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey>]: P extends 'enabled' ? MaybeRefOrGetter<QueryObserverOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey>[P]> : MaybeDeepRef<QueryObserverOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey>[P]>;
|
|
21
|
-
}, 'queryKey'> & {
|
|
22
|
-
shallow?: MaybeRef<boolean>;
|
|
23
|
-
initialData?: NonUndefinedGuard<TOutput> | (() => NonUndefinedGuard<TOutput>) | undefined;
|
|
24
|
-
};
|
|
25
|
-
export type InfiniteOptions<TInput, TOutput, TClientContext, TSelectData> = (undefined extends TInput ? {
|
|
26
|
-
input?: MaybeDeepRef<Omit<TInput, 'cursor'>>;
|
|
27
|
-
} : {
|
|
28
|
-
input: MaybeDeepRef<Omit<TInput, 'cursor'>>;
|
|
29
|
-
}) & (undefined extends TClientContext ? {
|
|
30
|
-
context?: MaybeDeepRef<TClientContext>;
|
|
31
|
-
} : {
|
|
32
|
-
context: MaybeDeepRef<TClientContext>;
|
|
33
|
-
}) & SetOptional<UseInfiniteQueryOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey, InferCursor<TInput>>, 'queryKey' | (undefined extends InferCursor<TInput> ? 'initialPageParam' : never)>;
|
|
34
|
-
export type MutationOptions<TInput, TOutput, TClientContext> = (undefined extends TClientContext ? {
|
|
35
|
-
context?: MaybeDeepRef<TClientContext>;
|
|
36
|
-
} : {
|
|
37
|
-
context: MaybeDeepRef<TClientContext>;
|
|
38
|
-
}) & {
|
|
39
|
-
[P in keyof MutationObserverOptions<TOutput, DefaultError, TInput, unknown>]: MaybeDeepRef<MutationObserverOptions<TOutput, DefaultError, TInput, unknown>[P]>;
|
|
40
|
-
} & {
|
|
41
|
-
shallow?: MaybeRef<boolean>;
|
|
42
|
-
};
|
|
43
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { QueryKey } from '@tanstack/vue-query';
|
|
2
|
-
import type { BuildKeyOptions, KeyType } from './key';
|
|
3
|
-
import type { MaybeDeepRef } from './types';
|
|
4
|
-
/**
|
|
5
|
-
* Utils at any level (procedure or router)
|
|
6
|
-
*/
|
|
7
|
-
export interface GeneralUtils<TInput> {
|
|
8
|
-
key: <UType extends KeyType = undefined>(options?: MaybeDeepRef<BuildKeyOptions<UType, TInput>>) => QueryKey;
|
|
9
|
-
}
|
|
10
|
-
export declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
|
11
|
-
//# sourceMappingURL=utils-general.d.ts.map
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { ProcedureClient } from '@orpc/server';
|
|
2
|
-
import type { IsEqual } from '@orpc/shared';
|
|
3
|
-
import type { QueryFunctionContext, QueryKey } from '@tanstack/vue-query';
|
|
4
|
-
import type { ComputedRef } from 'vue';
|
|
5
|
-
import type { InferCursor, InfiniteOptions, MutationOptions, QueryOptions } from './types';
|
|
6
|
-
/**
|
|
7
|
-
* Utils at procedure level
|
|
8
|
-
*/
|
|
9
|
-
export interface ProcedureUtils<TInput, TOutput, TClientContext> {
|
|
10
|
-
queryOptions: <U extends QueryOptions<TInput, TOutput, TClientContext, any>>(...opt: [options: U] | (undefined extends TInput & TClientContext ? [] : never)) => IsEqual<U, QueryOptions<TInput, TOutput, TClientContext, any>> extends true ? {
|
|
11
|
-
queryKey: ComputedRef<QueryKey>;
|
|
12
|
-
queryFn: (ctx: QueryFunctionContext) => Promise<TOutput>;
|
|
13
|
-
} : Omit<{
|
|
14
|
-
queryKey: ComputedRef<QueryKey>;
|
|
15
|
-
queryFn: (ctx: QueryFunctionContext) => Promise<TOutput>;
|
|
16
|
-
}, keyof U> & U;
|
|
17
|
-
infiniteOptions: <U extends InfiniteOptions<TInput, TOutput, TClientContext, any>>(options: U) => Omit<{
|
|
18
|
-
queryKey: ComputedRef<QueryKey>;
|
|
19
|
-
queryFn: (ctx: QueryFunctionContext<QueryKey, InferCursor<TInput>>) => Promise<TOutput>;
|
|
20
|
-
initialPageParam: undefined;
|
|
21
|
-
}, keyof U> & U;
|
|
22
|
-
mutationOptions: <U extends MutationOptions<TInput, TOutput, TClientContext>>(...opt: [options: U] | (undefined extends TClientContext ? [] : never)) => IsEqual<U, MutationOptions<TInput, TOutput, TClientContext>> extends true ? {
|
|
23
|
-
mutationKey: QueryKey;
|
|
24
|
-
mutationFn: (input: TInput) => Promise<TOutput>;
|
|
25
|
-
} : Omit<{
|
|
26
|
-
mutationKey: QueryKey;
|
|
27
|
-
mutationFn: (input: TInput) => Promise<TOutput>;
|
|
28
|
-
}, keyof U> & U;
|
|
29
|
-
}
|
|
30
|
-
export declare function createProcedureUtils<TInput, TOutput, TClientContext>(client: ProcedureClient<TInput, TOutput, TClientContext>, path: string[]): ProcedureUtils<TInput, TOutput, TClientContext>;
|
|
31
|
-
//# sourceMappingURL=utils-procedure.d.ts.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ProcedureClient, RouterClient } from '@orpc/server';
|
|
2
|
-
import { type GeneralUtils } from './utils-general';
|
|
3
|
-
import { type ProcedureUtils } from './utils-procedure';
|
|
4
|
-
export type RouterUtils<T extends RouterClient<any, any>> = T extends ProcedureClient<infer TInput, infer TOutput, infer TClientContext> ? ProcedureUtils<TInput, TOutput, TClientContext> & GeneralUtils<TInput> : {
|
|
5
|
-
[K in keyof T]: T[K] extends RouterClient<any, any> ? RouterUtils<T[K]> : never;
|
|
6
|
-
} & GeneralUtils<unknown>;
|
|
7
|
-
/**
|
|
8
|
-
* @param client - The client create form `@orpc/client`
|
|
9
|
-
* @param path - The base path for query key
|
|
10
|
-
*/
|
|
11
|
-
export declare function createRouterUtils<T extends RouterClient<any, any>>(client: T, path?: string[]): RouterUtils<T>;
|
|
12
|
-
//# sourceMappingURL=utils-router.d.ts.map
|
package/dist/src/utils.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { AnyFunction } from '@orpc/shared';
|
|
2
|
-
import type { Ref } from 'vue';
|
|
3
|
-
export type DeepUnref<T> = T extends Ref<infer U> ? DeepUnref<U> : T extends AnyFunction ? T : T extends object ? {
|
|
4
|
-
[K in keyof T]: DeepUnref<T[K]>;
|
|
5
|
-
} : T;
|
|
6
|
-
export declare function deepUnref<T>(value: T): DeepUnref<T>;
|
|
7
|
-
//# sourceMappingURL=utils.d.ts.map
|