@orpc/tanstack-query 0.0.0-next.fd6982a → 0.0.1

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.d.mts CHANGED
@@ -1,13 +1,133 @@
1
- import { PartialDeep } from '@orpc/shared';
2
- import { QueryKey } from '@tanstack/query-core';
1
+ import { OperationType as OperationType$1, OperationKeyOptions as OperationKeyOptions$1, OperationKey as OperationKey$1 } from '@orpc/tanstack-query';
2
+ import { ClientContext, Client, NestedClient } from '@orpc/client';
3
+ import { SetOptional, PartialDeep, MaybeOptionalOptions } from '@orpc/shared';
4
+ import { SkipToken, QueryObserverOptions, QueryKey, QueryFunction, experimental_streamedQuery, InfiniteQueryObserverOptions, InfiniteData, MutationObserverOptions } from '@tanstack/query-core';
3
5
 
4
- type OperationType = 'query' | 'streamed' | 'infinite' | 'mutation';
6
+ /**
7
+ * Utils at any level (procedure or router)
8
+ */
9
+ interface GeneralUtils<TInput> {
10
+ /**
11
+ * Generate a query/mutation key for checking status, invalidate, set, get, etc.
12
+ *
13
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
14
+ */
15
+ key<TType extends OperationType$1>(options?: OperationKeyOptions$1<TType, TInput>): OperationKey$1<TType, TInput>;
16
+ }
17
+ declare function createGeneralUtils<TInput>(path: readonly string[]): GeneralUtils<TInput>;
5
18
 
6
- interface BuildKeyOptions<TType extends OperationType, TInput> {
19
+ type experimental_StreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
20
+ type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
21
+ type OperationType = 'query' | 'streamed' | 'infinite' | 'mutation';
22
+ type OperationKeyOptions<TType extends OperationType, TInput> = {
7
23
  type?: TType;
8
24
  input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
25
+ fnOptions?: TType extends 'streamed' ? experimental_StreamedQueryOptions : never;
26
+ };
27
+ type OperationKey<TType extends OperationType, TInput> = [path: readonly string[], options: OperationKeyOptions<TType, TInput>];
28
+ declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
29
+ interface OperationContext {
30
+ [OPERATION_CONTEXT_SYMBOL]?: {
31
+ key: QueryKey;
32
+ type: OperationType;
33
+ };
34
+ }
35
+ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
36
+ input?: TInput | SkipToken;
37
+ } : {
38
+ input: TInput | SkipToken;
39
+ }) & (Record<never, never> extends TClientContext ? {
40
+ context?: TClientContext;
41
+ } : {
42
+ context: TClientContext;
43
+ }) & SetOptional<QueryObserverOptions<TOutput, TError, TSelectData>, 'queryKey'>;
44
+ interface QueryOptionsBase<TOutput, TError> {
45
+ queryKey: QueryKey;
46
+ queryFn: QueryFunction<TOutput>;
47
+ throwOnError?: (error: TError) => boolean;
48
+ retryDelay?: (count: number, error: TError) => number;
49
+ enabled: boolean;
50
+ }
51
+ type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & {
52
+ queryFnOptions?: experimental_StreamedQueryOptions;
53
+ };
54
+ interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
55
+ }
56
+ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = {
57
+ input: ((pageParam: TPageParam) => TInput) | SkipToken;
58
+ } & (Record<never, never> extends TClientContext ? {
59
+ context?: TClientContext;
60
+ } : {
61
+ context: TClientContext;
62
+ }) & SetOptional<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey'>;
63
+ interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
64
+ queryKey: QueryKey;
65
+ queryFn: QueryFunction<TOutput, QueryKey, TPageParam>;
66
+ select?(): InfiniteData<TOutput, TPageParam>;
67
+ throwOnError?: (error: TError) => boolean;
68
+ retryDelay?: (count: number, error: TError) => number;
69
+ enabled: boolean;
70
+ }
71
+ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
72
+ context?: TClientContext;
73
+ } : {
74
+ context: TClientContext;
75
+ }) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
76
+ type MutationOptions<TInput, TOutput, TError, TMutationContext> = MutationObserverOptions<TOutput, TError, TInput, TMutationContext>;
77
+
78
+ declare function generateOperationKey<TType extends OperationType, TInput>(path: readonly string[], state?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
79
+
80
+ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
81
+ /**
82
+ * Calling corresponding procedure client
83
+ *
84
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
85
+ */
86
+ call: Client<TClientContext, TInput, TOutput, TError>;
87
+ /**
88
+ * Generate options used for useQuery/useSuspenseQuery/prefetchQuery/...
89
+ *
90
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-options-utility Tanstack Query Options Utility Docs}
91
+ */
92
+ queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
93
+ /**
94
+ * Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/useSuspenseQuery/prefetchQuery/...
95
+ * Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
96
+ *
97
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
98
+ */
99
+ experimental_streamedOptions<U, USelectData = experimental_StreamedQueryOutput<TOutput>>(...rest: MaybeOptionalOptions<U & experimental_StreamedOptionsIn<TClientContext, TInput, experimental_StreamedQueryOutput<TOutput>, TError, USelectData>>): NoInfer<U & Omit<experimental_StreamedOptionsBase<experimental_StreamedQueryOutput<TOutput>, TError>, keyof U>>;
100
+ /**
101
+ * Generate options used for useInfiniteQuery/useSuspenseInfiniteQuery/prefetchInfiniteQuery/...
102
+ *
103
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
104
+ */
105
+ 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>>;
106
+ /**
107
+ * Generate options used for useMutation/...
108
+ *
109
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#mutation-options Tanstack Mutation Options Docs}
110
+ */
111
+ mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptions<TInput, TOutput, TError, UMutationContext>>;
112
+ }
113
+ interface CreateProcedureUtilsOptions {
114
+ path: readonly string[];
115
+ }
116
+ declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
117
+
118
+ type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
119
+ [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
120
+ } & GeneralUtils<unknown>;
121
+ interface CreateRouterUtilsOptions {
122
+ path?: readonly string[];
9
123
  }
