@orpc/vue-query 0.0.0-next.ff68fdb → 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 CHANGED
@@ -21,28 +21,24 @@
21
21
 
22
22
  <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
23
23
 
24
- **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards, ensuring a smooth and enjoyable developer experience.
24
+ **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
25
25
 
26
26
  ---
27
27
 
28
28
  ## Highlights
29
29
 
30
- - **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
31
- - **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
32
- - **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
33
- - **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
34
- - **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
35
- - **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
36
- - **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
37
- - **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
38
- - **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
39
- - **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
40
- - **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
41
- - **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
42
- - **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
43
- - **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
44
- - **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
45
- - **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
30
+ - **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
31
+ - **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
32
+ - **📝 Contract-First Development**: Optionally define your API contract before implementation.
33
+ - **🔍 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.
46
42
 
47
43
  ## Documentation
48
44
 
@@ -53,17 +49,21 @@ 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.
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/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
59
- - [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
60
- - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
61
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.
62
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
63
 
64
64
  ## `@orpc/vue-query`
65
65
 
66
- 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.
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
67
 
68
68
  ```ts
69
69
  export function Setup() {
@@ -107,6 +107,14 @@ export function Setup() {
107
107
  }
108
108
  ```
109
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
+
110
118
  ## License
111
119
 
112
120
  Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
package/dist/index.d.mts CHANGED
@@ -1,17 +1,17 @@
1
1
  import { ClientContext, Client, NestedClient } from '@orpc/client';
2
- import { QueryKey, QueryObserverOptions, QueryFunctionContext, UseInfiniteQueryOptions, MutationObserverOptions, InfiniteData } from '@tanstack/vue-query';
3
- import { PartialDeep, AnyFunction, SetOptional, MaybeOptionalOptions } from '@orpc/shared';
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';
4
6
  import { MaybeRef, MaybeRefOrGetter, ComputedRef, Ref } from 'vue';
5
7
 
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
8
  interface GeneralUtils<TInput> {
14
- key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
9
+ /**
10
+ * Generate a query/mutation key for checking status, invalidate, set, get, etc.
11
+ *
12
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
13
+ */
14
+ key<UType extends OperationType>(options?: OperationKeyOptions<UType, TInput>): QueryKey;
15
15
  }
16
16
  declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
17
17
 
@@ -22,10 +22,10 @@ declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput
22
22
  type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
23
23
  [Property in keyof T]: MaybeRefDeep<T[Property]>;
24
24
  } : T>;
