All Projects → joewood → avro-typescript

joewood / avro-typescript

Licence: MIT License
TypeScript Code Generator for Apache Avro Schema Types

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to avro-typescript

schema-registry-php-client
A PHP 7.3+ API client for the Confluent Schema Registry REST API based on Guzzle 6 - http://docs.confluent.io/current/schema-registry/docs/index.html
Stars: ✭ 40 (+110.53%)
Mutual labels:  avro, avro-schema
Schema Registry
Confluent Schema Registry for Kafka
Stars: ✭ 1,647 (+8568.42%)
Mutual labels:  avro, avro-schema
avro ex
An Avro Library that emphasizes testability and ease of use.
Stars: ✭ 47 (+147.37%)
Mutual labels:  avro, avro-schema
registryless-avro-converter
An avro converter for Kafka Connect without a Schema Registry
Stars: ✭ 45 (+136.84%)
Mutual labels:  avro, avro-schema
darwin
Avro Schema Evolution made easy
Stars: ✭ 26 (+36.84%)
Mutual labels:  avro, avro-schema
avro-serde-php
Avro Serialisation/Deserialisation (SerDe) library for PHP 7.3+ & 8.0 with a Symfony Serializer integration
Stars: ✭ 43 (+126.32%)
Mutual labels:  avro, avro-schema
avro-schema-generator
Library for generating avro schema files (.avsc) based on DB tables structure
Stars: ✭ 38 (+100%)
Mutual labels:  avro, avro-schema
avrow
Avrow is a pure Rust implementation of the avro specification https://avro.apache.org/docs/current/spec.html with Serde support.
Stars: ✭ 27 (+42.11%)
Mutual labels:  avro, avro-schema
xml-avro
Convert XSD -> AVSC and XML -> AVRO
Stars: ✭ 32 (+68.42%)
Mutual labels:  avro, avro-schema
avrora
A convenient Elixir library to work with Avro schemas and Confluent® Schema Registry
Stars: ✭ 59 (+210.53%)
Mutual labels:  avro, avro-schema
jasvorno
A library for strong, schema based conversion between 'natural' JSON documents and Avro
Stars: ✭ 18 (-5.26%)
Mutual labels:  avro
typesocket
🌐 TypeScript WebSockets library.
Stars: ✭ 24 (+26.32%)
Mutual labels:  typescript-library
react-picture-annotation
A simple annotation component.
Stars: ✭ 53 (+178.95%)
Mutual labels:  typescript-library
javascript-serialization-benchmark
Comparison and benchmark of JavaScript serialization libraries (Protocol Buffer, Avro, BSON, etc.)
Stars: ✭ 54 (+184.21%)
Mutual labels:  avro
safe-touch
⛓ Runtime optional chaining for JS
Stars: ✭ 71 (+273.68%)
Mutual labels:  typescript-library
Insulator
A client UI to inspect Kafka topics, consume, produce and much more
Stars: ✭ 53 (+178.95%)
Mutual labels:  avro
rustic
rustic is a TypeScript library providing emulation of Rust's Option and Result types (and some useful wrappers for common js functions as well!)
Stars: ✭ 71 (+273.68%)
Mutual labels:  typescript-library
sqlweb
SqlWeb is an extension of JsStore which allows to use sql query for performing database operation in IndexedDB.
Stars: ✭ 38 (+100%)
Mutual labels:  typescript-library
youtube-deno
A Deno client library of the YouTube Data API.
Stars: ✭ 30 (+57.89%)
Mutual labels:  typescript-library
typed-machine
A strict Finite State Machine, written in TS
Stars: ✭ 21 (+10.53%)
Mutual labels:  typescript-library

Avro Typescript

A simple JS library to convert Avro Schemas to TypeScript interfaces.

Install

npm install avro-typescript

The library can be run in node.js or the browser. It takes a Avro Schema as a JavaScript object (from JSON) and returns the TypeScript code as a string.

Usage

import { avroToTypeScript, RecordType } from "avro-typescript"

const schemaText = fs.readFileSync("example.avsc", "UTF8");
const schema = JSON.parse(schemaText) as RecordType;
console.log(avroToTypeScript(schema as RecordType));

Override logicalTypes

Tools like avsc allow you to override the serialization/deserialization of LogicalTypes, say from numbers to native JS Date objects, in this case we want to generate the typescript type as 'Date', not 'number'. Therefore, you can pass in a map 'logicalTypes' to the options to override the outputted TS type for the schema logicalType.

For example:

const schema: Schema = {
    type: "record",
    name: "logicalOverrides",
    fields: [
        {
            name: "eventDate",
            type: {
                type: "int",
                logicalType: "date",
            },
        },
        {
            name: "startTime",
            type: {
                type: "int",
                logicalType: "timestamp-millis",
            },
        },
        {
            name: "displayTime",
            type: {
                type: "string",
                logicalType: "iso-datetime",
            },
        },
    ],
};
const actual = avroToTypeScript(schema, {
logicalTypes: {
    date: 'Date',
    'timestamp-millis': 'Date',
}
});

// this will output
export interface logicalOverrides {
    eventDate: Date;
    startTime: Date;
    displayTime: string;
}

Features

Most Avro features are supported, including:

  • Enumerated Types
  • Maps
  • Named Records
  • Mandatory and optional fields
  • Unions
  • Primitives

To-do

  • Generate a function to set defaults as per the schema
  • Add support for fixed
  • Generate JSDocs from documentation
  • Add namespace support
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].