@orpc/react-query 0.0.0 → 0.15.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 ADDED
@@ -0,0 +1,89 @@
1
+ // src/key.ts
2
+ function buildKey(path, options) {
3
+ const withInput = options?.input !== void 0 ? { input: options?.input } : {};
4
+ const withType = options?.type !== void 0 ? { type: options?.type } : {};
5
+ return [
6
+ "__ORPC__",
7
+ path,
8
+ {
9
+ ...withInput,
10
+ ...withType
11
+ }
12
+ ];
13
+ }
14
+
15
+ // src/utils-general.ts
16
+ function createGeneralUtils(path) {
17
+ return {
18
+ key(options) {
19
+ return buildKey(path, options);
20
+ }
21
+ };
22
+ }
23
+
24
+ // src/utils-procedure.ts
25
+ function createProcedureUtils(client, path) {
26
+ return {
27
+ queryOptions(...[options]) {
28
+ const input = options?.input;
29
+ return {
30
+ queryKey: buildKey(path, { type: "query", input }),
31
+ queryFn: ({ signal }) => client(input, { signal }),
32
+ ...options
33
+ };
34
+ },
35
+ infiniteOptions(options) {
36
+ const input = options.input;
37
+ return {
38
+ queryKey: buildKey(path, { type: "infinite", input }),
39
+ queryFn: ({ pageParam, signal }) => client({ ...input, cursor: pageParam }, { signal }),
40
+ ...options
41
+ };
42
+ },
43
+ mutationOptions(options) {
44
+ return {
45
+ mutationKey: buildKey(path, { type: "mutation" }),
46
+ mutationFn: (input) => client(input),
47
+ ...options
48
+ };
49
+ }
50
+ };
51
+ }
52
+
53
+ // src/utils-router.ts
54
+ function createRouterUtils(client, path = []) {
55
+ const generalUtils = createGeneralUtils(path);
56
+ const procedureUtils = createProcedureUtils(client, path);
57
+ const recursive = new Proxy({
58
+ ...generalUtils,
59
+ ...procedureUtils
60
+ }, {
61
+ get(target, prop) {
62
+ const value = Reflect.get(target, prop);
63
+ if (typeof prop !== "string") {
64
+ return value;
65
+ }
66
+ const nextUtils = createRouterUtils(client[prop], [...path, prop]);
67
+ if (typeof value !== "function") {
68
+ return nextUtils;
69
+ }
70
+ return new Proxy(value, {
71
+ get(_, prop2) {
72
+ return Reflect.get(nextUtils, prop2);
73
+ }
74
+ });
75
+ }
76
+ });
77
+ return recursive;
78
+ }
79
+
80
+ // src/index.ts
81
+ var createORPCReactQueryUtils = createRouterUtils;
82
+ export {
83
+ buildKey,
84
+ createGeneralUtils,
85
+ createORPCReactQueryUtils,
86
+ createProcedureUtils,
87
+ createRouterUtils
88
+ };
89
+ //# sourceMappingURL=index.js.map
@@ -8,8 +8,10 @@ export type QueryOptions<TInput, TOutput, TSelectData> = (undefined extends TInp
8
8
  } : {
9
9
  input: TInput;
10
10
  }) & (SetOptional<UndefinedInitialDataOptions<TOutput, DefaultError, TSelectData, QueryKey>, 'queryKey'>);
11
- export type InfiniteOptions<TInput, TOutput, TSelectData> = {
11
+ export type InfiniteOptions<TInput, TOutput, TSelectData> = (undefined extends TInput ? {
12
+ input?: Omit<TInput, 'cursor'>;
13
+ } : {
12
14
  input: Omit<TInput, 'cursor'>;
13
- } & (SetOptional<UndefinedInitialDataInfiniteOptions<TOutput, DefaultError, TSelectData, QueryKey, InferCursor<TInput>>, 'queryKey' | (undefined extends InferCursor<TInput> ? 'initialPageParam' : never)>);
15
+ }) & (SetOptional<UndefinedInitialDataInfiniteOptions<TOutput, DefaultError, TSelectData, QueryKey, InferCursor<TInput>>, 'queryKey' | (undefined extends InferCursor<TInput> ? 'initialPageParam' : never)>);
14
16
  export type MutationOptions<TInput, TOutput> = UseMutationOptions<TOutput, DefaultError, TInput>;
