Skip to content
Merged
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
32 changes: 16 additions & 16 deletions packages/server/src/builder-variants.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ describe('BuilderWithMiddlewares', () => {
>
>()

// invalid TInContext
expectTypeOf(builder.use({} as Middleware<{ auth: 'invalid' }, any, any, any, any, any>)).toEqualTypeOf<never>()
// @ts-expect-error --- invalid TInContext
builder.use({} as Middleware<{ auth: 'invalid' }, any, any, any, any, any>)
// @ts-expect-error --- input is not match
builder.use(({ next }, input: 'invalid') => next({}))
// @ts-expect-error --- output is not match
Expand Down Expand Up @@ -358,8 +358,8 @@ describe('ProcedureBuilder', () => {
>
>()

// invalid TInContext
expectTypeOf(builder.use({} as Middleware<{ auth: 'invalid' }, any, any, any, any, any>)).toEqualTypeOf<never>()
// @ts-expect-error --- invalid TInContext
builder.use({} as Middleware<{ auth: 'invalid' }, any, any, any, any, any>)
// @ts-expect-error --- input is not match
builder.use(({ next }, input: 'invalid') => next({}))
// @ts-expect-error --- output is not match
Expand Down Expand Up @@ -552,8 +552,8 @@ describe('ProcedureBuilderWithInput', () => {
>
>()

// invalid TInContext
expectTypeOf(builder.use({} as Middleware<{ auth: 'invalid' }, any, any, any, any, any>)).toEqualTypeOf<never>()
// @ts-expect-error --- invalid TInContext
builder.use({} as Middleware<{ auth: 'invalid' }, any, any, any, any, any>)
// @ts-expect-error --- input is not match
builder.use(({ next }, input: 'invalid') => next({}))
// @ts-expect-error --- output is not match
Expand Down Expand Up @@ -600,8 +600,8 @@ describe('ProcedureBuilderWithInput', () => {
input => ({ invalid: true }),
)

// invalid TInContext
expectTypeOf(builder.use({} as Middleware<{ auth: 'invalid' }, any, any, any, any, any>, () => { })).toEqualTypeOf<never>()
// @ts-expect-error --- invalid TInContext
builder.use({} as Middleware<{ auth: 'invalid' }, any, any, any, any, any>, () => {})
// @ts-expect-error --- input is not match
builder.use(({ next }, input: 'invalid') => next({}), input => ({ mapped: true }))
// @ts-expect-error --- output is not match
Expand Down Expand Up @@ -789,8 +789,8 @@ describe('ProcedureBuilderWithOutput', () => {
>
>()

// invalid TInContext
expectTypeOf(builder.use({} as Middleware<{ auth: 'invalid' }, any, any, any, any, any>)).toEqualTypeOf<never>()
// @ts-expect-error --- invalid TInContext
builder.use({} as Middleware<{ auth: 'invalid' }, any, any, any, any, any>)
// @ts-expect-error --- input is not match
builder.use(({ next }, input: 'invalid') => next({}))
// @ts-expect-error --- output is not match
Expand Down Expand Up @@ -970,8 +970,8 @@ describe('ProcedureBuilderWithInputOutput', () => {
>
>()

// invalid TInContext
expectTypeOf(builder.use({} as Middleware<{ auth: 'invalid' }, any, any, any, any, any>)).toEqualTypeOf<never>()
// @ts-expect-error --- invalid TInContext
builder.use({} as Middleware<{ auth: 'invalid' }, any, any, any, any, any>)
// @ts-expect-error --- input is not match
builder.use(({ next }, input: 'invalid') => next({}))
// @ts-expect-error --- output is not match
Expand Down Expand Up @@ -1018,8 +1018,8 @@ describe('ProcedureBuilderWithInputOutput', () => {
input => ({ invalid: true }),
)

// invalid TInContext
expectTypeOf(builder.use({} as Middleware<{ auth: 'invalid' }, any, any, any, any, any>, () => { })).toEqualTypeOf<never>()
// @ts-expect-error --- invalid TInContext
builder.use({} as Middleware<{ auth: 'invalid' }, any, any, any, any, any>, () => {})
// @ts-expect-error --- input is not match
builder.use(({ next }, input: 'invalid') => next({}), input => ({ mapped: true }))
// @ts-expect-error --- output is not match
Expand Down Expand Up @@ -1163,8 +1163,8 @@ describe('RouterBuilder', () => {
>
>()

// invalid TInContext
expectTypeOf(builder.use({} as Middleware<{ auth: 'invalid' }, any, any, any, any, any>)).toEqualTypeOf<never>()
// @ts-expect-error --- invalid TInContext
builder.use({} as Middleware<{ auth: 'invalid' }, any, any, any, any, any>)
// @ts-expect-error --- input is not match
builder.use(({ next }, input: 'invalid') => next({}))
// @ts-expect-error --- output is not match
Expand Down
150 changes: 71 additions & 79 deletions packages/server/src/builder-variants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AnySchema, ContractRouter, ErrorMap, HTTPPath, InferSchemaInput, InferSchemaOutput, MergedErrorMap, Meta, Route, Schema } from '@orpc/contract'
import type { BuilderDef } from './builder'
import type { Context, ContextExtendsGuard, MergedCurrentContext, MergedInitialContext } from './context'
import type { Context, MergedCurrentContext, MergedInitialContext } from './context'
import type { ORPCErrorConstructorMap } from './error'
import type { Lazy } from './lazy'
import type { MapInputMiddleware, Middleware } from './middleware'
Expand Down Expand Up @@ -32,22 +32,21 @@ export interface BuilderWithMiddlewares<

'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(
middleware: Middleware<
UInContext,
UInContext | TCurrentContext,
UOutContext,
unknown,
unknown,
ORPCErrorConstructorMap<TErrorMap>,
TMeta
>,
): ContextExtendsGuard<TCurrentContext, UInContext>
& BuilderWithMiddlewares<
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
MergedCurrentContext<TCurrentContext, UOutContext>,
TInputSchema,
TOutputSchema,
TErrorMap,
TMeta
>
): BuilderWithMiddlewares<
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
MergedCurrentContext<TCurrentContext, UOutContext>,
TInputSchema,
TOutputSchema,
TErrorMap,
TMeta
>

'meta'(
meta: TMeta,
Expand Down Expand Up @@ -105,22 +104,21 @@ export interface ProcedureBuilder<

'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(
middleware: Middleware<
UInContext,
UInContext | TCurrentContext,
UOutContext,
unknown,
unknown,
ORPCErrorConstructorMap<TErrorMap>,
TMeta
>,
): ContextExtendsGuard<TCurrentContext, UInContext>
& ProcedureBuilder<
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
MergedCurrentContext<TCurrentContext, UOutContext>,
TInputSchema,
TOutputSchema,
TErrorMap,
TMeta
>
): ProcedureBuilder<
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
MergedCurrentContext<TCurrentContext, UOutContext>,
TInputSchema,
TOutputSchema,
TErrorMap,
TMeta
>

'meta'(
meta: TMeta,
Expand Down Expand Up @@ -159,42 +157,40 @@ export interface ProcedureBuilderWithInput<

'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(
middleware: Middleware<
UInContext,
UInContext | TCurrentContext,
UOutContext,
InferSchemaOutput<TInputSchema>,
unknown,
ORPCErrorConstructorMap<TErrorMap>,
TMeta
>,
): ContextExtendsGuard<TCurrentContext, UInContext>
& ProcedureBuilderWithInput<
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
MergedCurrentContext<TCurrentContext, UOutContext>,
TInputSchema,
TOutputSchema,
TErrorMap,
TMeta
>
): ProcedureBuilderWithInput<
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
MergedCurrentContext<TCurrentContext, UOutContext>,
TInputSchema,
TOutputSchema,
TErrorMap,
TMeta
>

'use'<UOutContext extends Context, UInput, UInContext extends Context = TCurrentContext>(
middleware: Middleware<
UInContext,
UInContext | TCurrentContext,
UOutContext,
UInput,
unknown,
ORPCErrorConstructorMap<TErrorMap>,
TMeta
>,
mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>,
): ContextExtendsGuard<TCurrentContext, UInContext>
& ProcedureBuilderWithInput<
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
MergedCurrentContext<TCurrentContext, UOutContext>,
TInputSchema,
TOutputSchema,
TErrorMap,
TMeta
>
): ProcedureBuilderWithInput<
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
MergedCurrentContext<TCurrentContext, UOutContext>,
TInputSchema,
TOutputSchema,
TErrorMap,
TMeta
>

'meta'(
meta: TMeta,
Expand Down Expand Up @@ -236,22 +232,21 @@ export interface ProcedureBuilderWithOutput<

'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(
middleware: Middleware<
UInContext,
UInContext | TCurrentContext,
UOutContext,
unknown,
InferSchemaInput<TOutputSchema>,
ORPCErrorConstructorMap<TErrorMap>,
TMeta
>,
): ContextExtendsGuard<TCurrentContext, UInContext>
& ProcedureBuilderWithOutput<
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
MergedCurrentContext<TCurrentContext, UOutContext>,
TInputSchema,
TOutputSchema,
TErrorMap,
TMeta
>
): ProcedureBuilderWithOutput<
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
MergedCurrentContext<TCurrentContext, UOutContext>,
TInputSchema,
TOutputSchema,
TErrorMap,
TMeta
>

'meta'(
meta: TMeta,
Expand Down Expand Up @@ -286,42 +281,40 @@ export interface ProcedureBuilderWithInputOutput<

'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(
middleware: Middleware<
UInContext,
UInContext | TCurrentContext,
UOutContext,
InferSchemaOutput<TInputSchema>,
InferSchemaInput<TOutputSchema>,
ORPCErrorConstructorMap<TErrorMap>,
TMeta
>,
): ContextExtendsGuard<TCurrentContext, UInContext>
& ProcedureBuilderWithInputOutput<
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
MergedCurrentContext<TCurrentContext, UOutContext>,
TInputSchema,
TOutputSchema,
TErrorMap,
TMeta
>
): ProcedureBuilderWithInputOutput<
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
MergedCurrentContext<TCurrentContext, UOutContext>,
TInputSchema,
TOutputSchema,
TErrorMap,
TMeta
>

'use'<UOutContext extends Context, UInput, UInContext extends Context = TCurrentContext>(
middleware: Middleware<
UInContext,
UInContext | TCurrentContext,
UOutContext,
UInput,
InferSchemaInput<TOutputSchema>,
ORPCErrorConstructorMap<TErrorMap>,
TMeta
>,
mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>,
): ContextExtendsGuard<TCurrentContext, UInContext>
& ProcedureBuilderWithInputOutput<
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
MergedCurrentContext<TCurrentContext, UOutContext>,
TInputSchema,
TOutputSchema,
TErrorMap,
TMeta
>
): ProcedureBuilderWithInputOutput<
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
MergedCurrentContext<TCurrentContext, UOutContext>,
TInputSchema,
TOutputSchema,
TErrorMap,
TMeta
>

'meta'(
meta: TMeta,
Expand Down Expand Up @@ -350,20 +343,19 @@ export interface RouterBuilder<

'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(
middleware: Middleware<
UInContext,
UInContext | TCurrentContext,
UOutContext,
unknown,
unknown,
ORPCErrorConstructorMap<TErrorMap>,
TMeta
>,
): ContextExtendsGuard<TCurrentContext, UInContext>
& RouterBuilder<
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
MergedCurrentContext<TCurrentContext, UOutContext>,
TErrorMap,
TMeta
>
): RouterBuilder<
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
MergedCurrentContext<TCurrentContext, UOutContext>,
TErrorMap,
TMeta
>

'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>

Expand Down
Loading