10
- declare function buildKey<TType extends OperationType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
124
+ /**
125
+ * Create a router utils from a client.
126
+ *
127
+ * @info Both client-side and server-side clients are supported.
128
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query Tanstack Query Integration}
129
+ */
130
+ declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
11
131
 
12
- export { buildKey };
13
- export type { BuildKeyOptions, OperationType };
132
+ export { OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createGeneralUtils, createProcedureUtils, createRouterUtils, createRouterUtils as createTanstackQueryUtils, generateOperationKey };
133
+ export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, OperationContext, OperationKey, OperationKeyOptions, OperationType, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, OperationContext as TanstackQueryOperationContext, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn, experimental_StreamedQueryOutput };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,133 @@
1
- import { PartialDeep } from '@orpc/shared';
2
- import { QueryKey } from '@tanstack/query-core';
1
+ import { OperationType as OperationType$1, OperationKeyOptions as OperationKeyOptions$1, OperationKey as OperationKey$1 } from '@orpc/tanstack-query';
2
+ import { ClientContext, Client, NestedClient } from '@orpc/client';
3
+ import { SetOptional, PartialDeep, MaybeOptionalOptions } from '@orpc/shared';
4
+ import { SkipToken, QueryObserverOptions, QueryKey, QueryFunction, experimental_streamedQuery, InfiniteQueryObserverOptions, InfiniteData, MutationObserverOptions } from '@tanstack/query-core';
3
5
 
4
- type OperationType = 'query' | 'streamed' | 'infinite' | 'mutation';
6
+ /**
7
+ * Utils at any level (procedure or router)
8
+ */
9
+ interface GeneralUtils<TInput> {
10
+ /**
11
+ * Generate a query/mutation key for checking status, invalidate, set, get, etc.
12
+ *
13
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
14
+ */
15
+ key<TType extends OperationType$1>(options?: OperationKeyOptions$1<TType, TInput>): OperationKey$1<TType, TInput>;
16
+ }
17
+ declare function createGeneralUtils<TInput>(path: readonly string[]): GeneralUtils<TInput>;
5
18
 
