Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export procedure builder #5444

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/server/src/@trpc/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export {
type RouterRecord as TRPCRouterRecord,
type AnySubscriptionProcedure as AnyTRPCSubscriptionProcedure,
type ProcedureOptions as TRPCProcedureOptions,
type AnyProcedureBuilder as AnyTRPCProcedureBuilder,
} from '../../unstable-core-do-not-import';

export type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ export type AnyProcedureBuilder = ProcedureBuilder<
any,
any,
any,
any,
any,
any,
any
UnsetMarker,
UnsetMarker,
UnsetMarker,
UnsetMarker
>;

/**
Expand Down Expand Up @@ -325,9 +325,9 @@ export function createBuilder<TContext, TMeta>(
const builder: AnyProcedureBuilder = {
_def,
input(input) {
const parser = getParseFn(input as Parser);
const parser = getParseFn(input);
return createNewBuilder(_def, {
inputs: [input as Parser],
inputs: [input],
middlewares: [createInputMiddleware(parser)],
});
},
Expand Down
11 changes: 2 additions & 9 deletions packages/tests/server/react/polymorphism.factory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
// building factories which can produce common functionality over a homologous data source.
//
import type { RouterLike, UtilsLike } from '@trpc/react-query/shared';
import type { AnyTRPCProcedureBuilder } from '@trpc/server';
import { TRPCError } from '@trpc/server';
import type {
AnyRootTypes,
createBuilder,
} from '@trpc/server/unstable-core-do-not-import';
import z from 'zod';
import type { $RootTypes } from './polymorphism.common';
import { t } from './polymorphism.common';
Expand All @@ -33,10 +30,6 @@ export type FileExportStatusType = z.infer<typeof FileExportStatus>;
// Dependencies
//

type BaseProcedure<TRoot extends AnyRootTypes> = ReturnType<
typeof createBuilder<TRoot['ctx'], TRoot['meta']>
>;

export type DataProvider = FileExportStatusType[];

//
Expand All @@ -47,7 +40,7 @@ export type DataProvider = FileExportStatusType[];
let COUNTER = 1;

export function createExportRoute<
TBaseProcedure extends BaseProcedure<$RootTypes>,
TBaseProcedure extends AnyTRPCProcedureBuilder,
>(baseProcedure: TBaseProcedure, dataProvider: DataProvider) {
return t.router({
start: baseProcedure
Expand Down
15 changes: 2 additions & 13 deletions packages/tests/server/react/polymorphism.subtyped-factory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
// which can be used with existing components, but has extra data for other use cases
//
import type { RouterLike, UtilsLike } from '@trpc/react-query/shared';
import type { AnyTRPCProcedureBuilder } from '@trpc/server';
import { TRPCError } from '@trpc/server';
import type {
AnyRootTypes,
createBuilder,
createRouterFactory,
} from '@trpc/server/unstable-core-do-not-import';
import z from 'zod';
import { t } from './polymorphism.common';
import { FileExportRequest, FileExportStatus } from './polymorphism.factory';
Expand All @@ -32,13 +28,6 @@ export type SubTypedFileExportStatusType = z.infer<
// Dependencies
//

type RouterFactory<TRoot extends AnyRootTypes> = ReturnType<
typeof createRouterFactory<TRoot>
>;
type BaseProcedure<TRoot extends AnyRootTypes> = ReturnType<
typeof createBuilder<TRoot['ctx'], TRoot['meta']>
>;

export type SubTypedDataProvider = SubTypedFileExportStatusType[];

//
Expand All @@ -49,7 +38,7 @@ export type SubTypedDataProvider = SubTypedFileExportStatusType[];
let COUNTER = 1;

export function createSubTypedExportRoute<
TBaseProcedure extends BaseProcedure<(typeof t)['_config']['$types']>,
TBaseProcedure extends AnyTRPCProcedureBuilder,
>(baseProcedure: TBaseProcedure, dataProvider: SubTypedDataProvider) {
return t.router({
start: baseProcedure
Expand Down
Loading