@@ -34,25 +34,25 @@ export class AvroSchemaEncoder {
3434 public encode ( value : unknown , schema : AvroSchema , selectedIndex ?: number ) : Uint8Array {
3535 this . writer . reset ( ) ;
3636 this . namedSchemas . clear ( ) ;
37-
37+
3838 // Validate schema first
3939 if ( ! this . validator . validateSchema ( schema ) ) {
4040 throw new Error ( 'Invalid Avro schema' ) ;
4141 }
42-
42+
4343 // Validate value against schema
4444 if ( ! this . validator . validateValue ( value , schema ) ) {
4545 throw new Error ( 'Value does not conform to schema' ) ;
4646 }
47-
47+
4848 this . collectNamedSchemas ( schema ) ;
49-
49+
5050 if ( Array . isArray ( schema ) && selectedIndex !== undefined ) {
5151 this . writeUnion ( value , schema , selectedIndex ) ;
5252 } else {
5353 this . writeValue ( value , schema ) ;
5454 }
55-
55+
5656 return this . writer . flush ( ) ;
5757 }
5858
@@ -130,7 +130,7 @@ export class AvroSchemaEncoder {
130130 if ( typeof schema === 'object' && schema . type !== 'record' ) {
131131 throw new Error ( 'Schema is not a record schema' ) ;
132132 }
133-
133+
134134 const recordSchema = this . resolveSchema ( schema ) as AvroRecordSchema ;
135135 if ( recordSchema . type !== 'record' ) {
136136 throw new Error ( 'Schema is not a record schema' ) ;
@@ -156,7 +156,7 @@ export class AvroSchemaEncoder {
156156 if ( typeof schema === 'object' && schema . type !== 'enum' ) {
157157 throw new Error ( 'Schema is not an enum schema' ) ;
158158 }
159-
159+
160160 const enumSchema = this . resolveSchema ( schema ) as AvroEnumSchema ;
161161 if ( enumSchema . type !== 'enum' ) {
162162 throw new Error ( 'Schema is not an enum schema' ) ;
@@ -166,7 +166,7 @@ export class AvroSchemaEncoder {
166166 if ( index === - 1 ) {
167167 throw new Error ( `Invalid enum value: ${ value } ` ) ;
168168 }
169-
169+
170170 this . writeVarIntSigned ( this . encodeZigZag32 ( index ) ) ;
171171 }
172172
@@ -177,21 +177,21 @@ export class AvroSchemaEncoder {
177177 if ( typeof schema === 'object' && schema . type !== 'array' ) {
178178 throw new Error ( 'Schema is not an array schema' ) ;
179179 }
180-
180+
181181 const arraySchema = this . resolveSchema ( schema ) as AvroArraySchema ;
182182 if ( arraySchema . type !== 'array' ) {
183183 throw new Error ( 'Schema is not an array schema' ) ;
184184 }
185185
186186 // Write array length
187187 this . writeVarIntUnsigned ( value . length ) ;
188-
188+
189189 // Write array items
190190 const length = value . length ;
191191 for ( let i = 0 ; i < length ; i ++ ) {
192192 this . writeValue ( value [ i ] , arraySchema . items ) ;
193193 }
194-
194+
195195 // Write end-of-array marker
196196 this . writeVarIntUnsigned ( 0 ) ;
197197 }
@@ -203,25 +203,25 @@ export class AvroSchemaEncoder {
203203 if ( typeof schema === 'object' && schema . type !== 'map' ) {
204204 throw new Error ( 'Schema is not a map schema' ) ;
205205 }
206-
206+
207207 const mapSchema = this . resolveSchema ( schema ) as AvroMapSchema ;
208208 if ( mapSchema . type !== 'map' ) {
209209 throw new Error ( 'Schema is not a map schema' ) ;
210210 }
211211
212212 const entries = Object . entries ( value ) ;
213-
213+
214214 // Write map length
215215 this . writeVarIntUnsigned ( entries . length ) ;
216-
216+
217217 // Write map entries
218218 const length = entries . length ;
219219 for ( let i = 0 ; i < length ; i ++ ) {
220220 const entry = entries [ i ] ;
221221 this . encoder . writeStr ( entry [ 0 ] ) ;
222222 this . writeValue ( entry [ 1 ] , mapSchema . values ) ;
223223 }
224-
224+
225225 // Write end-of-map marker
226226 this . writeVarIntUnsigned ( 0 ) ;
227227 }
@@ -237,7 +237,7 @@ export class AvroSchemaEncoder {
237237 let index = selectedIndex ;
238238 if ( index === undefined ) {
239239 // Find the first matching schema in the union
240- index = schema . findIndex ( subSchema => this . validator . validateValue ( value , subSchema ) ) ;
240+ index = schema . findIndex ( ( subSchema ) => this . validator . validateValue ( value , subSchema ) ) ;
241241 if ( index === - 1 ) {
242242 throw new Error ( 'Value does not match any schema in the union' ) ;
243243 }
@@ -249,7 +249,7 @@ export class AvroSchemaEncoder {
249249
250250 // Write union index
251251 this . writeVarIntSigned ( this . encodeZigZag32 ( index ) ) ;
252-
252+
253253 // Write the value according to the selected schema
254254 this . writeValue ( value , schema [ index ] ) ;
255255 }
@@ -261,7 +261,7 @@ export class AvroSchemaEncoder {
261261 if ( typeof schema === 'object' && schema . type !== 'fixed' ) {
262262 throw new Error ( 'Schema is not a fixed schema' ) ;
263263 }
264-
264+
265265 const fixedSchema = this . resolveSchema ( schema ) as AvroFixedSchema ;
266266 if ( fixedSchema . type !== 'fixed' ) {
267267 throw new Error ( 'Schema is not a fixed schema' ) ;
@@ -270,7 +270,7 @@ export class AvroSchemaEncoder {
270270 if ( value . length !== fixedSchema . size ) {
271271 throw new Error ( `Fixed value length ${ value . length } does not match schema size ${ fixedSchema . size } ` ) ;
272272 }
273-
273+
274274 this . writer . buf ( value , value . length ) ;
275275 }
276276
@@ -279,12 +279,13 @@ export class AvroSchemaEncoder {
279279 */
280280 public writeNumber ( value : number , schema : AvroSchema ) : void {
281281 const resolvedSchema = this . resolveSchema ( schema ) ;
282- const schemaType = typeof resolvedSchema === 'string'
283- ? resolvedSchema
284- : Array . isArray ( resolvedSchema )
285- ? 'union'
286- : resolvedSchema . type ;
287-
282+ const schemaType =
283+ typeof resolvedSchema === 'string'
284+ ? resolvedSchema
285+ : Array . isArray ( resolvedSchema )
286+ ? 'union'
287+ : resolvedSchema . type ;
288+
288289 switch ( schemaType ) {
289290 case 'int' :
290291 this . writeInt ( value , schema ) ;
@@ -369,12 +370,13 @@ export class AvroSchemaEncoder {
369370
370371 private validateSchemaType ( schema : AvroSchema , expectedType : string ) : void {
371372 const resolvedSchema = this . resolveSchema ( schema ) ;
372- const actualType = typeof resolvedSchema === 'string'
373- ? resolvedSchema
374- : Array . isArray ( resolvedSchema )
375- ? 'union'
376- : resolvedSchema . type ;
377-
373+ const actualType =
374+ typeof resolvedSchema === 'string'
375+ ? resolvedSchema
376+ : Array . isArray ( resolvedSchema )
377+ ? 'union'
378+ : resolvedSchema . type ;
379+
378380 if ( actualType !== expectedType ) {
379381 throw new Error ( `Expected schema type ${ expectedType } , got ${ actualType } ` ) ;
380382 }
@@ -399,7 +401,7 @@ export class AvroSchemaEncoder {
399401 const recordSchema = schema as AvroRecordSchema ;
400402 const recordFullName = this . getFullName ( recordSchema . name , recordSchema . namespace ) ;
401403 this . namedSchemas . set ( recordFullName , recordSchema ) ;
402- recordSchema . fields . forEach ( field => this . collectNamedSchemas ( field . type ) ) ;
404+ recordSchema . fields . forEach ( ( field ) => this . collectNamedSchemas ( field . type ) ) ;
403405 break ;
404406 case 'enum' :
405407 const enumSchema = schema as AvroEnumSchema ;
@@ -457,4 +459,4 @@ export class AvroSchemaEncoder {
457459 private encodeZigZag32 ( value : number ) : number {
458460 return ( value << 1 ) ^ ( value >> 31 ) ;
459461 }
460- }
462+ }
0 commit comments