@sachitv/avro-typescript 0.4.1 → 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 +2 -2
  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
@@ -11,8 +11,8 @@ export class DateLogicalType extends LogicalType {
11
11
  * Creates a new DateLogicalType.
12
12
  * @param underlying The underlying int type.
13
13
  */
14
- constructor(underlying) {
15
- super(underlying);
14
+ constructor(underlying, validate = true) {
15
+ super(underlying, validate);
16
16
  }
17
17
  /** Checks if the logical type can read from the underlying type. */
18
18
  canReadFromLogical(writer) {
@@ -50,8 +50,8 @@ export class TimeMillisLogicalType extends LogicalType {
50
50
  * Creates a new TimeMillisLogicalType.
51
51
  * @param underlying The underlying int type.
52
52
  */
53
- constructor(underlying) {
54
- super(underlying);
53
+ constructor(underlying, validate = true) {
54
+ super(underlying, validate);
55
55
  }
56
56
  /** Checks if the logical type can read from the underlying type. */
57
57
  canReadFromLogical(writer) {
@@ -88,8 +88,8 @@ export class TimeMicrosLogicalType extends LogicalType {
88
88
  * Creates a new TimeMicrosLogicalType.
89
89
  * @param underlying The underlying long type.
90
90
  */
91
- constructor(underlying) {
92
- super(underlying);
91
+ constructor(underlying, validate = true) {
92
+ super(underlying, validate);
93
93
  }
94
94
  /** Checks if the logical type can read from the underlying type. */
95
95
  canReadFromLogical(writer) {
@@ -126,8 +126,8 @@ export class TimestampMillisLogicalType extends LogicalType {
126
126
  * Creates a new TimestampMillisLogicalType.
127
127
  * @param underlying The underlying long type.
128
128
  */
129
- constructor(underlying) {
130
- super(underlying);
129
+ constructor(underlying, validate = true) {
130
+ super(underlying, validate);
131
131
  }
132
132
  /** Checks if the logical type can read from the underlying type. */
133
133
  canReadFromLogical(writer) {
@@ -175,8 +175,8 @@ export class TimestampMicrosLogicalType extends LogicalType {
175
175
  * Creates a new TimestampMicrosLogicalType.
176
176
  * @param underlying The underlying long type.
177
177
  */
178
- constructor(underlying) {
179
- super(underlying);
178
+ constructor(underlying, validate = true) {
179
+ super(underlying, validate);
180
180
  }
181
181
  /** Checks if the logical type can read from the underlying type. */
182
182
  canReadFromLogical(writer) {
@@ -214,8 +214,8 @@ export class TimestampNanosLogicalType extends LogicalType {
214
214
  * Creates a new TimestampNanosLogicalType.
215
215
  * @param underlying The underlying long type.
216
216
  */
217
- constructor(underlying) {
218
- super(underlying);
217
+ constructor(underlying, validate = true) {
218
+ super(underlying, validate);
219
219
  }
220
220
  /** Checks if the logical type can read from the underlying type. */
221
221
  canReadFromLogical(writer) {
@@ -253,8 +253,8 @@ export class LocalTimestampMillisLogicalType extends LogicalType {
253
253
  * Creates a new LocalTimestampMillisLogicalType.
254
254
  * @param underlying The underlying long type.
255
255
  */
256
- constructor(underlying) {
257
- super(underlying);
256
+ constructor(underlying, validate = true) {
257
+ super(underlying, validate);
258
258
  }
259
259
  /** Checks if the logical type can read from the underlying type. */
260
260
  canReadFromLogical(writer) {
@@ -293,8 +293,8 @@ export class LocalTimestampMicrosLogicalType extends LogicalType {
293
293
  * Creates a new LocalTimestampMicrosLogicalType.
294
294
  * @param underlying The underlying long type.
295
295
  */
296
- constructor(underlying) {
297
- super(underlying);
296
+ constructor(underlying, validate = true) {
297
+ super(underlying, validate);
298
298
  }
299
299
  /** Checks if the logical type can read from the underlying type. */
300
300
  canReadFromLogical(writer) {
@@ -332,8 +332,8 @@ export class LocalTimestampNanosLogicalType extends LogicalType {
332
332
  * Creates a new LocalTimestampNanosLogicalType.
333
333
  * @param underlying The underlying long type.
334
334
  */
335
- constructor(underlying) {
336
- super(underlying);
335
+ constructor(underlying, validate = true) {
336
+ super(underlying, validate);
337
337
  }
338
338
  /** Checks if the logical type can read from the underlying type. */
339
339
  canReadFromLogical(writer) {
@@ -12,7 +12,7 @@ export declare class UuidLogicalType extends LogicalType<string, string | Uint8A
12
12
  * Creates a UUID logical type backed by the given underlying type.
13
13
  * @param underlying The underlying StringType or FixedType.
14
14
  */
15
- constructor(underlying: StringType | FixedType);
15
+ constructor(underlying: StringType | FixedType, validate?: boolean);
16
16
  /**
17
17
  * Checks if this UUID logical type can read from the given writer logical type.
18
18
  * @param writer The writer logical type.
@@ -24,8 +24,8 @@ export class UuidLogicalType extends LogicalType {
24
24
  * Creates a UUID logical type backed by the given underlying type.
25
25
  * @param underlying The underlying StringType or FixedType.
26
26
  */
27
- constructor(underlying) {
28
- super(underlying);
27
+ constructor(underlying, validate = true) {
28
+ super(underlying, validate);
29
29
  _UuidLogicalType_underlying.set(this, void 0);
30
30
  _UuidLogicalType_named.set(this, void 0);
31
31
  __classPrivateFieldSet(this, _UuidLogicalType_underlying, underlying, "f");
@@ -1,4 +1,5 @@
1
1
  import type { ReadableTapLike, WritableTapLike } from "../../serialization/tap.js";
2
+ import type { SyncReadableTapLike, SyncWritableTapLike } from "../../serialization/tap_sync.js";
2
3
  import { FixedSizeBaseType } from "./fixed_size_base_type.js";
3
4
  import type { JSONType } from "../type.js";
4
5
  import { type ErrorHook } from "../error.js";
@@ -6,6 +7,8 @@ import { type ErrorHook } from "../error.js";
6
7
  * Boolean type.
7
8
  */
8
9
  export declare class BooleanType extends FixedSizeBaseType<boolean> {
10
+ /** Creates a new boolean type. */
11
+ constructor(validate?: boolean);
9
12
  /**
10
13
  * Validates if the value is a boolean.
11
14
  */
@@ -14,10 +17,8 @@ export declare class BooleanType extends FixedSizeBaseType<boolean> {
14
17
  * Reads a boolean value from the tap.
15
18
  */
16
19
  read(tap: ReadableTapLike): Promise<boolean>;
17
- /**
18
- * Writes a boolean value to the tap.
19
- */
20
- write(tap: WritableTapLike, value: boolean): Promise<void>;
20
+ /** Writes a boolean value to the tap without validation. */
21
+ writeUnchecked(tap: WritableTapLike, value: boolean): Promise<void>;
21
22
  /**
22
23
  * Skips a boolean value in the tap.
23
24
  */
@@ -46,4 +47,14 @@ export declare class BooleanType extends FixedSizeBaseType<boolean> {
46
47
  * Matches two boolean values from the taps.
47
48
  */
48
49
  match(tap1: ReadableTapLike, tap2: ReadableTapLike): Promise<number>;
50
+ /**
51
+ * Reads a boolean value synchronously from the tap.
52
+ */
53
+ readSync(tap: SyncReadableTapLike): boolean;
54
+ /** Writes a boolean value synchronously to the tap without validation. */
55
+ writeSyncUnchecked(tap: SyncWritableTapLike, value: boolean): void;
56
+ /**
57
+ * Matches two boolean values synchronously from the taps.
58
+ */
59
+ matchSync(tap1: SyncReadableTapLike, tap2: SyncReadableTapLike): number;
49
60
  }
@@ -4,6 +4,10 @@ import { throwInvalidError } from "../error.js";
4
4
  * Boolean type.
5
5
  */
6
6
  export class BooleanType extends FixedSizeBaseType {
7
+ /** Creates a new boolean type. */
8
+ constructor(validate = true) {
9
+ super(validate);
10
+ }
7
11
  /**
8
12
  * Validates if the value is a boolean.
9
13
  */
@@ -20,13 +24,8 @@ export class BooleanType extends FixedSizeBaseType {
20
24
  async read(tap) {
21
25
  return await tap.readBoolean();
22
26
  }
23
- /**
24
- * Writes a boolean value to the tap.
25
- */
26
- async write(tap, value) {
27
- if (typeof value !== "boolean") {
28
- throwInvalidError([], value, this);
29
- }
27
+ /** Writes a boolean value to the tap without validation. */
28
+ async writeUnchecked(tap, value) {
30
29
  await tap.writeBoolean(value);
31
30
  }
32
31
  /**
@@ -72,4 +71,20 @@ export class BooleanType extends FixedSizeBaseType {
72
71
  async match(tap1, tap2) {
73
72
  return await tap1.matchBoolean(tap2);
74
73
  }
74
+ /**
75
+ * Reads a boolean value synchronously from the tap.
76
+ */
77
+ readSync(tap) {
78
+ return tap.readBoolean();
79
+ }
80
+ /** Writes a boolean value synchronously to the tap without validation. */
81
+ writeSyncUnchecked(tap, value) {
82
+ tap.writeBoolean(value);
83
+ }
84
+ /**
85
+ * Matches two boolean values synchronously from the taps.
86
+ */
87
+ matchSync(tap1, tap2) {
88
+ return tap1.matchBoolean(tap2);
89
+ }
75
90
  }
@@ -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 { PrimitiveType } from "./primitive_type.js";
3
4
  import type { JSONType, Type } from "../type.js";
4
5
  import { Resolver } from "../resolver.js";
@@ -8,6 +9,8 @@ import { type ErrorHook } from "../error.js";
8
9
  */
9
10
  export declare class BytesType extends PrimitiveType<Uint8Array> {
10
11
  #private;
12
+ /** Creates a new bytes type. */
13
+ constructor(validate?: boolean);
11
14
  /** Checks if the value is a valid bytes array. */
12
15
  check(value: unknown, errorHook?: ErrorHook, path?: string[]): boolean;
13
16
  /**
@@ -15,17 +18,23 @@ export declare class BytesType extends PrimitiveType<Uint8Array> {
15
18
  */
16
19
  read(tap: ReadableTapLike): Promise<Uint8Array>;
17
20
  /**
18
- * Writes a byte array to the tap.
21
+ * Reads a byte array from the sync tap.
19
22
  */
20
- write(tap: WritableTapLike, value: Uint8Array): Promise<void>;
23
+ readSync(tap: SyncReadableTapLike): Uint8Array;
24
+ /** Writes a byte array to the tap without validation. */
25
+ writeUnchecked(tap: WritableTapLike, value: Uint8Array): Promise<void>;
26
+ /** Returns the encoded byte length of the given value. */
27
+ protected byteLength(value: Uint8Array): number;
28
+ /** Writes a byte array synchronously to the tap without validation. */
29
+ writeSyncUnchecked(tap: SyncWritableTapLike, value: Uint8Array): void;
21
30
  /**
22
31
  * Skips a byte array in the tap.
23
32
  */
24
33
  skip(tap: ReadableTapLike): Promise<void>;
25
34
  /**
26
- * Converts a byte array to an ArrayBuffer.
35
+ * Skips a byte array in the sync tap.
27
36
  */
28
- toBuffer(value: Uint8Array): Promise<ArrayBuffer>;
37
+ skipSync(tap: SyncReadableTapLike): void;
29
38
  /**
30
39
  * Creates a resolver for the writer type.
31
40
  */
@@ -46,4 +55,6 @@ export declare class BytesType extends PrimitiveType<Uint8Array> {
46
55
  toJSON(): JSONType;
47
56
  /** Matches bytes between two taps. */
48
57
  match(tap1: ReadableTapLike, tap2: ReadableTapLike): Promise<number>;
58
+ /** Matches bytes between two sync taps. */
59
+ matchSync(tap1: SyncReadableTapLike, tap2: SyncReadableTapLike): number;
49
60
  }
@@ -4,7 +4,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
6
  var _a, _BytesType_fromJsonString;
7
- import { WritableTap, } from "../../serialization/tap.js";
8
7
  import { PrimitiveType } from "./primitive_type.js";
9
8
  import { Resolver } from "../resolver.js";
10
9
  import { throwInvalidError } from "../error.js";
@@ -13,6 +12,10 @@ import { calculateVarintSize } from "../../internal/varint.js";
13
12
  * Bytes type.
14
13
  */
15
14
  export class BytesType extends PrimitiveType {
15
+ /** Creates a new bytes type. */
16
+ constructor(validate = true) {
17
+ super(validate);
18
+ }
16
19
  /** Checks if the value is a valid bytes array. */
17
20
  check(value, errorHook, path = []) {
18
21
  const isValid = value instanceof Uint8Array;
@@ -28,14 +31,23 @@ export class BytesType extends PrimitiveType {
28
31
  return await tap.readBytes();
29
32
  }
30
33
  /**
31
- * Writes a byte array to the tap.
34
+ * Reads a byte array from the sync tap.
32
35
  */
33
- async write(tap, value) {
34
- if (!(value instanceof Uint8Array)) {
35
- throwInvalidError([], value, this);
36
- }
36
+ readSync(tap) {
37
+ return tap.readBytes();
38
+ }
39
+ /** Writes a byte array to the tap without validation. */
40
+ async writeUnchecked(tap, value) {
37
41
  await tap.writeBytes(value);
38
42
  }
43
+ /** Returns the encoded byte length of the given value. */
44
+ byteLength(value) {
45
+ return calculateVarintSize(value.length) + value.length;
46
+ }
47
+ /** Writes a byte array synchronously to the tap without validation. */
48
+ writeSyncUnchecked(tap, value) {
49
+ tap.writeBytes(value);
50
+ }
39
51
  /**
40
52
  * Skips a byte array in the tap.
41
53
  */
@@ -43,17 +55,10 @@ export class BytesType extends PrimitiveType {
43
55
  await tap.skipBytes();
44
56
  }
45
57
  /**
46
- * Converts a byte array to an ArrayBuffer.
58
+ * Skips a byte array in the sync tap.
47
59
  */
48
- async toBuffer(value) {
49
- this.check(value, throwInvalidError, []);
50
- // Pre-allocate buffer based on value length for efficiency
51
- const lengthSize = calculateVarintSize(value.length);
52
- const totalSize = lengthSize + value.length;
53
- const buf = new ArrayBuffer(totalSize);
54
- const tap = new WritableTap(buf);
55
- await this.write(tap, value);
56
- return buf;
60
+ skipSync(tap) {
61
+ tap.skipBytes();
57
62
  }
58
63
  /**
59
64
  * Creates a resolver for the writer type.
@@ -69,6 +74,12 @@ export class BytesType extends PrimitiveType {
69
74
  const encoder = new TextEncoder();
70
75
  return encoder.encode(str);
71
76
  }
77
+ readSync(tap) {
78
+ const str = tap.readString();
79
+ // Convert string to bytes (assuming UTF-8)
80
+ const encoder = new TextEncoder();
81
+ return encoder.encode(str);
82
+ }
72
83
  }(this);
73
84
  }
74
85
  else {
@@ -126,6 +137,10 @@ export class BytesType extends PrimitiveType {
126
137
  async match(tap1, tap2) {
127
138
  return await tap1.matchBytes(tap2);
128
139
  }
140
+ /** Matches bytes between two sync taps. */
141
+ matchSync(tap1, tap2) {
142
+ return tap1.matchBytes(tap2);
143
+ }
129
144
  }
130
145
  _a = BytesType, _BytesType_fromJsonString = function _BytesType_fromJsonString(value) {
131
146
  const bytes = new Uint8Array(value.length);
@@ -1,4 +1,5 @@
1
1
  import type { ReadableTapLike, WritableTapLike } from "../../serialization/tap.js";
2
+ import type { SyncReadableTapLike, SyncWritableTapLike } from "../../serialization/tap_sync.js";
2
3
  import { FixedSizeBaseType } from "./fixed_size_base_type.js";
3
4
  import type { JSONType, Type } from "../type.js";
4
5
  import { Resolver } from "../resolver.js";
@@ -7,14 +8,24 @@ import { type ErrorHook } from "../error.js";
7
8
  * Double type (64-bit).
8
9
  */
9
10
  export declare class DoubleType extends FixedSizeBaseType<number> {
11
+ /** Creates a new double type. */
12
+ constructor(validate?: boolean);
10
13
  /** Checks if the value is a valid double. */
11
14
  check(value: unknown, errorHook?: ErrorHook, path?: string[]): boolean;
12
15
  /** Reads a double value from the tap. */
13
16
  read(tap: ReadableTapLike): Promise<number>;
14
- /** Writes a double value to the tap. */
15
- write(tap: WritableTapLike, value: number): Promise<void>;
17
+ /** Writes a double value to the tap without validation. */
18
+ writeUnchecked(tap: WritableTapLike, value: number): Promise<void>;
16
19
  /** Skips a double value in the tap. */
17
20
  skip(tap: ReadableTapLike): Promise<void>;
21
+ /** Reads a double value from the sync tap. */
22
+ readSync(tap: SyncReadableTapLike): number;
23
+ /** Writes a double value synchronously to the tap without validation. */
24
+ writeSyncUnchecked(tap: SyncWritableTapLike, value: number): void;
25
+ /** Skips a double value in the sync tap. */
26
+ skipSync(tap: SyncReadableTapLike): void;
27
+ /** Matches two sync taps for equality. */
28
+ matchSync(tap1: SyncReadableTapLike, tap2: SyncReadableTapLike): number;
18
29
  /**
19
30
  * Gets the size in bytes.
20
31
  */
@@ -8,6 +8,10 @@ import { throwInvalidError } from "../error.js";
8
8
  * Double type (64-bit).
9
9
  */
10
10
  export class DoubleType extends FixedSizeBaseType {
11
+ /** Creates a new double type. */
12
+ constructor(validate = true) {
13
+ super(validate);
14
+ }
11
15
  /** Checks if the value is a valid double. */
12
16
  check(value, errorHook, path = []) {
13
17
  const isValid = typeof value === "number";
@@ -20,17 +24,30 @@ export class DoubleType extends FixedSizeBaseType {
20
24
  async read(tap) {
21
25
  return await tap.readDouble();
22
26
  }
23
- /** Writes a double value to the tap. */
24
- async write(tap, value) {
25
- if (!this.check(value)) {
26
- throwInvalidError([], value, this);
27
- }
27
+ /** Writes a double value to the tap without validation. */
28
+ async writeUnchecked(tap, value) {
28
29
  await tap.writeDouble(value);
29
30
  }
30
31
  /** Skips a double value in the tap. */
31
32
  async skip(tap) {
32
33
  await tap.skipDouble();
33
34
  }
35
+ /** Reads a double value from the sync tap. */
36
+ readSync(tap) {
37
+ return tap.readDouble();
38
+ }
39
+ /** Writes a double value synchronously to the tap without validation. */
40
+ writeSyncUnchecked(tap, value) {
41
+ tap.writeDouble(value);
42
+ }
43
+ /** Skips a double value in the sync tap. */
44
+ skipSync(tap) {
45
+ tap.skipDouble();
46
+ }
47
+ /** Matches two sync taps for equality. */
48
+ matchSync(tap1, tap2) {
49
+ return tap1.matchDouble(tap2);
50
+ }
34
51
  /**
35
52
  * Gets the size in bytes.
36
53
  */
@@ -63,6 +80,10 @@ export class DoubleType extends FixedSizeBaseType {
63
80
  const intValue = await tap.readInt();
64
81
  return intValue;
65
82
  }
83
+ readSync(tap) {
84
+ const intValue = tap.readInt();
85
+ return intValue;
86
+ }
66
87
  }(this);
67
88
  }
68
89
  else if (writerType instanceof LongType) {
@@ -72,6 +93,10 @@ export class DoubleType extends FixedSizeBaseType {
72
93
  const longValue = await tap.readLong();
73
94
  return Number(longValue);
74
95
  }
96
+ readSync(tap) {
97
+ const longValue = tap.readLong();
98
+ return Number(longValue);
99
+ }
75
100
  }(this);
76
101
  }
77
102
  else if (writerType instanceof FloatType) {
@@ -81,6 +106,10 @@ export class DoubleType extends FixedSizeBaseType {
81
106
  const floatValue = await tap.readFloat();
82
107
  return floatValue;
83
108
  }
109
+ readSync(tap) {
110
+ const floatValue = tap.readFloat();
111
+ return floatValue;
112
+ }
84
113
  }(this);
85
114
  }
86
115
  else {
@@ -1,4 +1,5 @@
1
- import { type ReadableTapLike } from "../../serialization/tap.js";
1
+ import type { ReadableTapLike } from "../../serialization/tap.js";
2
+ import type { SyncReadableTapLike } from "../../serialization/tap_sync.js";
2
3
  import { BaseType } from "../base_type.js";
3
4
  /**
4
5
  * Base class for fixed-size Avro types.
@@ -9,20 +10,23 @@ import { BaseType } from "../base_type.js";
9
10
  * Provides optimized serialization for types with known fixed byte sizes.
10
11
  */
11
12
  export declare abstract class FixedSizeBaseType<T = unknown> extends BaseType<T> {
13
+ /** Creates a new fixed-size base type. */
14
+ constructor(validate?: boolean);
12
15
  /**
13
16
  * Returns the fixed size in bytes for this type.
14
17
  * @returns The exact size in bytes.
15
18
  */
16
19
  abstract sizeBytes(): number;
17
- /**
18
- * Serializes a value into an ArrayBuffer using the exact fixed size.
19
- * @param value The value to serialize.
20
- * @returns The serialized ArrayBuffer.
21
- */
22
- toBuffer(value: T): Promise<ArrayBuffer>;
20
+ /** Returns the fixed byte length for any value of this type. */
21
+ protected byteLength(_value: T): number;
23
22
  /**
24
23
  * Skips a fixed-size value by advancing the tap by the fixed size.
25
24
  * @param tap The tap to skip from.
26
25
  */
27
26
  skip(tap: ReadableTapLike): Promise<void>;
27
+ /**
28
+ * Skips a fixed-size value synchronously by advancing the tap by the fixed size.
29
+ * @param tap The sync tap to skip from.
30
+ */
31
+ skipSync(tap: SyncReadableTapLike): void;
28
32
  }
@@ -1,6 +1,4 @@
1
- import { WritableTap } from "../../serialization/tap.js";
2
1
  import { BaseType } from "../base_type.js";
3
- import { throwInvalidError } from "../error.js";
4
2
  /**
5
3
  * Base class for fixed-size Avro types.
6
4
  * Provides optimized serialization for types with known fixed byte sizes.
@@ -10,18 +8,13 @@ import { throwInvalidError } from "../error.js";
10
8
  * Provides optimized serialization for types with known fixed byte sizes.
11
9
  */
12
10
  export class FixedSizeBaseType extends BaseType {
13
- /**
14
- * Serializes a value into an ArrayBuffer using the exact fixed size.
15
- * @param value The value to serialize.
16
- * @returns The serialized ArrayBuffer.
17
- */
18
- async toBuffer(value) {
19
- this.check(value, throwInvalidError, []);
20
- const size = this.sizeBytes();
21
- const buf = new ArrayBuffer(size);
22
- const tap = new WritableTap(buf);
23
- await this.write(tap, value);
24
- return buf;
11
+ /** Creates a new fixed-size base type. */
12
+ constructor(validate = true) {
13
+ super(validate);
14
+ }
15
+ /** Returns the fixed byte length for any value of this type. */
16
+ byteLength(_value) {
17
+ return this.sizeBytes();
25
18
  }
26
19
  /**
27
20
  * Skips a fixed-size value by advancing the tap by the fixed size.
@@ -30,4 +23,11 @@ export class FixedSizeBaseType extends BaseType {
30
23
  async skip(tap) {
31
24
  await tap.skipFixed(this.sizeBytes());
32
25
  }
26
+ /**
27
+ * Skips a fixed-size value synchronously by advancing the tap by the fixed size.
28
+ * @param tap The sync tap to skip from.
29
+ */
30
+ skipSync(tap) {
31
+ tap.skipFixed(this.sizeBytes());
32
+ }
33
33
  }
@@ -1,4 +1,5 @@
1
1
  import type { ReadableTapLike, WritableTapLike } from "../../serialization/tap.js";
2
+ import type { SyncReadableTapLike, SyncWritableTapLike } from "../../serialization/tap_sync.js";
2
3
  import { FixedSizeBaseType } from "./fixed_size_base_type.js";
3
4
  import type { JSONType, Type } from "../type.js";
4
5
  import { Resolver } from "../resolver.js";
@@ -7,12 +8,18 @@ import { type ErrorHook } from "../error.js";
7
8
  * Float type (32-bit).
8
9
  */
9
10
  export declare class FloatType extends FixedSizeBaseType<number> {
11
+ /** Creates a new float type. */
12
+ constructor(validate?: boolean);
10
13
  /** Checks if the value is a valid float. */
11
14
  check(value: unknown, errorHook?: ErrorHook, path?: string[]): boolean;
12
15
  /** Reads a float value from the tap. */
13
16
  read(tap: ReadableTapLike): Promise<number>;
14
- /** Writes a float value to the tap. */
15
- write(tap: WritableTapLike, value: number): Promise<void>;
17
+ /** Reads a float value from the sync tap. */
18
+ readSync(tap: SyncReadableTapLike): number;
19
+ /** Writes a float value to the tap without validation. */
20
+ writeUnchecked(tap: WritableTapLike, value: number): Promise<void>;
21
+ /** Writes a float value synchronously to the tap without validation. */
22
+ writeSyncUnchecked(tap: SyncWritableTapLike, value: number): void;
16
23
  /** Skips a float value in the tap. */
17
24
  skip(tap: ReadableTapLike): Promise<void>;
18
25
  /**
@@ -35,4 +42,6 @@ export declare class FloatType extends FixedSizeBaseType<number> {
35
42
  toJSON(): JSONType;
36
43
  /** Matches float values between taps. */
37
44
  match(tap1: ReadableTapLike, tap2: ReadableTapLike): Promise<number>;
45
+ /** Matches float values between sync taps. */
46
+ matchSync(tap1: SyncReadableTapLike, tap2: SyncReadableTapLike): number;
38
47
  }
@@ -7,6 +7,10 @@ import { throwInvalidError } from "../error.js";
7
7
  * Float type (32-bit).
8
8
  */
9
9
  export class FloatType extends FixedSizeBaseType {
10
+ /** Creates a new float type. */
11
+ constructor(validate = true) {
12
+ super(validate);
13
+ }
10
14
  /** Checks if the value is a valid float. */
11
15
  check(value, errorHook, path = []) {
12
16
  const isValid = typeof value === "number";
@@ -19,13 +23,18 @@ export class FloatType extends FixedSizeBaseType {
19
23
  async read(tap) {
20
24
  return await tap.readFloat();
21
25
  }
22
- /** Writes a float value to the tap. */
23
- async write(tap, value) {
24
- if (!this.check(value)) {
25
- throwInvalidError([], value, this);
26
- }
26
+ /** Reads a float value from the sync tap. */
27
+ readSync(tap) {
28
+ return tap.readFloat();
29
+ }
30
+ /** Writes a float value to the tap without validation. */
31
+ async writeUnchecked(tap, value) {
27
32
  await tap.writeFloat(value);
28
33
  }
34
+ /** Writes a float value synchronously to the tap without validation. */
35
+ writeSyncUnchecked(tap, value) {
36
+ tap.writeFloat(value);
37
+ }
29
38
  /** Skips a float value in the tap. */
30
39
  async skip(tap) {
31
40
  await tap.skipFloat();
@@ -62,6 +71,10 @@ export class FloatType extends FixedSizeBaseType {
62
71
  const intValue = await tap.readInt();
63
72
  return intValue;
64
73
  }
74
+ readSync(tap) {
75
+ const intValue = tap.readInt();
76
+ return intValue;
77
+ }
65
78
  }(this);
66
79
  }
67
80
  else if (writerType instanceof LongType) {
@@ -71,6 +84,10 @@ export class FloatType extends FixedSizeBaseType {
71
84
  const longValue = await tap.readLong();
72
85
  return Number(longValue);
73
86
  }
87
+ readSync(tap) {
88
+ const longValue = tap.readLong();
89
+ return Number(longValue);
90
+ }
74
91
  }(this);
75
92
  }
76
93
  else {
@@ -85,4 +102,8 @@ export class FloatType extends FixedSizeBaseType {
85
102
  async match(tap1, tap2) {
86
103
  return await tap1.matchFloat(tap2);
87
104
  }
105
+ /** Matches float values between sync taps. */
106
+ matchSync(tap1, tap2) {
107
+ return tap1.matchFloat(tap2);
108
+ }
88
109
  }