@sachitv/avro-typescript 0.4.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 (163) hide show
  1. package/esm/_dnt.polyfills.d.ts +11 -0
  2. package/esm/_dnt.polyfills.js +15 -0
  3. package/esm/avro_reader.d.ts +156 -0
  4. package/esm/avro_reader.js +201 -0
  5. package/esm/avro_writer.d.ts +75 -0
  6. package/esm/avro_writer.js +105 -0
  7. package/esm/internal/collections/array_utils.d.ts +4 -0
  8. package/esm/internal/collections/array_utils.js +18 -0
  9. package/esm/internal/collections/circular_buffer.d.ts +48 -0
  10. package/esm/internal/collections/circular_buffer.js +129 -0
  11. package/esm/internal/crypto/md5.d.ts +12 -0
  12. package/esm/internal/crypto/md5.js +158 -0
  13. package/esm/internal/varint.d.ts +6 -0
  14. package/esm/internal/varint.js +30 -0
  15. package/esm/mod.d.ts +77 -0
  16. package/esm/mod.js +73 -0
  17. package/esm/package.json +3 -0
  18. package/esm/rpc/definitions/message_definition.d.ts +34 -0
  19. package/esm/rpc/definitions/message_definition.js +105 -0
  20. package/esm/rpc/definitions/protocol_definitions.d.ts +197 -0
  21. package/esm/rpc/definitions/protocol_definitions.js +1 -0
  22. package/esm/rpc/message_endpoint/base.d.ts +43 -0
  23. package/esm/rpc/message_endpoint/base.js +81 -0
  24. package/esm/rpc/message_endpoint/emitter.d.ts +96 -0
  25. package/esm/rpc/message_endpoint/emitter.js +245 -0
  26. package/esm/rpc/message_endpoint/helpers.d.ts +37 -0
  27. package/esm/rpc/message_endpoint/helpers.js +68 -0
  28. package/esm/rpc/message_endpoint/listener.d.ts +37 -0
  29. package/esm/rpc/message_endpoint/listener.js +212 -0
  30. package/esm/rpc/protocol/frame_assembler.d.ts +11 -0
  31. package/esm/rpc/protocol/frame_assembler.js +77 -0
  32. package/esm/rpc/protocol/protocol_helpers.d.ts +59 -0
  33. package/esm/rpc/protocol/protocol_helpers.js +123 -0
  34. package/esm/rpc/protocol/transports/fetch.d.ts +9 -0
  35. package/esm/rpc/protocol/transports/fetch.js +30 -0
  36. package/esm/rpc/protocol/transports/in_memory.d.ts +27 -0
  37. package/esm/rpc/protocol/transports/in_memory.js +125 -0
  38. package/esm/rpc/protocol/transports/transport_helpers.d.ts +118 -0
  39. package/esm/rpc/protocol/transports/transport_helpers.js +112 -0
  40. package/esm/rpc/protocol/transports/websocket.d.ts +9 -0
  41. package/esm/rpc/protocol/transports/websocket.js +102 -0
  42. package/esm/rpc/protocol/wire_format/framing.d.ts +44 -0
  43. package/esm/rpc/protocol/wire_format/framing.js +74 -0
  44. package/esm/rpc/protocol/wire_format/handshake.d.ts +110 -0
  45. package/esm/rpc/protocol/wire_format/handshake.js +239 -0
  46. package/esm/rpc/protocol/wire_format/messages.d.ts +192 -0
  47. package/esm/rpc/protocol/wire_format/messages.js +175 -0
  48. package/esm/rpc/protocol/wire_format/metadata.d.ts +44 -0
  49. package/esm/rpc/protocol/wire_format/metadata.js +74 -0
  50. package/esm/rpc/protocol_core.d.ts +121 -0
  51. package/esm/rpc/protocol_core.js +285 -0
  52. package/esm/schemas/base_type.d.ts +41 -0
  53. package/esm/schemas/base_type.js +49 -0
  54. package/esm/schemas/complex/array_type.d.ts +100 -0
  55. package/esm/schemas/complex/array_type.js +299 -0
  56. package/esm/schemas/complex/enum_type.d.ts +81 -0
  57. package/esm/schemas/complex/enum_type.js +217 -0
  58. package/esm/schemas/complex/fixed_type.d.ts +99 -0
  59. package/esm/schemas/complex/fixed_type.js +208 -0
  60. package/esm/schemas/complex/map_type.d.ts +97 -0
  61. package/esm/schemas/complex/map_type.js +290 -0
  62. package/esm/schemas/complex/named_type.d.ts +30 -0
  63. package/esm/schemas/complex/named_type.js +57 -0
  64. package/esm/schemas/complex/record_type.d.ts +165 -0
  65. package/esm/schemas/complex/record_type.js +547 -0
  66. package/esm/schemas/complex/resolve_names.d.ts +32 -0
  67. package/esm/schemas/complex/resolve_names.js +85 -0
  68. package/esm/schemas/complex/union_type.d.ts +116 -0
  69. package/esm/schemas/complex/union_type.js +392 -0
  70. package/esm/schemas/error.d.ts +31 -0
  71. package/esm/schemas/error.js +67 -0
  72. package/esm/schemas/json.d.ts +6 -0
  73. package/esm/schemas/json.js +35 -0
  74. package/esm/schemas/logical/decimal_logical_type.d.ts +49 -0
  75. package/esm/schemas/logical/decimal_logical_type.js +145 -0
  76. package/esm/schemas/logical/duration_logical_type.d.ts +66 -0
  77. package/esm/schemas/logical/duration_logical_type.js +112 -0
  78. package/esm/schemas/logical/logical_type.d.ts +138 -0
  79. package/esm/schemas/logical/logical_type.js +240 -0
  80. package/esm/schemas/logical/temporal_logical_types.d.ts +215 -0
  81. package/esm/schemas/logical/temporal_logical_types.js +364 -0
  82. package/esm/schemas/logical/uuid_logical_type.d.ts +63 -0
  83. package/esm/schemas/logical/uuid_logical_type.js +146 -0
  84. package/esm/schemas/primitive/boolean_type.d.ts +49 -0
  85. package/esm/schemas/primitive/boolean_type.js +75 -0
  86. package/esm/schemas/primitive/bytes_type.d.ts +49 -0
  87. package/esm/schemas/primitive/bytes_type.js +136 -0
  88. package/esm/schemas/primitive/double_type.d.ts +38 -0
  89. package/esm/schemas/primitive/double_type.js +98 -0
  90. package/esm/schemas/primitive/fixed_size_base_type.d.ts +28 -0
  91. package/esm/schemas/primitive/fixed_size_base_type.js +33 -0
  92. package/esm/schemas/primitive/float_type.d.ts +38 -0
  93. package/esm/schemas/primitive/float_type.js +88 -0
  94. package/esm/schemas/primitive/int_type.d.ts +31 -0
  95. package/esm/schemas/primitive/int_type.js +63 -0
  96. package/esm/schemas/primitive/long_type.d.ts +36 -0
  97. package/esm/schemas/primitive/long_type.js +95 -0
  98. package/esm/schemas/primitive/null_type.d.ts +45 -0
  99. package/esm/schemas/primitive/null_type.js +71 -0
  100. package/esm/schemas/primitive/primitive_type.d.ts +17 -0
  101. package/esm/schemas/primitive/primitive_type.js +27 -0
  102. package/esm/schemas/primitive/string_type.d.ts +34 -0
  103. package/esm/schemas/primitive/string_type.js +81 -0
  104. package/esm/schemas/resolver.d.ts +25 -0
  105. package/esm/schemas/resolver.js +25 -0
  106. package/esm/schemas/type.d.ts +101 -0
  107. package/esm/schemas/type.js +6 -0
  108. package/esm/serialization/avro_constants.d.ts +13 -0
  109. package/esm/serialization/avro_constants.js +29 -0
  110. package/esm/serialization/avro_file_parser.d.ts +68 -0
  111. package/esm/serialization/avro_file_parser.js +191 -0
  112. package/esm/serialization/avro_file_writer.d.ts +63 -0
  113. package/esm/serialization/avro_file_writer.js +235 -0
  114. package/esm/serialization/buffers/blob_readable_buffer.d.ts +53 -0
  115. package/esm/serialization/buffers/blob_readable_buffer.js +80 -0
  116. package/esm/serialization/buffers/buffer.d.ts +37 -0
  117. package/esm/serialization/buffers/buffer.js +1 -0
  118. package/esm/serialization/buffers/in_memory_buffer.d.ts +121 -0
  119. package/esm/serialization/buffers/in_memory_buffer.js +206 -0
  120. package/esm/serialization/clamp.d.ts +10 -0
  121. package/esm/serialization/clamp.js +19 -0
  122. package/esm/serialization/compare_bytes.d.ts +9 -0
  123. package/esm/serialization/compare_bytes.js +45 -0
  124. package/esm/serialization/conversion.d.ts +8 -0
  125. package/esm/serialization/conversion.js +15 -0
  126. package/esm/serialization/decoders/decoder.d.ts +16 -0
  127. package/esm/serialization/decoders/decoder.js +1 -0
  128. package/esm/serialization/decoders/deflate_decoder.d.ts +15 -0
  129. package/esm/serialization/decoders/deflate_decoder.js +26 -0
  130. package/esm/serialization/decoders/null_decoder.d.ts +12 -0
  131. package/esm/serialization/decoders/null_decoder.js +13 -0
  132. package/esm/serialization/encoders/deflate_encoder.d.ts +15 -0
  133. package/esm/serialization/encoders/deflate_encoder.js +26 -0
  134. package/esm/serialization/encoders/encoder.d.ts +16 -0
  135. package/esm/serialization/encoders/encoder.js +1 -0
  136. package/esm/serialization/encoders/null_encoder.d.ts +12 -0
  137. package/esm/serialization/encoders/null_encoder.js +13 -0
  138. package/esm/serialization/manipulate_bytes.d.ts +6 -0
  139. package/esm/serialization/manipulate_bytes.js +13 -0
  140. package/esm/serialization/read_uint_le.d.ts +4 -0
  141. package/esm/serialization/read_uint_le.js +14 -0
  142. package/esm/serialization/streams/fixed_size_stream_readable_buffer_adapter.d.ts +52 -0
  143. package/esm/serialization/streams/fixed_size_stream_readable_buffer_adapter.js +129 -0
  144. package/esm/serialization/streams/forward_only_stream_readable_buffer_adapter.d.ts +36 -0
  145. package/esm/serialization/streams/forward_only_stream_readable_buffer_adapter.js +114 -0
  146. package/esm/serialization/streams/stream_readable_buffer.d.ts +41 -0
  147. package/esm/serialization/streams/stream_readable_buffer.js +64 -0
  148. package/esm/serialization/streams/stream_readable_buffer_adapter.d.ts +38 -0
  149. package/esm/serialization/streams/stream_readable_buffer_adapter.js +105 -0
  150. package/esm/serialization/streams/stream_writable_buffer.d.ts +42 -0
  151. package/esm/serialization/streams/stream_writable_buffer.js +64 -0
  152. package/esm/serialization/streams/stream_writable_buffer_adapter.d.ts +36 -0
  153. package/esm/serialization/streams/stream_writable_buffer_adapter.js +65 -0
  154. package/esm/serialization/streams/streams.d.ts +29 -0
  155. package/esm/serialization/streams/streams.js +1 -0
  156. package/esm/serialization/tap.d.ts +427 -0
  157. package/esm/serialization/tap.js +605 -0
  158. package/esm/serialization/text_encoding.d.ts +12 -0
  159. package/esm/serialization/text_encoding.js +14 -0
  160. package/esm/type/create_type.d.ts +54 -0
  161. package/esm/type/create_type.js +401 -0
  162. package/package.json +33 -0
  163. package/sachitv-avro-typescript-0.4.0.tgz +0 -0
