@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,110 @@
1
+ import type { ReadableTap } from "../../../serialization/tap.js";
2
+ import { type MetadataInit, type MetadataMap } from "./metadata.js";
3
+ /**
4
+ * Represents the match status between client and server protocols in the Avro RPC handshake.
5
+ * - "BOTH": Both client and server protocols match.
6
+ * - "CLIENT": Only the client protocol is compatible.
7
+ * - "NONE": Neither protocol matches.
8
+ */
9
+ export type HandshakeMatch = "BOTH" | "CLIENT" | "NONE";
10
+ /**
11
+ * Initialization interface for a handshake request in the Avro RPC protocol.
12
+ * Used to construct the initial handshake message sent by the client.
13
+ */
14
+ export interface HandshakeRequestInit {
15
+ /** MD5 hash of the client's Avro protocol schema. */
16
+ clientHash: Uint8Array;
17
+ /** Optional string representation of the client's Avro protocol schema. */
18
+ clientProtocol?: string | null;
19
+ /** MD5 hash of the server's Avro protocol schema that the client expects. */
20
+ serverHash: Uint8Array;
21
+ /** Optional metadata map for additional handshake information. */
22
+ meta?: MetadataInit | null;
23
+ }
24
+ /**
25
+ * The processed handshake request message in the Avro RPC protocol.
26
+ * Contains the resolved fields after decoding or reading from a stream.
27
+ */
28
+ export interface HandshakeRequestMessage {
29
+ /** MD5 hash of the client's Avro protocol schema. */
30
+ clientHash: Uint8Array;
31
+ /** String representation of the client's Avro protocol schema, or null if not provided. */
32
+ clientProtocol: string | null;
33
+ /** MD5 hash of the server's Avro protocol schema that the client expects. */
34
+ serverHash: Uint8Array;
35
+ /** Metadata map for additional handshake information, or null if not provided. */
36
+ meta: MetadataMap | null;
37
+ }
38
+ /**
39
+ * Initialization interface for a handshake response in the Avro RPC protocol.
40
+ * Used to construct the response message sent by the server.
41
+ */
42
+ export interface HandshakeResponseInit {
43
+ /** The match status indicating compatibility between client and server protocols. */
44
+ match: HandshakeMatch;
45
+ /** Optional string representation of the server's Avro protocol schema. */
46
+ serverProtocol?: string | null;
47
+ /** Optional MD5 hash of the server's Avro protocol schema. */
48
+ serverHash?: Uint8Array | null;
49
+ /** Optional metadata map for additional handshake information. */
50
+ meta?: MetadataInit | null;
51
+ }
52
+ /**
53
+ * The processed handshake response message in the Avro RPC protocol.
54
+ * Contains the resolved fields after decoding or reading from a stream.
55
+ */
56
+ export interface HandshakeResponseMessage {
57
+ /** The match status indicating compatibility between client and server protocols. */
58
+ match: HandshakeMatch;
59
+ /** String representation of the server's Avro protocol schema, or null if not provided. */
60
+ serverProtocol: string | null;
61
+ /** MD5 hash of the server's Avro protocol schema, or null if not provided. */
62
+ serverHash: Uint8Array | null;
63
+ /** Metadata map for additional handshake information, or null if not provided. */
64
+ meta: MetadataMap | null;
65
+ }
66
+ /**
67
+ * Extracts an optional string value from an Avro union type in handshake messages.
68
+ * Handles the union of null and string, returning the string if present or null.
69
+ */
70
+ export declare function _extractOptionalString(unionValue: null | Record<string, string>): string | null;
71
+ /**
72
+ * Extracts an optional metadata map from an Avro union type in handshake messages.
73
+ * Handles the union of null and map, returning a cloned metadata map if present or null.
74
+ */
75
+ export declare function _extractOptionalMetadata(unionValue: null | Record<string, MetadataMap>): MetadataMap | null;
76
+ /**
77
+ * Extracts an optional MD5 hash from an Avro union type in handshake messages.
78
+ * Handles the union of null and MD5 fixed type, returning cloned bytes if present or null.
79
+ */
80
+ export declare function _extractOptionalMd5(unionValue: null | Record<string, Uint8Array>): Uint8Array | null;
81
+ /**
82
+ * Encodes a handshake request message into a byte buffer for transmission in the Avro RPC protocol.
83
+ * Serializes the request using the predefined Avro schema for handshake requests.
84
+ */
85
+ export declare function encodeHandshakeRequest(message: HandshakeRequestInit): Promise<Uint8Array>;
86
+ /**
87
+ * Decodes a byte buffer into a handshake request message in the Avro RPC protocol.
88
+ * Deserializes the buffer using the predefined Avro schema for handshake requests.
89
+ */
90
+ export declare function decodeHandshakeRequest(buffer: ArrayBuffer): Promise<HandshakeRequestMessage>;
91
+ /**
92
+ * Reads a handshake request message from a readable tap stream in the Avro RPC protocol.
93
+ * Deserializes the data from the stream using the predefined Avro schema for handshake requests.
94
+ */
95
+ export declare function readHandshakeRequestFromTap(tap: ReadableTap): Promise<HandshakeRequestMessage>;
96
+ /**
97
+ * Encodes a handshake response message into a byte buffer for transmission in the Avro RPC protocol.
98
+ * Serializes the response using the predefined Avro schema for handshake responses.
99
+ */
100
+ export declare function encodeHandshakeResponse(message: HandshakeResponseInit): Promise<Uint8Array>;
101
+ /**
102
+ * Decodes a byte buffer into a handshake response message in the Avro RPC protocol.
103
+ * Deserializes the buffer using the predefined Avro schema for handshake responses.
104
+ */
105
+ export declare function decodeHandshakeResponse(buffer: ArrayBuffer): Promise<HandshakeResponseMessage>;
106
+ /**
107
+ * Reads a handshake response message from a readable tap stream in the Avro RPC protocol.
108
+ * Deserializes the data from the stream using the predefined Avro schema for handshake responses.
109
+ */
110
+ export declare function readHandshakeResponseFromTap(tap: ReadableTap): Promise<HandshakeResponseMessage>;
@@ -0,0 +1,239 @@
1
+ import { createType } from "../../../type/create_type.js";
2
+ import { cloneBytes, cloneMetadataMap, toOptionalMetadataMap, } from "./metadata.js";
3
+ const handshakeRegistry = new Map();
4
+ const HANDSHAKE_REQUEST_TYPE = createType({
5
+ namespace: "org.apache.avro.ipc",
6
+ name: "HandshakeRequest",
7
+ type: "record",
8
+ fields: [
9
+ {
10
+ name: "clientHash",
11
+ type: { name: "MD5", type: "fixed", size: 16 },
12
+ },
13
+ {
14
+ name: "clientProtocol",
15
+ type: ["null", "string"],
16
+ default: null,
17
+ },
18
+ {
19
+ name: "serverHash",
20
+ type: "org.apache.avro.ipc.MD5",
21
+ },
22
+ {
23
+ name: "meta",
24
+ type: ["null", { type: "map", values: "bytes" }],
25
+ default: null,
26
+ },
27
+ ],
28
+ }, { registry: handshakeRegistry });
29
+ const HANDSHAKE_RESPONSE_TYPE = createType({
30
+ namespace: "org.apache.avro.ipc",
31
+ name: "HandshakeResponse",
32
+ type: "record",
33
+ fields: [
34
+ {
35
+ name: "match",
36
+ type: {
37
+ name: "HandshakeMatch",
38
+ type: "enum",
39
+ symbols: ["BOTH", "CLIENT", "NONE"],
40
+ },
41
+ },
42
+ {
43
+ name: "serverProtocol",
44
+ type: ["null", "string"],
45
+ default: null,
46
+ },
47
+ {
48
+ name: "serverHash",
49
+ type: [
50
+ "null",
51
+ "org.apache.avro.ipc.MD5",
52
+ ],
53
+ default: null,
54
+ },
55
+ {
56
+ name: "meta",
57
+ type: ["null", { type: "map", values: "bytes" }],
58
+ default: null,
59
+ },
60
+ ],
61
+ }, { registry: handshakeRegistry });
62
+ const STRING_BRANCH = "string";
63
+ const MAP_BRANCH = "map";
64
+ const MD5_BRANCH = "org.apache.avro.ipc.MD5";
65
+ // @internal
66
+ function _assertMd5Size(value, field) {
67
+ if (value.length !== 16) {
68
+ throw new RangeError(`${field} must contain exactly 16 bytes.`);
69
+ }
70
+ }
71
+ // @internal
72
+ function _wrapUnion(branch, value) {
73
+ return { [branch]: value };
74
+ }
75
+ // @internal
76
+ function _createHandshakeRequestRecord(message) {
77
+ const clientHash = cloneBytes(message.clientHash, "clientHash");
78
+ _assertMd5Size(clientHash, "clientHash");
79
+ const serverHash = cloneBytes(message.serverHash, "serverHash");
80
+ _assertMd5Size(serverHash, "serverHash");
81
+ const clientProtocol = message.clientProtocol ?? null;
82
+ let clientProtocolUnion;
83
+ if (clientProtocol === null) {
84
+ clientProtocolUnion = null;
85
+ }
86
+ else if (typeof clientProtocol === "string") {
87
+ clientProtocolUnion = _wrapUnion(STRING_BRANCH, clientProtocol);
88
+ }
89
+ else {
90
+ throw new TypeError("clientProtocol must be a string or null.");
91
+ }
92
+ const meta = toOptionalMetadataMap(message.meta);
93
+ const metaUnion = meta === null ? null : _wrapUnion(MAP_BRANCH, meta);
94
+ return {
95
+ clientHash,
96
+ clientProtocol: clientProtocolUnion,
97
+ serverHash,
98
+ meta: metaUnion,
99
+ };
100
+ }
101
+ // @internal
102
+ function _createHandshakeResponseRecord(message) {
103
+ const serverHash = message.serverHash ?? null;
104
+ let serverHashUnion;
105
+ if (serverHash === null) {
106
+ serverHashUnion = null;
107
+ }
108
+ else {
109
+ const hashBytes = cloneBytes(serverHash, "serverHash");
110
+ _assertMd5Size(hashBytes, "serverHash");
111
+ serverHashUnion = _wrapUnion(MD5_BRANCH, hashBytes);
112
+ }
113
+ const serverProtocol = message.serverProtocol ?? null;
114
+ let serverProtocolUnion;
115
+ if (serverProtocol === null) {
116
+ serverProtocolUnion = null;
117
+ }
118
+ else if (typeof serverProtocol === "string") {
119
+ serverProtocolUnion = _wrapUnion(STRING_BRANCH, serverProtocol);
120
+ }
121
+ else {
122
+ throw new TypeError("serverProtocol must be a string or null.");
123
+ }
124
+ const meta = toOptionalMetadataMap(message.meta);
125
+ const metaUnion = meta === null ? null : _wrapUnion(MAP_BRANCH, meta);
126
+ return {
127
+ match: message.match,
128
+ serverProtocol: serverProtocolUnion,
129
+ serverHash: serverHashUnion,
130
+ meta: metaUnion,
131
+ };
132
+ }
133
+ /**
134
+ * Extracts an optional string value from an Avro union type in handshake messages.
135
+ * Handles the union of null and string, returning the string if present or null.
136
+ */
137
+ export function _extractOptionalString(unionValue) {
138
+ if (unionValue === null) {
139
+ return null;
140
+ }
141
+ if (unionValue[STRING_BRANCH] !== undefined) {
142
+ return unionValue[STRING_BRANCH];
143
+ }
144
+ throw new Error("Unexpected union value for string branch.");
145
+ }
146
+ /**
147
+ * Extracts an optional metadata map from an Avro union type in handshake messages.
148
+ * Handles the union of null and map, returning a cloned metadata map if present or null.
149
+ */
150
+ export function _extractOptionalMetadata(unionValue) {
151
+ if (unionValue === null) {
152
+ return null;
153
+ }
154
+ const map = unionValue[MAP_BRANCH];
155
+ if (map === undefined) {
156
+ throw new Error("Unexpected union value for metadata branch.");
157
+ }
158
+ return cloneMetadataMap(map);
159
+ }
160
+ /**
161
+ * Extracts an optional MD5 hash from an Avro union type in handshake messages.
162
+ * Handles the union of null and MD5 fixed type, returning cloned bytes if present or null.
163
+ */
164
+ export function _extractOptionalMd5(unionValue) {
165
+ if (unionValue === null) {
166
+ return null;
167
+ }
168
+ const value = unionValue[MD5_BRANCH];
169
+ if (value === undefined) {
170
+ throw new Error("Unexpected union value for MD5 branch.");
171
+ }
172
+ return cloneBytes(value, "serverHash");
173
+ }
174
+ // @internal
175
+ function _toHandshakeRequestMessage(record) {
176
+ return {
177
+ clientHash: cloneBytes(record.clientHash, "clientHash"),
178
+ clientProtocol: _extractOptionalString(record.clientProtocol),
179
+ serverHash: cloneBytes(record.serverHash, "serverHash"),
180
+ meta: _extractOptionalMetadata(record.meta),
181
+ };
182
+ }
183
+ // @internal
184
+ function _toHandshakeResponseMessage(record) {
185
+ return {
186
+ match: record.match,
187
+ serverProtocol: _extractOptionalString(record.serverProtocol),
188
+ serverHash: _extractOptionalMd5(record.serverHash),
189
+ meta: _extractOptionalMetadata(record.meta),
190
+ };
191
+ }
192
+ /**
193
+ * Encodes a handshake request message into a byte buffer for transmission in the Avro RPC protocol.
194
+ * Serializes the request using the predefined Avro schema for handshake requests.
195
+ */
196
+ export async function encodeHandshakeRequest(message) {
197
+ const record = _createHandshakeRequestRecord(message);
198
+ return new Uint8Array(await HANDSHAKE_REQUEST_TYPE.toBuffer(record));
199
+ }
200
+ /**
201
+ * Decodes a byte buffer into a handshake request message in the Avro RPC protocol.
202
+ * Deserializes the buffer using the predefined Avro schema for handshake requests.
203
+ */
204
+ export async function decodeHandshakeRequest(buffer) {
205
+ const record = await HANDSHAKE_REQUEST_TYPE.fromBuffer(buffer);
206
+ return _toHandshakeRequestMessage(record);
207
+ }
208
+ /**
209
+ * Reads a handshake request message from a readable tap stream in the Avro RPC protocol.
210
+ * Deserializes the data from the stream using the predefined Avro schema for handshake requests.
211
+ */
212
+ export async function readHandshakeRequestFromTap(tap) {
213
+ const record = await HANDSHAKE_REQUEST_TYPE.read(tap);
214
+ return _toHandshakeRequestMessage(record);
215
+ }
216
+ /**
217
+ * Encodes a handshake response message into a byte buffer for transmission in the Avro RPC protocol.
218
+ * Serializes the response using the predefined Avro schema for handshake responses.
219
+ */
220
+ export async function encodeHandshakeResponse(message) {
221
+ const record = _createHandshakeResponseRecord(message);
222
+ return new Uint8Array(await HANDSHAKE_RESPONSE_TYPE.toBuffer(record));
223
+ }
224
+ /**
225
+ * Decodes a byte buffer into a handshake response message in the Avro RPC protocol.
226
+ * Deserializes the buffer using the predefined Avro schema for handshake responses.
227
+ */
228
+ export async function decodeHandshakeResponse(buffer) {
229
+ const record = await HANDSHAKE_RESPONSE_TYPE.fromBuffer(buffer);
230
+ return _toHandshakeResponseMessage(record);
231
+ }
232
+ /**
233
+ * Reads a handshake response message from a readable tap stream in the Avro RPC protocol.
234
+ * Deserializes the data from the stream using the predefined Avro schema for handshake responses.
235
+ */
236
+ export async function readHandshakeResponseFromTap(tap) {
237
+ const record = await HANDSHAKE_RESPONSE_TYPE.read(tap);
238
+ return _toHandshakeResponseMessage(record);
239
+ }
@@ -0,0 +1,192 @@
1
+ import type { Type } from "../../../schemas/type.js";
2
+ import { ReadableTap } from "../../../serialization/tap.js";
3
+ import { type MetadataInit, type MetadataMap } from "./metadata.js";
4
+ import { type HandshakeRequestInit, type HandshakeRequestMessage, type HandshakeResponseInit, type HandshakeResponseMessage } from "./handshake.js";
5
+ /**
6
+ * Initialization object for encoding a call request in the Avro RPC wire format.
7
+ * Contains the data needed to construct a call request message, including optional handshake,
8
+ * metadata, message name, request payload, and the Avro type of the request.
9
+ */
10
+ export interface CallRequestInit<T> {
11
+ /** Optional handshake request data for protocol negotiation in the Avro RPC wire format. */
12
+ handshake?: HandshakeRequestInit | HandshakeRequestMessage;
13
+ /** Optional metadata map or initialization object for additional message metadata. */
14
+ metadata?: MetadataInit | null;
15
+ /** The name of the RPC message being called. */
16
+ messageName: string;
17
+ /** The request payload data to be sent. */
18
+ request: T;
19
+ /** The Avro type definition for the request payload. */
20
+ requestType: Type<T>;
21
+ }
22
+ /**
23
+ * Represents a decoded call request message in the Avro RPC wire format.
24
+ * Contains the parsed handshake (if present), metadata, message name, and request payload.
25
+ */
26
+ export interface CallRequestMessage<T> {
27
+ /** Optional decoded handshake request message for protocol negotiation. */
28
+ handshake?: HandshakeRequestMessage;
29
+ /** Metadata map containing additional message information. */
30
+ metadata: MetadataMap;
31
+ /** The name of the RPC message being called. */
32
+ messageName: string;
33
+ /** The decoded request payload data. */
34
+ request: T;
35
+ }
36
+ /**
37
+ * Options for decoding a call request message from the Avro RPC wire format.
38
+ * Specifies the expected request type and whether a handshake is expected.
39
+ */
40
+ export interface DecodeCallRequestOptions<T> {
41
+ /** The Avro type definition for the request payload. */
42
+ requestType: Type<T>;
43
+ /** Whether to expect and parse handshake data in the message. */
44
+ expectHandshake?: boolean;
45
+ }
46
+ /**
47
+ * Envelope for a call request message in the Avro RPC wire format.
48
+ * Contains the handshake (if present), metadata, message name, and a tap for reading the request body.
49
+ */
50
+ export interface CallRequestEnvelope {
51
+ /** Optional decoded handshake request message. */
52
+ handshake?: HandshakeRequestMessage;
53
+ /** Metadata map with message metadata. */
54
+ metadata: MetadataMap;
55
+ /** The name of the RPC message. */
56
+ messageName: string;
57
+ /** Readable tap positioned at the start of the request payload for lazy reading. */
58
+ bodyTap: ReadableTap;
59
+ }
60
+ /**
61
+ * Initialization object for encoding a call response in the Avro RPC wire format.
62
+ * Contains the data needed to construct a call response message, including optional handshake,
63
+ * metadata, error flag, payload, and the Avro types for response and error.
64
+ */
65
+ export interface CallResponseInit<TResponse, TError> {
66
+ /** Optional handshake response data for protocol negotiation. */
67
+ handshake?: HandshakeResponseInit | HandshakeResponseMessage;
68
+ /** Optional metadata map or initialization object. */
69
+ metadata?: MetadataInit | null;
70
+ /** Flag indicating whether this response represents an error. */
71
+ isError: boolean;
72
+ /** The response or error payload data. */
73
+ payload: TResponse | TError;
74
+ /** The Avro type definition for the response payload. */
75
+ responseType: Type<TResponse>;
76
+ /** The Avro type definition for the error payload. */
77
+ errorType: Type<TError>;
78
+ }
79
+ /**
80
+ * Represents a decoded call response message in the Avro RPC wire format.
81
+ * Contains the parsed handshake (if present), metadata, error flag, and payload.
82
+ */
83
+ export interface CallResponseMessage<TResponse, TError> {
84
+ /** Optional decoded handshake response message. */
85
+ handshake?: HandshakeResponseMessage;
86
+ /** Metadata map containing additional message information. */
87
+ metadata: MetadataMap;
88
+ /** Flag indicating whether this response represents an error. */
89
+ isError: boolean;
90
+ /** The decoded response or error payload data. */
91
+ payload: TResponse | TError;
92
+ }
93
+ /**
94
+ * Options for decoding a call response message from the Avro RPC wire format.
95
+ * Specifies the expected response and error types, and whether a handshake is expected.
96
+ */
97
+ export interface DecodeCallResponseOptions<TResponse, TError> {
98
+ /** The Avro type definition for the response payload. */
99
+ responseType: Type<TResponse>;
100
+ /** The Avro type definition for the error payload. */
101
+ errorType: Type<TError>;
102
+ /** Whether to expect and parse handshake data in the message. */
103
+ expectHandshake?: boolean;
104
+ }
105
+ /**
106
+ * Envelope for a call response message in the Avro RPC wire format.
107
+ * Contains the handshake (if present), metadata, error flag, and a tap for reading the response body.
108
+ */
109
+ export interface CallResponseEnvelope {
110
+ /** Optional decoded handshake response message. */
111
+ handshake?: HandshakeResponseMessage;
112
+ /** Metadata map with message metadata. */
113
+ metadata: MetadataMap;
114
+ /** Flag indicating whether this response represents an error. */
115
+ isError: boolean;
116
+ /** Readable tap positioned at the start of the response or error payload for lazy reading. */
117
+ bodyTap: ReadableTap;
118
+ }
119
+ /**
120
+ * Encodes a call request message into a binary format for transmission.
121
+ *
122
+ * The encoded message includes optional handshake data, metadata, message name,
123
+ * and the request payload. The format follows the Avro RPC wire protocol.
124
+ *
125
+ * @param init - The call request initialization object containing handshake,
126
+ * metadata, message name, request data, and request type.
127
+ * @returns A promise that resolves to the encoded message as a Uint8Array.
128
+ */
129
+ export declare function encodeCallRequest<T>(init: CallRequestInit<T>): Promise<Uint8Array>;
130
+ /**
131
+ * Decodes a binary call request message into a structured object.
132
+ *
133
+ * This function parses the complete message including handshake (if expected),
134
+ * metadata, message name, and request payload.
135
+ *
136
+ * @param buffer - The binary data containing the encoded call request.
137
+ * @param options - Decoding options including the request type and whether
138
+ * to expect handshake data.
139
+ * @returns A promise that resolves to the decoded call request message.
140
+ */
141
+ export declare function decodeCallRequest<T>(buffer: ArrayBuffer, options: DecodeCallRequestOptions<T>): Promise<CallRequestMessage<T>>;
142
+ /**
143
+ * Decodes the envelope of a call request message without parsing the request payload.
144
+ *
145
+ * This function is useful for inspecting message metadata and headers before
146
+ * deciding whether to parse the full request payload. The request data remains
147
+ * in the bodyTap for later reading.
148
+ *
149
+ * @param buffer - The binary data containing the encoded call request.
150
+ * @param options - Options specifying whether to expect handshake data.
151
+ * @returns A promise that resolves to the call request envelope.
152
+ */
153
+ export declare function decodeCallRequestEnvelope(buffer: ArrayBuffer, options?: {
154
+ expectHandshake?: boolean;
155
+ }): Promise<CallRequestEnvelope>;
156
+ /**
157
+ * Encodes a call response message into a binary format for transmission.
158
+ *
159
+ * The encoded message includes optional handshake data, metadata, error flag,
160
+ * and either the response payload or error payload based on the isError flag.
161
+ *
162
+ * @param init - The call response initialization object containing handshake,
163
+ * metadata, error flag, payload, and response/error types.
164
+ * @returns A promise that resolves to the encoded message as a Uint8Array.
165
+ */
166
+ export declare function encodeCallResponse<TResponse, TError>(init: CallResponseInit<TResponse, TError>): Promise<Uint8Array>;
167
+ /**
168
+ * Decodes a binary call response message into a structured object.
169
+ *
170
+ * This function parses the complete message including handshake (if expected),
171
+ * metadata, error flag, and response or error payload based on the error flag.
172
+ *
173
+ * @param buffer - The binary data containing the encoded call response.
174
+ * @param options - Decoding options including response and error types, and
175
+ * whether to expect handshake data.
176
+ * @returns A promise that resolves to the decoded call response message.
177
+ */
178
+ export declare function decodeCallResponse<TResponse, TError>(buffer: ArrayBuffer, options: DecodeCallResponseOptions<TResponse, TError>): Promise<CallResponseMessage<TResponse, TError>>;
179
+ /**
180
+ * Decodes the envelope of a call response message without parsing the response payload.
181
+ *
182
+ * This function is useful for inspecting message metadata and error status before
183
+ * deciding whether to parse the full response or error payload. The payload data
184
+ * remains in the bodyTap for later reading.
185
+ *
186
+ * @param buffer - The binary data containing the encoded call response.
187
+ * @param options - Options specifying whether to expect handshake data.
188
+ * @returns A promise that resolves to the call response envelope.
189
+ */
190
+ export declare function decodeCallResponseEnvelope(buffer: ArrayBuffer, options?: {
191
+ expectHandshake?: boolean;
192
+ }): Promise<CallResponseEnvelope>;