Function: createValidationMiddleware()
createValidationMiddleware<
T
>(validators
:ValidatorMap
<T
>):EventMiddleware
Defined in: electron/events/middleware.ts:706
Creates middleware that validates event data using a map of validator functions.
Type Parameters
T
T
extends UnknownRecord
Record type defining event names and their data types.
Parameters
validators
ValidatorMap
<T
>
Map of event names to their validator functions.
Returns
EventMiddleware function that validates event data before processing.
Remarks
If validation fails, the event is blocked and an error is logged. Throws on validation failure.
Example
const validators = {
"user:login": (data: { userId: string }) => !!data.userId,
"data:update": (data: { table: string }) =>
data.table
? { isValid: true }
: { isValid: false, error: "Table name required" },
};
const validationMiddleware = createValidationMiddleware(validators);
eventBus.use(validationMiddleware);