25
- type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData> = (undefined extends TInput ? {
26
- input?: MaybeRefDeep<TInput>;
25
+ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
26
+ input?: MaybeRefDeep<TInput | SkipToken>;
27
27
  } : {
28
- input: MaybeRefDeep<TInput>;
28
+ input: MaybeRefDeep<TInput | SkipToken>;
29
29
  }) & (Record<never, never> extends TClientContext ? {
30
30
  context?: MaybeRefDeep<TClientContext>;
31
31
  } : {
@@ -35,46 +35,89 @@ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TErro
35
35
  } & {
36
36
  enabled?: MaybeRefOrGetter<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['enabled']>;
37
37
  queryKey?: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['queryKey']>;
38
- shallow?: MaybeRef<boolean>;
38
+ shallow?: boolean;
39
39
  };
40
- interface QueryOptionsBase<TOutput, TError extends Error> {
40
+ interface QueryOptionsBase<TOutput, TError> {
41
41
  queryKey: ComputedRef<QueryKey>;
42
42
  queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
43
- retry?(failureCount: number, error: TError): boolean;
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> {
44
53
  }
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 ? {
54
+ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = (Record<never, never> extends TClientContext ? {
48
55
  context?: MaybeRefDeep<TClientContext>;
49
56
  } : {
50
57
  context: MaybeRefDeep<TClientContext>;
51
- }) & SetOptional<UseInfiniteQueryOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey'>;
52
- interface InfiniteOptionsBase<TOutput, TError extends Error, TPageParam> {
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> {
53
67
  queryKey: ComputedRef<QueryKey>;
54
68
  queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
55
- retry?(failureCount: number, error: TError): boolean;
69
+ throwOnError?(error: TError): boolean;
70
+ retryDelay?: (count: number, error: TError) => number;
71
+ enabled: ComputedRef<boolean | undefined>;
56
72
  }
57
- type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TMutationContext> = (Record<never, never> extends TClientContext ? {
73
+ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
58
74
  context?: TClientContext;
59
75
  } : {
60
76
  context: TClientContext;
61
77
  }) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
62
- type MutationOptions<TInput, TOutput, TError extends Error, TMutationContext> = {
78
+ type MutationOptions<TInput, TOutput, TError, TMutationContext> = {
63
79
  [P in keyof MutationObserverOptions<TOutput, TError, TInput, TMutationContext>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput, TMutationContext>[P]>;
64
80
  } & {
65
81
  shallow?: MaybeRef<boolean>;
66
82
  };
67
83
 
68
- interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
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
+ */
69
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
+ */
70
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
+ */
71
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
+ */
72
115
  mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
73
116
  }
74
117
  interface CreateProcedureUtilsOptions {
75
118
  path: string[];
76
119
  }
77
- declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
120
+ declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
78
121
 
79
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> : {
80
123
  [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
@@ -82,6 +125,12 @@ type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientCo
82
125
  interface CreateRouterUtilsOptions {
83
126
  path?: string[];
84
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
+ */
85
134
  declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
86
135
 
87
136
  type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunction ? T : T extends object ? {
@@ -89,4 +138,5 @@ type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunctio
89
138
  } : T;
90
139
  declare function unrefDeep<T>(value: T): UnrefDeep<T>;
91
140
 
92
- export { type BuildKeyOptions, type CreateProcedureUtilsOptions, type CreateRouterUtilsOptions, type GeneralUtils, type InfiniteOptionsBase, type InfiniteOptionsIn, type KeyType, type MaybeRefDeep, type MutationOptions, type MutationOptionsIn, type ProcedureUtils, type QueryOptionsBase, type QueryOptionsIn, type RouterUtils, type UnrefDeep, buildKey, createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
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 CHANGED
@@ -1,17 +1,17 @@
1
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';
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';
4
6
  import { MaybeRef, MaybeRefOrGetter, ComputedRef, Ref } from 'vue';
5
7
 
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
8
  interface GeneralUtils<TInput> {
14
- key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
9
+ /**
10
+ * Generate a query/mutation key for checking status, invalidate, set, get, etc.
11
+ *
12
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
13
+ */
14
+ key<UType extends OperationType>(options?: OperationKeyOptions<UType, TInput>): QueryKey;
15
15
  }
16
16
  declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
17
17
 
@@ -22,10 +22,10 @@ declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput
22
22
  type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
23
23
  [Property in keyof T]: MaybeRefDeep<T[Property]>;
24
24
  } : T>;
25
- type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData> = (undefined extends TInput ? {
26
- input?: MaybeRefDeep<TInput>;
25
+ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
26
+ input?: MaybeRefDeep<TInput | SkipToken>;
27
27
  } : {
28
- input: MaybeRefDeep<TInput>;
28
+ input: MaybeRefDeep<TInput | SkipToken>;
29
29
  }) & (Record<never, never> extends TClientContext ? {
30
30
  context?: MaybeRefDeep<TClientContext>;
31
31
  } : {
@@ -35,46 +35,89 @@ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TErro
35
35
  } & {
36
36
  enabled?: MaybeRefOrGetter<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['enabled']>;
37
37
  queryKey?: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['queryKey']>;
38
- shallow?: MaybeRef<boolean>;
38
+ shallow?: boolean;
39
39
  };
40
- interface QueryOptionsBase<TOutput, TError extends Error> {
40
+ interface QueryOptionsBase<TOutput, TError> {
41
41
  queryKey: ComputedRef<QueryKey>;
42
42
  queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
43
- retry?(failureCount: number, error: TError): boolean;
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> {
44
53
  }
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 ? {
54
+ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = (Record<never, never> extends TClientContext ? {
48
55
  context?: MaybeRefDeep<TClientContext>;
49
56
  } : {
50
57
  context: MaybeRefDeep<TClientContext>;
51
- }) & SetOptional<UseInfiniteQueryOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey'>;
52
- interface InfiniteOptionsBase<TOutput, TError extends Error, TPageParam> {
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> {
53
67
  queryKey: ComputedRef<QueryKey>;
54
68
  queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
55
- retry?(failureCount: number, error: TError): boolean;
69
+ throwOnError?(error: TError): boolean;
70
+ retryDelay?: (count: number, error: TError) => number;
71
+ enabled: ComputedRef<boolean | undefined>;
56
72
  }
57
- type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TMutationContext> = (Record<never, never> extends TClientContext ? {
73
+ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
58
74
  context?: TClientContext;
59
75
  } : {
60
76
  context: TClientContext;
61
77
  }) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
62
- type MutationOptions<TInput, TOutput, TError extends Error, TMutationContext> = {
78
+ type MutationOptions<TInput, TOutput, TError, TMutationContext> = {
63
79
  [P in keyof MutationObserverOptions<TOutput, TError, TInput, TMutationContext>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput, TMutationContext>[P]>;
64
80
  } & {
65
81
  shallow?: MaybeRef<boolean>;
66
82
  };
67
83
 
68
- interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
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
+ */
69
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
+ */
70
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
+ */
71
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
+ */
72
115
  mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
73
116
  }
74
117
  interface CreateProcedureUtilsOptions {
75
118
  path: string[];
76
119
  }
77
- declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
120
+ declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
78
121
 
79
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> : {
80
123
  [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
@@ -82,6 +125,12 @@ type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientCo
82
125
  interface CreateRouterUtilsOptions {
83
126
  path?: string[];
84
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
+ */
85
134
  declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
86
135
 
87
136
  type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunction ? T : T extends object ? {
@@ -89,4 +138,5 @@ type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunctio
89
138
  } : T;
90
139
  declare function unrefDeep<T>(value: T): UnrefDeep<T>;
91
140
 
92
- export { type BuildKeyOptions, type CreateProcedureUtilsOptions, type CreateRouterUtilsOptions, type GeneralUtils, type InfiniteOptionsBase, type InfiniteOptionsIn, type KeyType, type MaybeRefDeep, type MutationOptions, type MutationOptionsIn, type ProcedureUtils, type QueryOptionsBase, type QueryOptionsIn, type RouterUtils, type UnrefDeep, buildKey, createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
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 CHANGED
@@ -1,19 +1,13 @@
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';
1
5
  import { isRef, computed } from 'vue';
2
- import { isObject } from '@orpc/shared';
3
-
4
- function buildKey(path, options) {
5
- const withInput = options?.input !== void 0 ? { input: options?.input } : {};
6
- const withType = options?.type !== void 0 ? { type: options?.type } : {};
7
- return [path, {
8
- ...withInput,
9
- ...withType
10
- }];
11
- }
12
6
 
13
7
  function createGeneralUtils(path) {
14
8
  return {
15
9
  key(options) {
16
- return buildKey(path, options);
10
+ return generateOperationKey(path, options);
17
11
  }
18
12
  };
19
13
  }
@@ -39,25 +33,62 @@ function createProcedureUtils(client, options) {
39
33
  call: client,
40
34
  queryOptions(...[optionsIn = {}]) {
41
35
  return {
42
- queryKey: computed(() => buildKey(options.path, { type: "query", input: unrefDeep(optionsIn.input) })),
43
- queryFn: ({ signal }) => client(unrefDeep(optionsIn.input), { signal, context: unrefDeep(optionsIn.context) }),
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
+ }),
44
66
  ...optionsIn
45
67
  };
46
68
  },
47
69
  infiniteOptions(optionsIn) {
48
70
  return {
49
71
  queryKey: computed(() => {
50
- return buildKey(options.path, { type: "infinite", input: unrefDeep(optionsIn.input(unrefDeep(optionsIn.initialPageParam))) });
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
+ });
51
77
  }),
52
78
  queryFn: ({ pageParam, signal }) => {
53
- return client(unrefDeep(optionsIn.input(pageParam)), { signal, context: unrefDeep(optionsIn.context) });
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) });
54
84
  },
85
+ enabled: computed(() => unrefDeep(optionsIn.input) === skipToken ? false : void 0),
55
86
  ...optionsIn
56
87
  };
57
88
  },
58
89
  mutationOptions(...[optionsIn = {}]) {
59
90
  return {
60
- mutationKey: buildKey(options.path, { type: "mutation" }),
91
+ mutationKey: generateOperationKey(options.path, { type: "mutation" }),
61
92
  mutationFn: (input) => client(input, { context: unrefDeep(optionsIn.context) }),
62
93
  ...optionsIn
63
94
  };
@@ -92,4 +123,4 @@ function createRouterUtils(client, options = {}) {
92
123
  return recursive;
93
124
  }
94
125
 
95
- export { buildKey, createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
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.ff68fdb",
4
+ "version": "0.0.0-next.ff7ad2e",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -27,12 +27,16 @@
27
27
  "dist"
28
28
  ],
29
29
  "peerDependencies": {
30
- "@tanstack/vue-query": ">=5.50.0",
30
+ "@tanstack/vue-query": ">=5.80.2",
31
31
  "vue": ">=3.3.0",
32
- "@orpc/client": "0.0.0-next.ff68fdb"
32
+ "@orpc/client": "0.0.0-next.ff7ad2e"
33
33
  },
34
34
  "dependencies": {
35
- "@orpc/shared": "0.0.0-next.ff68fdb"
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"
36
40
  },
37
41
  "scripts": {
38
42
  "build": "unbuild",