QVAC Logo

defineDuplexHandler( )

Helper function to define a duplex (bidirectional streaming) handler with full type inference.

function defineDuplexHandler<TRequest extends ZodType, TResponse extends ZodType>(
  definition: DuplexPluginHandlerDefinition<TRequest, TResponse>
): PluginHandlerDefinition<TRequest, TResponse>;

Parameters

NameTypeRequired?Description
definitionDuplexPluginHandlerDefinitionThe duplex handler definition with schemas and handler function

DuplexPluginHandlerDefinition

FieldTypeRequired?Description
requestSchemaZodTypeZod schema for validating incoming requests
responseSchemaZodTypeZod schema for validating outgoing responses
streamingtrueMust be true — duplex handlers are always streaming
duplextrueMust be true — marks this handler as bidirectional
handler(request, inputStream: AsyncIterable<Buffer>) => AsyncGenerator<response>The handler function — receives a validated request and an input stream, yields validated response chunks

Returns

PluginHandlerDefinition<TRequest, TResponse> — The same definition object, with full type inference applied. This is an identity function used for type checking.

On this page