UNPKG

@confluentinc/schemaregistry

Version:
67 lines (66 loc) 2.99 kB
import { Deserializer, DeserializerConfig, FieldTransform, RuleContext, SerdeType, Serializer, SerializerConfig } from "./serde"; import { Client, SchemaInfo } from "../schemaregistry-client"; import avro, { ForSchemaOptions, Type } from "avsc"; import { LRUCache } from 'lru-cache'; import { RuleRegistry } from "./rule-registry"; import { IHeaders } from "../../types/kafkajs"; export declare const AVRO_TYPE = "AVRO"; export type AvroSerdeConfig = Partial<ForSchemaOptions>; export interface AvroSerde { schemaToTypeCache: LRUCache<string, [avro.Type, Map<string, string>]>; } /** * AvroSerializerConfig is used to configure the AvroSerializer. */ export type AvroSerializerConfig = SerializerConfig & AvroSerdeConfig; /** * AvroSerializer is used to serialize messages using Avro. */ export declare class AvroSerializer extends Serializer implements AvroSerde { schemaToTypeCache: LRUCache<string, [avro.Type, Map<string, string>]>; /** * Create a new AvroSerializer. * @param client - the schema registry client * @param serdeType - the type of the serializer * @param conf - the serializer configuration * @param ruleRegistry - the rule registry */ constructor(client: Client, serdeType: SerdeType, conf: AvroSerializerConfig, ruleRegistry?: RuleRegistry); /** * serialize is used to serialize a message using Avro. * @param topic - the topic to serialize the message for * @param msg - the message to serialize * @param headers - optional headers */ serialize(topic: string, msg: any, headers?: IHeaders): Promise<Buffer>; fieldTransform(ctx: RuleContext, fieldTransform: FieldTransform, msg: any): Promise<any>; toType(info: SchemaInfo): Promise<[Type, Map<string, string>]>; static messageToSchema(msg: any): avro.Type; } /** * AvroDeserializerConfig is used to configure the AvroDeserializer. */ export type AvroDeserializerConfig = DeserializerConfig & AvroSerdeConfig; /** * AvroDeserializer is used to deserialize messages using Avro. */ export declare class AvroDeserializer extends Deserializer implements AvroSerde { schemaToTypeCache: LRUCache<string, [avro.Type, Map<string, string>]>; /** * Create a new AvroDeserializer. * @param client - the schema registry client * @param serdeType - the type of the deserializer * @param conf - the deserializer configuration * @param ruleRegistry - the rule registry */ constructor(client: Client, serdeType: SerdeType, conf: AvroDeserializerConfig, ruleRegistry?: RuleRegistry); /** * Deserializes a message. * @param topic - the topic * @param payload - the message payload * @param headers - optional headers */ deserialize(topic: string, payload: Buffer, headers?: IHeaders): Promise<any>; fieldTransform(ctx: RuleContext, fieldTransform: FieldTransform, msg: any): Promise<any>; toType(info: SchemaInfo): Promise<[Type, Map<string, string>]>; }