import { ClientContext, Client, AnyNestedClient, InferClientContext, InferClientError } from '@orpc/client'; import { RouterContract, RouterContractClient, ContractClientFactory, AnySchema, ErrorMap, MetaPlugin, Meta, InferSchemaInput, InferSchemaOutput, ORPCErrorFromErrorMap } from '@orpc/contract'; import { JsonifiedClient } from '@orpc/openapi'; import { Promisable, PartialDeep, Interceptor, PromiseWithError, MaybeOptionalOptions, OrderablePlugin, Public, ThrowableError } from '@orpc/shared'; import { EntryKey, UseQueryOptions, UseMutationOptionsGlobal, DefineQueryOptions, UseInfiniteQueryData, DefineInfiniteQueryOptions, UseMutationOptions, DefineQueryOptionsTagged, DefineInfiniteQueryOptionsTagged, DefineMutationOptionsTagged, UseInfiniteQueryFnContext, EntryKeyTagged, _EmptyObject } from '@pinia/colada'; type InferStreamedQueryOutput = TOutput extends AsyncIterable ? U[] : never; type InferLiveQueryOutput = TOutput extends AsyncIterable ? U : never; type UseQueryFnContext = Parameters['query']>[0]; /** * The context passed to the mutation function, including the merged * `UseMutationGlobalContext` values provided by a global `onMutate` hook. */ type UseMutationFnContext = Parameters>[2]; declare const OPERATION_CONTEXT_SYMBOL: unique symbol; type OperationType = 'query' | 'streamed' | 'live' | 'infinite' | 'mutation'; interface OperationContext { [OPERATION_CONTEXT_SYMBOL]?: { key: EntryKey; type: OperationType; }; } type QueryKeyOptions = (undefined extends TInput ? { input?: TInput; } : { input: TInput; }) | { key: EntryKey; }; type QueryOptionsIn = (undefined extends TInput ? { input?: TInput; } : { input: TInput; }) & (object extends TClientContext ? { context?: TClientContext; } : { context: TClientContext; }) & Omit, 'key' | 'query'> & Partial, 'key' | 'query'>>; type QueryOptionsOut = DefineQueryOptionsTagged; type StreamedKeyOptions = ((undefined extends TInput ? { input?: TInput; } : { input: TInput; }) & { fnOptions?: SerializableStreamedQueryOptions; }) | { key: EntryKey; }; type StreamedOptionsIn = QueryOptionsIn & { fnOptions?: SerializableStreamedQueryOptions; }; type StreamedOptionsOut = QueryOptionsOut; type InfiniteKeyOptions = Pick, 'input' | 'initialPageParam'> | { key: EntryKey; }; type InfiniteOptionsIn | undefined> = { input: (pageParam: TPageParam) => TInput; } & (object extends TClientContext ? { context?: TClientContext; } : { context: TClientContext; }) & Omit, 'key' | 'query'> & Partial, 'key' | 'query'>>; type InfiniteOptionsOut | undefined> = DefineInfiniteQueryOptionsTagged; type MutationKeyOptions = Pick, 'key'>; type MutationOptionsIn> = (object extends TClientContext ? { context?: TClientContext; } : { context: TClientContext; }) & Omit, 'mutation'> & Partial, 'mutation'>>; type MutationOptionsOut> = DefineMutationOptionsTagged; interface SerializableStreamedQueryOptions { /** * Determines how data is handled when the query is fetched again * * - `'reset'`: Clears existing data and returns the query to a pending state. * - `'append'`: Adds new streamed chunks to the existing data. * - `'replace'`: Buffers streamed data and replaces the cache after the stream completes. * * @default 'reset' */ refetchMode?: 'append' | 'reset' | 'replace'; /** * Limits the number of data chunks stored in the query result. * Older chunks are removed when the limit is reached. * * @default Number.POSITIVE_INFINITY (unlimited) */ maxChunks?: number; } /** * A Pinia Colada query function that accumulates streamed chunks into an array, * publishing each chunk to the cache entry as it arrives. * * Inspired by [TanStack Query streamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery) where: * - Options are serializable * - The output is predictable */ declare function serializableStreamedQuery(queryFn: (context: UseQueryFnContext) => Promisable>, { refetchMode, maxChunks }?: SerializableStreamedQueryOptions): (context: UseQueryFnContext) => Promise; interface OperationKeyPrefixOptions { /** * Prepended as the first element of the key when present. * Use this to avoid key conflicts when multiple router utils share the same client. */ prefix?: string; } type OperationKeyOptions = OperationKeyPrefixOptions & { type?: TType; input?: PartialDeep; fnOptions?: TType extends 'streamed' ? SerializableStreamedQueryOptions : never; }; type OperationKey = EntryKey & ([path: string[], options: Omit, 'prefix'>] | [prefix: string, path: string[], options: Omit, 'prefix'>]); /** * Generate a Pinia Colada entry key for a procedure. * * The input is serialized to JSON-compatible values because Pinia Colada * requires entry keys to be serializable. * * @see {@link https://orpc.dev/docs/integrations/pinia-colada#query-mutation-key Pinia Colada Query/Mutation Key Docs} */ declare function generateOperationKey(path: string[], options?: OperationKeyOptions): OperationKey; declare class SharedUtils { protected readonly path: string[]; protected readonly options: OperationKeyPrefixOptions; constructor(path: string[], options: OperationKeyPrefixOptions); /** * Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc. * * @see {@link https://orpc.dev/docs/integrations/pinia-colada#query-mutation-key Pinia Colada Query/Mutation Key Docs} */ key(options?: Omit, 'prefix'>): OperationKey; } interface ProcedureUtilsQueryInterceptorOptions { path: string[]; context: TClientContext & OperationContext; input: TInput; fnContext: UseQueryFnContext; } type ProcedureUtilsQueryInterceptor = Interceptor, PromiseWithError>; interface ProcedureUtilsStreamedInterceptorOptions extends ProcedureUtilsQueryInterceptorOptions { } type ProcedureUtilsStreamedInterceptor = Interceptor, PromiseWithError, TError>>; interface ProcedureUtilsLiveInterceptorOptions extends ProcedureUtilsQueryInterceptorOptions { } type ProcedureUtilsLiveInterceptor = Interceptor, PromiseWithError, TError>>; interface ProcedureUtilsInfiniteInterceptorOptions { path: string[]; context: TClientContext & OperationContext; input: TInput; fnContext: UseInfiniteQueryFnContext; } type ProcedureUtilsInfiniteInterceptor = Interceptor, PromiseWithError>; interface ProcedureUtilsMutationInterceptorOptions { path: string[]; context: TClientContext & OperationContext; input: TInput; fnContext: UseMutationFnContext; } type ProcedureUtilsMutationInterceptor = Interceptor, PromiseWithError>; /** * Can be partial options for spread-merged options, * or a function that receives per-call options and returns overridden this.options. */ type ProcedureUtilsModifier = Partial | ((options: T) => T); interface ProcedureUtilsOptions extends OperationKeyPrefixOptions { /** * Key options modifier for .queryKey and .queryOptions * Can be partial options or a function that receives per-call options and returns override this.options. */ queryKey?: ProcedureUtilsModifier>; /** * Interceptors that intercept query inside .queryOptions, guaranteed to be executed. */ queryInterceptors?: ProcedureUtilsQueryInterceptor[]; /** * Options modifier for .queryOptions * Can be partial options or a function that receives per-call options and returns override this.options. */ queryOptions?: ProcedureUtilsModifier>; /** * Key options modifier for .streamedKey and .streamedOptions * Can be partial options or a function that receives per-call options and returns override this.options. */ streamedKey?: ProcedureUtilsModifier>; /** * Interceptors that intercept query inside .streamedOptions, guaranteed to be executed. */ streamedInterceptors?: ProcedureUtilsStreamedInterceptor[]; /** * Options modifier for .streamedOptions * Can be partial options or a function that receives per-call options and returns override this.options. */ streamedOptions?: ProcedureUtilsModifier, TError, InferStreamedQueryOutput | undefined>>; /** * Key options modifier for .liveKey and .liveOptions * Can be partial options or a function that receives per-call options and returns override this.options. */ liveKey?: ProcedureUtilsModifier>; /** * Interceptors that intercept query inside .liveOptions, guaranteed to be executed. */ liveInterceptors?: ProcedureUtilsLiveInterceptor[]; /** * Options modifier for .liveOptions * Can be partial options or a function that receives per-call options and returns override this.options. */ liveOptions?: ProcedureUtilsModifier, TError, InferLiveQueryOutput | undefined>>; /** * Key options modifier for .infiniteKey and .infiniteOptions * Can be partial options or a function that receives per-call options and returns override this.options. */ infiniteKey?: ProcedureUtilsModifier>; /** * Interceptors that intercept query inside .infiniteOptions, guaranteed to be executed. */ infiniteInterceptors?: ProcedureUtilsInfiniteInterceptor[]; /** * Options modifier for .infiniteOptions * Can be partial options or a function that receives per-call options and returns override this.options. */ infiniteOptions?: ProcedureUtilsModifier | undefined>>; /** * Key options modifier for .mutationKey and .mutationOptions * Can be partial options or a function that receives per-call options and returns override this.options. */ mutationKey?: ProcedureUtilsModifier>; /** * Interceptors that intercept mutation inside .mutationOptions, guaranteed to be executed. */ mutationInterceptors?: ProcedureUtilsMutationInterceptor[]; /** * Options modifier for .mutationOptions * Can be partial options or a function that receives per-call options and returns override this.options. */ mutationOptions?: ProcedureUtilsModifier>>; } declare function isProcedureUtilsOptions(value: unknown): value is ProcedureUtilsOptions; /** * Merge two procedure utils options where `override` takes priority. * A key explicitly set to `undefined` in `override` resets the base value. * When both sides define a key: interceptors are concatenated (base ones run first), * modifiers are spread-merged when both are plain objects and composed (base applied * first) otherwise, with plain objects applied as regular spread merges. */ declare function mergeProcedureUtilsOptions(base: ProcedureUtilsOptions, override: ProcedureUtilsOptions): ProcedureUtilsOptions; declare class ProcedureUtils extends SharedUtils { protected readonly options: ProcedureUtilsOptions; /** * Calling corresponding procedure client * * @see {@link https://orpc.dev/docs/integrations/pinia-colada#calling-procedure-clients Pinia Colada Calling Procedure Client Docs} */ call: Client; constructor(path: string[], client: Client, options?: ProcedureUtilsOptions); /** * Generate a **full matching** key for useQuery/... * * @see {@link https://orpc.dev/docs/integrations/pinia-colada#query-mutation-key Pinia Colada Query/Mutation Key Docs} */ queryKey(...rest: MaybeOptionalOptions>): EntryKeyTagged; /** * Generate options used for useQuery/... * * @see {@link https://orpc.dev/docs/integrations/pinia-colada#query-options-utility Pinia Colada Query Options Utility Docs} */ queryOptions(...rest: MaybeOptionalOptions>): NoInfer>; /** * Generate a **full matching** key for [Streamed Query Options](https://orpc.dev/docs/integrations/pinia-colada#streamed-query-options-utility). * * @see {@link https://orpc.dev/docs/integrations/pinia-colada#query-mutation-key Pinia Colada Query/Mutation Key Docs} */ streamedKey(...rest: MaybeOptionalOptions>): EntryKeyTagged, TError>; /** * Configure queries for [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object). * The resulting data is an array of chunks, and each new chunk is appended as it arrives. * Works with `useQuery` and any other API that accepts query options. */ streamedOptions | undefined = undefined>(...rest: MaybeOptionalOptions, TError, UInitialData>>): NoInfer, TError, UInitialData>>; /** * Generate a **full matching** key for [Live Query Options](https://orpc.dev/docs/integrations/pinia-colada#live-query-options-utility). * * @see {@link https://orpc.dev/docs/integrations/pinia-colada#query-mutation-key Pinia Colada Query/Mutation Key Docs} */ liveKey(...rest: MaybeOptionalOptions>): EntryKeyTagged, TError>; /** * Configure live queries for [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object). * Unlike `.streamedOptions` which accumulates chunks, live queries replace the entire result with each new chunk received. * Works with `useQuery` and any other API that accepts query options. */ liveOptions | undefined = undefined>(...rest: MaybeOptionalOptions, TError, UInitialData>>): NoInfer, TError, UInitialData>>; /** * Generate a **full matching** key for useInfiniteQuery/... * * @see {@link https://orpc.dev/docs/integrations/pinia-colada#query-mutation-key Pinia Colada Query/Mutation Key Docs} */ infiniteKey(optionsIn: InfiniteKeyOptions): EntryKeyTagged, TError>; /** * Generate options used for useInfiniteQuery/... * * @see {@link https://orpc.dev/docs/integrations/pinia-colada#infinite-query-options-utility Pinia Colada Infinite Query Options Utility Docs} */ infiniteOptions | undefined = undefined>(optionsIn: InfiniteOptionsIn): NoInfer>; /** * Generate a **full matching** key for useMutation/... * * @see {@link https://orpc.dev/docs/integrations/pinia-colada#query-mutation-key Pinia Colada Query/Mutation Key Docs} */ mutationKey(...rest: MaybeOptionalOptions>): MutationOptionsOut['key']; /** * Generate options used for useMutation/... * * @see {@link https://orpc.dev/docs/integrations/pinia-colada#mutation-options Pinia Colada Mutation Options Docs} */ mutationOptions = _EmptyObject>(...rest: MaybeOptionalOptions>): NoInfer>; } interface RouterUtilsPlugin extends OrderablePlugin { /** * Initializes the router utils plugin and returns updated router utils options. * Called once per plugin instance during composition. * * This method allows plugins to wrap, extend, or transform router utils options, * such as interceptors or configuration. * * @param options - The current router utils options from previous plugins or base configuration * @returns Transformed router utils options with this plugin's modifications applied * * @example * ```ts * init(options) { * return { * ...options, * mutationInterceptors: [...(options.mutationInterceptors ?? []), myInterceptor] * } * } * ``` */ init?(options: RouterUtilsOptions): RouterUtilsOptions; /** * Initializes per-procedure router utils options and returns updated options. * Called once per procedure utils instance during composition. * * This method allows plugins to customize merged procedure-specific defaults, * such as query or mutation options, for the current path. * * @param path - The current procedure path * @param options - The merged procedure utils options for the current procedure * @returns Transformed procedure utils options with this plugin's modifications applied */ initProcedureOptions?(path: string[], options: ProcedureUtilsOptions, any, any, InferClientError>): ProcedureUtilsOptions, any, any, InferClientError>; } declare class CompositeRouterUtilsPlugin implements RouterUtilsPlugin { protected readonly plugins: RouterUtilsPlugin[]; readonly name = "~composite"; constructor(plugins?: RouterUtilsPlugin[]); init(options: RouterUtilsOptions): RouterUtilsOptions; initProcedureOptions(path: string[], options: ProcedureUtilsOptions, any, any, InferClientError>): ProcedureUtilsOptions, any, any, InferClientError>; } type RouterUtils = T extends Client ? Public> : { [K in keyof T]: T[K] extends AnyNestedClient ? RouterUtils : never; } & Public>; type RouterUtilsScoped = T extends Client ? ProcedureUtilsOptions : { [K in keyof T]?: T[K] extends AnyNestedClient ? RouterUtilsScoped : never; }; interface RouterUtilsOptions extends OperationKeyPrefixOptions { /** * Base path for all query keys. * * @internal */ path?: string[] | undefined; /** * Interceptors that intercept query inside .queryOptions */ queryInterceptors?: ProcedureUtilsQueryInterceptor, unknown, unknown, InferClientError>[]; /** * Interceptors that intercept query inside .streamedOptions */ streamedInterceptors?: ProcedureUtilsStreamedInterceptor, unknown, unknown, InferClientError>[]; /** * Interceptors that intercept query inside .liveOptions */ liveInterceptors?: ProcedureUtilsLiveInterceptor, unknown, unknown, InferClientError>[]; /** * Interceptors that intercept query inside .infiniteOptions */ infiniteInterceptors?: ProcedureUtilsInfiniteInterceptor, unknown, unknown, InferClientError>[]; /** * Interceptors that intercept mutation inside .mutationOptions */ mutationInterceptors?: ProcedureUtilsMutationInterceptor, unknown, unknown, InferClientError>[]; /** * Per-procedure options following the shape of the router. * Allows fine-grained configuration of individual procedure utils * without affecting the rest of the router. */ scoped?: RouterUtilsScoped | undefined; /** * Plugins to extend router utils behavior. */ plugins?: RouterUtilsPlugin[] | undefined; } /** * Create a router utils from a client. * * @info Both client-side and server-side clients are supported. * @see {@link https://orpc.dev/docs/integrations/pinia-colada Pinia Colada Docs} */ declare function createRouterUtils(client: T, options?: NoInfer>): RouterUtils; interface ContractUtilsFactory { (contract: T): RouterUtils>; } interface ContractUtilsFactoryOptions extends Omit>, 'path'> { } declare function createContractUtilsFactory(clientFactory: ContractClientFactory, options: ContractUtilsFactoryOptions): ContractUtilsFactory; interface ContractJsonifiedUtilsFactory { (contract: T): RouterUtils>>; } interface ContractJsonifiedUtilsFactoryOptions extends Omit>>, 'path'> { } declare function createContractJsonifiedUtilsFactory(clientFactory: ContractClientFactory, options: ContractJsonifiedUtilsFactoryOptions): ContractJsonifiedUtilsFactory; /** * A Pinia Colada query function that publishes each streamed chunk to the * cache entry as it arrives, replacing the previous value. */ declare function liveQuery(queryFn: (context: UseQueryFnContext) => Promisable>): (context: UseQueryFnContext) => Promise; type PiniaColadaMetaOptions = Omit, 'prefix'>; interface PiniaColadaMetaPlugin extends MetaPlugin { name: '~pinia-colada'; } /** * Define base Pinia Colada options and interceptors on a procedure contract. * Applied multiple times, later options are spread-merged with higher priority * while interceptors are concatenated. A key explicitly set to `undefined` * resets the value from earlier applications instead of merging. * * Apply them to router utils with {@link ContractOptionsUtilsPlugin}. * * @see {@link https://orpc.dev/docs/integrations/pinia-colada#contract-options-plugin Pinia Colada Contract Options Plugin Docs} */ declare function piniaColada(options: PiniaColadaMetaOptions, InferSchemaOutput, ORPCErrorFromErrorMap | ThrowableError>): PiniaColadaMetaPlugin; declare function getPiniaColadaMeta(procedureOrLazy: { '~orpc': { meta: Meta; }; }): PiniaColadaMetaOptions | undefined; /** * Router utils plugin that applies base options defined via {@link piniaColada} * on the given router contract. Meta options act as the base layer: options defined * on the utils override them, and utils interceptors run after meta interceptors. * * The contract shape must match the client the utils are created from, * so pass the root router contract when utils paths start from the root. * * @see {@link https://orpc.dev/docs/integrations/pinia-colada#contract-options-plugin Pinia Colada Contract Options Plugin Docs} */ declare class ContractOptionsUtilsPlugin implements RouterUtilsPlugin { private readonly contract; readonly name = "~contract-options"; constructor(contract: RouterContract); initProcedureOptions(path: string[], options: ProcedureUtilsOptions, any, any, InferClientError>): ProcedureUtilsOptions, any, any, InferClientError>; } export { CompositeRouterUtilsPlugin, ContractOptionsUtilsPlugin, OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, ProcedureUtils, SharedUtils, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createRouterUtils as createPiniaColadaUtils, createRouterUtils, generateOperationKey, getPiniaColadaMeta, isProcedureUtilsOptions, liveQuery, mergeProcedureUtilsOptions, piniaColada, serializableStreamedQuery }; export type { ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractUtilsFactory, ContractUtilsFactoryOptions, InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OperationContext, OperationKey, OperationKeyOptions, OperationKeyPrefixOptions, OperationType, PiniaColadaMetaOptions, PiniaColadaMetaPlugin, OperationContext as PiniaColadaOperationContext, ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, ProcedureUtilsLiveInterceptorOptions, ProcedureUtilsModifier, ProcedureUtilsMutationInterceptor, ProcedureUtilsMutationInterceptorOptions, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsQueryInterceptorOptions, ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, RouterUtils, RouterUtilsOptions, RouterUtilsPlugin, RouterUtilsScoped, SerializableStreamedQueryOptions, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut, UseMutationFnContext, UseQueryFnContext };