@orpc/react 0.0.0-next.ef3ba82 → 0.0.0-next.fd1db03
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 -21
- package/dist/src/general-hooks.d.ts +6 -6
- package/dist/src/general-utils.d.ts +22 -22
- package/dist/src/index.d.ts +1 -0
- package/dist/src/orpc-path.d.ts +3 -2
- package/dist/src/procedure-hooks.d.ts +14 -14
- package/dist/src/procedure-utils.d.ts +24 -24
- package/dist/src/react-context.d.ts +7 -8
- package/dist/src/react-hooks.d.ts +8 -11
- package/dist/src/react-utils.d.ts +8 -11
- package/dist/src/react.d.ts +13 -18
- package/dist/src/tanstack-key.d.ts +4 -4
- package/dist/src/tanstack-query.d.ts +1 -0
- package/dist/src/types.d.ts +5 -4
- package/dist/src/use-queries/builder.d.ts +7 -7
- package/dist/src/use-queries/builders.d.ts +7 -11
- package/dist/src/use-queries/hook.d.ts +10 -13
- package/package.json +10 -9
package/dist/index.js
CHANGED
@@ -275,7 +275,7 @@ function createProcedureHooks(options) {
|
|
275
275
|
return useQuery(
|
276
276
|
{
|
277
277
|
queryKey: getQueryKeyFromPath(options.path, { input, type: "query" }),
|
278
|
-
queryFn: () => client(input),
|
278
|
+
queryFn: ({ signal }) => client(input, { signal }),
|
279
279
|
...options_
|
280
280
|
},
|
281
281
|
context.queryClient
|
@@ -291,7 +291,7 @@ function createProcedureHooks(options) {
|
|
291
291
|
input,
|
292
292
|
type: "infinite"
|
293
293
|
}),
|
294
|
-
queryFn: ({ pageParam }) => client({ ...input, cursor: pageParam }),
|
294
|
+
queryFn: ({ pageParam, signal }) => client({ ...input, cursor: pageParam }, { signal }),
|
295
295
|
...rest
|
296
296
|
},
|
297
297
|
context.queryClient
|
@@ -303,7 +303,7 @@ function createProcedureHooks(options) {
|
|
303
303
|
return useSuspenseQuery(
|
304
304
|
{
|
305
305
|
queryKey: getQueryKeyFromPath(options.path, { input, type: "query" }),
|
306
|
-
queryFn: () => client(input),
|
306
|
+
queryFn: ({ signal }) => client(input, { signal }),
|
307
307
|
...options_
|
308
308
|
},
|
309
309
|
context.queryClient
|
@@ -319,7 +319,7 @@ function createProcedureHooks(options) {
|
|
319
319
|
input,
|
320
320
|
type: "infinite"
|
321
321
|
}),
|
322
|
-
queryFn: ({ pageParam }) => client({ ...input, cursor: pageParam }),
|
322
|
+
queryFn: ({ pageParam, signal }) => client({ ...input, cursor: pageParam }, { signal }),
|
323
323
|
...rest
|
324
324
|
},
|
325
325
|
context.queryClient
|
@@ -331,7 +331,7 @@ function createProcedureHooks(options) {
|
|
331
331
|
return usePrefetchQuery(
|
332
332
|
{
|
333
333
|
queryKey: getQueryKeyFromPath(options.path, { input, type: "query" }),
|
334
|
-
queryFn: () => client(input),
|
334
|
+
queryFn: ({ signal }) => client(input, { signal }),
|
335
335
|
...options_
|
336
336
|
},
|
337
337
|
context.queryClient
|
@@ -347,7 +347,7 @@ function createProcedureHooks(options) {
|
|
347
347
|
input,
|
348
348
|
type: "infinite"
|
349
349
|
}),
|
350
|
-
queryFn: ({ pageParam }) => client({ ...input, cursor: pageParam }),
|
350
|
+
queryFn: ({ pageParam, signal }) => client({ ...input, cursor: pageParam }, { signal }),
|
351
351
|
...rest
|
352
352
|
},
|
353
353
|
context.queryClient
|
@@ -374,7 +374,7 @@ function createProcedureUtils(options) {
|
|
374
374
|
fetchQuery(input, options_) {
|
375
375
|
return options.queryClient.fetchQuery({
|
376
376
|
queryKey: getQueryKeyFromPath(options.path, { input, type: "query" }),
|
377
|
-
queryFn: () => options.client(input),
|
377
|
+
queryFn: ({ signal }) => options.client(input, { signal }),
|
378
378
|
...options_
|
379
379
|
});
|
380
380
|
},
|
@@ -385,8 +385,8 @@ function createProcedureUtils(options) {
|
|
385
385
|
input,
|
386
386
|
type: "infinite"
|
387
387
|
}),
|
388
|
-
queryFn: ({ pageParam }) => {
|
389
|
-
return options.client({ ...input, pageParam });
|
388
|
+
queryFn: ({ pageParam, signal }) => {
|
389
|
+
return options.client({ ...input, pageParam }, { signal });
|
390
390
|
},
|
391
391
|
...rest
|
392
392
|
});
|
@@ -397,7 +397,7 @@ function createProcedureUtils(options) {
|
|
397
397
|
input,
|
398
398
|
type: "query"
|
399
399
|
}),
|
400
|
-
queryFn: () => options.client(input),
|
400
|
+
queryFn: ({ signal }) => options.client(input, { signal }),
|
401
401
|
...options_
|
402
402
|
});
|
403
403
|
},
|
@@ -408,8 +408,8 @@ function createProcedureUtils(options) {
|
|
408
408
|
input,
|
409
409
|
type: "infinite"
|
410
410
|
}),
|
411
|
-
queryFn: ({ pageParam }) => {
|
412
|
-
return options.client({ ...input, cursor: pageParam });
|
411
|
+
queryFn: ({ pageParam, signal }) => {
|
412
|
+
return options.client({ ...input, cursor: pageParam }, { signal });
|
413
413
|
},
|
414
414
|
...rest
|
415
415
|
});
|
@@ -436,7 +436,7 @@ function createProcedureUtils(options) {
|
|
436
436
|
input,
|
437
437
|
type: "query"
|
438
438
|
}),
|
439
|
-
queryFn: () => options.client(input),
|
439
|
+
queryFn: ({ signal }) => options.client(input, { signal }),
|
440
440
|
...options_
|
441
441
|
});
|
442
442
|
},
|
@@ -447,8 +447,8 @@ function createProcedureUtils(options) {
|
|
447
447
|
input,
|
448
448
|
type: "infinite"
|
449
449
|
}),
|
450
|
-
queryFn: ({ pageParam }) => {
|
451
|
-
return options.client({ ...input, pageParam });
|
450
|
+
queryFn: ({ pageParam, signal }) => {
|
451
|
+
return options.client({ ...input, pageParam }, { signal });
|
452
452
|
},
|
453
453
|
...rest
|
454
454
|
});
|
@@ -496,10 +496,10 @@ function createProcedureUtils(options) {
|
|
496
496
|
function createORPCHooks(options) {
|
497
497
|
const path = options.path ?? [];
|
498
498
|
const generalHooks = createGeneralHooks({ context: options.context, path });
|
499
|
-
const procedureHooks =
|
499
|
+
const procedureHooks = createProcedureHooks({
|
500
500
|
context: options.context,
|
501
501
|
path
|
502
|
-
})
|
502
|
+
});
|
503
503
|
return new Proxy(
|
504
504
|
{
|
505
505
|
[orpcPathSymbol]: path,
|
@@ -575,16 +575,14 @@ function createORPCUtils(options) {
|
|
575
575
|
}
|
576
576
|
|
577
577
|
// src/use-queries/hook.ts
|
578
|
-
import {
|
579
|
-
useQueries
|
580
|
-
} from "@tanstack/react-query";
|
578
|
+
import { useQueries } from "@tanstack/react-query";
|
581
579
|
|
582
580
|
// src/use-queries/builder.ts
|
583
581
|
function createUseQueriesBuilder(options) {
|
584
582
|
return (input, options_) => {
|
585
583
|
return {
|
586
584
|
queryKey: getQueryKeyFromPath(options.path, { input, type: "query" }),
|
587
|
-
queryFn: () => options.client(input),
|
585
|
+
queryFn: ({ signal }) => options.client(input, { signal }),
|
588
586
|
...options_
|
589
587
|
};
|
590
588
|
};
|
@@ -671,3 +669,4 @@ export {
|
|
671
669
|
createProcedureUtils,
|
672
670
|
useORPCContext
|
673
671
|
};
|
672
|
+
//# sourceMappingURL=index.js.map
|
@@ -1,14 +1,13 @@
|
|
1
|
-
import type { Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
1
|
import type { PartialDeep, SetOptional } from '@orpc/shared';
|
3
2
|
import type { ORPCQueryFilters } from './tanstack-query';
|
4
3
|
import { type DefaultError, type Mutation, type MutationFilters, type MutationState } from '@tanstack/react-query';
|
5
4
|
import { type ORPCContext } from './react-context';
|
6
|
-
export interface GeneralHooks<
|
7
|
-
useIsFetching: (filers?: ORPCQueryFilters<PartialDeep<
|
5
|
+
export interface GeneralHooks<TInput, TOutput> {
|
6
|
+
useIsFetching: (filers?: ORPCQueryFilters<PartialDeep<TInput>>) => number;
|
8
7
|
useIsMutating: (filters?: SetOptional<MutationFilters, 'mutationKey'>) => number;
|
9
|
-
useMutationState: <UResult = MutationState<
|
8
|
+
useMutationState: <UResult = MutationState<TOutput, DefaultError, TInput>>(options?: {
|
10
9
|
filters?: SetOptional<MutationFilters, 'mutationKey'>;
|
11
|
-
select?: (mutation: Mutation<
|
10
|
+
select?: (mutation: Mutation<TOutput, DefaultError, TInput>) => UResult;
|
12
11
|
}) => UResult[];
|
13
12
|
}
|
14
13
|
export interface CreateGeneralHooksOptions {
|
@@ -20,4 +19,5 @@ export interface CreateGeneralHooksOptions {
|
|
20
19
|
*/
|
21
20
|
path: string[];
|
22
21
|
}
|
23
|
-
export declare function createGeneralHooks<
|
22
|
+
export declare function createGeneralHooks<TInput, TOutput>(options: CreateGeneralHooksOptions): GeneralHooks<TInput, TOutput>;
|
23
|
+
//# sourceMappingURL=general-hooks.d.ts.map
|
@@ -1,32 +1,31 @@
|
|
1
|
-
import type { Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
1
|
import type { PartialDeep, SetOptional } from '@orpc/shared';
|
3
2
|
import type { CancelOptions, DefaultError, InfiniteData, InvalidateOptions, MutationFilters, MutationObserverOptions, OmitKeyof, QueryClient, QueryKey, QueryObserverOptions, RefetchOptions, ResetOptions, SetDataOptions, Updater } from '@tanstack/react-query';
|
4
3
|
import type { ORPCInvalidateQueryFilters, ORPCQueryFilters } from './tanstack-query';
|
5
|
-
import type { SchemaInputForInfiniteQuery } from './types';
|
6
|
-
export interface GeneralUtils<
|
7
|
-
getQueriesData: (filters?: OmitKeyof<ORPCQueryFilters<PartialDeep<
|
8
|
-
getInfiniteQueriesData: (filters?: OmitKeyof<ORPCQueryFilters<PartialDeep<SchemaInputForInfiniteQuery<
|
4
|
+
import type { InferCursor, SchemaInputForInfiniteQuery } from './types';
|
5
|
+
export interface GeneralUtils<TInput, TOutput> {
|
6
|
+
getQueriesData: (filters?: OmitKeyof<ORPCQueryFilters<PartialDeep<TInput>>, 'queryType'>) => [QueryKey, TOutput | undefined][];
|
7
|
+
getInfiniteQueriesData: (filters?: OmitKeyof<ORPCQueryFilters<PartialDeep<SchemaInputForInfiniteQuery<TInput>>>, 'queryType'>) => [
|
9
8
|
QueryKey,
|
10
|
-
undefined | InfiniteData<
|
9
|
+
undefined | InfiniteData<TOutput, InferCursor<TInput>>
|
11
10
|
][];
|
12
|
-
setQueriesData: (filters: OmitKeyof<ORPCQueryFilters<PartialDeep<
|
13
|
-
setInfiniteQueriesData: (filters: OmitKeyof<ORPCQueryFilters<PartialDeep<SchemaInputForInfiniteQuery<
|
11
|
+
setQueriesData: (filters: OmitKeyof<ORPCQueryFilters<PartialDeep<TInput>>, 'queryType'>, updater: Updater<TOutput | undefined, TOutput | undefined>, options?: SetDataOptions) => [QueryKey, TOutput | undefined][];
|
12
|
+
setInfiniteQueriesData: (filters: OmitKeyof<ORPCQueryFilters<PartialDeep<SchemaInputForInfiniteQuery<TInput>>>, 'queryType'>, updater: Updater<InfiniteData<TOutput, InferCursor<TInput>> | undefined, InfiniteData<TOutput, InferCursor<TInput>> | undefined>, options?: SetDataOptions) => [
|
14
13
|
QueryKey,
|
15
|
-
undefined | InfiniteData<
|
14
|
+
undefined | InfiniteData<TOutput, InferCursor<TInput>>
|
16
15
|
][];
|
17
|
-
invalidate: (filters?: ORPCInvalidateQueryFilters<PartialDeep<
|
18
|
-
refetch: (filters?: ORPCQueryFilters<PartialDeep<
|
19
|
-
cancel: (filters?: ORPCQueryFilters<PartialDeep<
|
20
|
-
remove: (filters?: ORPCQueryFilters<PartialDeep<
|
21
|
-
reset: (filters?: ORPCQueryFilters<PartialDeep<
|
22
|
-
isFetching: (filters?: ORPCQueryFilters<PartialDeep<
|
16
|
+
invalidate: (filters?: ORPCInvalidateQueryFilters<PartialDeep<TInput>>, options?: InvalidateOptions) => Promise<void>;
|
17
|
+
refetch: (filters?: ORPCQueryFilters<PartialDeep<TInput>>, options?: RefetchOptions) => Promise<void>;
|
18
|
+
cancel: (filters?: ORPCQueryFilters<PartialDeep<TInput>>, options?: CancelOptions) => Promise<void>;
|
19
|
+
remove: (filters?: ORPCQueryFilters<PartialDeep<TInput>>) => void;
|
20
|
+
reset: (filters?: ORPCQueryFilters<PartialDeep<TInput>>, options?: ResetOptions) => Promise<void>;
|
21
|
+
isFetching: (filters?: ORPCQueryFilters<PartialDeep<TInput>>) => number;
|
23
22
|
isMutating: (filters?: SetOptional<MutationFilters, 'mutationKey'>) => number;
|
24
|
-
getQueryDefaults: (filters?: Pick<ORPCQueryFilters<PartialDeep<
|
25
|
-
getInfiniteQueryDefaults: (filters?: Pick<ORPCQueryFilters<PartialDeep<SchemaInputForInfiniteQuery<
|
26
|
-
setQueryDefaults: (options: Partial<OmitKeyof<QueryObserverOptions<
|
27
|
-
setInfiniteQueryDefaults: (options: Partial<OmitKeyof<QueryObserverOptions<
|
28
|
-
getMutationDefaults: (filters?: Pick<MutationFilters, 'mutationKey'>) => MutationObserverOptions<
|
29
|
-
setMutationDefaults: (options: OmitKeyof<MutationObserverOptions<
|
23
|
+
getQueryDefaults: (filters?: Pick<ORPCQueryFilters<PartialDeep<TInput>>, 'input' | 'queryKey'>) => OmitKeyof<QueryObserverOptions<TOutput>, 'queryKey'>;
|
24
|
+
getInfiniteQueryDefaults: (filters?: Pick<ORPCQueryFilters<PartialDeep<SchemaInputForInfiniteQuery<TInput>>>, 'input' | 'queryKey'>) => OmitKeyof<QueryObserverOptions<TOutput, DefaultError, TOutput, InfiniteData<TOutput>, QueryKey, InferCursor<TInput>>, 'queryKey'>;
|
25
|
+
setQueryDefaults: (options: Partial<OmitKeyof<QueryObserverOptions<TOutput>, 'queryKey'>>, filters?: Pick<ORPCQueryFilters<PartialDeep<TInput>>, 'input' | 'queryKey'>) => void;
|
26
|
+
setInfiniteQueryDefaults: (options: Partial<OmitKeyof<QueryObserverOptions<TOutput, DefaultError, TOutput, InfiniteData<TOutput>, QueryKey, InferCursor<TInput>>, 'queryKey'>>, filters?: Pick<ORPCQueryFilters<PartialDeep<TInput>>, 'input' | 'queryKey'>) => void;
|
27
|
+
getMutationDefaults: (filters?: Pick<MutationFilters, 'mutationKey'>) => MutationObserverOptions<TOutput, DefaultError, TInput>;
|
28
|
+
setMutationDefaults: (options: OmitKeyof<MutationObserverOptions<TOutput, DefaultError, TInput>, 'mutationKey'>, filters?: Pick<MutationFilters, 'mutationKey'>) => void;
|
30
29
|
}
|
31
30
|
export interface CreateGeneralUtilsOptions {
|
32
31
|
queryClient: QueryClient;
|
@@ -37,4 +36,5 @@ export interface CreateGeneralUtilsOptions {
|
|
37
36
|
*/
|
38
37
|
path: string[];
|
39
38
|
}
|
40
|
-
export declare function createGeneralUtils<
|
39
|
+
export declare function createGeneralUtils<TInput, TOutput>(options: CreateGeneralUtilsOptions): GeneralUtils<TInput, TOutput>;
|
40
|
+
//# sourceMappingURL=general-utils.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/orpc-path.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import type { ProcedureHooks } from './procedure-hooks';
|
2
|
-
import type {
|
2
|
+
import type { ORPCHooks } from './react-hooks';
|
3
3
|
export declare const orpcPathSymbol: unique symbol;
|
4
|
-
export declare function getORPCPath(orpc:
|
4
|
+
export declare function getORPCPath(orpc: ORPCHooks<any> | ProcedureHooks<any, any>): string[];
|
5
|
+
//# sourceMappingURL=orpc-path.d.ts.map
|
@@ -1,22 +1,21 @@
|
|
1
|
-
import type {
|
2
|
-
import type { SchemaInputForInfiniteQuery } from './types';
|
1
|
+
import type { InferCursor, SchemaInputForInfiniteQuery } from './types';
|
3
2
|
import { type PartialOnUndefinedDeep, type SetOptional } from '@orpc/shared';
|
4
3
|
import { type DefaultError, type FetchInfiniteQueryOptions, type FetchQueryOptions, type InfiniteData, type QueryKey, type UseInfiniteQueryOptions, type UseInfiniteQueryResult, type UseMutationOptions, type UseMutationResult, type UseQueryOptions, type UseQueryResult, type UseSuspenseInfiniteQueryOptions, type UseSuspenseInfiniteQueryResult, type UseSuspenseQueryOptions, type UseSuspenseQueryResult } from '@tanstack/react-query';
|
5
4
|
import { type ORPCContext } from './react-context';
|
6
|
-
export interface ProcedureHooks<
|
7
|
-
useQuery: <USelectData =
|
8
|
-
useInfiniteQuery: <USelectData = InfiniteData<
|
9
|
-
input: SchemaInputForInfiniteQuery<
|
5
|
+
export interface ProcedureHooks<TInput, TOutput> {
|
6
|
+
useQuery: <USelectData = TOutput>(input: TInput, options?: SetOptional<UseQueryOptions<TOutput, DefaultError, USelectData>, 'queryFn' | 'queryKey'>) => UseQueryResult<USelectData>;
|
7
|
+
useInfiniteQuery: <USelectData = InfiniteData<TOutput, InferCursor<TInput>>>(options: PartialOnUndefinedDeep<SetOptional<UseInfiniteQueryOptions<TOutput, DefaultError, USelectData, TOutput, QueryKey, InferCursor<TInput>>, 'queryFn' | 'queryKey'> & {
|
8
|
+
input: SchemaInputForInfiniteQuery<TInput>;
|
10
9
|
}>) => UseInfiniteQueryResult<USelectData>;
|
11
|
-
useSuspenseQuery: <USelectData =
|
12
|
-
useSuspenseInfiniteQuery: <USelectData = InfiniteData<
|
13
|
-
input: SchemaInputForInfiniteQuery<
|
10
|
+
useSuspenseQuery: <USelectData = TOutput>(input: TInput, options?: SetOptional<UseSuspenseQueryOptions<TOutput, DefaultError, USelectData>, 'queryFn' | 'queryKey'>) => UseSuspenseQueryResult<USelectData>;
|
11
|
+
useSuspenseInfiniteQuery: <USelectData = InfiniteData<TOutput, InferCursor<TInput>>>(options: PartialOnUndefinedDeep<SetOptional<UseSuspenseInfiniteQueryOptions<TOutput, DefaultError, USelectData, TOutput, QueryKey, InferCursor<TInput>>, 'queryFn' | 'queryKey'> & {
|
12
|
+
input: SchemaInputForInfiniteQuery<TInput>;
|
14
13
|
}>) => UseSuspenseInfiniteQueryResult<USelectData>;
|
15
|
-
usePrefetchQuery: (input:
|
16
|
-
usePrefetchInfiniteQuery: (options: PartialOnUndefinedDeep<SetOptional<FetchInfiniteQueryOptions<
|
17
|
-
input: SchemaInputForInfiniteQuery<
|
14
|
+
usePrefetchQuery: (input: TInput, options?: FetchQueryOptions<TOutput>) => void;
|
15
|
+
usePrefetchInfiniteQuery: (options: PartialOnUndefinedDeep<SetOptional<FetchInfiniteQueryOptions<TOutput, DefaultError, TOutput, QueryKey, InferCursor<TInput>>, 'queryKey' | 'queryFn'> & {
|
16
|
+
input: SchemaInputForInfiniteQuery<TInput>;
|
18
17
|
}>) => void;
|
19
|
-
useMutation: (options?: SetOptional<UseMutationOptions<
|
18
|
+
useMutation: (options?: SetOptional<UseMutationOptions<TOutput, DefaultError, TInput>, 'mutationFn' | 'mutationKey'>) => UseMutationResult<TOutput, DefaultError, TInput>;
|
20
19
|
}
|
21
20
|
export interface CreateProcedureHooksOptions {
|
22
21
|
context: ORPCContext<any>;
|
@@ -27,4 +26,5 @@ export interface CreateProcedureHooksOptions {
|
|
27
26
|
*/
|
28
27
|
path: string[];
|
29
28
|
}
|
30
|
-
export declare function createProcedureHooks<
|
29
|
+
export declare function createProcedureHooks<TInput, TOutput>(options: CreateProcedureHooksOptions): ProcedureHooks<TInput, TOutput>;
|
30
|
+
//# sourceMappingURL=procedure-hooks.d.ts.map
|
@@ -1,34 +1,34 @@
|
|
1
|
-
import type { ProcedureClient } from '@orpc/
|
2
|
-
import type { Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { ProcedureClient } from '@orpc/server';
|
3
2
|
import type { PartialOnUndefinedDeep, SetOptional } from '@orpc/shared';
|
4
3
|
import type { DefaultError, EnsureInfiniteQueryDataOptions, EnsureQueryDataOptions, FetchInfiniteQueryOptions, FetchQueryOptions, InfiniteData, QueryClient, QueryKey, QueryState, SetDataOptions, Updater } from '@tanstack/react-query';
|
5
|
-
import type { SchemaInputForInfiniteQuery } from './types';
|
6
|
-
export interface ProcedureUtils<
|
7
|
-
fetchQuery: (input:
|
8
|
-
fetchInfiniteQuery: (options: PartialOnUndefinedDeep<SetOptional<FetchInfiniteQueryOptions<
|
9
|
-
input: SchemaInputForInfiniteQuery<
|
10
|
-
}>) => Promise<InfiniteData<
|
11
|
-
prefetchQuery: (input:
|
12
|
-
prefetchInfiniteQuery: (options: PartialOnUndefinedDeep<SetOptional<FetchInfiniteQueryOptions<
|
13
|
-
input: SchemaInputForInfiniteQuery<
|
4
|
+
import type { InferCursor, SchemaInputForInfiniteQuery } from './types';
|
5
|
+
export interface ProcedureUtils<TInput, TOutput> {
|
6
|
+
fetchQuery: (input: TInput, options?: SetOptional<FetchQueryOptions<TOutput>, 'queryKey' | 'queryFn'>) => Promise<TOutput>;
|
7
|
+
fetchInfiniteQuery: (options: PartialOnUndefinedDeep<SetOptional<FetchInfiniteQueryOptions<TOutput, DefaultError, TOutput, QueryKey, InferCursor<TInput>>, 'queryKey' | 'queryFn'> & {
|
8
|
+
input: SchemaInputForInfiniteQuery<TInput>;
|
9
|
+
}>) => Promise<InfiniteData<TOutput, InferCursor<TInput>>>;
|
10
|
+
prefetchQuery: (input: TInput, options?: SetOptional<FetchQueryOptions<TOutput>, 'queryKey' | 'queryFn'>) => Promise<void>;
|
11
|
+
prefetchInfiniteQuery: (options: PartialOnUndefinedDeep<SetOptional<FetchInfiniteQueryOptions<TOutput, DefaultError, TOutput, QueryKey, InferCursor<TInput>>, 'queryKey' | 'queryFn'> & {
|
12
|
+
input: SchemaInputForInfiniteQuery<TInput>;
|
14
13
|
}>) => Promise<void>;
|
15
|
-
getQueryData: (input:
|
16
|
-
getInfiniteQueryData: (input: SchemaInputForInfiniteQuery<
|
17
|
-
ensureQueryData: (input:
|
18
|
-
ensureInfiniteQueryData: (options: PartialOnUndefinedDeep<SetOptional<EnsureInfiniteQueryDataOptions<
|
19
|
-
input: SchemaInputForInfiniteQuery<
|
20
|
-
}>) => Promise<InfiniteData<
|
21
|
-
getQueryState: (input:
|
22
|
-
getInfiniteQueryState: (input: SchemaInputForInfiniteQuery<
|
23
|
-
setQueryData: (input:
|
24
|
-
setInfiniteQueryData: (input: SchemaInputForInfiniteQuery<
|
14
|
+
getQueryData: (input: TInput) => TOutput | undefined;
|
15
|
+
getInfiniteQueryData: (input: SchemaInputForInfiniteQuery<TInput>) => InfiniteData<TOutput, InferCursor<TInput>> | undefined;
|
16
|
+
ensureQueryData: (input: TInput, options?: SetOptional<EnsureQueryDataOptions<TOutput>, 'queryFn' | 'queryKey'>) => Promise<TOutput>;
|
17
|
+
ensureInfiniteQueryData: (options: PartialOnUndefinedDeep<SetOptional<EnsureInfiniteQueryDataOptions<TOutput, DefaultError, TOutput, QueryKey, InferCursor<TInput>>, 'queryKey' | 'queryFn'> & {
|
18
|
+
input: SchemaInputForInfiniteQuery<TInput>;
|
19
|
+
}>) => Promise<InfiniteData<TOutput, InferCursor<TInput>>>;
|
20
|
+
getQueryState: (input: TInput) => QueryState<TOutput> | undefined;
|
21
|
+
getInfiniteQueryState: (input: SchemaInputForInfiniteQuery<TInput>) => QueryState<InfiniteData<TOutput, InferCursor<TInput>>> | undefined;
|
22
|
+
setQueryData: (input: TInput, updater: Updater<TOutput | undefined, TOutput | undefined>, options?: SetDataOptions) => TOutput | undefined;
|
23
|
+
setInfiniteQueryData: (input: SchemaInputForInfiniteQuery<TInput>, updater: Updater<InfiniteData<TOutput, InferCursor<TInput>> | undefined, InfiniteData<TOutput, InferCursor<TInput>> | undefined>, options?: SetDataOptions) => InfiniteData<TOutput, InferCursor<TInput>> | undefined;
|
25
24
|
}
|
26
|
-
export interface CreateProcedureUtilsOptions<
|
27
|
-
client: ProcedureClient<
|
25
|
+
export interface CreateProcedureUtilsOptions<TInput, TOutput> {
|
26
|
+
client: ProcedureClient<TInput, TOutput, any>;
|
28
27
|
queryClient: QueryClient;
|
29
28
|
/**
|
30
29
|
* The path of procedure on sever
|
31
30
|
*/
|
32
31
|
path: string[];
|
33
32
|
}
|
34
|
-
export declare function createProcedureUtils<
|
33
|
+
export declare function createProcedureUtils<TInput, TOutput>(options: CreateProcedureUtilsOptions<TInput, TOutput>): ProcedureUtils<TInput, TOutput>;
|
34
|
+
//# sourceMappingURL=procedure-utils.d.ts.map
|
@@ -1,12 +1,11 @@
|
|
1
|
-
import type {
|
2
|
-
import type { ContractRouter } from '@orpc/contract';
|
3
|
-
import type { Router } from '@orpc/server';
|
1
|
+
import type { RouterClient } from '@orpc/server';
|
4
2
|
import type { QueryClient } from '@tanstack/react-query';
|
5
3
|
import { type Context } from 'react';
|
6
|
-
export interface ORPCContextValue<
|
7
|
-
client:
|
4
|
+
export interface ORPCContextValue<T extends RouterClient<any, any>> {
|
5
|
+
client: T;
|
8
6
|
queryClient: QueryClient;
|
9
7
|
}
|
10
|
-
export type ORPCContext<
|
11
|
-
export declare function createORPCContext<
|
12
|
-
export declare function useORPCContext<
|
8
|
+
export type ORPCContext<T extends RouterClient<any, any>> = Context<ORPCContextValue<T> | undefined>;
|
9
|
+
export declare function createORPCContext<T extends RouterClient<any, any>>(): ORPCContext<T>;
|
10
|
+
export declare function useORPCContext<T extends RouterClient<any, any>>(context: ORPCContext<T>): ORPCContextValue<T>;
|
11
|
+
//# sourceMappingURL=react-context.d.ts.map
|
@@ -1,16 +1,12 @@
|
|
1
|
-
import type {
|
2
|
-
import type { Procedure, Router } from '@orpc/server';
|
1
|
+
import type { ProcedureClient, RouterClient } from '@orpc/server';
|
3
2
|
import type { ORPCContext } from './react-context';
|
4
3
|
import { type GeneralHooks } from './general-hooks';
|
5
4
|
import { type ProcedureHooks } from './procedure-hooks';
|
6
|
-
export type
|
7
|
-
[K in keyof
|
8
|
-
} & GeneralHooks<
|
9
|
-
export
|
10
|
-
|
11
|
-
} & GeneralHooks<undefined, undefined, unknown>;
|
12
|
-
export interface CreateORPCHooksOptions<TRouter extends ContractRouter | Router<any>> {
|
13
|
-
context: ORPCContext<TRouter>;
|
5
|
+
export type ORPCHooks<T extends RouterClient<any, any>> = T extends ProcedureClient<infer TInput, infer TOutput, any> ? ProcedureHooks<TInput, TOutput> & GeneralHooks<TInput, TOutput> : {
|
6
|
+
[K in keyof T]: T[K] extends RouterClient<any, any> ? ORPCHooks<T[K]> : never;
|
7
|
+
} & GeneralHooks<unknown, unknown>;
|
8
|
+
export interface CreateORPCHooksOptions<T extends RouterClient<any, any>> {
|
9
|
+
context: ORPCContext<T>;
|
14
10
|
/**
|
15
11
|
* The path of the router.
|
16
12
|
*
|
@@ -18,4 +14,5 @@ export interface CreateORPCHooksOptions<TRouter extends ContractRouter | Router<
|
|
18
14
|
*/
|
19
15
|
path?: string[];
|
20
16
|
}
|
21
|
-
export declare function createORPCHooks<
|
17
|
+
export declare function createORPCHooks<T extends RouterClient<any, any>>(options: CreateORPCHooksOptions<T>): ORPCHooks<T>;
|
18
|
+
//# sourceMappingURL=react-hooks.d.ts.map
|
@@ -1,16 +1,12 @@
|
|
1
|
-
import type {
|
2
|
-
import type { Procedure, Router } from '@orpc/server';
|
1
|
+
import type { ProcedureClient, RouterClient } from '@orpc/server';
|
3
2
|
import type { ORPCContextValue } from './react-context';
|
4
3
|
import { type GeneralUtils } from './general-utils';
|
5
4
|
import { type ProcedureUtils } from './procedure-utils';
|
6
|
-
export type
|
7
|
-
[K in keyof
|
8
|
-
} & GeneralUtils<
|
9
|
-
export
|
10
|
-
|
11
|
-
} & GeneralUtils<undefined, undefined, unknown>;
|
12
|
-
export interface CreateORPCUtilsOptions<TRouter extends ContractRouter | Router<any>> {
|
13
|
-
contextValue: ORPCContextValue<TRouter>;
|
5
|
+
export type ORPCUtils<T extends RouterClient<any, any>> = T extends ProcedureClient<infer TInput, infer TOutput, any> ? ProcedureUtils<TInput, TOutput> & GeneralUtils<TInput, TOutput> : {
|
6
|
+
[K in keyof T]: T[K] extends RouterClient<any, any> ? ORPCUtils<T[K]> : never;
|
7
|
+
} & GeneralUtils<unknown, unknown>;
|
8
|
+
export interface CreateORPCUtilsOptions<T extends RouterClient<any, any>> {
|
9
|
+
contextValue: ORPCContextValue<T>;
|
14
10
|
/**
|
15
11
|
* The path of the router.
|
16
12
|
*
|
@@ -18,4 +14,5 @@ export interface CreateORPCUtilsOptions<TRouter extends ContractRouter | Router<
|
|
18
14
|
*/
|
19
15
|
path?: string[];
|
20
16
|
}
|
21
|
-
export declare function createORPCUtils<
|
17
|
+
export declare function createORPCUtils<T extends RouterClient<any, any>>(options: CreateORPCUtilsOptions<T>): ORPCUtils<T>;
|
18
|
+
//# sourceMappingURL=react-utils.d.ts.map
|
package/dist/src/react.d.ts
CHANGED
@@ -1,20 +1,15 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
3
|
-
import
|
4
|
-
import
|
5
|
-
import
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
useQueries: UseQueriesWithContractRouter<TRouter>;
|
1
|
+
import type { RouterClient } from '@orpc/server';
|
2
|
+
import type { ORPCContext, ORPCContextValue } from './react-context';
|
3
|
+
import type { ORPCHooks } from './react-hooks';
|
4
|
+
import type { ORPCUtils } from './react-utils';
|
5
|
+
import type { UseQueries } from './use-queries/hook';
|
6
|
+
export type ORPCReact<T extends RouterClient<any, any>> = ORPCHooks<T> & {
|
7
|
+
useContext: () => ORPCContextValue<T>;
|
8
|
+
useUtils: () => ORPCUtils<T>;
|
9
|
+
useQueries: UseQueries<T>;
|
11
10
|
};
|
12
|
-
export
|
13
|
-
|
14
|
-
|
15
|
-
useQueries: UseQueriesWithRouter<TRouter>;
|
16
|
-
};
|
17
|
-
export declare function createORPCReact<TRouter extends ContractRouter | Router<any>>(): {
|
18
|
-
orpc: TRouter extends Router<any> ? ORPCReactWithRouter<TRouter> : TRouter extends ContractRouter ? ORPCReactWithContractRouter<TRouter> : never;
|
19
|
-
ORPCContext: ORPCContext<TRouter>;
|
11
|
+
export declare function createORPCReact<T extends RouterClient<any, any>>(): {
|
12
|
+
orpc: ORPCReact<T>;
|
13
|
+
ORPCContext: ORPCContext<T>;
|
20
14
|
};
|
15
|
+
//# sourceMappingURL=react.d.ts.map
|
@@ -1,14 +1,14 @@
|
|
1
|
-
import type { SchemaInput } from '@orpc/contract';
|
2
1
|
import type { PartialDeep } from '@orpc/shared';
|
3
2
|
import type { MutationKey, QueryKey } from '@tanstack/react-query';
|
4
3
|
import type { ProcedureHooks } from './procedure-hooks';
|
5
|
-
import type {
|
4
|
+
import type { ORPCHooks } from './react-hooks';
|
6
5
|
export type QueryType = 'query' | 'infinite' | undefined;
|
7
6
|
export interface GetQueryKeyOptions<TInput> {
|
8
7
|
input?: TInput;
|
9
8
|
type?: QueryType;
|
10
9
|
}
|
11
|
-
export declare function getQueryKey<T extends
|
10
|
+
export declare function getQueryKey<T extends ORPCHooks<any> | ProcedureHooks<any, any>>(orpc: T, options?: GetQueryKeyOptions<T extends ProcedureHooks<infer UInput, any> ? PartialDeep<UInput> : unknown>): QueryKey;
|
12
11
|
export declare function getQueryKeyFromPath(path: string[], options?: GetQueryKeyOptions<unknown>): QueryKey;
|
13
|
-
export declare function getMutationKey<T extends
|
12
|
+
export declare function getMutationKey<T extends ORPCHooks<any> | ProcedureHooks<any, any>>(orpc: T): MutationKey;
|
14
13
|
export declare function getMutationKeyFromPath(path: string[]): MutationKey;
|
14
|
+
//# sourceMappingURL=tanstack-key.d.ts.map
|
@@ -16,3 +16,4 @@ export interface ORPCQueryFilters<TFilterInput> extends SetOptional<QueryFilters
|
|
16
16
|
}
|
17
17
|
export interface ORPCInvalidateQueryFilters<TFilterInput> extends SetOptional<InvalidateQueryFilters, 'queryKey'>, ORPCAdditionalQueryFilters<TFilterInput> {
|
18
18
|
}
|
19
|
+
//# sourceMappingURL=tanstack-query.d.ts.map
|
package/dist/src/types.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
2
|
-
export type
|
3
|
-
cursor?:
|
4
|
-
}
|
1
|
+
export type SchemaInputForInfiniteQuery<TInput> = Omit<TInput, 'cursor'>;
|
2
|
+
export type InferCursor<TInput> = TInput extends {
|
3
|
+
cursor?: any;
|
4
|
+
} ? TInput['cursor'] : never;
|
5
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -1,19 +1,19 @@
|
|
1
|
-
import type { ProcedureClient } from '@orpc/
|
2
|
-
import type { Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { ProcedureClient } from '@orpc/server';
|
3
2
|
import type { SetOptional } from '@orpc/shared';
|
4
3
|
import type { DefaultError, OmitKeyof, QueriesPlaceholderDataFunction, QueryKey, UseQueryOptions } from '@tanstack/react-query';
|
5
4
|
type UseQueryOptionsForUseQueries<TQueryFnData, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = OmitKeyof<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'placeholderData'> & {
|
6
5
|
placeholderData?: TQueryFnData | QueriesPlaceholderDataFunction<TQueryFnData>;
|
7
6
|
};
|
8
|
-
export interface UseQueriesBuilder<
|
9
|
-
(input:
|
7
|
+
export interface UseQueriesBuilder<TInput, TOutput> {
|
8
|
+
(input: TInput, options?: SetOptional<UseQueryOptionsForUseQueries<TOutput>, 'queryFn' | 'queryKey'>): UseQueryOptionsForUseQueries<TOutput>;
|
10
9
|
}
|
11
|
-
export interface CreateUseQueriesBuilderOptions<
|
12
|
-
client: ProcedureClient<
|
10
|
+
export interface CreateUseQueriesBuilderOptions<TInput, TOutput> {
|
11
|
+
client: ProcedureClient<TInput, TOutput, any>;
|
13
12
|
/**
|
14
13
|
* The path of procedure on server
|
15
14
|
*/
|
16
15
|
path: string[];
|
17
16
|
}
|
18
|
-
export declare function createUseQueriesBuilder<
|
17
|
+
export declare function createUseQueriesBuilder<TInput, TOutput>(options: CreateUseQueriesBuilderOptions<TInput, TOutput>): UseQueriesBuilder<TInput, TOutput>;
|
19
18
|
export {};
|
19
|
+
//# sourceMappingURL=builder.d.ts.map
|
@@ -1,18 +1,14 @@
|
|
1
|
-
import type {
|
2
|
-
import type { ContractProcedure, ContractRouter, SchemaOutput } from '@orpc/contract';
|
3
|
-
import type { Procedure, Router } from '@orpc/server';
|
1
|
+
import type { ProcedureClient, RouterClient } from '@orpc/server';
|
4
2
|
import { type UseQueriesBuilder } from './builder';
|
5
|
-
export type
|
6
|
-
[K in keyof
|
3
|
+
export type UseQueriesBuilders<T extends RouterClient<any, any>> = T extends ProcedureClient<infer UInput, infer UOutput, any> ? UseQueriesBuilder<UInput, UOutput> : {
|
4
|
+
[K in keyof T]: T[K] extends RouterClient<any, any> ? UseQueriesBuilders<T[K]> : never;
|
7
5
|
};
|
8
|
-
export
|
9
|
-
|
10
|
-
};
|
11
|
-
export interface CreateUseQueriesBuildersOptions<TRouter extends Router<any> | ContractRouter> {
|
12
|
-
client: TRouter extends Router<any> ? RouterClientWithRouter<TRouter> : TRouter extends ContractRouter ? RouterClientWithContractRouter<TRouter> : never;
|
6
|
+
export interface CreateUseQueriesBuildersOptions<T extends RouterClient<any, any>> {
|
7
|
+
client: T;
|
13
8
|
/**
|
14
9
|
* The path of router on server
|
15
10
|
*/
|
16
11
|
path?: string[];
|
17
12
|
}
|
18
|
-
export declare function createUseQueriesBuilders<
|
13
|
+
export declare function createUseQueriesBuilders<T extends RouterClient<any, any>>(options: CreateUseQueriesBuildersOptions<T>): UseQueriesBuilders<T>;
|
14
|
+
//# sourceMappingURL=builders.d.ts.map
|
@@ -1,15 +1,12 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
3
|
-
import
|
4
|
-
import {
|
5
|
-
|
6
|
-
|
7
|
-
<T extends Array<any> = [], TCombinedResult = QueriesResults<T>>(build: (builders: UseQueriesBuildersWithContractRouter<TRouter>) => [...QueriesOptions<T>], combine?: (result: QueriesResults<T>) => TCombinedResult): TCombinedResult;
|
1
|
+
import type { RouterClient } from '@orpc/server';
|
2
|
+
import type { QueriesOptions, QueriesResults } from '@tanstack/react-query';
|
3
|
+
import type { ORPCContext } from '../react-context';
|
4
|
+
import type { UseQueriesBuilders } from './builders';
|
5
|
+
export interface UseQueries<T extends RouterClient<any, any>> {
|
6
|
+
<U extends Array<any> = [], UCombinedResult = QueriesResults<U>>(build: (builders: UseQueriesBuilders<T>) => [...QueriesOptions<U>], combine?: (result: QueriesResults<U>) => UCombinedResult): UCombinedResult;
|
8
7
|
}
|
9
|
-
export interface
|
10
|
-
|
8
|
+
export interface UseQueriesFactoryOptions<T extends RouterClient<any, any>> {
|
9
|
+
context: ORPCContext<T>;
|
11
10
|
}
|
12
|
-
export
|
13
|
-
|
14
|
-
}
|
15
|
-
export declare function useQueriesFactory<TRouter extends Router<any> | ContractRouter>(options: UseQueriesFactoryOptions<TRouter>): TRouter extends Router<any> ? UseQueriesWithRouter<TRouter> : TRouter extends ContractRouter ? UseQueriesWithContractRouter<TRouter> : never;
|
11
|
+
export declare function useQueriesFactory<T extends RouterClient<any, any>>(options: UseQueriesFactoryOptions<T>): UseQueries<T>;
|
12
|
+
//# sourceMappingURL=hook.d.ts.map
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/react",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.0-next.
|
4
|
+
"version": "0.0.0-next.fd1db03",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -24,24 +24,25 @@
|
|
24
24
|
}
|
25
25
|
},
|
26
26
|
"files": [
|
27
|
-
"
|
27
|
+
"!**/*.map",
|
28
|
+
"!**/*.tsbuildinfo",
|
28
29
|
"dist"
|
29
30
|
],
|
30
31
|
"peerDependencies": {
|
31
|
-
"@tanstack/react-query": ">=5.
|
32
|
+
"@tanstack/react-query": ">=5.55.0",
|
32
33
|
"react": ">=18.3.0",
|
33
|
-
"@orpc/
|
34
|
-
"@orpc/server": "0.0.0-next.
|
35
|
-
"@orpc/
|
34
|
+
"@orpc/client": "0.0.0-next.fd1db03",
|
35
|
+
"@orpc/server": "0.0.0-next.fd1db03",
|
36
|
+
"@orpc/contract": "0.0.0-next.fd1db03"
|
36
37
|
},
|
37
38
|
"dependencies": {
|
38
|
-
"@orpc/shared": "0.0.0-next.
|
39
|
+
"@orpc/shared": "0.0.0-next.fd1db03"
|
39
40
|
},
|
40
41
|
"devDependencies": {
|
41
|
-
"zod": "^3.
|
42
|
+
"zod": "^3.24.1"
|
42
43
|
},
|
43
44
|
"scripts": {
|
44
|
-
"build": "tsup --clean --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|
45
|
+
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|
45
46
|
"build:watch": "pnpm run build --watch",
|
46
47
|
"type:check": "tsc -b"
|
47
48
|
}
|