@orpc/react-query 0.36.1 → 0.37.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
@@ -2,17 +2,13 @@
2
2
  function buildKey(path, options) {
3
3
  const withInput = options?.input !== void 0 ? { input: options?.input } : {};
4
4
  const withType = options?.type !== void 0 ? { type: options?.type } : {};
5
- return [
6
- "__ORPC__",
7
- path,
8
- {
9
- ...withInput,
10
- ...withType
11
- }
12
- ];
5
+ return [path, {
6
+ ...withInput,
7
+ ...withType
8
+ }];
13
9
  }
14
10
 
15
- // src/utils-general.ts
11
+ // src/general-utils.ts
16
12
  function createGeneralUtils(path) {
17
13
  return {
18
14
  key(options) {
@@ -21,37 +17,36 @@ function createGeneralUtils(path) {
21
17
  };
22
18
  }
23
19
 
24
- // src/utils-procedure.ts
20
+ // src/procedure-utils.ts
25
21
  function createProcedureUtils(client, path) {
26
22
  return {
27
- queryOptions(...[options]) {
28
- const input = options?.input;
23
+ queryOptions(...[{ input, context, ...rest } = {}]) {
29
24
  return {
30
25
  queryKey: buildKey(path, { type: "query", input }),
31
- queryFn: ({ signal }) => client(input, { signal, context: options?.context }),
32
- ...options
26
+ queryFn: ({ signal }) => client(input, { signal, context }),
27
+ ...rest
33
28
  };
34
29
  },
35
- infiniteOptions(options) {
36
- const input = options.input;
30
+ infiniteOptions({ input, context, ...rest }) {
37
31
  return {
38
- initialPageParam: void 0,
39
- queryKey: buildKey(path, { type: "infinite", input }),
40
- queryFn: ({ pageParam, signal }) => client({ ...input, cursor: pageParam }, { signal, context: options.context }),
41
- ...options
32
+ queryKey: buildKey(path, { type: "infinite", input: input(rest.initialPageParam) }),
33
+ queryFn: ({ pageParam, signal }) => {
34
+ return client(input(pageParam), { signal, context });
35
+ },
36
+ ...rest
42
37
  };
43
38
  },
44
- mutationOptions(...[options]) {
39
+ mutationOptions(...[{ context, ...rest } = {}]) {
45
40
  return {
46
41
  mutationKey: buildKey(path, { type: "mutation" }),
47
- mutationFn: (input) => client(input, { context: options?.context }),
48
- ...options
42
+ mutationFn: (input) => client(input, { context }),
43
+ ...rest
49
44
  };
50
45
  }
51
46
  };
52
47
  }
53
48
 
54
- // src/utils-router.ts
49
+ // src/router-utils.ts
55
50
  function createRouterUtils(client, path = []) {
56
51
  const generalUtils = createGeneralUtils(path);
57
52
  const procedureUtils = createProcedureUtils(client, path);
@@ -7,4 +7,4 @@ export interface GeneralUtils<TInput> {
7
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
- //# sourceMappingURL=utils-general.d.ts.map
10
+ //# sourceMappingURL=general-utils.d.ts.map
@@ -1,8 +1,8 @@
1
- import { createRouterUtils } from './utils-router';
1
+ import { createRouterUtils } from './router-utils';
2
+ export * from './general-utils';
2
3
  export * from './key';
4
+ export * from './procedure-utils';
5
+ export * from './router-utils';
3
6
  export * from './types';
4
- export * from './utils-general';
5
- export * from './utils-procedure';
6
- export * from './utils-router';
7
7
  export declare const createORPCReactQueryUtils: typeof createRouterUtils;
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
1
+ import type { Client } from '@orpc/contract';
2
+ import type { MaybeOptionalOptions } from '@orpc/shared';
3
+ import type { InfiniteData } from '@tanstack/react-query';
4
+ import type { InfiniteOptionsBase, InfiniteOptionsIn, MutationOptionsBase, MutationOptionsIn, QueryOptionsBase, QueryOptionsIn } from './types';
5
+ export interface ProcedureUtils<TClientContext, TInput, TOutput, TError extends Error> {
6
+ queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & QueryOptionsBase<TOutput, TError>>;
7
+ infiniteOptions<U, UPageParam, USelectData = InfiniteData<TOutput>>(options: U & InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UPageParam>): NoInfer<U & InfiniteOptionsBase<TOutput, TError, UPageParam>>;
8
+ mutationOptions<U>(...rest: MaybeOptionalOptions<U & MutationOptionsIn<TClientContext, TInput, TOutput, TError>>): NoInfer<U & MutationOptionsBase<TInput, TOutput, TError>>;
9
+ }
10
+ export declare function createProcedureUtils<TClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, path: string[]): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
11
+ //# sourceMappingURL=procedure-utils.d.ts.map
@@ -1,12 +1,12 @@
1
1
  import type { Client, NestedClient } from '@orpc/contract';
2
- import { type GeneralUtils } from './utils-general';
3
- import { type ProcedureUtils } from './utils-procedure';
2
+ import { type GeneralUtils } from './general-utils';
3
+ import { type ProcedureUtils } from './procedure-utils';
4
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
5
  [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
6
6
  } & GeneralUtils<unknown>;
7
7
  /**
8
- * @param client - The client create form `@orpc/client`
9
- * @param path - The base path for query key
8
+ * @param client - Any kind of oRPC clients: `createRouterClient`, `createORPCClient`, ...
9
+ * @param path - The base path for query key, when it it will be prefix to all keys
10
10
  */
11
11
  export declare function createRouterUtils<T extends NestedClient<any>>(client: T, path?: string[]): RouterUtils<T>;
12
- //# sourceMappingURL=utils-router.d.ts.map
12
+ //# sourceMappingURL=router-utils.d.ts.map
@@ -1,14 +1,6 @@
1
1
  import type { SetOptional } from '@orpc/shared';
2
- import type { QueryFunctionContext, QueryKey, UndefinedInitialDataInfiniteOptions, UndefinedInitialDataOptions, UseMutationOptions } from '@tanstack/react-query';
3
- export type InferCursor<T> = T extends {
4
- cursor?: any;
5
- } ? T['cursor'] : never;
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 ? {
2
+ import type { QueryFunctionContext, QueryKey, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from '@tanstack/react-query';
3
+ export type QueryOptionsIn<TClientContext, TInput, TOutput, TError extends Error, TSelectData> = (undefined extends TInput ? {
12
4
  input?: TInput;
13
5
  } : {
14
6
  input: TInput;
@@ -16,30 +8,32 @@ export type QueryOptionsExtra<TClientContext, TInput, TOutput, TError extends Er
16
8
  context?: TClientContext;
17
9
  } : {
18
10
  context: TClientContext;
19
- }) & (SetOptional<UndefinedInitialDataOptions<TOutput, TError, TSelectData, QueryKey>, 'queryKey'>);
20
- export interface InfiniteOptionsBase<TInput, TOutput, TError extends Error> {
11
+ }) & SetOptional<UseQueryOptions<TOutput, TError, TSelectData>, 'queryKey'>;
12
+ export interface QueryOptionsBase<TOutput, TError extends Error> {
21
13
  queryKey: QueryKey;
22
- queryFn(ctx: QueryFunctionContext<QueryKey, InferCursor<TInput>>): Promise<TOutput>;
14
+ queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
23
15
  retry?(failureCount: number, error: TError): boolean;
24
- initialPageParam: undefined;
25
16
  }
26
- export type InfiniteOptionsExtra<TClientContext, TInput, TOutput, TError extends Error, TSelectData> = (undefined extends TInput ? {
27
- input?: Omit<TInput, 'cursor'>;
28
- } : {
29
- input: Omit<TInput, 'cursor'>;
30
- }) & (undefined extends TClientContext ? {
17
+ export type InfiniteOptionsIn<TClientContext, TInput, TOutput, TError extends Error, TSelectData, TPageParam> = {
18
+ input: (pageParam: TPageParam) => TInput;
19
+ } & (undefined extends TClientContext ? {
31
20
  context?: TClientContext;
32
21
  } : {
33
22
  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>;
23
+ }) & SetOptional<UseInfiniteQueryOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey'>;
24
+ export interface InfiniteOptionsBase<TOutput, TError extends Error, TPageParam> {
25
+ queryKey: QueryKey;
26
+ queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
38
27
  retry?(failureCount: number, error: TError): boolean;
39
28
  }
40
- export type MutationOptionsExtra<TClientContext, TInput, TOutput, TError extends Error> = (undefined extends TClientContext ? {
29
+ export type MutationOptionsIn<TClientContext, TInput, TOutput, TError extends Error> = (undefined extends TClientContext ? {
41
30
  context?: TClientContext;
42
31
  } : {
43
32
  context: TClientContext;
44
33
  }) & UseMutationOptions<TOutput, TError, TInput>;
34
+ export interface MutationOptionsBase<TInput, TOutput, TError extends Error> {
35
+ mutationKey: QueryKey;
36
+ mutationFn(input: TInput): Promise<TOutput>;
37
+ retry?(failureCount: number, error: TError): boolean;
38
+ }
45
39
  //# sourceMappingURL=types.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.36.1",
4
+ "version": "0.37.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -34,11 +34,11 @@
34
34
  "peerDependencies": {
35
35
  "@tanstack/react-query": ">=5.59.0",
36
36
  "react": ">=18.3.0",
37
- "@orpc/client": "0.36.1",
38
- "@orpc/contract": "0.36.1"
37
+ "@orpc/client": "0.37.0",
38
+ "@orpc/contract": "0.37.0"
39
39
  },
40
40
  "dependencies": {
41
- "@orpc/shared": "0.36.1"
41
+ "@orpc/shared": "0.37.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "zod": "^3.24.1"
@@ -1,13 +0,0 @@
1
- import type { Client } from '@orpc/contract';
2
- import type { IsEqual } from '@orpc/shared';
3
- import type { InfiniteOptionsBase, InfiniteOptionsExtra, MutationOptionsBase, MutationOptionsExtra, QueryOptionsBase, QueryOptionsExtra } from './types';
4
- /**
5
- * Utils at procedure level
6
- */
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;
11
- }
12
- export declare function createProcedureUtils<TClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, path: string[]): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
13
- //# sourceMappingURL=utils-procedure.d.ts.map