@sachitv/avro-typescript 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/avro_reader_sync.d.ts +48 -0
- package/esm/avro_reader_sync.js +79 -0
- package/esm/avro_writer_sync.d.ts +28 -0
- package/esm/avro_writer_sync.js +63 -0
- package/esm/internal/collections/circular_buffer.d.ts +4 -3
- package/esm/internal/collections/circular_buffer.js +8 -6
- package/esm/mod.d.ts +17 -0
- package/esm/mod.js +11 -0
- package/esm/schemas/base_type.d.ts +8 -0
- package/esm/schemas/base_type.js +21 -0
- package/esm/schemas/complex/array_type.d.ts +31 -10
- package/esm/schemas/complex/array_type.js +129 -39
- package/esm/schemas/complex/enum_type.d.ts +24 -7
- package/esm/schemas/complex/enum_type.js +61 -15
- package/esm/schemas/complex/fixed_type.d.ts +27 -12
- package/esm/schemas/complex/fixed_type.js +40 -27
- package/esm/schemas/complex/map_type.d.ts +31 -10
- package/esm/schemas/complex/map_type.js +88 -47
- package/esm/schemas/complex/named_type.d.ts +1 -1
- package/esm/schemas/complex/named_type.js +2 -2
- package/esm/schemas/complex/record_field.d.ts +62 -0
- package/esm/schemas/complex/record_field.js +112 -0
- package/esm/schemas/complex/record_resolver.d.ts +45 -0
- package/esm/schemas/complex/record_resolver.js +92 -0
- package/esm/schemas/complex/record_type.d.ts +45 -70
- package/esm/schemas/complex/record_type.js +158 -213
- package/esm/schemas/complex/record_writer_cache.d.ts +44 -0
- package/esm/schemas/complex/record_writer_cache.js +141 -0
- package/esm/schemas/complex/record_writer_strategy.d.ts +123 -0
- package/esm/schemas/complex/record_writer_strategy.js +309 -0
- package/esm/schemas/complex/union_type.d.ts +23 -11
- package/esm/schemas/complex/union_type.js +77 -29
- package/esm/schemas/logical/decimal_logical_type.d.ts +1 -1
- package/esm/schemas/logical/decimal_logical_type.js +2 -2
- package/esm/schemas/logical/duration_logical_type.d.ts +1 -1
- package/esm/schemas/logical/duration_logical_type.js +2 -2
- package/esm/schemas/logical/logical_type.d.ts +27 -9
- package/esm/schemas/logical/logical_type.js +50 -17
- package/esm/schemas/logical/temporal_logical_types.d.ts +9 -9
- package/esm/schemas/logical/temporal_logical_types.js +18 -18
- package/esm/schemas/logical/uuid_logical_type.d.ts +1 -1
- package/esm/schemas/logical/uuid_logical_type.js +2 -2
- package/esm/schemas/primitive/boolean_type.d.ts +15 -4
- package/esm/schemas/primitive/boolean_type.js +22 -7
- package/esm/schemas/primitive/bytes_type.d.ts +16 -5
- package/esm/schemas/primitive/bytes_type.js +31 -16
- package/esm/schemas/primitive/double_type.d.ts +13 -2
- package/esm/schemas/primitive/double_type.js +34 -5
- package/esm/schemas/primitive/fixed_size_base_type.d.ts +11 -7
- package/esm/schemas/primitive/fixed_size_base_type.js +14 -14
- package/esm/schemas/primitive/float_type.d.ts +11 -2
- package/esm/schemas/primitive/float_type.js +26 -5
- package/esm/schemas/primitive/int_type.d.ts +17 -6
- package/esm/schemas/primitive/int_type.js +26 -17
- package/esm/schemas/primitive/long_type.d.ts +16 -5
- package/esm/schemas/primitive/long_type.js +30 -16
- package/esm/schemas/primitive/null_type.d.ts +15 -4
- package/esm/schemas/primitive/null_type.js +20 -7
- package/esm/schemas/primitive/primitive_type.d.ts +2 -0
- package/esm/schemas/primitive/primitive_type.js +4 -0
- package/esm/schemas/primitive/string_type.d.ts +17 -6
- package/esm/schemas/primitive/string_type.js +33 -18
- package/esm/schemas/resolver.d.ts +6 -0
- package/esm/schemas/type.d.ts +64 -4
- package/esm/schemas/type.js +97 -0
- package/esm/serialization/avro_file_parser_sync.d.ts +34 -0
- package/esm/serialization/avro_file_parser_sync.js +160 -0
- package/esm/serialization/avro_file_writer_sync.d.ts +47 -0
- package/esm/serialization/avro_file_writer_sync.js +211 -0
- package/esm/serialization/buffers/blob_readable_buffer.d.ts +4 -3
- package/esm/serialization/buffers/blob_readable_buffer.js +20 -6
- package/esm/serialization/buffers/buffer.d.ts +6 -1
- package/esm/serialization/buffers/buffer.js +3 -0
- package/esm/serialization/buffers/buffer_error.d.ts +28 -0
- package/esm/serialization/buffers/buffer_error.js +70 -0
- package/esm/serialization/buffers/buffer_sync.d.ts +51 -0
- package/esm/serialization/buffers/buffer_sync.js +4 -0
- package/esm/serialization/buffers/in_memory_buffer.d.ts +1 -0
- package/esm/serialization/buffers/in_memory_buffer.js +7 -5
- package/esm/serialization/buffers/in_memory_buffer_sync.d.ts +133 -0
- package/esm/serialization/buffers/in_memory_buffer_sync.js +259 -0
- package/esm/serialization/counting_writable_tap.d.ts +45 -0
- package/esm/serialization/counting_writable_tap.js +90 -0
- package/esm/serialization/counting_writable_tap_sync.d.ts +46 -0
- package/esm/serialization/counting_writable_tap_sync.js +87 -0
- package/esm/serialization/decoders/decoder_null_sync.d.ts +12 -0
- package/esm/serialization/decoders/decoder_null_sync.js +13 -0
- package/esm/serialization/decoders/decoder_sync.d.ts +15 -0
- package/esm/serialization/decoders/decoder_sync.js +1 -0
- package/esm/serialization/encoders/encoder_null_sync.d.ts +12 -0
- package/esm/serialization/encoders/encoder_null_sync.js +13 -0
- package/esm/serialization/encoders/encoder_sync.d.ts +15 -0
- package/esm/serialization/encoders/encoder_sync.js +1 -0
- package/esm/serialization/streams/fixed_size_stream_readable_buffer_adapter.d.ts +3 -2
- package/esm/serialization/streams/fixed_size_stream_readable_buffer_adapter.js +19 -9
- package/esm/serialization/streams/fixed_size_stream_reader_sync.d.ts +25 -0
- package/esm/serialization/streams/fixed_size_stream_reader_sync.js +63 -0
- package/esm/serialization/streams/fixed_size_stream_writer_sync.d.ts +45 -0
- package/esm/serialization/streams/fixed_size_stream_writer_sync.js +98 -0
- package/esm/serialization/streams/forward_only_stream_readable_buffer_adapter.d.ts +5 -3
- package/esm/serialization/streams/forward_only_stream_readable_buffer_adapter.js +18 -8
- package/esm/serialization/streams/stream_readable_buffer_adapter.d.ts +3 -2
- package/esm/serialization/streams/stream_readable_buffer_adapter.js +19 -6
- package/esm/serialization/streams/stream_readable_buffer_adapter_sync.d.ts +36 -0
- package/esm/serialization/streams/stream_readable_buffer_adapter_sync.js +93 -0
- package/esm/serialization/streams/stream_writable_buffer_adapter_sync.d.ts +45 -0
- package/esm/serialization/streams/stream_writable_buffer_adapter_sync.js +78 -0
- package/esm/serialization/streams/streams_sync.d.ts +36 -0
- package/esm/serialization/streams/streams_sync.js +4 -0
- package/esm/serialization/tap.d.ts +15 -32
- package/esm/serialization/tap.js +45 -134
- package/esm/serialization/tap_sync.d.ts +240 -0
- package/esm/serialization/tap_sync.js +545 -0
- package/esm/serialization/text_encoding.d.ts +16 -0
- package/esm/serialization/text_encoding.js +48 -1
- package/esm/type/create_type.d.ts +20 -0
- package/esm/type/create_type.js +49 -28
- package/package.json +1 -1
- package/esm/serialization/manipulate_bytes.d.ts +0 -6
- package/esm/serialization/manipulate_bytes.js +0 -13
- package/esm/serialization/read_uint_le.d.ts +0 -4
- package/esm/serialization/read_uint_le.js +0 -14
|
@@ -2,7 +2,8 @@ import { BaseType } from "../base_type.js";
|
|
|
2
2
|
import { Resolver } from "../resolver.js";
|
|
3
3
|
import { type JSONType, Type } from "../type.js";
|
|
4
4
|
import { type ErrorHook } from "../error.js";
|
|
5
|
-
import {
|
|
5
|
+
import type { ReadableTapLike, WritableTapLike } from "../../serialization/tap.js";
|
|
6
|
+
import type { SyncReadableTapLike, SyncWritableTapLike } from "../../serialization/tap_sync.js";
|
|
6
7
|
/**
|
|
7
8
|
* Represents a wrapped value for a union type.
|
|
8
9
|
*/
|
|
@@ -17,6 +18,8 @@ export type UnionValue = UnionWrappedValue | null;
|
|
|
17
18
|
export interface UnionTypeParams {
|
|
18
19
|
/** The types that make up the union. */
|
|
19
20
|
types: Type[];
|
|
21
|
+
/** Whether to validate during writes. Defaults to true. */
|
|
22
|
+
validate?: boolean;
|
|
20
23
|
}
|
|
21
24
|
/**
|
|
22
25
|
* Avro `union` type that supports values conforming to one of multiple schemas.
|
|
@@ -44,12 +47,13 @@ export declare class UnionType extends BaseType<UnionValue> {
|
|
|
44
47
|
*/
|
|
45
48
|
check(value: unknown, errorHook?: ErrorHook, path?: string[]): boolean;
|
|
46
49
|
/**
|
|
47
|
-
*
|
|
48
|
-
* Writes the branch index as a long, followed by the branch value if not null.
|
|
49
|
-
* @param tap The writable tap to write to.
|
|
50
|
-
* @param value The union value to serialize.
|
|
50
|
+
* Writes union value without validation.
|
|
51
51
|
*/
|
|
52
|
-
|
|
52
|
+
writeUnchecked(tap: WritableTapLike, value: UnionValue): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Writes union value without validation synchronously.
|
|
55
|
+
*/
|
|
56
|
+
writeSyncUnchecked(tap: SyncWritableTapLike, value: UnionValue): void;
|
|
53
57
|
/**
|
|
54
58
|
* Deserializes a union value from the readable tap.
|
|
55
59
|
* Reads the branch index, and if not null, reads the branch value and wraps it in an object.
|
|
@@ -57,6 +61,13 @@ export declare class UnionType extends BaseType<UnionValue> {
|
|
|
57
61
|
* @returns The deserialized union value.
|
|
58
62
|
*/
|
|
59
63
|
read(tap: ReadableTapLike): Promise<UnionValue>;
|
|
64
|
+
/**
|
|
65
|
+
* Reads a union branch index and its payload synchronously.
|
|
66
|
+
*/
|
|
67
|
+
/**
|
|
68
|
+
* Delegates synchronous read to the branch resolver.
|
|
69
|
+
*/
|
|
70
|
+
readSync(tap: SyncReadableTapLike): UnionValue;
|
|
60
71
|
/**
|
|
61
72
|
* Skips over a union value in the readable tap.
|
|
62
73
|
* Reads the branch index and skips the branch value if not null.
|
|
@@ -64,12 +75,9 @@ export declare class UnionType extends BaseType<UnionValue> {
|
|
|
64
75
|
*/
|
|
65
76
|
skip(tap: ReadableTapLike): Promise<void>;
|
|
66
77
|
/**
|
|
67
|
-
*
|
|
68
|
-
* Calculates the size needed for the index and branch value, then writes them to a new buffer.
|
|
69
|
-
* @param value The union value to convert.
|
|
70
|
-
* @returns The ArrayBuffer containing the serialized value.
|
|
78
|
+
* Skips a union value by skipping its branch payload synchronously.
|
|
71
79
|
*/
|
|
72
|
-
|
|
80
|
+
skipSync(tap: SyncReadableTapLike): void;
|
|
73
81
|
/**
|
|
74
82
|
* Creates a deep clone of the given value as a union value.
|
|
75
83
|
* Handles null values and wrapped objects by cloning the inner value using the branch type.
|
|
@@ -105,6 +113,10 @@ export declare class UnionType extends BaseType<UnionValue> {
|
|
|
105
113
|
* @returns Negative if tap1 < tap2, zero if equal, positive if tap1 > tap2.
|
|
106
114
|
*/
|
|
107
115
|
match(tap1: ReadableTapLike, tap2: ReadableTapLike): Promise<number>;
|
|
116
|
+
/**
|
|
117
|
+
* Compares union-encoded buffers synchronously.
|
|
118
|
+
*/
|
|
119
|
+
matchSync(tap1: SyncReadableTapLike, tap2: SyncReadableTapLike): number;
|
|
108
120
|
/**
|
|
109
121
|
* Creates a resolver for schema evolution from the writer type to this union type.
|
|
110
122
|
* If the writer is also a union, creates resolvers for each branch.
|
|
@@ -9,15 +9,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
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
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _UnionType_instances, _UnionType_types, _UnionType_branches, _UnionType_indices, _UnionType_resolveBranch, _UnionType_readBranchIndex, _UnionBranchResolver_branch, _UnionBranchResolver_branchResolver, _UnionFromUnionResolver_resolvers;
|
|
12
|
+
var _UnionType_instances, _UnionType_types, _UnionType_branches, _UnionType_indices, _UnionType_resolveBranch, _UnionType_readBranchIndex, _UnionType_readBranchIndexSync, _UnionBranchResolver_branch, _UnionBranchResolver_branchResolver, _UnionFromUnionResolver_resolvers;
|
|
13
13
|
import { BaseType } from "../base_type.js";
|
|
14
14
|
import { NamedType } from "./named_type.js";
|
|
15
15
|
import { Resolver } from "../resolver.js";
|
|
16
16
|
import { Type } from "../type.js";
|
|
17
17
|
import { throwInvalidError } from "../error.js";
|
|
18
|
-
import { WritableTap, } from "../../serialization/tap.js";
|
|
19
18
|
import { bigIntToSafeNumber } from "../../serialization/conversion.js";
|
|
20
|
-
import { calculateVarintSize } from "../../internal/varint.js";
|
|
21
19
|
function isPlainObject(value) {
|
|
22
20
|
return typeof value === "object" && value !== null &&
|
|
23
21
|
!Array.isArray(value);
|
|
@@ -54,7 +52,7 @@ export class UnionType extends BaseType {
|
|
|
54
52
|
* @param params The union type parameters.
|
|
55
53
|
*/
|
|
56
54
|
constructor(params) {
|
|
57
|
-
super();
|
|
55
|
+
super(params.validate ?? true);
|
|
58
56
|
_UnionType_instances.add(this);
|
|
59
57
|
_UnionType_types.set(this, void 0);
|
|
60
58
|
_UnionType_branches.set(this, void 0);
|
|
@@ -153,16 +151,23 @@ export class UnionType extends BaseType {
|
|
|
153
151
|
return isValid;
|
|
154
152
|
}
|
|
155
153
|
/**
|
|
156
|
-
*
|
|
157
|
-
* Writes the branch index as a long, followed by the branch value if not null.
|
|
158
|
-
* @param tap The writable tap to write to.
|
|
159
|
-
* @param value The union value to serialize.
|
|
154
|
+
* Writes union value without validation.
|
|
160
155
|
*/
|
|
161
|
-
async
|
|
156
|
+
async writeUnchecked(tap, value) {
|
|
162
157
|
const { index, branchValue } = __classPrivateFieldGet(this, _UnionType_instances, "m", _UnionType_resolveBranch).call(this, value);
|
|
163
158
|
await tap.writeLong(BigInt(index));
|
|
164
159
|
if (branchValue !== undefined) {
|
|
165
|
-
await __classPrivateFieldGet(this, _UnionType_branches, "f")[index].type.
|
|
160
|
+
await __classPrivateFieldGet(this, _UnionType_branches, "f")[index].type.writeUnchecked(tap, branchValue);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Writes union value without validation synchronously.
|
|
165
|
+
*/
|
|
166
|
+
writeSyncUnchecked(tap, value) {
|
|
167
|
+
const { index, branchValue } = __classPrivateFieldGet(this, _UnionType_instances, "m", _UnionType_resolveBranch).call(this, value);
|
|
168
|
+
tap.writeLong(BigInt(index));
|
|
169
|
+
if (branchValue !== undefined) {
|
|
170
|
+
__classPrivateFieldGet(this, _UnionType_branches, "f")[index].type.writeSyncUnchecked(tap, branchValue);
|
|
166
171
|
}
|
|
167
172
|
}
|
|
168
173
|
/**
|
|
@@ -180,6 +185,21 @@ export class UnionType extends BaseType {
|
|
|
180
185
|
const branchValue = await branch.type.read(tap);
|
|
181
186
|
return { [branch.name]: branchValue };
|
|
182
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Reads a union branch index and its payload synchronously.
|
|
190
|
+
*/
|
|
191
|
+
/**
|
|
192
|
+
* Delegates synchronous read to the branch resolver.
|
|
193
|
+
*/
|
|
194
|
+
readSync(tap) {
|
|
195
|
+
const index = __classPrivateFieldGet(this, _UnionType_instances, "m", _UnionType_readBranchIndexSync).call(this, tap);
|
|
196
|
+
const branch = __classPrivateFieldGet(this, _UnionType_branches, "f")[index];
|
|
197
|
+
if (branch.isNull) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
const branchValue = branch.type.readSync(tap);
|
|
201
|
+
return { [branch.name]: branchValue };
|
|
202
|
+
}
|
|
183
203
|
/**
|
|
184
204
|
* Skips over a union value in the readable tap.
|
|
185
205
|
* Reads the branch index and skips the branch value if not null.
|
|
@@ -193,27 +213,14 @@ export class UnionType extends BaseType {
|
|
|
193
213
|
}
|
|
194
214
|
}
|
|
195
215
|
/**
|
|
196
|
-
*
|
|
197
|
-
* Calculates the size needed for the index and branch value, then writes them to a new buffer.
|
|
198
|
-
* @param value The union value to convert.
|
|
199
|
-
* @returns The ArrayBuffer containing the serialized value.
|
|
216
|
+
* Skips a union value by skipping its branch payload synchronously.
|
|
200
217
|
*/
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (branchValue !== undefined) {
|
|
207
|
-
branchBytes = new Uint8Array(await __classPrivateFieldGet(this, _UnionType_branches, "f")[index].type.toBuffer(branchValue));
|
|
208
|
-
totalSize += branchBytes.byteLength;
|
|
209
|
-
}
|
|
210
|
-
const buffer = new ArrayBuffer(totalSize);
|
|
211
|
-
const tap = new WritableTap(buffer);
|
|
212
|
-
await tap.writeLong(BigInt(index));
|
|
213
|
-
if (branchBytes) {
|
|
214
|
-
await tap.writeFixed(branchBytes);
|
|
218
|
+
skipSync(tap) {
|
|
219
|
+
const index = __classPrivateFieldGet(this, _UnionType_instances, "m", _UnionType_readBranchIndexSync).call(this, tap);
|
|
220
|
+
const branch = __classPrivateFieldGet(this, _UnionType_branches, "f")[index];
|
|
221
|
+
if (!branch.isNull) {
|
|
222
|
+
branch.type.skipSync(tap);
|
|
215
223
|
}
|
|
216
|
-
return buffer;
|
|
217
224
|
}
|
|
218
225
|
/**
|
|
219
226
|
* Creates a deep clone of the given value as a union value.
|
|
@@ -294,6 +301,21 @@ export class UnionType extends BaseType {
|
|
|
294
301
|
}
|
|
295
302
|
return idx1 < idx2 ? -1 : 1;
|
|
296
303
|
}
|
|
304
|
+
/**
|
|
305
|
+
* Compares union-encoded buffers synchronously.
|
|
306
|
+
*/
|
|
307
|
+
matchSync(tap1, tap2) {
|
|
308
|
+
const idx1 = __classPrivateFieldGet(this, _UnionType_instances, "m", _UnionType_readBranchIndexSync).call(this, tap1);
|
|
309
|
+
const idx2 = __classPrivateFieldGet(this, _UnionType_instances, "m", _UnionType_readBranchIndexSync).call(this, tap2);
|
|
310
|
+
if (idx1 === idx2) {
|
|
311
|
+
const branch = __classPrivateFieldGet(this, _UnionType_branches, "f")[idx1];
|
|
312
|
+
if (branch.isNull) {
|
|
313
|
+
return 0;
|
|
314
|
+
}
|
|
315
|
+
return branch.type.matchSync(tap1, tap2);
|
|
316
|
+
}
|
|
317
|
+
return idx1 < idx2 ? -1 : 1;
|
|
318
|
+
}
|
|
297
319
|
/**
|
|
298
320
|
* Creates a resolver for schema evolution from the writer type to this union type.
|
|
299
321
|
* If the writer is also a union, creates resolvers for each branch.
|
|
@@ -355,6 +377,13 @@ _UnionType_types = new WeakMap(), _UnionType_branches = new WeakMap(), _UnionTyp
|
|
|
355
377
|
throw new Error(`Invalid union index: ${index}`);
|
|
356
378
|
}
|
|
357
379
|
return index;
|
|
380
|
+
}, _UnionType_readBranchIndexSync = function _UnionType_readBranchIndexSync(tap) {
|
|
381
|
+
const indexBigInt = tap.readLong();
|
|
382
|
+
const index = bigIntToSafeNumber(indexBigInt, "Union branch index");
|
|
383
|
+
if (index < 0 || index >= __classPrivateFieldGet(this, _UnionType_branches, "f").length) {
|
|
384
|
+
throw new Error(`Invalid union index: ${index}`);
|
|
385
|
+
}
|
|
386
|
+
return index;
|
|
358
387
|
};
|
|
359
388
|
class UnionBranchResolver extends Resolver {
|
|
360
389
|
constructor(reader, branch, branchResolver) {
|
|
@@ -371,6 +400,16 @@ class UnionBranchResolver extends Resolver {
|
|
|
371
400
|
}
|
|
372
401
|
return { [__classPrivateFieldGet(this, _UnionBranchResolver_branch, "f").name]: resolvedValue };
|
|
373
402
|
}
|
|
403
|
+
/**
|
|
404
|
+
* Reads the branch index synchronously and forwards to the per-branch resolver.
|
|
405
|
+
*/
|
|
406
|
+
readSync(tap) {
|
|
407
|
+
const resolvedValue = __classPrivateFieldGet(this, _UnionBranchResolver_branchResolver, "f").readSync(tap);
|
|
408
|
+
if (__classPrivateFieldGet(this, _UnionBranchResolver_branch, "f").isNull) {
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
return { [__classPrivateFieldGet(this, _UnionBranchResolver_branch, "f").name]: resolvedValue };
|
|
412
|
+
}
|
|
374
413
|
}
|
|
375
414
|
_UnionBranchResolver_branch = new WeakMap(), _UnionBranchResolver_branchResolver = new WeakMap();
|
|
376
415
|
class UnionFromUnionResolver extends Resolver {
|
|
@@ -388,5 +427,14 @@ class UnionFromUnionResolver extends Resolver {
|
|
|
388
427
|
}
|
|
389
428
|
return await resolver.read(tap);
|
|
390
429
|
}
|
|
430
|
+
readSync(tap) {
|
|
431
|
+
const indexBigInt = tap.readLong();
|
|
432
|
+
const index = bigIntToSafeNumber(indexBigInt, "Union branch index");
|
|
433
|
+
const resolver = __classPrivateFieldGet(this, _UnionFromUnionResolver_resolvers, "f")[index];
|
|
434
|
+
if (!resolver) {
|
|
435
|
+
throw new Error(`Invalid union index: ${index}`);
|
|
436
|
+
}
|
|
437
|
+
return resolver.readSync(tap);
|
|
438
|
+
}
|
|
391
439
|
}
|
|
392
440
|
_UnionFromUnionResolver_resolvers = new WeakMap();
|
|
@@ -16,7 +16,7 @@ export declare class DecimalLogicalType extends LogicalType<bigint, Uint8Array>
|
|
|
16
16
|
* @param underlying The underlying bytes or fixed type.
|
|
17
17
|
* @param params The precision and scale parameters.
|
|
18
18
|
*/
|
|
19
|
-
constructor(underlying: BytesType | FixedType, params: DecimalParams);
|
|
19
|
+
constructor(underlying: BytesType | FixedType, params: DecimalParams, validate?: boolean);
|
|
20
20
|
/**
|
|
21
21
|
* Gets the precision of the decimal.
|
|
22
22
|
*/
|
|
@@ -23,8 +23,8 @@ export class DecimalLogicalType extends LogicalType {
|
|
|
23
23
|
* @param underlying The underlying bytes or fixed type.
|
|
24
24
|
* @param params The precision and scale parameters.
|
|
25
25
|
*/
|
|
26
|
-
constructor(underlying, params) {
|
|
27
|
-
super(underlying);
|
|
26
|
+
constructor(underlying, params, validate = true) {
|
|
27
|
+
super(underlying, validate);
|
|
28
28
|
_DecimalLogicalType_precision.set(this, void 0);
|
|
29
29
|
_DecimalLogicalType_scale.set(this, void 0);
|
|
30
30
|
_DecimalLogicalType_fixedSize.set(this, void 0);
|
|
@@ -21,7 +21,7 @@ export declare class DurationLogicalType extends NamedLogicalType<DurationValue,
|
|
|
21
21
|
* Creates a new DurationLogicalType.
|
|
22
22
|
* @param underlying The underlying fixed type (must be 12 bytes).
|
|
23
23
|
*/
|
|
24
|
-
constructor(underlying: FixedType);
|
|
24
|
+
constructor(underlying: FixedType, validate?: boolean);
|
|
25
25
|
/**
|
|
26
26
|
* Checks if this logical type can read from the given writer logical type.
|
|
27
27
|
* @param writer The writer logical type.
|
|
@@ -9,8 +9,8 @@ export class DurationLogicalType extends NamedLogicalType {
|
|
|
9
9
|
* Creates a new DurationLogicalType.
|
|
10
10
|
* @param underlying The underlying fixed type (must be 12 bytes).
|
|
11
11
|
*/
|
|
12
|
-
constructor(underlying) {
|
|
13
|
-
super(underlying);
|
|
12
|
+
constructor(underlying, validate = true) {
|
|
13
|
+
super(underlying, validate);
|
|
14
14
|
if (underlying.getSize() !== 12) {
|
|
15
15
|
throw new Error("Duration logical type requires fixed size of 12 bytes.");
|
|
16
16
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReadableTapLike, WritableTapLike } from "../../serialization/tap.js";
|
|
2
|
+
import type { SyncReadableTapLike, SyncWritableTapLike } from "../../serialization/tap_sync.js";
|
|
2
3
|
import { Resolver } from "../resolver.js";
|
|
3
4
|
import type { NamedType } from "../complex/named_type.js";
|
|
4
5
|
import { Type } from "../type.js";
|
|
@@ -15,7 +16,7 @@ export declare abstract class LogicalType<TValue, TUnderlying> extends Type<TVal
|
|
|
15
16
|
* Constructs a new LogicalType.
|
|
16
17
|
* @param underlyingType - The underlying type to wrap.
|
|
17
18
|
*/
|
|
18
|
-
protected constructor(underlyingType: Type<TUnderlying
|
|
19
|
+
protected constructor(underlyingType: Type<TUnderlying>, validate?: boolean);
|
|
19
20
|
/**
|
|
20
21
|
* Gets the underlying type that this logical type wraps.
|
|
21
22
|
*/
|
|
@@ -41,16 +42,15 @@ export declare abstract class LogicalType<TValue, TUnderlying> extends Type<TVal
|
|
|
41
42
|
* Determines if this logical type is compatible with the writer logical type for reading.
|
|
42
43
|
*/
|
|
43
44
|
protected canReadFromLogical(_writer: LogicalType<unknown, unknown>): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Serializes the logical value to an ArrayBuffer.
|
|
46
|
-
* @param value The logical value to serialize.
|
|
47
|
-
*/
|
|
48
|
-
toBuffer(value: TValue): Promise<ArrayBuffer>;
|
|
49
45
|
/**
|
|
50
46
|
* Deserializes a logical value from an ArrayBuffer.
|
|
51
47
|
* @param buffer The buffer to deserialize from.
|
|
52
48
|
*/
|
|
53
49
|
fromBuffer(buffer: ArrayBuffer): Promise<TValue>;
|
|
50
|
+
/**
|
|
51
|
+
* Converts a synchronous buffer into the logical value by decoding the underlying type.
|
|
52
|
+
*/
|
|
53
|
+
fromSyncBuffer(buffer: ArrayBuffer): TValue;
|
|
54
54
|
/**
|
|
55
55
|
* Checks if the given value is valid for this type.
|
|
56
56
|
* @param value The value to validate.
|
|
@@ -79,15 +79,33 @@ export declare abstract class LogicalType<TValue, TUnderlying> extends Type<TVal
|
|
|
79
79
|
*/
|
|
80
80
|
random(): TValue;
|
|
81
81
|
/**
|
|
82
|
-
* Writes
|
|
82
|
+
* Writes logical value without validation.
|
|
83
|
+
* Applies the logical transform but uses the underlying type's unchecked writer.
|
|
84
|
+
*/
|
|
85
|
+
writeUnchecked(tap: WritableTapLike, value: TValue): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Writes logical value without validation synchronously.
|
|
88
|
+
* Applies the logical transform but uses the underlying type's unchecked writer.
|
|
83
89
|
*/
|
|
84
|
-
|
|
90
|
+
writeSyncUnchecked(tap: SyncWritableTapLike, value: TValue): void;
|
|
85
91
|
/** Reads the value from the tap. */
|
|
86
92
|
read(tap: ReadableTapLike): Promise<TValue>;
|
|
93
|
+
/**
|
|
94
|
+
* Reads the logical value synchronously from the underlying type.
|
|
95
|
+
*/
|
|
96
|
+
readSync(tap: SyncReadableTapLike): TValue;
|
|
87
97
|
/** Skips the value in the tap. */
|
|
88
98
|
skip(tap: ReadableTapLike): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Skips the logical value by skipping the underlying representation.
|
|
101
|
+
*/
|
|
102
|
+
skipSync(tap: SyncReadableTapLike): void;
|
|
89
103
|
/** Matches the value in the taps. */
|
|
90
104
|
match(tap1: ReadableTapLike, tap2: ReadableTapLike): Promise<number>;
|
|
105
|
+
/**
|
|
106
|
+
* Compares two sync taps by delegating to the underlying type match.
|
|
107
|
+
*/
|
|
108
|
+
matchSync(tap1: SyncReadableTapLike, tap2: SyncReadableTapLike): number;
|
|
91
109
|
/**
|
|
92
110
|
* Creates a resolver for reading from the writer type, handling logical types specially.
|
|
93
111
|
*/
|
|
@@ -118,7 +136,7 @@ export declare abstract class NamedLogicalType<TValue, TUnderlying> extends Logi
|
|
|
118
136
|
* Creates a new NamedLogicalType.
|
|
119
137
|
* @param namedType The underlying named type.
|
|
120
138
|
*/
|
|
121
|
-
protected constructor(namedType: NamedType<TUnderlying
|
|
139
|
+
protected constructor(namedType: NamedType<TUnderlying>, validate?: boolean);
|
|
122
140
|
/**
|
|
123
141
|
* Gets the full name of the underlying type.
|
|
124
142
|
*/
|
|
@@ -22,8 +22,8 @@ export class LogicalType extends Type {
|
|
|
22
22
|
* Constructs a new LogicalType.
|
|
23
23
|
* @param underlyingType - The underlying type to wrap.
|
|
24
24
|
*/
|
|
25
|
-
constructor(underlyingType) {
|
|
26
|
-
super();
|
|
25
|
+
constructor(underlyingType, validate = true) {
|
|
26
|
+
super(validate);
|
|
27
27
|
/** The underlying type that this logical type wraps. */
|
|
28
28
|
Object.defineProperty(this, "underlyingType", {
|
|
29
29
|
enumerable: true,
|
|
@@ -52,15 +52,6 @@ export class LogicalType extends Type {
|
|
|
52
52
|
canReadFromLogical(_writer) {
|
|
53
53
|
return _writer.constructor === this.constructor;
|
|
54
54
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Serializes the logical value to an ArrayBuffer.
|
|
57
|
-
* @param value The logical value to serialize.
|
|
58
|
-
*/
|
|
59
|
-
async toBuffer(value) {
|
|
60
|
-
this.ensureValid(value, []);
|
|
61
|
-
const underlying = this.toUnderlying(value);
|
|
62
|
-
return await this.underlyingType.toBuffer(underlying);
|
|
63
|
-
}
|
|
64
55
|
/**
|
|
65
56
|
* Deserializes a logical value from an ArrayBuffer.
|
|
66
57
|
* @param buffer The buffer to deserialize from.
|
|
@@ -69,6 +60,13 @@ export class LogicalType extends Type {
|
|
|
69
60
|
const underlying = await this.underlyingType.fromBuffer(buffer);
|
|
70
61
|
return this.fromUnderlying(underlying);
|
|
71
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Converts a synchronous buffer into the logical value by decoding the underlying type.
|
|
65
|
+
*/
|
|
66
|
+
fromSyncBuffer(buffer) {
|
|
67
|
+
const underlying = this.underlyingType.fromSyncBuffer(buffer);
|
|
68
|
+
return this.fromUnderlying(underlying);
|
|
69
|
+
}
|
|
72
70
|
/**
|
|
73
71
|
* Checks if the given value is valid for this type.
|
|
74
72
|
* @param value The value to validate.
|
|
@@ -127,25 +125,53 @@ export class LogicalType extends Type {
|
|
|
127
125
|
return this.fromUnderlying(underlying);
|
|
128
126
|
}
|
|
129
127
|
/**
|
|
130
|
-
* Writes
|
|
128
|
+
* Writes logical value without validation.
|
|
129
|
+
* Applies the logical transform but uses the underlying type's unchecked writer.
|
|
131
130
|
*/
|
|
132
|
-
async
|
|
133
|
-
this.
|
|
134
|
-
await this.underlyingType.
|
|
131
|
+
async writeUnchecked(tap, value) {
|
|
132
|
+
const underlying = this.toUnderlying(value);
|
|
133
|
+
await this.underlyingType.writeUnchecked(tap, underlying);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Writes logical value without validation synchronously.
|
|
137
|
+
* Applies the logical transform but uses the underlying type's unchecked writer.
|
|
138
|
+
*/
|
|
139
|
+
writeSyncUnchecked(tap, value) {
|
|
140
|
+
const underlying = this.toUnderlying(value);
|
|
141
|
+
this.underlyingType.writeSyncUnchecked(tap, underlying);
|
|
135
142
|
}
|
|
136
143
|
/** Reads the value from the tap. */
|
|
137
144
|
async read(tap) {
|
|
138
145
|
const underlying = await this.underlyingType.read(tap);
|
|
139
146
|
return this.fromUnderlying(underlying);
|
|
140
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Reads the logical value synchronously from the underlying type.
|
|
150
|
+
*/
|
|
151
|
+
readSync(tap) {
|
|
152
|
+
const underlying = this.underlyingType.readSync(tap);
|
|
153
|
+
return this.fromUnderlying(underlying);
|
|
154
|
+
}
|
|
141
155
|
/** Skips the value in the tap. */
|
|
142
156
|
async skip(tap) {
|
|
143
157
|
await this.underlyingType.skip(tap);
|
|
144
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Skips the logical value by skipping the underlying representation.
|
|
161
|
+
*/
|
|
162
|
+
skipSync(tap) {
|
|
163
|
+
this.underlyingType.skipSync(tap);
|
|
164
|
+
}
|
|
145
165
|
/** Matches the value in the taps. */
|
|
146
166
|
async match(tap1, tap2) {
|
|
147
167
|
return await this.underlyingType.match(tap1, tap2);
|
|
148
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Compares two sync taps by delegating to the underlying type match.
|
|
171
|
+
*/
|
|
172
|
+
matchSync(tap1, tap2) {
|
|
173
|
+
return this.underlyingType.matchSync(tap1, tap2);
|
|
174
|
+
}
|
|
149
175
|
/**
|
|
150
176
|
* Creates a resolver for reading from the writer type, handling logical types specially.
|
|
151
177
|
*/
|
|
@@ -181,6 +207,13 @@ class LogicalResolver extends Resolver {
|
|
|
181
207
|
const underlying = await __classPrivateFieldGet(this, _LogicalResolver_resolver, "f").read(tap);
|
|
182
208
|
return __classPrivateFieldGet(this, _LogicalResolver_logicalType, "f").convertFromUnderlying(underlying);
|
|
183
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* Synchronously resolves logical values emitted by resolved streams.
|
|
212
|
+
*/
|
|
213
|
+
readSync(tap) {
|
|
214
|
+
const underlying = __classPrivateFieldGet(this, _LogicalResolver_resolver, "f").readSync(tap);
|
|
215
|
+
return __classPrivateFieldGet(this, _LogicalResolver_logicalType, "f").convertFromUnderlying(underlying);
|
|
216
|
+
}
|
|
184
217
|
}
|
|
185
218
|
_LogicalResolver_logicalType = new WeakMap(), _LogicalResolver_resolver = new WeakMap();
|
|
186
219
|
/**
|
|
@@ -196,8 +229,8 @@ export class NamedLogicalType extends LogicalType {
|
|
|
196
229
|
* Creates a new NamedLogicalType.
|
|
197
230
|
* @param namedType The underlying named type.
|
|
198
231
|
*/
|
|
199
|
-
constructor(namedType) {
|
|
200
|
-
super(namedType);
|
|
232
|
+
constructor(namedType, validate = true) {
|
|
233
|
+
super(namedType, validate);
|
|
201
234
|
/** The underlying named type. */
|
|
202
235
|
Object.defineProperty(this, "namedType", {
|
|
203
236
|
enumerable: true,
|
|
@@ -11,7 +11,7 @@ export declare class DateLogicalType extends LogicalType<number, number> {
|
|
|
11
11
|
* Creates a new DateLogicalType.
|
|
12
12
|
* @param underlying The underlying int type.
|
|
13
13
|
*/
|
|
14
|
-
constructor(underlying: IntType);
|
|
14
|
+
constructor(underlying: IntType, validate?: boolean);
|
|
15
15
|
/** Checks if the logical type can read from the underlying type. */
|
|
16
16
|
protected canReadFromLogical(writer: LogicalType<unknown, unknown>): boolean;
|
|
17
17
|
/** Checks if the value is a valid instance of this logical type. */
|
|
@@ -35,7 +35,7 @@ export declare class TimeMillisLogicalType extends LogicalType<number, number> {
|
|
|
35
35
|
* Creates a new TimeMillisLogicalType.
|
|
36
36
|
* @param underlying The underlying int type.
|
|
37
37
|
*/
|
|
38
|
-
constructor(underlying: IntType);
|
|
38
|
+
constructor(underlying: IntType, validate?: boolean);
|
|
39
39
|
/** Checks if the logical type can read from the underlying type. */
|
|
40
40
|
protected canReadFromLogical(writer: LogicalType<unknown, unknown>): boolean;
|
|
41
41
|
/** Checks if the value is a valid instance of this logical type. */
|
|
@@ -58,7 +58,7 @@ export declare class TimeMicrosLogicalType extends LogicalType<bigint, bigint> {
|
|
|
58
58
|
* Creates a new TimeMicrosLogicalType.
|
|
59
59
|
* @param underlying The underlying long type.
|
|
60
60
|
*/
|
|
61
|
-
constructor(underlying: LongType);
|
|
61
|
+
constructor(underlying: LongType, validate?: boolean);
|
|
62
62
|
/** Checks if the logical type can read from the underlying type. */
|
|
63
63
|
protected canReadFromLogical(writer: LogicalType<unknown, unknown>): boolean;
|
|
64
64
|
/** Checks if the value is a valid instance of this logical type. */
|
|
@@ -82,7 +82,7 @@ export declare class TimestampMillisLogicalType extends LogicalType<Date, bigint
|
|
|
82
82
|
* Creates a new TimestampMillisLogicalType.
|
|
83
83
|
* @param underlying The underlying long type.
|
|
84
84
|
*/
|
|
85
|
-
constructor(underlying: LongType);
|
|
85
|
+
constructor(underlying: LongType, validate?: boolean);
|
|
86
86
|
/** Checks if the logical type can read from the underlying type. */
|
|
87
87
|
protected canReadFromLogical(writer: LogicalType<unknown, unknown>): boolean;
|
|
88
88
|
/** Checks if the value is a valid instance of this logical type. */
|
|
@@ -107,7 +107,7 @@ export declare class TimestampMicrosLogicalType extends LogicalType<bigint, bigi
|
|
|
107
107
|
* Creates a new TimestampMicrosLogicalType.
|
|
108
108
|
* @param underlying The underlying long type.
|
|
109
109
|
*/
|
|
110
|
-
constructor(underlying: LongType);
|
|
110
|
+
constructor(underlying: LongType, validate?: boolean);
|
|
111
111
|
/** Checks if the logical type can read from the underlying type. */
|
|
112
112
|
protected canReadFromLogical(writer: LogicalType<unknown, unknown>): boolean;
|
|
113
113
|
/** Checks if the value is a valid instance of this logical type. */
|
|
@@ -130,7 +130,7 @@ export declare class TimestampNanosLogicalType extends LogicalType<bigint, bigin
|
|
|
130
130
|
* Creates a new TimestampNanosLogicalType.
|
|
131
131
|
* @param underlying The underlying long type.
|
|
132
132
|
*/
|
|
133
|
-
constructor(underlying: LongType);
|
|
133
|
+
constructor(underlying: LongType, validate?: boolean);
|
|
134
134
|
/** Checks if the logical type can read from the underlying type. */
|
|
135
135
|
protected canReadFromLogical(writer: LogicalType<unknown, unknown>): boolean;
|
|
136
136
|
/** Checks if the value is a valid instance of this logical type. */
|
|
@@ -153,7 +153,7 @@ export declare class LocalTimestampMillisLogicalType extends LogicalType<number,
|
|
|
153
153
|
* Creates a new LocalTimestampMillisLogicalType.
|
|
154
154
|
* @param underlying The underlying long type.
|
|
155
155
|
*/
|
|
156
|
-
constructor(underlying: LongType);
|
|
156
|
+
constructor(underlying: LongType, validate?: boolean);
|
|
157
157
|
/** Checks if the logical type can read from the underlying type. */
|
|
158
158
|
protected canReadFromLogical(writer: LogicalType<unknown, unknown>): boolean;
|
|
159
159
|
/** Checks if the value is a valid instance of this logical type. */
|
|
@@ -176,7 +176,7 @@ export declare class LocalTimestampMicrosLogicalType extends LogicalType<bigint,
|
|
|
176
176
|
* Creates a new LocalTimestampMicrosLogicalType.
|
|
177
177
|
* @param underlying The underlying long type.
|
|
178
178
|
*/
|
|
179
|
-
constructor(underlying: LongType);
|
|
179
|
+
constructor(underlying: LongType, validate?: boolean);
|
|
180
180
|
/** Checks if the logical type can read from the underlying type. */
|
|
181
181
|
protected canReadFromLogical(writer: LogicalType<unknown, unknown>): boolean;
|
|
182
182
|
/** Checks if the value is a valid instance of this logical type. */
|
|
@@ -199,7 +199,7 @@ export declare class LocalTimestampNanosLogicalType extends LogicalType<bigint,
|
|
|
199
199
|
* Creates a new LocalTimestampNanosLogicalType.
|
|
200
200
|
* @param underlying The underlying long type.
|
|
201
201
|
*/
|
|
202
|
-
constructor(underlying: LongType);
|
|
202
|
+
constructor(underlying: LongType, validate?: boolean);
|
|
203
203
|
/** Checks if the logical type can read from the underlying type. */
|
|
204
204
|
protected canReadFromLogical(writer: LogicalType<unknown, unknown>): boolean;
|
|
205
205
|
/** Checks if the value is a valid instance of this logical type. */
|