Skip to content

Commit

Permalink
fix: cleanup some types and deprecate old things (#5060)
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT committed Nov 18, 2023
1 parent edceb5e commit a3b294a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 32 deletions.
8 changes: 4 additions & 4 deletions packages/server/src/core/initTRPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
defaultTransformer,
getDataTransformer,
} from '../transformer';
import { FlatOverwrite, Unwrap } from '../types';
import { Unwrap } from '../types';
import {
CreateRootConfigTypes,
isServerDefault,
Expand All @@ -21,7 +21,7 @@ import {
} from './internals/config';
import { mergeRouters } from './internals/mergeRouters';
import { createBuilder } from './internals/procedureBuilder';
import { PickFirstDefined, ValidateShape } from './internals/utils';
import { Overwrite, PickFirstDefined, ValidateShape } from './internals/utils';
import { createMiddlewareFactory } from './middleware';
import { createRouterFactory } from './router';

Expand Down Expand Up @@ -50,13 +50,13 @@ class TRPCBuilder<TParams extends PartialRootConfigTypes = object> {
| RootConfigTypes['ctx']
| ((...args: unknown[]) => RootConfigTypes['ctx']),
>() {
type NextParams = FlatOverwrite<TParams, { ctx: Unwrap<TNewContext> }>;
type NextParams = Overwrite<TParams, { ctx: Unwrap<TNewContext> }>;

return new TRPCBuilder<NextParams>();
}

meta<TNewMeta extends RootConfigTypes['meta']>() {
type NextParams = FlatOverwrite<TParams, { meta: TNewMeta }>;
type NextParams = Overwrite<TParams, { meta: TNewMeta }>;

return new TRPCBuilder<NextParams>();
}
Expand Down
12 changes: 6 additions & 6 deletions packages/server/src/core/internals/procedureBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { AnyRootConfig } from './config';
import { getParseFn } from './getParseFn';
import { mergeWithoutOverrides } from './mergeWithoutOverrides';
import {
DefaultValue as FallbackValue,
DefaultValue,
middlewareMarker,
Overwrite,
OverwriteKnown,
Expand All @@ -40,8 +40,8 @@ type CreateProcedureReturnInput<
_input_out: UnsetMarker extends TNext['_input_out']
? TPrev['_input_out']
: Overwrite<TPrev['_input_out'], TNext['_input_out']>;
_output_in: FallbackValue<TNext['_output_in'], TPrev['_output_in']>;
_output_out: FallbackValue<TNext['_output_out'], TPrev['_output_out']>;
_output_in: DefaultValue<TNext['_output_in'], TPrev['_output_in']>;
_output_out: DefaultValue<TNext['_output_out'], TPrev['_output_out']>;
}>;

/**
Expand Down Expand Up @@ -156,7 +156,7 @@ export interface ProcedureBuilder<TParams extends ProcedureParams> {
query<$Output>(
resolver: (
opts: ResolveOptions<TParams>,
) => MaybePromise<FallbackValue<TParams['_output_in'], $Output>>,
) => MaybePromise<DefaultValue<TParams['_output_in'], $Output>>,
): BuildProcedure<'query', TParams, $Output>;

/**
Expand All @@ -165,7 +165,7 @@ export interface ProcedureBuilder<TParams extends ProcedureParams> {
mutation<$Output>(
resolver: (
opts: ResolveOptions<TParams>,
) => MaybePromise<FallbackValue<TParams['_output_in'], $Output>>,
) => MaybePromise<DefaultValue<TParams['_output_in'], $Output>>,
): BuildProcedure<'mutation', TParams, $Output>;

/**
Expand All @@ -174,7 +174,7 @@ export interface ProcedureBuilder<TParams extends ProcedureParams> {
subscription<$Output>(
resolver: (
opts: ResolveOptions<TParams>,
) => MaybePromise<FallbackValue<TParams['_output_in'], $Output>>,
) => MaybePromise<DefaultValue<TParams['_output_in'], $Output>>,
): BuildProcedure<'subscription', TParams, $Output>;
/**
* @internal
Expand Down
18 changes: 9 additions & 9 deletions packages/server/src/core/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AnyRootConfig, RootConfig } from './internals/config';
import { ParseFn } from './internals/getParseFn';
import { ProcedureBuilderMiddleware } from './internals/procedureBuilder';
import {
DefaultValue as FallbackValue,
DefaultValue,
MiddlewareMarker,
Overwrite,
UnsetMarker,
Expand Down Expand Up @@ -64,10 +64,10 @@ export interface MiddlewareBuilder<
_config: TRoot['_config'];
_meta: TRoot['_meta'];
_ctx_out: Overwrite<TRoot['_ctx_out'], TNewParams['_ctx_out']>;
_input_in: FallbackValue<TRoot['_input_in'], TNewParams['_input_in']>;
_input_out: FallbackValue<TRoot['_input_out'], TNewParams['_input_out']>;
_output_in: FallbackValue<TRoot['_output_in'], TNewParams['_output_in']>;
_output_out: FallbackValue<
_input_in: DefaultValue<TRoot['_input_in'], TNewParams['_input_in']>;
_input_out: DefaultValue<TRoot['_input_out'], TNewParams['_input_out']>;
_output_in: DefaultValue<TRoot['_output_in'], TNewParams['_output_in']>;
_output_out: DefaultValue<
TRoot['_output_out'],
TNewParams['_output_out']
>;
Expand Down Expand Up @@ -102,10 +102,10 @@ type CreateMiddlewareReturnInput<
_config: TPrev['_config'];
_meta: TPrev['_meta'];
_ctx_out: Overwrite<TPrev['_ctx_out'], TNext['_ctx_out']>;
_input_in: FallbackValue<TNext['_input_in'], TPrev['_input_in']>;
_input_out: FallbackValue<TNext['_input_out'], TPrev['_input_out']>;
_output_in: FallbackValue<TNext['_output_in'], TPrev['_output_in']>;
_output_out: FallbackValue<TNext['_output_out'], TPrev['_output_out']>;
_input_in: DefaultValue<TNext['_input_in'], TPrev['_input_in']>;
_input_out: DefaultValue<TNext['_input_out'], TPrev['_input_out']>;
_output_in: DefaultValue<TNext['_output_in'], TPrev['_output_in']>;
_output_out: DefaultValue<TNext['_output_out'], TPrev['_output_out']>;
}
>;

Expand Down
8 changes: 8 additions & 0 deletions packages/server/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
/**
* @internal
* @deprecated
*/
export type identity<TType> = TType;

/**
* @deprecated
*/
export type InferOptional<TType, TKeys extends keyof TType> = Omit<
TType,
TKeys
> &
Partial<Pick<TType, TKeys>>;

/**
* @deprecated
*/
export type UndefinedKeys<TType> = {
[K in keyof TType]: undefined extends TType[K] ? K : never;
}[keyof TType];

/**
* @internal
* @deprecated
*/
export type FlatOverwrite<TType, TWith> = InferOptional<
{
Expand Down
32 changes: 19 additions & 13 deletions packages/tests/server/adapters/fastify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,20 @@ describe('anonymous user', () => {
await app.stop();
});

test('fetch POST', async () => {
const data = { text: 'life', life: 42 };
const req = await fetch(`http://localhost:${config.port}/hello`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
// body should be object
expect(await req.json()).toMatchInlineSnapshot(`
test(
'fetch POST',
async () => {
const data = { text: 'life', life: 42 };
const req = await fetch(`http://localhost:${config.port}/hello`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
// body should be object
expect(await req.json()).toMatchInlineSnapshot(`
Object {
"body": Object {
"life": 42,
Expand All @@ -267,7 +269,11 @@ describe('anonymous user', () => {
"hello": "POST",
}
`);
});
},
{
retry: 3,
},
);

test('query', async () => {
expect(await app.client.ping.query()).toMatchInlineSnapshot(`"pong"`);
Expand Down

3 comments on commit a3b294a

@vercel
Copy link

@vercel vercel bot commented on a3b294a Nov 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

next-prisma-starter – ./examples/next-prisma-starter

next-prisma-starter-git-main-trpc.vercel.app
nextjs.trpc.io
next-prisma-starter-trpc.vercel.app

@vercel
Copy link

@vercel vercel bot commented on a3b294a Nov 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

www – ./www

www.trpc.io
www-git-main-trpc.vercel.app
www-trpc.vercel.app
alpha.trpc.io
beta.trpc.io
trpc.io

@vercel
Copy link

@vercel vercel bot commented on a3b294a Nov 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

og-image – ./www/og-image

og-image-three-neon.vercel.app
og-image.trpc.io
og-image-git-main-trpc.vercel.app
og-image-trpc.vercel.app

Please sign in to comment.