6
- interface BuildKeyOptions<TType extends OperationType, TInput> {
19
+ type experimental_StreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
20
+ type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
21
+ type OperationType = 'query' | 'streamed' | 'infinite' | 'mutation';
22
+ type OperationKeyOptions<TType extends OperationType, TInput> = {
7
23
  type?: TType;
8
24
  input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
25
+ fnOptions?: TType extends 'streamed' ? experimental_StreamedQueryOptions : never;
26
+ };
27
+ type OperationKey<TType extends OperationType, TInput> = [path: readonly string[], options: OperationKeyOptions<TType, TInput>];
28
+ declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
29
+ interface OperationContext {
30
+ [OPERATION_CONTEXT_SYMBOL]?: {
31
+ key: QueryKey;
32
+ type: OperationType;
33
+ };
34
+ }
35
+ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
36
+ input?: TInput | SkipToken;
37
+ } : {
38
+ input: TInput | SkipToken;
39
+ }) & (Record<never, never> extends TClientContext ? {
40
+ context?: TClientContext;
41
+ } : {
42
+ context: TClientContext;
43
+ }) & SetOptional<QueryObserverOptions<TOutput, TError, TSelectData>, 'queryKey'>;
44
+ interface QueryOptionsBase<TOutput, TError> {
45
+ queryKey: QueryKey;
46
+ queryFn: QueryFunction<TOutput>;
47
+ throwOnError?: (error: TError) => boolean;
48
+ retryDelay?: (count: number, error: TError) => number;
49
+ enabled: boolean;
50
+ }
51
+ type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & {
52
+ queryFnOptions?: experimental_StreamedQueryOptions;
53
+ };
54
+ interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
55
+ }
56
+ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = {
57
+ input: ((pageParam: TPageParam) => TInput) | SkipToken;
58
+ } & (Record<never, never> extends TClientContext ? {
59
+ context?: TClientContext;
60
+ } : {
61
+ context: TClientContext;
62
+ }) & SetOptional<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey'>;
63
+ interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
64
+ queryKey: QueryKey;
65
+ queryFn: QueryFunction<TOutput, QueryKey, TPageParam>;
66
+ select?(): InfiniteData<TOutput, TPageParam>;
67
+ throwOnError?: (error: TError) => boolean;
68
+ retryDelay?: (count: number, error: TError) => number;
69
+ enabled: boolean;
70
+ }
71
+ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
72
+ context?: TClientContext;
73
+ } : {
74
+ context: TClientContext;
75
+ }) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
76
+ type MutationOptions<TInput, TOutput, TError, TMutationContext> = MutationObserverOptions<TOutput, TError, TInput, TMutationContext>;
77
+
78
+ declare function generateOperationKey<TType extends OperationType, TInput>(path: readonly string[], state?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
79
+
80
+ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
81
+ /**
82
+ * Calling corresponding procedure client
83
+ *
84
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
85
+ */
86
+ call: Client<TClientContext, TInput, TOutput, TError>;
87
+ /**
88
+ * Generate options used for useQuery/useSuspenseQuery/prefetchQuery/...
89
+ *
90
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-options-utility Tanstack Query Options Utility Docs}
91
+ */
92
+ queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
93
+ /**
94
+ * Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/useSuspenseQuery/prefetchQuery/...
95
+ * Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
96
+ *
97
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
98
+ */
99
+ experimental_streamedOptions<U, USelectData = experimental_StreamedQueryOutput<TOutput>>(...rest: MaybeOptionalOptions<U & experimental_StreamedOptionsIn<TClientContext, TInput, experimental_StreamedQueryOutput<TOutput>, TError, USelectData>>): NoInfer<U & Omit<experimental_StreamedOptionsBase<experimental_StreamedQueryOutput<TOutput>, TError>, keyof U>>;
100
+ /**
101
+ * Generate options used for useInfiniteQuery/useSuspenseInfiniteQuery/prefetchInfiniteQuery/...
102
+ *
103
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
104
+ */
105
+ 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>>;
106
+ /**
107
+ * Generate options used for useMutation/...
108
+ *
109
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#mutation-options Tanstack Mutation Options Docs}
110
+ */
111
+ mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptions<TInput, TOutput, TError, UMutationContext>>;
112
+ }
113
+ interface CreateProcedureUtilsOptions {
114
+ path: readonly string[];
115
+ }
116
+ declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
117
+
118
+ type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
119
+ [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
120
+ } & GeneralUtils<unknown>;
121
+ interface CreateRouterUtilsOptions {
122
+ path?: readonly string[];
9
123
  }
