@orpc/vue-query 0.46.0 → 0.48.0

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
@@ -32,7 +32,7 @@
32
32
  - **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
33
33
  - **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
34
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.
35
+ - **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
36
36
  - **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
37
37
  - **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
38
38
  - **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
@@ -55,6 +55,8 @@ You can find the full documentation [here](https://orpc.unnoq.com).
55
55
  - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
56
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
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).
58
60
  - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
59
61
  - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
60
62
  - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ClientContext, Client, NestedClient } from '@orpc/client';
2
2
  import { QueryKey, QueryObserverOptions, QueryFunctionContext, UseInfiniteQueryOptions, MutationObserverOptions, InfiniteData } from '@tanstack/vue-query';
3
3
  import { PartialDeep, AnyFunction, SetOptional, MaybeOptionalOptions } from '@orpc/shared';
4
- import { MaybeRef, MaybeRefOrGetter, ComputedRef } from 'vue';
4
+ import { MaybeRef, MaybeRefOrGetter, ComputedRef, Ref } from 'vue';
5
5
 
6
6
  type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
7
7
  interface BuildKeyOptions<TType extends KeyType, TInput> {
@@ -58,34 +58,35 @@ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
58
58
  context?: TClientContext;
59
59
  } : {
60
60
  context: TClientContext;
61
- }) & {
61
+ }) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
62
+ type MutationOptions<TInput, TOutput, TError extends Error, TMutationContext> = {
62
63
  [P in keyof MutationObserverOptions<TOutput, TError, TInput, TMutationContext>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput, TMutationContext>[P]>;
63
64
  } & {
64
65
  shallow?: MaybeRef<boolean>;
65
66
  };
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
67
 
72
68
  interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
73
69
  call: Client<TClientContext, TInput, TOutput, TError>;
74
70
  queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
75
71
  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>>;
72
+ mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
73
+ }
74
+ interface CreateProcedureUtilsOptions {
75
+ path: string[];
77
76
  }
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>;
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>;
79
78
 
80
79
  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
80
  [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
82
81
  } & 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>;
82
+ interface CreateRouterUtilsOptions {
83
+ path?: string[];
84
+ }
85
+ declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
88
86
 
89
- declare const createORPCVueQueryUtils: typeof createRouterUtils;
87
+ type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunction ? T : T extends object ? {
88
+ [K in keyof T]: UnrefDeep<T[K]>;
89
+ } : T;
90
+ declare function unrefDeep<T>(value: T): UnrefDeep<T>;
90
91
 
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 };
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 };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ClientContext, Client, NestedClient } from '@orpc/client';
2
2
  import { QueryKey, QueryObserverOptions, QueryFunctionContext, UseInfiniteQueryOptions, MutationObserverOptions, InfiniteData } from '@tanstack/vue-query';
3
3
  import { PartialDeep, AnyFunction, SetOptional, MaybeOptionalOptions } from '@orpc/shared';
4
- import { MaybeRef, MaybeRefOrGetter, ComputedRef } from 'vue';
4
+ import { MaybeRef, MaybeRefOrGetter, ComputedRef, Ref } from 'vue';
5
5
 
6
6
  type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
7
7
  interface BuildKeyOptions<TType extends KeyType, TInput> {
@@ -58,34 +58,35 @@ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
58
58
  context?: TClientContext;
59
59
  } : {
60
60
  context: TClientContext;
61
- }) & {
61
+ }) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
62
+ type MutationOptions<TInput, TOutput, TError extends Error, TMutationContext> = {
62
63
  [P in keyof MutationObserverOptions<TOutput, TError, TInput, TMutationContext>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput, TMutationContext>[P]>;
63
64
  } & {
64
65
  shallow?: MaybeRef<boolean>;
65
66
  };
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
67
 
72
68
  interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
73
69
  call: Client<TClientContext, TInput, TOutput, TError>;
74
70
  queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
75
71
  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>>;
72
+ mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
73
+ }
74
+ interface CreateProcedureUtilsOptions {
75
+ path: string[];
77
76
  }
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>;
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>;
79
78
 
80
79
  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
80
  [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
82
81
  } & 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>;
82
+ interface CreateRouterUtilsOptions {
83
+ path?: string[];
84
+ }
85
+ declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
88
86
 
