mtth / avsc

Avro for JavaScript :zap:
MIT License
1.27k stars 147 forks source link

Allow using avro.Type instances in schema unions #417

Closed valadaptive closed 1 year ago

valadaptive commented 1 year ago

In a type schema, union members can be type schemas or predefined avro.Type instances:

{
    name: 'Foo',
    type: 'record',
    fields: [
        {
            name: 'bar',
            type: [
                'string',
                Type.forSchema(...)
            ]
        }
    ]
}

This adds support for that in the TypeScript definitions.

valadaptive commented 1 year ago

Upon revisiting this, I went with a simpler solution--expand AvroSchema to include Type instances and arrays of Type instances. This makes Schema an alias of AvroSchema, but I think that's fine. I'd like to revisit the typings more heavily in the future anyway.

mtth commented 1 year ago

Sounds reasonable.

I'd like to revisit the typings more heavily in the future anyway.

In case it's useful, you can take a look at the typings for @avro/types here. Some of the methods have been renamed but the API is very similar. (The @avro/* packages were an attempt to decompose avsc into focused components but I never found the time to complete the migration. With the introduction of exports it also isn't as important anymore.)