Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Commit

Permalink
patch(server): fix dev --turbo (trpc#5604)
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT authored Apr 2, 2024
1 parent fdcb4a7 commit c89fb11
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-tmp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
# Replace this with the branch you want to release from
# 👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇
- 'issues/5557-types-node-wut'
- '04-02-no-typesProxy'
# 👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆
paths:
- '.github/workflows/release-tmp.yml'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"postinstall": "pnpm codegen",
"prepack": "tsx scripts/version.ts",
"version": "tsx scripts/version.ts",
"link-all": "cd packages && cd ../server && pnpm link --global && cd ../client && pnpm link --global && cd ../react-query && pnpm link --global && cd ../next && pnpm link --global",
"link-all": "cd packages/server && cd ../server && pnpm link --global && cd ../client && pnpm link --global && cd ../react-query && pnpm link --global && cd ../next && pnpm link --global",
"commit-date": "git log -n 1 --date=format:'%Y-%m-%d-%H-%M-%S' --pretty=format:'%ad'",
"canary-preid": "echo \"$(pnpm --silent current-branch)-$(pnpm --silent commit-date)\"",
"current-branch": "echo \"$(git rev-parse --abbrev-ref HEAD)\" | sed -E 's/refs\\/heads\\///' | sed -E 's/\\W|_/-/g' | sed -e 's/\\//-/'",
Expand Down
18 changes: 9 additions & 9 deletions packages/server/src/unstable-core-do-not-import/initTRPC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ test('config types', () => {
expectTypeOf<typeof t._config.$types.meta>().toEqualTypeOf<Meta>();
}

{
const {
_config: { $types },
} = initTRPC.create();
// @ts-expect-error mock unknown key
expect(() => $types.unknown).toThrow(
`Tried to access "$types.unknown" which is not available at runtime`,
);
}
// {
// const {
// _config: { $types },
// } = initTRPC.create();
// // @ts-expect-error mock unknown key
// expect(() => $types.unknown).toThrow(
// `Tried to access "$types.unknown" which is not available at runtime`,
// );
// }
});

test('detect server env', () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/server/src/unstable-core-do-not-import/initTRPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
import type { DataTransformerOptions } from './transformer';
import { defaultTransformer, getDataTransformer } from './transformer';
import type { Unwrap, ValidateShape } from './types';
import { $typesProxy } from './utils';

type inferErrorFormatterShape<TType> = TType extends ErrorFormatter<
any,
Expand Down Expand Up @@ -95,7 +94,7 @@ class TRPCBuilder<TContext extends object, TMeta extends object> {
* These are just types, they can't be used at runtime
* @internal
*/
$types: $typesProxy,
$types: null as any,
};

{
Expand Down
4 changes: 4 additions & 0 deletions packages/server/src/unstable-core-do-not-import/procedure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export interface Procedure<
TDef extends BuiltProcedureDef,
> {
_def: {
/**
* These are just types, they can't be used at runtime
* @internal
*/
$types: {
input: TDef['input'];
output: TDef['output'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import type {
Simplify,
TypeError,
} from './types';
import { $typesProxy, mergeWithoutOverrides } from './utils';
import { mergeWithoutOverrides } from './utils';

type IntersectIfDefined<TType, TWith> = TType extends UnsetMarker
? TWith
Expand Down Expand Up @@ -498,7 +498,7 @@ function createResolver(
type: _defIn.type,
experimental_caller: Boolean(finalBuilder._def.caller),
meta: finalBuilder._def.meta,
$types: $typesProxy,
$types: null as any,
};

const invoke = createProcedureCaller(finalBuilder._def);
Expand Down
12 changes: 0 additions & 12 deletions packages/server/src/unstable-core-do-not-import/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { createFlatProxy } from './createProxy';

/**
* Ensures there are no duplicate keys when building a procedure.
* @internal
Expand Down Expand Up @@ -43,13 +41,3 @@ export function omitPrototype<TObj extends Record<string, unknown>>(
): TObj {
return Object.assign(Object.create(null), obj);
}

/**
* Prevents access to `$types` at runtime
* @internal
*/
export const $typesProxy = createFlatProxy<any>((key) => {
throw new Error(
`Tried to access "$types.${key}" which is not available at runtime`,
);
});

0 comments on commit c89fb11

Please sign in to comment.