@overture-stack/lyric
Version:
Data Submission system
26 lines (25 loc) • 1.15 kB
TypeScript
import type { ResultOnCommit } from '../utils/types.js';
/** Minimal producer interface; keeps kafkajs out of the library's direct dependency graph. */
export interface KafkaProducer {
send(params: {
topic: string;
messages: Array<{
value: string;
}>;
}): Promise<unknown>;
}
/** Configuration for {@link createKafkaPublisher}. */
export type KafkaPublisherConfig = {
/** Called when `producer.send` throws after all retries. Defaults to `console.error`. */
onError?: (err: unknown) => void;
producer: KafkaProducer;
/** Topic to publish to; created automatically on startup if it does not exist. */
topic: string;
};
/**
* Returns an `onFinishCommit` handler that batches all records from a commit into a single
* `producer.send` call. Each message includes an `action` field (`insert`, `update`, or `delete`)
* describing what happened to the record in the submission, and `isValid` reflecting the record's
* current stored state.
*/
export declare const createKafkaPublisher: ({ onError, producer, topic }: KafkaPublisherConfig) => (result: ResultOnCommit) => Promise<void>;