@orpc/tanstack-query 2.0.0-beta.18 → 2.0.0-beta.19
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 +5 -2
- package/dist/index.d.mts +45 -36
- package/dist/index.d.ts +45 -36
- package/dist/index.mjs +51 -57
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -49,11 +49,14 @@ You can read the documentation [here](https://orpc.dev).
|
|
|
49
49
|
**Framework & ecosystem integrations**
|
|
50
50
|
|
|
51
51
|
- [@orpc/next](https://www.npmjs.com/package/@orpc/next): Integrate with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data).
|
|
52
|
+
- [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk): Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools.
|
|
52
53
|
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): Integrate with [TanStack Query](https://tanstack.com/query/latest).
|
|
54
|
+
- [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada): Integrate with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
53
55
|
- [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect): Integrate with [Effect](https://effect.website/).
|
|
54
56
|
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Implement your contract with [NestJS](https://nestjs.com/).
|
|
55
57
|
- [@orpc/bun](https://www.npmjs.com/package/@orpc/bun): Adapters for [Bun's Redis](https://bun.sh/).
|
|
56
58
|
- [@orpc/cloudflare](https://www.npmjs.com/package/@orpc/cloudflare): Adapters for [Cloudflare's RateLimit and Durable Objects](https://developers.cloudflare.com/workers/).
|
|
59
|
+
- [@orpc/trpc](https://www.npmjs.com/package/@orpc/trpc): Reuse existing [tRPC](https://trpc.io/) routers within oRPC.
|
|
57
60
|
|
|
58
61
|
**Observability**
|
|
59
62
|
|
|
@@ -105,11 +108,10 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
105
108
|
<td align="center"><a href="https://github.com/valerii15298?ref=orpc" target="_blank" rel="noopener" title="Valerii Petryniak"><img src="https://avatars.githubusercontent.com/u/44531564?u=88ac74d9bacd20401518441907acad21063cd397&v=4" width="139" alt="Valerii Petryniak"/><br />Valerii Petryniak</a></td>
|
|
106
109
|
<td align="center"><a href="https://github.com/letstri?ref=orpc" target="_blank" rel="noopener" title="Valerii Strilets"><img src="https://avatars.githubusercontent.com/u/13253748?u=c7b10399ccc8f8081e24db94ec32cd9858e86ac3&v=4" width="139" alt="Valerii Strilets"/><br />Valerii Strilets</a></td>
|
|
107
110
|
<td align="center"><a href="https://github.com/K-Mistele?ref=orpc" target="_blank" rel="noopener" title="Kyle Mistele"><img src="https://avatars.githubusercontent.com/u/18430555?u=3afebeb81de666e35aaac3ed46f14159d7603ffb&v=4" width="139" alt="Kyle Mistele"/><br />Kyle Mistele</a></td>
|
|
108
|
-
<td align="center"><a href="https://github.com/andrewpeters9?ref=orpc" target="_blank" rel="noopener" title="Andrew Peters"><img src="https://avatars.githubusercontent.com/u/36251325?v=4" width="139" alt="Andrew Peters"/><br />Andrew Peters</a></td>
|
|
109
111
|
<td align="center"><a href="https://github.com/R44VC0RP?ref=orpc" target="_blank" rel="noopener" title="Ryan Vogel"><img src="https://avatars.githubusercontent.com/u/89211796?u=1857347b9787d8d8a7ea5bfc333f96be92d5a683&v=4" width="139" alt="Ryan Vogel"/><br />Ryan Vogel</a></td>
|
|
112
|
+
<td align="center"><a href="https://github.com/christ12938?ref=orpc" target="_blank" rel="noopener" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="139" alt="christ12938"/><br />christ12938</a></td>
|
|
110
113
|
</tr>
|
|
111
114
|
<tr>
|
|
112
|
-
<td align="center"><a href="https://github.com/christ12938?ref=orpc" target="_blank" rel="noopener" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="139" alt="christ12938"/><br />christ12938</a></td>
|
|
113
115
|
<td align="center"><a href="https://github.com/Ryanjso?ref=orpc" target="_blank" rel="noopener" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&v=4" width="139" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
|
|
114
116
|
<td align="center"><a href="https://github.com/itigoore01?ref=orpc" target="_blank" rel="noopener" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&v=4" width="139" alt="shota"/><br />shota</a></td>
|
|
115
117
|
</tr>
|
|
@@ -169,6 +171,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
169
171
|
<a href="https://github.com/nelsonlaidev?ref=orpc" target="_blank" rel="noopener" title="Nelson Lai"><img src="https://avatars.githubusercontent.com/u/75498339?u=2fc0e0b95dd184c5ffb744df977cb15a18b60672&v=4" width="32" height="32" alt="Nelson Lai" /></a>
|
|
170
172
|
<a href="https://github.com/nguyenlc1993?ref=orpc" target="_blank" rel="noopener" title="Lê Cao Nguyên"><img src="https://avatars.githubusercontent.com/u/13871971?u=83c8b69d9e35b589c4e1f066cc113b1d9461386f&v=4" width="32" height="32" alt="Lê Cao Nguyên" /></a>
|
|
171
173
|
<a href="https://github.com/wobsoriano?ref=orpc" target="_blank" rel="noopener" title="Robert Soriano"><img src="https://avatars.githubusercontent.com/u/13049130?u=6d72104182e7c9ed25934815313fb69107332111&v=4" width="32" height="32" alt="Robert Soriano" /></a>
|
|
174
|
+
<a href="https://github.com/andrewpeters9?ref=orpc" target="_blank" rel="noopener" title="Andrew Peters"><img src="https://avatars.githubusercontent.com/u/36251325?v=4" width="32" height="32" alt="Andrew Peters" /></a>
|
|
172
175
|
<a href="https://github.com/SKostyukovich?ref=orpc" target="_blank" rel="noopener" title="SKostyukovich"><img src="https://avatars.githubusercontent.com/u/10700067?v=4" width="32" height="32" alt="SKostyukovich" /></a>
|
|
173
176
|
<a href="https://github.com/peter-adam-dy?ref=orpc" target="_blank" rel="noopener" title="Peter Adam"><img src="https://avatars.githubusercontent.com/u/132129459?u=4f3dbbb3b443990b56acb7d6a5d11ed2c555f6db&v=4" width="32" height="32" alt="Peter Adam" /></a>
|
|
174
177
|
<a href="https://github.com/FabworksHQ?ref=orpc" target="_blank" rel="noopener" title="Fabworks"><img src="https://avatars.githubusercontent.com/u/160179500?v=4" width="32" height="32" alt="Fabworks" /></a>
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ClientContext, Client, AnyNestedClient, InferClientContext, InferClientError
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { ClientContext, Client, AnyNestedClient, InferClientContext, InferClientError } from '@orpc/client';
|
|
2
|
+
import { RouterContract, RouterContractClient, ContractClientFactory } from '@orpc/contract';
|
|
3
|
+
import { JsonifiedClient } from '@orpc/openapi';
|
|
4
4
|
import { Promisable, PartialDeep, Interceptor, PromiseWithError, MaybeOptionalOptions, OrderablePlugin, Public } from '@orpc/shared';
|
|
5
5
|
import { QueryKey, QueryFunctionContext, QueryFunction, SkipToken, QueryObserverOptions, InfiniteQueryObserverOptions, MutationObserverOptions, DataTag, InfiniteData, MutationFunctionContext } from '@tanstack/query-core';
|
|
6
6
|
|
|
@@ -33,12 +33,6 @@ declare function serializableStreamedQuery<TQueryFnData = unknown, TQueryKey ext
|
|
|
33
33
|
type InferStreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
34
34
|
type InferLiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
|
|
35
35
|
type OperationType = 'query' | 'streamed' | 'live' | 'infinite' | 'mutation';
|
|
36
|
-
type OperationKeyOptions<TType extends OperationType, TInput> = {
|
|
37
|
-
type?: TType;
|
|
38
|
-
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
|
39
|
-
fnOptions?: TType extends 'streamed' ? SerializableStreamedQueryOptions : never;
|
|
40
|
-
};
|
|
41
|
-
type OperationKey<TType extends OperationType, TInput> = [path: string[], options: OperationKeyOptions<TType, TInput>];
|
|
42
36
|
declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
|
|
43
37
|
interface OperationContext {
|
|
44
38
|
[OPERATION_CONTEXT_SYMBOL]?: {
|
|
@@ -108,6 +102,31 @@ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
|
|
|
108
102
|
}) & MutationOptionsOut<TInput, TOutput, TError, TMutationContext>;
|
|
109
103
|
type MutationOptionsOut<TInput, TOutput, TError, TMutationContext> = MutationObserverOptions<TOutput, TError, TInput, TMutationContext>;
|
|
110
104
|
|
|
105
|
+
interface OperationKeyPrefixOptions {
|
|
106
|
+
/**
|
|
107
|
+
* Prepended as the first element of the key when present.
|
|
108
|
+
* Use this to avoid key conflicts when multiple router utils share the same client.
|
|
109
|
+
*/
|
|
110
|
+
prefix?: string;
|
|
111
|
+
}
|
|
112
|
+
type OperationKeyOptions<TType extends OperationType, TInput> = OperationKeyPrefixOptions & {
|
|
113
|
+
type?: TType;
|
|
114
|
+
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
|
115
|
+
fnOptions?: TType extends 'streamed' ? SerializableStreamedQueryOptions : never;
|
|
116
|
+
};
|
|
117
|
+
type OperationKey<TType extends OperationType, TInput> = [path: string[], options: Omit<OperationKeyOptions<TType, TInput>, 'prefix'>] | [prefix: string, path: string[], options: Omit<OperationKeyOptions<TType, TInput>, 'prefix'>];
|
|
118
|
+
declare function generateOperationKey<TType extends OperationType, TInput>(path: string[], options?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
|
|
119
|
+
|
|
120
|
+
declare class SharedUtils<TInput> {
|
|
121
|
+
protected readonly path: string[];
|
|
122
|
+
protected readonly options: OperationKeyPrefixOptions;
|
|
123
|
+
constructor(path: string[], options: OperationKeyPrefixOptions);
|
|
124
|
+
/**
|
|
125
|
+
* Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
|
|
126
|
+
*/
|
|
127
|
+
key<TType extends OperationType>(options?: Omit<OperationKeyOptions<TType, TInput>, 'prefix'>): OperationKey<TType, TInput>;
|
|
128
|
+
}
|
|
129
|
+
|
|
111
130
|
interface ProcedureUtilsQueryInterceptorOptions<TClientContext extends ClientContext, TInput> {
|
|
112
131
|
path: string[];
|
|
113
132
|
context: TClientContext & OperationContext;
|
|
@@ -135,7 +154,7 @@ type ProcedureUtilsMutationInterceptor<TClientContext extends ClientContext, TIn
|
|
|
135
154
|
* or a function that receives per-call options and returns overridden this.options.
|
|
136
155
|
*/
|
|
137
156
|
type ProcedureUtilsModifier<T extends object> = Partial<T> | ((options: T) => T);
|
|
138
|
-
interface ProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
157
|
+
interface ProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TOutput, TError> extends OperationKeyPrefixOptions {
|
|
139
158
|
/**
|
|
140
159
|
* Key options modifier for .queryKey and .queryOptions
|
|
141
160
|
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
@@ -207,9 +226,8 @@ interface ProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TO
|
|
|
207
226
|
*/
|
|
208
227
|
mutationOptions?: ProcedureUtilsModifier<MutationOptionsIn<TClientContext, TInput, TOutput, TError, unknown>>;
|
|
209
228
|
}
|
|
210
|
-
declare class ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
211
|
-
|
|
212
|
-
private readonly options;
|
|
229
|
+
declare class ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> extends SharedUtils<TInput> {
|
|
230
|
+
protected readonly options: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>;
|
|
213
231
|
/**
|
|
214
232
|
* Calling corresponding procedure client
|
|
215
233
|
*/
|
|
@@ -297,24 +315,17 @@ interface RouterUtilsPlugin<T extends AnyNestedClient> extends OrderablePlugin {
|
|
|
297
315
|
initProcedureOptions?(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
298
316
|
}
|
|
299
317
|
|
|
300
|
-
|
|
301
|
-
private readonly path;
|
|
302
|
-
constructor(path: string[]);
|
|
303
|
-
/**
|
|
304
|
-
* Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
|
|
305
|
-
*/
|
|
306
|
-
key<TType extends OperationType>(options?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
|
|
307
|
-
}
|
|
308
|
-
type RouterUtils<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Public<ProcedureUtils<UClientContext, UInput, UOutput, UError>> & Public<SharedRouterUtils<UInput>> : {
|
|
318
|
+
type RouterUtils<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Public<ProcedureUtils<UClientContext, UInput, UOutput, UError>> : {
|
|
309
319
|
[K in keyof T]: T[K] extends AnyNestedClient ? RouterUtils<T[K]> : never;
|
|
310
|
-
} & Public<
|
|
320
|
+
} & Public<SharedUtils<unknown>>;
|
|
311
321
|
type RouterUtilsScoped<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtilsOptions<UClientContext, UInput, UOutput, UError> : {
|
|
312
322
|
[K in keyof T]?: T[K] extends AnyNestedClient ? RouterUtilsScoped<T[K]> : never;
|
|
313
323
|
};
|
|
314
|
-
interface RouterUtilsOptions<T extends AnyNestedClient> {
|
|
324
|
+
interface RouterUtilsOptions<T extends AnyNestedClient> extends OperationKeyPrefixOptions {
|
|
315
325
|
/**
|
|
316
|
-
* Base path for all query keys.
|
|
317
|
-
*
|
|
326
|
+
* Base path for all query keys.
|
|
327
|
+
*
|
|
328
|
+
* @internal
|
|
318
329
|
*/
|
|
319
330
|
path?: string[] | undefined;
|
|
320
331
|
/**
|
|
@@ -356,19 +367,17 @@ interface RouterUtilsOptions<T extends AnyNestedClient> {
|
|
|
356
367
|
declare function createRouterUtils<T extends AnyNestedClient>(client: T, options?: NoInfer<RouterUtilsOptions<T>>): RouterUtils<T>;
|
|
357
368
|
|
|
358
369
|
interface ContractUtilsFactory<TClientContext extends ClientContext> {
|
|
359
|
-
<
|
|
370
|
+
<T extends RouterContract>(contract: T): RouterUtils<RouterContractClient<T, TClientContext>>;
|
|
360
371
|
}
|
|
361
|
-
interface ContractUtilsFactoryOptions<TClientContext extends ClientContext> extends RouterUtilsOptions<RouterContractClient<RouterContract, TClientContext
|
|
372
|
+
interface ContractUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<RouterContractClient<RouterContract, TClientContext>>, 'path'> {
|
|
362
373
|
}
|
|
363
|
-
declare function createContractUtilsFactory<TClientContext extends ClientContext>(
|
|
374
|
+
declare function createContractUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractUtilsFactoryOptions<TClientContext>): ContractUtilsFactory<TClientContext>;
|
|
364
375
|
interface ContractJsonifiedUtilsFactory<TClientContext extends ClientContext> {
|
|
365
|
-
<
|
|
376
|
+
<T extends RouterContract>(contract: T): RouterUtils<JsonifiedClient<RouterContractClient<T, TClientContext>>>;
|
|
366
377
|
}
|
|
367
|
-
interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends ClientContext> extends RouterUtilsOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext
|
|
378
|
+
interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, 'path'> {
|
|
368
379
|
}
|
|
369
|
-
declare function createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(
|
|
370
|
-
|
|
371
|
-
declare function generateOperationKey<TType extends OperationType, TInput>(path: string[], state?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
|
|
380
|
+
declare function createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractJsonifiedUtilsFactoryOptions<TClientContext>): ContractJsonifiedUtilsFactory<TClientContext>;
|
|
372
381
|
|
|
373
|
-
export { OPERATION_CONTEXT_SYMBOL, ProcedureUtils,
|
|
374
|
-
export type { ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractUtilsFactory, ContractUtilsFactoryOptions, InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OperationContext, OperationKey, OperationKeyOptions, OperationType, ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, ProcedureUtilsLiveInterceptorOptions, ProcedureUtilsModifier, ProcedureUtilsMutationInterceptor, ProcedureUtilsMutationInterceptorOptions, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsQueryInterceptorOptions, ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, RouterUtils, RouterUtilsOptions, RouterUtilsScoped, SerializableStreamedQueryOptions, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut, OperationContext as TanstackQueryOperationContext };
|
|
382
|
+
export { OPERATION_CONTEXT_SYMBOL, ProcedureUtils, SharedUtils, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createRouterUtils, createRouterUtils as createTanstackQueryUtils, generateOperationKey, serializableStreamedQuery };
|
|
383
|
+
export type { ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractUtilsFactory, ContractUtilsFactoryOptions, InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OperationContext, OperationKey, OperationKeyOptions, OperationKeyPrefixOptions, OperationType, ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, ProcedureUtilsLiveInterceptorOptions, ProcedureUtilsModifier, ProcedureUtilsMutationInterceptor, ProcedureUtilsMutationInterceptorOptions, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsQueryInterceptorOptions, ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, RouterUtils, RouterUtilsOptions, RouterUtilsScoped, SerializableStreamedQueryOptions, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut, OperationContext as TanstackQueryOperationContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ClientContext, Client, AnyNestedClient, InferClientContext, InferClientError
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { ClientContext, Client, AnyNestedClient, InferClientContext, InferClientError } from '@orpc/client';
|
|
2
|
+
import { RouterContract, RouterContractClient, ContractClientFactory } from '@orpc/contract';
|
|
3
|
+
import { JsonifiedClient } from '@orpc/openapi';
|
|
4
4
|
import { Promisable, PartialDeep, Interceptor, PromiseWithError, MaybeOptionalOptions, OrderablePlugin, Public } from '@orpc/shared';
|
|
5
5
|
import { QueryKey, QueryFunctionContext, QueryFunction, SkipToken, QueryObserverOptions, InfiniteQueryObserverOptions, MutationObserverOptions, DataTag, InfiniteData, MutationFunctionContext } from '@tanstack/query-core';
|
|
6
6
|
|
|
@@ -33,12 +33,6 @@ declare function serializableStreamedQuery<TQueryFnData = unknown, TQueryKey ext
|
|
|
33
33
|
type InferStreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
34
34
|
type InferLiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
|
|
35
35
|
type OperationType = 'query' | 'streamed' | 'live' | 'infinite' | 'mutation';
|
|
36
|
-
type OperationKeyOptions<TType extends OperationType, TInput> = {
|
|
37
|
-
type?: TType;
|
|
38
|
-
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
|
39
|
-
fnOptions?: TType extends 'streamed' ? SerializableStreamedQueryOptions : never;
|
|
40
|
-
};
|
|
41
|
-
type OperationKey<TType extends OperationType, TInput> = [path: string[], options: OperationKeyOptions<TType, TInput>];
|
|
42
36
|
declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
|
|
43
37
|
interface OperationContext {
|
|
44
38
|
[OPERATION_CONTEXT_SYMBOL]?: {
|
|
@@ -108,6 +102,31 @@ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
|
|
|
108
102
|
}) & MutationOptionsOut<TInput, TOutput, TError, TMutationContext>;
|
|
109
103
|
type MutationOptionsOut<TInput, TOutput, TError, TMutationContext> = MutationObserverOptions<TOutput, TError, TInput, TMutationContext>;
|
|
110
104
|
|
|
105
|
+
interface OperationKeyPrefixOptions {
|
|
106
|
+
/**
|
|
107
|
+
* Prepended as the first element of the key when present.
|
|
108
|
+
* Use this to avoid key conflicts when multiple router utils share the same client.
|
|
109
|
+
*/
|
|
110
|
+
prefix?: string;
|
|
111
|
+
}
|
|
112
|
+
type OperationKeyOptions<TType extends OperationType, TInput> = OperationKeyPrefixOptions & {
|
|
113
|
+
type?: TType;
|
|
114
|
+
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
|
115
|
+
fnOptions?: TType extends 'streamed' ? SerializableStreamedQueryOptions : never;
|
|
116
|
+
};
|
|
117
|
+
type OperationKey<TType extends OperationType, TInput> = [path: string[], options: Omit<OperationKeyOptions<TType, TInput>, 'prefix'>] | [prefix: string, path: string[], options: Omit<OperationKeyOptions<TType, TInput>, 'prefix'>];
|
|
118
|
+
declare function generateOperationKey<TType extends OperationType, TInput>(path: string[], options?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
|
|
119
|
+
|
|
120
|
+
declare class SharedUtils<TInput> {
|
|
121
|
+
protected readonly path: string[];
|
|
122
|
+
protected readonly options: OperationKeyPrefixOptions;
|
|
123
|
+
constructor(path: string[], options: OperationKeyPrefixOptions);
|
|
124
|
+
/**
|
|
125
|
+
* Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
|
|
126
|
+
*/
|
|
127
|
+
key<TType extends OperationType>(options?: Omit<OperationKeyOptions<TType, TInput>, 'prefix'>): OperationKey<TType, TInput>;
|
|
128
|
+
}
|
|
129
|
+
|
|
111
130
|
interface ProcedureUtilsQueryInterceptorOptions<TClientContext extends ClientContext, TInput> {
|
|
112
131
|
path: string[];
|
|
113
132
|
context: TClientContext & OperationContext;
|
|
@@ -135,7 +154,7 @@ type ProcedureUtilsMutationInterceptor<TClientContext extends ClientContext, TIn
|
|
|
135
154
|
* or a function that receives per-call options and returns overridden this.options.
|
|
136
155
|
*/
|
|
137
156
|
type ProcedureUtilsModifier<T extends object> = Partial<T> | ((options: T) => T);
|
|
138
|
-
interface ProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
157
|
+
interface ProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TOutput, TError> extends OperationKeyPrefixOptions {
|
|
139
158
|
/**
|
|
140
159
|
* Key options modifier for .queryKey and .queryOptions
|
|
141
160
|
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
@@ -207,9 +226,8 @@ interface ProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TO
|
|
|
207
226
|
*/
|
|
208
227
|
mutationOptions?: ProcedureUtilsModifier<MutationOptionsIn<TClientContext, TInput, TOutput, TError, unknown>>;
|
|
209
228
|
}
|
|
210
|
-
declare class ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
211
|
-
|
|
212
|
-
private readonly options;
|
|
229
|
+
declare class ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> extends SharedUtils<TInput> {
|
|
230
|
+
protected readonly options: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>;
|
|
213
231
|
/**
|
|
214
232
|
* Calling corresponding procedure client
|
|
215
233
|
*/
|
|
@@ -297,24 +315,17 @@ interface RouterUtilsPlugin<T extends AnyNestedClient> extends OrderablePlugin {
|
|
|
297
315
|
initProcedureOptions?(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
298
316
|
}
|
|
299
317
|
|
|
300
|
-
|
|
301
|
-
private readonly path;
|
|
302
|
-
constructor(path: string[]);
|
|
303
|
-
/**
|
|
304
|
-
* Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
|
|
305
|
-
*/
|
|
306
|
-
key<TType extends OperationType>(options?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
|
|
307
|
-
}
|
|
308
|
-
type RouterUtils<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Public<ProcedureUtils<UClientContext, UInput, UOutput, UError>> & Public<SharedRouterUtils<UInput>> : {
|
|
318
|
+
type RouterUtils<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Public<ProcedureUtils<UClientContext, UInput, UOutput, UError>> : {
|
|
309
319
|
[K in keyof T]: T[K] extends AnyNestedClient ? RouterUtils<T[K]> : never;
|
|
310
|
-
} & Public<
|
|
320
|
+
} & Public<SharedUtils<unknown>>;
|
|
311
321
|
type RouterUtilsScoped<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtilsOptions<UClientContext, UInput, UOutput, UError> : {
|
|
312
322
|
[K in keyof T]?: T[K] extends AnyNestedClient ? RouterUtilsScoped<T[K]> : never;
|
|
313
323
|
};
|
|
314
|
-
interface RouterUtilsOptions<T extends AnyNestedClient> {
|
|
324
|
+
interface RouterUtilsOptions<T extends AnyNestedClient> extends OperationKeyPrefixOptions {
|
|
315
325
|
/**
|
|
316
|
-
* Base path for all query keys.
|
|
317
|
-
*
|
|
326
|
+
* Base path for all query keys.
|
|
327
|
+
*
|
|
328
|
+
* @internal
|
|
318
329
|
*/
|
|
319
330
|
path?: string[] | undefined;
|
|
320
331
|
/**
|
|
@@ -356,19 +367,17 @@ interface RouterUtilsOptions<T extends AnyNestedClient> {
|
|
|
356
367
|
declare function createRouterUtils<T extends AnyNestedClient>(client: T, options?: NoInfer<RouterUtilsOptions<T>>): RouterUtils<T>;
|
|
357
368
|
|
|
358
369
|
interface ContractUtilsFactory<TClientContext extends ClientContext> {
|
|
359
|
-
<
|
|
370
|
+
<T extends RouterContract>(contract: T): RouterUtils<RouterContractClient<T, TClientContext>>;
|
|
360
371
|
}
|
|
361
|
-
interface ContractUtilsFactoryOptions<TClientContext extends ClientContext> extends RouterUtilsOptions<RouterContractClient<RouterContract, TClientContext
|
|
372
|
+
interface ContractUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<RouterContractClient<RouterContract, TClientContext>>, 'path'> {
|
|
362
373
|
}
|
|
363
|
-
declare function createContractUtilsFactory<TClientContext extends ClientContext>(
|
|
374
|
+
declare function createContractUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractUtilsFactoryOptions<TClientContext>): ContractUtilsFactory<TClientContext>;
|
|
364
375
|
interface ContractJsonifiedUtilsFactory<TClientContext extends ClientContext> {
|
|
365
|
-
<
|
|
376
|
+
<T extends RouterContract>(contract: T): RouterUtils<JsonifiedClient<RouterContractClient<T, TClientContext>>>;
|
|
366
377
|
}
|
|
367
|
-
interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends ClientContext> extends RouterUtilsOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext
|
|
378
|
+
interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, 'path'> {
|
|
368
379
|
}
|
|
369
|
-
declare function createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(
|
|
370
|
-
|
|
371
|
-
declare function generateOperationKey<TType extends OperationType, TInput>(path: string[], state?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
|
|
380
|
+
declare function createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractJsonifiedUtilsFactoryOptions<TClientContext>): ContractJsonifiedUtilsFactory<TClientContext>;
|
|
372
381
|
|
|
373
|
-
export { OPERATION_CONTEXT_SYMBOL, ProcedureUtils,
|
|
374
|
-
export type { ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractUtilsFactory, ContractUtilsFactoryOptions, InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OperationContext, OperationKey, OperationKeyOptions, OperationType, ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, ProcedureUtilsLiveInterceptorOptions, ProcedureUtilsModifier, ProcedureUtilsMutationInterceptor, ProcedureUtilsMutationInterceptorOptions, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsQueryInterceptorOptions, ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, RouterUtils, RouterUtilsOptions, RouterUtilsScoped, SerializableStreamedQueryOptions, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut, OperationContext as TanstackQueryOperationContext };
|
|
382
|
+
export { OPERATION_CONTEXT_SYMBOL, ProcedureUtils, SharedUtils, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createRouterUtils, createRouterUtils as createTanstackQueryUtils, generateOperationKey, serializableStreamedQuery };
|
|
383
|
+
export type { ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractUtilsFactory, ContractUtilsFactoryOptions, InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OperationContext, OperationKey, OperationKeyOptions, OperationKeyPrefixOptions, OperationType, ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, ProcedureUtilsLiveInterceptorOptions, ProcedureUtilsModifier, ProcedureUtilsMutationInterceptor, ProcedureUtilsMutationInterceptorOptions, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsQueryInterceptorOptions, ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, RouterUtils, RouterUtilsOptions, RouterUtilsScoped, SerializableStreamedQueryOptions, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut, OperationContext as TanstackQueryOperationContext };
|
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveBasePathMeta } from '@orpc/contract';
|
|
2
2
|
import { sortPlugins, stringifyJSON, resolveMaybeOptionalOptions, intercept, toArray, isAsyncIteratorObject, bindMethods, getOrBind, get, isTypescriptObject } from '@orpc/shared';
|
|
3
3
|
import { RECURSIVE_CLIENT_UNWRAP_KEYS } from '@orpc/client';
|
|
4
4
|
import { skipToken } from '@tanstack/query-core';
|
|
5
5
|
|
|
6
|
-
function generateOperationKey(path, state = {}) {
|
|
7
|
-
return [path, {
|
|
8
|
-
...state.input !== void 0 ? { input: state.input } : {},
|
|
9
|
-
...state.type !== void 0 ? { type: state.type } : {},
|
|
10
|
-
...state.fnOptions !== void 0 ? { fnOptions: state.fnOptions } : {}
|
|
11
|
-
}];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
6
|
class CompositeRouterUtilsPlugin {
|
|
15
7
|
constructor(plugins = []) {
|
|
16
8
|
this.plugins = plugins;
|
|
@@ -35,6 +27,18 @@ class CompositeRouterUtilsPlugin {
|
|
|
35
27
|
}
|
|
36
28
|
}
|
|
37
29
|
|
|
30
|
+
function generateOperationKey(path, options = {}) {
|
|
31
|
+
return [
|
|
32
|
+
...options.prefix !== void 0 ? [options.prefix] : [],
|
|
33
|
+
path,
|
|
34
|
+
{
|
|
35
|
+
...options.input !== void 0 ? { input: options.input } : {},
|
|
36
|
+
...options.type !== void 0 ? { type: options.type } : {},
|
|
37
|
+
...options.fnOptions !== void 0 ? { fnOptions: options.fnOptions } : {}
|
|
38
|
+
}
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
|
|
38
42
|
function liveQuery(queryFn) {
|
|
39
43
|
return async (context) => {
|
|
40
44
|
const stream = await queryFn(context);
|
|
@@ -53,6 +57,19 @@ function liveQuery(queryFn) {
|
|
|
53
57
|
};
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
class SharedUtils {
|
|
61
|
+
constructor(path, options) {
|
|
62
|
+
this.path = path;
|
|
63
|
+
this.options = options;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
|
|
67
|
+
*/
|
|
68
|
+
key(options = {}) {
|
|
69
|
+
return generateOperationKey(this.path, { ...options, prefix: this.options.prefix });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
56
73
|
function serializableStreamedQuery(queryFn, { refetchMode = "reset", maxChunks = Number.POSITIVE_INFINITY } = {}) {
|
|
57
74
|
return async (context) => {
|
|
58
75
|
const query = context.client.getQueryCache().find({ queryKey: context.queryKey, exact: true });
|
|
@@ -111,16 +128,15 @@ function limitArraySize(items, maxSize) {
|
|
|
111
128
|
|
|
112
129
|
const OPERATION_CONTEXT_SYMBOL = Symbol.for("ORPC_TANSTACK_QUERY_OPERATION_CONTEXT");
|
|
113
130
|
|
|
114
|
-
class ProcedureUtils {
|
|
115
|
-
constructor(path, client, options = {}) {
|
|
116
|
-
this.path = path;
|
|
117
|
-
this.options = options;
|
|
118
|
-
this.call = client;
|
|
119
|
-
}
|
|
131
|
+
class ProcedureUtils extends SharedUtils {
|
|
120
132
|
/**
|
|
121
133
|
* Calling corresponding procedure client
|
|
122
134
|
*/
|
|
123
135
|
call;
|
|
136
|
+
constructor(path, client, options = {}) {
|
|
137
|
+
super(path, options);
|
|
138
|
+
this.call = client;
|
|
139
|
+
}
|
|
124
140
|
/**
|
|
125
141
|
* Generate a **full matching** key for [Query Options](https://orpc.dev/docs/integrations/tanstack-query#query-options).
|
|
126
142
|
*/
|
|
@@ -131,7 +147,7 @@ class ProcedureUtils {
|
|
|
131
147
|
} else if (this.options.queryKey) {
|
|
132
148
|
optionsIn = { ...this.options.queryKey, ...optionsIn };
|
|
133
149
|
}
|
|
134
|
-
const queryKey = optionsIn.queryKey ?? generateOperationKey(this.path, { type: "query", input: optionsIn.input });
|
|
150
|
+
const queryKey = optionsIn.queryKey ?? generateOperationKey(this.path, { prefix: this.options.prefix, type: "query", input: optionsIn.input });
|
|
135
151
|
return queryKey;
|
|
136
152
|
}
|
|
137
153
|
/**
|
|
@@ -187,7 +203,7 @@ class ProcedureUtils {
|
|
|
187
203
|
} else if (this.options.streamedKey) {
|
|
188
204
|
optionsIn = { ...this.options.streamedKey, ...optionsIn };
|
|
189
205
|
}
|
|
190
|
-
const queryKey = optionsIn.queryKey ?? generateOperationKey(this.path, { type: "streamed", input: optionsIn.input, fnOptions: optionsIn.queryFnOptions });
|
|
206
|
+
const queryKey = optionsIn.queryKey ?? generateOperationKey(this.path, { prefix: this.options.prefix, type: "streamed", input: optionsIn.input, fnOptions: optionsIn.queryFnOptions });
|
|
191
207
|
return queryKey;
|
|
192
208
|
}
|
|
193
209
|
/**
|
|
@@ -254,7 +270,7 @@ class ProcedureUtils {
|
|
|
254
270
|
} else if (this.options.liveKey) {
|
|
255
271
|
optionsIn = { ...this.options.liveKey, ...optionsIn };
|
|
256
272
|
}
|
|
257
|
-
const queryKey = optionsIn.queryKey ?? generateOperationKey(this.path, { type: "live", input: optionsIn.input });
|
|
273
|
+
const queryKey = optionsIn.queryKey ?? generateOperationKey(this.path, { prefix: this.options.prefix, type: "live", input: optionsIn.input });
|
|
258
274
|
return queryKey;
|
|
259
275
|
}
|
|
260
276
|
/**
|
|
@@ -321,6 +337,7 @@ class ProcedureUtils {
|
|
|
321
337
|
optionsIn = { ...this.options.infiniteKey, ...optionsIn };
|
|
322
338
|
}
|
|
323
339
|
const queryKey = optionsIn.queryKey ?? generateOperationKey(this.path, {
|
|
340
|
+
prefix: this.options.prefix,
|
|
324
341
|
type: "infinite",
|
|
325
342
|
input: optionsIn.input === skipToken ? skipToken : optionsIn.input(optionsIn.initialPageParam)
|
|
326
343
|
});
|
|
@@ -377,7 +394,7 @@ class ProcedureUtils {
|
|
|
377
394
|
} else if (this.options.mutationKey) {
|
|
378
395
|
optionsIn = { ...this.options.mutationKey, ...optionsIn };
|
|
379
396
|
}
|
|
380
|
-
const mutationKey = optionsIn.mutationKey ?? generateOperationKey(this.path, { type: "mutation" });
|
|
397
|
+
const mutationKey = optionsIn.mutationKey ?? generateOperationKey(this.path, { prefix: this.options.prefix, type: "mutation" });
|
|
381
398
|
return mutationKey;
|
|
382
399
|
}
|
|
383
400
|
/**
|
|
@@ -421,29 +438,18 @@ class ProcedureUtils {
|
|
|
421
438
|
}
|
|
422
439
|
}
|
|
423
440
|
|
|
424
|
-
class SharedRouterUtils {
|
|
425
|
-
constructor(path) {
|
|
426
|
-
this.path = path;
|
|
427
|
-
}
|
|
428
|
-
/**
|
|
429
|
-
* Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
|
|
430
|
-
*/
|
|
431
|
-
key(options = {}) {
|
|
432
|
-
return generateOperationKey(this.path, options);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
441
|
function createRouterUtils(client, options = {}) {
|
|
436
442
|
const plugin = new CompositeRouterUtilsPlugin(options.plugins);
|
|
437
443
|
options = plugin.init(options);
|
|
438
444
|
return createRouterUtilsInternal(client, options, plugin);
|
|
439
445
|
}
|
|
440
|
-
function createRouterUtilsInternal(client, options
|
|
446
|
+
function createRouterUtilsInternal(client, options, plugin) {
|
|
441
447
|
const path = toArray(options.path);
|
|
442
|
-
const
|
|
443
|
-
const procedureUtils = typeof client === "function" && (options.scoped === void 0 || isProcedureUtilsOptions(options.scoped)) ? bindMethods(new ProcedureUtils(
|
|
448
|
+
const utils = typeof client === "function" && (options.scoped === void 0 || isProcedureUtilsOptions(options.scoped)) ? bindMethods(new ProcedureUtils(
|
|
444
449
|
path,
|
|
445
450
|
client,
|
|
446
451
|
plugin.initProcedureOptions(path, {
|
|
452
|
+
prefix: options.prefix,
|
|
447
453
|
...options.scoped,
|
|
448
454
|
queryInterceptors: [...toArray(options.queryInterceptors), ...toArray(options.scoped?.queryInterceptors)],
|
|
449
455
|
streamedInterceptors: [...toArray(options.streamedInterceptors), ...toArray(options.scoped?.streamedInterceptors)],
|
|
@@ -451,11 +457,8 @@ function createRouterUtilsInternal(client, options = {}, plugin) {
|
|
|
451
457
|
infiniteInterceptors: [...toArray(options.infiniteInterceptors), ...toArray(options.scoped?.infiniteInterceptors)],
|
|
452
458
|
mutationInterceptors: [...toArray(options.mutationInterceptors), ...toArray(options.scoped?.mutationInterceptors)]
|
|
453
459
|
})
|
|
454
|
-
)) :
|
|
455
|
-
const recursive = new Proxy({
|
|
456
|
-
...sharedUtils,
|
|
457
|
-
...procedureUtils
|
|
458
|
-
}, {
|
|
460
|
+
)) : bindMethods(new SharedUtils(path, options));
|
|
461
|
+
const recursive = new Proxy(utils, {
|
|
459
462
|
get(target, prop) {
|
|
460
463
|
const value = getOrBind(target, prop);
|
|
461
464
|
const nextClient = get(client, [prop]);
|
|
@@ -504,30 +507,21 @@ function isProcedureUtilsOptions(value) {
|
|
|
504
507
|
return true;
|
|
505
508
|
}
|
|
506
509
|
|
|
507
|
-
function createContractUtilsFactory(
|
|
508
|
-
|
|
509
|
-
const
|
|
510
|
-
|
|
510
|
+
function createContractUtilsFactory(clientFactory, options) {
|
|
511
|
+
const factory = (contract) => {
|
|
512
|
+
const client = clientFactory(contract);
|
|
513
|
+
const path = resolveBasePathMeta(contract);
|
|
514
|
+
if (path === void 0) {
|
|
511
515
|
throw new TypeError(
|
|
512
516
|
"ContractUtilsFactory: procedure contract must define `meta.path` that matches its path in the root router contract."
|
|
513
517
|
);
|
|
514
518
|
}
|
|
515
|
-
|
|
516
|
-
if (scoped !== void 0 && (scoped === null || typeof scoped !== "object")) {
|
|
517
|
-
throw new TypeError(
|
|
518
|
-
`ContractUtilsFactory: "scoped" at path "${path.join(".")}" must be an object or undefined, got "${scoped}".`
|
|
519
|
-
);
|
|
520
|
-
}
|
|
521
|
-
const client = (...rest) => caller(procedure, ...rest);
|
|
522
|
-
return createRouterUtils(client, {
|
|
523
|
-
...options,
|
|
524
|
-
scoped,
|
|
525
|
-
path: [...toArray(options.path), ...path]
|
|
526
|
-
});
|
|
519
|
+
return createRouterUtils(client, { ...options, path, scoped: get(options.scoped, path) });
|
|
527
520
|
};
|
|
521
|
+
return factory;
|
|
528
522
|
}
|
|
529
|
-
function createContractJsonifiedUtilsFactory(
|
|
530
|
-
return createContractUtilsFactory(
|
|
523
|
+
function createContractJsonifiedUtilsFactory(clientFactory, options) {
|
|
524
|
+
return createContractUtilsFactory(clientFactory, options);
|
|
531
525
|
}
|
|
532
526
|
|
|
533
|
-
export { OPERATION_CONTEXT_SYMBOL, ProcedureUtils,
|
|
527
|
+
export { OPERATION_CONTEXT_SYMBOL, ProcedureUtils, SharedUtils, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createRouterUtils, createRouterUtils as createTanstackQueryUtils, generateOperationKey, serializableStreamedQuery };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/tanstack-query",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.19",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"@tanstack/query-core": ">=5.80.2"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@orpc/
|
|
33
|
-
"@orpc/
|
|
34
|
-
"@orpc/shared": "2.0.0-beta.
|
|
35
|
-
"@orpc/
|
|
32
|
+
"@orpc/contract": "2.0.0-beta.19",
|
|
33
|
+
"@orpc/client": "2.0.0-beta.19",
|
|
34
|
+
"@orpc/shared": "2.0.0-beta.19",
|
|
35
|
+
"@orpc/openapi": "2.0.0-beta.19"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@angular/core": "^22.0.1",
|