@@ -0,0 +1,95 @@
1
+ import { WritableTap, } from "../../serialization/tap.js";
2
+ import { PrimitiveType } from "./primitive_type.js";
3
+ import { Resolver } from "../resolver.js";
4
+ import { IntType } from "./int_type.js";
5
+ import { throwInvalidError } from "../error.js";
6
+ import { calculateVarintSize } from "../../internal/varint.js";
7
+ const MIN_LONG = -(1n << 63n);
8
+ const MAX_LONG = (1n << 63n) - 1n;
9
+ /**
10
+ * Long type (64-bit).
11
+ */
12
+ export class LongType extends PrimitiveType {
13
+ /** Checks if the value is a valid long. */
14
+ check(value, errorHook, path = []) {
15
+ const isValid = typeof value === "bigint" && value >= MIN_LONG &&
16
+ value <= MAX_LONG;
17
+ if (!isValid && errorHook) {
18
+ errorHook(path, value, this);
19
+ }
20
+ return isValid;
21
+ }
22
+ /** Reads a long value from the tap. */
23
+ async read(tap) {
24
+ return await tap.readLong();
25
+ }
26
+ /** Writes a long value to the tap. */
27
+ async write(tap, value) {
28
+ if (!this.check(value)) {
29
+ throwInvalidError([], value, this);
30
+ }
31
+ await tap.writeLong(value);
32
+ }
33
+ /** Skips a long value in the tap. */
34
+ async skip(tap) {
35
+ await tap.skipLong();
36
+ }
37
+ /** Converts a bigint value to its buffer representation. */
38
+ async toBuffer(value) {
39
+ this.check(value, throwInvalidError, []);
40
+ // For long, allocate exact size based on value
41
+ const size = calculateVarintSize(value);
42
+ const buf = new ArrayBuffer(size);
43
+ const tap = new WritableTap(buf);
44
+ await this.write(tap, value);
45
+ return buf;
46
+ }
47
+ /**
48
+ * Compares two long values.
49
+ */
50
+ compare(val1, val2) {
51
+ return val1 < val2 ? -1 : val1 > val2 ? 1 : 0;
52
+ }
53
+ /**
54
+ * Generates a random long value.
55
+ */
56
+ random() {
57
+ return BigInt(Math.floor(Math.random() * 1000));
58
+ }
59
+ /** Clones and validates a value as a bigint. */
60
+ cloneFromValue(value) {
61
+ if (typeof value === "bigint") {
62
+ this.check(value, throwInvalidError, []);
63
+ return value;
64
+ }
65
+ if (typeof value === "number" && Number.isInteger(value)) {
66
+ const candidate = BigInt(value);
67
+ this.check(candidate, throwInvalidError, []);
68
+ return candidate;
69
+ }
70
+ throwInvalidError([], value, this);
71
+ }
72
+ /** Creates a resolver for reading from the writer type. */
73
+ createResolver(writerType) {
74
+ if (writerType instanceof IntType) {
75
+ // Long can promote from int (32-bit to 64-bit)
76
+ return new class extends Resolver {
77
+ async read(tap) {
78
+ const intValue = await tap.readInt();
79
+ return BigInt(intValue);
80
+ }
81
+ }(this);
82
+ }
83
+ else {
84
+ return super.createResolver(writerType);
85
+ }
86
+ }
87
+ /** Returns the JSON representation of the type. */
88
+ toJSON() {
89
+ return "long";
90
+ }
91
+ /** Compares two taps for long equality. */
92
+ async match(tap1, tap2) {
93
+ return await tap1.matchLong(tap2);
94
+ }
95
+ }
@@ -0,0 +1,45 @@
1
+ import type { ReadableTapLike, WritableTapLike } from "../../serialization/tap.js";
2
+ import { FixedSizeBaseType } from "./fixed_size_base_type.js";
3
+ import type { JSONType } from "../type.js";
4
+ import { type ErrorHook } from "../error.js";
5
+ /**
6
+ * Null type.
7
+ */
8
+ export declare class NullType extends FixedSizeBaseType<null> {
9
+ /**
10
+ * Checks if the value is null.
11
+ */
12
+ check(value: unknown, errorHook?: ErrorHook, path?: string[]): boolean;
13
+ /**
14
+ * Reads a null value from the tap.
15
+ */
16
+ read(_tap: ReadableTapLike): Promise<null>;
17
+ /**
18
+ * Writes a null value to the tap.
19
+ */
20
+ write(_tap: WritableTapLike, value: null): Promise<void>;
21
+ /**
22
+ * Skips a null value in the tap.
23
+ */
24
+ skip(_tap: ReadableTapLike): Promise<void>;
25
+ /**
26
+ * Gets the size in bytes.
27
+ */
28
+ sizeBytes(): number;
29
+ /**
30
+ * Clones a null value from the given value.
31
+ */
32
+ cloneFromValue(value: unknown): null;
33
+ /**
34
+ * Compares two null values.
35
+ */
36
+ compare(_val1: null, _val2: null): number;
37
+ /**
38
+ * Generates a random null value.
39
+ */
40
+ random(): null;
41
+ /** Returns the JSON representation of the type. */
42
+ toJSON(): JSONType;
43
+ /** Compares two null values in the taps. */
44
+ match(_tap1: ReadableTapLike, _tap2: ReadableTapLike): Promise<number>;
45
+ }
@@ -0,0 +1,71 @@
1
+ import { FixedSizeBaseType } from "./fixed_size_base_type.js";
2
+ import { throwInvalidError } from "../error.js";
3
+ /**
4
+ * Null type.
5
+ */
6
+ export class NullType extends FixedSizeBaseType {
7
+ /**
8
+ * Checks if the value is null.
9
+ */
10
+ check(value, errorHook, path = []) {
11
+ const isValid = value === null;
12
+ if (!isValid && errorHook) {
13
+ errorHook(path, value, this);
14
+ }
15
+ return isValid;
16
+ }
17
+ /**
18
+ * Reads a null value from the tap.
19
+ */
20
+ async read(_tap) {
21
+ return await Promise.resolve(null);
22
+ }
23
+ /**
24
+ * Writes a null value to the tap.
25
+ */
26
+ async write(_tap, value) {
27
+ if (value !== null) {
28
+ throwInvalidError([], value, this);
29
+ }
30
+ await Promise.resolve();
31
+ }
32
+ /**
33
+ * Skips a null value in the tap.
34
+ */
35
+ async skip(_tap) {
36
+ // Null takes no space
37
+ }
38
+ /**
39
+ * Gets the size in bytes.
40
+ */
41
+ sizeBytes() {
42
+ return 0; // Null takes no space
43
+ }
44
+ /**
45
+ * Clones a null value from the given value.
46
+ */
47
+ cloneFromValue(value) {
48
+ this.check(value, throwInvalidError, []);
49
+ return value;
50
+ }
51
+ /**
52
+ * Compares two null values.
53
+ */
54
+ compare(_val1, _val2) {
55
+ return 0;
56
+ }
57
+ /**
58
+ * Generates a random null value.
59
+ */
60
+ random() {
61
+ return null;
62
+ }
63
+ /** Returns the JSON representation of the type. */
64
+ toJSON() {
65
+ return "null";
66
+ }
67
+ /** Compares two null values in the taps. */
68
+ async match(_tap1, _tap2) {
69
+ return await Promise.resolve(0);
70
+ }
71
+ }
@@ -0,0 +1,17 @@
1
+ import { BaseType } from "../base_type.js";
2
+ /**
3
+ * Abstract base class for primitive Avro types.
4
+ */
5
+ export declare abstract class PrimitiveType<T = unknown> extends BaseType<T> {
6
+ /**
7
+ * Clones a primitive value (primitives are immutable).
8
+ */
9
+ /**
10
+ * Clones a primitive value.
11
+ */
12
+ cloneFromValue(value: unknown): T;
13
+ /**
14
+ * Compares two primitive values.
15
+ */
16
+ compare(val1: T, val2: T): number;
17
+ }
@@ -0,0 +1,27 @@
1
+ import { BaseType } from "../base_type.js";
2
+ import { throwInvalidError } from "../error.js";
3
+ /**
4
+ * Abstract base class for primitive Avro types.
5
+ */
6
+ export class PrimitiveType extends BaseType {
7
+ /**
8
+ * Clones a primitive value (primitives are immutable).
9
+ */
10
+ /**
11
+ * Clones a primitive value.
12
+ */
13
+ cloneFromValue(value) {
14
+ this.check(value, throwInvalidError, []);
15
+ return value;
16
+ }
17
+ /**
18
+ * Compares two primitive values.
19
+ */
20
+ compare(val1, val2) {
21
+ if (val1 < val2)
22
+ return -1;
23
+ if (val1 > val2)
24
+ return 1;
25
+ return 0;
26
+ }
27
+ }
@@ -0,0 +1,34 @@
1
+ import { type ReadableTapLike, type WritableTapLike } from "../../serialization/tap.js";
2
+ import { PrimitiveType } from "./primitive_type.js";
3
+ import type { JSONType, Type } from "../type.js";
4
+ import { Resolver } from "../resolver.js";
5
+ import { type ErrorHook } from "../error.js";
6
+ /**
7
+ * String type.
8
+ */
9
+ export declare class StringType extends PrimitiveType<string> {
10
+ /** Checks if the value is a valid string. */
11
+ check(value: unknown, errorHook?: ErrorHook, path?: string[]): boolean;
12
+ /** Converts a string value to its Avro-encoded buffer representation. */
13
+ toBuffer(value: string): Promise<ArrayBuffer>;
14
+ /** Reads a string value from the tap. */
15
+ read(tap: ReadableTapLike): Promise<string>;
16
+ /** Writes a string value to the tap. */
17
+ write(tap: WritableTapLike, value: string): Promise<void>;
18
+ /** Skips a string value in the tap. */
19
+ skip(tap: ReadableTapLike): Promise<void>;
20
+ /**
21
+ * Compares two string values.
22
+ */
23
+ compare(val1: string, val2: string): number;
24
+ /**
25
+ * Generates a random string value.
26
+ */
27
+ random(): string;
28
+ /** Creates a resolver for reading from a writer type. */
29
+ createResolver(writerType: Type): Resolver;
30
+ /** Returns the JSON representation of the string type. */
31
+ toJSON(): JSONType;
32
+ /** Matches two readable taps for string equality. */
33
+ match(tap1: ReadableTapLike, tap2: ReadableTapLike): Promise<number>;
34
+ }
@@ -0,0 +1,81 @@
1
+ import { WritableTap, } from "../../serialization/tap.js";
2
+ import { PrimitiveType } from "./primitive_type.js";
3
+ import { Resolver } from "../resolver.js";
4
+ import { throwInvalidError } from "../error.js";
5
+ import { calculateVarintSize } from "../../internal/varint.js";
6
+ import { decode, encode } from "../../serialization/text_encoding.js";
7
+ /**
8
+ * String type.
9
+ */
10
+ export class StringType extends PrimitiveType {
11
+ /** Checks if the value is a valid string. */
12
+ check(value, errorHook, path = []) {
13
+ const isValid = typeof value === "string";
14
+ if (!isValid && errorHook) {
15
+ errorHook(path, value, this);
16
+ }
17
+ return isValid;
18
+ }
19
+ /** Converts a string value to its Avro-encoded buffer representation. */
20
+ async toBuffer(value) {
21
+ this.check(value, throwInvalidError, []);
22
+ const strBytes = encode(value);
23
+ const lengthSize = calculateVarintSize(strBytes.length);
24
+ const buf = new ArrayBuffer(lengthSize + strBytes.length);
25
+ const tap = new WritableTap(buf);
26
+ await this.write(tap, value);
27
+ return buf;
28
+ }
29
+ /** Reads a string value from the tap. */
30
+ async read(tap) {
31
+ return await tap.readString();
32
+ }
33
+ /** Writes a string value to the tap. */
34
+ async write(tap, value) {
35
+ if (typeof value !== "string") {
36
+ throwInvalidError([], value, this);
37
+ }
38
+ await tap.writeString(value);
39
+ }
40
+ /** Skips a string value in the tap. */
41
+ async skip(tap) {
42
+ await tap.skipString();
43
+ }
44
+ /**
45
+ * Compares two string values.
46
+ */
47
+ compare(val1, val2) {
48
+ return val1 < val2 ? -1 : val1 > val2 ? 1 : 0;
49
+ }
50
+ /**
51
+ * Generates a random string value.
52
+ */
53
+ random() {
54
+ return Math.random().toString(36).substring(2, 10);
55
+ }
56
+ /** Creates a resolver for reading from a writer type. */
57
+ createResolver(writerType) {
58
+ if (writerType.toJSON() === "bytes") {
59
+ // String can promote from bytes. We use an anonymous class here to avoid a
60
+ // cyclic dependency between this file and the bytes type file.
61
+ return new class extends Resolver {
62
+ async read(tap) {
63
+ const bytes = await tap.readBytes();
64
+ // Convert bytes to string (assuming UTF-8)
65
+ return decode(bytes);
66
+ }
67
+ }(this);
68
+ }
69
+ else {
70
+ return super.createResolver(writerType);
71
+ }
72
+ }
73
+ /** Returns the JSON representation of the string type. */
74
+ toJSON() {
75
+ return "string";
76
+ }
77
+ /** Matches two readable taps for string equality. */
78
+ async match(tap1, tap2) {
79
+ return await tap1.matchString(tap2);
80
+ }
81
+ }
@@ -0,0 +1,25 @@
1
+ import type { ReadableTapLike } from "../serialization/tap.js";
2
+ import type { Type } from "./type.js";
3
+ /**
4
+ * Base resolver for schema evolution, allowing reading data written with one schema
5
+ * using a different but compatible reader schema.
6
+ */
7
+ /**
8
+ * Abstract base class for schema resolvers.
9
+ * Resolvers handle reading data written by a writer schema into a reader schema,
10
+ * potentially performing conversions or handling evolution.
11
+ */
12
+ export declare abstract class Resolver<T = unknown> {
13
+ /** The type used for reading. */
14
+ protected readerType: Type<T>;
15
+ /**
16
+ * Creates a new Resolver.
17
+ * @param readerType The reader schema type.
18
+ */
19
+ constructor(readerType: Type<T>);
20
+ /**
21
+ * Reads a value from the tap using the resolution logic.
22
+ * @param tap The tap to read from.
23
+ */
24
+ abstract read(tap: ReadableTapLike): Promise<T>;
25
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Base resolver for schema evolution, allowing reading data written with one schema
3
+ * using a different but compatible reader schema.
4
+ */
5
+ /**
6
+ * Abstract base class for schema resolvers.
7
+ * Resolvers handle reading data written by a writer schema into a reader schema,
8
+ * potentially performing conversions or handling evolution.
9
+ */
10
+ export class Resolver {
11
+ /**
12
+ * Creates a new Resolver.
13
+ * @param readerType The reader schema type.
14
+ */
15
+ constructor(readerType) {
16
+ /** The type used for reading. */
17
+ Object.defineProperty(this, "readerType", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: void 0
22
+ });
23
+ this.readerType = readerType;
24
+ }
25
+ }
@@ -0,0 +1,101 @@
1
+ import type { ReadableTapLike, WritableTapLike } from "../serialization/tap.js";
2
+ import type { Resolver } from "./resolver.js";
3
+ import type { ErrorHook } from "./error.js";
4
+ /**
5
+ * Options for validation, including an optional error hook.
6
+ */
7
+ export type IsValidOptions = {
8
+ errorHook?: ErrorHook;
9
+ };
10
+ /**
11
+ * Represents a JSON value used in Avro schema definitions.
12
+ */
13
+ export type JSONType = string | number | boolean | null | {
14
+ [key: string]: JSONType;
15
+ } | JSONType[];
16
+ /**
17
+ * Pure abstract base class for all Avro schema types.
18
+ * Provides the common interface for serialization, deserialization, validation, and cloning.
19
+ */
20
+ export declare abstract class Type<T = unknown> {
21
+ /**
22
+ * Serializes a value into an ArrayBuffer using the schema.
23
+ * @param value The value to serialize.
24
+ * @returns The serialized ArrayBuffer.
25
+ */
26
+ abstract toBuffer(value: T): Promise<ArrayBuffer>;
27
+ /**
28
+ * Deserializes an ArrayBuffer into a value using the schema.
29
+ * @param buffer The ArrayBuffer to deserialize.
30
+ * @returns The deserialized value.
31
+ */
32
+ abstract fromBuffer(buffer: ArrayBuffer): Promise<T>;
33
+ /**
34
+ * Validates if a value conforms to the schema.
35
+ * @param value The value to validate.
36
+ * @param opts Optional validation options.
37
+ * @returns True if valid, false otherwise.
38
+ */
39
+ abstract isValid(value: unknown, opts?: IsValidOptions): boolean;
40
+ /**
41
+ * Creates a deep clone of the value.
42
+ * @param value The value to clone.
43
+ * @returns The cloned value.
44
+ */
45
+ abstract cloneFromValue(value: unknown): T;
46
+ /**
47
+ * Creates a resolver for schema evolution from a writer type to this reader type.
48
+ * @param writerType The writer schema type.
49
+ * @returns A resolver for reading the writer type as this type.
50
+ */
51
+ abstract createResolver(writerType: Type): Resolver;
52
+ /**
53
+ * Writes a value to the tap. Must be implemented by subclasses.
54
+ * @param tap The tap to write to.
55
+ * @param value The value to write.
56
+ */
57
+ abstract write(tap: WritableTapLike, value: T): Promise<void>;
58
+ /**
59
+ * Reads a value from the tap. Must be implemented by subclasses.
60
+ * @param tap The tap to read from.
61
+ * @returns The read value.
62
+ */
63
+ abstract read(tap: ReadableTapLike): Promise<T>;
64
+ /**
65
+ * Skips a value in the tap. Must be implemented by subclasses.
66
+ * @param tap The tap to skip from.
67
+ */
68
+ abstract skip(tap: ReadableTapLike): Promise<void>;
69
+ /**
70
+ * Checks if a value is valid according to the schema. Must be implemented by subclasses.
71
+ * @param value The value to check.
72
+ * @param errorHook Optional error callback.
73
+ * @param path Current path in the schema for error reporting.
74
+ * @returns True if valid.
75
+ */
76
+ abstract check(value: unknown, errorHook?: ErrorHook, path?: string[]): boolean;
77
+ /**
78
+ * Compares two values. Must be implemented by subclasses.
79
+ * @param val1 First value.
80
+ * @param val2 Second value.
81
+ * @returns -1 if val1 < val2, 0 if equal, 1 if val1 > val2.
82
+ */
83
+ abstract compare(val1: T, val2: T): number;
84
+ /**
85
+ * Generates a random value. Must be implemented by subclasses.
86
+ * @returns A random value of this type.
87
+ */
88
+ abstract random(): T;
89
+ /**
90
+ * Returns the JSON schema representation.
91
+ * @returns The JSON representation as JSONType.
92
+ */
93
+ abstract toJSON(): JSONType;
94
+ /**
95
+ * Compares two encoded buffers. Must be implemented by subclasses.
96
+ * @param tap1 The first tap.
97
+ * @param tap2 The second tap.
98
+ * @returns -1 if tap1 < tap2, 0 if equal, 1 if tap1 > tap2.
99
+ */
100
+ abstract match(tap1: ReadableTapLike, tap2: ReadableTapLike): Promise<number>;
101
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Pure abstract base class for all Avro schema types.
3
+ * Provides the common interface for serialization, deserialization, validation, and cloning.
4
+ */
5
+ export class Type {
6
+ }
@@ -0,0 +1,13 @@
1
+ import type { Type } from "../schemas/type.js";
2
+ /**
3
+ * Avro schema definition for the object container file header section.
4
+ */
5
+ export declare const HEADER_TYPE: Type;
6
+ /**
7
+ * Avro schema definition for individual data blocks within a container file.
8
+ */
9
+ export declare const BLOCK_TYPE: Type;
10
+ /**
11
+ * Magic bytes that prefix every Avro object container file (`Obj\x01`).
12
+ */
13
+ export declare const MAGIC_BYTES: Uint8Array;
@@ -0,0 +1,29 @@
1
+ import { createType } from "../type/create_type.js";
2
+ /**
3
+ * Avro schema definition for the object container file header section.
4
+ */
5
+ export const HEADER_TYPE = createType({
6
+ type: "record",
7
+ name: "org.apache.avro.file.Header",
8
+ fields: [
9
+ { name: "magic", type: { type: "fixed", name: "Magic", size: 4 } },
10
+ { name: "meta", type: { type: "map", values: "bytes" } },
11
+ { name: "sync", type: { type: "fixed", name: "Sync", size: 16 } },
12
+ ],
13
+ });
14
+ /**
15
+ * Avro schema definition for individual data blocks within a container file.
16
+ */
17
+ export const BLOCK_TYPE = createType({
18
+ type: "record",
19
+ name: "org.apache.avro.file.Block",
20
+ fields: [
21
+ { name: "count", type: "long" },
22
+ { name: "data", type: "bytes" },
23
+ { name: "sync", type: { type: "fixed", name: "Sync", size: 16 } },
24
+ ],
25
+ });
26
+ /**
27
+ * Magic bytes that prefix every Avro object container file (`Obj\x01`).
28
+ */
29
+ export const MAGIC_BYTES = new Uint8Array([0x4F, 0x62, 0x6A, 0x01]); // 'Obj\x01'
@@ -0,0 +1,68 @@
1
+ import { Type } from "../schemas/type.js";
2
+ import type { IReadableBuffer } from "./buffers/buffer.js";
3
+ import type { Decoder, DecoderRegistry } from "./decoders/decoder.js";
4
+ import { BLOCK_TYPE, HEADER_TYPE, MAGIC_BYTES } from "./avro_constants.js";
5
+ export type { Decoder, DecoderRegistry };
6
+ export { BLOCK_TYPE, HEADER_TYPE, MAGIC_BYTES };
7
+ /**
8
+ * Internal interface for Avro file header information.
9
+ */
10
+ export interface AvroHeader {
11
+ /** The magic bytes that identify the file as an Avro object container file, typically "Obj\x01". */
12
+ magic: Uint8Array;
13
+ /** A map of metadata key-value pairs containing schema, codec, and other file information. */
14
+ meta: Map<string, Uint8Array>;
15
+ /** A 16-byte synchronization marker used to separate data blocks in the file. */
16
+ sync: Uint8Array;
17
+ /** The parsed Avro schema type derived from the schema in the metadata. */
18
+ schemaType: Type;
19
+ }
20
+ /**
21
+ * Public interface for parsed Avro file header with proper typing.
22
+ */
23
+ export interface ParsedAvroHeader {
24
+ /** The magic bytes that identify the file as an Avro object container file, typically "Obj\x01". */
25
+ magic: Uint8Array;
26
+ /** A map of metadata key-value pairs containing schema, codec, and other file information. */
27
+ meta: Map<string, Uint8Array>;
28
+ /** A 16-byte synchronization marker used to separate data blocks in the file. */
29
+ sync: Uint8Array;
30
+ }
31
+ /**
32
+ * Internal parser for Avro object container files.
33
+ * Handles header parsing and record iteration.
34
+ */
35
+ export interface AvroFileParserOptions {
36
+ /** Optional reader schema used to resolve records written with a different schema. */
37
+ readerSchema?: unknown;
38
+ /** Custom codec decoders. Cannot include "null" or "deflate" as they are built-in. */
39
+ decoders?: DecoderRegistry;
40
+ }
41
+ /**
42
+ * Parser for Avro object container files that reads headers, resolves schemas,
43
+ * and streams decoded records from readable buffers.
44
+ */
45
+ export declare class AvroFileParser {
46
+ #private;
47
+ /**
48
+ * Creates a new AvroFileParser.
49
+ *
50
+ * @param buffer The readable buffer containing Avro data.
51
+ * @param options Configuration options for parsing.
52
+ */
53
+ constructor(buffer: IReadableBuffer, options?: AvroFileParserOptions);
54
+ /**
55
+ * Gets the parsed Avro file header with proper typing.
56
+ *
57
+ * @returns Promise that resolves to the parsed header information.
58
+ * @throws Error if the file is not a valid Avro file.
59
+ */
60
+ getHeader(): Promise<ParsedAvroHeader>;
61
+ /**
62
+ * Asynchronously iterates over all records in the Avro file.
63
+ *
64
+ * @returns AsyncIterableIterator that yields each record.
65
+ * @throws Error if the file contains invalid data or is corrupted.
66
+ */
67
+ iterRecords(): AsyncIterableIterator<unknown>;
68
+ }