@sachitv/avro-typescript 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/esm/avro_reader_sync.d.ts +48 -0
  2. package/esm/avro_reader_sync.js +79 -0
  3. package/esm/avro_writer_sync.d.ts +28 -0
  4. package/esm/avro_writer_sync.js +63 -0
  5. package/esm/internal/collections/circular_buffer.d.ts +4 -3
  6. package/esm/internal/collections/circular_buffer.js +8 -6
  7. package/esm/mod.d.ts +17 -0
  8. package/esm/mod.js +11 -0
  9. package/esm/schemas/base_type.d.ts +8 -0
  10. package/esm/schemas/base_type.js +21 -0
  11. package/esm/schemas/complex/array_type.d.ts +31 -10
  12. package/esm/schemas/complex/array_type.js +129 -39
  13. package/esm/schemas/complex/enum_type.d.ts +24 -7
  14. package/esm/schemas/complex/enum_type.js +61 -15
  15. package/esm/schemas/complex/fixed_type.d.ts +27 -12
  16. package/esm/schemas/complex/fixed_type.js +40 -27
  17. package/esm/schemas/complex/map_type.d.ts +31 -10
  18. package/esm/schemas/complex/map_type.js +88 -47
  19. package/esm/schemas/complex/named_type.d.ts +1 -1
  20. package/esm/schemas/complex/named_type.js +2 -2
  21. package/esm/schemas/complex/record_field.d.ts +62 -0
  22. package/esm/schemas/complex/record_field.js +112 -0
  23. package/esm/schemas/complex/record_resolver.d.ts +45 -0
  24. package/esm/schemas/complex/record_resolver.js +92 -0
  25. package/esm/schemas/complex/record_type.d.ts +45 -70
  26. package/esm/schemas/complex/record_type.js +158 -213
  27. package/esm/schemas/complex/record_writer_cache.d.ts +44 -0
  28. package/esm/schemas/complex/record_writer_cache.js +141 -0
  29. package/esm/schemas/complex/record_writer_strategy.d.ts +123 -0
  30. package/esm/schemas/complex/record_writer_strategy.js +309 -0
  31. package/esm/schemas/complex/union_type.d.ts +23 -11
  32. package/esm/schemas/complex/union_type.js +77 -29
  33. package/esm/schemas/logical/decimal_logical_type.d.ts +1 -1
  34. package/esm/schemas/logical/decimal_logical_type.js +2 -2
  35. package/esm/schemas/logical/duration_logical_type.d.ts +1 -1
  36. package/esm/schemas/logical/duration_logical_type.js +2 -2
  37. package/esm/schemas/logical/logical_type.d.ts +27 -9
  38. package/esm/schemas/logical/logical_type.js +50 -17
  39. package/esm/schemas/logical/temporal_logical_types.d.ts +9 -9
  40. package/esm/schemas/logical/temporal_logical_types.js +18 -18
  41. package/esm/schemas/logical/uuid_logical_type.d.ts +1 -1
  42. package/esm/schemas/logical/uuid_logical_type.js +2 -2
  43. package/esm/schemas/primitive/boolean_type.d.ts +15 -4
  44. package/esm/schemas/primitive/boolean_type.js +22 -7
  45. package/esm/schemas/primitive/bytes_type.d.ts +16 -5
  46. package/esm/schemas/primitive/bytes_type.js +31 -16
  47. package/esm/schemas/primitive/double_type.d.ts +13 -2
  48. package/esm/schemas/primitive/double_type.js +34 -5
  49. package/esm/schemas/primitive/fixed_size_base_type.d.ts +11 -7
  50. package/esm/schemas/primitive/fixed_size_base_type.js +14 -14
  51. package/esm/schemas/primitive/float_type.d.ts +11 -2
  52. package/esm/schemas/primitive/float_type.js +26 -5
  53. package/esm/schemas/primitive/int_type.d.ts +17 -6
  54. package/esm/schemas/primitive/int_type.js +26 -17
  55. package/esm/schemas/primitive/long_type.d.ts +16 -5
  56. package/esm/schemas/primitive/long_type.js +30 -16
  57. package/esm/schemas/primitive/null_type.d.ts +15 -4
  58. package/esm/schemas/primitive/null_type.js +20 -7
  59. package/esm/schemas/primitive/primitive_type.d.ts +2 -0
  60. package/esm/schemas/primitive/primitive_type.js +4 -0
  61. package/esm/schemas/primitive/string_type.d.ts +17 -6
  62. package/esm/schemas/primitive/string_type.js +33 -18
  63. package/esm/schemas/resolver.d.ts +6 -0
  64. package/esm/schemas/type.d.ts +64 -4
  65. package/esm/schemas/type.js +97 -0
  66. package/esm/serialization/avro_file_parser_sync.d.ts +34 -0
  67. package/esm/serialization/avro_file_parser_sync.js +160 -0
  68. package/esm/serialization/avro_file_writer_sync.d.ts +47 -0
  69. package/esm/serialization/avro_file_writer_sync.js +211 -0
  70. package/esm/serialization/buffers/blob_readable_buffer.d.ts +4 -3
  71. package/esm/serialization/buffers/blob_readable_buffer.js +20 -6
  72. package/esm/serialization/buffers/buffer.d.ts +6 -1
  73. package/esm/serialization/buffers/buffer.js +3 -0
  74. package/esm/serialization/buffers/buffer_error.d.ts +28 -0
  75. package/esm/serialization/buffers/buffer_error.js +70 -0
  76. package/esm/serialization/buffers/buffer_sync.d.ts +51 -0
  77. package/esm/serialization/buffers/buffer_sync.js +4 -0
  78. package/esm/serialization/buffers/in_memory_buffer.d.ts +1 -0
  79. package/esm/serialization/buffers/in_memory_buffer.js +7 -5
  80. package/esm/serialization/buffers/in_memory_buffer_sync.d.ts +133 -0
  81. package/esm/serialization/buffers/in_memory_buffer_sync.js +259 -0
  82. package/esm/serialization/counting_writable_tap.d.ts +45 -0
  83. package/esm/serialization/counting_writable_tap.js +90 -0
  84. package/esm/serialization/counting_writable_tap_sync.d.ts +46 -0
  85. package/esm/serialization/counting_writable_tap_sync.js +87 -0
  86. package/esm/serialization/decoders/decoder_null_sync.d.ts +12 -0
  87. package/esm/serialization/decoders/decoder_null_sync.js +13 -0
  88. package/esm/serialization/decoders/decoder_sync.d.ts +15 -0
  89. package/esm/serialization/decoders/decoder_sync.js +1 -0
  90. package/esm/serialization/encoders/encoder_null_sync.d.ts +12 -0
  91. package/esm/serialization/encoders/encoder_null_sync.js +13 -0
  92. package/esm/serialization/encoders/encoder_sync.d.ts +15 -0
  93. package/esm/serialization/encoders/encoder_sync.js +1 -0
  94. package/esm/serialization/streams/fixed_size_stream_readable_buffer_adapter.d.ts +3 -2
  95. package/esm/serialization/streams/fixed_size_stream_readable_buffer_adapter.js +19 -9
  96. package/esm/serialization/streams/fixed_size_stream_reader_sync.d.ts +25 -0
  97. package/esm/serialization/streams/fixed_size_stream_reader_sync.js +63 -0
  98. package/esm/serialization/streams/fixed_size_stream_writer_sync.d.ts +45 -0
  99. package/esm/serialization/streams/fixed_size_stream_writer_sync.js +98 -0
  100. package/esm/serialization/streams/forward_only_stream_readable_buffer_adapter.d.ts +5 -3
  101. package/esm/serialization/streams/forward_only_stream_readable_buffer_adapter.js +18 -8
  102. package/esm/serialization/streams/stream_readable_buffer_adapter.d.ts +3 -2
  103. package/esm/serialization/streams/stream_readable_buffer_adapter.js +19 -6
  104. package/esm/serialization/streams/stream_readable_buffer_adapter_sync.d.ts +36 -0
  105. package/esm/serialization/streams/stream_readable_buffer_adapter_sync.js +93 -0
  106. package/esm/serialization/streams/stream_writable_buffer_adapter_sync.d.ts +45 -0
  107. package/esm/serialization/streams/stream_writable_buffer_adapter_sync.js +78 -0
  108. package/esm/serialization/streams/streams_sync.d.ts +36 -0
  109. package/esm/serialization/streams/streams_sync.js +4 -0
  110. package/esm/serialization/tap.d.ts +15 -32
  111. package/esm/serialization/tap.js +45 -134
  112. package/esm/serialization/tap_sync.d.ts +240 -0
  113. package/esm/serialization/tap_sync.js +545 -0
  114. package/esm/serialization/text_encoding.d.ts +16 -0
  115. package/esm/serialization/text_encoding.js +48 -1
  116. package/esm/type/create_type.d.ts +20 -0
  117. package/esm/type/create_type.js +49 -28
  118. package/package.json +1 -1
  119. package/esm/serialization/manipulate_bytes.d.ts +0 -6
  120. package/esm/serialization/manipulate_bytes.js +0 -13
  121. package/esm/serialization/read_uint_le.d.ts +0 -4
  122. package/esm/serialization/read_uint_le.js +0 -14
