@orpc/react-query 0.0.0-next.ee0aeaf → 0.0.0-next.f56d2b3

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
@@ -28,22 +28,23 @@ function createProcedureUtils(client, path) {
28
28
  const input = options?.input;
29
29
  return {
30
30
  queryKey: buildKey(path, { type: "query", input }),
31
- queryFn: ({ signal }) => client(input, { signal }),
31
+ queryFn: ({ signal }) => client(input, { signal, context: options?.context }),
32
32
  ...options
33
33
  };
34
34
  },
35
35
  infiniteOptions(options) {
36
36
  const input = options.input;
37
37
  return {
38
+ initialPageParam: void 0,
38
39
  queryKey: buildKey(path, { type: "infinite", input }),
39
- queryFn: ({ pageParam, signal }) => client({ ...input, cursor: pageParam }, { signal }),
40
+ queryFn: ({ pageParam, signal }) => client({ ...input, cursor: pageParam }, { signal, context: options.context }),
40
41
  ...options
41
42
  };
42
43
  },
43
- mutationOptions(options) {
44
+ mutationOptions(...[options]) {
44
45
  return {
45
46
  mutationKey: buildKey(path, { type: "mutation" }),
46
- mutationFn: (input) => client(input),
47
+ mutationFn: (input) => client(input, { context: options?.context }),
47
48
  ...options
48
49
  };
49
50
  }
@@ -1,17 +1,45 @@
1
1
  import type { SetOptional } from '@orpc/shared';
2
- import type { DefaultError, QueryKey, UndefinedInitialDataInfiniteOptions, UndefinedInitialDataOptions, UseMutationOptions } from '@tanstack/react-query';
2
+ import type { QueryFunctionContext, QueryKey, UndefinedInitialDataInfiniteOptions, UndefinedInitialDataOptions, UseMutationOptions } from '@tanstack/react-query';
3
3
  export type InferCursor<T> = T extends {
4
4
  cursor?: any;
5
5
  } ? T['cursor'] : never;
6
- export type QueryOptions<TInput, TOutput, TSelectData> = (undefined extends TInput ? {
6
+ export interface QueryOptionsBase<TOutput, TError extends Error> {
7
+ queryKey: QueryKey;
8
+ queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
9
+ retry?(failureCount: number, error: TError): boolean;
10
+ }
11
+ export type QueryOptionsExtra<TClientContext, TInput, TOutput, TError extends Error, TSelectData> = (undefined extends TInput ? {
7
12
  input?: TInput;
8
13
  } : {
9
14
  input: TInput;
10
- }) & (SetOptional<UndefinedInitialDataOptions<TOutput, DefaultError, TSelectData, QueryKey>, 'queryKey'>);
11
- export type InfiniteOptions<TInput, TOutput, TSelectData> = (undefined extends TInput ? {
15
+ }) & (undefined extends TClientContext ? {
16
+ context?: TClientContext;
17
+ } : {
18
+ context: TClientContext;
19
+ }) & (SetOptional<UndefinedInitialDataOptions<TOutput, TError, TSelectData, QueryKey>, 'queryKey'>);
20
+ export interface InfiniteOptionsBase<TInput, TOutput, TError extends Error> {
21
+ queryKey: QueryKey;
22
+ queryFn(ctx: QueryFunctionContext<QueryKey, InferCursor<TInput>>): Promise<TOutput>;
23
+ retry?(failureCount: number, error: TError): boolean;
24
+ initialPageParam: undefined;
25
+ }
26
+ export type InfiniteOptionsExtra<TClientContext, TInput, TOutput, TError extends Error, TSelectData> = (undefined extends TInput ? {
12
27
  input?: Omit<TInput, 'cursor'>;
13
28
  } : {
14
29
  input: Omit<TInput, 'cursor'>;
15
- }) & (SetOptional<UndefinedInitialDataInfiniteOptions<TOutput, DefaultError, TSelectData, QueryKey, InferCursor<TInput>>, 'queryKey' | (undefined extends InferCursor<TInput> ? 'initialPageParam' : never)>);
16
- export type MutationOptions<TInput, TOutput> = UseMutationOptions<TOutput, DefaultError, TInput>;
30
+ }) & (undefined extends TClientContext ? {
31
+ context?: TClientContext;
32
+ } : {
33
+ context: TClientContext;
34
+ }) & (SetOptional<UndefinedInitialDataInfiniteOptions<TOutput, TError, TSelectData, QueryKey, InferCursor<TInput>>, 'queryKey' | (undefined extends InferCursor<TInput> ? 'initialPageParam' : never)>);
35
+ export interface MutationOptionsBase<TInput, TOutput, TError extends Error> {
36
+ mutationKey: QueryKey;
37
+ mutationFn(input: TInput): Promise<TOutput>;
38
+ retry?(failureCount: number, error: TError): boolean;
39
+ }
40
+ export type MutationOptionsExtra<TClientContext, TInput, TOutput, TError extends Error> = (undefined extends TClientContext ? {
41
+ context?: TClientContext;
42
+ } : {
43
+ context: TClientContext;
44
+ }) & UseMutationOptions<TOutput, TError, TInput>;
17
45
  //# sourceMappingURL=types.d.ts.map
@@ -4,7 +4,7 @@ import type { BuildKeyOptions, KeyType } from './key';
4
4
  * Utils at any level (procedure or router)
5
5
  */
6
6
  export interface GeneralUtils<TInput> {
7
- key: <UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>) => QueryKey;
7
+ key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
8
8
  }
