@tamasha/kafka-schema-validation
v1.0.6
Published
Kafka topic schema validation framework with type-safe message definitions
Downloads
710
Readme
@tamasha/kafka-schema-validation
Kafka topic schema validation framework with type-safe message definitions.
Installation
npm install @tamasha/kafka-schema-validationUsage
Using the Default Schema Registry
import { TopicSchemaRegistry, DEFAULT_TOPIC_SCHEMAS } from '@tamasha/kafka-schema-validation';
const registry = new TopicSchemaRegistry(DEFAULT_TOPIC_SCHEMAS);
// Validate a message
const payload = registry.validateMessage('user-events', messageValue, 'produce');Defining Custom Schemas
import { defineAction, defineTopic, defineTopicSchemas } from '@tamasha/kafka-schema-validation';
const mySchema = defineTopic({
actionField: 'action',
partitionField: 'userId',
actions: {
created: defineAction<{ action: 'created'; userId: string; }>({
fields: {
action: { type: 'string', literal: 'created' },
userId: { type: 'string' },
},
}),
},
});
const schemas = defineTopicSchemas({
'my-topic': mySchema,
});Type-Safe Message Types
import type { UserEventMessage, OrderEventMessage } from '@tamasha/kafka-schema-validation';
function handleUserEvent(message: UserEventMessage) {
// TypeScript knows the exact shape of the message
}Available Topics
user-events- User login/logout eventsorder-events- Order created/fulfilled eventswallet- Wallet deposit success/failed eventscall- Call start/ended eventsaudience.updates- Audience entry/exit events
License
MIT
