@orpc/vue-query 0.0.0-next.5e77e65 → 0.0.0-next.73eb96a

Sign up to get free protection for your applications and to get access to all the features.
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,16 @@ 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 }) => {
59
+ return client({ ...deepUnref(input), cursor: pageParam }, { signal, context: deepUnref(options.context) });
60
+ },
59
61
  ...options
60
62
  };
61
63
  },
62
- mutationOptions(options) {
64
+ mutationOptions(...[options]) {
63
65
  return {
64
66
  mutationKey: buildKey(path, { type: "mutation" }),
65
- mutationFn: (input) => client(input),
67
+ mutationFn: (input) => client(input, { context: deepUnref(options?.context) }),
66
68
  ...options
67
69
  };
68
70
  }
@@ -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
- [P in keyof QueryObserverOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey>]: P extends 'enabled' ? MaybeRefOrGetter<MaybeDeepRef<QueryObserverOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey>[P]>> : MaybeDeepRef<QueryObserverOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey>[P]>;
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>;
@@ -1,25 +1,25 @@
1
- import type { Caller } from '@orpc/server';
1
+ import type { ProcedureClient } from '@orpc/server';
2
2
  import type { IsEqual } from '@orpc/shared';
3
- import type { QueryKey } from '@tanstack/vue-query';
3
+ import type { QueryFunctionContext, QueryKey } from '@tanstack/vue-query';
4
4
  import type { ComputedRef } from 'vue';
5
- import type { InfiniteOptions, MutationOptions, QueryOptions } from './types';
5
+ import type { InferCursor, 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 ? {
11
- queryKey: QueryKey;
12
- queryFn: () => Promise<TOutput>;
9
+ export interface ProcedureUtils<TInput, TOutput, TClientContext> {
10
+ queryOptions: <U extends QueryOptions<TInput, TOutput, TClientContext, any>>(...opt: [options: U] | (undefined extends TInput & TClientContext ? [] : never)) => IsEqual<U, QueryOptions<TInput, TOutput, TClientContext, any>> extends true ? {
11
+ queryKey: ComputedRef<QueryKey>;
12
+ queryFn: (ctx: QueryFunctionContext) => Promise<TOutput>;
13
13
  } : Omit<{
14
14
  queryKey: ComputedRef<QueryKey>;
15
- queryFn: () => Promise<TOutput>;
15
+ queryFn: (ctx: QueryFunctionContext) => 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
- queryFn: () => Promise<TOutput>;
19
+ queryFn: (ctx: QueryFunctionContext<QueryKey, InferCursor<TInput>>) => 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: Caller<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,14 +1,12 @@
1
- import type { RouterClient } from '@orpc/client';
2
- import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract';
3
- import type { Lazy, Procedure, Router } from '@orpc/server';
1
+ import type { ProcedureClient, RouterClient } from '@orpc/server';
4
2
  import { type GeneralUtils } from './utils-general';
5
3
  import { type ProcedureUtils } from './utils-procedure';
6
- export type RouterUtils<T extends Router<any> | ContractRouter> = {
7
- [K in keyof T]: T[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> | Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> | Lazy<Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput>> ? ProcedureUtils<SchemaInput<UInputSchema>, SchemaOutput<UOutputSchema, UFuncOutput>> & GeneralUtils<SchemaInput<UInputSchema>> : T[K] extends Router<any> | ContractRouter ? 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;
8
6
  } & GeneralUtils<unknown>;
9
7
  /**
10
8
  * @param client - The client create form `@orpc/client`
11
9
  * @param path - The base path for query key
12
10
  */
13
- export declare function createRouterUtils<T extends Router<any> | ContractRouter>(client: RouterClient<T>, path?: string[]): RouterUtils<T>;
11
+ export declare function createRouterUtils<T extends RouterClient<any, any>>(client: T, path?: string[]): RouterUtils<T>;
14
12
  //# sourceMappingURL=utils-router.d.ts.map
@@ -1,3 +1,7 @@
1
- import type { MaybeDeepRef } from './types';
2
- export declare function deepUnref<T>(value: MaybeDeepRef<T>): T;
1
+ import type { AnyFunction } from '@orpc/shared';
2
+ import type { Ref } from 'vue';
3
+ export type DeepUnref<T> = T extends Ref<infer U> ? DeepUnref<U> : T extends AnyFunction ? T : T extends object ? {
4
+ [K in keyof T]: DeepUnref<T[K]>;
5
+ } : T;
6
+ export declare function deepUnref<T>(value: T): DeepUnref<T>;
3
7
  //# sourceMappingURL=utils.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.0.0-next.5e77e65",
4
+ "version": "0.0.0-next.73eb96a",
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.0.0-next.5e77e65",
38
- "@orpc/client": "0.0.0-next.5e77e65",
39
- "@orpc/server": "0.0.0-next.5e77e65"
37
+ "@orpc/server": "0.0.0-next.73eb96a",
38
+ "@orpc/contract": "0.0.0-next.73eb96a",
39
+ "@orpc/client": "0.0.0-next.73eb96a"
40
40
  },
41
41
  "scripts": {
42
42
  "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",