bencebalogh / avro-schema-registry

Confluent Schema Registry implementation in javascript to easily serialize and deserialize kafka messages
MIT License
28 stars 30 forks source link

Add support for Naming Strategies (Issue #28) #31

Open flqw opened 4 years ago

flqw commented 4 years ago

Adds support for the different subject name strategies provided from confluent:

Adds the following functions:

        encodeKeyBySchema: (strategy: string, schema: any, msg: any, parseOptions?: any) => Promise<Buffer>
        encodeMessageBySchema: (strategy: string, schema: any, msg: any, parseOptions?: any) => Promise<Buffer>
        encodeMessageByTopicRecordName: (topic: string, recordName: string, msg: any, parseOptions?: any) => Promise<Buffer>
        encodeMessageByRecordName: (recordName: string, msg: any, parseOptions?: any) => Promise<Buffer>
        getSchemaByTopicRecordName: (topic: string, recordName: string, parseOptions?: any) => Promise<{ id: number, parsedSchema: any }>
        getSchemaByRecordName: (recordName: string, parseOptions?: any) => Promise<{ id: number, parsedSchema: any }>

Strategy constants can be accessed via the registry object e.g. registry.Strategy.RecordNameStrategy.

All existing functions fall back to TopicNameStrategy to be backwards compatible.

I fixed the existing tests but did not write some for the new functions, i also have not updated the readme.