@orpc/tanstack-query 2.0.0-beta.19 → 2.0.0-beta.20
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 +1 -0
- package/dist/index.d.mts +57 -4
- package/dist/index.d.ts +57 -4
- package/dist/index.mjs +116 -33
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -52,6 +52,7 @@ You can read the documentation [here](https://orpc.dev).
|
|
|
52
52
|
- [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk): Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools.
|
|
53
53
|
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): Integrate with [TanStack Query](https://tanstack.com/query/latest).
|
|
54
54
|
- [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada): Integrate with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
55
|
+
- [@orpc/swr](https://www.npmjs.com/package/@orpc/swr): Integrate with [SWR](https://swr.vercel.app/).
|
|
55
56
|
- [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect): Integrate with [Effect](https://effect.website/).
|
|
56
57
|
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Implement your contract with [NestJS](https://nestjs.com/).
|
|
57
58
|
- [@orpc/bun](https://www.npmjs.com/package/@orpc/bun): Adapters for [Bun's Redis](https://bun.sh/).
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ClientContext, Client, AnyNestedClient, InferClientContext, InferClientError } from '@orpc/client';
|
|
2
|
-
import { RouterContract, RouterContractClient, ContractClientFactory } from '@orpc/contract';
|
|
2
|
+
import { RouterContract, RouterContractClient, ContractClientFactory, AnySchema, ErrorMap, MetaPlugin, Meta, InferSchemaInput, InferSchemaOutput, ORPCErrorFromErrorMap } from '@orpc/contract';
|
|
3
3
|
import { JsonifiedClient } from '@orpc/openapi';
|
|
4
|
-
import { Promisable, PartialDeep, Interceptor, PromiseWithError, MaybeOptionalOptions, OrderablePlugin, Public } from '@orpc/shared';
|
|
4
|
+
import { Promisable, PartialDeep, Interceptor, PromiseWithError, MaybeOptionalOptions, OrderablePlugin, Public, ThrowableError } from '@orpc/shared';
|
|
5
5
|
import { QueryKey, QueryFunctionContext, QueryFunction, SkipToken, QueryObserverOptions, InfiniteQueryObserverOptions, MutationObserverOptions, DataTag, InfiniteData, MutationFunctionContext } from '@tanstack/query-core';
|
|
6
6
|
|
|
7
7
|
interface SerializableStreamedQueryOptions {
|
|
@@ -226,6 +226,15 @@ interface ProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TO
|
|
|
226
226
|
*/
|
|
227
227
|
mutationOptions?: ProcedureUtilsModifier<MutationOptionsIn<TClientContext, TInput, TOutput, TError, unknown>>;
|
|
228
228
|
}
|
|
229
|
+
declare function isProcedureUtilsOptions(value: unknown): value is ProcedureUtilsOptions<any, any, any, any>;
|
|
230
|
+
/**
|
|
231
|
+
* Merge two procedure utils options where `override` takes priority.
|
|
232
|
+
* A key explicitly set to `undefined` in `override` resets the base value.
|
|
233
|
+
* When both sides define a key: interceptors are concatenated (base ones run first),
|
|
234
|
+
* modifiers are spread-merged when both are plain objects and composed (base applied
|
|
235
|
+
* first) otherwise, with plain objects applied as regular spread merges.
|
|
236
|
+
*/
|
|
237
|
+
declare function mergeProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TOutput, TError>(base: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>, override: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>): ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>;
|
|
229
238
|
declare class ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> extends SharedUtils<TInput> {
|
|
230
239
|
protected readonly options: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>;
|
|
231
240
|
/**
|
|
@@ -314,6 +323,13 @@ interface RouterUtilsPlugin<T extends AnyNestedClient> extends OrderablePlugin {
|
|
|
314
323
|
*/
|
|
315
324
|
initProcedureOptions?(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
316
325
|
}
|
|
326
|
+
declare class CompositeRouterUtilsPlugin<T extends AnyNestedClient> implements RouterUtilsPlugin<T> {
|
|
327
|
+
protected readonly plugins: RouterUtilsPlugin<T>[];
|
|
328
|
+
readonly name = "~composite";
|
|
329
|
+
constructor(plugins?: RouterUtilsPlugin<T>[]);
|
|
330
|
+
init(options: RouterUtilsOptions<T>): RouterUtilsOptions<T>;
|
|
331
|
+
initProcedureOptions(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
332
|
+
}
|
|
317
333
|
|
|
318
334
|
type RouterUtils<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Public<ProcedureUtils<UClientContext, UInput, UOutput, UError>> : {
|
|
319
335
|
[K in keyof T]: T[K] extends AnyNestedClient ? RouterUtils<T[K]> : never;
|
|
@@ -379,5 +395,42 @@ interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends ClientCont
|
|
|
379
395
|
}
|
|
380
396
|
declare function createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractJsonifiedUtilsFactoryOptions<TClientContext>): ContractJsonifiedUtilsFactory<TClientContext>;
|
|
381
397
|
|
|
382
|
-
|
|
383
|
-
|
|
398
|
+
type TanstackQueryMetaOptions<TClientContext extends ClientContext, TInput, TOutput, TError> = Omit<ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>, 'prefix'>;
|
|
399
|
+
interface TanstackQueryMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends MetaPlugin<TInputSchema, TOutputSchema, TErrorMap> {
|
|
400
|
+
name: '~tanstack-query';
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Define base TanStack Query options and interceptors on a procedure contract.
|
|
404
|
+
* Applied multiple times, later options are spread-merged with higher priority
|
|
405
|
+
* while interceptors are concatenated. A key explicitly set to `undefined`
|
|
406
|
+
* resets the value from earlier applications instead of merging.
|
|
407
|
+
*
|
|
408
|
+
* Apply them to router utils with {@link ContractOptionsUtilsPlugin}.
|
|
409
|
+
*
|
|
410
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin TanStack Query Contract Options Plugin Docs}
|
|
411
|
+
*/
|
|
412
|
+
declare function tanstackQuery<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(options: TanstackQueryMetaOptions<ClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>): TanstackQueryMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>;
|
|
413
|
+
declare function getTanstackQueryMeta(procedureOrLazy: {
|
|
414
|
+
'~orpc': {
|
|
415
|
+
meta: Meta;
|
|
416
|
+
};
|
|
417
|
+
}): TanstackQueryMetaOptions<ClientContext, unknown, unknown, ThrowableError> | undefined;
|
|
418
|
+
/**
|
|
419
|
+
* Router utils plugin that applies base options defined via {@link tanstackQuery}
|
|
420
|
+
* on the given router contract. Meta options act as the base layer: options defined
|
|
421
|
+
* on the utils override them, and utils interceptors run after meta interceptors.
|
|
422
|
+
*
|
|
423
|
+
* The contract shape must match the client the utils are created from,
|
|
424
|
+
* so pass the root router contract when utils paths start from the root.
|
|
425
|
+
*
|
|
426
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin TanStack Query Contract Options Plugin Docs}
|
|
427
|
+
*/
|
|
428
|
+
declare class ContractOptionsUtilsPlugin<T extends AnyNestedClient = AnyNestedClient> implements RouterUtilsPlugin<T> {
|
|
429
|
+
private readonly contract;
|
|
430
|
+
readonly name = "~contract-options";
|
|
431
|
+
constructor(contract: RouterContract);
|
|
432
|
+
initProcedureOptions(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export { CompositeRouterUtilsPlugin, ContractOptionsUtilsPlugin, OPERATION_CONTEXT_SYMBOL, ProcedureUtils, SharedUtils, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createRouterUtils, createRouterUtils as createTanstackQueryUtils, generateOperationKey, getTanstackQueryMeta, isProcedureUtilsOptions, mergeProcedureUtilsOptions, serializableStreamedQuery, tanstackQuery };
|
|
436
|
+
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, RouterUtilsPlugin, RouterUtilsScoped, SerializableStreamedQueryOptions, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut, TanstackQueryMetaOptions, TanstackQueryMetaPlugin, OperationContext as TanstackQueryOperationContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ClientContext, Client, AnyNestedClient, InferClientContext, InferClientError } from '@orpc/client';
|
|
2
|
-
import { RouterContract, RouterContractClient, ContractClientFactory } from '@orpc/contract';
|
|
2
|
+
import { RouterContract, RouterContractClient, ContractClientFactory, AnySchema, ErrorMap, MetaPlugin, Meta, InferSchemaInput, InferSchemaOutput, ORPCErrorFromErrorMap } from '@orpc/contract';
|
|
3
3
|
import { JsonifiedClient } from '@orpc/openapi';
|
|
4
|
-
import { Promisable, PartialDeep, Interceptor, PromiseWithError, MaybeOptionalOptions, OrderablePlugin, Public } from '@orpc/shared';
|
|
4
|
+
import { Promisable, PartialDeep, Interceptor, PromiseWithError, MaybeOptionalOptions, OrderablePlugin, Public, ThrowableError } from '@orpc/shared';
|
|
5
5
|
import { QueryKey, QueryFunctionContext, QueryFunction, SkipToken, QueryObserverOptions, InfiniteQueryObserverOptions, MutationObserverOptions, DataTag, InfiniteData, MutationFunctionContext } from '@tanstack/query-core';
|
|
6
6
|
|
|
7
7
|
interface SerializableStreamedQueryOptions {
|
|
@@ -226,6 +226,15 @@ interface ProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TO
|
|
|
226
226
|
*/
|
|
227
227
|
mutationOptions?: ProcedureUtilsModifier<MutationOptionsIn<TClientContext, TInput, TOutput, TError, unknown>>;
|
|
228
228
|
}
|
|
229
|
+
declare function isProcedureUtilsOptions(value: unknown): value is ProcedureUtilsOptions<any, any, any, any>;
|
|
230
|
+
/**
|
|
231
|
+
* Merge two procedure utils options where `override` takes priority.
|
|
232
|
+
* A key explicitly set to `undefined` in `override` resets the base value.
|
|
233
|
+
* When both sides define a key: interceptors are concatenated (base ones run first),
|
|
234
|
+
* modifiers are spread-merged when both are plain objects and composed (base applied
|
|
235
|
+
* first) otherwise, with plain objects applied as regular spread merges.
|
|
236
|
+
*/
|
|
237
|
+
declare function mergeProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TOutput, TError>(base: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>, override: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>): ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>;
|
|
229
238
|
declare class ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> extends SharedUtils<TInput> {
|
|
230
239
|
protected readonly options: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>;
|
|
231
240
|
/**
|
|
@@ -314,6 +323,13 @@ interface RouterUtilsPlugin<T extends AnyNestedClient> extends OrderablePlugin {
|
|
|
314
323
|
*/
|
|
315
324
|
initProcedureOptions?(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
316
325
|
}
|
|
326
|
+
declare class CompositeRouterUtilsPlugin<T extends AnyNestedClient> implements RouterUtilsPlugin<T> {
|
|
327
|
+
protected readonly plugins: RouterUtilsPlugin<T>[];
|
|
328
|
+
readonly name = "~composite";
|
|
329
|
+
constructor(plugins?: RouterUtilsPlugin<T>[]);
|
|
330
|
+
init(options: RouterUtilsOptions<T>): RouterUtilsOptions<T>;
|
|
331
|
+
initProcedureOptions(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
332
|
+
}
|
|
317
333
|
|
|
318
334
|
type RouterUtils<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Public<ProcedureUtils<UClientContext, UInput, UOutput, UError>> : {
|
|
319
335
|
[K in keyof T]: T[K] extends AnyNestedClient ? RouterUtils<T[K]> : never;
|
|
@@ -379,5 +395,42 @@ interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends ClientCont
|
|
|
379
395
|
}
|
|
380
396
|
declare function createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractJsonifiedUtilsFactoryOptions<TClientContext>): ContractJsonifiedUtilsFactory<TClientContext>;
|
|
381
397
|
|
|
382
|
-
|
|
383
|
-
|
|
398
|
+
type TanstackQueryMetaOptions<TClientContext extends ClientContext, TInput, TOutput, TError> = Omit<ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>, 'prefix'>;
|
|
399
|
+
interface TanstackQueryMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends MetaPlugin<TInputSchema, TOutputSchema, TErrorMap> {
|
|
400
|
+
name: '~tanstack-query';
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Define base TanStack Query options and interceptors on a procedure contract.
|
|
404
|
+
* Applied multiple times, later options are spread-merged with higher priority
|
|
405
|
+
* while interceptors are concatenated. A key explicitly set to `undefined`
|
|
406
|
+
* resets the value from earlier applications instead of merging.
|
|
407
|
+
*
|
|
408
|
+
* Apply them to router utils with {@link ContractOptionsUtilsPlugin}.
|
|
409
|
+
*
|
|
410
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin TanStack Query Contract Options Plugin Docs}
|
|
411
|
+
*/
|
|
412
|
+
declare function tanstackQuery<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(options: TanstackQueryMetaOptions<ClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>): TanstackQueryMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>;
|
|
413
|
+
declare function getTanstackQueryMeta(procedureOrLazy: {
|
|
414
|
+
'~orpc': {
|
|
415
|
+
meta: Meta;
|
|
416
|
+
};
|
|
417
|
+
}): TanstackQueryMetaOptions<ClientContext, unknown, unknown, ThrowableError> | undefined;
|
|
418
|
+
/**
|
|
419
|
+
* Router utils plugin that applies base options defined via {@link tanstackQuery}
|
|
420
|
+
* on the given router contract. Meta options act as the base layer: options defined
|
|
421
|
+
* on the utils override them, and utils interceptors run after meta interceptors.
|
|
422
|
+
*
|
|
423
|
+
* The contract shape must match the client the utils are created from,
|
|
424
|
+
* so pass the root router contract when utils paths start from the root.
|
|
425
|
+
*
|
|
426
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin TanStack Query Contract Options Plugin Docs}
|
|
427
|
+
*/
|
|
428
|
+
declare class ContractOptionsUtilsPlugin<T extends AnyNestedClient = AnyNestedClient> implements RouterUtilsPlugin<T> {
|
|
429
|
+
private readonly contract;
|
|
430
|
+
readonly name = "~contract-options";
|
|
431
|
+
constructor(contract: RouterContract);
|
|
432
|
+
initProcedureOptions(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export { CompositeRouterUtilsPlugin, ContractOptionsUtilsPlugin, OPERATION_CONTEXT_SYMBOL, ProcedureUtils, SharedUtils, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createRouterUtils, createRouterUtils as createTanstackQueryUtils, generateOperationKey, getTanstackQueryMeta, isProcedureUtilsOptions, mergeProcedureUtilsOptions, serializableStreamedQuery, tanstackQuery };
|
|
436
|
+
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, RouterUtilsPlugin, RouterUtilsScoped, SerializableStreamedQueryOptions, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut, TanstackQueryMetaOptions, TanstackQueryMetaPlugin, OperationContext as TanstackQueryOperationContext };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { resolveBasePathMeta } from '@orpc/contract';
|
|
2
|
-
import { sortPlugins, stringifyJSON, resolveMaybeOptionalOptions, intercept, toArray, isAsyncIteratorObject, bindMethods, getOrBind, get
|
|
1
|
+
import { resolveBasePathMeta, getRouterContract, ProcedureContract } from '@orpc/contract';
|
|
2
|
+
import { sortPlugins, stringifyJSON, resolveMaybeOptionalOptions, intercept, toArray, isAsyncIteratorObject, isTypescriptObject, bindMethods, getOrBind, get } from '@orpc/shared';
|
|
3
3
|
import { RECURSIVE_CLIENT_UNWRAP_KEYS } from '@orpc/client';
|
|
4
4
|
import { skipToken } from '@tanstack/query-core';
|
|
5
5
|
|
|
@@ -128,6 +128,75 @@ function limitArraySize(items, maxSize) {
|
|
|
128
128
|
|
|
129
129
|
const OPERATION_CONTEXT_SYMBOL = Symbol.for("ORPC_TANSTACK_QUERY_OPERATION_CONTEXT");
|
|
130
130
|
|
|
131
|
+
const PROCEDURE_UTILS_INTERCEPTOR_KEYS = [
|
|
132
|
+
"queryInterceptors",
|
|
133
|
+
"streamedInterceptors",
|
|
134
|
+
"liveInterceptors",
|
|
135
|
+
"infiniteInterceptors",
|
|
136
|
+
"mutationInterceptors"
|
|
137
|
+
];
|
|
138
|
+
const PROCEDURE_UTILS_MODIFIER_KEYS = [
|
|
139
|
+
"queryKey",
|
|
140
|
+
"queryOptions",
|
|
141
|
+
"streamedKey",
|
|
142
|
+
"streamedOptions",
|
|
143
|
+
"liveKey",
|
|
144
|
+
"liveOptions",
|
|
145
|
+
"infiniteKey",
|
|
146
|
+
"infiniteOptions",
|
|
147
|
+
"mutationKey",
|
|
148
|
+
"mutationOptions"
|
|
149
|
+
];
|
|
150
|
+
function isProcedureUtilsOptions(value) {
|
|
151
|
+
if (!isTypescriptObject(value)) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
for (const key in value) {
|
|
155
|
+
if (value[key] === void 0) {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (key === "prefix") {
|
|
159
|
+
if (typeof value[key] !== "string") {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
} else if (PROCEDURE_UTILS_INTERCEPTOR_KEYS.includes(key)) {
|
|
163
|
+
if (!Array.isArray(value[key]) || value[key].some((i) => typeof i !== "function")) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
} else if (PROCEDURE_UTILS_MODIFIER_KEYS.includes(key)) {
|
|
167
|
+
if (!isTypescriptObject(value[key])) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
function mergeProcedureUtilsModifier(base, override) {
|
|
175
|
+
if (typeof base !== "function" && typeof override !== "function") {
|
|
176
|
+
return { ...base, ...override };
|
|
177
|
+
}
|
|
178
|
+
const applyBase = typeof base === "function" ? base : (options) => ({ ...base, ...options });
|
|
179
|
+
const applyOverride = typeof override === "function" ? override : (options) => ({ ...override, ...options });
|
|
180
|
+
return (options) => applyOverride(applyBase(options));
|
|
181
|
+
}
|
|
182
|
+
function mergeProcedureUtilsOptions(base, override) {
|
|
183
|
+
const merged = { ...base, ...override };
|
|
184
|
+
for (const key of PROCEDURE_UTILS_INTERCEPTOR_KEYS) {
|
|
185
|
+
const baseValue = base[key];
|
|
186
|
+
const overrideValue = override[key];
|
|
187
|
+
if (baseValue && overrideValue) {
|
|
188
|
+
merged[key] = [...baseValue, ...overrideValue];
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
for (const key of PROCEDURE_UTILS_MODIFIER_KEYS) {
|
|
192
|
+
const baseValue = base[key];
|
|
193
|
+
const overrideValue = override[key];
|
|
194
|
+
if (baseValue && overrideValue) {
|
|
195
|
+
merged[key] = mergeProcedureUtilsModifier(baseValue, overrideValue);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return merged;
|
|
199
|
+
}
|
|
131
200
|
class ProcedureUtils extends SharedUtils {
|
|
132
201
|
/**
|
|
133
202
|
* Calling corresponding procedure client
|
|
@@ -448,15 +517,17 @@ function createRouterUtilsInternal(client, options, plugin) {
|
|
|
448
517
|
const utils = typeof client === "function" && (options.scoped === void 0 || isProcedureUtilsOptions(options.scoped)) ? bindMethods(new ProcedureUtils(
|
|
449
518
|
path,
|
|
450
519
|
client,
|
|
451
|
-
plugin.initProcedureOptions(path,
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
520
|
+
plugin.initProcedureOptions(path, mergeProcedureUtilsOptions(
|
|
521
|
+
{
|
|
522
|
+
prefix: options.prefix,
|
|
523
|
+
queryInterceptors: options.queryInterceptors,
|
|
524
|
+
streamedInterceptors: options.streamedInterceptors,
|
|
525
|
+
liveInterceptors: options.liveInterceptors,
|
|
526
|
+
infiniteInterceptors: options.infiniteInterceptors,
|
|
527
|
+
mutationInterceptors: options.mutationInterceptors
|
|
528
|
+
},
|
|
529
|
+
options.scoped ?? {}
|
|
530
|
+
))
|
|
460
531
|
)) : bindMethods(new SharedUtils(path, options));
|
|
461
532
|
const recursive = new Proxy(utils, {
|
|
462
533
|
get(target, prop) {
|
|
@@ -485,27 +556,6 @@ function createRouterUtilsInternal(client, options, plugin) {
|
|
|
485
556
|
});
|
|
486
557
|
return recursive;
|
|
487
558
|
}
|
|
488
|
-
function isProcedureUtilsOptions(value) {
|
|
489
|
-
if (!isTypescriptObject(value)) {
|
|
490
|
-
return false;
|
|
491
|
-
}
|
|
492
|
-
if (value.queryInterceptors !== void 0 && !Array.isArray(value.queryInterceptors)) {
|
|
493
|
-
return false;
|
|
494
|
-
}
|
|
495
|
-
if (value.streamedInterceptors !== void 0 && !Array.isArray(value.streamedInterceptors)) {
|
|
496
|
-
return false;
|
|
497
|
-
}
|
|
498
|
-
if (value.liveInterceptors !== void 0 && !Array.isArray(value.liveInterceptors)) {
|
|
499
|
-
return false;
|
|
500
|
-
}
|
|
501
|
-
if (value.infiniteInterceptors !== void 0 && !Array.isArray(value.infiniteInterceptors)) {
|
|
502
|
-
return false;
|
|
503
|
-
}
|
|
504
|
-
if (value.mutationInterceptors !== void 0 && !Array.isArray(value.mutationInterceptors)) {
|
|
505
|
-
return false;
|
|
506
|
-
}
|
|
507
|
-
return true;
|
|
508
|
-
}
|
|
509
559
|
|
|
510
560
|
function createContractUtilsFactory(clientFactory, options) {
|
|
511
561
|
const factory = (contract) => {
|
|
@@ -524,4 +574,37 @@ function createContractJsonifiedUtilsFactory(clientFactory, options) {
|
|
|
524
574
|
return createContractUtilsFactory(clientFactory, options);
|
|
525
575
|
}
|
|
526
576
|
|
|
527
|
-
|
|
577
|
+
function tanstackQuery(options) {
|
|
578
|
+
return {
|
|
579
|
+
name: "~tanstack-query",
|
|
580
|
+
init(meta) {
|
|
581
|
+
const current = meta["~tanstack-query"];
|
|
582
|
+
return {
|
|
583
|
+
...meta,
|
|
584
|
+
"~tanstack-query": current ? mergeProcedureUtilsOptions(current, options) : options
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
function getTanstackQueryMeta(procedureOrLazy) {
|
|
590
|
+
return procedureOrLazy["~orpc"].meta["~tanstack-query"];
|
|
591
|
+
}
|
|
592
|
+
class ContractOptionsUtilsPlugin {
|
|
593
|
+
constructor(contract) {
|
|
594
|
+
this.contract = contract;
|
|
595
|
+
}
|
|
596
|
+
name = "~contract-options";
|
|
597
|
+
initProcedureOptions(path, options) {
|
|
598
|
+
const procedure = getRouterContract(this.contract, path);
|
|
599
|
+
if (!(procedure instanceof ProcedureContract)) {
|
|
600
|
+
return options;
|
|
601
|
+
}
|
|
602
|
+
const base = getTanstackQueryMeta(procedure);
|
|
603
|
+
if (!base) {
|
|
604
|
+
return options;
|
|
605
|
+
}
|
|
606
|
+
return mergeProcedureUtilsOptions(base, options);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
export { CompositeRouterUtilsPlugin, ContractOptionsUtilsPlugin, OPERATION_CONTEXT_SYMBOL, ProcedureUtils, SharedUtils, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createRouterUtils, createRouterUtils as createTanstackQueryUtils, generateOperationKey, getTanstackQueryMeta, isProcedureUtilsOptions, mergeProcedureUtilsOptions, serializableStreamedQuery, tanstackQuery };
|
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.20",
|
|
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/contract": "2.0.0-beta.
|
|
33
|
-
"@orpc/
|
|
34
|
-
"@orpc/
|
|
35
|
-
"@orpc/
|
|
32
|
+
"@orpc/contract": "2.0.0-beta.20",
|
|
33
|
+
"@orpc/openapi": "2.0.0-beta.20",
|
|
34
|
+
"@orpc/client": "2.0.0-beta.20",
|
|
35
|
+
"@orpc/shared": "2.0.0-beta.20"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@angular/core": "^22.0.1",
|