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