Coder Social home page Coder Social logo

diogofcunha / avro-schema-builder Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 127 KB

A robust and feature-rich package for building Avro Schema definitions.

License: MIT License

JavaScript 0.46% TypeScript 99.54%
avro avro-kafka avro-schema avro-schema-registry javascript kafka-js nodejs schema schema-builder serialization

avro-schema-builder's Introduction

avro-schema-builder

CircleCI npm package

A robust and feature-rich package for building Avro Schema definitions.

Description

avro-schema-builder is a convenient way of programmatically building Avro Schemas. With the help of TypeScript type definitions, this library provides a type-safe and self-documenting way of creating Avro schemas, without dealing with JSON files or worrying about schema validation or learning the depth of Avro specific representation like defaults and object nesting.

Install

yarn add avro-schema-builder
npm install avro-schema-builder

Usage

import {AvroSchemaBuilder, PrimitiveField, PrimitiveType} from 'avro-schema-builder';

new AvroSchemaBuilder('myRecord')
  .record('record.record')
  .addField(
    new RecordField({
      namespace: 'record.primitive.x',
      name: 'children',
      doc: 'children field',
      order: FieldOrder.ascending,
      nullable: true,
    })
      .addField(
        new PrimitiveField({
          name: 'id',
          type: 'int',
        }),
      )
      .addField(
        new RecordField({
          namespace: 'record.primitive.x.y',
          name: 'grandchildren',
          doc: 'children field',
          order: FieldOrder.descending,
          nullable: true,
          defaultValue: null,
        }).addField(
          new PrimitiveField({
            name: 'id',
            type: 'int',
          }),
        ),
      ),
  )
  .compile();

console.log(JSON.stringify(schema, null, 2));

This will output the following Avro Schema:

{
  "type": "record",
  "name": "myRecord",
  "namespace": "record.record",
  "fields": [
    {
      "name": "children",
      "type": [
        "null",
        {
          "fields": [
            {
              "name": "id",
              "type": "int"
            },
            {
              "name": "grandchildren",
              "type": [
                "null",
                {
                  "default": null,
                  "fields": [
                    {
                      "name": "id",
                      "type": "int"
                    }
                  ],
                  "name": "grandchildren",
                  "namespace": "record.primitive.x.y",
                  "type": "record"
                }
              ]
            }
          ],
          "name": "children",
          "namespace": "record.primitive.x",
          "type": "record"
        }
      ]
    }
  ]
}

Documentation

This package provides several classes and types for building Avro schemas:

  • AvroSchemaBuilder: Main entry point for creating a schema. It is initialized with the name of the schema.
  • FieldBuilder: Represents a field in the schema. It can be of various types including PrimitiveField, RecordField, ArrayField, EnumField, MapField, FixedField, UnionField, and ReferenceField.
  • Other classes (PrimitiveField, RecordField, ArrayField, etc.): Represent the different types of fields available in Avro.
  • types: Contains TypeScript type definitions for the various Avro types.

For a more detailed explanation of the classes and types available, and how to use them, please check out the source code and the test cases.

Contributing

Contributions are welcome! Please submit a pull request with any improvements or bug fixes. Make sure to add tests for any new features and bug fixes, and ensure that the existing tests pass.

License

This project is licensed under the MIT License.

Contact

If you need help or have questions, feel free to open an issue in the GitHub repository.

avro-schema-builder's People

Contributors

diogofcunha avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.