@orpc/vue-query 0.0.0-next.ff5907c → 0.0.0-next.ff7ad2e
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 +120 -0
- package/dist/index.d.mts +142 -0
- package/dist/index.d.ts +142 -0
- package/dist/index.mjs +126 -0
- package/package.json +12 -13
- package/dist/index.js +0 -110
- 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
ADDED
@@ -0,0 +1,120 @@
|
|
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
|
25
|
+
|
26
|
+
---
|
27
|
+
|
28
|
+
## Highlights
|
29
|
+
|
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
|
+
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
34
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
35
|
+
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
36
|
+
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
37
|
+
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
38
|
+
- **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
|
39
|
+
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
40
|
+
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
41
|
+
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
42
|
+
|
43
|
+
## Documentation
|
44
|
+
|
45
|
+
You can find the full documentation [here](https://orpc.unnoq.com).
|
46
|
+
|
47
|
+
## Packages
|
48
|
+
|
49
|
+
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
50
|
+
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
51
|
+
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
52
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
53
|
+
- [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
|
54
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
55
|
+
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
56
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
57
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
58
|
+
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
59
|
+
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
60
|
+
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
61
|
+
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
62
|
+
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
63
|
+
|
64
|
+
## `@orpc/vue-query`
|
65
|
+
|
66
|
+
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.
|
67
|
+
|
68
|
+
```ts
|
69
|
+
export function Setup() {
|
70
|
+
const query = useQuery(orpc.planet.find.queryOptions({
|
71
|
+
input: { id: 123 }, // Specify input if needed
|
72
|
+
context: { cache: true }, // Provide client context if needed
|
73
|
+
// additional options...
|
74
|
+
}))
|
75
|
+
|
76
|
+
const query = useInfiniteQuery(orpc.planet.list.infiniteOptions({
|
77
|
+
input: (pageParam: number | undefined) => ({ limit: 10, offset: pageParam }),
|
78
|
+
context: { cache: true }, // Provide client context if needed
|
79
|
+
initialPageParam: undefined,
|
80
|
+
getNextPageParam: lastPage => lastPage.nextPageParam,
|
81
|
+
// additional options...
|
82
|
+
}))
|
83
|
+
|
84
|
+
const mutation = useMutation(orpc.planet.create.mutationOptions({
|
85
|
+
context: { cache: true }, // Provide client context if needed
|
86
|
+
// additional options...
|
87
|
+
}))
|
88
|
+
|
89
|
+
mutation.mutate({ name: 'Earth' })
|
90
|
+
|
91
|
+
const queryClient = useQueryClient()
|
92
|
+
|
93
|
+
// Invalidate all planet queries
|
94
|
+
queryClient.invalidateQueries({
|
95
|
+
queryKey: orpc.planet.key(),
|
96
|
+
})
|
97
|
+
|
98
|
+
// Invalidate only regular (non-infinite) planet queries
|
99
|
+
queryClient.invalidateQueries({
|
100
|
+
queryKey: orpc.planet.key({ type: 'query' })
|
101
|
+
})
|
102
|
+
|
103
|
+
// Invalidate the planet find query with id 123
|
104
|
+
queryClient.invalidateQueries({
|
105
|
+
queryKey: orpc.planet.find.key({ input: { id: 123 } })
|
106
|
+
})
|
107
|
+
}
|
108
|
+
```
|
109
|
+
|
110
|
+
## Sponsors
|
111
|
+
|
112
|
+
<p align="center">
|
113
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
114
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
115
|
+
</a>
|
116
|
+
</p>
|
117
|
+
|
118
|
+
## License
|
119
|
+
|
120
|
+
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,142 @@
|
|
1
|
+
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
2
|
+
import { OperationType, OperationKeyOptions } from '@orpc/tanstack-query';
|
3
|
+
export { OperationKeyOptions as BuildKeyOptions, OperationType as KeyType, generateOperationKey as buildKey } from '@orpc/tanstack-query';
|
4
|
+
import { QueryKey, SkipToken, QueryObserverOptions, QueryFunctionContext, experimental_streamedQuery, InfiniteQueryObserverOptions, MutationObserverOptions, InfiniteData } from '@tanstack/vue-query';
|
5
|
+
import { AnyFunction, MaybeOptionalOptions } from '@orpc/shared';
|
6
|
+
import { MaybeRef, MaybeRefOrGetter, ComputedRef, Ref } from 'vue';
|
7
|
+
|
8
|
+
interface GeneralUtils<TInput> {
|
9
|
+
/**
|
10
|
+
* Generate a query/mutation key for checking status, invalidate, set, get, etc.
|
11
|
+
*
|
12
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
|
13
|
+
*/
|
14
|
+
key<UType extends OperationType>(options?: OperationKeyOptions<UType, TInput>): QueryKey;
|
15
|
+
}
|
16
|
+
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Since `@tanstack/vue-query` is not exporting the type `MaybeRefDeep` we need to copy it from the source code.
|
20
|
+
* https://github.com/TanStack/query/blob/7ff544e12e79388e513b1cd886aeb946f80f0153/packages/vue-query/src/types.ts#L19C1-L27C2
|
21
|
+
*/
|
22
|
+
type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
|
23
|
+
[Property in keyof T]: MaybeRefDeep<T[Property]>;
|
24
|
+
} : T>;
|
25
|
+
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
|
26
|
+
input?: MaybeRefDeep<TInput | SkipToken>;
|
27
|
+
} : {
|
28
|
+
input: MaybeRefDeep<TInput | SkipToken>;
|
29
|
+
}) & (Record<never, never> extends TClientContext ? {
|
30
|
+
context?: MaybeRefDeep<TClientContext>;
|
31
|
+
} : {
|
32
|
+
context: MaybeRefDeep<TClientContext>;
|
33
|
+
}) & {
|
34
|
+
[P in keyof Omit<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>, 'queryKey' | 'enabled'>]: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>[P]>;
|
35
|
+
} & {
|
36
|
+
enabled?: MaybeRefOrGetter<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['enabled']>;
|
37
|
+
queryKey?: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['queryKey']>;
|
38
|
+
shallow?: boolean;
|
39
|
+
};
|
40
|
+
interface QueryOptionsBase<TOutput, TError> {
|
41
|
+
queryKey: ComputedRef<QueryKey>;
|
42
|
+
queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
|
43
|
+
throwOnError?(error: TError): boolean;
|
44
|
+
retryDelay?: (count: number, error: TError) => number;
|
45
|
+
enabled: ComputedRef<boolean | undefined>;
|
46
|
+
}
|
47
|
+
type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
|
48
|
+
type experimental_InferStreamedOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
49
|
+
type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & {
|
50
|
+
queryFnOptions?: experimental_StreamedQueryOptions;
|
51
|
+
};
|
52
|
+
interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
|
53
|
+
}
|
54
|
+
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = (Record<never, never> extends TClientContext ? {
|
55
|
+
context?: MaybeRefDeep<TClientContext>;
|
56
|
+
} : {
|
57
|
+
context: MaybeRefDeep<TClientContext>;
|
58
|
+
}) & {
|
59
|
+
[Property in keyof Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey' | 'enabled'>]: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>[Property]>;
|
60
|
+
} & {
|
61
|
+
input: MaybeRef<((pageParam: TPageParam) => MaybeRefDeep<TInput>) | SkipToken>;
|
62
|
+
enabled?: MaybeRefOrGetter<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>['enabled']>;
|
63
|
+
queryKey?: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>['queryKey']>;
|
64
|
+
shallow?: boolean;
|
65
|
+
};
|
66
|
+
interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
|
67
|
+
queryKey: ComputedRef<QueryKey>;
|
68
|
+
queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
|
69
|
+
throwOnError?(error: TError): boolean;
|
70
|
+
retryDelay?: (count: number, error: TError) => number;
|
71
|
+
enabled: ComputedRef<boolean | undefined>;
|
72
|
+
}
|
73
|
+
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
74
|
+
context?: TClientContext;
|
75
|
+
} : {
|
76
|
+
context: TClientContext;
|
77
|
+
}) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
|
78
|
+
type MutationOptions<TInput, TOutput, TError, TMutationContext> = {
|
79
|
+
[P in keyof MutationObserverOptions<TOutput, TError, TInput, TMutationContext>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput, TMutationContext>[P]>;
|
80
|
+
} & {
|
81
|
+
shallow?: MaybeRef<boolean>;
|
82
|
+
};
|
83
|
+
|
84
|
+
interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
85
|
+
/**
|
86
|
+
* Calling corresponding procedure client
|
87
|
+
*
|
88
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
|
89
|
+
*/
|
90
|
+
call: Client<TClientContext, TInput, TOutput, TError>;
|
91
|
+
/**
|
92
|
+
* Generate options used for useQuery/prefetchQuery/...
|
93
|
+
*
|
94
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-options-utility Tanstack Query Options Utility Docs}
|
95
|
+
*/
|
96
|
+
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
97
|
+
/**
|
98
|
+
* Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/prefetchQuery/...
|
99
|
+
* Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
100
|
+
*
|
101
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
|
102
|
+
*/
|
103
|
+
experimental_streamedOptions<U, USelectData = experimental_InferStreamedOutput<TOutput>>(...rest: MaybeOptionalOptions<U & experimental_StreamedOptionsIn<TClientContext, TInput, experimental_InferStreamedOutput<TOutput>, TError, USelectData>>): NoInfer<U & Omit<experimental_StreamedOptionsBase<experimental_InferStreamedOutput<TOutput>, TError>, keyof U>>;
|
104
|
+
/**
|
105
|
+
* Generate options used for useInfiniteQuery/prefetchInfiniteQuery/...
|
106
|
+
*
|
107
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
|
108
|
+
*/
|
109
|
+
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>>;
|
110
|
+
/**
|
111
|
+
* Generate options used for useMutation/...
|
112
|
+
*
|
113
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#mutation-options Tanstack Mutation Options Docs}
|
114
|
+
*/
|
115
|
+
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
|
116
|
+
}
|
117
|
+
interface CreateProcedureUtilsOptions {
|
118
|
+
path: string[];
|
119
|
+
}
|
120
|
+
declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
121
|
+
|
122
|
+
type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
|
123
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
|
124
|
+
} & GeneralUtils<unknown>;
|
125
|
+
interface CreateRouterUtilsOptions {
|
126
|
+
path?: string[];
|
127
|
+
}
|
128
|
+
/**
|
129
|
+
* Create a router utils from a client.
|
130
|
+
*
|
131
|
+
* @info Both client-side and server-side clients are supported.
|
132
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/vue Tanstack Query Vue Docs}
|
133
|
+
*/
|
134
|
+
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
135
|
+
|
136
|
+
type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunction ? T : T extends object ? {
|
137
|
+
[K in keyof T]: UnrefDeep<T[K]>;
|
138
|
+
} : T;
|
139
|
+
declare function unrefDeep<T>(value: T): UnrefDeep<T>;
|
140
|
+
|
141
|
+
export { createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
|
142
|
+
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MaybeRefDeep, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, UnrefDeep, experimental_InferStreamedOutput, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn };
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
2
|
+
import { OperationType, OperationKeyOptions } from '@orpc/tanstack-query';
|
3
|
+
export { OperationKeyOptions as BuildKeyOptions, OperationType as KeyType, generateOperationKey as buildKey } from '@orpc/tanstack-query';
|
4
|
+
import { QueryKey, SkipToken, QueryObserverOptions, QueryFunctionContext, experimental_streamedQuery, InfiniteQueryObserverOptions, MutationObserverOptions, InfiniteData } from '@tanstack/vue-query';
|
5
|
+
import { AnyFunction, MaybeOptionalOptions } from '@orpc/shared';
|
6
|
+
import { MaybeRef, MaybeRefOrGetter, ComputedRef, Ref } from 'vue';
|
7
|
+
|
8
|
+
interface GeneralUtils<TInput> {
|
9
|
+
/**
|
10
|
+
* Generate a query/mutation key for checking status, invalidate, set, get, etc.
|
11
|
+
*
|
12
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
|
13
|
+
*/
|
14
|
+
key<UType extends OperationType>(options?: OperationKeyOptions<UType, TInput>): QueryKey;
|
15
|
+
}
|
16
|
+
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Since `@tanstack/vue-query` is not exporting the type `MaybeRefDeep` we need to copy it from the source code.
|
20
|
+
* https://github.com/TanStack/query/blob/7ff544e12e79388e513b1cd886aeb946f80f0153/packages/vue-query/src/types.ts#L19C1-L27C2
|
21
|
+
*/
|
22
|
+
type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
|
23
|
+
[Property in keyof T]: MaybeRefDeep<T[Property]>;
|
24
|
+
} : T>;
|
25
|
+
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
|
26
|
+
input?: MaybeRefDeep<TInput | SkipToken>;
|
27
|
+
} : {
|
28
|
+
input: MaybeRefDeep<TInput | SkipToken>;
|
29
|
+
}) & (Record<never, never> extends TClientContext ? {
|
30
|
+
context?: MaybeRefDeep<TClientContext>;
|
31
|
+
} : {
|
32
|
+
context: MaybeRefDeep<TClientContext>;
|
33
|
+
}) & {
|
34
|
+
[P in keyof Omit<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>, 'queryKey' | 'enabled'>]: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>[P]>;
|
35
|
+
} & {
|
36
|
+
enabled?: MaybeRefOrGetter<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['enabled']>;
|
37
|
+
queryKey?: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['queryKey']>;
|
38
|
+
shallow?: boolean;
|
39
|
+
};
|
40
|
+
interface QueryOptionsBase<TOutput, TError> {
|
41
|
+
queryKey: ComputedRef<QueryKey>;
|
42
|
+
queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
|
43
|
+
throwOnError?(error: TError): boolean;
|
44
|
+
retryDelay?: (count: number, error: TError) => number;
|
45
|
+
enabled: ComputedRef<boolean | undefined>;
|
46
|
+
}
|
47
|
+
type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
|
48
|
+
type experimental_InferStreamedOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
49
|
+
type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & {
|
50
|
+
queryFnOptions?: experimental_StreamedQueryOptions;
|
51
|
+
};
|
52
|
+
interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
|
53
|
+
}
|
54
|
+
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = (Record<never, never> extends TClientContext ? {
|
55
|
+
context?: MaybeRefDeep<TClientContext>;
|
56
|
+
} : {
|
57
|
+
context: MaybeRefDeep<TClientContext>;
|
58
|
+
}) & {
|
59
|
+
[Property in keyof Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey' | 'enabled'>]: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>[Property]>;
|
60
|
+
} & {
|
61
|
+
input: MaybeRef<((pageParam: TPageParam) => MaybeRefDeep<TInput>) | SkipToken>;
|
62
|
+
enabled?: MaybeRefOrGetter<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>['enabled']>;
|
63
|
+
queryKey?: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>['queryKey']>;
|
64
|
+
shallow?: boolean;
|
65
|
+
};
|
66
|
+
interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
|
67
|
+
queryKey: ComputedRef<QueryKey>;
|
68
|
+
queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
|
69
|
+
throwOnError?(error: TError): boolean;
|
70
|
+
retryDelay?: (count: number, error: TError) => number;
|
71
|
+
enabled: ComputedRef<boolean | undefined>;
|
72
|
+
}
|
73
|
+
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
74
|
+
context?: TClientContext;
|
75
|
+
} : {
|
76
|
+
context: TClientContext;
|
77
|
+
}) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
|
78
|
+
type MutationOptions<TInput, TOutput, TError, TMutationContext> = {
|
79
|
+
[P in keyof MutationObserverOptions<TOutput, TError, TInput, TMutationContext>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput, TMutationContext>[P]>;
|
80
|
+
} & {
|
81
|
+
shallow?: MaybeRef<boolean>;
|
82
|
+
};
|
83
|
+
|
84
|
+
interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
85
|
+
/**
|
86
|
+
* Calling corresponding procedure client
|
87
|
+
*
|
88
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
|
89
|
+
*/
|
90
|
+
call: Client<TClientContext, TInput, TOutput, TError>;
|
91
|
+
/**
|
92
|
+
* Generate options used for useQuery/prefetchQuery/...
|
93
|
+
*
|
94
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-options-utility Tanstack Query Options Utility Docs}
|
95
|
+
*/
|
96
|
+
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
97
|
+
/**
|
98
|
+
* Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/prefetchQuery/...
|
99
|
+
* Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
100
|
+
*
|
101
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
|
102
|
+
*/
|
103
|
+
experimental_streamedOptions<U, USelectData = experimental_InferStreamedOutput<TOutput>>(...rest: MaybeOptionalOptions<U & experimental_StreamedOptionsIn<TClientContext, TInput, experimental_InferStreamedOutput<TOutput>, TError, USelectData>>): NoInfer<U & Omit<experimental_StreamedOptionsBase<experimental_InferStreamedOutput<TOutput>, TError>, keyof U>>;
|
104
|
+
/**
|
105
|
+
* Generate options used for useInfiniteQuery/prefetchInfiniteQuery/...
|
106
|
+
*
|
107
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
|
108
|
+
*/
|
109
|
+
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>>;
|
110
|
+
/**
|
111
|
+
* Generate options used for useMutation/...
|
112
|
+
*
|
113
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#mutation-options Tanstack Mutation Options Docs}
|
114
|
+
*/
|
115
|
+
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
|
116
|
+
}
|
117
|
+
interface CreateProcedureUtilsOptions {
|
118
|
+
path: string[];
|
119
|
+
}
|
120
|
+
declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
121
|
+
|
122
|
+
type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
|
123
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
|
124
|
+
} & GeneralUtils<unknown>;
|
125
|
+
interface CreateRouterUtilsOptions {
|
126
|
+
path?: string[];
|
127
|
+
}
|
128
|
+
/**
|
129
|
+
* Create a router utils from a client.
|
130
|
+
*
|
131
|
+
* @info Both client-side and server-side clients are supported.
|
132
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/vue Tanstack Query Vue Docs}
|
133
|
+
*/
|
134
|
+
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
135
|
+
|
136
|
+
type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunction ? T : T extends object ? {
|
137
|
+
[K in keyof T]: UnrefDeep<T[K]>;
|
138
|
+
} : T;
|
139
|
+
declare function unrefDeep<T>(value: T): UnrefDeep<T>;
|
140
|
+
|
141
|
+
export { createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
|
142
|
+
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MaybeRefDeep, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, UnrefDeep, experimental_InferStreamedOutput, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn };
|
package/dist/index.mjs
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
import { generateOperationKey } from '@orpc/tanstack-query';
|
2
|
+
export { generateOperationKey as buildKey } from '@orpc/tanstack-query';
|
3
|
+
import { isObject, isAsyncIteratorObject } from '@orpc/shared';
|
4
|
+
import { skipToken, experimental_streamedQuery } from '@tanstack/vue-query';
|
5
|
+
import { isRef, computed } from 'vue';
|
6
|
+
|
7
|
+
function createGeneralUtils(path) {
|
8
|
+
return {
|
9
|
+
key(options) {
|
10
|
+
return generateOperationKey(path, options);
|
11
|
+
}
|
12
|
+
};
|
13
|
+
}
|
14
|
+
|
15
|
+
function unrefDeep(value) {
|
16
|
+
if (isRef(value)) {
|
17
|
+
return unrefDeep(value.value);
|
18
|
+
}
|
19
|
+
if (Array.isArray(value)) {
|
20
|
+
return value.map(unrefDeep);
|
21
|
+
}
|
22
|
+
if (isObject(value)) {
|
23
|
+
return Object.keys(value).reduce((acc, key) => {
|
24
|
+
acc[key] = unrefDeep(value[key]);
|
25
|
+
return acc;
|
26
|
+
}, {});
|
27
|
+
}
|
28
|
+
return value;
|
29
|
+
}
|
30
|
+
|
31
|
+
function createProcedureUtils(client, options) {
|
32
|
+
return {
|
33
|
+
call: client,
|
34
|
+
queryOptions(...[optionsIn = {}]) {
|
35
|
+
return {
|
36
|
+
queryKey: computed(() => generateOperationKey(options.path, { type: "query", input: unrefDeep(optionsIn.input) })),
|
37
|
+
queryFn: ({ signal }) => {
|
38
|
+
const input = unrefDeep(optionsIn.input);
|
39
|
+
if (input === skipToken) {
|
40
|
+
throw new Error("queryFn should not be called with skipToken used as input");
|
41
|
+
}
|
42
|
+
return client(input, { signal, context: unrefDeep(optionsIn.context) });
|
43
|
+
},
|
44
|
+
enabled: computed(() => unrefDeep(optionsIn.input) === skipToken ? false : void 0),
|
45
|
+
...optionsIn
|
46
|
+
};
|
47
|
+
},
|
48
|
+
experimental_streamedOptions(...[optionsIn = {}]) {
|
49
|
+
return {
|
50
|
+
enabled: computed(() => unrefDeep(optionsIn.input) === skipToken ? false : void 0),
|
51
|
+
queryKey: computed(() => generateOperationKey(options.path, { type: "streamed", input: unrefDeep(optionsIn.input), fnOptions: optionsIn.queryFnOptions })),
|
52
|
+
queryFn: experimental_streamedQuery({
|
53
|
+
queryFn: async ({ signal }) => {
|
54
|
+
const input = unrefDeep(optionsIn.input);
|
55
|
+
if (input === skipToken) {
|
56
|
+
throw new Error("queryFn should not be called with skipToken used as input");
|
57
|
+
}
|
58
|
+
const output = await client(input, { signal, context: unrefDeep(optionsIn.context) });
|
59
|
+
if (!isAsyncIteratorObject(output)) {
|
60
|
+
throw new Error("streamedQuery requires an event iterator output");
|
61
|
+
}
|
62
|
+
return output;
|
63
|
+
},
|
64
|
+
...optionsIn.queryFnOptions
|
65
|
+
}),
|
66
|
+
...optionsIn
|
67
|
+
};
|
68
|
+
},
|
69
|
+
infiniteOptions(optionsIn) {
|
70
|
+
return {
|
71
|
+
queryKey: computed(() => {
|
72
|
+
const input = unrefDeep(optionsIn.input);
|
73
|
+
return generateOperationKey(options.path, {
|
74
|
+
type: "infinite",
|
75
|
+
input: input === skipToken ? skipToken : unrefDeep(input(unrefDeep(optionsIn.initialPageParam)))
|
76
|
+
});
|
77
|
+
}),
|
78
|
+
queryFn: ({ pageParam, signal }) => {
|
79
|
+
const input = unrefDeep(optionsIn.input);
|
80
|
+
if (input === skipToken) {
|
81
|
+
throw new Error("queryFn should not be called with skipToken used as input");
|
82
|
+
}
|
83
|
+
return client(unrefDeep(input(pageParam)), { signal, context: unrefDeep(optionsIn.context) });
|
84
|
+
},
|
85
|
+
enabled: computed(() => unrefDeep(optionsIn.input) === skipToken ? false : void 0),
|
86
|
+
...optionsIn
|
87
|
+
};
|
88
|
+
},
|
89
|
+
mutationOptions(...[optionsIn = {}]) {
|
90
|
+
return {
|
91
|
+
mutationKey: generateOperationKey(options.path, { type: "mutation" }),
|
92
|
+
mutationFn: (input) => client(input, { context: unrefDeep(optionsIn.context) }),
|
93
|
+
...optionsIn
|
94
|
+
};
|
95
|
+
}
|
96
|
+
};
|
97
|
+
}
|
98
|
+
|
99
|
+
function createRouterUtils(client, options = {}) {
|
100
|
+
const path = options.path ?? [];
|
101
|
+
const generalUtils = createGeneralUtils(path);
|
102
|
+
const procedureUtils = createProcedureUtils(client, { path });
|
103
|
+
const recursive = new Proxy({
|
104
|
+
...generalUtils,
|
105
|
+
...procedureUtils
|
106
|
+
}, {
|
107
|
+
get(target, prop) {
|
108
|
+
const value = Reflect.get(target, prop);
|
109
|
+
if (typeof prop !== "string") {
|
110
|
+
return value;
|
111
|
+
}
|
112
|
+
const nextUtils = createRouterUtils(client[prop], { ...options, path: [...path, prop] });
|
113
|
+
if (typeof value !== "function") {
|
114
|
+
return nextUtils;
|
115
|
+
}
|
116
|
+
return new Proxy(value, {
|
117
|
+
get(_, prop2) {
|
118
|
+
return Reflect.get(nextUtils, prop2);
|
119
|
+
}
|
120
|
+
});
|
121
|
+
}
|
122
|
+
});
|
123
|
+
return recursive;
|
124
|
+
}
|
125
|
+
|
126
|
+
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.ff7ad2e",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -18,29 +18,28 @@
|
|
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.80.2",
|
36
31
|
"vue": ">=3.3.0",
|
37
|
-
"@orpc/client": "0.0.0-next.
|
32
|
+
"@orpc/client": "0.0.0-next.ff7ad2e"
|
38
33
|
},
|
39
34
|
"dependencies": {
|
40
|
-
"@orpc/shared": "0.0.0-next.
|
35
|
+
"@orpc/shared": "0.0.0-next.ff7ad2e",
|
36
|
+
"@orpc/tanstack-query": "0.0.0-next.ff7ad2e"
|
37
|
+
},
|
38
|
+
"devDependencies": {
|
39
|
+
"@tanstack/vue-query": "^5.85.3"
|
41
40
|
},
|
42
41
|
"scripts": {
|
43
|
-
"build": "
|
42
|
+
"build": "unbuild",
|
44
43
|
"build:watch": "pnpm run build --watch",
|
45
44
|
"type:check": "tsc -b"
|
46
45
|
}
|
package/dist/index.js
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
// src/key.ts
|
2
|
-
function buildKey(path, options) {
|
3
|
-
const withInput = options?.input !== void 0 ? { input: options?.input } : {};
|
4
|
-
const withType = options?.type !== void 0 ? { type: options?.type } : {};
|
5
|
-
return [path, {
|
6
|
-
...withInput,
|
7
|
-
...withType
|
8
|
-
}];
|
9
|
-
}
|
10
|
-
|
11
|
-
// src/general-utils.ts
|
12
|
-
function createGeneralUtils(path) {
|
13
|
-
return {
|
14
|
-
key(options) {
|
15
|
-
return buildKey(path, options);
|
16
|
-
}
|
17
|
-
};
|
18
|
-
}
|
19
|
-
|
20
|
-
// src/procedure-utils.ts
|
21
|
-
import { computed } from "vue";
|
22
|
-
|
23
|
-
// src/utils.ts
|
24
|
-
import { isObject } from "@orpc/shared";
|
25
|
-
import { isRef } from "vue";
|
26
|
-
function unrefDeep(value) {
|
27
|
-
if (isRef(value)) {
|
28
|
-
return unrefDeep(value.value);
|
29
|
-
}
|
30
|
-
if (Array.isArray(value)) {
|
31
|
-
return value.map(unrefDeep);
|
32
|
-
}
|
33
|
-
if (isObject(value)) {
|
34
|
-
return Object.keys(value).reduce((acc, key) => {
|
35
|
-
acc[key] = unrefDeep(value[key]);
|
36
|
-
return acc;
|
37
|
-
}, {});
|
38
|
-
}
|
39
|
-
return value;
|
40
|
-
}
|
41
|
-
|
42
|
-
// src/procedure-utils.ts
|
43
|
-
function createProcedureUtils(client, path) {
|
44
|
-
return {
|
45
|
-
call: client,
|
46
|
-
queryOptions(...[{ input, context, ...rest } = {}]) {
|
47
|
-
return {
|
48
|
-
queryKey: computed(() => buildKey(path, { type: "query", input: unrefDeep(input) })),
|
49
|
-
queryFn: ({ signal }) => client(unrefDeep(input), { signal, context: unrefDeep(context) }),
|
50
|
-
...rest
|
51
|
-
};
|
52
|
-
},
|
53
|
-
infiniteOptions({ input, context, ...rest }) {
|
54
|
-
return {
|
55
|
-
queryKey: computed(() => {
|
56
|
-
return buildKey(path, { type: "infinite", input: unrefDeep(input(unrefDeep(rest.initialPageParam))) });
|
57
|
-
}),
|
58
|
-
queryFn: ({ pageParam, signal }) => {
|
59
|
-
return client(unrefDeep(input(pageParam)), { signal, context: unrefDeep(context) });
|
60
|
-
},
|
61
|
-
...rest
|
62
|
-
};
|
63
|
-
},
|
64
|
-
mutationOptions(...[{ context, ...rest } = {}]) {
|
65
|
-
return {
|
66
|
-
mutationKey: buildKey(path, { type: "mutation" }),
|
67
|
-
mutationFn: (input) => client(input, { context: unrefDeep(context) }),
|
68
|
-
...rest
|
69
|
-
};
|
70
|
-
}
|
71
|
-
};
|
72
|
-
}
|
73
|
-
|
74
|
-
// src/router-utils.ts
|
75
|
-
function createRouterUtils(client, path = []) {
|
76
|
-
const generalUtils = createGeneralUtils(path);
|
77
|
-
const procedureUtils = createProcedureUtils(client, path);
|
78
|
-
const recursive = new Proxy({
|
79
|
-
...generalUtils,
|
80
|
-
...procedureUtils
|
81
|
-
}, {
|
82
|
-
get(target, prop) {
|
83
|
-
const value = Reflect.get(target, prop);
|
84
|
-
if (typeof prop !== "string") {
|
85
|
-
return value;
|
86
|
-
}
|
87
|
-
const nextUtils = createRouterUtils(client[prop], [...path, prop]);
|
88
|
-
if (typeof value !== "function") {
|
89
|
-
return nextUtils;
|
90
|
-
}
|
91
|
-
return new Proxy(value, {
|
92
|
-
get(_, prop2) {
|
93
|
-
return Reflect.get(nextUtils, prop2);
|
94
|
-
}
|
95
|
-
});
|
96
|
-
}
|
97
|
-
});
|
98
|
-
return recursive;
|
99
|
-
}
|
100
|
-
|
101
|
-
// src/index.ts
|
102
|
-
var createORPCVueQueryUtils = createRouterUtils;
|
103
|
-
export {
|
104
|
-
buildKey,
|
105
|
-
createGeneralUtils,
|
106
|
-
createORPCVueQueryUtils,
|
107
|
-
createProcedureUtils,
|
108
|
-
createRouterUtils
|
109
|
-
};
|
110
|
-
//# sourceMappingURL=index.js.map
|
@@ -1,7 +0,0 @@
|
|
1
|
-
import type { QueryKey } from '@tanstack/vue-query';
|
2
|
-
import type { BuildKeyOptions, KeyType } from './key';
|
3
|
-
export interface GeneralUtils<TInput> {
|
4
|
-
key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
|
5
|
-
}
|
6
|
-
export declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
7
|
-
//# sourceMappingURL=general-utils.d.ts.map
|
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
|