@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.
- package/esm/_dnt.polyfills.d.ts +11 -0
- package/esm/_dnt.polyfills.js +15 -0
- package/esm/avro_reader.d.ts +156 -0
- package/esm/avro_reader.js +201 -0
- package/esm/avro_writer.d.ts +75 -0
- package/esm/avro_writer.js +105 -0
- package/esm/internal/collections/array_utils.d.ts +4 -0
- package/esm/internal/collections/array_utils.js +18 -0
- package/esm/internal/collections/circular_buffer.d.ts +48 -0
- package/esm/internal/collections/circular_buffer.js +129 -0
- package/esm/internal/crypto/md5.d.ts +12 -0
- package/esm/internal/crypto/md5.js +158 -0
- package/esm/internal/varint.d.ts +6 -0
- package/esm/internal/varint.js +30 -0
- package/esm/mod.d.ts +77 -0
- package/esm/mod.js +73 -0
- package/esm/package.json +3 -0
- package/esm/rpc/definitions/message_definition.d.ts +34 -0
- package/esm/rpc/definitions/message_definition.js +105 -0
- package/esm/rpc/definitions/protocol_definitions.d.ts +197 -0
- package/esm/rpc/definitions/protocol_definitions.js +1 -0
- package/esm/rpc/message_endpoint/base.d.ts +43 -0
- package/esm/rpc/message_endpoint/base.js +81 -0
- package/esm/rpc/message_endpoint/emitter.d.ts +96 -0
- package/esm/rpc/message_endpoint/emitter.js +245 -0
- package/esm/rpc/message_endpoint/helpers.d.ts +37 -0
- package/esm/rpc/message_endpoint/helpers.js +68 -0
- package/esm/rpc/message_endpoint/listener.d.ts +37 -0
- package/esm/rpc/message_endpoint/listener.js +212 -0
- package/esm/rpc/protocol/frame_assembler.d.ts +11 -0
- package/esm/rpc/protocol/frame_assembler.js +77 -0
- package/esm/rpc/protocol/protocol_helpers.d.ts +59 -0
- package/esm/rpc/protocol/protocol_helpers.js +123 -0
- package/esm/rpc/protocol/transports/fetch.d.ts +9 -0
- package/esm/rpc/protocol/transports/fetch.js +30 -0
- package/esm/rpc/protocol/transports/in_memory.d.ts +27 -0
- package/esm/rpc/protocol/transports/in_memory.js +125 -0
- package/esm/rpc/protocol/transports/transport_helpers.d.ts +118 -0
- package/esm/rpc/protocol/transports/transport_helpers.js +112 -0
- package/esm/rpc/protocol/transports/websocket.d.ts +9 -0
- package/esm/rpc/protocol/transports/websocket.js +102 -0
- package/esm/rpc/protocol/wire_format/framing.d.ts +44 -0
- package/esm/rpc/protocol/wire_format/framing.js +74 -0
- package/esm/rpc/protocol/wire_format/handshake.d.ts +110 -0
- package/esm/rpc/protocol/wire_format/handshake.js +239 -0
- package/esm/rpc/protocol/wire_format/messages.d.ts +192 -0
- package/esm/rpc/protocol/wire_format/messages.js +175 -0
- package/esm/rpc/protocol/wire_format/metadata.d.ts +44 -0
- package/esm/rpc/protocol/wire_format/metadata.js +74 -0
- package/esm/rpc/protocol_core.d.ts +121 -0
- package/esm/rpc/protocol_core.js +285 -0
- package/esm/schemas/base_type.d.ts +41 -0
- package/esm/schemas/base_type.js +49 -0
- package/esm/schemas/complex/array_type.d.ts +100 -0
- package/esm/schemas/complex/array_type.js +299 -0
- package/esm/schemas/complex/enum_type.d.ts +81 -0
- package/esm/schemas/complex/enum_type.js +217 -0
- package/esm/schemas/complex/fixed_type.d.ts +99 -0
- package/esm/schemas/complex/fixed_type.js +208 -0
- package/esm/schemas/complex/map_type.d.ts +97 -0
- package/esm/schemas/complex/map_type.js +290 -0
- package/esm/schemas/complex/named_type.d.ts +30 -0
- package/esm/schemas/complex/named_type.js +57 -0
- package/esm/schemas/complex/record_type.d.ts +165 -0
- package/esm/schemas/complex/record_type.js +547 -0
- package/esm/schemas/complex/resolve_names.d.ts +32 -0
- package/esm/schemas/complex/resolve_names.js +85 -0
- package/esm/schemas/complex/union_type.d.ts +116 -0
- package/esm/schemas/complex/union_type.js +392 -0
- package/esm/schemas/error.d.ts +31 -0
- package/esm/schemas/error.js +67 -0
- package/esm/schemas/json.d.ts +6 -0
- package/esm/schemas/json.js +35 -0
- package/esm/schemas/logical/decimal_logical_type.d.ts +49 -0
- package/esm/schemas/logical/decimal_logical_type.js +145 -0
- package/esm/schemas/logical/duration_logical_type.d.ts +66 -0
- package/esm/schemas/logical/duration_logical_type.js +112 -0
- package/esm/schemas/logical/logical_type.d.ts +138 -0
- package/esm/schemas/logical/logical_type.js +240 -0
- package/esm/schemas/logical/temporal_logical_types.d.ts +215 -0
- package/esm/schemas/logical/temporal_logical_types.js +364 -0
- package/esm/schemas/logical/uuid_logical_type.d.ts +63 -0
- package/esm/schemas/logical/uuid_logical_type.js +146 -0
- package/esm/schemas/primitive/boolean_type.d.ts +49 -0
- package/esm/schemas/primitive/boolean_type.js +75 -0
- package/esm/schemas/primitive/bytes_type.d.ts +49 -0
- package/esm/schemas/primitive/bytes_type.js +136 -0
- package/esm/schemas/primitive/double_type.d.ts +38 -0
- package/esm/schemas/primitive/double_type.js +98 -0
- package/esm/schemas/primitive/fixed_size_base_type.d.ts +28 -0
- package/esm/schemas/primitive/fixed_size_base_type.js +33 -0
- package/esm/schemas/primitive/float_type.d.ts +38 -0
- package/esm/schemas/primitive/float_type.js +88 -0
- package/esm/schemas/primitive/int_type.d.ts +31 -0
- package/esm/schemas/primitive/int_type.js +63 -0
- package/esm/schemas/primitive/long_type.d.ts +36 -0
- package/esm/schemas/primitive/long_type.js +95 -0
- package/esm/schemas/primitive/null_type.d.ts +45 -0
- package/esm/schemas/primitive/null_type.js +71 -0
- package/esm/schemas/primitive/primitive_type.d.ts +17 -0
- package/esm/schemas/primitive/primitive_type.js +27 -0
- package/esm/schemas/primitive/string_type.d.ts +34 -0
- package/esm/schemas/primitive/string_type.js +81 -0
- package/esm/schemas/resolver.d.ts +25 -0
- package/esm/schemas/resolver.js +25 -0
- package/esm/schemas/type.d.ts +101 -0
- package/esm/schemas/type.js +6 -0
- package/esm/serialization/avro_constants.d.ts +13 -0
- package/esm/serialization/avro_constants.js +29 -0
- package/esm/serialization/avro_file_parser.d.ts +68 -0
- package/esm/serialization/avro_file_parser.js +191 -0
- package/esm/serialization/avro_file_writer.d.ts +63 -0
- package/esm/serialization/avro_file_writer.js +235 -0
- package/esm/serialization/buffers/blob_readable_buffer.d.ts +53 -0
- package/esm/serialization/buffers/blob_readable_buffer.js +80 -0
- package/esm/serialization/buffers/buffer.d.ts +37 -0
- package/esm/serialization/buffers/buffer.js +1 -0
- package/esm/serialization/buffers/in_memory_buffer.d.ts +121 -0
- package/esm/serialization/buffers/in_memory_buffer.js +206 -0
- package/esm/serialization/clamp.d.ts +10 -0
- package/esm/serialization/clamp.js +19 -0
- package/esm/serialization/compare_bytes.d.ts +9 -0
- package/esm/serialization/compare_bytes.js +45 -0
- package/esm/serialization/conversion.d.ts +8 -0
- package/esm/serialization/conversion.js +15 -0
- package/esm/serialization/decoders/decoder.d.ts +16 -0
- package/esm/serialization/decoders/decoder.js +1 -0
- package/esm/serialization/decoders/deflate_decoder.d.ts +15 -0
- package/esm/serialization/decoders/deflate_decoder.js +26 -0
- package/esm/serialization/decoders/null_decoder.d.ts +12 -0
- package/esm/serialization/decoders/null_decoder.js +13 -0
- package/esm/serialization/encoders/deflate_encoder.d.ts +15 -0
- package/esm/serialization/encoders/deflate_encoder.js +26 -0
- package/esm/serialization/encoders/encoder.d.ts +16 -0
- package/esm/serialization/encoders/encoder.js +1 -0
- package/esm/serialization/encoders/null_encoder.d.ts +12 -0
- package/esm/serialization/encoders/null_encoder.js +13 -0
- package/esm/serialization/manipulate_bytes.d.ts +6 -0
- package/esm/serialization/manipulate_bytes.js +13 -0
- package/esm/serialization/read_uint_le.d.ts +4 -0
- package/esm/serialization/read_uint_le.js +14 -0
- package/esm/serialization/streams/fixed_size_stream_readable_buffer_adapter.d.ts +52 -0
- package/esm/serialization/streams/fixed_size_stream_readable_buffer_adapter.js +129 -0
- package/esm/serialization/streams/forward_only_stream_readable_buffer_adapter.d.ts +36 -0
- package/esm/serialization/streams/forward_only_stream_readable_buffer_adapter.js +114 -0
- package/esm/serialization/streams/stream_readable_buffer.d.ts +41 -0
- package/esm/serialization/streams/stream_readable_buffer.js +64 -0
- package/esm/serialization/streams/stream_readable_buffer_adapter.d.ts +38 -0
- package/esm/serialization/streams/stream_readable_buffer_adapter.js +105 -0
- package/esm/serialization/streams/stream_writable_buffer.d.ts +42 -0
- package/esm/serialization/streams/stream_writable_buffer.js +64 -0
- package/esm/serialization/streams/stream_writable_buffer_adapter.d.ts +36 -0
- package/esm/serialization/streams/stream_writable_buffer_adapter.js +65 -0
- package/esm/serialization/streams/streams.d.ts +29 -0
- package/esm/serialization/streams/streams.js +1 -0
- package/esm/serialization/tap.d.ts +427 -0
- package/esm/serialization/tap.js +605 -0
- package/esm/serialization/text_encoding.d.ts +12 -0
- package/esm/serialization/text_encoding.js +14 -0
- package/esm/type/create_type.d.ts +54 -0
- package/esm/type/create_type.js +401 -0
- package/package.json +33 -0
- package/sachitv-avro-typescript-0.4.0.tgz +0 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { IReadableBuffer, IWritableBuffer } from "./buffer.js";
|
|
2
|
+
/**
|
|
3
|
+
* Shared strict in-memory buffer base with common functionality.
|
|
4
|
+
*/
|
|
5
|
+
export declare abstract class InMemoryBufferBase {
|
|
6
|
+
/** The underlying Uint8Array view of the buffer. */
|
|
7
|
+
protected readonly view: Uint8Array;
|
|
8
|
+
/**
|
|
9
|
+
* Constructs an InMemoryBufferBase with the given ArrayBuffer.
|
|
10
|
+
* @param buf The ArrayBuffer to create the view from.
|
|
11
|
+
*/
|
|
12
|
+
constructor(buf: ArrayBuffer);
|
|
13
|
+
/**
|
|
14
|
+
* Returns the length of the buffer in bytes.
|
|
15
|
+
* @returns The length of the buffer.
|
|
16
|
+
*/
|
|
17
|
+
length(): Promise<number>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Strict read-only in-memory buffer for serialization reads.
|
|
21
|
+
* Throws errors on all out-of-bounds operations.
|
|
22
|
+
*
|
|
23
|
+
* Key features:
|
|
24
|
+
* - Fixed size: The buffer size is determined at construction and cannot be resized.
|
|
25
|
+
* - Random access: Supports reading at arbitrary byte offsets.
|
|
26
|
+
* - Strict bounds checking: Operations that exceed buffer bounds throw RangeError.
|
|
27
|
+
* - Efficient: Uses Uint8Array for fast byte-level operations.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const arrayBuffer = new ArrayBuffer(1024);
|
|
32
|
+
* const buffer = new StrictInMemoryReadableBuffer(arrayBuffer);
|
|
33
|
+
*
|
|
34
|
+
* // Read some data
|
|
35
|
+
* const data = await buffer.read(0, 4); // Returns Uint8Array of 4 bytes
|
|
36
|
+
*
|
|
37
|
+
* // This will throw:
|
|
38
|
+
* await buffer.read(1020, 10); // RangeError: Operation exceeds buffer bounds
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare class InMemoryReadableBuffer extends InMemoryBufferBase implements IReadableBuffer {
|
|
42
|
+
/**
|
|
43
|
+
* Checks if the offset and size are within buffer bounds.
|
|
44
|
+
* @param offset The starting offset.
|
|
45
|
+
* @param size The number of bytes to check.
|
|
46
|
+
*/
|
|
47
|
+
private checkBounds;
|
|
48
|
+
/**
|
|
49
|
+
* Reads a portion of the buffer.
|
|
50
|
+
* @param offset The starting offset.
|
|
51
|
+
* @param size The number of bytes to read.
|
|
52
|
+
* @returns A Uint8Array containing the read bytes.
|
|
53
|
+
*/
|
|
54
|
+
read(offset: number, size: number): Promise<Uint8Array>;
|
|
55
|
+
/**
|
|
56
|
+
* Checks if more data can be read starting at the given offset.
|
|
57
|
+
* @param offset The byte offset to check.
|
|
58
|
+
* @returns True if at least one byte can be read from the offset.
|
|
59
|
+
*/
|
|
60
|
+
canReadMore(offset: number): Promise<boolean>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Strict write-only in-memory buffer for serialization writes.
|
|
64
|
+
* Throws errors when attempting to write beyond buffer bounds.
|
|
65
|
+
*
|
|
66
|
+
* Key features:
|
|
67
|
+
* - Fixed size: The buffer size is determined at construction and cannot be resized.
|
|
68
|
+
* - Sequential writes: Maintains an internal offset that advances with each write.
|
|
69
|
+
* - Strict bounds checking: Throws RangeError when write would exceed buffer capacity.
|
|
70
|
+
* - Efficient: Uses Uint8Array for fast byte-level operations.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const arrayBuffer = new ArrayBuffer(1024);
|
|
75
|
+
* const buffer = new StrictInMemoryWritableBuffer(arrayBuffer);
|
|
76
|
+
*
|
|
77
|
+
* // Write some data
|
|
78
|
+
* await buffer.appendBytes(new Uint8Array([1, 2, 3, 4]));
|
|
79
|
+
*
|
|
80
|
+
* // This will throw if buffer is full:
|
|
81
|
+
* await buffer.appendBytes(new Uint8Array(2000)); // RangeError: Write operation exceeds buffer bounds
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare class InMemoryWritableBuffer extends InMemoryBufferBase implements IWritableBuffer {
|
|
85
|
+
#private;
|
|
86
|
+
/**
|
|
87
|
+
* Creates a new writable buffer with the specified ArrayBuffer and initial offset.
|
|
88
|
+
* @param buf The underlying ArrayBuffer to write to.
|
|
89
|
+
* @param offset The starting offset within the buffer (default: 0).
|
|
90
|
+
*/
|
|
91
|
+
constructor(buf: ArrayBuffer, offset?: number);
|
|
92
|
+
/**
|
|
93
|
+
* Checks if writing the given data at the specified offset would exceed buffer bounds.
|
|
94
|
+
* Throws a RangeError if the operation would exceed bounds.
|
|
95
|
+
* @param offset The offset to write at.
|
|
96
|
+
* @param data The data to write.
|
|
97
|
+
*/
|
|
98
|
+
protected checkWriteBounds(offset: number, data: Uint8Array): void;
|
|
99
|
+
/**
|
|
100
|
+
* Appends the given bytes to the buffer at the current offset and advances the offset.
|
|
101
|
+
* @param data The bytes to append.
|
|
102
|
+
*/
|
|
103
|
+
appendBytes(data: Uint8Array): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Checks if the buffer is in a valid state.
|
|
106
|
+
* Always returns true as this buffer throws on overflow instead of becoming invalid.
|
|
107
|
+
* @returns Always true.
|
|
108
|
+
*/
|
|
109
|
+
isValid(): Promise<boolean>;
|
|
110
|
+
/**
|
|
111
|
+
* Checks if the buffer can accept appending the given number of bytes.
|
|
112
|
+
* @param size The number of bytes to check.
|
|
113
|
+
* @returns True if the buffer can accept the append.
|
|
114
|
+
*/
|
|
115
|
+
canAppendMore(_size: number): Promise<boolean>;
|
|
116
|
+
/**
|
|
117
|
+
* Gets a copy of the buffer containing only the bytes written to the buffer.
|
|
118
|
+
* @returns An ArrayBuffer containing only the written data.
|
|
119
|
+
*/
|
|
120
|
+
getBufferCopy(): ArrayBuffer;
|
|
121
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
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 _InMemoryWritableBuffer_offset, _InMemoryWritableBuffer_initialOffset;
|
|
13
|
+
/**
|
|
14
|
+
* Shared strict in-memory buffer base with common functionality.
|
|
15
|
+
*/
|
|
16
|
+
export class InMemoryBufferBase {
|
|
17
|
+
/**
|
|
18
|
+
* Constructs an InMemoryBufferBase with the given ArrayBuffer.
|
|
19
|
+
* @param buf The ArrayBuffer to create the view from.
|
|
20
|
+
*/
|
|
21
|
+
constructor(buf) {
|
|
22
|
+
/** The underlying Uint8Array view of the buffer. */
|
|
23
|
+
Object.defineProperty(this, "view", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
this.view = new Uint8Array(buf);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Returns the length of the buffer in bytes.
|
|
33
|
+
* @returns The length of the buffer.
|
|
34
|
+
*/
|
|
35
|
+
// deno-lint-ignore require-await
|
|
36
|
+
async length() {
|
|
37
|
+
return this.view.length;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Strict read-only in-memory buffer for serialization reads.
|
|
42
|
+
* Throws errors on all out-of-bounds operations.
|
|
43
|
+
*
|
|
44
|
+
* Key features:
|
|
45
|
+
* - Fixed size: The buffer size is determined at construction and cannot be resized.
|
|
46
|
+
* - Random access: Supports reading at arbitrary byte offsets.
|
|
47
|
+
* - Strict bounds checking: Operations that exceed buffer bounds throw RangeError.
|
|
48
|
+
* - Efficient: Uses Uint8Array for fast byte-level operations.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const arrayBuffer = new ArrayBuffer(1024);
|
|
53
|
+
* const buffer = new StrictInMemoryReadableBuffer(arrayBuffer);
|
|
54
|
+
*
|
|
55
|
+
* // Read some data
|
|
56
|
+
* const data = await buffer.read(0, 4); // Returns Uint8Array of 4 bytes
|
|
57
|
+
*
|
|
58
|
+
* // This will throw:
|
|
59
|
+
* await buffer.read(1020, 10); // RangeError: Operation exceeds buffer bounds
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export class InMemoryReadableBuffer extends InMemoryBufferBase {
|
|
63
|
+
/**
|
|
64
|
+
* Checks if the offset and size are within buffer bounds.
|
|
65
|
+
* @param offset The starting offset.
|
|
66
|
+
* @param size The number of bytes to check.
|
|
67
|
+
*/
|
|
68
|
+
checkBounds(offset, size) {
|
|
69
|
+
if (offset < 0 || size < 0) {
|
|
70
|
+
throw new RangeError(`Offset and size must be non-negative. Got offset=${offset}, size=${size}`);
|
|
71
|
+
}
|
|
72
|
+
if (offset + size > this.view.length) {
|
|
73
|
+
throw new RangeError(`Operation exceeds buffer bounds. offset=${offset}, size=${size}, bufferLength=${this.view.length}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Reads a portion of the buffer.
|
|
78
|
+
* @param offset The starting offset.
|
|
79
|
+
* @param size The number of bytes to read.
|
|
80
|
+
* @returns A Uint8Array containing the read bytes.
|
|
81
|
+
*/
|
|
82
|
+
// deno-lint-ignore require-await
|
|
83
|
+
async read(offset, size) {
|
|
84
|
+
this.checkBounds(offset, size);
|
|
85
|
+
return this.view.slice(offset, offset + size);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Checks if more data can be read starting at the given offset.
|
|
89
|
+
* @param offset The byte offset to check.
|
|
90
|
+
* @returns True if at least one byte can be read from the offset.
|
|
91
|
+
*/
|
|
92
|
+
// deno-lint-ignore require-await
|
|
93
|
+
async canReadMore(offset) {
|
|
94
|
+
try {
|
|
95
|
+
this.checkBounds(offset, 1);
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Strict write-only in-memory buffer for serialization writes.
|
|
105
|
+
* Throws errors when attempting to write beyond buffer bounds.
|
|
106
|
+
*
|
|
107
|
+
* Key features:
|
|
108
|
+
* - Fixed size: The buffer size is determined at construction and cannot be resized.
|
|
109
|
+
* - Sequential writes: Maintains an internal offset that advances with each write.
|
|
110
|
+
* - Strict bounds checking: Throws RangeError when write would exceed buffer capacity.
|
|
111
|
+
* - Efficient: Uses Uint8Array for fast byte-level operations.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const arrayBuffer = new ArrayBuffer(1024);
|
|
116
|
+
* const buffer = new StrictInMemoryWritableBuffer(arrayBuffer);
|
|
117
|
+
*
|
|
118
|
+
* // Write some data
|
|
119
|
+
* await buffer.appendBytes(new Uint8Array([1, 2, 3, 4]));
|
|
120
|
+
*
|
|
121
|
+
* // This will throw if buffer is full:
|
|
122
|
+
* await buffer.appendBytes(new Uint8Array(2000)); // RangeError: Write operation exceeds buffer bounds
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export class InMemoryWritableBuffer extends InMemoryBufferBase {
|
|
126
|
+
/**
|
|
127
|
+
* Creates a new writable buffer with the specified ArrayBuffer and initial offset.
|
|
128
|
+
* @param buf The underlying ArrayBuffer to write to.
|
|
129
|
+
* @param offset The starting offset within the buffer (default: 0).
|
|
130
|
+
*/
|
|
131
|
+
constructor(buf, offset = 0) {
|
|
132
|
+
super(buf);
|
|
133
|
+
_InMemoryWritableBuffer_offset.set(this, void 0);
|
|
134
|
+
_InMemoryWritableBuffer_initialOffset.set(this, void 0);
|
|
135
|
+
if (offset < 0 || offset > this.view.length) {
|
|
136
|
+
throw new RangeError(`Initial offset must be within buffer bounds. Got offset=${offset}, bufferLength=${this.view.length}`);
|
|
137
|
+
}
|
|
138
|
+
__classPrivateFieldSet(this, _InMemoryWritableBuffer_initialOffset, offset, "f");
|
|
139
|
+
__classPrivateFieldSet(this, _InMemoryWritableBuffer_offset, offset, "f");
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Checks if writing the given data at the specified offset would exceed buffer bounds.
|
|
143
|
+
* Throws a RangeError if the operation would exceed bounds.
|
|
144
|
+
* @param offset The offset to write at.
|
|
145
|
+
* @param data The data to write.
|
|
146
|
+
*/
|
|
147
|
+
checkWriteBounds(offset, data) {
|
|
148
|
+
if (offset < 0) {
|
|
149
|
+
throw new RangeError(`Offset must be non-negative. Got offset=${offset}`);
|
|
150
|
+
}
|
|
151
|
+
if (offset + data.length > this.view.length) {
|
|
152
|
+
throw new RangeError(`Write operation exceeds buffer bounds. offset=${offset}, dataSize=${data.length}, bufferLength=${this.view.length}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Appends the given bytes to the buffer at the current offset and advances the offset.
|
|
157
|
+
* @param data The bytes to append.
|
|
158
|
+
*/
|
|
159
|
+
// deno-lint-ignore require-await
|
|
160
|
+
async appendBytes(data) {
|
|
161
|
+
this.checkWriteBounds(__classPrivateFieldGet(this, _InMemoryWritableBuffer_offset, "f"), data);
|
|
162
|
+
if (data.length === 0) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
this.view.set(data, __classPrivateFieldGet(this, _InMemoryWritableBuffer_offset, "f"));
|
|
166
|
+
__classPrivateFieldSet(this, _InMemoryWritableBuffer_offset, __classPrivateFieldGet(this, _InMemoryWritableBuffer_offset, "f") + data.length, "f");
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Checks if the buffer is in a valid state.
|
|
170
|
+
* Always returns true as this buffer throws on overflow instead of becoming invalid.
|
|
171
|
+
* @returns Always true.
|
|
172
|
+
*/
|
|
173
|
+
// deno-lint-ignore require-await
|
|
174
|
+
async isValid() {
|
|
175
|
+
return true; // Always valid since we throw on overflow instead of marking as invalid
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Checks if the buffer can accept appending the given number of bytes.
|
|
179
|
+
* @param size The number of bytes to check.
|
|
180
|
+
* @returns True if the buffer can accept the append.
|
|
181
|
+
*/
|
|
182
|
+
async canAppendMore(_size) {
|
|
183
|
+
return await this.isValid();
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* @internal Test-only function to get the current write offset position.
|
|
187
|
+
*/
|
|
188
|
+
_testOnlyOffset() {
|
|
189
|
+
return __classPrivateFieldGet(this, _InMemoryWritableBuffer_offset, "f");
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* @internal Test-only function to get the remaining space in the buffer.
|
|
193
|
+
*/
|
|
194
|
+
_testOnlyRemaining() {
|
|
195
|
+
return this.view.length - __classPrivateFieldGet(this, _InMemoryWritableBuffer_offset, "f");
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Gets a copy of the buffer containing only the bytes written to the buffer.
|
|
199
|
+
* @returns An ArrayBuffer containing only the written data.
|
|
200
|
+
*/
|
|
201
|
+
getBufferCopy() {
|
|
202
|
+
const sliced = this.view.slice(__classPrivateFieldGet(this, _InMemoryWritableBuffer_initialOffset, "f"), __classPrivateFieldGet(this, _InMemoryWritableBuffer_offset, "f"));
|
|
203
|
+
return sliced.buffer.slice(sliced.byteOffset, sliced.byteOffset + sliced.length);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
_InMemoryWritableBuffer_offset = new WeakMap(), _InMemoryWritableBuffer_initialOffset = new WeakMap();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clamps a requested length for a DataView based on its byte length and an offset.
|
|
3
|
+
* Ensures the returned length does not exceed the available bytes in the view from the offset.
|
|
4
|
+
*
|
|
5
|
+
* @param view The DataView to clamp the length for.
|
|
6
|
+
* @param offset The starting offset within the DataView.
|
|
7
|
+
* @param length The requested length.
|
|
8
|
+
* @returns The clamped length.
|
|
9
|
+
*/
|
|
10
|
+
export declare function clampLengthForView(view: DataView, offset: number, length: number): number;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clamps a requested length for a DataView based on its byte length and an offset.
|
|
3
|
+
* Ensures the returned length does not exceed the available bytes in the view from the offset.
|
|
4
|
+
*
|
|
5
|
+
* @param view The DataView to clamp the length for.
|
|
6
|
+
* @param offset The starting offset within the DataView.
|
|
7
|
+
* @param length The requested length.
|
|
8
|
+
* @returns The clamped length.
|
|
9
|
+
*/
|
|
10
|
+
export function clampLengthForView(view, offset, length) {
|
|
11
|
+
if (offset >= view.byteLength) {
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
const available = view.byteLength - offset;
|
|
15
|
+
if (length <= 0) {
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
return length > available ? available : length;
|
|
19
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compares two Uint8Array objects.
|
|
3
|
+
* Returns a negative value if a is less than b, a positive value if a is greater than b,
|
|
4
|
+
* and 0 if they are equal.
|
|
5
|
+
* @param a The first Uint8Array to compare.
|
|
6
|
+
* @param b The second Uint8Array to compare.
|
|
7
|
+
* @returns A negative, positive, or zero number indicating the comparison result.
|
|
8
|
+
*/
|
|
9
|
+
export declare function compareUint8Arrays(a: Uint8Array, b: Uint8Array): number;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { clampLengthForView } from "./clamp.js";
|
|
2
|
+
/**
|
|
3
|
+
* Compares two byte ranges from DataView objects.
|
|
4
|
+
* Returns a negative value if viewA is less than viewB, a positive value if viewA is greater than viewB,
|
|
5
|
+
* and 0 if they are equal.
|
|
6
|
+
* @param viewA The first DataView to compare.
|
|
7
|
+
* @param offsetA The starting offset in viewA.
|
|
8
|
+
* @param lengthA The length of the byte range in viewA.
|
|
9
|
+
* @param viewB The second DataView to compare.
|
|
10
|
+
* @param offsetB The starting offset in viewB.
|
|
11
|
+
* @param lengthB The length of the byte range in viewB.
|
|
12
|
+
* @returns A negative, positive, or zero number indicating the comparison result.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export function _compareByteRanges(viewA, offsetA, lengthA, viewB, offsetB, lengthB) {
|
|
16
|
+
const safeOffsetA = offsetA >= 0 ? offsetA : 0;
|
|
17
|
+
const safeOffsetB = offsetB >= 0 ? offsetB : 0;
|
|
18
|
+
const clampedLengthA = clampLengthForView(viewA, safeOffsetA, lengthA);
|
|
19
|
+
const clampedLengthB = clampLengthForView(viewB, safeOffsetB, lengthB);
|
|
20
|
+
const len = Math.min(clampedLengthA, clampedLengthB);
|
|
21
|
+
for (let i = 0; i < len; i++) {
|
|
22
|
+
const diff = viewA.getUint8(safeOffsetA + i) -
|
|
23
|
+
viewB.getUint8(safeOffsetB + i);
|
|
24
|
+
if (diff !== 0) {
|
|
25
|
+
return diff < 0 ? -1 : 1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (clampedLengthA === clampedLengthB) {
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
return clampedLengthA < clampedLengthB ? -1 : 1;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Compares two Uint8Array objects.
|
|
35
|
+
* Returns a negative value if a is less than b, a positive value if a is greater than b,
|
|
36
|
+
* and 0 if they are equal.
|
|
37
|
+
* @param a The first Uint8Array to compare.
|
|
38
|
+
* @param b The second Uint8Array to compare.
|
|
39
|
+
* @returns A negative, positive, or zero number indicating the comparison result.
|
|
40
|
+
*/
|
|
41
|
+
export function compareUint8Arrays(a, b) {
|
|
42
|
+
const viewA = new DataView(a.buffer, a.byteOffset, a.byteLength);
|
|
43
|
+
const viewB = new DataView(b.buffer, b.byteOffset, b.byteLength);
|
|
44
|
+
return _compareByteRanges(viewA, 0, a.length, viewB, 0, b.length);
|
|
45
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a bigint to a number, throwing a RangeError if the bigint is outside the safe integer range.
|
|
3
|
+
* @param value The bigint to convert.
|
|
4
|
+
* @param context A string describing the context of the conversion, used in the error message if an error occurs.
|
|
5
|
+
* @returns The converted number.
|
|
6
|
+
* @throws {RangeError} if the bigint is outside the safe integer range.
|
|
7
|
+
*/
|
|
8
|
+
export declare function bigIntToSafeNumber(value: bigint, context: string): number;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const MAX_SAFE_INTEGER_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
|
|
2
|
+
const MIN_SAFE_INTEGER_BIGINT = BigInt(Number.MIN_SAFE_INTEGER);
|
|
3
|
+
/**
|
|
4
|
+
* Converts a bigint to a number, throwing a RangeError if the bigint is outside the safe integer range.
|
|
5
|
+
* @param value The bigint to convert.
|
|
6
|
+
* @param context A string describing the context of the conversion, used in the error message if an error occurs.
|
|
7
|
+
* @returns The converted number.
|
|
8
|
+
* @throws {RangeError} if the bigint is outside the safe integer range.
|
|
9
|
+
*/
|
|
10
|
+
export function bigIntToSafeNumber(value, context) {
|
|
11
|
+
if (value > MAX_SAFE_INTEGER_BIGINT || value < MIN_SAFE_INTEGER_BIGINT) {
|
|
12
|
+
throw new RangeError(`${context} is outside the safe integer range.`);
|
|
13
|
+
}
|
|
14
|
+
return Number(value);
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for custom Avro codec decoders.
|
|
3
|
+
*/
|
|
4
|
+
export interface Decoder {
|
|
5
|
+
/**
|
|
6
|
+
* Decompresses the given data using the codec's algorithm.
|
|
7
|
+
*
|
|
8
|
+
* @param compressedData The compressed data from the Avro file block
|
|
9
|
+
* @returns Promise that resolves to the decompressed data
|
|
10
|
+
*/
|
|
11
|
+
decode(compressedData: Uint8Array): Promise<Uint8Array>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Registry of codec name to decoder implementation.
|
|
15
|
+
*/
|
|
16
|
+
export type DecoderRegistry = Record<string, Decoder>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Decoder } from "./decoder.js";
|
|
2
|
+
/**
|
|
3
|
+
* Built-in deflate decoder using modern web standards.
|
|
4
|
+
*
|
|
5
|
+
* Uses the 'deflate-raw' format which corresponds to RFC 1951 as specified
|
|
6
|
+
* in the Avro specification (no zlib header or checksum).
|
|
7
|
+
*/
|
|
8
|
+
export declare class DeflateDecoder implements Decoder {
|
|
9
|
+
/**
|
|
10
|
+
* Decodes data that was compressed with the deflate algorithm.
|
|
11
|
+
* @param compressedData The compressed data.
|
|
12
|
+
* @returns The decompressed data.
|
|
13
|
+
*/
|
|
14
|
+
decode(compressedData: Uint8Array): Promise<Uint8Array>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in deflate decoder using modern web standards.
|
|
3
|
+
*
|
|
4
|
+
* Uses the 'deflate-raw' format which corresponds to RFC 1951 as specified
|
|
5
|
+
* in the Avro specification (no zlib header or checksum).
|
|
6
|
+
*/
|
|
7
|
+
export class DeflateDecoder {
|
|
8
|
+
/**
|
|
9
|
+
* Decodes data that was compressed with the deflate algorithm.
|
|
10
|
+
* @param compressedData The compressed data.
|
|
11
|
+
* @returns The decompressed data.
|
|
12
|
+
*/
|
|
13
|
+
async decode(compressedData) {
|
|
14
|
+
if (typeof DecompressionStream === "undefined") {
|
|
15
|
+
throw new Error("Deflate codec not supported in this environment. DecompressionStream API required.");
|
|
16
|
+
}
|
|
17
|
+
const stream = new ReadableStream({
|
|
18
|
+
start(controller) {
|
|
19
|
+
controller.enqueue(compressedData);
|
|
20
|
+
controller.close();
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
const decompressed = await new Response(stream.pipeThrough(new DecompressionStream("deflate-raw"))).arrayBuffer();
|
|
24
|
+
return new Uint8Array(decompressed);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Decoder } from "./decoder.js";
|
|
2
|
+
/**
|
|
3
|
+
* Built-in null decoder (no compression).
|
|
4
|
+
*/
|
|
5
|
+
export declare class NullDecoder implements Decoder {
|
|
6
|
+
/**
|
|
7
|
+
* Decodes data by passing it through unchanged.
|
|
8
|
+
* @param compressedData The data to decode.
|
|
9
|
+
* @returns The decoded (uncompressed) data.
|
|
10
|
+
*/
|
|
11
|
+
decode(compressedData: Uint8Array): Promise<Uint8Array>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in null decoder (no compression).
|
|
3
|
+
*/
|
|
4
|
+
export class NullDecoder {
|
|
5
|
+
/**
|
|
6
|
+
* Decodes data by passing it through unchanged.
|
|
7
|
+
* @param compressedData The data to decode.
|
|
8
|
+
* @returns The decoded (uncompressed) data.
|
|
9
|
+
*/
|
|
10
|
+
decode(compressedData) {
|
|
11
|
+
return Promise.resolve(compressedData);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Encoder } from "./encoder.js";
|
|
2
|
+
/**
|
|
3
|
+
* Built-in deflate encoder using modern web standards.
|
|
4
|
+
*
|
|
5
|
+
* Uses the 'deflate-raw' format which corresponds to RFC 1951 as specified
|
|
6
|
+
* in the Avro specification (no zlib header or checksum).
|
|
7
|
+
*/
|
|
8
|
+
export declare class DeflateEncoder implements Encoder {
|
|
9
|
+
/**
|
|
10
|
+
* Encodes data using the deflate algorithm.
|
|
11
|
+
* @param uncompressedData The data to compress.
|
|
12
|
+
* @returns The compressed data.
|
|
13
|
+
*/
|
|
14
|
+
encode(uncompressedData: Uint8Array): Promise<Uint8Array>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in deflate encoder using modern web standards.
|
|
3
|
+
*
|
|
4
|
+
* Uses the 'deflate-raw' format which corresponds to RFC 1951 as specified
|
|
5
|
+
* in the Avro specification (no zlib header or checksum).
|
|
6
|
+
*/
|
|
7
|
+
export class DeflateEncoder {
|
|
8
|
+
/**
|
|
9
|
+
* Encodes data using the deflate algorithm.
|
|
10
|
+
* @param uncompressedData The data to compress.
|
|
11
|
+
* @returns The compressed data.
|
|
12
|
+
*/
|
|
13
|
+
async encode(uncompressedData) {
|
|
14
|
+
if (typeof CompressionStream === "undefined") {
|
|
15
|
+
throw new Error("Deflate codec not supported in this environment. CompressionStream API required.");
|
|
16
|
+
}
|
|
17
|
+
const stream = new ReadableStream({
|
|
18
|
+
start(controller) {
|
|
19
|
+
controller.enqueue(uncompressedData);
|
|
20
|
+
controller.close();
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
const compressed = await new Response(stream.pipeThrough(new CompressionStream("deflate-raw"))).arrayBuffer();
|
|
24
|
+
return new Uint8Array(compressed);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for custom Avro codec encoders.
|
|
3
|
+
*/
|
|
4
|
+
export interface Encoder {
|
|
5
|
+
/**
|
|
6
|
+
* Compresses the given data using the codec's algorithm.
|
|
7
|
+
*
|
|
8
|
+
* @param uncompressedData The raw block data that should be compressed
|
|
9
|
+
* @returns Promise that resolves to the compressed data
|
|
10
|
+
*/
|
|
11
|
+
encode(uncompressedData: Uint8Array): Promise<Uint8Array>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Registry of codec name to encoder implementation.
|
|
15
|
+
*/
|
|
16
|
+
export type EncoderRegistry = Record<string, Encoder>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Encoder } from "./encoder.js";
|
|
2
|
+
/**
|
|
3
|
+
* Built-in null encoder (no compression).
|
|
4
|
+
*/
|
|
5
|
+
export declare class NullEncoder implements Encoder {
|
|
6
|
+
/**
|
|
7
|
+
* Encodes data by passing it through unchanged.
|
|
8
|
+
* @param uncompressedData The data to encode.
|
|
9
|
+
* @returns The encoded (uncompressed) data.
|
|
10
|
+
*/
|
|
11
|
+
encode(uncompressedData: Uint8Array): Promise<Uint8Array>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in null encoder (no compression).
|
|
3
|
+
*/
|
|
4
|
+
export class NullEncoder {
|
|
5
|
+
/**
|
|
6
|
+
* Encodes data by passing it through unchanged.
|
|
7
|
+
* @param uncompressedData The data to encode.
|
|
8
|
+
* @returns The encoded (uncompressed) data.
|
|
9
|
+
*/
|
|
10
|
+
encode(uncompressedData) {
|
|
11
|
+
return Promise.resolve(uncompressedData);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inverts the bits of the bytes in a Uint8Array up to a specified length.
|
|
3
|
+
* @param arr The Uint8Array to invert.
|
|
4
|
+
* @param len The number of bytes to invert from the beginning of the array.
|
|
5
|
+
*/
|
|
6
|
+
export declare function invert(arr: Uint8Array, len: number): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inverts the bits of the bytes in a Uint8Array up to a specified length.
|
|
3
|
+
* @param arr The Uint8Array to invert.
|
|
4
|
+
* @param len The number of bytes to invert from the beginning of the array.
|
|
5
|
+
*/
|
|
6
|
+
export function invert(arr, len) {
|
|
7
|
+
const view = new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
8
|
+
let remaining = Math.min(Math.max(len, 0), arr.length);
|
|
9
|
+
while (remaining--) {
|
|
10
|
+
const current = view.getUint8(remaining);
|
|
11
|
+
view.setUint8(remaining, (~current) & 0xff);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads an unsigned little-endian integer from a buffer at a specified offset and byte length.
|
|
3
|
+
*/
|
|
4
|
+
export function readUIntLE(view, offset, byteLength) {
|
|
5
|
+
let value = 0;
|
|
6
|
+
for (let i = 0; i < byteLength; i++) {
|
|
7
|
+
const index = offset + i;
|
|
8
|
+
if (index >= view.byteLength) {
|
|
9
|
+
break;
|
|
10
|
+
}
|
|
11
|
+
value |= view.getUint8(index) << (8 * i);
|
|
12
|
+
}
|
|
13
|
+
return value >>> 0;
|
|
14
|
+
}
|