From a8cf716110af939aa108ab03698e7cedfd8e23a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=8Bnh=20L=C3=AA?= Date: Sat, 21 Nov 2026 15:49:53 +0700 Subject: [PATCH 01/11] refactor(tanstack-query, pinia-colada, swr, msw)!: unify integration naming and trim exports - tanstack-query: rename the streamed option `queryFnOptions` to `fnOptions` - export the factory, operation context symbol and type only under the package-specific names (drop `createRouterUtils`, `OPERATION_CONTEXT_SYMBOL`, `OperationContext`) - export `ProcedureUtils`, `SharedUtils` and `HTTPProcedureUtils` as types only - stop exporting the `*InRest` helper types; keep the `*Internal` recursion types, marked @internal, because declaration emit of generic code needs them - tanstack-query: `createHydrationOptions` and `createStructuralSharing` take `{ serializer }` instead of a positional serializer - pinia-colada: point the `createORPCVueColadaUtils` deprecation at `createPiniaColadaUtils` --- .../blog/nextjs-ssr-orpc-tanstack-query.mdx | 4 +- .../docs/integrations/tanstack-query.mdx | 12 +++--- apps/content/docs/migrations/from-v1.mdx | 8 +++- packages/msw/src/http-router-utils.ts | 6 +++ packages/msw/src/index.test.ts | 6 +++ packages/msw/src/index.ts | 10 +++-- packages/pinia-colada/src/index.test.ts | 10 ++++- packages/pinia-colada/src/index.ts | 40 +++++++++++++++---- packages/pinia-colada/src/router-utils.ts | 12 ++++++ packages/pinia-colada/tests/ssr.test.tsx | 6 +-- packages/swr/src/index.test.ts | 10 ++++- packages/swr/src/index.ts | 27 +++++++++---- packages/swr/src/router-utils.ts | 6 +++ packages/tanstack-query/src/index.test.ts | 9 +++++ packages/tanstack-query/src/index.ts | 36 +++++++++++++---- .../src/procedure-utils.test-d.ts | 12 +++--- .../src/procedure-utils.test.ts | 6 +-- .../tanstack-query/src/procedure-utils.ts | 10 ++--- packages/tanstack-query/src/router-utils.ts | 12 ++++++ packages/tanstack-query/src/ssr.test-d.ts | 8 +++- packages/tanstack-query/src/ssr.test.ts | 6 +-- packages/tanstack-query/src/ssr.ts | 16 ++++++-- .../src/structural-sharing.test.ts | 18 ++++----- .../tanstack-query/src/structural-sharing.ts | 14 ++++++- packages/tanstack-query/src/types.ts | 4 +- packages/tanstack-query/tests/e2e.test.tsx | 4 +- playgrounds/bun/src/components/chat-room.tsx | 2 +- playgrounds/bun/src/lib/orpc.ts | 4 +- .../cloudflare/src/components/chat-room.tsx | 2 +- playgrounds/cloudflare/src/lib/orpc.ts | 4 +- playgrounds/next/src/components/chat-room.tsx | 2 +- playgrounds/next/src/lib/orpc.ts | 4 +- playgrounds/next/src/lib/query-client.ts | 2 +- 33 files changed, 246 insertions(+), 86 deletions(-) diff --git a/apps/content/blog/nextjs-ssr-orpc-tanstack-query.mdx b/apps/content/blog/nextjs-ssr-orpc-tanstack-query.mdx index 5b6ea7795e..3dc3b0b609 100644 --- a/apps/content/blog/nextjs-ssr-orpc-tanstack-query.mdx +++ b/apps/content/blog/nextjs-ssr-orpc-tanstack-query.mdx @@ -214,7 +214,7 @@ function createQueryClient(): QueryClient { queries: { staleTime: 60 * 1000, // > 0 to prevent immediate refetching on mount }, - ...createHydrationOptions(serializer), + ...createHydrationOptions({ serializer }), }, }) } @@ -341,7 +341,7 @@ import { orpc } from '@/lib/orpc' export function DiscoveryFeed() { const { data: events = [] } = useQuery( orpc.planet.feed.streamedOptions({ - queryFnOptions: { maxChunks: 10 }, // keep only the 10 newest events + fnOptions: { maxChunks: 10 }, // keep only the 10 newest events retry: true, // reconnect forever if the stream drops }), ) diff --git a/apps/content/docs/integrations/tanstack-query.mdx b/apps/content/docs/integrations/tanstack-query.mdx index df70f55a2f..8e0b352c96 100644 --- a/apps/content/docs/integrations/tanstack-query.mdx +++ b/apps/content/docs/integrations/tanstack-query.mdx @@ -80,7 +80,7 @@ Use `.streamedOptions` to build query options for an [AsyncIteratorObject](/docs const query = useQuery( orpc.streamed.streamedOptions({ input: { id: 123 }, - queryFnOptions: { + fnOptions: { refetchMode: 'reset', maxChunks: 3, // Keep only the last 3 events }, @@ -99,10 +99,10 @@ For a loading state, call `queryClient.resetQueries({ queryKey })` before refetc ::: :::warning -`queryFnOptions` is part of the query key, except for default values: +`fnOptions` is part of the query key, except for default values: - Queries with different options get separate cache entries and separate streams. To share one, use the same options, and show fewer chunks with `select`, e.g. `select: data => data.slice(-3)`. -- To read or write the cache by key, pass the same options: `streamedKey({ input, queryFnOptions })`. +- To read or write the cache by key, pass the same options: `streamedKey({ input, fnOptions })`. ::: ## Live Query Options @@ -561,7 +561,7 @@ const queryClient = new QueryClient({ }) ``` -With an RPC [key serializer](#key-serializer), equal instances of [custom types](/docs/rpc/serializer#custom-serializers) are kept too, compared by what their handler serializes them to. For queries not built with oRPC utils, pass it to `createStructuralSharing(serializer)`. +With an RPC [key serializer](#key-serializer), equal instances of [custom types](/docs/rpc/serializer#custom-serializers) are kept too, compared by what their handler serializes them to. For queries not built with oRPC utils, pass it to `createStructuralSharing({ serializer })`. ## Server-Side Rendering (SSR) @@ -569,7 +569,7 @@ When [server-side rendering](/docs/recipes/optimizing-ssr) with [TanStack Query ### Custom Serializers -TanStack Query dehydrates query data as plain JSON, which cannot represent oRPC types such as `Date`, `BigInt`, `Set`, or `Map`. Pass your [RPC Serializer](/docs/rpc/serializer#custom-serializers) to `createHydrationOptions` to keep them intact. +TanStack Query dehydrates query data as plain JSON, which cannot represent oRPC types such as `Date`, `BigInt`, `Set`, or `Map`. Pass your [RPC Serializer](/docs/rpc/serializer#custom-serializers) to `createHydrationOptions` as the `serializer` option to keep them intact. ```ts import { createHydrationOptions } from '@orpc/tanstack-query' @@ -580,7 +580,7 @@ const queryClient = new QueryClient({ queries: { staleTime: 60 * 1000, // > 0 to prevent immediate refetching on mount }, - ...createHydrationOptions(serializer), // dehydrate.serializeData and hydrate.deserializeData + ...createHydrationOptions({ serializer }), // dehydrate.serializeData and hydrate.deserializeData }, }) ``` diff --git a/apps/content/docs/migrations/from-v1.mdx b/apps/content/docs/migrations/from-v1.mdx index fee840ee12..c9c94df29b 100644 --- a/apps/content/docs/migrations/from-v1.mdx +++ b/apps/content/docs/migrations/from-v1.mdx @@ -1193,9 +1193,12 @@ orpc.live.experimental_liveOptions({ input: {} }) `experimental_defaults` became `scoped`, and the hydration serializer changed from `StandardRPCJsonSerializer` to `RPCJsonSerializer` (see [RPC JSON Serializer](/docs/rpc/serializer#rpc-json-serializer)). +Each integration now exports its factory, operation context symbol and type only under the package-specific names: the generic `createRouterUtils`, `OPERATION_CONTEXT_SYMBOL` and `OperationContext` exports were removed. For TanStack Query, use `createTanstackQueryUtils`, `TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL` and `TanstackQueryOperationContext`. `ProcedureUtils` and `SharedUtils` are exported as types only. + Streamed queries changed (see [Streamed Query Options](/docs/integrations/tanstack-query#streamed-query-options)): - `refetchMode: 'reset'` keeps the old data until the new stream connects, then sets it to `[]`. (v1 cleared it immediately, returning the query to `pending`.) +- `queryFnOptions` is now `fnOptions`, the same name `.key({ type: 'streamed', fnOptions })` uses. - `refetchMode: 'replace'` was removed. To keep the old data until the stream ends, collect the stream in a custom `queryFn`: ```ts @@ -1207,7 +1210,7 @@ orpc.streamed.streamedOptions({ ### SWR and Pinia Colada -`@orpc/experimental-react-swr` is now `@orpc/swr` (see [SWR Integration](/docs/integrations/swr)), and `@orpc/vue-colada` is now `@orpc/pinia-colada` with `createORPCVueColadaUtils` renamed to `createPiniaColadaUtils` (see [Pinia Colada Integration](/docs/integrations/pinia-colada)). Both switched from `path` to `prefix`, same as TanStack Query. +`@orpc/experimental-react-swr` is now `@orpc/swr` (see [SWR Integration](/docs/integrations/swr)), and `@orpc/vue-colada` is now `@orpc/pinia-colada` with `createORPCVueColadaUtils` renamed to `createPiniaColadaUtils` (see [Pinia Colada Integration](/docs/integrations/pinia-colada)). Both switched from `path` to `prefix`, same as TanStack Query, and both dropped the generic exports too: use `createSWRUtils`, `SWR_OPERATION_CONTEXT_SYMBOL` and `SWROperationContext`, or `createPiniaColadaUtils`, `PINIA_COLADA_OPERATION_CONTEXT_SYMBOL` and `PiniaColadaOperationContext`. In SWR, `.subscriber` with `refetchMode: 'reset'` now sets the data to `[]` when the stream connects, instead of `undefined`. @@ -1402,5 +1405,8 @@ These renames still compile through deprecated aliases, so you can migrate them | `useOptimisticServerAction` | `useOptimisticServerFunction` | `@orpc/next/hooks` | | `createFormAction` | `createServerFormFunction` | `@orpc/next` | | `createORPCVueColadaUtils` | `createPiniaColadaUtils` | `@orpc/pinia-colada` | +| `createRouterUtils` | `createTanstackQueryUtils` | `@orpc/tanstack-query` | +| `createRouterUtils` | `createPiniaColadaUtils` | `@orpc/pinia-colada` | +| `createRouterUtils` | `createSWRUtils` | `@orpc/swr` | If anything is missing from this guide, check the corresponding page in the v2 docs, or open an issue on [GitHub](https://github.com/middleapi/orpc/issues). diff --git a/packages/msw/src/http-router-utils.ts b/packages/msw/src/http-router-utils.ts index bf4d72b9f2..916bffef4d 100644 --- a/packages/msw/src/http-router-utils.ts +++ b/packages/msw/src/http-router-utils.ts @@ -11,6 +11,12 @@ export type HTTPRouterUtils< TContext extends Context, > = HTTPRouterUtilsInternal +/** + * The recursion behind {@link HTTPRouterUtils}. Exported only so TypeScript can name it + * in declarations emitted for generic code, do not use it directly. + * + * @internal + */ export type HTTPRouterUtilsInternal = T extends ProcedureContract ? HTTPProcedureUtils diff --git a/packages/msw/src/index.test.ts b/packages/msw/src/index.test.ts index d72bfb7e38..9ec11a90a2 100644 --- a/packages/msw/src/index.test.ts +++ b/packages/msw/src/index.test.ts @@ -3,3 +3,9 @@ it('exports createHTTPUtils', async () => { createHTTPUtils: expect.any(Function), }) }) + +it('does not export generic names or utils classes', async () => { + const exports = await import('./index') + + expect(exports).not.toHaveProperty('HTTPProcedureUtils') +}) diff --git a/packages/msw/src/index.ts b/packages/msw/src/index.ts index 48c94b2f53..c4460c5d31 100644 --- a/packages/msw/src/index.ts +++ b/packages/msw/src/index.ts @@ -1,3 +1,7 @@ -export { HTTPProcedureUtils } from './http-procedure-utils' -export type { HTTPProcedureUtilsOptions } from './http-procedure-utils' -export * from './http-router-utils' +export type { HTTPProcedureUtils, HTTPProcedureUtilsOptions } from './http-procedure-utils' +export { createHTTPUtils } from './http-router-utils' +export type { + HTTPRouterUtils, + HTTPRouterUtilsInternal, + HTTPRouterUtilsOptions, +} from './http-router-utils' diff --git a/packages/pinia-colada/src/index.test.ts b/packages/pinia-colada/src/index.test.ts index b561a7647b..7504ce8942 100644 --- a/packages/pinia-colada/src/index.test.ts +++ b/packages/pinia-colada/src/index.test.ts @@ -1,8 +1,16 @@ it('exports createPiniaColadaUtils, PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, StreamQuerySSRUtilsPlugin', async () => { await expect(import('./index')).resolves.toMatchObject({ createPiniaColadaUtils: expect.any(Function), - createRouterUtils: expect.any(Function), PINIA_COLADA_OPERATION_CONTEXT_SYMBOL: expect.any(Symbol), StreamQuerySSRUtilsPlugin: expect.any(Function), }) }) + +it('does not export generic names or utils classes', async () => { + const exports = await import('./index') + + expect(exports).not.toHaveProperty('createRouterUtils') + expect(exports).not.toHaveProperty('OPERATION_CONTEXT_SYMBOL') + expect(exports).not.toHaveProperty('ProcedureUtils') + expect(exports).not.toHaveProperty('SharedUtils') +}) diff --git a/packages/pinia-colada/src/index.ts b/packages/pinia-colada/src/index.ts index 189595acd2..908b9a693c 100644 --- a/packages/pinia-colada/src/index.ts +++ b/packages/pinia-colada/src/index.ts @@ -7,8 +7,9 @@ export type { } from './key' export * from './meta' export type { RouterUtilsPlugin } from './plugin' -export { mergeProcedureUtilsOptions, ProcedureUtils } from './procedure-utils' +export { mergeProcedureUtilsOptions } from './procedure-utils' export type { + ProcedureUtils, ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, @@ -22,21 +23,44 @@ export type { ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, } from './procedure-utils' -export * from './router-utils' export { /** - * @deprecated Use `createRouterUtils` instead. + * @deprecated Use `createPiniaColadaUtils` instead. */ createRouterUtils as createORPCVueColadaUtils, } from './router-utils' export { createRouterUtils as createPiniaColadaUtils } from './router-utils' -export { SharedUtils } from './shared-utils' +export type { + RouterUtils, + RouterUtilsInternal, + RouterUtilsOptions, + RouterUtilsScoped, + RouterUtilsScopedInternal, +} from './router-utils' +export type { SharedUtils } from './shared-utils' export * from './ssr' export type { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from './stream-query' -export * from './types' -export { - OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, - type OperationContext as PiniaColadaOperationContext, +export { OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL } from './types' +export type { + InferLiveQueryOutput, + InferStreamedQueryOutput, + InfiniteKeyOptions, + InfiniteOptionsIn, + InfiniteOptionsOut, + LiveOptionsIn, + MutationKeyOptions, + MutationOptionsIn, + MutationOptionsOut, + OperationType, + OperationContext as PiniaColadaOperationContext, + QueryKeyOptions, + QueryOptionsIn, + QueryOptionsOut, + StreamedKeyOptions, + StreamedOptionsIn, + StreamedOptionsOut, + UseMutationFnContext, + UseQueryFnContext, } from './types' export type { AnyNestedClient } from '@orpc/client' diff --git a/packages/pinia-colada/src/router-utils.ts b/packages/pinia-colada/src/router-utils.ts index 20c25d0798..678d47dbbc 100644 --- a/packages/pinia-colada/src/router-utils.ts +++ b/packages/pinia-colada/src/router-utils.ts @@ -29,6 +29,12 @@ import { SharedUtils } from './shared-utils' */ export type RouterUtils = RouterUtilsInternal +/** + * The recursion behind {@link RouterUtils}. Exported only so TypeScript can name it + * in declarations emitted for generic code, do not use it directly. + * + * @internal + */ export type RouterUtilsInternal = T extends Client ? Public> @@ -38,6 +44,12 @@ export type RouterUtilsInternal = export type RouterUtilsScoped = RouterUtilsScopedInternal +/** + * The recursion behind {@link RouterUtilsScoped}. Exported only so TypeScript can name it + * in declarations emitted for generic code, do not use it directly. + * + * @internal + */ export type RouterUtilsScopedInternal = T extends Client ? ProcedureUtilsOptions diff --git a/packages/pinia-colada/tests/ssr.test.tsx b/packages/pinia-colada/tests/ssr.test.tsx index 3995215189..ab61089284 100644 --- a/packages/pinia-colada/tests/ssr.test.tsx +++ b/packages/pinia-colada/tests/ssr.test.tsx @@ -12,7 +12,7 @@ import { createSSRApp, defineComponent, h, nextTick, ref, watch } from 'vue' import { renderToString } from 'vue/server-renderer' import type { RouterUtils } from '../src/index' -import { createRouterUtils, StreamQuerySSRUtilsPlugin } from '../src/index' +import { createPiniaColadaUtils, StreamQuerySSRUtilsPlugin } from '../src/index' import { createChunkController } from './__shared__/utils' type StreamClient = { stream: Client, Error> } @@ -44,7 +44,7 @@ describe.each([ return server.stream() }), } as unknown as StreamClient - const utils = createRouterUtils(client, { + const utils = createPiniaColadaUtils(client, { plugins: [new StreamQuerySSRUtilsPlugin({ isServer: true })], }) const pinia = createPinia() @@ -72,7 +72,7 @@ describe.each([ expect(started).toHaveBeenCalledTimes(1) const client = { stream: vi.fn(() => browser.stream()) } as unknown as StreamClient - const utils = createRouterUtils(client, { + const utils = createPiniaColadaUtils(client, { plugins: [new StreamQuerySSRUtilsPlugin({ isServer: false })], }) diff --git a/packages/swr/src/index.test.ts b/packages/swr/src/index.test.ts index ef976db9ab..aed7024b35 100644 --- a/packages/swr/src/index.test.ts +++ b/packages/swr/src/index.test.ts @@ -1,7 +1,15 @@ it('exports createSWRUtils, SWR_OPERATION_CONTEXT_SYMBOL', async () => { await expect(import('./index')).resolves.toMatchObject({ createSWRUtils: expect.any(Function), - createRouterUtils: expect.any(Function), SWR_OPERATION_CONTEXT_SYMBOL: expect.any(Symbol), }) }) + +it('does not export generic names or utils classes', async () => { + const exports = await import('./index') + + expect(exports).not.toHaveProperty('createRouterUtils') + expect(exports).not.toHaveProperty('OPERATION_CONTEXT_SYMBOL') + expect(exports).not.toHaveProperty('ProcedureUtils') + expect(exports).not.toHaveProperty('SharedUtils') +}) diff --git a/packages/swr/src/index.ts b/packages/swr/src/index.ts index 44c2bdf6f7..dd7f67b10a 100644 --- a/packages/swr/src/index.ts +++ b/packages/swr/src/index.ts @@ -1,13 +1,24 @@ export type { OperationKey, OperationKeyOptions, OperationKeyPrefixOptions } from './key' -export { ProcedureUtils } from './procedure-utils' -export type { ProcedureUtilsOptions } from './procedure-utils' -export * from './router-utils' +export type { ProcedureUtils, ProcedureUtilsOptions } from './procedure-utils' export { createRouterUtils as createSWRUtils } from './router-utils' -export { SharedUtils } from './shared-utils' -export * from './types' -export { - OPERATION_CONTEXT_SYMBOL as SWR_OPERATION_CONTEXT_SYMBOL, - type OperationContext as SWROperationContext, +export type { RouterUtils, RouterUtilsInternal, RouterUtilsOptions } from './router-utils' +export type { SharedUtils } from './shared-utils' +export { OPERATION_CONTEXT_SYMBOL as SWR_OPERATION_CONTEXT_SYMBOL } from './types' +export type { + Fetcher, + FetcherOptions, + InferLiveSubscriberOutput, + InferSubscriberOutput, + KeyOptions, + Matcher, + MatcherOptions, + MatcherStrategy, + Mutator, + MutatorOptions, + OperationType, + Subscriber, + SubscriberOptions, + OperationContext as SWROperationContext, } from './types' export type { Public } from '@orpc/shared' diff --git a/packages/swr/src/router-utils.ts b/packages/swr/src/router-utils.ts index 39a2da0863..4310f7db4d 100644 --- a/packages/swr/src/router-utils.ts +++ b/packages/swr/src/router-utils.ts @@ -9,6 +9,12 @@ import { SharedUtils } from './shared-utils' export type RouterUtils = RouterUtilsInternal +/** + * The recursion behind {@link RouterUtils}. Exported only so TypeScript can name it + * in declarations emitted for generic code, do not use it directly. + * + * @internal + */ export type RouterUtilsInternal = T extends Client ? Public> diff --git a/packages/tanstack-query/src/index.test.ts b/packages/tanstack-query/src/index.test.ts index cf9f87c518..ae323f9e09 100644 --- a/packages/tanstack-query/src/index.test.ts +++ b/packages/tanstack-query/src/index.test.ts @@ -4,3 +4,12 @@ it('exports createTanstackQueryUtils, TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL', TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL: expect.any(Symbol), }) }) + +it('does not export generic names or utils classes', async () => { + const exports = await import('./index') + + expect(exports).not.toHaveProperty('createRouterUtils') + expect(exports).not.toHaveProperty('OPERATION_CONTEXT_SYMBOL') + expect(exports).not.toHaveProperty('ProcedureUtils') + expect(exports).not.toHaveProperty('SharedUtils') +}) diff --git a/packages/tanstack-query/src/index.ts b/packages/tanstack-query/src/index.ts index 59f6271d0b..799c2c1200 100644 --- a/packages/tanstack-query/src/index.ts +++ b/packages/tanstack-query/src/index.ts @@ -7,8 +7,9 @@ export type { } from './key' export * from './meta' export type { RouterUtilsPlugin } from './plugin' -export { mergeProcedureUtilsOptions, ProcedureUtils } from './procedure-utils' +export { mergeProcedureUtilsOptions } from './procedure-utils' export type { + ProcedureUtils, ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, @@ -22,16 +23,37 @@ export type { ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, } from './procedure-utils' -export * from './router-utils' export { createRouterUtils as createTanstackQueryUtils } from './router-utils' -export { SharedUtils } from './shared-utils' +export type { + RouterUtils, + RouterUtilsInternal, + RouterUtilsOptions, + RouterUtilsScoped, + RouterUtilsScopedInternal, +} from './router-utils' +export type { SharedUtils } from './shared-utils' export * from './ssr' export type { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from './stream-query' export * from './structural-sharing' -export * from './types' -export { - OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, - type OperationContext as TanstackQueryOperationContext, +export { OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL } from './types' +export type { + InferLiveQueryOutput, + InferStreamedQueryOutput, + InfiniteKeyOptions, + InfiniteOptionsIn, + InfiniteOptionsOut, + LiveOptionsIn, + MutationKeyOptions, + MutationOptionsIn, + MutationOptionsOut, + OperationType, + QueryKeyOptions, + QueryOptionsIn, + QueryOptionsOut, + StreamedKeyOptions, + StreamedOptionsIn, + StreamedOptionsOut, + OperationContext as TanstackQueryOperationContext, } from './types' export type { AnyNestedClient } from '@orpc/client' diff --git a/packages/tanstack-query/src/procedure-utils.test-d.ts b/packages/tanstack-query/src/procedure-utils.test-d.ts index 409d00a3d2..66cd58c93a 100644 --- a/packages/tanstack-query/src/procedure-utils.test-d.ts +++ b/packages/tanstack-query/src/procedure-utils.test-d.ts @@ -293,7 +293,7 @@ describe('ProcedureUtils', () => { expectTypeOf( optionalUtils.streamedKey({ input: { search: 'search' }, - queryFnOptions: { + fnOptions: { maxChunks: 1, refetchMode: 'append', }, @@ -301,7 +301,7 @@ describe('ProcedureUtils', () => { ).toExtend() // @ts-expect-error - 'replace' is no longer a refetch mode - optionalUtils.streamedKey({ queryFnOptions: { refetchMode: 'replace' } }) + optionalUtils.streamedKey({ fnOptions: { refetchMode: 'replace' } }) // @ts-expect-error - settleOnFirstData is not part of the key optionalUtils.streamedKey({ settleOnFirstData: true }) }) @@ -375,7 +375,7 @@ describe('ProcedureUtils', () => { streamUtils.streamedOptions({ initialData: () => 'invalid' }) }) - it('accepts settleOnFirstData and serializable queryFnOptions', () => { + it('accepts settleOnFirstData and serializable fnOptions', () => { streamUtils.streamedOptions({ settleOnFirstData: true }) streamUtils.streamedOptions({ settleOnFirstData: false }) // @ts-expect-error - invalid settleOnFirstData @@ -390,7 +390,7 @@ describe('ProcedureUtils', () => { settleOnFirstData: true, }) - streamUtils.streamedOptions({ queryFnOptions: { refetchMode: 'reset', maxChunks: 10 } }) + streamUtils.streamedOptions({ fnOptions: { refetchMode: 'reset', maxChunks: 10 } }) }) it('return valid streamed options', () => { @@ -1116,7 +1116,7 @@ describe('ProcedureUtilsOptions', () => { const _defaults: TestOptions = { streamedKey: { input: { search: 'test' }, - queryFnOptions: { maxChunks: 10 }, + fnOptions: { maxChunks: 10 }, }, } @@ -1133,7 +1133,7 @@ describe('ProcedureUtilsOptions', () => { return { input: { search: 'test' }, - queryFnOptions: { maxChunks: 10 }, + fnOptions: { maxChunks: 10 }, } }, } diff --git a/packages/tanstack-query/src/procedure-utils.test.ts b/packages/tanstack-query/src/procedure-utils.test.ts index 24057912ff..2d8cbfca93 100644 --- a/packages/tanstack-query/src/procedure-utils.test.ts +++ b/packages/tanstack-query/src/procedure-utils.test.ts @@ -60,7 +60,7 @@ describe('procedureUtils', () => { input: 1, }) - keyedUtils.streamedKey({ input: 1, queryFnOptions: { maxChunks: 1 } } as any) + keyedUtils.streamedKey({ input: 1, fnOptions: { maxChunks: 1 } } as any) expect(generateOperationKeySpy).toHaveBeenNthCalledWith(2, ['ping'], { prefix: '__prefix__', serializer, @@ -184,7 +184,7 @@ describe('procedureUtils', () => { const options = utils.streamedOptions({ input: { search: '__search__' }, context: { batch: '__batch__' }, - queryFnOptions: { + fnOptions: { refetchMode: 'append', }, }) @@ -236,7 +236,7 @@ describe('procedureUtils', () => { it('passes settleOnFirstData to the query function, not to the key or the query options', async () => { const options = utils.streamedOptions({ input: { search: '__search__' }, - queryFnOptions: { maxChunks: 2 }, + fnOptions: { maxChunks: 2 }, settleOnFirstData: true, }) diff --git a/packages/tanstack-query/src/procedure-utils.ts b/packages/tanstack-query/src/procedure-utils.ts index 80584b9206..0e79d3f6c9 100644 --- a/packages/tanstack-query/src/procedure-utils.ts +++ b/packages/tanstack-query/src/procedure-utils.ts @@ -451,7 +451,7 @@ export class ProcedureUtils< const queryKey = this.queryKey(optionsIn) return { - structuralSharing: createStructuralSharing(this.options.serializer), + structuralSharing: createStructuralSharing({ serializer: this.options.serializer }), ...(optionsIn as any), queryKey, queryFn: (fnContext) => { @@ -507,7 +507,7 @@ export class ProcedureUtils< this.key({ type: 'streamed', input: (optionsIn as any).input, - fnOptions: (optionsIn as any).queryFnOptions, + fnOptions: (optionsIn as any).fnOptions, }) return queryKey as DataTag, TError> @@ -579,7 +579,7 @@ export class ProcedureUtils< return output }, - { ...optionsIn.queryFnOptions, settleOnFirstData }, + { ...optionsIn.fnOptions, settleOnFirstData }, )(fnContext) }, ) @@ -637,7 +637,7 @@ export class ProcedureUtils< const { settleOnFirstData, ...queryOptions } = optionsIn return { - structuralSharing: createStructuralSharing(this.options.serializer), + structuralSharing: createStructuralSharing({ serializer: this.options.serializer }), ...(queryOptions as any), queryKey, queryFn: (fnContext) => { @@ -740,7 +740,7 @@ export class ProcedureUtils< const queryKey = this.infiniteKey(optionsIn) return { - structuralSharing: createStructuralSharing(this.options.serializer), + structuralSharing: createStructuralSharing({ serializer: this.options.serializer }), ...(optionsIn as any), queryKey, queryFn: (fnContext) => { diff --git a/packages/tanstack-query/src/router-utils.ts b/packages/tanstack-query/src/router-utils.ts index a674da31c0..87ba7aeeac 100644 --- a/packages/tanstack-query/src/router-utils.ts +++ b/packages/tanstack-query/src/router-utils.ts @@ -29,6 +29,12 @@ import { SharedUtils } from './shared-utils' */ export type RouterUtils = RouterUtilsInternal +/** + * The recursion behind {@link RouterUtils}. Exported only so TypeScript can name it + * in declarations emitted for generic code, do not use it directly. + * + * @internal + */ export type RouterUtilsInternal = T extends Client ? Public> @@ -38,6 +44,12 @@ export type RouterUtilsInternal = export type RouterUtilsScoped = RouterUtilsScopedInternal +/** + * The recursion behind {@link RouterUtilsScoped}. Exported only so TypeScript can name it + * in declarations emitted for generic code, do not use it directly. + * + * @internal + */ export type RouterUtilsScopedInternal = T extends Client ? ProcedureUtilsOptions diff --git a/packages/tanstack-query/src/ssr.test-d.ts b/packages/tanstack-query/src/ssr.test-d.ts index 7e6c9320a2..3fa171e5b4 100644 --- a/packages/tanstack-query/src/ssr.test-d.ts +++ b/packages/tanstack-query/src/ssr.test-d.ts @@ -5,10 +5,14 @@ import { createRouterUtils } from './router-utils' import { createHydrationOptions, StreamQuerySSRUtilsPlugin } from './ssr' it('accepts an RPCSerializer', () => { - createHydrationOptions(new RPCSerializer()) + createHydrationOptions() + createHydrationOptions({}) + createHydrationOptions({ serializer: new RPCSerializer() }) // @ts-expect-error not a serializer - createHydrationOptions({}) + createHydrationOptions({ serializer: {} }) + // @ts-expect-error the serializer is no longer a positional argument + createHydrationOptions(new RPCSerializer()) }) it('StreamQuerySSRUtilsPlugin infers the client', () => { diff --git a/packages/tanstack-query/src/ssr.test.ts b/packages/tanstack-query/src/ssr.test.ts index c6acdf5eae..4c6bc74ae7 100644 --- a/packages/tanstack-query/src/ssr.test.ts +++ b/packages/tanstack-query/src/ssr.test.ts @@ -45,8 +45,8 @@ describe('createHydrationOptions', () => { constructor(public name: string) {} } - const options = createHydrationOptions( - new RPCJsonSerializer({ + const options = createHydrationOptions({ + serializer: new RPCJsonSerializer({ handlers: { person: { condition: (value) => value instanceof Person, @@ -55,7 +55,7 @@ describe('createHydrationOptions', () => { }, }, }), - ) + }) expect(roundTrip({ person: new Person('Earth') }, options)).toEqual({ person: new Person('Earth'), diff --git a/packages/tanstack-query/src/ssr.ts b/packages/tanstack-query/src/ssr.ts index a461ca543f..14aa1fee41 100644 --- a/packages/tanstack-query/src/ssr.ts +++ b/packages/tanstack-query/src/ssr.ts @@ -12,17 +12,27 @@ import type { RouterUtilsPlugin } from './plugin' import type { ProcedureUtilsOptions } from './procedure-utils' import { mergeProcedureUtilsOptions } from './procedure-utils' +export interface CreateHydrationOptionsOptions { + /** + * Serializes query data when dehydrating, and deserializes it when hydrating. + * Pass the serializer your link uses so custom types are supported. + * + * @default new RPCJsonSerializer() + */ + serializer?: Public | undefined +} + /** * Creates `dehydrate` and `hydrate` query client defaults that preserve oRPC types. * * @see {@link https://orpc.dev/docs/integrations/tanstack-query#custom-serializers | TanStack Query Integration - Custom Serializers} */ -export function createHydrationOptions( - serializer: Public = new RPCJsonSerializer(), -): { +export function createHydrationOptions(options: CreateHydrationOptionsOptions = {}): { dehydrate: { serializeData: (data: unknown) => RPCJsonSerialization } hydrate: { deserializeData: (data: RPCJsonSerialization) => unknown } } { + const serializer = options.serializer ?? new RPCJsonSerializer() + return { dehydrate: { serializeData(data) { diff --git a/packages/tanstack-query/src/structural-sharing.test.ts b/packages/tanstack-query/src/structural-sharing.test.ts index f13deb441e..162ce7d048 100644 --- a/packages/tanstack-query/src/structural-sharing.test.ts +++ b/packages/tanstack-query/src/structural-sharing.test.ts @@ -158,8 +158,8 @@ describe('structuralSharing', () => { }) describe('with a serializer', () => { - const sharing = createStructuralSharing( - new RPCJsonSerializer({ + const sharing = createStructuralSharing({ + serializer: new RPCJsonSerializer({ handlers: { person: { condition: (value) => value instanceof Person, @@ -173,7 +173,7 @@ describe('structuralSharing', () => { }, }, }), - ) + }) it('keeps equal instances of types with custom handlers', () => { const old = { people: [new Person('Earth', new Date('2025-01-01'))] } @@ -199,8 +199,8 @@ describe('structuralSharing', () => { }) it('compares dates with own fields through a custom date handler', () => { - const zoned = createStructuralSharing( - new RPCJsonSerializer({ + const zoned = createStructuralSharing({ + serializer: new RPCJsonSerializer({ handlers: { date: { condition: (value) => value instanceof Date, @@ -210,7 +210,7 @@ describe('structuralSharing', () => { }, }, }), - ) + }) const old = Object.assign(new Date(0), { zone: 'UTC' }) const next = Object.assign(new Date(0), { zone: 'PST' }) @@ -244,8 +244,8 @@ describe('structuralSharing', () => { }) describe('with an OpenAPI serializer', () => { - const sharing = createStructuralSharing( - new OpenAPIJsonSerializer({ + const sharing = createStructuralSharing({ + serializer: new OpenAPIJsonSerializer({ handlers: { person: { condition: (value) => value instanceof Person, @@ -253,7 +253,7 @@ describe('structuralSharing', () => { }, }, }), - ) + }) it.each([ ['bigint and string members', new Set([1n]), new Set(['1'])], diff --git a/packages/tanstack-query/src/structural-sharing.ts b/packages/tanstack-query/src/structural-sharing.ts index b4af07c27b..187091382a 100644 --- a/packages/tanstack-query/src/structural-sharing.ts +++ b/packages/tanstack-query/src/structural-sharing.ts @@ -4,6 +4,14 @@ import { setOwn, stringifyJSON } from '@orpc/shared' export type StructuralSharing = (oldData: unknown, newData: T) => T +export interface CreateStructuralSharingOptions { + /** + * Compares custom types by what their handler serializes them to. + * Without it, only the built-in types are compared. + */ + serializer?: Public | undefined +} + /** * Creates a `structuralSharing` function that works like TanStack Query's default, but also keeps * the previous reference for equal `Date`, `URL`, `Map` and `Set` values, which oRPC's serializer @@ -14,7 +22,11 @@ export type StructuralSharing = (oldData: unknown, newData: T) => T * * @see {@link https://orpc.dev/docs/integrations/tanstack-query#structural-sharing | TanStack Query Integration - Structural Sharing} */ -export function createStructuralSharing(serializer?: Public): StructuralSharing { +export function createStructuralSharing( + options: CreateStructuralSharingOptions = {}, +): StructuralSharing { + const serializer = options.serializer + return (oldData, newData) => replaceEqualDeep(oldData, newData, 0, serializer) } diff --git a/packages/tanstack-query/src/types.ts b/packages/tanstack-query/src/types.ts index 2e6d4012e6..5063ae1da8 100644 --- a/packages/tanstack-query/src/types.ts +++ b/packages/tanstack-query/src/types.ts @@ -87,7 +87,7 @@ export type QueryOptionsOut = Pick< export type StreamedKeyOptions = | ((undefined extends TInput ? { input?: TInput | SkipToken } : { input: TInput | SkipToken }) & { - queryFnOptions?: SerializableStreamedQueryOptions | undefined + fnOptions?: SerializableStreamedQueryOptions | undefined }) | { queryKey: QueryKey } @@ -99,7 +99,7 @@ export type StreamedOptionsIn< TSelectData, TInitialData, > = QueryOptionsIn & { - queryFnOptions?: SerializableStreamedQueryOptions | undefined + fnOptions?: SerializableStreamedQueryOptions | undefined } & SettleOnFirstDataOptions /** diff --git a/packages/tanstack-query/tests/e2e.test.tsx b/packages/tanstack-query/tests/e2e.test.tsx index 7a95a5b524..deb03ee378 100644 --- a/packages/tanstack-query/tests/e2e.test.tsx +++ b/packages/tanstack-query/tests/e2e.test.tsx @@ -94,7 +94,7 @@ it('case: with streamed/useQuery', async () => { const { result } = renderHook(() => useQuery( orpc.stream.streamedOptions({ - queryFnOptions: { + fnOptions: { refetchMode: 'append', maxChunks: 3, }, @@ -132,7 +132,7 @@ it('case: with streamed/useQuery', async () => { queryClient.getQueryData( orpc.stream.streamedKey({ input: { input: 2 }, - queryFnOptions: { refetchMode: 'append', maxChunks: 3 }, + fnOptions: { refetchMode: 'append', maxChunks: 3 }, }), ), ).toEqual([{ output: '0' }, { output: '1' }]) diff --git a/playgrounds/bun/src/components/chat-room.tsx b/playgrounds/bun/src/components/chat-room.tsx index eec281f1ee..47cd156e57 100644 --- a/playgrounds/bun/src/components/chat-room.tsx +++ b/playgrounds/bun/src/components/chat-room.tsx @@ -11,7 +11,7 @@ export function ChatRoom() { orpc.message.subscribe.streamedOptions({ input: { channel: CHANNEL }, context: { retry: Infinity }, - queryFnOptions: { maxChunks: 10 }, + fnOptions: { maxChunks: 10 }, }), ) diff --git a/playgrounds/bun/src/lib/orpc.ts b/playgrounds/bun/src/lib/orpc.ts index b9b7395006..90f4962866 100644 --- a/playgrounds/bun/src/lib/orpc.ts +++ b/playgrounds/bun/src/lib/orpc.ts @@ -3,7 +3,7 @@ import type { RetryLinkPluginContext } from '@orpc/client/plugins' import { RetryLinkPlugin } from '@orpc/client/plugins' import { RPCLink } from '@orpc/client/websocket' import type { RouterClient } from '@orpc/server' -import { createRouterUtils } from '@orpc/tanstack-query' +import { createTanstackQueryUtils } from '@orpc/tanstack-query' import type { router } from '../routers' @@ -16,4 +16,4 @@ const link = new RPCLink({ export const client: RouterClient = createORPCClient(link) -export const orpc = createRouterUtils(client) +export const orpc = createTanstackQueryUtils(client) diff --git a/playgrounds/cloudflare/src/components/chat-room.tsx b/playgrounds/cloudflare/src/components/chat-room.tsx index eec281f1ee..47cd156e57 100644 --- a/playgrounds/cloudflare/src/components/chat-room.tsx +++ b/playgrounds/cloudflare/src/components/chat-room.tsx @@ -11,7 +11,7 @@ export function ChatRoom() { orpc.message.subscribe.streamedOptions({ input: { channel: CHANNEL }, context: { retry: Infinity }, - queryFnOptions: { maxChunks: 10 }, + fnOptions: { maxChunks: 10 }, }), ) diff --git a/playgrounds/cloudflare/src/lib/orpc.ts b/playgrounds/cloudflare/src/lib/orpc.ts index bdd802fac8..558bd5be58 100644 --- a/playgrounds/cloudflare/src/lib/orpc.ts +++ b/playgrounds/cloudflare/src/lib/orpc.ts @@ -3,7 +3,7 @@ import { RPCLink } from '@orpc/client/fetch' import type { RetryLinkPluginContext } from '@orpc/client/plugins' import { BatchLinkPlugin, RetryLinkPlugin } from '@orpc/client/plugins' import type { RouterClient } from '@orpc/server' -import { createRouterUtils } from '@orpc/tanstack-query' +import { createTanstackQueryUtils } from '@orpc/tanstack-query' import type { router } from '../../worker/routers' @@ -27,4 +27,4 @@ const link = new RPCLink({ export const client: RouterClient = createORPCClient(link) -export const orpc = createRouterUtils(client) +export const orpc = createTanstackQueryUtils(client) diff --git a/playgrounds/next/src/components/chat-room.tsx b/playgrounds/next/src/components/chat-room.tsx index d5c6a09018..8426fea3bb 100644 --- a/playgrounds/next/src/components/chat-room.tsx +++ b/playgrounds/next/src/components/chat-room.tsx @@ -13,7 +13,7 @@ export function ChatRoom() { orpc.message.subscribe.streamedOptions({ input: { channel: CHANNEL }, context: { retry: Infinity }, - queryFnOptions: { maxChunks: 10 }, + fnOptions: { maxChunks: 10 }, }), ) diff --git a/playgrounds/next/src/lib/orpc.ts b/playgrounds/next/src/lib/orpc.ts index 4abc9101b5..8b924e5076 100644 --- a/playgrounds/next/src/lib/orpc.ts +++ b/playgrounds/next/src/lib/orpc.ts @@ -3,7 +3,7 @@ import { RPCLink } from '@orpc/client/fetch' import type { RetryLinkPluginContext } from '@orpc/client/plugins' import { BatchLinkPlugin, RetryLinkPlugin } from '@orpc/client/plugins' import type { RouterClient } from '@orpc/server' -import { createRouterUtils, StreamQuerySSRUtilsPlugin } from '@orpc/tanstack-query' +import { createTanstackQueryUtils, StreamQuerySSRUtilsPlugin } from '@orpc/tanstack-query' import type { router } from '@/routers' @@ -52,6 +52,6 @@ const link = new RPCLink({ export const client: RouterClient = globalThis.$client ?? createORPCClient(link) -export const orpc = createRouterUtils(client, { +export const orpc = createTanstackQueryUtils(client, { plugins: [new StreamQuerySSRUtilsPlugin()], }) diff --git a/playgrounds/next/src/lib/query-client.ts b/playgrounds/next/src/lib/query-client.ts index 68c55b00c1..e40e5e15f1 100644 --- a/playgrounds/next/src/lib/query-client.ts +++ b/playgrounds/next/src/lib/query-client.ts @@ -31,7 +31,7 @@ function createQueryClient(): QueryClient { queries: { staleTime: 60 * 1000, // > 0 to prevent immediate refetching on mount }, - ...createHydrationOptions(serializer), + ...createHydrationOptions({ serializer }), }, }) } From a27ccd7a389c5db742d82d718d06451969d8562d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=8Bnh=20L=C3=AA?= Date: Sun, 22 Nov 2026 08:30:02 +0700 Subject: [PATCH 02/11] refactor(tanstack-query, pinia-colada, swr): keep the createRouterUtils export --- apps/content/docs/migrations/from-v1.mdx | 7 ++----- packages/pinia-colada/src/index.test.ts | 4 ++-- packages/pinia-colada/src/index.ts | 2 +- packages/swr/src/index.test.ts | 4 ++-- packages/swr/src/index.ts | 2 +- packages/tanstack-query/src/index.test.ts | 4 ++-- packages/tanstack-query/src/index.ts | 2 +- 7 files changed, 11 insertions(+), 14 deletions(-) diff --git a/apps/content/docs/migrations/from-v1.mdx b/apps/content/docs/migrations/from-v1.mdx index c9c94df29b..21d3108cf7 100644 --- a/apps/content/docs/migrations/from-v1.mdx +++ b/apps/content/docs/migrations/from-v1.mdx @@ -1193,7 +1193,7 @@ orpc.live.experimental_liveOptions({ input: {} }) `experimental_defaults` became `scoped`, and the hydration serializer changed from `StandardRPCJsonSerializer` to `RPCJsonSerializer` (see [RPC JSON Serializer](/docs/rpc/serializer#rpc-json-serializer)). -Each integration now exports its factory, operation context symbol and type only under the package-specific names: the generic `createRouterUtils`, `OPERATION_CONTEXT_SYMBOL` and `OperationContext` exports were removed. For TanStack Query, use `createTanstackQueryUtils`, `TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL` and `TanstackQueryOperationContext`. `ProcedureUtils` and `SharedUtils` are exported as types only. +Each integration now exports its operation context symbol and type only under the package-specific names: the generic `OPERATION_CONTEXT_SYMBOL` and `OperationContext` exports were removed. For TanStack Query, use `TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL` and `TanstackQueryOperationContext`. `ProcedureUtils` and `SharedUtils` are exported as types only. Streamed queries changed (see [Streamed Query Options](/docs/integrations/tanstack-query#streamed-query-options)): @@ -1210,7 +1210,7 @@ orpc.streamed.streamedOptions({ ### SWR and Pinia Colada -`@orpc/experimental-react-swr` is now `@orpc/swr` (see [SWR Integration](/docs/integrations/swr)), and `@orpc/vue-colada` is now `@orpc/pinia-colada` with `createORPCVueColadaUtils` renamed to `createPiniaColadaUtils` (see [Pinia Colada Integration](/docs/integrations/pinia-colada)). Both switched from `path` to `prefix`, same as TanStack Query, and both dropped the generic exports too: use `createSWRUtils`, `SWR_OPERATION_CONTEXT_SYMBOL` and `SWROperationContext`, or `createPiniaColadaUtils`, `PINIA_COLADA_OPERATION_CONTEXT_SYMBOL` and `PiniaColadaOperationContext`. +`@orpc/experimental-react-swr` is now `@orpc/swr` (see [SWR Integration](/docs/integrations/swr)), and `@orpc/vue-colada` is now `@orpc/pinia-colada` with `createORPCVueColadaUtils` renamed to `createPiniaColadaUtils` (see [Pinia Colada Integration](/docs/integrations/pinia-colada)). Both switched from `path` to `prefix`, same as TanStack Query, and both dropped the generic context exports too: use `SWR_OPERATION_CONTEXT_SYMBOL` and `SWROperationContext`, or `PINIA_COLADA_OPERATION_CONTEXT_SYMBOL` and `PiniaColadaOperationContext`. In SWR, `.subscriber` with `refetchMode: 'reset'` now sets the data to `[]` when the stream connects, instead of `undefined`. @@ -1405,8 +1405,5 @@ These renames still compile through deprecated aliases, so you can migrate them | `useOptimisticServerAction` | `useOptimisticServerFunction` | `@orpc/next/hooks` | | `createFormAction` | `createServerFormFunction` | `@orpc/next` | | `createORPCVueColadaUtils` | `createPiniaColadaUtils` | `@orpc/pinia-colada` | -| `createRouterUtils` | `createTanstackQueryUtils` | `@orpc/tanstack-query` | -| `createRouterUtils` | `createPiniaColadaUtils` | `@orpc/pinia-colada` | -| `createRouterUtils` | `createSWRUtils` | `@orpc/swr` | If anything is missing from this guide, check the corresponding page in the v2 docs, or open an issue on [GitHub](https://github.com/middleapi/orpc/issues). diff --git a/packages/pinia-colada/src/index.test.ts b/packages/pinia-colada/src/index.test.ts index 7504ce8942..71867c63e0 100644 --- a/packages/pinia-colada/src/index.test.ts +++ b/packages/pinia-colada/src/index.test.ts @@ -6,10 +6,10 @@ it('exports createPiniaColadaUtils, PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, Strea }) }) -it('does not export generic names or utils classes', async () => { +it('exports createRouterUtils, but no generic context symbol or utils classes', async () => { const exports = await import('./index') - expect(exports).not.toHaveProperty('createRouterUtils') + expect(exports).toHaveProperty('createRouterUtils') expect(exports).not.toHaveProperty('OPERATION_CONTEXT_SYMBOL') expect(exports).not.toHaveProperty('ProcedureUtils') expect(exports).not.toHaveProperty('SharedUtils') diff --git a/packages/pinia-colada/src/index.ts b/packages/pinia-colada/src/index.ts index 908b9a693c..395c47b245 100644 --- a/packages/pinia-colada/src/index.ts +++ b/packages/pinia-colada/src/index.ts @@ -29,7 +29,7 @@ export { */ createRouterUtils as createORPCVueColadaUtils, } from './router-utils' -export { createRouterUtils as createPiniaColadaUtils } from './router-utils' +export { createRouterUtils, createRouterUtils as createPiniaColadaUtils } from './router-utils' export type { RouterUtils, RouterUtilsInternal, diff --git a/packages/swr/src/index.test.ts b/packages/swr/src/index.test.ts index aed7024b35..dc871442d3 100644 --- a/packages/swr/src/index.test.ts +++ b/packages/swr/src/index.test.ts @@ -5,10 +5,10 @@ it('exports createSWRUtils, SWR_OPERATION_CONTEXT_SYMBOL', async () => { }) }) -it('does not export generic names or utils classes', async () => { +it('exports createRouterUtils, but no generic context symbol or utils classes', async () => { const exports = await import('./index') - expect(exports).not.toHaveProperty('createRouterUtils') + expect(exports).toHaveProperty('createRouterUtils') expect(exports).not.toHaveProperty('OPERATION_CONTEXT_SYMBOL') expect(exports).not.toHaveProperty('ProcedureUtils') expect(exports).not.toHaveProperty('SharedUtils') diff --git a/packages/swr/src/index.ts b/packages/swr/src/index.ts index dd7f67b10a..47284882c1 100644 --- a/packages/swr/src/index.ts +++ b/packages/swr/src/index.ts @@ -1,6 +1,6 @@ export type { OperationKey, OperationKeyOptions, OperationKeyPrefixOptions } from './key' export type { ProcedureUtils, ProcedureUtilsOptions } from './procedure-utils' -export { createRouterUtils as createSWRUtils } from './router-utils' +export { createRouterUtils, createRouterUtils as createSWRUtils } from './router-utils' export type { RouterUtils, RouterUtilsInternal, RouterUtilsOptions } from './router-utils' export type { SharedUtils } from './shared-utils' export { OPERATION_CONTEXT_SYMBOL as SWR_OPERATION_CONTEXT_SYMBOL } from './types' diff --git a/packages/tanstack-query/src/index.test.ts b/packages/tanstack-query/src/index.test.ts index ae323f9e09..ccedb815c7 100644 --- a/packages/tanstack-query/src/index.test.ts +++ b/packages/tanstack-query/src/index.test.ts @@ -5,10 +5,10 @@ it('exports createTanstackQueryUtils, TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL', }) }) -it('does not export generic names or utils classes', async () => { +it('exports createRouterUtils, but no generic context symbol or utils classes', async () => { const exports = await import('./index') - expect(exports).not.toHaveProperty('createRouterUtils') + expect(exports).toHaveProperty('createRouterUtils') expect(exports).not.toHaveProperty('OPERATION_CONTEXT_SYMBOL') expect(exports).not.toHaveProperty('ProcedureUtils') expect(exports).not.toHaveProperty('SharedUtils') diff --git a/packages/tanstack-query/src/index.ts b/packages/tanstack-query/src/index.ts index 799c2c1200..7f51b857d4 100644 --- a/packages/tanstack-query/src/index.ts +++ b/packages/tanstack-query/src/index.ts @@ -23,7 +23,7 @@ export type { ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, } from './procedure-utils' -export { createRouterUtils as createTanstackQueryUtils } from './router-utils' +export { createRouterUtils, createRouterUtils as createTanstackQueryUtils } from './router-utils' export type { RouterUtils, RouterUtilsInternal, From e910d00d9218b4ca771b0a420fece54806614658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=8Bnh=20L=C3=AA?= Date: Mon, 23 Nov 2026 14:16:06 +0700 Subject: [PATCH 03/11] refactor(tanstack-query, pinia-colada, swr): keep generic operation context names as deprecated aliases --- apps/content/docs/migrations/from-v1.mdx | 4 ++-- packages/pinia-colada/src/index.test.ts | 4 ++-- packages/pinia-colada/src/index.ts | 14 +++++++++++++- packages/swr/src/index.test.ts | 4 ++-- packages/swr/src/index.ts | 14 +++++++++++++- packages/tanstack-query/src/index.test.ts | 4 ++-- packages/tanstack-query/src/index.ts | 14 +++++++++++++- 7 files changed, 47 insertions(+), 11 deletions(-) diff --git a/apps/content/docs/migrations/from-v1.mdx b/apps/content/docs/migrations/from-v1.mdx index 21d3108cf7..1b355bbb16 100644 --- a/apps/content/docs/migrations/from-v1.mdx +++ b/apps/content/docs/migrations/from-v1.mdx @@ -1193,7 +1193,7 @@ orpc.live.experimental_liveOptions({ input: {} }) `experimental_defaults` became `scoped`, and the hydration serializer changed from `StandardRPCJsonSerializer` to `RPCJsonSerializer` (see [RPC JSON Serializer](/docs/rpc/serializer#rpc-json-serializer)). -Each integration now exports its operation context symbol and type only under the package-specific names: the generic `OPERATION_CONTEXT_SYMBOL` and `OperationContext` exports were removed. For TanStack Query, use `TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL` and `TanstackQueryOperationContext`. `ProcedureUtils` and `SharedUtils` are exported as types only. +`ProcedureUtils` and `SharedUtils` are exported as types only. Streamed queries changed (see [Streamed Query Options](/docs/integrations/tanstack-query#streamed-query-options)): @@ -1210,7 +1210,7 @@ orpc.streamed.streamedOptions({ ### SWR and Pinia Colada -`@orpc/experimental-react-swr` is now `@orpc/swr` (see [SWR Integration](/docs/integrations/swr)), and `@orpc/vue-colada` is now `@orpc/pinia-colada` with `createORPCVueColadaUtils` renamed to `createPiniaColadaUtils` (see [Pinia Colada Integration](/docs/integrations/pinia-colada)). Both switched from `path` to `prefix`, same as TanStack Query, and both dropped the generic context exports too: use `SWR_OPERATION_CONTEXT_SYMBOL` and `SWROperationContext`, or `PINIA_COLADA_OPERATION_CONTEXT_SYMBOL` and `PiniaColadaOperationContext`. +`@orpc/experimental-react-swr` is now `@orpc/swr` (see [SWR Integration](/docs/integrations/swr)), and `@orpc/vue-colada` is now `@orpc/pinia-colada` with `createORPCVueColadaUtils` renamed to `createPiniaColadaUtils` (see [Pinia Colada Integration](/docs/integrations/pinia-colada)). Both switched from `path` to `prefix`, same as TanStack Query. In SWR, `.subscriber` with `refetchMode: 'reset'` now sets the data to `[]` when the stream connects, instead of `undefined`. diff --git a/packages/pinia-colada/src/index.test.ts b/packages/pinia-colada/src/index.test.ts index 71867c63e0..f8dde266b1 100644 --- a/packages/pinia-colada/src/index.test.ts +++ b/packages/pinia-colada/src/index.test.ts @@ -6,11 +6,11 @@ it('exports createPiniaColadaUtils, PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, Strea }) }) -it('exports createRouterUtils, but no generic context symbol or utils classes', async () => { +it('exports the generic names, but no utils classes', async () => { const exports = await import('./index') expect(exports).toHaveProperty('createRouterUtils') - expect(exports).not.toHaveProperty('OPERATION_CONTEXT_SYMBOL') + expect(exports).toHaveProperty('OPERATION_CONTEXT_SYMBOL') expect(exports).not.toHaveProperty('ProcedureUtils') expect(exports).not.toHaveProperty('SharedUtils') }) diff --git a/packages/pinia-colada/src/index.ts b/packages/pinia-colada/src/index.ts index 395c47b245..eac240f021 100644 --- a/packages/pinia-colada/src/index.ts +++ b/packages/pinia-colada/src/index.ts @@ -40,7 +40,19 @@ export type { export type { SharedUtils } from './shared-utils' export * from './ssr' export type { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from './stream-query' -export { OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL } from './types' +export { + /** + * @deprecated Use `PINIA_COLADA_OPERATION_CONTEXT_SYMBOL` instead. + */ + OPERATION_CONTEXT_SYMBOL, + OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, +} from './types' +export type { + /** + * @deprecated Use `PiniaColadaOperationContext` instead. + */ + OperationContext, +} from './types' export type { InferLiveQueryOutput, InferStreamedQueryOutput, diff --git a/packages/swr/src/index.test.ts b/packages/swr/src/index.test.ts index dc871442d3..4558b68152 100644 --- a/packages/swr/src/index.test.ts +++ b/packages/swr/src/index.test.ts @@ -5,11 +5,11 @@ it('exports createSWRUtils, SWR_OPERATION_CONTEXT_SYMBOL', async () => { }) }) -it('exports createRouterUtils, but no generic context symbol or utils classes', async () => { +it('exports the generic names, but no utils classes', async () => { const exports = await import('./index') expect(exports).toHaveProperty('createRouterUtils') - expect(exports).not.toHaveProperty('OPERATION_CONTEXT_SYMBOL') + expect(exports).toHaveProperty('OPERATION_CONTEXT_SYMBOL') expect(exports).not.toHaveProperty('ProcedureUtils') expect(exports).not.toHaveProperty('SharedUtils') }) diff --git a/packages/swr/src/index.ts b/packages/swr/src/index.ts index 47284882c1..9a6604fd3d 100644 --- a/packages/swr/src/index.ts +++ b/packages/swr/src/index.ts @@ -3,7 +3,19 @@ export type { ProcedureUtils, ProcedureUtilsOptions } from './procedure-utils' export { createRouterUtils, createRouterUtils as createSWRUtils } from './router-utils' export type { RouterUtils, RouterUtilsInternal, RouterUtilsOptions } from './router-utils' export type { SharedUtils } from './shared-utils' -export { OPERATION_CONTEXT_SYMBOL as SWR_OPERATION_CONTEXT_SYMBOL } from './types' +export { + /** + * @deprecated Use `SWR_OPERATION_CONTEXT_SYMBOL` instead. + */ + OPERATION_CONTEXT_SYMBOL, + OPERATION_CONTEXT_SYMBOL as SWR_OPERATION_CONTEXT_SYMBOL, +} from './types' +export type { + /** + * @deprecated Use `SWROperationContext` instead. + */ + OperationContext, +} from './types' export type { Fetcher, FetcherOptions, diff --git a/packages/tanstack-query/src/index.test.ts b/packages/tanstack-query/src/index.test.ts index ccedb815c7..ad98198b57 100644 --- a/packages/tanstack-query/src/index.test.ts +++ b/packages/tanstack-query/src/index.test.ts @@ -5,11 +5,11 @@ it('exports createTanstackQueryUtils, TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL', }) }) -it('exports createRouterUtils, but no generic context symbol or utils classes', async () => { +it('exports the generic names, but no utils classes', async () => { const exports = await import('./index') expect(exports).toHaveProperty('createRouterUtils') - expect(exports).not.toHaveProperty('OPERATION_CONTEXT_SYMBOL') + expect(exports).toHaveProperty('OPERATION_CONTEXT_SYMBOL') expect(exports).not.toHaveProperty('ProcedureUtils') expect(exports).not.toHaveProperty('SharedUtils') }) diff --git a/packages/tanstack-query/src/index.ts b/packages/tanstack-query/src/index.ts index 7f51b857d4..e79203ab55 100644 --- a/packages/tanstack-query/src/index.ts +++ b/packages/tanstack-query/src/index.ts @@ -35,7 +35,19 @@ export type { SharedUtils } from './shared-utils' export * from './ssr' export type { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from './stream-query' export * from './structural-sharing' -export { OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL } from './types' +export { + /** + * @deprecated Use `TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL` instead. + */ + OPERATION_CONTEXT_SYMBOL, + OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, +} from './types' +export type { + /** + * @deprecated Use `TanstackQueryOperationContext` instead. + */ + OperationContext, +} from './types' export type { InferLiveQueryOutput, InferStreamedQueryOutput, From f6a8404b3967e4bbf877782a605d282da08623c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=8Bnh=20L=C3=AA?= Date: Mon, 23 Nov 2026 14:18:42 +0700 Subject: [PATCH 04/11] docs(tanstack-query): drop a migration note that does not apply to v1 --- apps/content/docs/migrations/from-v1.mdx | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/content/docs/migrations/from-v1.mdx b/apps/content/docs/migrations/from-v1.mdx index 1b355bbb16..80a7c256bf 100644 --- a/apps/content/docs/migrations/from-v1.mdx +++ b/apps/content/docs/migrations/from-v1.mdx @@ -1193,8 +1193,6 @@ orpc.live.experimental_liveOptions({ input: {} }) `experimental_defaults` became `scoped`, and the hydration serializer changed from `StandardRPCJsonSerializer` to `RPCJsonSerializer` (see [RPC JSON Serializer](/docs/rpc/serializer#rpc-json-serializer)). -`ProcedureUtils` and `SharedUtils` are exported as types only. - Streamed queries changed (see [Streamed Query Options](/docs/integrations/tanstack-query#streamed-query-options)): - `refetchMode: 'reset'` keeps the old data until the new stream connects, then sets it to `[]`. (v1 cleared it immediately, returning the query to `pending`.) From c3d8baebf628c1c984d7bdd4c9811aaea71bc9bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=8Bnh=20L=C3=AA?= Date: Mon, 23 Nov 2026 14:24:23 +0700 Subject: [PATCH 05/11] test(tanstack-query, pinia-colada, swr, msw): merge export assertions into one test --- packages/msw/src/index.test.ts | 9 +++------ packages/pinia-colada/src/index.test.ts | 13 +++++-------- packages/swr/src/index.test.ts | 13 +++++-------- packages/tanstack-query/src/index.test.ts | 13 +++++-------- 4 files changed, 18 insertions(+), 30 deletions(-) diff --git a/packages/msw/src/index.test.ts b/packages/msw/src/index.test.ts index 9ec11a90a2..6366096d8e 100644 --- a/packages/msw/src/index.test.ts +++ b/packages/msw/src/index.test.ts @@ -1,11 +1,8 @@ it('exports createHTTPUtils', async () => { - await expect(import('./index')).resolves.toMatchObject({ - createHTTPUtils: expect.any(Function), - }) -}) - -it('does not export generic names or utils classes', async () => { const exports = await import('./index') + expect(exports).toMatchObject({ + createHTTPUtils: expect.any(Function), + }) expect(exports).not.toHaveProperty('HTTPProcedureUtils') }) diff --git a/packages/pinia-colada/src/index.test.ts b/packages/pinia-colada/src/index.test.ts index f8dde266b1..5ea47cc05d 100644 --- a/packages/pinia-colada/src/index.test.ts +++ b/packages/pinia-colada/src/index.test.ts @@ -1,16 +1,13 @@ it('exports createPiniaColadaUtils, PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, StreamQuerySSRUtilsPlugin', async () => { - await expect(import('./index')).resolves.toMatchObject({ + const exports = await import('./index') + + expect(exports).toMatchObject({ createPiniaColadaUtils: expect.any(Function), + createRouterUtils: expect.any(Function), PINIA_COLADA_OPERATION_CONTEXT_SYMBOL: expect.any(Symbol), + OPERATION_CONTEXT_SYMBOL: expect.any(Symbol), StreamQuerySSRUtilsPlugin: expect.any(Function), }) -}) - -it('exports the generic names, but no utils classes', async () => { - const exports = await import('./index') - - expect(exports).toHaveProperty('createRouterUtils') - expect(exports).toHaveProperty('OPERATION_CONTEXT_SYMBOL') expect(exports).not.toHaveProperty('ProcedureUtils') expect(exports).not.toHaveProperty('SharedUtils') }) diff --git a/packages/swr/src/index.test.ts b/packages/swr/src/index.test.ts index 4558b68152..7943470f31 100644 --- a/packages/swr/src/index.test.ts +++ b/packages/swr/src/index.test.ts @@ -1,15 +1,12 @@ it('exports createSWRUtils, SWR_OPERATION_CONTEXT_SYMBOL', async () => { - await expect(import('./index')).resolves.toMatchObject({ + const exports = await import('./index') + + expect(exports).toMatchObject({ createSWRUtils: expect.any(Function), + createRouterUtils: expect.any(Function), SWR_OPERATION_CONTEXT_SYMBOL: expect.any(Symbol), + OPERATION_CONTEXT_SYMBOL: expect.any(Symbol), }) -}) - -it('exports the generic names, but no utils classes', async () => { - const exports = await import('./index') - - expect(exports).toHaveProperty('createRouterUtils') - expect(exports).toHaveProperty('OPERATION_CONTEXT_SYMBOL') expect(exports).not.toHaveProperty('ProcedureUtils') expect(exports).not.toHaveProperty('SharedUtils') }) diff --git a/packages/tanstack-query/src/index.test.ts b/packages/tanstack-query/src/index.test.ts index ad98198b57..65ea0379ab 100644 --- a/packages/tanstack-query/src/index.test.ts +++ b/packages/tanstack-query/src/index.test.ts @@ -1,15 +1,12 @@ it('exports createTanstackQueryUtils, TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL', async () => { - await expect(import('./index')).resolves.toMatchObject({ + const exports = await import('./index') + + expect(exports).toMatchObject({ createTanstackQueryUtils: expect.any(Function), + createRouterUtils: expect.any(Function), TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL: expect.any(Symbol), + OPERATION_CONTEXT_SYMBOL: expect.any(Symbol), }) -}) - -it('exports the generic names, but no utils classes', async () => { - const exports = await import('./index') - - expect(exports).toHaveProperty('createRouterUtils') - expect(exports).toHaveProperty('OPERATION_CONTEXT_SYMBOL') expect(exports).not.toHaveProperty('ProcedureUtils') expect(exports).not.toHaveProperty('SharedUtils') }) From 5469f6b74db6e34930bf39809f741f8c91715a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=8Bnh=20L=C3=AA?= Date: Mon, 23 Nov 2026 14:26:50 +0700 Subject: [PATCH 06/11] refactor(tanstack-query, pinia-colada, swr, msw): keep the utils classes as runtime exports --- packages/msw/src/index.test.ts | 2 +- packages/msw/src/index.ts | 3 ++- packages/pinia-colada/src/index.test.ts | 4 ++-- packages/pinia-colada/src/index.ts | 5 ++--- packages/swr/src/index.test.ts | 4 ++-- packages/swr/src/index.ts | 5 +++-- packages/tanstack-query/src/index.test.ts | 4 ++-- packages/tanstack-query/src/index.ts | 5 ++--- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/msw/src/index.test.ts b/packages/msw/src/index.test.ts index 6366096d8e..d30cf2cc43 100644 --- a/packages/msw/src/index.test.ts +++ b/packages/msw/src/index.test.ts @@ -3,6 +3,6 @@ it('exports createHTTPUtils', async () => { expect(exports).toMatchObject({ createHTTPUtils: expect.any(Function), + HTTPProcedureUtils: expect.any(Function), }) - expect(exports).not.toHaveProperty('HTTPProcedureUtils') }) diff --git a/packages/msw/src/index.ts b/packages/msw/src/index.ts index c4460c5d31..76e4c6b0a2 100644 --- a/packages/msw/src/index.ts +++ b/packages/msw/src/index.ts @@ -1,4 +1,5 @@ -export type { HTTPProcedureUtils, HTTPProcedureUtilsOptions } from './http-procedure-utils' +export { HTTPProcedureUtils } from './http-procedure-utils' +export type { HTTPProcedureUtilsOptions } from './http-procedure-utils' export { createHTTPUtils } from './http-router-utils' export type { HTTPRouterUtils, diff --git a/packages/pinia-colada/src/index.test.ts b/packages/pinia-colada/src/index.test.ts index 5ea47cc05d..deed51796a 100644 --- a/packages/pinia-colada/src/index.test.ts +++ b/packages/pinia-colada/src/index.test.ts @@ -4,10 +4,10 @@ it('exports createPiniaColadaUtils, PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, Strea expect(exports).toMatchObject({ createPiniaColadaUtils: expect.any(Function), createRouterUtils: expect.any(Function), + ProcedureUtils: expect.any(Function), + SharedUtils: expect.any(Function), PINIA_COLADA_OPERATION_CONTEXT_SYMBOL: expect.any(Symbol), OPERATION_CONTEXT_SYMBOL: expect.any(Symbol), StreamQuerySSRUtilsPlugin: expect.any(Function), }) - expect(exports).not.toHaveProperty('ProcedureUtils') - expect(exports).not.toHaveProperty('SharedUtils') }) diff --git a/packages/pinia-colada/src/index.ts b/packages/pinia-colada/src/index.ts index eac240f021..1510ad2583 100644 --- a/packages/pinia-colada/src/index.ts +++ b/packages/pinia-colada/src/index.ts @@ -7,9 +7,8 @@ export type { } from './key' export * from './meta' export type { RouterUtilsPlugin } from './plugin' -export { mergeProcedureUtilsOptions } from './procedure-utils' +export { mergeProcedureUtilsOptions, ProcedureUtils } from './procedure-utils' export type { - ProcedureUtils, ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, @@ -37,7 +36,7 @@ export type { RouterUtilsScoped, RouterUtilsScopedInternal, } from './router-utils' -export type { SharedUtils } from './shared-utils' +export { SharedUtils } from './shared-utils' export * from './ssr' export type { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from './stream-query' export { diff --git a/packages/swr/src/index.test.ts b/packages/swr/src/index.test.ts index 7943470f31..c5035a661a 100644 --- a/packages/swr/src/index.test.ts +++ b/packages/swr/src/index.test.ts @@ -4,9 +4,9 @@ it('exports createSWRUtils, SWR_OPERATION_CONTEXT_SYMBOL', async () => { expect(exports).toMatchObject({ createSWRUtils: expect.any(Function), createRouterUtils: expect.any(Function), + ProcedureUtils: expect.any(Function), + SharedUtils: expect.any(Function), SWR_OPERATION_CONTEXT_SYMBOL: expect.any(Symbol), OPERATION_CONTEXT_SYMBOL: expect.any(Symbol), }) - expect(exports).not.toHaveProperty('ProcedureUtils') - expect(exports).not.toHaveProperty('SharedUtils') }) diff --git a/packages/swr/src/index.ts b/packages/swr/src/index.ts index 9a6604fd3d..d18f1a7d62 100644 --- a/packages/swr/src/index.ts +++ b/packages/swr/src/index.ts @@ -1,8 +1,9 @@ export type { OperationKey, OperationKeyOptions, OperationKeyPrefixOptions } from './key' -export type { ProcedureUtils, ProcedureUtilsOptions } from './procedure-utils' +export { ProcedureUtils } from './procedure-utils' +export type { ProcedureUtilsOptions } from './procedure-utils' export { createRouterUtils, createRouterUtils as createSWRUtils } from './router-utils' export type { RouterUtils, RouterUtilsInternal, RouterUtilsOptions } from './router-utils' -export type { SharedUtils } from './shared-utils' +export { SharedUtils } from './shared-utils' export { /** * @deprecated Use `SWR_OPERATION_CONTEXT_SYMBOL` instead. diff --git a/packages/tanstack-query/src/index.test.ts b/packages/tanstack-query/src/index.test.ts index 65ea0379ab..7a33481721 100644 --- a/packages/tanstack-query/src/index.test.ts +++ b/packages/tanstack-query/src/index.test.ts @@ -4,9 +4,9 @@ it('exports createTanstackQueryUtils, TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL', expect(exports).toMatchObject({ createTanstackQueryUtils: expect.any(Function), createRouterUtils: expect.any(Function), + ProcedureUtils: expect.any(Function), + SharedUtils: expect.any(Function), TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL: expect.any(Symbol), OPERATION_CONTEXT_SYMBOL: expect.any(Symbol), }) - expect(exports).not.toHaveProperty('ProcedureUtils') - expect(exports).not.toHaveProperty('SharedUtils') }) diff --git a/packages/tanstack-query/src/index.ts b/packages/tanstack-query/src/index.ts index e79203ab55..6421c2a4d0 100644 --- a/packages/tanstack-query/src/index.ts +++ b/packages/tanstack-query/src/index.ts @@ -7,9 +7,8 @@ export type { } from './key' export * from './meta' export type { RouterUtilsPlugin } from './plugin' -export { mergeProcedureUtilsOptions } from './procedure-utils' +export { mergeProcedureUtilsOptions, ProcedureUtils } from './procedure-utils' export type { - ProcedureUtils, ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, @@ -31,7 +30,7 @@ export type { RouterUtilsScoped, RouterUtilsScopedInternal, } from './router-utils' -export type { SharedUtils } from './shared-utils' +export { SharedUtils } from './shared-utils' export * from './ssr' export type { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from './stream-query' export * from './structural-sharing' From 7bc67c6ad71fcf4973834be4638116b5aa9a7fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=8Bnh=20L=C3=AA?= Date: Mon, 23 Nov 2026 14:27:10 +0700 Subject: [PATCH 07/11] refactor(tanstack-query): keep exporting the *InRest types --- packages/tanstack-query/src/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/tanstack-query/src/index.ts b/packages/tanstack-query/src/index.ts index 6421c2a4d0..ea94447d49 100644 --- a/packages/tanstack-query/src/index.ts +++ b/packages/tanstack-query/src/index.ts @@ -54,15 +54,19 @@ export type { InfiniteOptionsIn, InfiniteOptionsOut, LiveOptionsIn, + LiveOptionsInRest, MutationKeyOptions, MutationOptionsIn, + MutationOptionsInRest, MutationOptionsOut, OperationType, QueryKeyOptions, QueryOptionsIn, + QueryOptionsInRest, QueryOptionsOut, StreamedKeyOptions, StreamedOptionsIn, + StreamedOptionsInRest, StreamedOptionsOut, OperationContext as TanstackQueryOperationContext, } from './types' From 33b163868b62064e5bc7bbae8b2cff658021e1c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=8Bnh=20L=C3=AA?= Date: Mon, 23 Nov 2026 14:27:39 +0700 Subject: [PATCH 08/11] refactor(tanstack-query, pinia-colada, swr, msw): go back to export * in the entry files --- packages/msw/src/index.ts | 7 +---- packages/pinia-colada/src/index.ts | 37 ++++---------------------- packages/swr/src/index.ts | 26 ++++--------------- packages/tanstack-query/src/index.ts | 39 ++++------------------------ 4 files changed, 16 insertions(+), 93 deletions(-) diff --git a/packages/msw/src/index.ts b/packages/msw/src/index.ts index 76e4c6b0a2..48c94b2f53 100644 --- a/packages/msw/src/index.ts +++ b/packages/msw/src/index.ts @@ -1,8 +1,3 @@ export { HTTPProcedureUtils } from './http-procedure-utils' export type { HTTPProcedureUtilsOptions } from './http-procedure-utils' -export { createHTTPUtils } from './http-router-utils' -export type { - HTTPRouterUtils, - HTTPRouterUtilsInternal, - HTTPRouterUtilsOptions, -} from './http-router-utils' +export * from './http-router-utils' diff --git a/packages/pinia-colada/src/index.ts b/packages/pinia-colada/src/index.ts index 1510ad2583..1a3328b70a 100644 --- a/packages/pinia-colada/src/index.ts +++ b/packages/pinia-colada/src/index.ts @@ -22,56 +22,29 @@ export type { ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, } from './procedure-utils' +export * from './router-utils' export { /** * @deprecated Use `createPiniaColadaUtils` instead. */ createRouterUtils as createORPCVueColadaUtils, } from './router-utils' -export { createRouterUtils, createRouterUtils as createPiniaColadaUtils } from './router-utils' -export type { - RouterUtils, - RouterUtilsInternal, - RouterUtilsOptions, - RouterUtilsScoped, - RouterUtilsScopedInternal, -} from './router-utils' +export { createRouterUtils as createPiniaColadaUtils } from './router-utils' export { SharedUtils } from './shared-utils' export * from './ssr' export type { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from './stream-query' +export * from './types' export { /** * @deprecated Use `PINIA_COLADA_OPERATION_CONTEXT_SYMBOL` instead. */ OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, -} from './types' -export type { /** * @deprecated Use `PiniaColadaOperationContext` instead. */ - OperationContext, -} from './types' -export type { - InferLiveQueryOutput, - InferStreamedQueryOutput, - InfiniteKeyOptions, - InfiniteOptionsIn, - InfiniteOptionsOut, - LiveOptionsIn, - MutationKeyOptions, - MutationOptionsIn, - MutationOptionsOut, - OperationType, - OperationContext as PiniaColadaOperationContext, - QueryKeyOptions, - QueryOptionsIn, - QueryOptionsOut, - StreamedKeyOptions, - StreamedOptionsIn, - StreamedOptionsOut, - UseMutationFnContext, - UseQueryFnContext, + type OperationContext, + type OperationContext as PiniaColadaOperationContext, } from './types' export type { AnyNestedClient } from '@orpc/client' diff --git a/packages/swr/src/index.ts b/packages/swr/src/index.ts index d18f1a7d62..54eb48b552 100644 --- a/packages/swr/src/index.ts +++ b/packages/swr/src/index.ts @@ -1,37 +1,21 @@ export type { OperationKey, OperationKeyOptions, OperationKeyPrefixOptions } from './key' export { ProcedureUtils } from './procedure-utils' export type { ProcedureUtilsOptions } from './procedure-utils' -export { createRouterUtils, createRouterUtils as createSWRUtils } from './router-utils' -export type { RouterUtils, RouterUtilsInternal, RouterUtilsOptions } from './router-utils' +export * from './router-utils' +export { createRouterUtils as createSWRUtils } from './router-utils' export { SharedUtils } from './shared-utils' +export * from './types' export { /** * @deprecated Use `SWR_OPERATION_CONTEXT_SYMBOL` instead. */ OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as SWR_OPERATION_CONTEXT_SYMBOL, -} from './types' -export type { /** * @deprecated Use `SWROperationContext` instead. */ - OperationContext, -} from './types' -export type { - Fetcher, - FetcherOptions, - InferLiveSubscriberOutput, - InferSubscriberOutput, - KeyOptions, - Matcher, - MatcherOptions, - MatcherStrategy, - Mutator, - MutatorOptions, - OperationType, - Subscriber, - SubscriberOptions, - OperationContext as SWROperationContext, + type OperationContext, + type OperationContext as SWROperationContext, } from './types' export type { Public } from '@orpc/shared' diff --git a/packages/tanstack-query/src/index.ts b/packages/tanstack-query/src/index.ts index ea94447d49..8e524ad4b5 100644 --- a/packages/tanstack-query/src/index.ts +++ b/packages/tanstack-query/src/index.ts @@ -22,53 +22,24 @@ export type { ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, } from './procedure-utils' -export { createRouterUtils, createRouterUtils as createTanstackQueryUtils } from './router-utils' -export type { - RouterUtils, - RouterUtilsInternal, - RouterUtilsOptions, - RouterUtilsScoped, - RouterUtilsScopedInternal, -} from './router-utils' +export * from './router-utils' +export { createRouterUtils as createTanstackQueryUtils } from './router-utils' export { SharedUtils } from './shared-utils' export * from './ssr' export type { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from './stream-query' export * from './structural-sharing' +export * from './types' export { /** * @deprecated Use `TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL` instead. */ OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, -} from './types' -export type { /** * @deprecated Use `TanstackQueryOperationContext` instead. */ - OperationContext, -} from './types' -export type { - InferLiveQueryOutput, - InferStreamedQueryOutput, - InfiniteKeyOptions, - InfiniteOptionsIn, - InfiniteOptionsOut, - LiveOptionsIn, - LiveOptionsInRest, - MutationKeyOptions, - MutationOptionsIn, - MutationOptionsInRest, - MutationOptionsOut, - OperationType, - QueryKeyOptions, - QueryOptionsIn, - QueryOptionsInRest, - QueryOptionsOut, - StreamedKeyOptions, - StreamedOptionsIn, - StreamedOptionsInRest, - StreamedOptionsOut, - OperationContext as TanstackQueryOperationContext, + type OperationContext, + type OperationContext as TanstackQueryOperationContext, } from './types' export type { AnyNestedClient } from '@orpc/client' From 2ac5a9b89efe902a9aa5e4ffff1ecc07e08d7baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=8Bnh=20L=C3=AA?= Date: Mon, 23 Nov 2026 14:29:27 +0700 Subject: [PATCH 09/11] refactor(tanstack-query, pinia-colada, swr): declare the operation context under package-specific names --- .../pinia-colada/src/contract-utils.test-d.ts | 22 ++++++--- packages/pinia-colada/src/index.ts | 6 +-- packages/pinia-colada/src/meta.test-d.ts | 4 +- .../pinia-colada/src/procedure-utils.test.ts | 46 +++++++++---------- packages/pinia-colada/src/procedure-utils.ts | 30 ++++++------ packages/pinia-colada/src/types.ts | 6 +-- packages/swr/src/index.ts | 6 +-- packages/swr/src/procedure-utils.test.ts | 21 +++++---- packages/swr/src/procedure-utils.ts | 20 ++++---- packages/swr/src/types.ts | 6 +-- .../src/contract-utils.test-d.ts | 22 ++++++--- packages/tanstack-query/src/index.ts | 6 +-- packages/tanstack-query/src/meta.test-d.ts | 4 +- .../src/procedure-utils.test.ts | 36 +++++++-------- .../tanstack-query/src/procedure-utils.ts | 26 +++++------ packages/tanstack-query/src/types.ts | 6 +-- 16 files changed, 140 insertions(+), 127 deletions(-) diff --git a/packages/pinia-colada/src/contract-utils.test-d.ts b/packages/pinia-colada/src/contract-utils.test-d.ts index 6371c6d874..41af8260ef 100644 --- a/packages/pinia-colada/src/contract-utils.test-d.ts +++ b/packages/pinia-colada/src/contract-utils.test-d.ts @@ -7,7 +7,7 @@ import type { PromiseWithError } from '@orpc/shared' import { createContractJsonifiedUtilsFactory, createContractUtilsFactory } from './contract-utils' import type { ProcedureUtils } from './procedure-utils' import type { SharedUtils } from './shared-utils' -import type { OperationContext } from './types' +import type { PiniaColadaOperationContext } from './types' const contract = { ping: oc.meta(meta.path(['ping'])), @@ -29,7 +29,7 @@ describe('createContractUtilsFactory', () => { mutationInterceptors: [ async ({ context, next, input }) => { expectTypeOf(input).toEqualTypeOf() - expectTypeOf(context).toEqualTypeOf<{ cache?: boolean } & OperationContext>() + expectTypeOf(context).toEqualTypeOf<{ cache?: boolean } & PiniaColadaOperationContext>() const result = next() @@ -43,7 +43,9 @@ describe('createContractUtilsFactory', () => { queryInterceptors: [ async ({ context, next, input }) => { expectTypeOf(input).toEqualTypeOf() - expectTypeOf(context).toEqualTypeOf<{ cache?: boolean } & OperationContext>() + expectTypeOf(context).toEqualTypeOf< + { cache?: boolean } & PiniaColadaOperationContext + >() const result = next() @@ -60,7 +62,9 @@ describe('createContractUtilsFactory', () => { mutationInterceptors: [ async ({ context, next, input }) => { expectTypeOf(input).toEqualTypeOf() - expectTypeOf(context).toEqualTypeOf<{ cache?: boolean } & OperationContext>() + expectTypeOf(context).toEqualTypeOf< + { cache?: boolean } & PiniaColadaOperationContext + >() const result = next() @@ -110,7 +114,7 @@ describe('createContractJsonifiedUtilsFactory', () => { mutationInterceptors: [ async ({ context, next, input }) => { expectTypeOf(input).toEqualTypeOf() - expectTypeOf(context).toEqualTypeOf<{ cache?: boolean } & OperationContext>() + expectTypeOf(context).toEqualTypeOf<{ cache?: boolean } & PiniaColadaOperationContext>() const result = next() @@ -124,7 +128,9 @@ describe('createContractJsonifiedUtilsFactory', () => { queryInterceptors: [ async ({ context, next, input }) => { expectTypeOf(input).toEqualTypeOf() - expectTypeOf(context).toEqualTypeOf<{ cache?: boolean } & OperationContext>() + expectTypeOf(context).toEqualTypeOf< + { cache?: boolean } & PiniaColadaOperationContext + >() const result = next() @@ -141,7 +147,9 @@ describe('createContractJsonifiedUtilsFactory', () => { mutationInterceptors: [ async ({ context, next, input }) => { expectTypeOf(input).toEqualTypeOf() - expectTypeOf(context).toEqualTypeOf<{ cache?: boolean } & OperationContext>() + expectTypeOf(context).toEqualTypeOf< + { cache?: boolean } & PiniaColadaOperationContext + >() const result = next() diff --git a/packages/pinia-colada/src/index.ts b/packages/pinia-colada/src/index.ts index 1a3328b70a..5209086de2 100644 --- a/packages/pinia-colada/src/index.ts +++ b/packages/pinia-colada/src/index.ts @@ -38,13 +38,11 @@ export { /** * @deprecated Use `PINIA_COLADA_OPERATION_CONTEXT_SYMBOL` instead. */ - OPERATION_CONTEXT_SYMBOL, - OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, + PINIA_COLADA_OPERATION_CONTEXT_SYMBOL as OPERATION_CONTEXT_SYMBOL, /** * @deprecated Use `PiniaColadaOperationContext` instead. */ - type OperationContext, - type OperationContext as PiniaColadaOperationContext, + type PiniaColadaOperationContext as OperationContext, } from './types' export type { AnyNestedClient } from '@orpc/client' diff --git a/packages/pinia-colada/src/meta.test-d.ts b/packages/pinia-colada/src/meta.test-d.ts index ce671784af..c7b11b80fe 100644 --- a/packages/pinia-colada/src/meta.test-d.ts +++ b/packages/pinia-colada/src/meta.test-d.ts @@ -3,7 +3,7 @@ import { oc, type } from '@orpc/contract' import type { PromiseWithError } from '@orpc/shared' import { piniaColada } from './meta' -import type { OperationContext } from './types' +import type { PiniaColadaOperationContext } from './types' describe('piniaColada', () => { it('infers input, output and error types from the contract', () => { @@ -16,7 +16,7 @@ describe('piniaColada', () => { queryInterceptors: [ async ({ context, input, next }) => { expectTypeOf(input).toEqualTypeOf() - expectTypeOf(context).toEqualTypeOf() + expectTypeOf(context).toEqualTypeOf() const result = next() diff --git a/packages/pinia-colada/src/procedure-utils.test.ts b/packages/pinia-colada/src/procedure-utils.test.ts index 89a6161394..45545642dc 100644 --- a/packages/pinia-colada/src/procedure-utils.test.ts +++ b/packages/pinia-colada/src/procedure-utils.test.ts @@ -8,7 +8,7 @@ import { ProcedureUtils, } from './procedure-utils' import * as StreamQueryModule from './stream-query' -import { OPERATION_CONTEXT_SYMBOL } from './types' +import { PINIA_COLADA_OPERATION_CONTEXT_SYMBOL } from './types' const generateOperationKeySpy = vi.spyOn(KeyModule, 'generateOperationKey') const streamedQuerySpy = vi.spyOn(StreamQueryModule, 'serializableStreamedQuery') @@ -174,7 +174,7 @@ describe('procedureUtils', () => { expect(client).toHaveBeenCalledWith(1, { signal: expect.any(AbortSignal), context: { - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: options.key, type: 'streamed', }, @@ -265,7 +265,7 @@ describe('procedureUtils', () => { fnContext, context: { batch: true, - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: options.key, type: 'streamed', }, @@ -281,7 +281,7 @@ describe('procedureUtils', () => { signal: expect.any(AbortSignal), context: { batch: true, - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: options.key, type: 'streamed', }, @@ -398,7 +398,7 @@ describe('procedureUtils', () => { expect(client).toHaveBeenCalledWith(1, { signal: expect.any(AbortSignal), context: { - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: options.key, type: 'live', }, @@ -480,7 +480,7 @@ describe('procedureUtils', () => { fnContext, context: { batch: true, - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: options.key, type: 'live', }, @@ -496,7 +496,7 @@ describe('procedureUtils', () => { signal: expect.any(AbortSignal), context: { batch: true, - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: options.key, type: 'live', }, @@ -680,7 +680,7 @@ describe('procedureUtils', () => { expect(client).toHaveBeenCalledWith(1, { signal, context: { - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: options.key, type: 'query', }, @@ -704,7 +704,7 @@ describe('procedureUtils', () => { expect(client).toHaveBeenCalledWith(undefined, { signal, context: { - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: options.key, type: 'query', }, @@ -722,7 +722,7 @@ describe('procedureUtils', () => { signal, context: { batch: true, - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: options.key, type: 'query', }, @@ -747,7 +747,7 @@ describe('procedureUtils', () => { expect(client).toHaveBeenCalledWith(undefined, { signal, context: { - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: ['__custom__'], type: 'query', }, @@ -803,7 +803,7 @@ describe('procedureUtils', () => { fnContext, context: { batch: true, - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: options.key, type: 'query', }, @@ -821,7 +821,7 @@ describe('procedureUtils', () => { context: { batch: true, extra: true, - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: options.key, type: 'query', }, @@ -881,7 +881,7 @@ describe('procedureUtils', () => { { signal, context: { - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: options.key, type: 'infinite', }, @@ -919,7 +919,7 @@ describe('procedureUtils', () => { signal, context: { batch: true, - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: options.key, type: 'infinite', }, @@ -952,7 +952,7 @@ describe('procedureUtils', () => { { signal, context: { - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: ['__custom__'], type: 'infinite', }, @@ -1008,7 +1008,7 @@ describe('procedureUtils', () => { fnContext, context: { batch: true, - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: options.key, type: 'infinite', }, @@ -1025,7 +1025,7 @@ describe('procedureUtils', () => { signal, context: { batch: true, - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: options.key, type: 'infinite', }, @@ -1077,7 +1077,7 @@ describe('procedureUtils', () => { expect(client).toHaveBeenCalledTimes(1) expect(client).toHaveBeenCalledWith(1, { context: { - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: generateOperationKeySpy.mock.results[1]!.value, type: 'mutation', }, @@ -1105,7 +1105,7 @@ describe('procedureUtils', () => { expect(client).toHaveBeenCalledWith(1, { context: { batch: true, - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: generateOperationKeySpy.mock.results[1]!.value, type: 'mutation', }, @@ -1130,7 +1130,7 @@ describe('procedureUtils', () => { await expect(options.mutation(1, {})).resolves.toEqual('__mocked__') expect(client).toHaveBeenCalledWith(1, { context: { - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: ['__custom__'], type: 'mutation', }, @@ -1182,7 +1182,7 @@ describe('procedureUtils', () => { fnContext, context: { batch: true, - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: generateOperationKeySpy.mock.results[0]!.value, type: 'mutation', }, @@ -1198,7 +1198,7 @@ describe('procedureUtils', () => { expect(client).toHaveBeenCalledWith('__override__', { context: { batch: true, - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: generateOperationKeySpy.mock.results[0]!.value, type: 'mutation', }, diff --git a/packages/pinia-colada/src/procedure-utils.ts b/packages/pinia-colada/src/procedure-utils.ts index cad4cf7586..f914f5e3af 100644 --- a/packages/pinia-colada/src/procedure-utils.ts +++ b/packages/pinia-colada/src/procedure-utils.ts @@ -27,7 +27,7 @@ import type { MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, - OperationContext, + PiniaColadaOperationContext, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, @@ -37,14 +37,14 @@ import type { UseMutationFnContext, UseQueryFnContext, } from './types' -import { OPERATION_CONTEXT_SYMBOL } from './types' +import { PINIA_COLADA_OPERATION_CONTEXT_SYMBOL } from './types' export interface ProcedureUtilsQueryInterceptorOptions< TClientContext extends ClientContext, TInput, > { path: string[] - context: TClientContext & OperationContext + context: TClientContext & PiniaColadaOperationContext input: TInput fnContext: UseQueryFnContext } @@ -91,7 +91,7 @@ export interface ProcedureUtilsInfiniteInterceptorOptions< TInput, > { path: string[] - context: TClientContext & OperationContext + context: TClientContext & PiniaColadaOperationContext input: TInput fnContext: UseInfiniteQueryFnContext } @@ -110,7 +110,7 @@ export interface ProcedureUtilsMutationInterceptorOptions< TInput, > { path: string[] - context: TClientContext & OperationContext + context: TClientContext & PiniaColadaOperationContext input: TInput fnContext: UseMutationFnContext } @@ -473,12 +473,12 @@ export class ProcedureUtils< { path: this.path, context: { - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key, type: 'query', }, ...context, - } satisfies OperationContext as any, + } satisfies PiniaColadaOperationContext as any, input: input as TInput, fnContext, }, @@ -567,12 +567,12 @@ export class ProcedureUtils< { path: this.path, context: { - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key, type: 'streamed', }, ...context, - } satisfies OperationContext as any, + } satisfies PiniaColadaOperationContext as any, input: input as TInput, fnContext, }, @@ -662,12 +662,12 @@ export class ProcedureUtils< { path: this.path, context: { - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key, type: 'live', }, ...context, - } satisfies OperationContext as any, + } satisfies PiniaColadaOperationContext as any, input: input as TInput, fnContext, }, @@ -758,12 +758,12 @@ export class ProcedureUtils< { path: this.path, context: { - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key, type: 'infinite', }, ...context, - } satisfies OperationContext as any, + } satisfies PiniaColadaOperationContext as any, input: input(fnContext.pageParam) as TInput, fnContext, }, @@ -837,12 +837,12 @@ export class ProcedureUtils< { path: this.path, context: { - [OPERATION_CONTEXT_SYMBOL]: { + [PINIA_COLADA_OPERATION_CONTEXT_SYMBOL]: { key: typeof key === 'function' ? key(input) : key, type: 'mutation', }, ...context, - } satisfies OperationContext as any, + } satisfies PiniaColadaOperationContext as any, input, fnContext, }, diff --git a/packages/pinia-colada/src/types.ts b/packages/pinia-colada/src/types.ts index 9b40dc697f..d5521d7571 100644 --- a/packages/pinia-colada/src/types.ts +++ b/packages/pinia-colada/src/types.ts @@ -31,7 +31,7 @@ export type UseMutationFnContext = Parameters { vi.clearAllMocks() @@ -45,7 +45,7 @@ describe('procedureUtils', () => { expect(client).toHaveBeenCalledTimes(1) expect(client).toHaveBeenCalledWith( { search: '__search__' }, - { context: { batch: true, [OPERATION_CONTEXT_SYMBOL]: { key, type: 'fetcher' } } }, + { context: { batch: true, [SWR_OPERATION_CONTEXT_SYMBOL]: { key, type: 'fetcher' } } }, ) }) @@ -64,7 +64,10 @@ describe('procedureUtils', () => { expect(client).toHaveBeenCalledWith( { search: '__search__' }, { - context: { batch: true, [OPERATION_CONTEXT_SYMBOL]: { key: prefixedKey, type: 'fetcher' } }, + context: { + batch: true, + [SWR_OPERATION_CONTEXT_SYMBOL]: { key: prefixedKey, type: 'fetcher' }, + }, }, ) }) @@ -90,7 +93,7 @@ describe('procedureUtils', () => { expect(client).toHaveBeenCalledWith( { search: '__search__' }, { - context: { batch: true, [OPERATION_CONTEXT_SYMBOL]: { key, type: 'subscriber' } }, + context: { batch: true, [SWR_OPERATION_CONTEXT_SYMBOL]: { key, type: 'subscriber' } }, signal: expect.any(AbortSignal), }, ) @@ -129,7 +132,7 @@ describe('procedureUtils', () => { expect(client).toHaveBeenCalledWith( { search: '__search__' }, { - context: { batch: true, [OPERATION_CONTEXT_SYMBOL]: { key, type: 'subscriber' } }, + context: { batch: true, [SWR_OPERATION_CONTEXT_SYMBOL]: { key, type: 'subscriber' } }, signal: expect.any(AbortSignal), }, ) @@ -161,7 +164,7 @@ describe('procedureUtils', () => { expect(client).toHaveBeenCalledWith( { search: '__search__' }, { - context: { batch: true, [OPERATION_CONTEXT_SYMBOL]: { key, type: 'subscriber' } }, + context: { batch: true, [SWR_OPERATION_CONTEXT_SYMBOL]: { key, type: 'subscriber' } }, signal: expect.any(AbortSignal), }, ) @@ -322,7 +325,7 @@ describe('procedureUtils', () => { expect(client).toHaveBeenCalledWith( { search: '__search__' }, { - context: { batch: true, [OPERATION_CONTEXT_SYMBOL]: { key, type: 'liveSubscriber' } }, + context: { batch: true, [SWR_OPERATION_CONTEXT_SYMBOL]: { key, type: 'liveSubscriber' } }, signal: expect.any(AbortSignal), }, ) @@ -351,7 +354,7 @@ describe('procedureUtils', () => { expect(client).toHaveBeenCalledWith( { search: '__search__' }, { - context: { batch: true, [OPERATION_CONTEXT_SYMBOL]: { key, type: 'liveSubscriber' } }, + context: { batch: true, [SWR_OPERATION_CONTEXT_SYMBOL]: { key, type: 'liveSubscriber' } }, signal: expect.any(AbortSignal), }, ) @@ -461,7 +464,7 @@ describe('procedureUtils', () => { expect(client).toHaveBeenCalledTimes(1) expect(client).toHaveBeenCalledWith( { search: '__search__' }, - { context: { batch: true, [OPERATION_CONTEXT_SYMBOL]: { key: 'key', type: 'mutator' } } }, + { context: { batch: true, [SWR_OPERATION_CONTEXT_SYMBOL]: { key: 'key', type: 'mutator' } } }, ) }) }) diff --git a/packages/swr/src/procedure-utils.ts b/packages/swr/src/procedure-utils.ts index 0a2c2c0b16..d8817e4f62 100644 --- a/packages/swr/src/procedure-utils.ts +++ b/packages/swr/src/procedure-utils.ts @@ -13,11 +13,11 @@ import type { KeyOptions, Mutator, MutatorOptions, - OperationContext, + SWROperationContext, Subscriber, SubscriberOptions, } from './types' -import { OPERATION_CONTEXT_SYMBOL } from './types' +import { SWR_OPERATION_CONTEXT_SYMBOL } from './types' export interface ProcedureUtilsOptions extends OperationKeyPrefixOptions {} @@ -74,9 +74,9 @@ export class ProcedureUtils< return this.call(input, { context: { - [OPERATION_CONTEXT_SYMBOL]: { key, type: 'fetcher' }, + [SWR_OPERATION_CONTEXT_SYMBOL]: { key, type: 'fetcher' }, ...options.context, - } satisfies OperationContext as any, + } satisfies SWROperationContext as any, }) } } @@ -104,9 +104,9 @@ export class ProcedureUtils< const iterator = await this.call(input, { context: { - [OPERATION_CONTEXT_SYMBOL]: { key, type: 'subscriber' }, + [SWR_OPERATION_CONTEXT_SYMBOL]: { key, type: 'subscriber' }, ...options.context, - } satisfies OperationContext as any, + } satisfies SWROperationContext as any, signal: controller.signal, }) @@ -175,9 +175,9 @@ export class ProcedureUtils< const iterator = await this.call(input, { context: { - [OPERATION_CONTEXT_SYMBOL]: { key, type: 'liveSubscriber' }, + [SWR_OPERATION_CONTEXT_SYMBOL]: { key, type: 'liveSubscriber' }, ...options.context, - } satisfies OperationContext as any, + } satisfies SWROperationContext as any, signal: controller.signal, }) @@ -224,9 +224,9 @@ export class ProcedureUtils< return (key, { arg }) => this.call(arg, { context: { - [OPERATION_CONTEXT_SYMBOL]: { key, type: 'mutator' }, + [SWR_OPERATION_CONTEXT_SYMBOL]: { key, type: 'mutator' }, ...options.context, - } satisfies OperationContext as any, + } satisfies SWROperationContext as any, }) } } diff --git a/packages/swr/src/types.ts b/packages/swr/src/types.ts index 99eda09541..b911ad6204 100644 --- a/packages/swr/src/types.ts +++ b/packages/swr/src/types.ts @@ -15,7 +15,7 @@ export type OperationType = 'fetcher' | 'mutator' | 'subscriber' | 'liveSubscrib * * @see {@link https://orpc.dev/docs/integrations/swr#operation-context | SWR Integration - Operation Context} */ -export const OPERATION_CONTEXT_SYMBOL: unique symbol = /* @__PURE__ */ Symbol.for( +export const SWR_OPERATION_CONTEXT_SYMBOL: unique symbol = /* @__PURE__ */ Symbol.for( 'ORPC_SWR_OPERATION_CONTEXT', ) @@ -25,8 +25,8 @@ export const OPERATION_CONTEXT_SYMBOL: unique symbol = /* @__PURE__ */ Symbol.fo * * @see {@link https://orpc.dev/docs/integrations/swr#operation-context | SWR Integration - Operation Context} */ -export interface OperationContext { - [OPERATION_CONTEXT_SYMBOL]?: { +export interface SWROperationContext { + [SWR_OPERATION_CONTEXT_SYMBOL]?: { key: unknown type: OperationType } diff --git a/packages/tanstack-query/src/contract-utils.test-d.ts b/packages/tanstack-query/src/contract-utils.test-d.ts index 6371c6d874..ee1603e79f 100644 --- a/packages/tanstack-query/src/contract-utils.test-d.ts +++ b/packages/tanstack-query/src/contract-utils.test-d.ts @@ -7,7 +7,7 @@ import type { PromiseWithError } from '@orpc/shared' import { createContractJsonifiedUtilsFactory, createContractUtilsFactory } from './contract-utils' import type { ProcedureUtils } from './procedure-utils' import type { SharedUtils } from './shared-utils' -import type { OperationContext } from './types' +import type { TanstackQueryOperationContext } from './types' const contract = { ping: oc.meta(meta.path(['ping'])), @@ -29,7 +29,7 @@ describe('createContractUtilsFactory', () => { mutationInterceptors: [ async ({ context, next, input }) => { expectTypeOf(input).toEqualTypeOf() - expectTypeOf(context).toEqualTypeOf<{ cache?: boolean } & OperationContext>() + expectTypeOf(context).toEqualTypeOf<{ cache?: boolean } & TanstackQueryOperationContext>() const result = next() @@ -43,7 +43,9 @@ describe('createContractUtilsFactory', () => { queryInterceptors: [ async ({ context, next, input }) => { expectTypeOf(input).toEqualTypeOf() - expectTypeOf(context).toEqualTypeOf<{ cache?: boolean } & OperationContext>() + expectTypeOf(context).toEqualTypeOf< + { cache?: boolean } & TanstackQueryOperationContext + >() const result = next() @@ -60,7 +62,9 @@ describe('createContractUtilsFactory', () => { mutationInterceptors: [ async ({ context, next, input }) => { expectTypeOf(input).toEqualTypeOf() - expectTypeOf(context).toEqualTypeOf<{ cache?: boolean } & OperationContext>() + expectTypeOf(context).toEqualTypeOf< + { cache?: boolean } & TanstackQueryOperationContext + >() const result = next() @@ -110,7 +114,7 @@ describe('createContractJsonifiedUtilsFactory', () => { mutationInterceptors: [ async ({ context, next, input }) => { expectTypeOf(input).toEqualTypeOf() - expectTypeOf(context).toEqualTypeOf<{ cache?: boolean } & OperationContext>() + expectTypeOf(context).toEqualTypeOf<{ cache?: boolean } & TanstackQueryOperationContext>() const result = next() @@ -124,7 +128,9 @@ describe('createContractJsonifiedUtilsFactory', () => { queryInterceptors: [ async ({ context, next, input }) => { expectTypeOf(input).toEqualTypeOf() - expectTypeOf(context).toEqualTypeOf<{ cache?: boolean } & OperationContext>() + expectTypeOf(context).toEqualTypeOf< + { cache?: boolean } & TanstackQueryOperationContext + >() const result = next() @@ -141,7 +147,9 @@ describe('createContractJsonifiedUtilsFactory', () => { mutationInterceptors: [ async ({ context, next, input }) => { expectTypeOf(input).toEqualTypeOf() - expectTypeOf(context).toEqualTypeOf<{ cache?: boolean } & OperationContext>() + expectTypeOf(context).toEqualTypeOf< + { cache?: boolean } & TanstackQueryOperationContext + >() const result = next() diff --git a/packages/tanstack-query/src/index.ts b/packages/tanstack-query/src/index.ts index 8e524ad4b5..7e795ca31f 100644 --- a/packages/tanstack-query/src/index.ts +++ b/packages/tanstack-query/src/index.ts @@ -33,13 +33,11 @@ export { /** * @deprecated Use `TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL` instead. */ - OPERATION_CONTEXT_SYMBOL, - OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, + TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL as OPERATION_CONTEXT_SYMBOL, /** * @deprecated Use `TanstackQueryOperationContext` instead. */ - type OperationContext, - type OperationContext as TanstackQueryOperationContext, + type TanstackQueryOperationContext as OperationContext, } from './types' export type { AnyNestedClient } from '@orpc/client' diff --git a/packages/tanstack-query/src/meta.test-d.ts b/packages/tanstack-query/src/meta.test-d.ts index a79a8b6433..af957b6fef 100644 --- a/packages/tanstack-query/src/meta.test-d.ts +++ b/packages/tanstack-query/src/meta.test-d.ts @@ -5,7 +5,7 @@ import type { PromiseWithError } from '@orpc/shared' import type { SkipToken } from '@tanstack/query-core' import { tanstackQuery } from './meta' -import type { OperationContext } from './types' +import type { TanstackQueryOperationContext } from './types' describe('tanstackQuery', () => { it('infers input, output and error types from the contract', () => { @@ -18,7 +18,7 @@ describe('tanstackQuery', () => { queryInterceptors: [ async ({ context, input, next }) => { expectTypeOf(input).toEqualTypeOf() - expectTypeOf(context).toEqualTypeOf() + expectTypeOf(context).toEqualTypeOf() const result = next() diff --git a/packages/tanstack-query/src/procedure-utils.test.ts b/packages/tanstack-query/src/procedure-utils.test.ts index 2d8cbfca93..c5cc750c84 100644 --- a/packages/tanstack-query/src/procedure-utils.test.ts +++ b/packages/tanstack-query/src/procedure-utils.test.ts @@ -9,7 +9,7 @@ import { ProcedureUtils, } from './procedure-utils' import * as streamQueryModule from './stream-query' -import { OPERATION_CONTEXT_SYMBOL } from './types' +import { TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL } from './types' const streamedQuerySpy = vi.spyOn(streamQueryModule, 'serializableStreamedQuery') @@ -122,7 +122,7 @@ describe('procedureUtils', () => { signal, context: { batch: '__batch__', - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: options.queryKey, type: 'query', }, @@ -224,7 +224,7 @@ describe('procedureUtils', () => { signal: expect.any(AbortSignal), context: { batch: '__batch__', - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: options.queryKey, type: 'streamed', }, @@ -292,7 +292,7 @@ describe('procedureUtils', () => { signal: expect.any(AbortSignal), context: { batch: '__batch__', - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: options.queryKey, type: 'streamed', }, @@ -370,7 +370,7 @@ describe('procedureUtils', () => { signal: expect.any(AbortSignal), context: { batch: '__batch__', - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: options.queryKey, type: 'live', }, @@ -433,7 +433,7 @@ describe('procedureUtils', () => { signal: expect.any(AbortSignal), context: { batch: '__batch__', - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: options.queryKey, type: 'live', }, @@ -513,7 +513,7 @@ describe('procedureUtils', () => { signal, context: { batch: '__batch__', - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: options.queryKey, type: 'infinite', }, @@ -592,7 +592,7 @@ describe('procedureUtils', () => { expect(client).toHaveBeenCalledWith('__input__', { context: { batch: '__batch__', - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: options.mutationKey, type: 'mutation', }, @@ -1296,7 +1296,7 @@ describe('createProcedureUtils with interceptors', () => { input: { search: '__search__' }, context: { batch: '__batch__', - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: options.queryKey, type: 'query', }, @@ -1309,7 +1309,7 @@ describe('createProcedureUtils with interceptors', () => { signal, context: { batch: '__intercepted_batch__', - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: options.queryKey, type: 'query', }, @@ -1354,7 +1354,7 @@ describe('createProcedureUtils with interceptors', () => { input: { search: '__search__' }, context: { batch: '__batch__', - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: options.queryKey, type: 'streamed', }, @@ -1371,7 +1371,7 @@ describe('createProcedureUtils with interceptors', () => { signal: expect.any(AbortSignal), context: { batch: '__intercepted_batch__', - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: options.queryKey, type: 'streamed', }, @@ -1416,7 +1416,7 @@ describe('createProcedureUtils with interceptors', () => { input: { search: '__search__' }, context: { batch: '__batch__', - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: options.queryKey, type: 'live', }, @@ -1433,7 +1433,7 @@ describe('createProcedureUtils with interceptors', () => { signal: expect.any(AbortSignal), context: { batch: '__intercepted_batch__', - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: options.queryKey, type: 'live', }, @@ -1478,7 +1478,7 @@ describe('createProcedureUtils with interceptors', () => { input: { search: '__search__', pageParam: '__pageParam__' }, context: { batch: '__batch__', - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: options.queryKey, type: 'infinite', }, @@ -1491,7 +1491,7 @@ describe('createProcedureUtils with interceptors', () => { signal, context: { batch: '__intercepted_batch__', - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: options.queryKey, type: 'infinite', }, @@ -1529,7 +1529,7 @@ describe('createProcedureUtils with interceptors', () => { input: '__input__', context: { batch: '__batch__', - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: options.mutationKey, type: 'mutation', }, @@ -1539,7 +1539,7 @@ describe('createProcedureUtils with interceptors', () => { expect(client).toHaveBeenCalledWith('__intercepted_input__', { context: { batch: '__intercepted_batch__', - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: options.mutationKey, type: 'mutation', }, diff --git a/packages/tanstack-query/src/procedure-utils.ts b/packages/tanstack-query/src/procedure-utils.ts index 0e79d3f6c9..9c6fe49715 100644 --- a/packages/tanstack-query/src/procedure-utils.ts +++ b/packages/tanstack-query/src/procedure-utils.ts @@ -34,7 +34,7 @@ import type { MutationOptionsIn, MutationOptionsOut, MutationOptionsInRest, - OperationContext, + TanstackQueryOperationContext, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, @@ -44,7 +44,7 @@ import type { StreamedOptionsOut, StreamedOptionsInRest, } from './types' -import { OPERATION_CONTEXT_SYMBOL } from './types' +import { TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL } from './types' function resolveOptionsInRest(rest: [options?: T]): T { return rest[0] ?? ({} as T) // only undefined when options are optional @@ -55,7 +55,7 @@ export interface ProcedureUtilsQueryInterceptorOptions< TInput, > { path: string[] - context: TClientContext & OperationContext + context: TClientContext & TanstackQueryOperationContext input: TInput | SkipToken fnContext: QueryFunctionContext } @@ -460,12 +460,12 @@ export class ProcedureUtils< { path: this.path, context: { - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: queryKey, type: 'query', }, ...optionsIn.context, - } satisfies OperationContext as any, + } satisfies TanstackQueryOperationContext as any, input: optionsIn.input as TInput | SkipToken, fnContext, }, @@ -551,12 +551,12 @@ export class ProcedureUtils< { path: this.path, context: { - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: queryKey, type: 'streamed', }, ...optionsIn.context, - } satisfies OperationContext as any, + } satisfies TanstackQueryOperationContext as any, input: optionsIn.input as TInput | SkipToken, fnContext, }, @@ -646,12 +646,12 @@ export class ProcedureUtils< { path: this.path, context: { - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: queryKey, type: 'live', }, ...optionsIn.context, - } satisfies OperationContext as any, + } satisfies TanstackQueryOperationContext as any, input: optionsIn.input as TInput | SkipToken, fnContext, }, @@ -749,12 +749,12 @@ export class ProcedureUtils< { path: this.path, context: { - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: queryKey, type: 'infinite', }, ...optionsIn.context, - } satisfies OperationContext as any, + } satisfies TanstackQueryOperationContext as any, input: optionsIn.input === skipToken ? skipToken @@ -819,12 +819,12 @@ export class ProcedureUtils< { path: this.path, context: { - [OPERATION_CONTEXT_SYMBOL]: { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]: { key: mutationKey, type: 'mutation', }, ...optionsIn.context, - } satisfies OperationContext as any, + } satisfies TanstackQueryOperationContext as any, fnContext, input, }, diff --git a/packages/tanstack-query/src/types.ts b/packages/tanstack-query/src/types.ts index 5063ae1da8..80724b6338 100644 --- a/packages/tanstack-query/src/types.ts +++ b/packages/tanstack-query/src/types.ts @@ -23,7 +23,7 @@ export type OperationType = 'query' | 'streamed' | 'live' | 'infinite' | 'mutati * * @see {@link https://orpc.dev/docs/integrations/tanstack-query#client-context | TanStack Query Integration - Client Context} */ -export const OPERATION_CONTEXT_SYMBOL: unique symbol = /* @__PURE__ */ Symbol.for( +export const TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL: unique symbol = /* @__PURE__ */ Symbol.for( 'ORPC_TANSTACK_QUERY_OPERATION_CONTEXT', ) as any @@ -33,8 +33,8 @@ export const OPERATION_CONTEXT_SYMBOL: unique symbol = /* @__PURE__ */ Symbol.fo * * @see {@link https://orpc.dev/docs/integrations/tanstack-query#client-context | TanStack Query Integration - Client Context} */ -export interface OperationContext { - [OPERATION_CONTEXT_SYMBOL]?: { +export interface TanstackQueryOperationContext { + [TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL]?: { key: QueryKey type: OperationType } From 1d2a8276e4f4caaf1b26bb3987753f52ae01ecfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=8Bnh=20L=C3=AA?= Date: Mon, 23 Nov 2026 14:37:09 +0700 Subject: [PATCH 10/11] fix(tanstack-query, pinia-colada, swr): declare deprecated aliases so the tag reaches consumers --- packages/pinia-colada/src/index.ts | 16 ---------------- packages/pinia-colada/src/router-utils.ts | 5 +++++ packages/pinia-colada/src/types.ts | 11 +++++++++++ packages/swr/src/index.ts | 10 ---------- packages/swr/src/types.ts | 11 +++++++++++ packages/tanstack-query/src/index.ts | 10 ---------- packages/tanstack-query/src/types.ts | 11 +++++++++++ 7 files changed, 38 insertions(+), 36 deletions(-) diff --git a/packages/pinia-colada/src/index.ts b/packages/pinia-colada/src/index.ts index 5209086de2..6a7f9aba2b 100644 --- a/packages/pinia-colada/src/index.ts +++ b/packages/pinia-colada/src/index.ts @@ -23,27 +23,11 @@ export type { ProcedureUtilsStreamedInterceptorOptions, } from './procedure-utils' export * from './router-utils' -export { - /** - * @deprecated Use `createPiniaColadaUtils` instead. - */ - createRouterUtils as createORPCVueColadaUtils, -} from './router-utils' export { createRouterUtils as createPiniaColadaUtils } from './router-utils' export { SharedUtils } from './shared-utils' export * from './ssr' export type { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from './stream-query' export * from './types' -export { - /** - * @deprecated Use `PINIA_COLADA_OPERATION_CONTEXT_SYMBOL` instead. - */ - PINIA_COLADA_OPERATION_CONTEXT_SYMBOL as OPERATION_CONTEXT_SYMBOL, - /** - * @deprecated Use `PiniaColadaOperationContext` instead. - */ - type PiniaColadaOperationContext as OperationContext, -} from './types' export type { AnyNestedClient } from '@orpc/client' diff --git a/packages/pinia-colada/src/router-utils.ts b/packages/pinia-colada/src/router-utils.ts index 678d47dbbc..91497571d1 100644 --- a/packages/pinia-colada/src/router-utils.ts +++ b/packages/pinia-colada/src/router-utils.ts @@ -147,6 +147,11 @@ export function createRouterUtils( return createRouterUtilsInternal(client, options, plugin) } +/** + * @deprecated Use `createPiniaColadaUtils` instead. + */ +export const createORPCVueColadaUtils: typeof createRouterUtils = createRouterUtils + function createRouterUtilsInternal( client: T, options: RouterUtilsOptions, diff --git a/packages/pinia-colada/src/types.ts b/packages/pinia-colada/src/types.ts index d5521d7571..3359fc23fe 100644 --- a/packages/pinia-colada/src/types.ts +++ b/packages/pinia-colada/src/types.ts @@ -50,6 +50,17 @@ export interface PiniaColadaOperationContext { } } +/** + * @deprecated Use `PINIA_COLADA_OPERATION_CONTEXT_SYMBOL` instead. + */ +export const OPERATION_CONTEXT_SYMBOL: typeof PINIA_COLADA_OPERATION_CONTEXT_SYMBOL = + PINIA_COLADA_OPERATION_CONTEXT_SYMBOL + +/** + * @deprecated Use `PiniaColadaOperationContext` instead. + */ +export type OperationContext = PiniaColadaOperationContext + export type QueryKeyOptions = | (undefined extends TInput ? { input?: TInput } : { input: TInput }) | { key: EntryKey } diff --git a/packages/swr/src/index.ts b/packages/swr/src/index.ts index ac13cba440..3906d8a2d4 100644 --- a/packages/swr/src/index.ts +++ b/packages/swr/src/index.ts @@ -5,15 +5,5 @@ export * from './router-utils' export { createRouterUtils as createSWRUtils } from './router-utils' export { SharedUtils } from './shared-utils' export * from './types' -export { - /** - * @deprecated Use `SWR_OPERATION_CONTEXT_SYMBOL` instead. - */ - SWR_OPERATION_CONTEXT_SYMBOL as OPERATION_CONTEXT_SYMBOL, - /** - * @deprecated Use `SWROperationContext` instead. - */ - type SWROperationContext as OperationContext, -} from './types' export type { Public } from '@orpc/shared' diff --git a/packages/swr/src/types.ts b/packages/swr/src/types.ts index b911ad6204..ab78ebf4b9 100644 --- a/packages/swr/src/types.ts +++ b/packages/swr/src/types.ts @@ -32,6 +32,17 @@ export interface SWROperationContext { } } +/** + * @deprecated Use `SWR_OPERATION_CONTEXT_SYMBOL` instead. + */ +export const OPERATION_CONTEXT_SYMBOL: typeof SWR_OPERATION_CONTEXT_SYMBOL = + SWR_OPERATION_CONTEXT_SYMBOL + +/** + * @deprecated Use `SWROperationContext` instead. + */ +export type OperationContext = SWROperationContext + export type KeyOptions = undefined extends TInput ? { input?: TInput } : { input: TInput } export type MatcherStrategy = 'exact' | 'partial' diff --git a/packages/tanstack-query/src/index.ts b/packages/tanstack-query/src/index.ts index 7e795ca31f..c91712a946 100644 --- a/packages/tanstack-query/src/index.ts +++ b/packages/tanstack-query/src/index.ts @@ -29,16 +29,6 @@ export * from './ssr' export type { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from './stream-query' export * from './structural-sharing' export * from './types' -export { - /** - * @deprecated Use `TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL` instead. - */ - TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL as OPERATION_CONTEXT_SYMBOL, - /** - * @deprecated Use `TanstackQueryOperationContext` instead. - */ - type TanstackQueryOperationContext as OperationContext, -} from './types' export type { AnyNestedClient } from '@orpc/client' diff --git a/packages/tanstack-query/src/types.ts b/packages/tanstack-query/src/types.ts index 80724b6338..ce26319803 100644 --- a/packages/tanstack-query/src/types.ts +++ b/packages/tanstack-query/src/types.ts @@ -40,6 +40,17 @@ export interface TanstackQueryOperationContext { } } +/** + * @deprecated Use `TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL` instead. + */ +export const OPERATION_CONTEXT_SYMBOL: typeof TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL = + TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL + +/** + * @deprecated Use `TanstackQueryOperationContext` instead. + */ +export type OperationContext = TanstackQueryOperationContext + export type QueryKeyOptions = | (undefined extends TInput ? { input?: TInput | SkipToken } : { input: TInput | SkipToken }) | { queryKey: QueryKey } From 376842da5a0b8006d06e7694203bea6e50d7c454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=8Bnh=20L=C3=AA?= Date: Mon, 23 Nov 2026 14:40:43 +0700 Subject: [PATCH 11/11] refactor(tanstack-query, pinia-colada, swr): keep deprecated names as export aliases --- packages/pinia-colada/src/index.ts | 16 ++++++++++++++++ packages/pinia-colada/src/router-utils.ts | 5 ----- packages/pinia-colada/src/types.ts | 11 ----------- packages/swr/src/index.ts | 10 ++++++++++ packages/swr/src/types.ts | 11 ----------- packages/tanstack-query/src/index.ts | 10 ++++++++++ packages/tanstack-query/src/types.ts | 11 ----------- 7 files changed, 36 insertions(+), 38 deletions(-) diff --git a/packages/pinia-colada/src/index.ts b/packages/pinia-colada/src/index.ts index 6a7f9aba2b..5209086de2 100644 --- a/packages/pinia-colada/src/index.ts +++ b/packages/pinia-colada/src/index.ts @@ -23,11 +23,27 @@ export type { ProcedureUtilsStreamedInterceptorOptions, } from './procedure-utils' export * from './router-utils' +export { + /** + * @deprecated Use `createPiniaColadaUtils` instead. + */ + createRouterUtils as createORPCVueColadaUtils, +} from './router-utils' export { createRouterUtils as createPiniaColadaUtils } from './router-utils' export { SharedUtils } from './shared-utils' export * from './ssr' export type { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from './stream-query' export * from './types' +export { + /** + * @deprecated Use `PINIA_COLADA_OPERATION_CONTEXT_SYMBOL` instead. + */ + PINIA_COLADA_OPERATION_CONTEXT_SYMBOL as OPERATION_CONTEXT_SYMBOL, + /** + * @deprecated Use `PiniaColadaOperationContext` instead. + */ + type PiniaColadaOperationContext as OperationContext, +} from './types' export type { AnyNestedClient } from '@orpc/client' diff --git a/packages/pinia-colada/src/router-utils.ts b/packages/pinia-colada/src/router-utils.ts index 91497571d1..678d47dbbc 100644 --- a/packages/pinia-colada/src/router-utils.ts +++ b/packages/pinia-colada/src/router-utils.ts @@ -147,11 +147,6 @@ export function createRouterUtils( return createRouterUtilsInternal(client, options, plugin) } -/** - * @deprecated Use `createPiniaColadaUtils` instead. - */ -export const createORPCVueColadaUtils: typeof createRouterUtils = createRouterUtils - function createRouterUtilsInternal( client: T, options: RouterUtilsOptions, diff --git a/packages/pinia-colada/src/types.ts b/packages/pinia-colada/src/types.ts index 3359fc23fe..d5521d7571 100644 --- a/packages/pinia-colada/src/types.ts +++ b/packages/pinia-colada/src/types.ts @@ -50,17 +50,6 @@ export interface PiniaColadaOperationContext { } } -/** - * @deprecated Use `PINIA_COLADA_OPERATION_CONTEXT_SYMBOL` instead. - */ -export const OPERATION_CONTEXT_SYMBOL: typeof PINIA_COLADA_OPERATION_CONTEXT_SYMBOL = - PINIA_COLADA_OPERATION_CONTEXT_SYMBOL - -/** - * @deprecated Use `PiniaColadaOperationContext` instead. - */ -export type OperationContext = PiniaColadaOperationContext - export type QueryKeyOptions = | (undefined extends TInput ? { input?: TInput } : { input: TInput }) | { key: EntryKey } diff --git a/packages/swr/src/index.ts b/packages/swr/src/index.ts index 3906d8a2d4..ac13cba440 100644 --- a/packages/swr/src/index.ts +++ b/packages/swr/src/index.ts @@ -5,5 +5,15 @@ export * from './router-utils' export { createRouterUtils as createSWRUtils } from './router-utils' export { SharedUtils } from './shared-utils' export * from './types' +export { + /** + * @deprecated Use `SWR_OPERATION_CONTEXT_SYMBOL` instead. + */ + SWR_OPERATION_CONTEXT_SYMBOL as OPERATION_CONTEXT_SYMBOL, + /** + * @deprecated Use `SWROperationContext` instead. + */ + type SWROperationContext as OperationContext, +} from './types' export type { Public } from '@orpc/shared' diff --git a/packages/swr/src/types.ts b/packages/swr/src/types.ts index ab78ebf4b9..b911ad6204 100644 --- a/packages/swr/src/types.ts +++ b/packages/swr/src/types.ts @@ -32,17 +32,6 @@ export interface SWROperationContext { } } -/** - * @deprecated Use `SWR_OPERATION_CONTEXT_SYMBOL` instead. - */ -export const OPERATION_CONTEXT_SYMBOL: typeof SWR_OPERATION_CONTEXT_SYMBOL = - SWR_OPERATION_CONTEXT_SYMBOL - -/** - * @deprecated Use `SWROperationContext` instead. - */ -export type OperationContext = SWROperationContext - export type KeyOptions = undefined extends TInput ? { input?: TInput } : { input: TInput } export type MatcherStrategy = 'exact' | 'partial' diff --git a/packages/tanstack-query/src/index.ts b/packages/tanstack-query/src/index.ts index c91712a946..7e795ca31f 100644 --- a/packages/tanstack-query/src/index.ts +++ b/packages/tanstack-query/src/index.ts @@ -29,6 +29,16 @@ export * from './ssr' export type { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from './stream-query' export * from './structural-sharing' export * from './types' +export { + /** + * @deprecated Use `TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL` instead. + */ + TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL as OPERATION_CONTEXT_SYMBOL, + /** + * @deprecated Use `TanstackQueryOperationContext` instead. + */ + type TanstackQueryOperationContext as OperationContext, +} from './types' export type { AnyNestedClient } from '@orpc/client' diff --git a/packages/tanstack-query/src/types.ts b/packages/tanstack-query/src/types.ts index ce26319803..80724b6338 100644 --- a/packages/tanstack-query/src/types.ts +++ b/packages/tanstack-query/src/types.ts @@ -40,17 +40,6 @@ export interface TanstackQueryOperationContext { } } -/** - * @deprecated Use `TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL` instead. - */ -export const OPERATION_CONTEXT_SYMBOL: typeof TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL = - TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL - -/** - * @deprecated Use `TanstackQueryOperationContext` instead. - */ -export type OperationContext = TanstackQueryOperationContext - export type QueryKeyOptions = | (undefined extends TInput ? { input?: TInput | SkipToken } : { input: TInput | SkipToken }) | { queryKey: QueryKey }