@@ -9,13 +9,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _ArrayType_instances, _ArrayType_itemsType, _ArrayType_readArraySize, _ArrayResolver_itemResolver;
13
- import { WritableTap, } from "../../serialization/tap.js";
12
+ var _ArrayType_instances, _ArrayType_itemsType, _ArrayType_readArraySize, _ArrayType_readArraySizeSync, _ArrayResolver_itemResolver;
14
13
  import { bigIntToSafeNumber } from "../../serialization/conversion.js";
15
14
  import { BaseType } from "../base_type.js";
16
15
  import { Resolver } from "../resolver.js";
17
- import { throwInvalidError } from "../error.js";
18
- import { calculateVarintSize } from "../../internal/varint.js";
19
16
  /**
20
17
  * Helper function to read an array from a tap.
21
18
  * @param tap The tap to read from.
@@ -40,6 +37,31 @@ export async function readArrayInto(tap, readElement, collect) {
40
37
  }
41
38
  }
42
39
  }
40
+ /**
41
+ * Synchronous helper function to read an array from a tap.
42
+ * @param tap The tap to read from.
43
+ * @param readElement Function to read a single element.
44
+ * @param collect Function to collect each read element.
45
+ */
46
+ export function readArrayIntoSync(tap, readElement, collect) {
47
+ /**
48
+ * Reads repeated blocks from the tap synchronously and collects decoded elements.
49
+ */
50
+ while (true) {
51
+ const rawCount = tap.readLong();
52
+ if (rawCount === 0n) {
53
+ break;
54
+ }
55
+ let count = bigIntToSafeNumber(rawCount, "Array block length");
56
+ if (count < 0) {
57
+ count = -count;
58
+ tap.skipLong();
59
+ }
60
+ for (let i = 0; i < count; i++) {
61
+ collect(readElement(tap));
62
+ }
63
+ }
64
+ }
43
65
  /**
44
66
  * Avro `array` type for homogeneous collections of items described by a schema.
45
67
  */
