Skip to content

Commit

Permalink
fix restrict context
Browse files Browse the repository at this point in the history
  • Loading branch information
unnoq committed Jan 31, 2025
1 parent 84fa778 commit 4e7d1c1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/server/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { IsNever } from '@orpc/shared'

export type Context = Record<string, any>

export type TypeInitialContext<T extends Context> = (type: T) => unknown

export type MergedContext<T extends Context, U extends Context> = T & U

export function mergeContext<T extends Context, U extends Context>(
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/procedure.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AbortSignal, ContractProcedureDef, ErrorMap, Meta, ORPCErrorConstructorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract'
import type { Promisable } from '@orpc/shared'
import type { Context } from './context'
import type { Context, TypeInitialContext } from './context'
import type { AnyMiddleware } from './middleware'
import { isContractProcedure } from '@orpc/contract'

Expand Down Expand Up @@ -40,7 +40,7 @@ export interface ProcedureDef<
TErrorMap extends ErrorMap,
TMeta extends Meta,
> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
__initialContext?(type: TInitialContext): unknown
__initialContext: TypeInitialContext<TInitialContext>
middlewares: AnyMiddleware[]
inputValidationIndex: number
outputValidationIndex: number
Expand Down
3 changes: 1 addition & 2 deletions packages/server/src/router.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ describe('Router', () => {
expectTypeOf(pong).toMatchTypeOf<Router<InitialContext, any>>()
expectTypeOf(router).toMatchTypeOf<Router<InitialContext, any>>()

// FIX: make bellow line work
// expectTypeOf(ping).not.toMatchTypeOf<Router<Context, any>>()
expectTypeOf(ping).not.toMatchTypeOf<Router<Context, any>>()
})
})

Expand Down

0 comments on commit 4e7d1c1

Please sign in to comment.