@orpc/vue-query 0.18.0 → 0.20.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/dist/index.js CHANGED
@@ -47,7 +47,7 @@ function createProcedureUtils(client, path) {
47
47
  const input = options?.input;
48
48
  return {
49
49
  queryKey: computed(() => buildKey(path, { type: "query", input: deepUnref(input) })),
50
- queryFn: ({ signal }) => client(deepUnref(input), { signal }),
50
+ queryFn: ({ signal }) => client(deepUnref(input), { signal, context: deepUnref(options?.context) }),
51
51
  ...options
52
52
  };
53
53
  },
@@ -55,14 +55,14 @@ function createProcedureUtils(client, path) {
55
55
  const input = options.input;
56
56
  return {
57
57
  queryKey: computed(() => buildKey(path, { type: "infinite", input: deepUnref(input) })),
58
- queryFn: ({ pageParam, signal }) => client({ ...deepUnref(input), cursor: pageParam }, { signal }),
58
+ queryFn: ({ pageParam, signal }) => client({ ...deepUnref(input), cursor: pageParam }, { signal, context: deepUnref(options.context) }),
59
59
  ...options
60
60
  };
61
61
  },
62
- mutationOptions(options) {
62
+ mutationOptions(...[options]) {
63
63
  return {
64
64
  mutationKey: buildKey(path, { type: "mutation" }),
65
- mutationFn: (input) => client(input),
65
+ mutationFn: (input) => client(input, { context: deepUnref(options?.context) }),
66
66
  ...options
67
67
  };
68
68
  }
@@ -8,22 +8,34 @@ export type NonUndefinedGuard<T> = T extends undefined ? never : T;
8
8
  export type InferCursor<T> = T extends {
9
9
  cursor?: any;
10
10
  } ? T['cursor'] : never;
11
- export type QueryOptions<TInput, TOutput, TSelectData> = (undefined extends TInput ? {
11
+ export type QueryOptions<TInput, TOutput, TClientContext, TSelectData> = (undefined extends TInput ? {
12
12
  input?: MaybeDeepRef<TInput>;
13
13
  } : {
14
14
  input: MaybeDeepRef<TInput>;
15
+ }) & (undefined extends TClientContext ? {
16
+ context?: MaybeDeepRef<TClientContext>;
17
+ } : {
18
+ context: MaybeDeepRef<TClientContext>;
15
19
  }) & SetOptional<{
16
20
  [P in keyof QueryObserverOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey>]: P extends 'enabled' ? MaybeRefOrGetter<QueryObserverOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey>[P]> : MaybeDeepRef<QueryObserverOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey>[P]>;
17
21
  }, 'queryKey'> & {
18
22
  shallow?: MaybeRef<boolean>;
19
23
  initialData?: NonUndefinedGuard<TOutput> | (() => NonUndefinedGuard<TOutput>) | undefined;
20
24
  };
21
- export type InfiniteOptions<TInput, TOutput, TSelectData> = (undefined extends TInput ? {
25
+ export type InfiniteOptions<TInput, TOutput, TClientContext, TSelectData> = (undefined extends TInput ? {
22
26
  input?: MaybeDeepRef<Omit<TInput, 'cursor'>>;
23
27
  } : {
24
28
  input: MaybeDeepRef<Omit<TInput, 'cursor'>>;
29
+ }) & (undefined extends TClientContext ? {
30
+ context?: MaybeDeepRef<TClientContext>;
31
+ } : {
32
+ context: MaybeDeepRef<TClientContext>;
25
33
  }) & SetOptional<UseInfiniteQueryOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey, InferCursor<TInput>>, 'queryKey' | (undefined extends InferCursor<TInput> ? 'initialPageParam' : never)>;
26
- export type MutationOptions<TInput, TOutput> = {
34
+ export type MutationOptions<TInput, TOutput, TClientContext> = (undefined extends TClientContext ? {
35
+ context?: MaybeDeepRef<TClientContext>;
36
+ } : {
37
+ context: MaybeDeepRef<TClientContext>;
38
+ }) & {
27
39
  [P in keyof MutationObserverOptions<TOutput, DefaultError, TInput, unknown>]: MaybeDeepRef<MutationObserverOptions<TOutput, DefaultError, TInput, unknown>[P]>;
28
40
  } & {
29
41
  shallow?: MaybeRef<boolean>;
@@ -6,20 +6,20 @@ import type { InfiniteOptions, MutationOptions, QueryOptions } from './types';
6
6
  /**
7
7
  * Utils at procedure level
8
8
  */
9
- export interface ProcedureUtils<TInput, TOutput> {
10
- queryOptions: <U extends QueryOptions<TInput, TOutput, any>>(...options: [U] | (undefined extends TInput ? [] : never)) => IsEqual<U, QueryOptions<TInput, TOutput, any>> extends true ? {
9
+ export interface ProcedureUtils<TInput, TOutput, TClientContext> {
10
+ queryOptions: <U extends QueryOptions<TInput, TOutput, TClientContext, any>>(...opt: [options: U] | (undefined extends TInput & TClientContext ? [] : never)) => IsEqual<U, QueryOptions<TInput, TOutput, TClientContext, any>> extends true ? {
11
11
  queryKey: QueryKey;
12
12
  queryFn: () => Promise<TOutput>;
13
13
  } : Omit<{
14
14
  queryKey: ComputedRef<QueryKey>;
15
15
  queryFn: () => Promise<TOutput>;
16
16
  }, keyof U> & U;
17
- infiniteOptions: <U extends InfiniteOptions<TInput, TOutput, any>>(options: U) => Omit<{
17
+ infiniteOptions: <U extends InfiniteOptions<TInput, TOutput, TClientContext, any>>(options: U) => Omit<{
18
18
  queryKey: ComputedRef<QueryKey>;
19
19
  queryFn: () => Promise<TOutput>;
20
20
  initialPageParam: undefined;
21
21
  }, keyof U> & U;
22
- mutationOptions: <U extends MutationOptions<TInput, TOutput>>(options?: U) => IsEqual<U, MutationOptions<TInput, TOutput>> extends true ? {
22
+ mutationOptions: <U extends MutationOptions<TInput, TOutput, TClientContext>>(...opt: [options: U] | (undefined extends TClientContext ? [] : never)) => IsEqual<U, MutationOptions<TInput, TOutput, TClientContext>> extends true ? {
23
23
  mutationKey: QueryKey;
24
24
  mutationFn: (input: TInput) => Promise<TOutput>;
25
25
  } : Omit<{
@@ -27,5 +27,5 @@ export interface ProcedureUtils<TInput, TOutput> {
27
27
  mutationFn: (input: TInput) => Promise<TOutput>;
28
28
  }, keyof U> & U;
29
29
  }
30
- export declare function createProcedureUtils<TInput, TOutput>(client: ProcedureClient<TInput, TOutput>, path: string[]): ProcedureUtils<TInput, TOutput>;
30
+ export declare function createProcedureUtils<TInput, TOutput, TClientContext>(client: ProcedureClient<TInput, TOutput, TClientContext>, path: string[]): ProcedureUtils<TInput, TOutput, TClientContext>;
31
31
  //# sourceMappingURL=utils-procedure.d.ts.map
@@ -1,12 +1,12 @@
1
1
  import type { ProcedureClient, RouterClient } from '@orpc/server';
2
2
  import { type GeneralUtils } from './utils-general';
3
3
  import { type ProcedureUtils } from './utils-procedure';
4
- export type RouterUtils<T extends RouterClient<any>> = T extends ProcedureClient<infer TInput, infer TOutput> ? ProcedureUtils<TInput, TOutput> & GeneralUtils<TInput> : {
5
- [K in keyof T]: T[K] extends RouterClient<any> ? RouterUtils<T[K]> : never;
4
+ export type RouterUtils<T extends RouterClient<any, any>> = T extends ProcedureClient<infer TInput, infer TOutput, infer TClientContext> ? ProcedureUtils<TInput, TOutput, TClientContext> & GeneralUtils<TInput> : {
5
+ [K in keyof T]: T[K] extends RouterClient<any, any> ? RouterUtils<T[K]> : never;
6
6
  } & GeneralUtils<unknown>;
7
7
  /**
8
8
  * @param client - The client create form `@orpc/client`
9
9
  * @param path - The base path for query key
10
10
  */
11
- export declare function createRouterUtils<T extends RouterClient<any>>(client: T, path?: string[]): RouterUtils<T>;
11
+ export declare function createRouterUtils<T extends RouterClient<any, any>>(client: T, path?: string[]): RouterUtils<T>;
12
12
  //# sourceMappingURL=utils-router.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/vue-query",
3
3
  "type": "module",
4
- "version": "0.18.0",
4
+ "version": "0.20.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -34,9 +34,9 @@
34
34
  "peerDependencies": {
35
35
  "@tanstack/vue-query": ">=5.50.0",
36
36
  "vue": ">=3.3.0",
37
- "@orpc/contract": "0.18.0",
38
- "@orpc/server": "0.18.0",
39
- "@orpc/client": "0.18.0"
37
+ "@orpc/client": "0.20.0",
38
+ "@orpc/contract": "0.20.0",
39
+ "@orpc/server": "0.20.0"
40
40
  },
41
41
  "scripts": {
42
42
  "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",