|
| 1 | +/** |
| 2 | + * Apache Avro schema type definitions based on Avro 1.12.0 specification. |
| 3 | + * Specification: https://avro.apache.org/docs/1.12.0/specification/ |
| 4 | + */ |
| 5 | + |
| 6 | +// Base schema interface with common properties |
| 7 | +export interface AvroBaseSchema { |
| 8 | + /** The schema type */ |
| 9 | + type: string; |
| 10 | + /** Optional documentation for the schema */ |
| 11 | + doc?: string; |
| 12 | + /** Optional JSON object of string-valued properties */ |
| 13 | + [key: string]: any; |
| 14 | +} |
| 15 | + |
| 16 | +// Primitive type schemas |
| 17 | +export interface AvroNullSchema extends AvroBaseSchema { |
| 18 | + type: 'null'; |
| 19 | +} |
| 20 | + |
| 21 | +export interface AvroBooleanSchema extends AvroBaseSchema { |
| 22 | + type: 'boolean'; |
| 23 | +} |
| 24 | + |
| 25 | +export interface AvroIntSchema extends AvroBaseSchema { |
| 26 | + type: 'int'; |
| 27 | +} |
| 28 | + |
| 29 | +export interface AvroLongSchema extends AvroBaseSchema { |
| 30 | + type: 'long'; |
| 31 | +} |
| 32 | + |
| 33 | +export interface AvroFloatSchema extends AvroBaseSchema { |
| 34 | + type: 'float'; |
| 35 | +} |
| 36 | + |
| 37 | +export interface AvroDoubleSchema extends AvroBaseSchema { |
| 38 | + type: 'double'; |
| 39 | +} |
| 40 | + |
| 41 | +export interface AvroBytesSchema extends AvroBaseSchema { |
| 42 | + type: 'bytes'; |
| 43 | +} |
| 44 | + |
| 45 | +export interface AvroStringSchema extends AvroBaseSchema { |
| 46 | + type: 'string'; |
| 47 | +} |
| 48 | + |
| 49 | +// Complex type schemas |
| 50 | + |
| 51 | +export interface AvroRecordField { |
| 52 | + /** Name of the field */ |
| 53 | + name: string; |
| 54 | + /** Schema of the field */ |
| 55 | + type: AvroSchema; |
| 56 | + /** Optional documentation for the field */ |
| 57 | + doc?: string; |
| 58 | + /** Optional default value for the field */ |
| 59 | + default?: any; |
| 60 | + /** Optional ordering for the field */ |
| 61 | + order?: 'ascending' | 'descending' | 'ignore'; |
| 62 | + /** Optional aliases for the field */ |
| 63 | + aliases?: string[]; |
| 64 | +} |
| 65 | + |
| 66 | +export interface AvroRecordSchema extends AvroBaseSchema { |
| 67 | + type: 'record'; |
| 68 | + /** Name of the record schema */ |
| 69 | + name: string; |
| 70 | + /** Optional namespace for the record */ |
| 71 | + namespace?: string; |
| 72 | + /** Array of field definitions */ |
| 73 | + fields: AvroRecordField[]; |
| 74 | + /** Optional aliases for the record */ |
| 75 | + aliases?: string[]; |
| 76 | +} |
| 77 | + |
| 78 | +export interface AvroEnumSchema extends AvroBaseSchema { |
| 79 | + type: 'enum'; |
| 80 | + /** Name of the enum schema */ |
| 81 | + name: string; |
| 82 | + /** Optional namespace for the enum */ |
| 83 | + namespace?: string; |
| 84 | + /** Array of symbols in the enum */ |
| 85 | + symbols: string[]; |
| 86 | + /** Optional default symbol */ |
| 87 | + default?: string; |
| 88 | + /** Optional aliases for the enum */ |
| 89 | + aliases?: string[]; |
| 90 | +} |
| 91 | + |
| 92 | +export interface AvroArraySchema extends AvroBaseSchema { |
| 93 | + type: 'array'; |
| 94 | + /** Schema of the array items */ |
| 95 | + items: AvroSchema; |
| 96 | +} |
| 97 | + |
| 98 | +export interface AvroMapSchema extends AvroBaseSchema { |
| 99 | + type: 'map'; |
| 100 | + /** Schema of the map values */ |
| 101 | + values: AvroSchema; |
| 102 | +} |
| 103 | + |
| 104 | +export interface AvroUnionSchema extends Array<AvroSchema> { |
| 105 | + /** Union schemas are represented as JSON arrays */ |
| 106 | +} |
| 107 | + |
| 108 | +export interface AvroFixedSchema extends AvroBaseSchema { |
| 109 | + type: 'fixed'; |
| 110 | + /** Name of the fixed schema */ |
| 111 | + name: string; |
| 112 | + /** Optional namespace for the fixed */ |
| 113 | + namespace?: string; |
| 114 | + /** Size of the fixed-length data in bytes */ |
| 115 | + size: number; |
| 116 | + /** Optional aliases for the fixed */ |
| 117 | + aliases?: string[]; |
| 118 | +} |
| 119 | + |
| 120 | +// Union of all primitive schemas |
| 121 | +export type AvroPrimitiveSchema = |
| 122 | + | AvroNullSchema |
| 123 | + | AvroBooleanSchema |
| 124 | + | AvroIntSchema |
| 125 | + | AvroLongSchema |
| 126 | + | AvroFloatSchema |
| 127 | + | AvroDoubleSchema |
| 128 | + | AvroBytesSchema |
| 129 | + | AvroStringSchema; |
| 130 | + |
| 131 | +// Union of all complex schemas |
| 132 | +export type AvroComplexSchema = |
| 133 | + | AvroRecordSchema |
| 134 | + | AvroEnumSchema |
| 135 | + | AvroArraySchema |
| 136 | + | AvroMapSchema |
| 137 | + | AvroUnionSchema |
| 138 | + | AvroFixedSchema; |
| 139 | + |
| 140 | +// Union of all schema types |
| 141 | +export type AvroSchema = AvroPrimitiveSchema | AvroComplexSchema | string; |
| 142 | + |
| 143 | +// Named schemas (record, enum, fixed) |
| 144 | +export type AvroNamedSchema = AvroRecordSchema | AvroEnumSchema | AvroFixedSchema; |
| 145 | + |
| 146 | +// Logical types - extensions to primitive types |
| 147 | +export interface AvroLogicalTypeSchema extends AvroBaseSchema { |
| 148 | + /** The logical type name */ |
| 149 | + logicalType: string; |
| 150 | +} |
| 151 | + |
| 152 | +export interface AvroDecimalLogicalType extends AvroLogicalTypeSchema { |
| 153 | + logicalType: 'decimal'; |
| 154 | + /** The maximum number of digits in the decimal */ |
| 155 | + precision: number; |
| 156 | + /** The number of digits to the right of the decimal point */ |
| 157 | + scale?: number; |
| 158 | +} |
| 159 | + |
| 160 | +export interface AvroUuidLogicalType extends AvroStringSchema { |
| 161 | + logicalType: 'uuid'; |
| 162 | +} |
| 163 | + |
| 164 | +export interface AvroDateLogicalType extends AvroIntSchema { |
| 165 | + logicalType: 'date'; |
| 166 | +} |
| 167 | + |
| 168 | +export interface AvroTimeMillisLogicalType extends AvroIntSchema { |
| 169 | + logicalType: 'time-millis'; |
| 170 | +} |
| 171 | + |
| 172 | +export interface AvroTimeMicrosLogicalType extends AvroLongSchema { |
| 173 | + logicalType: 'time-micros'; |
| 174 | +} |
| 175 | + |
| 176 | +export interface AvroTimestampMillisLogicalType extends AvroLongSchema { |
| 177 | + logicalType: 'timestamp-millis'; |
| 178 | +} |
| 179 | + |
| 180 | +export interface AvroTimestampMicrosLogicalType extends AvroLongSchema { |
| 181 | + logicalType: 'timestamp-micros'; |
| 182 | +} |
| 183 | + |
| 184 | +export interface AvroLocalTimestampMillisLogicalType extends AvroLongSchema { |
| 185 | + logicalType: 'local-timestamp-millis'; |
| 186 | +} |
| 187 | + |
| 188 | +export interface AvroLocalTimestampMicrosLogicalType extends AvroLongSchema { |
| 189 | + logicalType: 'local-timestamp-micros'; |
| 190 | +} |
| 191 | + |
| 192 | +export interface AvroDurationLogicalType extends AvroFixedSchema { |
| 193 | + logicalType: 'duration'; |
| 194 | + size: 12; |
| 195 | +} |
0 commit comments