10
- declare function buildKey<TType extends OperationType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
124
+ /**
125
+ * Create a router utils from a client.
126
+ *
127
+ * @info Both client-side and server-side clients are supported.
128
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query Tanstack Query Integration}
129
+ */
130
+ declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
11
131
 
12
- export { buildKey };
13
- export type { BuildKeyOptions, OperationType };
132
+ export { OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createGeneralUtils, createProcedureUtils, createRouterUtils, createRouterUtils as createTanstackQueryUtils, generateOperationKey };
133
+ export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, OperationContext, OperationKey, OperationKeyOptions, OperationType, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, OperationContext as TanstackQueryOperationContext, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn, experimental_StreamedQueryOutput };
package/dist/index.mjs CHANGED
@@ -1,10 +1,151 @@
1
- function buildKey(path, options = {}) {
2
- const withInput = options.input !== void 0 ? { input: options?.input } : {};
3
- const withType = options.type !== void 0 ? { type: options?.type } : {};
1
+ import { generateOperationKey as generateOperationKey$1 } from '@orpc/tanstack-query';
2
+ import { isAsyncIteratorObject, toArray } from '@orpc/shared';
3
+ import { skipToken, experimental_streamedQuery } from '@tanstack/query-core';
4
+
5
+ function createGeneralUtils(path) {
6
+ return {
7
+ key(options) {
8
+ return generateOperationKey$1(path, options);
9
+ }
10
+ };
11
+ }
12
+
13
+ function generateOperationKey(path, state = {}) {
4
14
  return [path, {
5
- ...withInput,
6
- ...withType
15
+ ...state.input !== void 0 ? { input: state.input } : {},
16
+ ...state.type !== void 0 ? { type: state.type } : {},
17
+ ...state.fnOptions !== void 0 ? { fnOptions: state.fnOptions } : {}
7
18
  }];
8
19
  }
9
20
 
10
- export { buildKey };
21
+ const OPERATION_CONTEXT_SYMBOL = Symbol("ORPC_OPERATION_CONTEXT");
22
+
23
+ function createProcedureUtils(client, options) {
24
+ return {
25
+ call: client,
26
+ queryOptions(...[optionsIn = {}]) {
27
+ const queryKey = optionsIn.queryKey ?? generateOperationKey(options.path, { type: "query", input: optionsIn.input });
28
+ return {
29
+ queryFn: ({ signal }) => {
30
+ if (optionsIn.input === skipToken) {
31
+ throw new Error("queryFn should not be called with skipToken used as input");
32
+ }
33
+ return client(optionsIn.input, {
34
+ signal,
35
+ context: {
36
+ [OPERATION_CONTEXT_SYMBOL]: {
37
+ key: queryKey,
38
+ type: "query"
39
+ },
40
+ ...optionsIn.context
41
+ }
42
+ });
43
+ },
44
+ enabled: optionsIn.input !== skipToken,
45
+ ...optionsIn,
46
+ queryKey
47
+ };
48
+ },
49
+ experimental_streamedOptions(...[optionsIn = {}]) {
50
+ const queryKey = optionsIn.queryKey ?? generateOperationKey(options.path, { type: "streamed", input: optionsIn.input, fnOptions: optionsIn.queryFnOptions });
51
+ return {
52
+ enabled: optionsIn.input !== skipToken,
53
+ queryFn: experimental_streamedQuery({
54
+ queryFn: async ({ signal }) => {
55
+ if (optionsIn.input === skipToken) {
56
+ throw new Error("queryFn should not be called with skipToken used as input");
57
+ }
58
+ const output = await client(optionsIn.input, {
59
+ signal,
60
+ context: {
61
+ [OPERATION_CONTEXT_SYMBOL]: {
62
+ key: queryKey,
63
+ type: "streamed"
64
+ },
65
+ ...optionsIn.context
66
+ }
67
+ });
68
+ if (!isAsyncIteratorObject(output)) {
69
+ throw new Error("streamedQuery requires an event iterator output");
70
+ }
71
+ return output;
72
+ },
73
+ ...optionsIn.queryFnOptions
74
+ }),
75
+ ...optionsIn,
76
+ queryKey
77
+ };
78
+ },
79
+ infiniteOptions(optionsIn) {
80
+ const queryKey = optionsIn.queryKey ?? generateOperationKey(options.path, {
81
+ type: "infinite",
82
+ input: optionsIn.input === skipToken ? skipToken : optionsIn.input(optionsIn.initialPageParam)
83
+ });
84
+ return {
85
+ queryFn: ({ pageParam, signal }) => {
86
+ if (optionsIn.input === skipToken) {
87
+ throw new Error("queryFn should not be called with skipToken used as input");
88
+ }
89
+ return client(optionsIn.input(pageParam), {
90
+ signal,
91
+ context: {
92
+ [OPERATION_CONTEXT_SYMBOL]: {
93
+ key: queryKey,
94
+ type: "infinite"
95
+ },
96
+ ...optionsIn.context
97
+ }
98
+ });
99
+ },
100
+ enabled: optionsIn.input !== skipToken,
101
+ ...optionsIn,
102
+ queryKey
103
+ };
104
+ },
105
+ mutationOptions(...[optionsIn = {}]) {
106
+ const mutationKey = optionsIn.mutationKey ?? generateOperationKey(options.path, { type: "mutation" });
107
+ return {
108
+ mutationFn: (input) => client(input, {
109
+ context: {
110
+ [OPERATION_CONTEXT_SYMBOL]: {
111
+ key: mutationKey,
112
+ type: "mutation"
113
+ },
114
+ ...optionsIn.context
115
+ }
116
+ }),
117
+ ...optionsIn,
118
+ mutationKey
119
+ };
120
+ }
121
+ };
122
+ }
123
+
124
+ function createRouterUtils(client, options = {}) {
125
+ const path = toArray(options.path);
126
+ const generalUtils = createGeneralUtils(path);
127
+ const procedureUtils = createProcedureUtils(client, { path });
128
+ const recursive = new Proxy({
129
+ ...generalUtils,
130
+ ...procedureUtils
131
+ }, {
132
+ get(target, prop) {
133
+ const value = Reflect.get(target, prop);
134
+ if (typeof prop !== "string") {
135
+ return value;
136
+ }
137
+ const nextUtils = createRouterUtils(client[prop], { ...options, path: [...path, prop] });
138
+ if (typeof value !== "function") {
139
+ return nextUtils;
140
+ }
141
+ return new Proxy(value, {
142
+ get(_, prop2) {
143
+ return Reflect.get(nextUtils, prop2);
144
+ }
145
+ });
146
+ }
147
+ });
148
+ return recursive;
149
+ }
150
+
151
+ export { OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createGeneralUtils, createProcedureUtils, createRouterUtils, createRouterUtils as createTanstackQueryUtils, generateOperationKey };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/tanstack-query",
3
3
  "type": "module",
4
- "version": "0.0.0-next.fd6982a",
4
+ "version": "0.0.1",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -25,13 +25,21 @@
25
25
  ],
26
26
  "peerDependencies": {
27
27
  "@tanstack/query-core": ">=5.55.0",
28
- "@orpc/client": "0.0.0-next.fd6982a"
28
+ "@orpc/client": "1.3.0"
29
29
  },
30
30
  "dependencies": {
31
- "@orpc/shared": "0.0.0-next.fd6982a"
31
+ "@orpc/shared": "1.3.0"
32
32
  },
33
33
  "devDependencies": {
34
+ "@angular/core": "^20.0.0",
35
+ "@tanstack/angular-query-experimental": "^5.77.2",
34
36
  "@tanstack/query-core": "^5.77.2",
37
+ "@tanstack/react-query": "^5.77.2",
38
+ "@tanstack/solid-query": "^5.77.2",
39
+ "@tanstack/svelte-query": "^5.77.2",
40
+ "@tanstack/vue-query": "^5.77.2",
41
+ "svelte": "^5.26.2",
42
+ "vue": "^3.5.16",
35
43
  "zod": "^3.25.11"
36
44
  },
37
45
  "scripts": {