15
17
  //# sourceMappingURL=types.d.ts.map
@@ -1,11 +1,12 @@
1
- import type { IsEqual, SetOptional } from '@orpc/shared';
2
- import type { DefaultError, QueryKey, UseMutationOptions } from '@tanstack/react-query';
3
- import type { InfiniteOptions, QueryOptions } from './types';
1
+ import type { Caller } from '@orpc/server';
2
+ import type { IsEqual } from '@orpc/shared';
3
+ import type { QueryKey } from '@tanstack/react-query';
4
+ import type { InfiniteOptions, MutationOptions, QueryOptions } from './types';
4
5
  /**
5
6
  * Utils at procedure level
6
7
  */
7
8
  export interface ProcedureUtils<TInput, TOutput> {
8
- queryOptions: <U extends QueryOptions<TInput, TOutput, TOutput>>(...options: [U] | (undefined extends TInput ? [] : never)) => IsEqual<U, QueryOptions<TInput, TOutput, TOutput>> extends true ? {
9
+ queryOptions: <U extends QueryOptions<TInput, TOutput, any>>(...opts: [options: U] | (undefined extends TInput ? [] : never)) => IsEqual<U, QueryOptions<TInput, TOutput, any>> extends true ? {
9
10
  queryKey: QueryKey;
10
11
  queryFn: () => Promise<TOutput>;
11
12
  } : Omit<{
@@ -17,7 +18,13 @@ export interface ProcedureUtils<TInput, TOutput> {
17
18
  queryFn: () => Promise<TOutput>;
18
19
  initialPageParam: undefined;
19
20
  }, keyof U> & U;
20
- mutationOptions: (options?: SetOptional<UseMutationOptions<TOutput, DefaultError, TInput>, 'mutationFn' | 'mutationKey'>) => UseMutationOptions<TOutput, DefaultError, TInput>;
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;
21
28
  }
22
- export declare function createProcedureUtils<TInput, TOutput>(client: (input: TInput) => Promise<TOutput>, path: string[]): ProcedureUtils<TInput, TOutput>;
29
+ export declare function createProcedureUtils<TInput, TOutput>(client: Caller<TInput, TOutput>, path: string[]): ProcedureUtils<TInput, TOutput>;
23
30
  //# sourceMappingURL=utils-procedure.d.ts.map
@@ -1,3 +1,4 @@
1
+ import type { RouterClient } from '@orpc/client';
1
2
  import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract';
2
3
  import type { Lazy, Procedure, Router } from '@orpc/server';
3
4
  import { type GeneralUtils } from './utils-general';
@@ -9,6 +10,5 @@ export type RouterUtils<T extends Router<any> | ContractRouter> = {
9
10
  * @param client - The client create form `@orpc/client`
10
11
  * @param path - The base path for query key
11
12
  */
12
- export declare function createRouterUtils<T extends Router<any> | ContractRouter>(client: any, // TODO typed
13
- path?: string[]): RouterUtils<T>;
13
+ export declare function createRouterUtils<T extends Router<any> | ContractRouter>(client: RouterClient<T>, path?: string[]): RouterUtils<T>;
14
14
  //# 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",
4
+ "version": "0.15.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -34,15 +34,15 @@
34
34
  "peerDependencies": {
35
35
  "@tanstack/react-query": ">=5.59.0",
36
36
  "react": ">=18.3.0",
37
- "@orpc/client": "0.14.0",
38
- "@orpc/contract": "0.14.0",
39
- "@orpc/server": "0.14.0"
37
+ "@orpc/client": "0.15.0",
38
+ "@orpc/contract": "0.15.0",
39
+ "@orpc/server": "0.15.0"
40
40
  },
41
41
  "dependencies": {
42
- "@orpc/shared": "0.14.0"
42
+ "@orpc/shared": "0.15.0"
43
43
  },
44
44
  "devDependencies": {
45
- "zod": "^3.21.4"
45
+ "zod": "^3.24.1"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",