UNPKG

@platformatic/kafka

Version:

Modern and performant client for Apache Kafka

52 lines (51 loc) 1.72 kB
import { allowedProduceAcks, ProduceAcks } from "../../apis/enumerations.js"; import { allowedCompressionsAlgorithms, compressionsAlgorithms } from "../../protocol/compression.js"; import { messageSchema } from "../../protocol/records.js"; import { ajv, enumErrorMessage } from "../../utils.js"; import { serdeProperties } from "../serde.js"; export const produceOptionsProperties = { producerId: { bigint: true }, producerEpoch: { type: 'number' }, idempotent: { type: 'boolean' }, acks: { type: 'number', enumeration: { allowed: allowedProduceAcks, errorMessage: enumErrorMessage(ProduceAcks) } }, compression: { type: 'string', enumeration: { allowed: allowedCompressionsAlgorithms, errorMessage: enumErrorMessage(compressionsAlgorithms) } }, partitioner: { function: true }, autocreateTopics: { type: 'boolean' }, repeatOnStaleMetadata: { type: 'boolean' } }; export const produceOptionsSchema = { type: 'object', properties: produceOptionsProperties, additionalProperties: false }; export const produceOptionsValidator = ajv.compile(produceOptionsSchema); export const producerOptionsValidator = ajv.compile({ type: 'object', properties: { ...produceOptionsProperties, serializers: serdeProperties }, additionalProperties: true }); export const sendOptionsSchema = { type: 'object', properties: { messages: { type: 'array', items: messageSchema }, ...produceOptionsProperties }, required: ['messages'], additionalProperties: false }; export const sendOptionsValidator = ajv.compile(sendOptionsSchema);