@kafkats/codec-zod
v0.6.0
Published
Zod codec helpers for @kafkats/client.
Downloads
393
Maintainers
Readme
@kafkats/codec-zod
Zod schema validation codecs for @kafkats/client.
Installation
npm install @kafkats/client @kafkats/codec-zod zodUsage
import { KafkaClient } from '@kafkats/client'
import { zodCodec } from '@kafkats/codec-zod'
import { z } from 'zod'
const UserEvent = z.object({
userId: z.string(),
action: z.enum(['login', 'logout', 'purchase']),
timestamp: z.number(),
})
const client = new KafkaClient({ brokers: ['localhost:9092'] })
const producer = client.producer()
await producer.send(
'user-events',
[
{
key: 'user-1',
value: { userId: 'user-1', action: 'login', timestamp: Date.now() },
},
],
{ valueCodec: zodCodec(UserEvent) }
)Documentation
Full documentation at chrisrecalis.github.io/kafkats
License
MIT