9
9
  export declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
10
10
  //# sourceMappingURL=utils-general.d.ts.map
@@ -1,30 +1,13 @@
1
- import type { Caller } from '@orpc/server';
1
+ import type { Client } from '@orpc/contract';
2
2
  import type { IsEqual } from '@orpc/shared';
3
- import type { QueryKey } from '@tanstack/react-query';
4
- import type { InfiniteOptions, MutationOptions, QueryOptions } from './types';
3
+ import type { InfiniteOptionsBase, InfiniteOptionsExtra, MutationOptionsBase, MutationOptionsExtra, QueryOptionsBase, QueryOptionsExtra } from './types';
5
4
  /**
6
5
  * Utils at procedure level
7
6
  */
8
- export interface ProcedureUtils<TInput, TOutput> {
9
- queryOptions: <U extends QueryOptions<TInput, TOutput, any>>(...opts: [options: U] | (undefined extends TInput ? [] : never)) => IsEqual<U, QueryOptions<TInput, TOutput, any>> extends true ? {
10
- queryKey: QueryKey;
11
- queryFn: () => Promise<TOutput>;
12
- } : Omit<{
13
- queryKey: QueryKey;
14
- queryFn: () => Promise<TOutput>;
15
- }, keyof U> & U;
16
- infiniteOptions: <U extends InfiniteOptions<TInput, TOutput, any>>(options: U) => Omit<{
17
- queryKey: QueryKey;
18
- queryFn: () => Promise<TOutput>;
19
- initialPageParam: undefined;
20
- }, keyof U> & U;
21
- mutationOptions: <U extends MutationOptions<TInput, TOutput>>(options?: U) => IsEqual<U, MutationOptions<TInput, TOutput>> extends true ? {
22
- mutationKey: QueryKey;
23
- mutationFn: (input: TInput) => Promise<TOutput>;
24
- } : Omit<{
25
- mutationKey: QueryKey;
26
- mutationFn: (input: TInput) => Promise<TOutput>;
27
- }, keyof U> & U;
7
+ export interface ProcedureUtils<TClientContext, TInput, TOutput, TError extends Error> {
8
+ queryOptions<U extends QueryOptionsExtra<TClientContext, TInput, TOutput, TError, any>>(...opts: [options: U] | (undefined extends TInput & TClientContext ? [] : never)): IsEqual<U, QueryOptionsExtra<TClientContext, TInput, TOutput, TError, any>> extends true ? QueryOptionsBase<TOutput, TError> : Omit<QueryOptionsBase<TOutput, TError>, keyof U> & U;
9
+ infiniteOptions<U extends InfiniteOptionsExtra<TClientContext, TInput, TOutput, TError, any>>(options: U): Omit<InfiniteOptionsBase<TInput, TOutput, TError>, keyof U> & U;
10
+ mutationOptions<U extends MutationOptionsExtra<TClientContext, TInput, TOutput, TError>>(...opt: [options: U] | (undefined extends TClientContext ? [] : never)): IsEqual<U, MutationOptionsExtra<TClientContext, TInput, TOutput, TError>> extends true ? MutationOptionsBase<TInput, TOutput, TError> : Omit<MutationOptionsBase<TInput, TOutput, TError>, keyof U> & U;
28
11
  }
29
- export declare function createProcedureUtils<TInput, TOutput>(client: Caller<TInput, TOutput>, path: string[]): ProcedureUtils<TInput, TOutput>;
12
+ export declare function createProcedureUtils<TClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, path: string[]): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
30
13
  //# 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 { Client, NestedClient } from '@orpc/contract';
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 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;
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 NestedClient<any>>(client: T, path?: string[]): RouterUtils<T>;
14
12
  //# sourceMappingURL=utils-router.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/react-query",
3
3
  "type": "module",
4
- "version": "0.0.0-next.ee0aeaf",
4
+ "version": "0.0.0-next.f56d2b3",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -34,12 +34,11 @@
34
34
  "peerDependencies": {
35
35
  "@tanstack/react-query": ">=5.59.0",
36
36
  "react": ">=18.3.0",
37
- "@orpc/client": "0.0.0-next.ee0aeaf",
38
- "@orpc/contract": "0.0.0-next.ee0aeaf",
39
- "@orpc/server": "0.0.0-next.ee0aeaf"
37
+ "@orpc/client": "0.0.0-next.f56d2b3",
38
+ "@orpc/contract": "0.0.0-next.f56d2b3"
40
39
  },
41
40
  "dependencies": {
42
- "@orpc/shared": "0.0.0-next.ee0aeaf"
41
+ "@orpc/shared": "0.0.0-next.f56d2b3"
43
42
  },
44
43
  "devDependencies": {
45
44
  "zod": "^3.24.1"