UNPKG

@message-in-the-middle/core

Version:

Framework-agnostic middleware pattern for message queue processing. Core package with all middlewares.

29 lines 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createZodValidator = createZodValidator; const validation_middleware_1 = require("../middlewares/validation.middleware"); function createZodValidator(schema, options = {}) { const validator = async (data) => { try { let processedSchema = schema; if (options.strip) { processedSchema = processedSchema.strip(); } if (options.allowUnknown) { processedSchema = processedSchema.passthrough(); } const result = await processedSchema.parseAsync(data); return result; } catch (error) { if (options.errorFormatter && error.errors) { throw options.errorFormatter(error); } throw error; } }; return new validation_middleware_1.ValidateInboundMiddleware(validator, { throwOnError: !options.passthrough, }); } //# sourceMappingURL=zod.validator.js.map