@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,129 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _CircularBuffer_instances, _CircularBuffer_buffer, _CircularBuffer_capacity, _CircularBuffer_windowStart, _CircularBuffer_windowEnd, _CircularBuffer_validateDataSize, _CircularBuffer_slideWindowIfNeeded, _CircularBuffer_addData, _CircularBuffer_validateGetParameters, _CircularBuffer_validateGetRange;
13
+ /**
14
+ * A circular buffer implementation that maintains a rolling window of Uint8Array data.
15
+ * Uses copyWithin for efficient window sliding and provides memory-efficient random access.
16
+ */
17
+ export class CircularBuffer {
18
+ /**
19
+ * Creates a new circular buffer with the specified capacity.
20
+ * @param capacity Maximum number of bytes the buffer can hold
21
+ * @throws RangeError if capacity is not positive
22
+ */
23
+ constructor(capacity) {
24
+ _CircularBuffer_instances.add(this);
25
+ _CircularBuffer_buffer.set(this, void 0);
26
+ _CircularBuffer_capacity.set(this, void 0);
27
+ _CircularBuffer_windowStart.set(this, void 0);
28
+ _CircularBuffer_windowEnd.set(this, void 0);
29
+ if (capacity <= 0) {
30
+ throw new RangeError("Capacity must be positive");
31
+ }
32
+ __classPrivateFieldSet(this, _CircularBuffer_capacity, capacity, "f");
33
+ __classPrivateFieldSet(this, _CircularBuffer_buffer, new Uint8Array(capacity), "f");
34
+ __classPrivateFieldSet(this, _CircularBuffer_windowStart, 0, "f");
35
+ __classPrivateFieldSet(this, _CircularBuffer_windowEnd, 0, "f");
36
+ }
37
+ /**
38
+ * Maximum capacity of the buffer in bytes.
39
+ */
40
+ capacity() {
41
+ return __classPrivateFieldGet(this, _CircularBuffer_capacity, "f");
42
+ }
43
+ /**
44
+ * Current number of bytes in the buffer.
45
+ */
46
+ length() {
47
+ return __classPrivateFieldGet(this, _CircularBuffer_windowEnd, "f") - __classPrivateFieldGet(this, _CircularBuffer_windowStart, "f");
48
+ }
49
+ /**
50
+ * Position in the overall data stream where the current window starts.
51
+ */
52
+ windowStart() {
53
+ return __classPrivateFieldGet(this, _CircularBuffer_windowStart, "f");
54
+ }
55
+ /**
56
+ * Position in the overall data stream where the current window ends (exclusive).
57
+ */
58
+ windowEnd() {
59
+ return __classPrivateFieldGet(this, _CircularBuffer_windowEnd, "f");
60
+ }
61
+ /**
62
+ * Clears the buffer, resetting the window to empty.
63
+ */
64
+ clear() {
65
+ __classPrivateFieldSet(this, _CircularBuffer_windowStart, 0, "f");
66
+ __classPrivateFieldSet(this, _CircularBuffer_windowEnd, 0, "f");
67
+ }
68
+ /**
69
+ * Adds data to the buffer, sliding the window if necessary.
70
+ * @param data Uint8Array to add
71
+ * @throws RangeError if data size exceeds buffer capacity
72
+ */
73
+ push(data) {
74
+ if (data.length === 0) {
75
+ return;
76
+ }
77
+ __classPrivateFieldGet(this, _CircularBuffer_instances, "m", _CircularBuffer_validateDataSize).call(this, data.length);
78
+ __classPrivateFieldGet(this, _CircularBuffer_instances, "m", _CircularBuffer_slideWindowIfNeeded).call(this, data.length);
79
+ __classPrivateFieldGet(this, _CircularBuffer_instances, "m", _CircularBuffer_addData).call(this, data);
80
+ }
81
+ /**
82
+ * Retrieves a contiguous sequence of bytes from the buffer.
83
+ * @param start Start position relative to the overall data stream
84
+ * @param size Number of bytes to retrieve
85
+ * @returns Readonly view of the requested bytes (shallow copy, no allocation)
86
+ * @throws RangeError if start is before window start or size is negative
87
+ * @throws RangeError if requested range extends beyond window end
88
+ */
89
+ get(start, size) {
90
+ __classPrivateFieldGet(this, _CircularBuffer_instances, "m", _CircularBuffer_validateGetParameters).call(this, start, size);
91
+ __classPrivateFieldGet(this, _CircularBuffer_instances, "m", _CircularBuffer_validateGetRange).call(this, start, size);
92
+ const bufferStart = start - __classPrivateFieldGet(this, _CircularBuffer_windowStart, "f");
93
+ return __classPrivateFieldGet(this, _CircularBuffer_buffer, "f").subarray(bufferStart, bufferStart + size);
94
+ }
95
+ }
96
+ _CircularBuffer_buffer = new WeakMap(), _CircularBuffer_capacity = new WeakMap(), _CircularBuffer_windowStart = new WeakMap(), _CircularBuffer_windowEnd = new WeakMap(), _CircularBuffer_instances = new WeakSet(), _CircularBuffer_validateDataSize = function _CircularBuffer_validateDataSize(dataSize) {
97
+ if (dataSize > __classPrivateFieldGet(this, _CircularBuffer_capacity, "f")) {
98
+ throw new RangeError(`Data size ${dataSize} exceeds buffer capacity ${__classPrivateFieldGet(this, _CircularBuffer_capacity, "f")}`);
99
+ }
100
+ }, _CircularBuffer_slideWindowIfNeeded = function _CircularBuffer_slideWindowIfNeeded(dataSize) {
101
+ const currentLength = this.length();
102
+ if (currentLength + dataSize > __classPrivateFieldGet(this, _CircularBuffer_capacity, "f")) {
103
+ const slideAmount = (currentLength + dataSize) - __classPrivateFieldGet(this, _CircularBuffer_capacity, "f");
104
+ const newWindowStart = __classPrivateFieldGet(this, _CircularBuffer_windowStart, "f") + slideAmount;
105
+ // Slide the window using copyWithin
106
+ const shift = newWindowStart - __classPrivateFieldGet(this, _CircularBuffer_windowStart, "f");
107
+ if (shift > 0 && shift <= currentLength) {
108
+ __classPrivateFieldGet(this, _CircularBuffer_buffer, "f").copyWithin(0, shift, currentLength);
109
+ __classPrivateFieldSet(this, _CircularBuffer_windowStart, newWindowStart, "f");
110
+ __classPrivateFieldSet(this, _CircularBuffer_windowEnd, __classPrivateFieldGet(this, _CircularBuffer_windowStart, "f") + (currentLength - shift), "f");
111
+ }
112
+ }
113
+ }, _CircularBuffer_addData = function _CircularBuffer_addData(data) {
114
+ const bufferOffset = __classPrivateFieldGet(this, _CircularBuffer_windowEnd, "f") - __classPrivateFieldGet(this, _CircularBuffer_windowStart, "f");
115
+ __classPrivateFieldGet(this, _CircularBuffer_buffer, "f").set(data, bufferOffset);
116
+ __classPrivateFieldSet(this, _CircularBuffer_windowEnd, __classPrivateFieldGet(this, _CircularBuffer_windowEnd, "f") + data.length, "f");
117
+ }, _CircularBuffer_validateGetParameters = function _CircularBuffer_validateGetParameters(start, size) {
118
+ if (start < __classPrivateFieldGet(this, _CircularBuffer_windowStart, "f")) {
119
+ throw new RangeError(`Start position ${start} is before window start ${__classPrivateFieldGet(this, _CircularBuffer_windowStart, "f")}`);
120
+ }
121
+ if (size < 0) {
122
+ throw new RangeError(`Size ${size} cannot be negative`);
123
+ }
124
+ }, _CircularBuffer_validateGetRange = function _CircularBuffer_validateGetRange(start, size) {
125
+ const end = start + size;
126
+ if (end > __classPrivateFieldGet(this, _CircularBuffer_windowEnd, "f")) {
127
+ throw new RangeError(`Requested range [${start}, ${end}) extends beyond window end ${__classPrivateFieldGet(this, _CircularBuffer_windowEnd, "f")}`);
128
+ }
129
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Computes MD5 hash from string.
3
+ * @param value The string to hash.
4
+ * @returns The MD5 hash as a Uint8Array.
5
+ */
6
+ export declare function md5FromString(value: string): Uint8Array;
7
+ /**
8
+ * Computes MD5 hash from Uint8Array.
9
+ * @param input The input bytes to hash.
10
+ * @returns The MD5 hash as a Uint8Array.
11
+ */
12
+ export declare function md5(input: Uint8Array): Uint8Array;
@@ -0,0 +1,158 @@
1
+ const S = [
2
+ 7,
3
+ 12,
4
+ 17,
5
+ 22,
6
+ 7,
7
+ 12,
8
+ 17,
9
+ 22,
10
+ 7,
11
+ 12,
12
+ 17,
13
+ 22,
14
+ 7,
15
+ 12,
16
+ 17,
17
+ 22,
18
+ 5,
19
+ 9,
20
+ 14,
21
+ 20,
22
+ 5,
23
+ 9,
24
+ 14,
25
+ 20,
26
+ 5,
27
+ 9,
28
+ 14,
29
+ 20,
30
+ 5,
31
+ 9,
32
+ 14,
33
+ 20,
34
+ 4,
35
+ 11,
36
+ 16,
37
+ 23,
38
+ 4,
39
+ 11,
40
+ 16,
41
+ 23,
42
+ 4,
43
+ 11,
44
+ 16,
45
+ 23,
46
+ 4,
47
+ 11,
48
+ 16,
49
+ 23,
50
+ 6,
51
+ 10,
52
+ 15,
53
+ 21,
54
+ 6,
55
+ 10,
56
+ 15,
57
+ 21,
58
+ 6,
59
+ 10,
60
+ 15,
61
+ 21,
62
+ 6,
63
+ 10,
64
+ 15,
65
+ 21,
66
+ ];
67
+ const K = new Uint32Array(64);
68
+ for (let i = 0; i < 64; i++) {
69
+ K[i] = Math.floor(Math.abs(Math.sin(i + 1)) * 2 ** 32);
70
+ }
71
+ const textEncoder = new TextEncoder();
72
+ /**
73
+ * Computes MD5 hash from string.
74
+ * @param value The string to hash.
75
+ * @returns The MD5 hash as a Uint8Array.
76
+ */
77
+ export function md5FromString(value) {
78
+ return md5(textEncoder.encode(value));
79
+ }
80
+ /**
81
+ * Computes MD5 hash from Uint8Array.
82
+ * @param input The input bytes to hash.
83
+ * @returns The MD5 hash as a Uint8Array.
84
+ */
85
+ export function md5(input) {
86
+ const data = pad(input);
87
+ let a = 0x67452301;
88
+ let b = 0xefcdab89;
89
+ let c = 0x98badcfe;
90
+ let d = 0x10325476;
91
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
92
+ for (let offset = 0; offset < data.byteLength; offset += 64) {
93
+ const chunk = new Uint32Array(16);
94
+ for (let i = 0; i < 16; i++) {
95
+ chunk[i] = view.getUint32(offset + i * 4, true);
96
+ }
97
+ let A = a;
98
+ let B = b;
99
+ let C = c;
100
+ let D = d;
101
+ for (let i = 0; i < 64; i++) {
102
+ let F;
103
+ let g;
104
+ if (i < 16) {
105
+ F = (B & C) | (~B & D);
106
+ g = i;
107
+ }
108
+ else if (i < 32) {
109
+ F = (D & B) | (~D & C);
110
+ g = (5 * i + 1) % 16;
111
+ }
112
+ else if (i < 48) {
113
+ F = B ^ C ^ D;
114
+ g = (3 * i + 5) % 16;
115
+ }
116
+ else {
117
+ F = C ^ (B | ~D);
118
+ g = (7 * i) % 16;
119
+ }
120
+ const temp = D;
121
+ D = C;
122
+ C = B;
123
+ const sum = (A + F + K[i] + chunk[g]) >>> 0;
124
+ const rotated = rotateLeft(sum, S[i]);
125
+ B = (B + rotated) >>> 0;
126
+ A = temp;
127
+ }
128
+ a = (a + A) >>> 0;
129
+ b = (b + B) >>> 0;
130
+ c = (c + C) >>> 0;
131
+ d = (d + D) >>> 0;
132
+ }
133
+ const result = new Uint8Array(16);
134
+ const resultView = new DataView(result.buffer);
135
+ resultView.setUint32(0, a, true);
136
+ resultView.setUint32(4, b, true);
137
+ resultView.setUint32(8, c, true);
138
+ resultView.setUint32(12, d, true);
139
+ return result;
140
+ }
141
+ function rotateLeft(value, shift) {
142
+ return ((value << shift) | (value >>> (32 - shift))) >>> 0;
143
+ }
144
+ function pad(input) {
145
+ const bitLength = BigInt(input.length) * 8n;
146
+ let paddingLength = 56 - (input.length + 1) % 64;
147
+ if (paddingLength < 0) {
148
+ paddingLength += 64;
149
+ }
150
+ const totalLength = input.length + 1 + paddingLength + 8;
151
+ const output = new Uint8Array(totalLength);
152
+ output.set(input, 0);
153
+ output[input.length] = 0x80;
154
+ const view = new DataView(output.buffer);
155
+ view.setUint32(totalLength - 8, Number(bitLength & 0xffffffffn), true);
156
+ view.setUint32(totalLength - 4, Number((bitLength >> 32n) & 0xffffffffn), true);
157
+ return output;
158
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Calculates the number of bytes required to encode a value as a zigzag varint.
3
+ * @param value The number or bigint to encode.
4
+ * @returns The size in bytes (1-10).
5
+ */
6
+ export declare function calculateVarintSize(value: number | bigint): number;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Calculates the number of bytes required to encode a value as a zigzag varint.
3
+ * @param value The number or bigint to encode.
4
+ * @returns The size in bytes (1-10).
5
+ */
6
+ export function calculateVarintSize(value) {
7
+ const val = typeof value === "number" ? BigInt(value) : value;
8
+ // Zigzag encoding: (val << 1) ^ (val >> 63)
9
+ const zigzag = (val << 1n) ^ (val >> 63n);
10
+ // Now calculate varint size for the unsigned zigzag value
11
+ if (zigzag < 128n)
12
+ return 1;
13
+ if (zigzag < 16384n)
14
+ return 2;
15
+ if (zigzag < 2097152n)
16
+ return 3;
17
+ if (zigzag < 268435456n)
18
+ return 4;
19
+ if (zigzag < 34359738368n)
20
+ return 5;
21
+ if (zigzag < 4398046511104n)
22
+ return 6;
23
+ if (zigzag < 562949953421312n)
24
+ return 7;
25
+ if (zigzag < 72057594037927936n)
26
+ return 8;
27
+ if (zigzag < 9223372036854775808n)
28
+ return 9;
29
+ return 10;
30
+ }
package/esm/mod.d.ts ADDED
@@ -0,0 +1,77 @@
1
+ import "./_dnt.polyfills.js";
2
+ export { AvroReader } from "./avro_reader.js";
3
+ export { AvroWriter } from "./avro_writer.js";
4
+ export { createType } from "./type/create_type.js";
5
+ export { Type } from "./schemas/type.js";
6
+ export { BaseType } from "./schemas/base_type.js";
7
+ export { PrimitiveType } from "./schemas/primitive/primitive_type.js";
8
+ export { FixedSizeBaseType } from "./schemas/primitive/fixed_size_base_type.js";
9
+ export { NamedType } from "./schemas/complex/named_type.js";
10
+ export { LogicalType, NamedLogicalType, withLogicalTypeJSON, } from "./schemas/logical/logical_type.js";
11
+ export { BooleanType } from "./schemas/primitive/boolean_type.js";
12
+ export { IntType } from "./schemas/primitive/int_type.js";
13
+ export { LongType } from "./schemas/primitive/long_type.js";
14
+ export { FloatType } from "./schemas/primitive/float_type.js";
15
+ export { DoubleType } from "./schemas/primitive/double_type.js";
16
+ export { BytesType } from "./schemas/primitive/bytes_type.js";
17
+ export { StringType } from "./schemas/primitive/string_type.js";
18
+ export { NullType } from "./schemas/primitive/null_type.js";
19
+ export { RecordType } from "./schemas/complex/record_type.js";
20
+ export { ArrayType } from "./schemas/complex/array_type.js";
21
+ export { MapType } from "./schemas/complex/map_type.js";
22
+ export { UnionType } from "./schemas/complex/union_type.js";
23
+ export { EnumType } from "./schemas/complex/enum_type.js";
24
+ export { FixedType } from "./schemas/complex/fixed_type.js";
25
+ export { UuidLogicalType } from "./schemas/logical/uuid_logical_type.js";
26
+ export { DecimalLogicalType } from "./schemas/logical/decimal_logical_type.js";
27
+ export { DurationLogicalType } from "./schemas/logical/duration_logical_type.js";
28
+ export { DateLogicalType } from "./schemas/logical/temporal_logical_types.js";
29
+ export { TimeMillisLogicalType } from "./schemas/logical/temporal_logical_types.js";
30
+ export { TimeMicrosLogicalType } from "./schemas/logical/temporal_logical_types.js";
31
+ export { TimestampMillisLogicalType } from "./schemas/logical/temporal_logical_types.js";
32
+ export { TimestampMicrosLogicalType } from "./schemas/logical/temporal_logical_types.js";
33
+ export { TimestampNanosLogicalType } from "./schemas/logical/temporal_logical_types.js";
34
+ export { LocalTimestampMillisLogicalType } from "./schemas/logical/temporal_logical_types.js";
35
+ export { LocalTimestampMicrosLogicalType } from "./schemas/logical/temporal_logical_types.js";
36
+ export { LocalTimestampNanosLogicalType } from "./schemas/logical/temporal_logical_types.js";
37
+ export { Resolver } from "./schemas/resolver.js";
38
+ export { ValidationError } from "./schemas/error.js";
39
+ export { safeStringify } from "./schemas/json.js";
40
+ export type { AvroFileParserOptions, AvroHeader, ParsedAvroHeader, } from "./serialization/avro_file_parser.js";
41
+ export type { AvroWriterOptions } from "./serialization/avro_file_writer.js";
42
+ export { AvroFileParser } from "./serialization/avro_file_parser.js";
43
+ export { AvroFileWriter } from "./serialization/avro_file_writer.js";
44
+ export { BLOCK_TYPE, HEADER_TYPE, MAGIC_BYTES, } from "./serialization/avro_constants.js";
45
+ export type { IReadableAndWritableBuffer, IReadableBuffer, IWritableBuffer, } from "./serialization/buffers/buffer.js";
46
+ export { BlobReadableBuffer } from "./serialization/buffers/blob_readable_buffer.js";
47
+ export { InMemoryReadableBuffer, InMemoryWritableBuffer, } from "./serialization/buffers/in_memory_buffer.js";
48
+ export type { IStreamReadableBuffer, IStreamWritableBuffer, } from "./serialization/streams/streams.js";
49
+ export { StreamReadableBuffer } from "./serialization/streams/stream_readable_buffer.js";
50
+ export { StreamWritableBuffer } from "./serialization/streams/stream_writable_buffer.js";
51
+ export { StreamReadableBufferAdapter } from "./serialization/streams/stream_readable_buffer_adapter.js";
52
+ export { StreamWritableBufferAdapter } from "./serialization/streams/stream_writable_buffer_adapter.js";
53
+ export { FixedSizeStreamReadableBufferAdapter } from "./serialization/streams/fixed_size_stream_readable_buffer_adapter.js";
54
+ export { ForwardOnlyStreamReadableBufferAdapter } from "./serialization/streams/forward_only_stream_readable_buffer_adapter.js";
55
+ export type { Encoder } from "./serialization/encoders/encoder.js";
56
+ export type { Decoder } from "./serialization/decoders/decoder.js";
57
+ export { NullEncoder } from "./serialization/encoders/null_encoder.js";
58
+ export { DeflateEncoder } from "./serialization/encoders/deflate_encoder.js";
59
+ export { NullDecoder } from "./serialization/decoders/null_decoder.js";
60
+ export { DeflateDecoder } from "./serialization/decoders/deflate_decoder.js";
61
+ export type { ReadableTapLike, WritableTapLike } from "./serialization/tap.js";
62
+ export { ReadableTap, WritableTap } from "./serialization/tap.js";
63
+ export { decode, encode } from "./serialization/text_encoding.js";
64
+ export { Protocol } from "./rpc/protocol_core.js";
65
+ export { MessageEndpoint } from "./rpc/message_endpoint/base.js";
66
+ export { MessageEmitter, StatelessEmitter, } from "./rpc/message_endpoint/emitter.js";
67
+ export { MessageListener, StatelessListener, } from "./rpc/message_endpoint/listener.js";
68
+ export type { CallRequestEnvelopeOptions, MessageDefinition, MessageTransportOptions, ProtocolDefinition, ProtocolHandlerContext, ProtocolInfo, ProtocolLike, ProtocolOptions, ResolverEntry, } from "./rpc/definitions/protocol_definitions.js";
69
+ export { Message } from "./rpc/definitions/message_definition.js";
70
+ export type { HandshakeRequestInit, HandshakeRequestMessage, HandshakeResponseInit, HandshakeResponseMessage, } from "./rpc/protocol/wire_format/handshake.js";
71
+ export type { CallRequestEnvelope, CallRequestInit, CallRequestMessage, CallResponseEnvelope, CallResponseInit, CallResponseMessage, DecodeCallRequestOptions, DecodeCallResponseOptions, } from "./rpc/protocol/wire_format/messages.js";
72
+ export type { DecodeFramedMessageOptions, DecodeFramedMessageResult, FrameMessageOptions, } from "./rpc/protocol/wire_format/framing.js";
73
+ export type { BinaryDuplex, BinaryDuplexLike, BinaryReadable, BinaryWritable, FetchTransportOptions, WebSocketTransportOptions, } from "./rpc/protocol/transports/transport_helpers.js";
74
+ export type { InMemoryTransportPair } from "./rpc/protocol/transports/in_memory.js";
75
+ export { createFetchTransport } from "./rpc/protocol/transports/fetch.js";
76
+ export { createWebSocketTransport } from "./rpc/protocol/transports/websocket.js";
77
+ export { createInMemoryTransport, createInMemoryTransportPair, } from "./rpc/protocol/transports/in_memory.js";
package/esm/mod.js ADDED
@@ -0,0 +1,73 @@
1
+ // Core Avro functionality
2
+ import "./_dnt.polyfills.js";
3
+ export { AvroReader } from "./avro_reader.js";
4
+ export { AvroWriter } from "./avro_writer.js";
5
+ export { createType } from "./type/create_type.js";
6
+ // Schema types
7
+ export { Type } from "./schemas/type.js";
8
+ export { BaseType } from "./schemas/base_type.js";
9
+ export { PrimitiveType } from "./schemas/primitive/primitive_type.js";
10
+ export { FixedSizeBaseType } from "./schemas/primitive/fixed_size_base_type.js";
11
+ export { NamedType } from "./schemas/complex/named_type.js";
12
+ export { LogicalType, NamedLogicalType, withLogicalTypeJSON, } from "./schemas/logical/logical_type.js";
13
+ // Primitive types
14
+ export { BooleanType } from "./schemas/primitive/boolean_type.js";
15
+ export { IntType } from "./schemas/primitive/int_type.js";
16
+ export { LongType } from "./schemas/primitive/long_type.js";
17
+ export { FloatType } from "./schemas/primitive/float_type.js";
18
+ export { DoubleType } from "./schemas/primitive/double_type.js";
19
+ export { BytesType } from "./schemas/primitive/bytes_type.js";
20
+ export { StringType } from "./schemas/primitive/string_type.js";
21
+ export { NullType } from "./schemas/primitive/null_type.js";
22
+ // Complex types
23
+ export { RecordType } from "./schemas/complex/record_type.js";
24
+ export { ArrayType } from "./schemas/complex/array_type.js";
25
+ export { MapType } from "./schemas/complex/map_type.js";
26
+ export { UnionType } from "./schemas/complex/union_type.js";
27
+ export { EnumType } from "./schemas/complex/enum_type.js";
28
+ export { FixedType } from "./schemas/complex/fixed_type.js";
29
+ // Logical types
30
+ export { UuidLogicalType } from "./schemas/logical/uuid_logical_type.js";
31
+ export { DecimalLogicalType } from "./schemas/logical/decimal_logical_type.js";
32
+ export { DurationLogicalType } from "./schemas/logical/duration_logical_type.js";
33
+ export { DateLogicalType } from "./schemas/logical/temporal_logical_types.js";
34
+ export { TimeMillisLogicalType } from "./schemas/logical/temporal_logical_types.js";
35
+ export { TimeMicrosLogicalType } from "./schemas/logical/temporal_logical_types.js";
36
+ export { TimestampMillisLogicalType } from "./schemas/logical/temporal_logical_types.js";
37
+ export { TimestampMicrosLogicalType } from "./schemas/logical/temporal_logical_types.js";
38
+ export { TimestampNanosLogicalType } from "./schemas/logical/temporal_logical_types.js";
39
+ export { LocalTimestampMillisLogicalType } from "./schemas/logical/temporal_logical_types.js";
40
+ export { LocalTimestampMicrosLogicalType } from "./schemas/logical/temporal_logical_types.js";
41
+ export { LocalTimestampNanosLogicalType } from "./schemas/logical/temporal_logical_types.js";
42
+ // Schema utilities
43
+ export { Resolver } from "./schemas/resolver.js";
44
+ export { ValidationError } from "./schemas/error.js";
45
+ export { safeStringify } from "./schemas/json.js";
46
+ export { AvroFileParser } from "./serialization/avro_file_parser.js";
47
+ export { AvroFileWriter } from "./serialization/avro_file_writer.js";
48
+ export { BLOCK_TYPE, HEADER_TYPE, MAGIC_BYTES, } from "./serialization/avro_constants.js";
49
+ export { BlobReadableBuffer } from "./serialization/buffers/blob_readable_buffer.js";
50
+ export { InMemoryReadableBuffer, InMemoryWritableBuffer, } from "./serialization/buffers/in_memory_buffer.js";
51
+ export { StreamReadableBuffer } from "./serialization/streams/stream_readable_buffer.js";
52
+ export { StreamWritableBuffer } from "./serialization/streams/stream_writable_buffer.js";
53
+ export { StreamReadableBufferAdapter } from "./serialization/streams/stream_readable_buffer_adapter.js";
54
+ export { StreamWritableBufferAdapter } from "./serialization/streams/stream_writable_buffer_adapter.js";
55
+ export { FixedSizeStreamReadableBufferAdapter } from "./serialization/streams/fixed_size_stream_readable_buffer_adapter.js";
56
+ export { ForwardOnlyStreamReadableBufferAdapter } from "./serialization/streams/forward_only_stream_readable_buffer_adapter.js";
57
+ export { NullEncoder } from "./serialization/encoders/null_encoder.js";
58
+ export { DeflateEncoder } from "./serialization/encoders/deflate_encoder.js";
59
+ export { NullDecoder } from "./serialization/decoders/null_decoder.js";
60
+ export { DeflateDecoder } from "./serialization/decoders/deflate_decoder.js";
61
+ export { ReadableTap, WritableTap } from "./serialization/tap.js";
62
+ // Utilities
63
+ export { decode, encode } from "./serialization/text_encoding.js";
64
+ // RPC - Protocols
65
+ export { Protocol } from "./rpc/protocol_core.js";
66
+ // RPC - Message endpoints
67
+ export { MessageEndpoint } from "./rpc/message_endpoint/base.js";
68
+ export { MessageEmitter, StatelessEmitter, } from "./rpc/message_endpoint/emitter.js";
69
+ export { MessageListener, StatelessListener, } from "./rpc/message_endpoint/listener.js";
70
+ export { Message } from "./rpc/definitions/message_definition.js";
71
+ export { createFetchTransport } from "./rpc/protocol/transports/fetch.js";
72
+ export { createWebSocketTransport } from "./rpc/protocol/transports/websocket.js";
73
+ export { createInMemoryTransport, createInMemoryTransportPair, } from "./rpc/protocol/transports/in_memory.js";
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,34 @@
1
+ import { type CreateTypeOptions } from "../../type/create_type.js";
2
+ import type { RecordType } from "../../schemas/complex/record_type.js";
3
+ import type { UnionType } from "../../schemas/complex/union_type.js";
4
+ import type { Type } from "../../schemas/type.js";
5
+ import type { MessageDefinition } from "./protocol_definitions.js";
6
+ /**
7
+ * Schema-aware representation of an Avro RPC message definition including
8
+ * request, response, and error types.
9
+ */
10
+ export declare class Message {
11
+ /** The name of the message. */
12
+ readonly name: string;
13
+ /** Optional documentation for the message. */
14
+ readonly doc?: string;
15
+ /** The record type representing the request parameters. */
16
+ readonly requestType: RecordType;
17
+ /** The type returned by the message (if not one-way). */
18
+ readonly responseType: Type;
19
+ /** The union type of possible errors. */
20
+ readonly errorType: UnionType;
21
+ /** Whether the message is one-way (no response). */
22
+ readonly oneWay: boolean;
23
+ /**
24
+ * Creates a new Message definition.
25
+ * @param name The name of the message.
26
+ * @param attrs The message attributes from the protocol definition.
27
+ * @param opts Options for creating types (namespace, registry).
28
+ */
29
+ constructor(name: string, attrs: MessageDefinition, opts: CreateTypeOptions);
30
+ /**
31
+ * Converts the message definition back to a JSON-compatible object.
32
+ */
33
+ toJSON(): Record<string, unknown>;
34
+ }
@@ -0,0 +1,105 @@
1
+ import { createType } from "../../type/create_type.js";
2
+ import { NullType } from "../../schemas/primitive/null_type.js";
3
+ /**
4
+ * Schema-aware representation of an Avro RPC message definition including
5
+ * request, response, and error types.
6
+ */
7
+ export class Message {
8
+ /**
9
+ * Creates a new Message definition.
10
+ * @param name The name of the message.
11
+ * @param attrs The message attributes from the protocol definition.
12
+ * @param opts Options for creating types (namespace, registry).
13
+ */
14
+ constructor(name, attrs, opts) {
15
+ /** The name of the message. */
16
+ Object.defineProperty(this, "name", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: void 0
21
+ });
22
+ /** Optional documentation for the message. */
23
+ Object.defineProperty(this, "doc", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: void 0
28
+ });
29
+ /** The record type representing the request parameters. */
30
+ Object.defineProperty(this, "requestType", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: void 0
35
+ });
36
+ /** The type returned by the message (if not one-way). */
37
+ Object.defineProperty(this, "responseType", {
38
+ enumerable: true,
39
+ configurable: true,
40
+ writable: true,
41
+ value: void 0
42
+ });
43
+ /** The union type of possible errors. */
44
+ Object.defineProperty(this, "errorType", {
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true,
48
+ value: void 0
49
+ });
50
+ /** Whether the message is one-way (no response). */
51
+ Object.defineProperty(this, "oneWay", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: void 0
56
+ });
57
+ this.name = name;
58
+ this.doc = attrs.doc;
59
+ this.requestType = createType({
60
+ name,
61
+ type: "request",
62
+ fields: attrs.request,
63
+ }, opts);
64
+ if (!attrs.response) {
65
+ throw new Error("missing response");
66
+ }
67
+ this.responseType = createType(attrs.response, opts);
68
+ const errors = attrs.errors ? attrs.errors.slice() : [];
69
+ errors.unshift("string");
70
+ this.errorType = createType(errors, opts);
71
+ this.oneWay = !!attrs["one-way"];
72
+ if (this.oneWay) {
73
+ if (!(this.responseType instanceof NullType)) {
74
+ throw new Error("one-way messages must return 'null'");
75
+ }
76
+ if (this.errorType.getTypes().length > 1) {
77
+ throw new Error("one-way messages cannot declare errors");
78
+ }
79
+ }
80
+ }
81
+ /**
82
+ * Converts the message definition back to a JSON-compatible object.
83
+ */
84
+ toJSON() {
85
+ const json = {
86
+ request: extractRequestFields(this.requestType),
87
+ response: this.responseType.toJSON(),
88
+ };
89
+ if (this.doc) {
90
+ json.doc = this.doc;
91
+ }
92
+ if (this.oneWay) {
93
+ json["one-way"] = true;
94
+ }
95
+ const errors = this.errorType.toJSON();
96
+ if (Array.isArray(errors) && errors.length > 1) {
97
+ json.errors = errors.slice(1);
98
+ }
99
+ return json;
100
+ }
101
+ }
102
+ function extractRequestFields(requestType) {
103
+ const json = requestType.toJSON();
104
+ return json.fields;
105
+ }