diff --git a/examples/next-prisma-websockets-starter/src/utils/trpc.ts b/examples/next-prisma-websockets-starter/src/utils/trpc.ts index d5043c3c96e..d9e64acff25 100644 --- a/examples/next-prisma-websockets-starter/src/utils/trpc.ts +++ b/examples/next-prisma-websockets-starter/src/utils/trpc.ts @@ -2,7 +2,7 @@ import { httpBatchLink } from '@trpc/client/links/httpBatchLink'; import { loggerLink } from '@trpc/client/links/loggerLink'; import { wsLink, createWSClient } from '@trpc/client/links/wsLink'; import { createTRPCNext } from '@trpc/next'; -import type { inferProcedureOutput } from '@trpc/server'; +import type { inferRouterOutputs } from '@trpc/server'; import { NextPageContext } from 'next'; import getConfig from 'next/config'; import type { AppRouter } from 'server/routers/_app'; @@ -83,8 +83,6 @@ export const trpc = createTRPCNext({ // export const transformer = superjson; /** * This is a helper method to infer the output of a query resolver - * @example type HelloOutput = inferQueryOutput<'hello'> + * @example type HelloOutput = RouterOutputs['hello'] */ -export type inferQueryOutput< - TRouteKey extends keyof AppRouter['_def']['queries'], -> = inferProcedureOutput; +export type RouterOutputs = inferRouterOutputs; diff --git a/packages/react-query/src/ssg/index.ts b/packages/react-query/src/ssg/index.ts index 600c2bd0d5b..0b3b0612de4 100644 --- a/packages/react-query/src/ssg/index.ts +++ b/packages/react-query/src/ssg/index.ts @@ -1,4 +1,2 @@ -export { createSSGHelpers } from './ssg'; -export type { CreateSSGHelpersOptions } from './ssg'; export { createProxySSGHelpers } from './ssgProxy'; export type { DecoratedProcedureSSGRecord } from './ssgProxy'; diff --git a/packages/react-query/src/ssg/ssg.ts b/packages/react-query/src/ssg/ssg.ts deleted file mode 100644 index 46ccb9b5d6f..00000000000 --- a/packages/react-query/src/ssg/ssg.ts +++ /dev/null @@ -1,144 +0,0 @@ -import { - DehydrateOptions, - DehydratedState, - InfiniteData, - dehydrate, -} from '@tanstack/react-query'; -import { - AnyRouter, - ClientDataTransformerOptions, - callProcedure, - inferHandlerInput, - inferProcedureOutput, - inferRouterContext, -} from '@trpc/server'; -import { getArrayQueryKey } from '../internals/getArrayQueryKey'; -import { CreateTRPCReactQueryClientConfig, getQueryClient } from '../shared'; - -interface CreateSSGHelpersOptionsBase { - router: TRouter; - ctx: inferRouterContext; - transformer?: ClientDataTransformerOptions; -} -export type CreateSSGHelpersOptions = - CreateSSGHelpersOptionsBase & CreateTRPCReactQueryClientConfig; - -/** - * Create functions you can use for server-side rendering / static generation - * @deprecated use `createProxySSGHelpers` instead - */ -export function createSSGHelpers( - opts: CreateSSGHelpersOptions, -) { - const { router, transformer, ctx } = opts; - type TQueries = TRouter['_def']['queries']; - const queryClient = getQueryClient(opts); - - const serialize = transformer - ? ('input' in transformer ? transformer.input : transformer).serialize - : (obj: unknown) => obj; - - const prefetchQuery = async < - TPath extends keyof TQueries & string, - TProcedure extends TQueries[TPath], - >( - ...pathAndInput: [path: TPath, ...args: inferHandlerInput] - ) => { - return queryClient.prefetchQuery( - getArrayQueryKey(pathAndInput, 'query'), - () => { - return callProcedure({ - procedures: router._def.procedures, - path: pathAndInput[0], - rawInput: pathAndInput[1], - ctx, - type: 'query', - }); - }, - ); - }; - - const prefetchInfiniteQuery = async < - TPath extends keyof TQueries & string, - TProcedure extends TQueries[TPath], - >( - ...pathAndInput: [path: TPath, ...args: inferHandlerInput] - ) => { - return queryClient.prefetchInfiniteQuery( - getArrayQueryKey(pathAndInput, 'infinite'), - () => { - return callProcedure({ - procedures: router._def.procedures, - path: pathAndInput[0], - rawInput: pathAndInput[1], - ctx, - type: 'query', - }); - }, - ); - }; - - const fetchQuery = async < - TPath extends keyof TQueries & string, - TProcedure extends TQueries[TPath], - TOutput extends inferProcedureOutput, - >( - ...pathAndInput: [path: TPath, ...args: inferHandlerInput] - ): Promise => { - return queryClient.fetchQuery( - getArrayQueryKey(pathAndInput, 'query'), - () => { - return callProcedure({ - procedures: router._def.procedures, - path: pathAndInput[0], - rawInput: pathAndInput[1], - ctx, - type: 'query', - }); - }, - ); - }; - - const fetchInfiniteQuery = async < - TPath extends keyof TQueries & string, - TProcedure extends TQueries[TPath], - TOutput extends inferProcedureOutput, - >( - ...pathAndInput: [path: TPath, ...args: inferHandlerInput] - ): Promise> => { - return queryClient.fetchInfiniteQuery( - getArrayQueryKey(pathAndInput, 'infinite'), - () => { - return callProcedure({ - procedures: router._def.procedures, - path: pathAndInput[0], - rawInput: pathAndInput[1], - ctx, - type: 'query', - }); - }, - ); - }; - - function _dehydrate( - opts: DehydrateOptions = { - shouldDehydrateQuery() { - // makes sure to serialize errors - return true; - }, - }, - ): DehydratedState { - const before = dehydrate(queryClient, opts); - const after = serialize(before); - return after; - } - - return { - prefetchQuery, - prefetchInfiniteQuery, - fetchQuery, - fetchInfiniteQuery, - dehydrate: _dehydrate, - queryClient, - }; -} diff --git a/packages/react-query/src/ssg/ssgProxy.ts b/packages/react-query/src/ssg/ssgProxy.ts index 293e6755bbd..9238c256fca 100644 --- a/packages/react-query/src/ssg/ssgProxy.ts +++ b/packages/react-query/src/ssg/ssgProxy.ts @@ -3,21 +3,35 @@ import { DehydratedState, InfiniteData, QueryClient, + dehydrate, } from '@tanstack/react-query'; import { AnyProcedure, AnyQueryProcedure, AnyRouter, + ClientDataTransformerOptions, Filter, ProtectedIntersection, + callProcedure, inferHandlerInput, + inferRouterContext, } from '@trpc/server'; import { createFlatProxy, createRecursiveProxy, inferTransformedProcedureOutput, } from '@trpc/server/shared'; -import { CreateSSGHelpersOptions, createSSGHelpers } from './ssg'; +import { getArrayQueryKey } from '../internals/getArrayQueryKey'; +import { getQueryKey } from '../internals/getQueryKey'; +import { CreateTRPCReactQueryClientConfig, getQueryClient } from '../shared'; + +interface CreateSSGHelpersOptionsBase { + router: TRouter; + ctx: inferRouterContext; + transformer?: ClientDataTransformerOptions; +} +export type CreateSSGHelpersOptions = + CreateSSGHelpersOptionsBase & CreateTRPCReactQueryClientConfig; type DecorateProcedure = { /** @@ -66,7 +80,25 @@ type AnyDecoratedProcedure = DecorateProcedure; export function createProxySSGHelpers( opts: CreateSSGHelpersOptions, ) { - const helpers = createSSGHelpers(opts); + const { router, transformer, ctx } = opts; + const queryClient = getQueryClient(opts); + + const serialize = transformer + ? ('input' in transformer ? transformer.input : transformer).serialize + : (obj: unknown) => obj; + + function _dehydrate( + opts: DehydrateOptions = { + shouldDehydrateQuery() { + // makes sure to serialize errors + return true; + }, + }, + ): DehydratedState { + const before = dehydrate(queryClient, opts); + const after = serialize(before); + return after; + } type CreateProxySSGHelpers = ProtectedIntersection< { @@ -77,36 +109,43 @@ export function createProxySSGHelpers( >; return createFlatProxy((key) => { - if (key === 'queryClient') { - return helpers.queryClient; - } + if (key === 'queryClient') return queryClient; + if (key === 'dehydrate') return _dehydrate; - if (key === 'dehydrate') { - return helpers.dehydrate; - } return createRecursiveProxy((opts) => { const args = opts.args; - + const input = args[0]; const pathCopy = [key, ...opts.path]; - const utilName = pathCopy.pop() as keyof AnyDecoratedProcedure; - const fullPath = pathCopy.join('.'); - switch (utilName) { - case 'fetch': { - return helpers.fetchQuery(fullPath, ...(args as any)); - } - case 'fetchInfinite': { - return helpers.fetchInfiniteQuery(fullPath, ...(args as any)); - } - case 'prefetch': { - return helpers.prefetchQuery(fullPath, ...(args as any)); - } - case 'prefetchInfinite': { - return helpers.prefetchInfiniteQuery(fullPath, ...(args as any)); - } - } + const _callProcedure = () => + callProcedure({ + procedures: router._def.procedures, + path: fullPath, + rawInput: input, + ctx, + type: 'query', + }); + + // TODO: Come back when we have sorted out all the querykey stuff + const queryKey = getArrayQueryKey( + getQueryKey(fullPath, input), + ['fetchInfinite', 'prefetchInfinite'].includes(utilName) + ? 'infinite' + : 'query', + ); + + const helperMap: Record unknown> = { + fetch: () => queryClient.fetchQuery(queryKey, _callProcedure), + fetchInfinite: () => + queryClient.fetchInfiniteQuery(queryKey, _callProcedure), + prefetch: () => queryClient.prefetchQuery(queryKey, _callProcedure), + prefetchInfinite: () => + queryClient.prefetchInfiniteQuery(queryKey, _callProcedure), + }; + + return helperMap[utilName](); }); }); } diff --git a/packages/server/src/adapters/lambda/index.ts b/packages/server/src/adapters/lambda/index.ts deleted file mode 100644 index 43e09b459af..00000000000 --- a/packages/server/src/adapters/lambda/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { - CreateAWSLambdaContextOptions, - awsLambdaRequestHandler, -} from '../aws-lambda'; -import { APIGatewayEvent } from '../aws-lambda/utils'; - -export * from '../aws-lambda'; - -/** - * @deprecated use `aws-lambda` instead - */ -export type CreateLambdaContextOptions = - CreateAWSLambdaContextOptions; - -/** - * @deprecated use `aws-lambda` instead - */ -export const lambdaRequestHandler = awsLambdaRequestHandler; diff --git a/packages/server/src/core/internals/procedureBuilder.ts b/packages/server/src/core/internals/procedureBuilder.ts index b9f9a164bff..ab92de672be 100644 --- a/packages/server/src/core/internals/procedureBuilder.ts +++ b/packages/server/src/core/internals/procedureBuilder.ts @@ -386,7 +386,6 @@ function createProcedureCaller(_def: AnyProcedureBuilderDef): AnyProcedure { return result.data; }; procedure._def = _def; - procedure.meta = _def.meta; return procedure as AnyProcedure; } diff --git a/packages/server/src/core/procedure.ts b/packages/server/src/core/procedure.ts index f0ff3feef34..800ec985353 100644 --- a/packages/server/src/core/procedure.ts +++ b/packages/server/src/core/procedure.ts @@ -79,10 +79,6 @@ export interface Procedure< > { _type: TType; _def: TParams & ProcedureBuilderDef; - /** - * @deprecated use `._def.meta` instead - */ - meta?: TParams['_meta']; _procedure: true; /** * @internal diff --git a/packages/server/src/core/router.ts b/packages/server/src/core/router.ts index 6d919802662..f8968e4a5cf 100644 --- a/packages/server/src/core/router.ts +++ b/packages/server/src/core/router.ts @@ -7,19 +7,8 @@ import { defaultTransformer } from '../transformer'; import { AnyRootConfig } from './internals/config'; import { omitPrototype } from './internals/omitPrototype'; import { ProcedureCallOptions } from './internals/procedureBuilder'; -import { - AnyMutationProcedure, - AnyProcedure, - AnyQueryProcedure, - AnySubscriptionProcedure, - ProcedureArgs, -} from './procedure'; -import { - ProcedureType, - inferHandlerInput, - inferProcedureOutput, - procedureTypes, -} from './types'; +import { AnyProcedure, ProcedureArgs } from './procedure'; +import { ProcedureType, procedureTypes } from './types'; /** @internal **/ export type ProcedureRecord = Record; @@ -28,66 +17,18 @@ export interface ProcedureRouterRecord { [key: string]: AnyProcedure | AnyRouter; } -/** - * @deprecated - */ -interface DeprecatedProcedureRouterRecord { - queries: Record; - mutations: Record; - subscriptions: Record; -} - export interface RouterDef< TConfig extends AnyRootConfig, TRecord extends ProcedureRouterRecord, - /** - * @deprecated - */ - TOld extends DeprecatedProcedureRouterRecord = { - // eslint-disable-next-line @typescript-eslint/ban-types - queries: {}; - // eslint-disable-next-line @typescript-eslint/ban-types - mutations: {}; - // eslint-disable-next-line @typescript-eslint/ban-types - subscriptions: {}; - }, > { _config: TConfig; router: true; procedures: TRecord; record: TRecord; - /** - * V9 queries - * @deprecated - */ - queries: TOld['queries']; - /** - * V9 mutations - * @deprecated - */ - mutations: TOld['mutations']; - /** - * V9 subscriptions - * @deprecated - */ - subscriptions: TOld['subscriptions']; } -export type AnyRouterDef< - TConfig extends AnyRootConfig = AnyRootConfig, - TOld extends DeprecatedProcedureRouterRecord = any, -> = RouterDef; - -/** - * @internal - */ -type inferHandlerFn = < - TProcedure extends TProcedures[TPath], - TPath extends keyof TProcedures & string, ->( - path: TPath, - ...args: inferHandlerInput -) => Promise>; +export type AnyRouterDef = + RouterDef; type DecorateProcedure = ( input: ProcedureArgs[0], @@ -109,20 +50,7 @@ type DecoratedProcedureRecord = { */ type RouterCaller = ( ctx: TDef['_config']['$types']['ctx'], -) => { - /** - * @deprecated - */ - query: inferHandlerFn; - /** - * @deprecated - */ - mutation: inferHandlerFn; - /** - * @deprecated - */ - subscription: inferHandlerFn; -} & DecoratedProcedureRecord; +) => DecoratedProcedureRecord; export interface Router { _def: TDef; @@ -221,15 +149,6 @@ export function createRouterFactory( procedures: routerProcedures, ...emptyRouter, record: procedures, - queries: Object.entries(routerProcedures) - .filter((pair) => (pair[1] as any)._def.query) - .reduce((acc, [key, val]) => ({ ...acc, [key]: val }), {}), - mutations: Object.entries(routerProcedures) - .filter((pair) => (pair[1] as any)._def.mutation) - .reduce((acc, [key, val]) => ({ ...acc, [key]: val }), {}), - subscriptions: Object.entries(routerProcedures) - .filter((pair) => (pair[1] as any)._def.subscription) - .reduce((acc, [key, val]) => ({ ...acc, [key]: val }), {}), }; const router: AnyRouter = { diff --git a/packages/server/src/core/types.ts b/packages/server/src/core/types.ts index 4233aa7b619..81ef1cd8a37 100644 --- a/packages/server/src/core/types.ts +++ b/packages/server/src/core/types.ts @@ -1,4 +1,3 @@ -import { inferObservableValue } from '../observable'; import { inferTransformedProcedureOutput } from '../shared'; import { AnyProcedure, ProcedureArgs } from './procedure'; import { AnyRouter, AnyRouterDef, Router } from './router'; @@ -37,16 +36,6 @@ export type inferProcedureParams = TProcedure extends AnyProcedure export type inferProcedureOutput = inferProcedureParams['_output_out']; -/** - * @deprecated will be removed in next major as it's v9 stuff - */ -export type inferSubscriptionOutput< - TRouter extends AnyRouter, - TPath extends keyof TRouter['_def']['subscriptions'] & string, -> = inferObservableValue< - inferProcedureOutput ->; - export type inferProcedureClientError = inferProcedureParams['_config']['errorShape']; diff --git a/packages/server/src/rpc/envelopes.ts b/packages/server/src/rpc/envelopes.ts index bf7efa2adbe..f95d31f66bd 100644 --- a/packages/server/src/rpc/envelopes.ts +++ b/packages/server/src/rpc/envelopes.ts @@ -64,11 +64,6 @@ export interface TRPCSuccessResponse } > {} -/** - * @deprecated use `TRPCSuccessResponse` instead - */ -export type TRPCResultResponse = TRPCSuccessResponse; - export interface TRPCErrorResponse< TError extends TRPCErrorShape = TRPCErrorShape, > extends JSONRPC2.ErrorResponse {} diff --git a/packages/tests/server/children.test.ts b/packages/tests/server/children.test.ts index 329aed5c83d..07a9c6b57bf 100644 --- a/packages/tests/server/children.test.ts +++ b/packages/tests/server/children.test.ts @@ -16,29 +16,13 @@ test('children', async () => { }), }); - const { queries, mutations, subscriptions, procedures } = router._def; - expect({ - queries, - mutations, - subscriptions, - procedures, - }).toMatchInlineSnapshot(` + const { procedures } = router._def; + expect(procedures).toMatchInlineSnapshot(` Object { - "mutations": Object { - "child.grandchild.mut": [Function], - }, - "procedures": Object { - "child.childQuery": [Function], - "child.grandchild.foo": [Function], - "child.grandchild.mut": [Function], - "foo": [Function], - }, - "queries": Object { - "child.childQuery": [Function], - "child.grandchild.foo": [Function], - "foo": [Function], - }, - "subscriptions": Object {}, + "child.childQuery": [Function], + "child.grandchild.foo": [Function], + "child.grandchild.mut": [Function], + "foo": [Function], } `); diff --git a/packages/tests/server/react/useMutation.test.tsx b/packages/tests/server/react/useMutation.test.tsx index 0dea333cc60..17e4a9f31cc 100644 --- a/packages/tests/server/react/useMutation.test.tsx +++ b/packages/tests/server/react/useMutation.test.tsx @@ -41,15 +41,6 @@ const ctx = konn() date: new Date(), })), }), - /** - * @deprecated - */ - deprecatedRouter: t.router({ - /** - * @deprecated - */ - deprecatedProcedure: t.procedure.query(() => '..'), - }), }); return getServerAndReactClient(appRouter); diff --git a/packages/tests/server/react/useQuery.test.tsx b/packages/tests/server/react/useQuery.test.tsx index 2c3a9da25af..a69f055a5bd 100644 --- a/packages/tests/server/react/useQuery.test.tsx +++ b/packages/tests/server/react/useQuery.test.tsx @@ -58,15 +58,6 @@ const ctx = konn() }; }), }), - /** - * @deprecated - */ - deprecatedRouter: t.router({ - /** - * @deprecated - */ - deprecatedProcedure: t.procedure.query(() => '..'), - }), }); return getServerAndReactClient(appRouter); @@ -225,23 +216,6 @@ test('useInfiniteQuery()', async () => { }); }); -test('deprecated routers', async () => { - const { proxy, App } = ctx; - - function MyComponent() { - // FIXME this should have strike-through - proxy.deprecatedRouter.deprecatedProcedure.useQuery(); - - return null; - } - - render( - - - , - ); -}); - test('useSuspenseInfiniteQuery()', async () => { const { App, proxy } = ctx; function MyComponent() { @@ -297,23 +271,6 @@ test('useSuspenseInfiniteQuery()', async () => { }); }); -test('deprecated routers', async () => { - const { proxy, App } = ctx; - - function MyComponent() { - // FIXME this should have strike-through - proxy.deprecatedRouter.deprecatedProcedure.useQuery(); - - return null; - } - - render( - - - , - ); -}); - test('useQuery options inference', () => { const { appRouter, proxy, App } = ctx; diff --git a/scripts/generateMergeRouters.ts b/scripts/generateMergeRouters.ts index 1e3b4a597f0..5b5bc2c8c40 100644 --- a/scripts/generateMergeRouters.ts +++ b/scripts/generateMergeRouters.ts @@ -22,9 +22,6 @@ const TEMPLATE = ` ): Router<{ _config: RP0['_config']; router: true; - queries: __queries__; - mutations: __mutations__; - subscriptions: __subscriptions__; procedures: __procedures__; record: __records__; isDev: boolean; @@ -46,18 +43,12 @@ const partList: string[] = []; for (let index = 0; index < NUM_ARGS; index++) { const generics: string[] = []; const args: string[] = []; - const queries: string[] = []; - const mutations: string[] = []; - const subscriptions: string[] = []; const procedures: string[] = []; const records: string[] = []; for (let j = 0; j < index + 1; j++) { generics.push(`RP${j} extends AnyRouterDef`); args.push(`router${j}: Router`); - queries.push(`RP${j}['queries']`); - mutations.push(`RP${j}['mutations']`); - subscriptions.push(`RP${j}['subscriptions']`); procedures.push(`RP${j}['procedures']`); records.push(`RP${j}['record']`); } @@ -65,9 +56,6 @@ for (let index = 0; index < NUM_ARGS; index++) { const part = TEMPLATE.replace('', '') .replace(/__generics__/g, generics.join(', ')) .replace(/__args__/g, args.join(', ')) - .replace(/__queries__/g, queries.join(' & ')) - .replace(/__mutations__/g, mutations.join(' & ')) - .replace(/__subscriptions__/g, subscriptions.join(' & ')) .replace(/__procedures__/g, procedures.join(' & ')) .replace(/__records__/g, records.join(' & '));