@@ -49,7 +71,7 @@ export class ArrayType extends BaseType {
49
71
  * @param params The array type parameters.
50
72
  */
51
73
  constructor(params) {
52
- super();
74
+ super(params.validate ?? true);
53
75
  _ArrayType_instances.add(this);
54
76
  _ArrayType_itemsType.set(this, void 0);
55
77
  if (!params.items) {
@@ -92,22 +114,29 @@ export class ArrayType extends BaseType {
92
114
  return isValid;
93
115
  }
94
116
  /**
95
- * Overrides the base write method to serialize an array.
96
- * @param tap The tap to write to.
97
- * @param value The array to write.
117
+ * Writes array without validation.
98
118
  */
99
- async write(tap, value) {
100
- if (!Array.isArray(value)) {
101
- throwInvalidError([], value, this);
102
- }
119
+ async writeUnchecked(tap, value) {
103
120
  if (value.length > 0) {
104
121
  await tap.writeLong(BigInt(value.length));
105
122
  for (const element of value) {
106
- await __classPrivateFieldGet(this, _ArrayType_itemsType, "f").write(tap, element);
123
+ await __classPrivateFieldGet(this, _ArrayType_itemsType, "f").writeUnchecked(tap, element);
107
124
  }
108
125
  }
109
126
  await tap.writeLong(0n);
110
127
  }
128
+ /**
129
+ * Writes array without validation synchronously.
130
+ */
131
+ writeSyncUnchecked(tap, value) {
132
+ if (value.length > 0) {
133
+ tap.writeLong(BigInt(value.length));
134
+ for (const element of value) {
135
+ __classPrivateFieldGet(this, _ArrayType_itemsType, "f").writeSyncUnchecked(tap, element);
136
+ }
137
+ }
138
+ tap.writeLong(0n);
139
+ }
111
140
  /**
112
141
  * Overrides the base skip method to skip over an array in the tap.
113
142
  * @param tap The tap to skip from.
@@ -137,6 +166,30 @@ export class ArrayType extends BaseType {
137
166
  }
138
167
  }
139
168
  }
169
+ /**
170
+ * Advances the sync tap past the encoded array without decoding elements.
171
+ */
172
+ skipSync(tap) {
173
+ while (true) {
174
+ const rawCount = tap.readLong();
175
+ if (rawCount === 0n) {
176
+ break;
177
+ }
178
+ let count = bigIntToSafeNumber(rawCount, "Array block length");
179
+ if (count < 0) {
180
+ count = -count;
181
+ const blockSize = Number(tap.readLong());
182
+ if (blockSize > 0) {
183
+ tap.skipFixed(blockSize);
184
+ }
185
+ }
186
+ else {
187
+ for (let i = 0; i < count; i++) {
188
+ __classPrivateFieldGet(this, _ArrayType_itemsType, "f").skipSync(tap);
189
+ }
190
+ }
191
+ }
192
+ }
140
193
  /**
141
194
  * Overrides the base read method to deserialize an array.
142
195
  * @param tap The tap to read from.
@@ -150,32 +203,17 @@ export class ArrayType extends BaseType {
150
203
  return result;
151
204
  }
152
205
  /**
153
- * Overrides the base toBuffer method to serialize an array to a buffer.
154
- * @param value The array to serialize.
155
- * @returns The serialized buffer.
206
+ * Reads the entire array synchronously from the tap.
156
207
  */
157
- async toBuffer(value) {
158
- if (!Array.isArray(value)) {
159
- throwInvalidError([], value, this);
160
- }
161
- const elementBuffers = value.length === 0 ? [] : await Promise.all(value.map(async (element) => new Uint8Array(await __classPrivateFieldGet(this, _ArrayType_itemsType, "f").toBuffer(element))));
162
- let totalSize = 1; // final zero block terminator
163
- if (value.length > 0) {
164
- totalSize += calculateVarintSize(value.length);
165
- for (const buf of elementBuffers) {
166
- totalSize += buf.byteLength;
167
- }
168
- }
169
- const buffer = new ArrayBuffer(totalSize);
170
- const tap = new WritableTap(buffer);
171
- if (value.length > 0) {
172
- await tap.writeLong(BigInt(value.length));
173
- for (const buf of elementBuffers) {
174
- await tap.writeFixed(buf);
175
- }
176
- }
177
- await tap.writeLong(0n);
178
- return buffer;
208
+ /**
209
+ * Reads resolved elements synchronously through the item resolver.
210
+ */
211
+ readSync(tap) {
212
+ const result = [];
213
+ readArrayIntoSync(tap, (innerTap) => __classPrivateFieldGet(this, _ArrayType_itemsType, "f").readSync(innerTap), (value) => {
214
+ result.push(value);
215
+ });
216
+ return result;
179
217
  }
180
218
  /**
181
219
  * Overrides the base cloneFromValue method to clone an array.
@@ -257,7 +295,45 @@ export class ArrayType extends BaseType {
257
295
  n2 = await __classPrivateFieldGet(this, _ArrayType_instances, "m", _ArrayType_readArraySize).call(this, tap2);
258
296
  }
259
297
  }
260
- return n1 === n2 ? 0 : n1 < n2 ? -1 : 1;
298
+ if (n1 === n2) {
299
+ return 0;
300
+ }
301
+ if (n1 < n2) {
302
+ return -1;
303
+ }
304
+ return 1;
305
+ }
306
+ /**
307
+ * Compares two sync taps that encode arrays for ordering.
308
+ */
309
+ matchSync(tap1, tap2) {
310
+ let n1 = __classPrivateFieldGet(this, _ArrayType_instances, "m", _ArrayType_readArraySizeSync).call(this, tap1);
311
+ let n2 = __classPrivateFieldGet(this, _ArrayType_instances, "m", _ArrayType_readArraySizeSync).call(this, tap2);
312
+ while (n1 !== 0n && n2 !== 0n) {
313
+ const f = __classPrivateFieldGet(this, _ArrayType_itemsType, "f").matchSync(tap1, tap2);
314
+ if (f !== 0) {
315
+ return f;
316
+ }
317
+ if (n1 > 0n) {
318
+ n1--;
319
+ }
320
+ if (n1 === 0n) {
321
+ n1 = __classPrivateFieldGet(this, _ArrayType_instances, "m", _ArrayType_readArraySizeSync).call(this, tap1);
322
+ }
323
+ if (n2 > 0n) {
324
+ n2--;
325
+ }
326
+ if (n2 === 0n) {
327
+ n2 = __classPrivateFieldGet(this, _ArrayType_instances, "m", _ArrayType_readArraySizeSync).call(this, tap2);
328
+ }
329
+ }
330
+ if (n1 === n2) {
331
+ return 0;
332
+ }
333
+ if (n1 < n2) {
334
+ return -1;
335
+ }
336
+ return 1;
261
337
  }
262
338
  /**
263
339
  * Creates a resolver for schema evolution between array types.
@@ -279,6 +355,13 @@ _ArrayType_itemsType = new WeakMap(), _ArrayType_instances = new WeakSet(), _Arr
279
355
  await tap.skipLong(); // skip size
280
356
  }
281
357
  return n;
358
+ }, _ArrayType_readArraySizeSync = function _ArrayType_readArraySizeSync(tap) {
359
+ let n = tap.readLong();
360
+ if (n < 0n) {
361
+ n = -n;
362
+ tap.skipLong();
363
+ }
364
+ return n;
282
365
  };
283
366
  class ArrayResolver extends Resolver {
284
367
  constructor(reader, itemResolver) {
@@ -295,5 +378,12 @@ class ArrayResolver extends Resolver {
295
378
  });
296
379
  return result;
297
380
  }
381
+ readSync(tap) {
382
+ const result = [];
383
+ readArrayIntoSync(tap, (innerTap) => __classPrivateFieldGet(this, _ArrayResolver_itemResolver, "f").readSync(innerTap), (value) => {
384
+ result.push(value);
385
+ });
386
+ return result;
387
+ }
298
388
  }
299
389
  _ArrayResolver_itemResolver = new WeakMap();
@@ -1,4 +1,5 @@
1
- import { type ReadableTapLike, type WritableTapLike } from "../../serialization/tap.js";
1
+ import type { ReadableTapLike, WritableTapLike } from "../../serialization/tap.js";
2
+ import type { SyncReadableTapLike, SyncWritableTapLike } from "../../serialization/tap_sync.js";
2
3
  import { Resolver } from "../resolver.js";
3
4
  import type { JSONType, Type } from "../type.js";
4
5
  import { NamedType } from "./named_type.js";
@@ -12,6 +13,8 @@ export interface EnumTypeParams extends ResolvedNames {
12
13
  symbols: string[];
13
14
  /** Optional default value. */
14
15
  default?: string;
16
+ /** Whether to validate during writes. Defaults to true. */
17
+ validate?: boolean;
15
18
  }
16
19
  /**
17
20
  * Avro enum type implemented in TypeScript.
@@ -41,23 +44,33 @@ export declare class EnumType extends NamedType<string> {
41
44
  */
42
45
  check(value: unknown, errorHook?: ErrorHook, path?: string[]): boolean;
43
46
  /**
44
- * Serializes the enum value by writing its index.
45
- * @param tap The tap to write to.
46
- * @param value The enum value to write.
47
+ * Writes enum value without type validation.
48
+ * Still validates that the symbol exists to avoid undefined behavior.
47
49
  */
48
- write(tap: WritableTapLike, value: string): Promise<void>;
50
+ writeUnchecked(tap: WritableTapLike, value: string): Promise<void>;
51
+ /**
52
+ * Writes enum value without type validation synchronously.
53
+ * Still validates that the symbol exists to avoid undefined behavior.
54
+ */
55
+ writeSyncUnchecked(tap: SyncWritableTapLike, value: string): void;
56
+ /** Returns the encoded byte length for the given enum value. */
57
+ protected byteLength(value: string): number;
49
58
  /**
50
59
  * Skips the enum value in the tap.
51
60
  */
52
61
  skip(tap: ReadableTapLike): Promise<void>;
62
+ /**
63
+ * Advances the sync tap past a stored enum index.
64
+ */
65
+ skipSync(tap: SyncReadableTapLike): void;
53
66
  /**
54
67
  * Reads the enum value from the tap.
55
68
  */
56
69
  read(tap: ReadableTapLike): Promise<string>;
57
70
  /**
58
- * Converts the enum value to its binary buffer representation.
71
+ * Reads an enum index synchronously and returns the matching symbol.
59
72
  */
60
- toBuffer(value: string): Promise<ArrayBuffer>;
73
+ readSync(tap: SyncReadableTapLike): string;
61
74
  /** Clones a value into a string. */
62
75
  cloneFromValue(value: unknown): string;
63
76
  /** Compares two strings. */
@@ -74,6 +87,10 @@ export declare class EnumType extends NamedType<string> {
74
87
  * Compares two encoded enum values for equality.
75
88
  */
76
89
  match(tap1: ReadableTapLike, tap2: ReadableTapLike): Promise<number>;
90
+ /**
91
+ * Compares the enum indices stored in two sync taps.
92
+ */
93
+ matchSync(tap1: SyncReadableTapLike, tap2: SyncReadableTapLike): number;
77
94
  /**
78
95
  * Creates a resolver for schema evolution between enum types.
79
96
  */
@@ -10,7 +10,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _EnumType_symbols, _EnumType_indices, _EnumType_default;
13
- import { WritableTap, } from "../../serialization/tap.js";
14
13
  import { Resolver } from "../resolver.js";
15
14
  import { NamedType } from "./named_type.js";
16
15
  import { isValidName } from "./resolve_names.js";
@@ -30,7 +29,7 @@ export class EnumType extends NamedType {
30
29
  throw new Error("EnumType requires a non-empty symbols array.");
31
30
  }
32
31
  const { symbols, default: defaultValue, ...nameInfo } = params;
33
- super(nameInfo);
32
+ super(nameInfo, params.validate ?? true);
34
33
  _EnumType_symbols.set(this, void 0);
35
34
  _EnumType_indices.set(this, void 0);
36
35
  _EnumType_default.set(this, void 0);
@@ -79,23 +78,47 @@ export class EnumType extends NamedType {
79
78
  return isValid;
80
79
  }
81
80
  /**
82
- * Serializes the enum value by writing its index.
83
- * @param tap The tap to write to.
84
- * @param value The enum value to write.
81
+ * Writes enum value without type validation.
82
+ * Still validates that the symbol exists to avoid undefined behavior.
85
83
  */
86
- async write(tap, value) {
84
+ async writeUnchecked(tap, value) {
87
85
  const index = __classPrivateFieldGet(this, _EnumType_indices, "f").get(value);
88
86
  if (index === undefined) {
89
87
  throwInvalidError([], value, this);
90
88
  }
91
89
  await tap.writeLong(BigInt(index));
92
90
  }
91
+ /**
92
+ * Writes enum value without type validation synchronously.
93
+ * Still validates that the symbol exists to avoid undefined behavior.
94
+ */
95
+ writeSyncUnchecked(tap, value) {
96
+ const index = __classPrivateFieldGet(this, _EnumType_indices, "f").get(value);
97
+ if (index === undefined) {
98
+ throwInvalidError([], value, this);
99
+ }
100
+ tap.writeLong(BigInt(index));
101
+ }
102
+ /** Returns the encoded byte length for the given enum value. */
103
+ byteLength(value) {
104
+ const index = __classPrivateFieldGet(this, _EnumType_indices, "f").get(value);
105
+ if (index === undefined) {
106
+ throwInvalidError([], value, this);
107
+ }
108
+ return calculateVarintSize(index);
109
+ }
93
110
  /**
94
111
  * Skips the enum value in the tap.
95
112
  */
96
113
  async skip(tap) {
97
114
  await tap.skipLong();
98
115
  }
116
+ /**
117
+ * Advances the sync tap past a stored enum index.
118
+ */
119
+ skipSync(tap) {
120
+ tap.skipLong();
121
+ }
99
122
  /**
100
123
  * Reads the enum value from the tap.
101
124
  */
@@ -108,16 +131,15 @@ export class EnumType extends NamedType {
108
131
  return __classPrivateFieldGet(this, _EnumType_symbols, "f")[index];
109
132
  }
110
133
  /**
111
- * Converts the enum value to its binary buffer representation.
134
+ * Reads an enum index synchronously and returns the matching symbol.
112
135
  */
113
- async toBuffer(value) {
114
- this.check(value, throwInvalidError, []);
115
- const index = __classPrivateFieldGet(this, _EnumType_indices, "f").get(value);
116
- const size = calculateVarintSize(index);
117
- const buffer = new ArrayBuffer(size);
118
- const tap = new WritableTap(buffer);
119
- await this.write(tap, value);
120
- return buffer;
136
+ readSync(tap) {
137
+ const rawIndex = tap.readLong();
138
+ const index = Number(rawIndex);
139
+ if (!Number.isSafeInteger(index) || index < 0 || index >= __classPrivateFieldGet(this, _EnumType_symbols, "f").length) {
140
+ throw new Error(`Invalid enum index ${rawIndex.toString()} for ${this.getFullName()}`);
141
+ }
142
+ return __classPrivateFieldGet(this, _EnumType_symbols, "f")[index];
121
143
  }
122
144
  /** Clones a value into a string. */
123
145
  cloneFromValue(value) {
@@ -154,6 +176,12 @@ export class EnumType extends NamedType {
154
176
  async match(tap1, tap2) {
155
177
  return await tap1.matchLong(tap2);
156
178
  }
179
+ /**
180
+ * Compares the enum indices stored in two sync taps.
181
+ */
182
+ matchSync(tap1, tap2) {
183
+ return tap1.matchLong(tap2);
184
+ }
157
185
  /**
158
186
  * Creates a resolver for schema evolution between enum types.
159
187
  */
@@ -182,6 +210,12 @@ export class EnumType extends NamedType {
182
210
  async read(tap) {
183
211
  return await __classPrivateFieldGet(this, _writer, "f").read(tap);
184
212
  }
213
+ /**
214
+ * Reads a symbol via the underlying writer enum synchronously.
215
+ */
216
+ readSync(tap) {
217
+ return __classPrivateFieldGet(this, _writer, "f").readSync(tap);
218
+ }
185
219
  },
186
220
  _writer = new WeakMap(),
187
221
  _a)(this, writerType);
@@ -204,6 +238,18 @@ export class EnumType extends NamedType {
204
238
  return __classPrivateFieldGet(__classPrivateFieldGet(this, _reader, "f"), _EnumType_default, "f");
205
239
  }
206
240
  }
241
+ /**
242
+ * Reads a writer symbol and falls back to the reader default synchronously.
243
+ */
244
+ readSync(tap) {
245
+ const writerSymbol = __classPrivateFieldGet(this, _writer_1, "f").readSync(tap);
246
+ if (__classPrivateFieldGet(__classPrivateFieldGet(this, _reader, "f"), _EnumType_indices, "f").has(writerSymbol)) {
247
+ return writerSymbol;
248
+ }
249
+ else {
250
+ return __classPrivateFieldGet(__classPrivateFieldGet(this, _reader, "f"), _EnumType_default, "f");
251
+ }
252
+ }
207
253
  },
208
254
  _writer_1 = new WeakMap(),
209
255
  _reader = new WeakMap(),
@@ -1,4 +1,5 @@
1
- import { type ReadableTapLike, type WritableTapLike } from "../../serialization/tap.js";
1
+ import type { ReadableTapLike, WritableTapLike } from "../../serialization/tap.js";
2
+ import type { SyncReadableTapLike, SyncWritableTapLike } from "../../serialization/tap_sync.js";
2
3
  import { NamedType } from "./named_type.js";
3
4
  import { Resolver } from "../resolver.js";
4
5
  import type { JSONType, Type } from "../type.js";
@@ -10,6 +11,8 @@ import type { ResolvedNames } from "./resolve_names.js";
10
11
  export interface FixedTypeParams extends ResolvedNames {
11
12
  /** The size in bytes. */
12
13
  size: number;
14
+ /** Whether to validate during writes. Defaults to true. */
15
+ validate?: boolean;
13
16
  }
14
17
  /**
15
18
  * Avro `fixed` type representing a fixed-length byte sequence.
@@ -21,23 +24,18 @@ export declare class FixedType extends NamedType<Uint8Array> {
21
24
  * @param params The fixed type parameters.
22
25
  */
23
26
  constructor(params: FixedTypeParams);
24
- /**
25
- * Gets the size in bytes.
26
- */
27
- sizeBytes(): number;
28
- /**
29
- * Serializes a value into an ArrayBuffer using the exact fixed size.
30
- * @param value The value to serialize.
31
- * @returns The serialized ArrayBuffer.
32
- */
33
- toBuffer(value: Uint8Array): Promise<ArrayBuffer>;
34
27
  /**
35
28
  * Skips a fixed-size value by advancing the tap by the fixed size.
36
29
  * @param tap The tap to skip from.
37
30
  */
38
31
  skip(tap: ReadableTapLike): Promise<void>;
32
+ /**
33
+ * Advances a sync tap past the fixed payload without reading.
34
+ */
35
+ skipSync(tap: SyncReadableTapLike): void;
39
36
  /**
40
37
  * Gets the size in bytes.
38
+ * This is a public method so that it can be called in the resolver.
41
39
  */
42
40
  getSize(): number;
43
41
  /**
@@ -54,12 +52,25 @@ export declare class FixedType extends NamedType<Uint8Array> {
54
52
  * @returns The read byte array.
55
53
  */
56
54
  read(tap: ReadableTapLike): Promise<Uint8Array>;
55
+ /**
56
+ * Reads the fixed bytes synchronously from a tap.
57
+ */
58
+ readSync(tap: SyncReadableTapLike): Uint8Array;
57
59
  /**
58
60
  * Writes a fixed-size byte array to the tap.
59
61
  * @param tap The tap to write to.
60
62
  * @param value The byte array to write.
61
63
  */
62
- write(tap: WritableTapLike, value: Uint8Array): Promise<void>;
64
+ /**
65
+ * Writes fixed bytes without validation.
66
+ */
67
+ writeUnchecked(tap: WritableTapLike, value: Uint8Array): Promise<void>;
68
+ /**
69
+ * Writes fixed bytes without validation synchronously.
70
+ */
71
+ writeSyncUnchecked(tap: SyncWritableTapLike, value: Uint8Array): void;
72
+ /** Returns the fixed byte length. */
73
+ protected byteLength(_value: Uint8Array): number;
63
74
  /**
64
75
  * Matches two fixed-size byte arrays from the taps.
65
76
  * @param tap1 The first tap.
@@ -67,6 +78,10 @@ export declare class FixedType extends NamedType<Uint8Array> {
67
78
  * @returns The comparison result.
68
79
  */
69
80
  match(tap1: ReadableTapLike, tap2: ReadableTapLike): Promise<number>;
81
+ /**
82
+ * Compares two sync taps that decode fixed values.
83
+ */
84
+ matchSync(tap1: SyncReadableTapLike, tap2: SyncReadableTapLike): number;
70
85
  /**
71
86
  * Compares two fixed values for ordering.
72
87
  * @param val1 The first value to compare.
@@ -10,7 +10,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _a, _FixedType_size, _FixedType_fromJsonString;
13
- import { WritableTap, } from "../../serialization/tap.js";
14
13
  import { NamedType } from "./named_type.js";
15
14
  import { Resolver } from "../resolver.js";
16
15
  import { throwInvalidError } from "../error.js";
@@ -28,38 +27,26 @@ export class FixedType extends NamedType {
28
27
  if (!Number.isInteger(size) || size < 1) {
29
28
  throw new Error(`Invalid fixed size: ${size}. Size must be a positive integer.`);
30
29
  }
31
- super(names);
30
+ super(names, params.validate ?? true);
32
31
  _FixedType_size.set(this, void 0);
33
32
  __classPrivateFieldSet(this, _FixedType_size, size, "f");
34
33
  }
35
- /**
36
- * Gets the size in bytes.
37
- */
38
- sizeBytes() {
39
- return __classPrivateFieldGet(this, _FixedType_size, "f");
40
- }
41
- /**
42
- * Serializes a value into an ArrayBuffer using the exact fixed size.
43
- * @param value The value to serialize.
44
- * @returns The serialized ArrayBuffer.
45
- */
46
- async toBuffer(value) {
47
- this.check(value, throwInvalidError, []);
48
- const size = this.sizeBytes();
49
- const buf = new ArrayBuffer(size);
50
- const tap = new WritableTap(buf);
51
- await this.write(tap, value);
52
- return buf;
53
- }
54
34
  /**
55
35
  * Skips a fixed-size value by advancing the tap by the fixed size.
56
36
  * @param tap The tap to skip from.
57
37
  */
58
38
  async skip(tap) {
59
- await tap.skipFixed(this.sizeBytes());
39
+ await tap.skipFixed(__classPrivateFieldGet(this, _FixedType_size, "f"));
40
+ }
41
+ /**
42
+ * Advances a sync tap past the fixed payload without reading.
43
+ */
44
+ skipSync(tap) {
45
+ tap.skipFixed(__classPrivateFieldGet(this, _FixedType_size, "f"));
60
46
  }
61
47
  /**
62
48
  * Gets the size in bytes.
49
+ * This is a public method so that it can be called in the resolver.
63
50
  */
64
51
  getSize() {
65
52
  return __classPrivateFieldGet(this, _FixedType_size, "f");
@@ -86,16 +73,32 @@ export class FixedType extends NamedType {
86
73
  async read(tap) {
87
74
  return await tap.readFixed(__classPrivateFieldGet(this, _FixedType_size, "f"));
88
75
  }
76
+ /**
77
+ * Reads the fixed bytes synchronously from a tap.
78
+ */
79
+ readSync(tap) {
80
+ return tap.readFixed(__classPrivateFieldGet(this, _FixedType_size, "f"));
81
+ }
89
82
  /**
90
83
  * Writes a fixed-size byte array to the tap.
91
84
  * @param tap The tap to write to.
92
85
  * @param value The byte array to write.
93
86
  */
94
- async write(tap, value) {
95
- if (!(value instanceof Uint8Array) || value.length !== __classPrivateFieldGet(this, _FixedType_size, "f")) {
96
- throwInvalidError([], value, this);
97
- }
98
- await tap.writeFixed(value, __classPrivateFieldGet(this, _FixedType_size, "f"));
87
+ /**
88
+ * Writes fixed bytes without validation.
89
+ */
90
+ async writeUnchecked(tap, value) {
91
+ await tap.writeFixed(value);
92
+ }
93
+ /**
94
+ * Writes fixed bytes without validation synchronously.
95
+ */
96
+ writeSyncUnchecked(tap, value) {
97
+ tap.writeFixed(value);
98
+ }
99
+ /** Returns the fixed byte length. */
100
+ byteLength(_value) {
101
+ return __classPrivateFieldGet(this, _FixedType_size, "f");
99
102
  }
100
103
  /**
101
104
  * Matches two fixed-size byte arrays from the taps.
@@ -106,6 +109,12 @@ export class FixedType extends NamedType {
106
109
  async match(tap1, tap2) {
107
110
  return await tap1.matchFixed(tap2, __classPrivateFieldGet(this, _FixedType_size, "f"));
108
111
  }
112
+ /**
113
+ * Compares two sync taps that decode fixed values.
114
+ */
115
+ matchSync(tap1, tap2) {
116
+ return tap1.matchFixed(tap2, __classPrivateFieldGet(this, _FixedType_size, "f"));
117
+ }
109
118
  /**
110
119
  * Compares two fixed values for ordering.
111
120
  * @param val1 The first value to compare.
@@ -205,4 +214,8 @@ class FixedResolver extends Resolver {
205
214
  const reader = this.readerType;
206
215
  return await reader.read(tap);
207
216
  }
217
+ readSync(tap) {
218
+ const reader = this.readerType;
219
+ return reader.readSync(tap);
220
+ }
208
221
  }