@orpc/react-query 0.0.0-next.b4e6d3a → 0.0.0-next.b825e0c

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,13 +2,17 @@
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 [path, {
6
- ...withInput,
7
- ...withType
8
- }];
5
+ return [
6
+ "__ORPC__",
7
+ path,
8
+ {
9
+ ...withInput,
10
+ ...withType
11
+ }
12
+ ];
9
13
  }
10
14
 
11
- // src/general-utils.ts
15
+ // src/utils-general.ts
12
16
  function createGeneralUtils(path) {
13
17
  return {
14
18
  key(options) {
@@ -17,37 +21,37 @@ function createGeneralUtils(path) {
17
21
  };
18
22
  }
19
23
 
20
- // src/procedure-utils.ts
24
+ // src/utils-procedure.ts
21
25
  function createProcedureUtils(client, path) {
22
26
  return {
23
- call: client,
24
- queryOptions(...[{ input, context, ...rest } = {}]) {
27
+ queryOptions(...[options]) {
28
+ const input = options?.input;
25
29
  return {
26
30
  queryKey: buildKey(path, { type: "query", input }),
27
- queryFn: ({ signal }) => client(input, { signal, context }),
28
- ...rest
31
+ queryFn: ({ signal }) => client(input, { signal, context: options?.context }),
32
+ ...options
29
33
  };
30
34
  },
31
- infiniteOptions({ input, context, ...rest }) {
35
+ infiniteOptions(options) {
36
+ const input = options.input;
32
37
  return {
33
- queryKey: buildKey(path, { type: "infinite", input: input(rest.initialPageParam) }),
34
- queryFn: ({ pageParam, signal }) => {
35
- return client(input(pageParam), { signal, context });
36
- },
37
- ...rest
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
38
42
  };
39
43
  },
40
- mutationOptions(...[{ context, ...rest } = {}]) {
44
+ mutationOptions(...[options]) {
41
45
  return {
42
46
  mutationKey: buildKey(path, { type: "mutation" }),
43
- mutationFn: (input) => client(input, { context }),
44
- ...rest
47
+ mutationFn: (input) => client(input, { context: options?.context }),
48
+ ...options
45
49
  };
46
50
  }
47
51
  };
48
52
  }
49
53
 
50
- // src/router-utils.ts
54
+ // src/utils-router.ts
51
55
  function createRouterUtils(client, path = []) {
52
56
  const generalUtils = createGeneralUtils(path);
53
57
  const procedureUtils = createProcedureUtils(client, path);
@@ -1,8 +1,8 @@
1
- import { createRouterUtils } from './router-utils';
2
- export * from './general-utils';
1
+ import { createRouterUtils } from './utils-router';
3
2
  export * from './key';
4
- export * from './procedure-utils';
5
- export * from './router-utils';
6
3
  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
@@ -1,40 +1,45 @@
1
- import type { ClientContext } from '@orpc/contract';
2
1
  import type { SetOptional } from '@orpc/shared';
3
- import type { QueryFunctionContext, QueryKey, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from '@tanstack/react-query';
4
- export type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData> = (undefined extends TInput ? {
5
- input?: TInput;
6
- } : {
7
- input: TInput;
8
- }) & (Record<never, never> extends TClientContext ? {
9
- context?: TClientContext;
10
- } : {
11
- context: TClientContext;
12
- }) & SetOptional<UseQueryOptions<TOutput, TError, TSelectData>, 'queryKey'>;
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;
13
6
  export interface QueryOptionsBase<TOutput, TError extends Error> {
14
7
  queryKey: QueryKey;
15
8
  queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
16
9
  retry?(failureCount: number, error: TError): boolean;
17
10
  }
18
- export type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData, TPageParam> = {
19
- input: (pageParam: TPageParam) => TInput;
20
- } & (Record<never, never> extends TClientContext ? {
11
+ export type QueryOptionsExtra<TClientContext, TInput, TOutput, TError extends Error, TSelectData> = (undefined extends TInput ? {
12
+ input?: TInput;
13
+ } : {
14
+ input: TInput;
15
+ }) & (undefined extends TClientContext ? {
21
16
  context?: TClientContext;
22
17
  } : {
23
18
  context: TClientContext;
24
- }) & SetOptional<UseInfiniteQueryOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey'>;
25
- export interface InfiniteOptionsBase<TOutput, TError extends Error, TPageParam> {
19
+ }) & (SetOptional<UndefinedInitialDataOptions<TOutput, TError, TSelectData, QueryKey>, 'queryKey'>);
20
+ export interface InfiniteOptionsBase<TInput, TOutput, TError extends Error> {
26
21
  queryKey: QueryKey;
27
- queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
22
+ queryFn(ctx: QueryFunctionContext<QueryKey, InferCursor<TInput>>): Promise<TOutput>;
28
23
  retry?(failureCount: number, error: TError): boolean;
24
+ initialPageParam: undefined;
29
25
  }
30
- export type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> = (Record<never, never> extends TClientContext ? {
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 ? {
31
31
  context?: TClientContext;
32
32
  } : {
33
33
  context: TClientContext;
34
- }) & UseMutationOptions<TOutput, TError, TInput>;
34
+ }) & (SetOptional<UndefinedInitialDataInfiniteOptions<TOutput, TError, TSelectData, QueryKey, InferCursor<TInput>>, 'queryKey' | (undefined extends InferCursor<TInput> ? 'initialPageParam' : never)>);
35
35
  export interface MutationOptionsBase<TInput, TOutput, TError extends Error> {
36
36
  mutationKey: QueryKey;
37
37
  mutationFn(input: TInput): Promise<TOutput>;
38
38
  retry?(failureCount: number, error: TError): boolean;
39
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>;
40
45
  //# sourceMappingURL=types.d.ts.map
@@ -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=general-utils.d.ts.map
10
+ //# sourceMappingURL=utils-general.d.ts.map
@@ -0,0 +1,13 @@
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
@@ -1,12 +1,12 @@
1
1
  import type { Client, NestedClient } from '@orpc/contract';
2
- import { type GeneralUtils } from './general-utils';
3
- import { type ProcedureUtils } from './procedure-utils';
2
+ import { type GeneralUtils } from './utils-general';
3
+ import { type ProcedureUtils } from './utils-procedure';
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 - 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
8
+ * @param client - The client create form `@orpc/client`
9
+ * @param path - The base path for query key
10
10
  */
11
11
  export declare function createRouterUtils<T extends NestedClient<any>>(client: T, path?: string[]): RouterUtils<T>;
12
- //# sourceMappingURL=router-utils.d.ts.map
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.b4e6d3a",
4
+ "version": "0.0.0-next.b825e0c",
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.0.0-next.b4e6d3a",
38
- "@orpc/contract": "0.0.0-next.b4e6d3a"
37
+ "@orpc/contract": "0.0.0-next.b825e0c",
38
+ "@orpc/client": "0.0.0-next.b825e0c"
39
39
  },
40
40
  "dependencies": {
41
- "@orpc/shared": "0.0.0-next.b4e6d3a"
41
+ "@orpc/shared": "0.0.0-next.b825e0c"
42
42
  },
43
43
  "devDependencies": {
44
44
  "zod": "^3.24.1"
@@ -1,12 +0,0 @@
1
- import type { Client, ClientContext } 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 extends ClientContext, TInput, TOutput, TError extends Error> {
6
- call: Client<TClientContext, TInput, TOutput, TError>;
7
- queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & QueryOptionsBase<TOutput, TError>>;
8
- infiniteOptions<U, UPageParam, USelectData = InfiniteData<TOutput>>(options: U & InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UPageParam>): NoInfer<U & InfiniteOptionsBase<TOutput, TError, UPageParam>>;
9
- mutationOptions<U>(...rest: MaybeOptionalOptions<U & MutationOptionsIn<TClientContext, TInput, TOutput, TError>>): NoInfer<U & MutationOptionsBase<TInput, TOutput, TError>>;
10
- }
11
- export declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, path: string[]): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
12
- //# sourceMappingURL=procedure-utils.d.ts.map