89
- declare const createORPCVueQueryUtils: typeof createRouterUtils;
87
+ type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunction ? T : T extends object ? {
88
+ [K in keyof T]: UnrefDeep<T[K]>;
89
+ } : T;
90
+ declare function unrefDeep<T>(value: T): UnrefDeep<T>;
90
91
 
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 };
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 };
package/dist/index.mjs CHANGED
@@ -34,40 +34,41 @@ function unrefDeep(value) {
34
34
  return value;
35
35
  }
36
36
 
37
- function createProcedureUtils(client, path) {
37
+ function createProcedureUtils(client, options) {
38
38
  return {
39
39
  call: client,
40
- queryOptions(...[{ input, context, ...rest } = {}]) {
40
+ queryOptions(...[optionsIn = {}]) {
41
41
  return {
42
- queryKey: computed(() => buildKey(path, { type: "query", input: unrefDeep(input) })),
43
- queryFn: ({ signal }) => client(unrefDeep(input), { signal, context: unrefDeep(context) }),
44
- ...rest
42
+ queryKey: computed(() => buildKey(options.path, { type: "query", input: unrefDeep(optionsIn.input) })),
43
+ queryFn: ({ signal }) => client(unrefDeep(optionsIn.input), { signal, context: unrefDeep(optionsIn.context) }),
44
+ ...optionsIn
45
45
  };
46
46
  },
47
- infiniteOptions({ input, context, ...rest }) {
47
+ infiniteOptions(optionsIn) {
48
48
  return {
49
49
  queryKey: computed(() => {
50
- return buildKey(path, { type: "infinite", input: unrefDeep(input(unrefDeep(rest.initialPageParam))) });
50
+ return buildKey(options.path, { type: "infinite", input: unrefDeep(optionsIn.input(unrefDeep(optionsIn.initialPageParam))) });
51
51
  }),
52
52
  queryFn: ({ pageParam, signal }) => {
53
- return client(unrefDeep(input(pageParam)), { signal, context: unrefDeep(context) });
53
+ return client(unrefDeep(optionsIn.input(pageParam)), { signal, context: unrefDeep(optionsIn.context) });
54
54
  },
55
- ...rest
55
+ ...optionsIn
56
56
  };
57
57
  },
58
- mutationOptions(...[{ context, ...rest } = {}]) {
58
+ mutationOptions(...[optionsIn = {}]) {
59
59
  return {
60
- mutationKey: buildKey(path, { type: "mutation" }),
61
- mutationFn: (input) => client(input, { context: unrefDeep(context) }),
62
- ...rest
60
+ mutationKey: buildKey(options.path, { type: "mutation" }),
61
+ mutationFn: (input) => client(input, { context: unrefDeep(optionsIn.context) }),
62
+ ...optionsIn
63
63
  };
64
64
  }
65
65
  };
66
66
  }
67
67
 
68
- function createRouterUtils(client, path = []) {
68
+ function createRouterUtils(client, options = {}) {
69
+ const path = options.path ?? [];
69
70
  const generalUtils = createGeneralUtils(path);
70
- const procedureUtils = createProcedureUtils(client, path);
71
+ const procedureUtils = createProcedureUtils(client, { path });
71
72
  const recursive = new Proxy({
72
73
  ...generalUtils,
73
74
  ...procedureUtils
@@ -77,7 +78,7 @@ function createRouterUtils(client, path = []) {
77
78
  if (typeof prop !== "string") {
78
79
  return value;
79
80
  }
80
- const nextUtils = createRouterUtils(client[prop], [...path, prop]);
81
+ const nextUtils = createRouterUtils(client[prop], { ...options, path: [...path, prop] });
81
82
  if (typeof value !== "function") {
82
83
  return nextUtils;
83
84
  }
@@ -91,6 +92,4 @@ function createRouterUtils(client, path = []) {
91
92
  return recursive;
92
93
  }
93
94
 
94
- const createORPCVueQueryUtils = createRouterUtils;
95
-
96
- export { buildKey, createGeneralUtils, createORPCVueQueryUtils, createProcedureUtils, createRouterUtils };
95
+ export { buildKey, createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/vue-query",
3
3
  "type": "module",
4
- "version": "0.46.0",
4
+ "version": "0.48.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -29,10 +29,10 @@
29
29
  "peerDependencies": {
30
30
  "@tanstack/vue-query": ">=5.50.0",
31
31
  "vue": ">=3.3.0",
32
- "@orpc/client": "0.46.0"
32
+ "@orpc/client": "0.48.0"
33
33
  },
34
34
  "dependencies": {
35
- "@orpc/shared": "0.46.0"
35
+ "@orpc/shared": "0.48.0"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "unbuild",