@orpc/react-query 0.0.0-next.e7d7758 → 0.0.0-next.e7ee5a9

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/README.md ADDED
@@ -0,0 +1,110 @@
1
+ <div align="center">
2
+ <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
3
+ </div>
4
+
5
+ <h1></h1>
6
+
7
+ <div align="center">
8
+ <a href="https://codecov.io/gh/unnoq/orpc">
9
+ <img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
10
+ </a>
11
+ <a href="https://www.npmjs.com/package/@orpc/react-query">
12
+ <img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Freact-query?logo=npm" />
13
+ </a>
14
+ <a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
15
+ <img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
16
+ </a>
17
+ <a href="https://discord.gg/TXEbwRBvQn">
18
+ <img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
19
+ </a>
20
+ </div>
21
+
22
+ <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
23
+
24
+ **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards, ensuring a smooth and enjoyable developer experience.
25
+
26
+ ---
27
+
28
+ ## Highlights
29
+
30
+ - **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
31
+ - **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
32
+ - **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
33
+ - **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
34
+ - **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
35
+ - **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue), Pinia Colada, and more.
36
+ - **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
37
+ - **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
38
+ - **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
39
+ - **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
40
+ - **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
41
+ - **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
42
+ - **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
43
+ - **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
44
+ - **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
45
+ - **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
46
+
47
+ ## Documentation
48
+
49
+ You can find the full documentation [here](https://orpc.unnoq.com).
50
+
51
+ ## Packages
52
+
53
+ - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
+ - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
+ - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
56
+ - [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
57
+ - [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
58
+ - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
59
+ - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
60
+ - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
61
+
62
+ ## `@orpc/react-query`
63
+
64
+ Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview). Read the [documentation](https://orpc.unnoq.com/docs/tanstack-query/react) for more information.
65
+
66
+ ```ts
67
+ export function Example() {
68
+ const query = useQuery(orpc.planet.find.queryOptions({
69
+ input: { id: 123 }, // Specify input if needed
70
+ context: { cache: true }, // Provide client context if needed
71
+ // additional options...
72
+ }))
73
+
74
+ const query = useInfiniteQuery(orpc.planet.list.infiniteOptions({
75
+ input: (pageParam: number | undefined) => ({ limit: 10, offset: pageParam }),
76
+ context: { cache: true }, // Provide client context if needed
77
+ initialPageParam: undefined,
78
+ getNextPageParam: lastPage => lastPage.nextPageParam,
79
+ // additional options...
80
+ }))
81
+
82
+ const mutation = useMutation(orpc.planet.create.mutationOptions({
83
+ context: { cache: true }, // Provide client context if needed
84
+ // additional options...
85
+ }))
86
+
87
+ mutation.mutate({ name: 'Earth' })
88
+
89
+ const queryClient = useQueryClient()
90
+
91
+ // Invalidate all planet queries
92
+ queryClient.invalidateQueries({
93
+ queryKey: orpc.planet.key(),
94
+ })
95
+
96
+ // Invalidate only regular (non-infinite) planet queries
97
+ queryClient.invalidateQueries({
98
+ queryKey: orpc.planet.key({ type: 'query' })
99
+ })
100
+
101
+ // Invalidate the planet find query with id 123
102
+ queryClient.invalidateQueries({
103
+ queryKey: orpc.planet.find.key({ input: { id: 123 } })
104
+ })
105
+ }
106
+ ```
107
+
108
+ ## License
109
+
110
+ Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
@@ -0,0 +1,76 @@
1
+ import { ClientContext, Client, NestedClient } from '@orpc/client';
2
+ import { QueryKey, UseQueryOptions, QueryFunctionContext, UseInfiniteQueryOptions, UseMutationOptions, InfiniteData } from '@tanstack/react-query';
3
+ import { PartialDeep, SetOptional, MaybeOptionalOptions } from '@orpc/shared';
4
+
5
+ type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
6
+ interface BuildKeyOptions<TType extends KeyType, TInput> {
7
+ type?: TType;
8
+ input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
9
+ }
10
+ declare function buildKey<TType extends KeyType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
11
+
12
+ /**
13
+ * Utils at any level (procedure or router)
14
+ */
15
+ interface GeneralUtils<TInput> {
16
+ key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
17
+ }
18
+ declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
19
+
20
+ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData> = (undefined extends TInput ? {
21
+ input?: TInput;
22
+ } : {
23
+ input: TInput;
24
+ }) & (Record<never, never> extends TClientContext ? {
25
+ context?: TClientContext;
26
+ } : {
27
+ context: TClientContext;
28
+ }) & SetOptional<UseQueryOptions<TOutput, TError, TSelectData>, 'queryKey'>;
29
+ interface QueryOptionsBase<TOutput, TError extends Error> {
30
+ queryKey: QueryKey;
31
+ queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
32
+ retry?(failureCount: number, error: TError): boolean;
33
+ }
34
+ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData, TPageParam> = {
35
+ input: (pageParam: TPageParam) => TInput;
36
+ } & (Record<never, never> extends TClientContext ? {
37
+ context?: TClientContext;
38
+ } : {
39
+ context: TClientContext;
40
+ }) & SetOptional<UseInfiniteQueryOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey'>;
41
+ interface InfiniteOptionsBase<TOutput, TError extends Error, TPageParam> {
42
+ queryKey: QueryKey;
43
+ queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
44
+ retry?(failureCount: number, error: TError): boolean;
45
+ }
46
+ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TMutationContext> = (Record<never, never> extends TClientContext ? {
47
+ context?: TClientContext;
48
+ } : {
49
+ context: TClientContext;
50
+ }) & UseMutationOptions<TOutput, TError, TInput, TMutationContext>;
51
+ interface MutationOptionsBase<TInput, TOutput, TError extends Error> {
52
+ mutationKey: QueryKey;
53
+ mutationFn(input: TInput): Promise<TOutput>;
54
+ retry?(failureCount: number, error: TError): boolean;
55
+ }
56
+
57
+ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
58
+ call: Client<TClientContext, TInput, TOutput, TError>;
59
+ queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
60
+ infiniteOptions<U, UPageParam, USelectData = InfiniteData<TOutput, UPageParam>>(options: U & InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UPageParam>): NoInfer<U & Omit<InfiniteOptionsBase<TOutput, TError, UPageParam>, keyof U>>;
61
+ mutationOptions<U, UMutationContext>(...rest: MaybeOptionalOptions<U & MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<U & Omit<MutationOptionsBase<TInput, TOutput, TError>, keyof U>>;
62
+ }
63
+ declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, path: string[]): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
64
+
65
+ type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
66
+ [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
67
+ } & GeneralUtils<unknown>;
68
+ /**
69
+ * @param client - Any kind of oRPC clients: `createRouterClient`, `createORPCClient`, ...
70
+ * @param path - The base path for query key, when it it will be prefix to all keys
71
+ */
72
+ declare function createRouterUtils<T extends NestedClient<any>>(client: T, path?: string[]): RouterUtils<T>;
73
+
74
+ declare const createORPCReactQueryUtils: typeof createRouterUtils;
75
+
76
+ export { type BuildKeyOptions, type GeneralUtils, type InfiniteOptionsBase, type InfiniteOptionsIn, type KeyType, type MutationOptionsBase, type MutationOptionsIn, type ProcedureUtils, type QueryOptionsBase, type QueryOptionsIn, type RouterUtils, buildKey, createGeneralUtils, createORPCReactQueryUtils, createProcedureUtils, createRouterUtils };
@@ -0,0 +1,76 @@
1
+ import { ClientContext, Client, NestedClient } from '@orpc/client';
2
+ import { QueryKey, UseQueryOptions, QueryFunctionContext, UseInfiniteQueryOptions, UseMutationOptions, InfiniteData } from '@tanstack/react-query';
3
+ import { PartialDeep, SetOptional, MaybeOptionalOptions } from '@orpc/shared';
4
+
5
+ type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
6
+ interface BuildKeyOptions<TType extends KeyType, TInput> {
7
+ type?: TType;
8
+ input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
9
+ }
10
+ declare function buildKey<TType extends KeyType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
11
+
12
+ /**
13
+ * Utils at any level (procedure or router)
14
+ */
15
+ interface GeneralUtils<TInput> {
16
+ key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
17
+ }
18
+ declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
19
+
20
+ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData> = (undefined extends TInput ? {
21
+ input?: TInput;
22
+ } : {
23
+ input: TInput;
24
+ }) & (Record<never, never> extends TClientContext ? {
25
+ context?: TClientContext;
26
+ } : {
27
+ context: TClientContext;
28
+ }) & SetOptional<UseQueryOptions<TOutput, TError, TSelectData>, 'queryKey'>;
29
+ interface QueryOptionsBase<TOutput, TError extends Error> {
30
+ queryKey: QueryKey;
31
+ queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
32
+ retry?(failureCount: number, error: TError): boolean;
33
+ }
34
+ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData, TPageParam> = {
35
+ input: (pageParam: TPageParam) => TInput;
36
+ } & (Record<never, never> extends TClientContext ? {
37
+ context?: TClientContext;
38
+ } : {
39
+ context: TClientContext;
40
+ }) & SetOptional<UseInfiniteQueryOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey'>;
41
+ interface InfiniteOptionsBase<TOutput, TError extends Error, TPageParam> {
42
+ queryKey: QueryKey;
43
+ queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
44
+ retry?(failureCount: number, error: TError): boolean;
45
+ }
46
+ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TMutationContext> = (Record<never, never> extends TClientContext ? {
47
+ context?: TClientContext;
48
+ } : {
49
+ context: TClientContext;
50
+ }) & UseMutationOptions<TOutput, TError, TInput, TMutationContext>;
51
+ interface MutationOptionsBase<TInput, TOutput, TError extends Error> {
52
+ mutationKey: QueryKey;
53
+ mutationFn(input: TInput): Promise<TOutput>;
54
+ retry?(failureCount: number, error: TError): boolean;
55
+ }
56
+
57
+ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
58
+ call: Client<TClientContext, TInput, TOutput, TError>;
59
+ queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
60
+ infiniteOptions<U, UPageParam, USelectData = InfiniteData<TOutput, UPageParam>>(options: U & InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UPageParam>): NoInfer<U & Omit<InfiniteOptionsBase<TOutput, TError, UPageParam>, keyof U>>;
61
+ mutationOptions<U, UMutationContext>(...rest: MaybeOptionalOptions<U & MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<U & Omit<MutationOptionsBase<TInput, TOutput, TError>, keyof U>>;
62
+ }
63
+ declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, path: string[]): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
64
+
65
+ type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
66
+ [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
67
+ } & GeneralUtils<unknown>;
68
+ /**
69
+ * @param client - Any kind of oRPC clients: `createRouterClient`, `createORPCClient`, ...
70
+ * @param path - The base path for query key, when it it will be prefix to all keys
71
+ */
72
+ declare function createRouterUtils<T extends NestedClient<any>>(client: T, path?: string[]): RouterUtils<T>;
73
+
74
+ declare const createORPCReactQueryUtils: typeof createRouterUtils;
75
+
76
+ export { type BuildKeyOptions, type GeneralUtils, type InfiniteOptionsBase, type InfiniteOptionsIn, type KeyType, type MutationOptionsBase, type MutationOptionsIn, type ProcedureUtils, type QueryOptionsBase, type QueryOptionsIn, type RouterUtils, buildKey, createGeneralUtils, createORPCReactQueryUtils, createProcedureUtils, createRouterUtils };
@@ -1,18 +1,12 @@
1
- // src/key.ts
2
1
  function buildKey(path, options) {
3
2
  const withInput = options?.input !== void 0 ? { input: options?.input } : {};
4
3
  const withType = options?.type !== void 0 ? { type: options?.type } : {};
5
- return [
6
- "__ORPC__",
7
- path,
8
- {
9
- ...withInput,
10
- ...withType
11
- }
12
- ];
4
+ return [path, {
5
+ ...withInput,
6
+ ...withType
7
+ }];
13
8
  }
14
9
 
15
- // src/utils-general.ts
16
10
  function createGeneralUtils(path) {
17
11
  return {
18
12
  key(options) {
@@ -21,36 +15,35 @@ function createGeneralUtils(path) {
21
15
  };
22
16
  }
23
17
 
24
- // src/utils-procedure.ts
25
18
  function createProcedureUtils(client, path) {
26
19
  return {
27
- queryOptions(...[options]) {
28
- const input = options?.input;
20
+ call: client,
21
+ queryOptions(...[{ input, context, ...rest } = {}]) {
29
22
  return {
30
23
  queryKey: buildKey(path, { type: "query", input }),
31
- queryFn: ({ signal }) => client(input, { signal, context: options?.context }),
32
- ...options
24
+ queryFn: ({ signal }) => client(input, { signal, context }),
25
+ ...rest
33
26
  };
34
27
  },
35
- infiniteOptions(options) {
36
- const input = options.input;
28
+ infiniteOptions({ input, context, ...rest }) {
37
29
  return {
38
- queryKey: buildKey(path, { type: "infinite", input }),
39
- queryFn: ({ pageParam, signal }) => client({ ...input, cursor: pageParam }, { signal, context: options.context }),
40
- ...options
30
+ queryKey: buildKey(path, { type: "infinite", input: input(rest.initialPageParam) }),
31
+ queryFn: ({ pageParam, signal }) => {
32
+ return client(input(pageParam), { signal, context });
33
+ },
34
+ ...rest
41
35
  };
42
36
  },
43
- mutationOptions(...[options]) {
37
+ mutationOptions(...[{ context, ...rest } = {}]) {
44
38
  return {
45
39
  mutationKey: buildKey(path, { type: "mutation" }),
46
- mutationFn: (input) => client(input, { context: options?.context }),
47
- ...options
40
+ mutationFn: (input) => client(input, { context }),
41
+ ...rest
48
42
  };
49
43
  }
50
44
  };
51
45
  }
52
46
 
53
- // src/utils-router.ts
54
47
  function createRouterUtils(client, path = []) {
55
48
  const generalUtils = createGeneralUtils(path);
56
49
  const procedureUtils = createProcedureUtils(client, path);
@@ -77,13 +70,6 @@ function createRouterUtils(client, path = []) {
77
70
  return recursive;
78
71
  }
79
72
 
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
73
+ const createORPCReactQueryUtils = createRouterUtils;
74
+
75
+ export { buildKey, createGeneralUtils, createORPCReactQueryUtils, createProcedureUtils, createRouterUtils };
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.e7d7758",
4
+ "version": "0.0.0-next.e7ee5a9",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -18,34 +18,27 @@
18
18
  ],
19
19
  "exports": {
20
20
  ".": {
21
- "types": "./dist/src/index.d.ts",
22
- "import": "./dist/index.js",
23
- "default": "./dist/index.js"
24
- },
25
- "./🔒/*": {
26
- "types": "./dist/src/*.d.ts"
21
+ "types": "./dist/index.d.mts",
22
+ "import": "./dist/index.mjs",
23
+ "default": "./dist/index.mjs"
27
24
  }
28
25
  },
29
26
  "files": [
30
- "!**/*.map",
31
- "!**/*.tsbuildinfo",
32
27
  "dist"
33
28
  ],
34
29
  "peerDependencies": {
35
30
  "@tanstack/react-query": ">=5.59.0",
36
31
  "react": ">=18.3.0",
37
- "@orpc/client": "0.0.0-next.e7d7758",
38
- "@orpc/contract": "0.0.0-next.e7d7758",
39
- "@orpc/server": "0.0.0-next.e7d7758"
32
+ "@orpc/client": "0.0.0-next.e7ee5a9"
40
33
  },
41
34
  "dependencies": {
42
- "@orpc/shared": "0.0.0-next.e7d7758"
35
+ "@orpc/shared": "0.0.0-next.e7ee5a9"
43
36
  },
44
37
  "devDependencies": {
45
38
  "zod": "^3.24.1"
46
39
  },
47
40
  "scripts": {
48
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
41
+ "build": "unbuild",
49
42
  "build:watch": "pnpm run build --watch",
50
43
  "type:check": "tsc -b"
51
44
  }
@@ -1,8 +0,0 @@
1
- import { createRouterUtils } from './utils-router';
2
- export * from './key';
3
- export * from './types';
4
- export * from './utils-general';
5
- export * from './utils-procedure';
6
- export * from './utils-router';
7
- export declare const createORPCReactQueryUtils: typeof createRouterUtils;
8
- //# sourceMappingURL=index.d.ts.map
package/dist/src/key.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import type { PartialDeep } from '@orpc/shared';
2
- import type { QueryKey } from '@tanstack/react-query';
3
- export type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
4
- export interface BuildKeyOptions<TType extends KeyType, TInput> {
5
- type?: TType;
6
- input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
7
- }
8
- export declare function buildKey<TType extends KeyType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
9
- //# sourceMappingURL=key.d.ts.map
@@ -1,29 +0,0 @@
1
- import type { SetOptional } from '@orpc/shared';
2
- import type { DefaultError, QueryKey, UndefinedInitialDataInfiniteOptions, UndefinedInitialDataOptions, UseMutationOptions } from '@tanstack/react-query';
3
- export type InferCursor<T> = T extends {
4
- cursor?: any;
5
- } ? T['cursor'] : never;
6
- export type QueryOptions<TInput, TOutput, TClientContext, TSelectData> = (undefined extends TInput ? {
7
- input?: TInput;
8
- } : {
9
- input: TInput;
10
- }) & (undefined extends TClientContext ? {
11
- context?: TClientContext;
12
- } : {
13
- context: TClientContext;
14
- }) & (SetOptional<UndefinedInitialDataOptions<TOutput, DefaultError, TSelectData, QueryKey>, 'queryKey'>);
15
- export type InfiniteOptions<TInput, TOutput, TClientContext, TSelectData> = (undefined extends TInput ? {
16
- input?: Omit<TInput, 'cursor'>;
17
- } : {
18
- input: Omit<TInput, 'cursor'>;
19
- }) & (undefined extends TClientContext ? {
20
- context?: TClientContext;
21
- } : {
22
- context: TClientContext;
23
- }) & (SetOptional<UndefinedInitialDataInfiniteOptions<TOutput, DefaultError, TSelectData, QueryKey, InferCursor<TInput>>, 'queryKey' | (undefined extends InferCursor<TInput> ? 'initialPageParam' : never)>);
24
- export type MutationOptions<TInput, TOutput, TClientContext> = (undefined extends TClientContext ? {
25
- context?: TClientContext;
26
- } : {
27
- context: TClientContext;
28
- }) & UseMutationOptions<TOutput, DefaultError, TInput>;
29
- //# sourceMappingURL=types.d.ts.map
@@ -1,10 +0,0 @@
1
- import type { QueryKey } from '@tanstack/react-query';
2
- import type { BuildKeyOptions, KeyType } from './key';
3
- /**
4
- * Utils at any level (procedure or router)
5
- */
6
- export interface GeneralUtils<TInput> {
7
- key: <UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>) => QueryKey;
8
- }
9
- export declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
10
- //# sourceMappingURL=utils-general.d.ts.map
@@ -1,30 +0,0 @@
1
- import type { ProcedureClient } from '@orpc/server';
2
- import type { IsEqual } from '@orpc/shared';
3
- import type { QueryFunctionContext, QueryKey } from '@tanstack/react-query';
4
- import type { InferCursor, InfiniteOptions, MutationOptions, QueryOptions } from './types';
5
- /**
6
- * Utils at procedure level
7
- */
8
- export interface ProcedureUtils<TInput, TOutput, TClientContext> {
9
- queryOptions: <U extends QueryOptions<TInput, TOutput, TClientContext, any>>(...opts: [options: U] | (undefined extends TInput & TClientContext ? [] : never)) => IsEqual<U, QueryOptions<TInput, TOutput, TClientContext, any>> extends true ? {
10
- queryKey: QueryKey;
11
- queryFn: (ctx: QueryFunctionContext) => Promise<TOutput>;
12
- } : Omit<{
13
- queryKey: QueryKey;
14
- queryFn: (ctx: QueryFunctionContext) => Promise<TOutput>;
15
- }, keyof U> & U;
16
- infiniteOptions: <U extends InfiniteOptions<TInput, TOutput, TClientContext, any>>(options: U) => Omit<{
17
- queryKey: QueryKey;
18
- queryFn: (ctx: QueryFunctionContext<QueryKey, InferCursor<TInput>>) => Promise<TOutput>;
19
- initialPageParam: undefined;
20
- }, keyof U> & U;
21
- mutationOptions: <U extends MutationOptions<TInput, TOutput, TClientContext>>(...opt: [options: U] | (undefined extends TClientContext ? [] : never)) => IsEqual<U, MutationOptions<TInput, TOutput, TClientContext>> 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;
28
- }
29
- export declare function createProcedureUtils<TInput, TOutput, TClientContext>(client: ProcedureClient<TInput, TOutput, TClientContext>, path: string[]): ProcedureUtils<TInput, TOutput, TClientContext>;
30
- //# sourceMappingURL=utils-procedure.d.ts.map
@@ -1,12 +0,0 @@
1
- import type { ProcedureClient, RouterClient } from '@orpc/server';
2
- import { type GeneralUtils } from './utils-general';
3
- import { type ProcedureUtils } from './utils-procedure';
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;
6
- } & GeneralUtils<unknown>;
7
- /**
8
- * @param client - The client create form `@orpc/client`
9
- * @param path - The base path for query key
10
- */
11
- export declare function createRouterUtils<T extends RouterClient<any, any>>(client: T, path?: string[]): RouterUtils<T>;
12
- //# sourceMappingURL=utils-router.d.ts.map