@@ -12,7 +12,7 @@ import {
1212 type SchemaDef ,
1313} from '../schema' ;
1414import type { AnyKysely } from '../utils/kysely-utils' ;
15- import type { OrUndefinedIf , Simplify , UnwrapTuplePromises } from '../utils/type-utils' ;
15+ import type { MaybePromise , OrUndefinedIf , Simplify , UnwrapTuplePromises } from '../utils/type-utils' ;
1616import type { TRANSACTION_UNSUPPORTED_METHODS } from './constants' ;
1717import type {
1818 AggregateArgs ,
@@ -297,16 +297,25 @@ type ProcedureCallParams<Schema extends SchemaDef, Params> = _HasRequiredProcedu
297297 ? [ input : ProcedureEnvelope < Schema , Params > ]
298298 : [ ] | [ input : ProcedureEnvelope < Schema , Params > ] ;
299299
300+ type ProcedureArgs < Schema extends SchemaDef , Params > = _ProcedureParamNames < Params > extends never
301+ ? Record < string , never >
302+ : MapProcedureArgsObject < Schema , Params > ;
303+
304+ type ProcedureHandlerCtx < Schema extends SchemaDef , Params > = { client : ClientContract < Schema > } &
305+ ( _HasRequiredProcedureParams < Params > extends true
306+ ? { args : ProcedureArgs < Schema , Params > }
307+ : { args ?: ProcedureArgs < Schema , Params > } ) ;
308+
300309export type ProcedureFunc < Schema extends SchemaDef , Proc extends ProcedureDef > = (
301310 ...args : ProcedureCallParams < Schema , Proc [ 'params' ] >
302- ) => Promise < MapProcedureReturn < Schema , Proc > > ;
311+ ) => MaybePromise < MapProcedureReturn < Schema , Proc > > ;
303312
304313/**
305314 * Signature for procedure handlers configured via client options.
306315 */
307316export type ProcedureHandlerFunc < Schema extends SchemaDef , Proc extends ProcedureDef > = (
308- ... args : ProcedureCallParams < Schema , Proc [ 'params' ] >
309- ) => Promise < MapProcedureReturn < Schema , Proc > > ;
317+ ctx : ProcedureHandlerCtx < Schema , Proc [ 'params' ] >
318+ ) => MaybePromise < MapProcedureReturn < Schema , Proc > > ;
310319
311320type MapProcedureReturn < Schema extends SchemaDef , Proc extends ProcedureDef > = Proc extends { returnType : infer R }
312321 ? Proc extends { returnArray : true }
0 commit comments