@sachitv/avro-typescript 0.4.1 → 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 +2 -2
- 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
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ReadableTapLike, WritableTapLike } from "../../serialization/tap.js";
|
|
2
|
+
import type { SyncReadableTapLike, SyncWritableTapLike } from "../../serialization/tap_sync.js";
|
|
2
3
|
import { PrimitiveType } from "./primitive_type.js";
|
|
3
4
|
import type { JSONType } from "../type.js";
|
|
4
|
-
import {
|
|
5
|
+
import type { ErrorHook } from "../error.js";
|
|
5
6
|
/**
|
|
6
7
|
* Int type (32-bit).
|
|
7
8
|
*/
|
|
8
9
|
export declare class IntType extends PrimitiveType<number> {
|
|
10
|
+
/** Creates a new int type. */
|
|
11
|
+
constructor(validate?: boolean);
|
|
9
12
|
/** Checks if the value is a valid 32-bit integer. */
|
|
10
13
|
check(value: unknown, errorHook?: ErrorHook, path?: string[]): boolean;
|
|
11
14
|
/** Reads a 32-bit integer from the tap. */
|
|
12
15
|
read(tap: ReadableTapLike): Promise<number>;
|
|
13
|
-
/** Writes a 32-bit integer to the tap. */
|
|
14
|
-
|
|
16
|
+
/** Writes a 32-bit integer to the tap without validation. */
|
|
17
|
+
writeUnchecked(tap: WritableTapLike, value: number): Promise<void>;
|
|
18
|
+
/** Returns the encoded byte length of the given value. */
|
|
19
|
+
protected byteLength(value: number): number;
|
|
15
20
|
/** Skips a 32-bit integer in the tap. */
|
|
16
21
|
skip(tap: ReadableTapLike): Promise<void>;
|
|
17
|
-
/** Converts a 32-bit integer to its buffer representation. */
|
|
18
|
-
toBuffer(value: number): Promise<ArrayBuffer>;
|
|
19
22
|
/**
|
|
20
23
|
* Compares two int values.
|
|
21
24
|
*/
|
|
@@ -28,4 +31,12 @@ export declare class IntType extends PrimitiveType<number> {
|
|
|
28
31
|
toJSON(): JSONType;
|
|
29
32
|
/** Matches two 32-bit integers in the taps. */
|
|
30
33
|
match(tap1: ReadableTapLike, tap2: ReadableTapLike): Promise<number>;
|
|
34
|
+
/** Reads a 32-bit integer synchronously from the tap. */
|
|
35
|
+
readSync(tap: SyncReadableTapLike): number;
|
|
36
|
+
/** Writes a 32-bit integer synchronously to the tap without validation. */
|
|
37
|
+
writeSyncUnchecked(tap: SyncWritableTapLike, value: number): void;
|
|
38
|
+
/** Skips a 32-bit integer synchronously in the tap. */
|
|
39
|
+
skipSync(tap: SyncReadableTapLike): void;
|
|
40
|
+
/** Matches two 32-bit integers synchronously in the taps. */
|
|
41
|
+
matchSync(tap1: SyncReadableTapLike, tap2: SyncReadableTapLike): number;
|
|
31
42
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { WritableTap, } from "../../serialization/tap.js";
|
|
2
1
|
import { PrimitiveType } from "./primitive_type.js";
|
|
3
2
|
import { calculateVarintSize } from "../../internal/varint.js";
|
|
4
|
-
import { throwInvalidError } from "../error.js";
|
|
5
3
|
/**
|
|
6
4
|
* Int type (32-bit).
|
|
7
5
|
*/
|
|
8
6
|
export class IntType extends PrimitiveType {
|
|
7
|
+
/** Creates a new int type. */
|
|
8
|
+
constructor(validate = true) {
|
|
9
|
+
super(validate);
|
|
10
|
+
}
|
|
9
11
|
/** Checks if the value is a valid 32-bit integer. */
|
|
10
12
|
check(value, errorHook, path = []) {
|
|
11
13
|
const isValid = typeof value === "number" && Number.isInteger(value) &&
|
|
@@ -19,27 +21,18 @@ export class IntType extends PrimitiveType {
|
|
|
19
21
|
async read(tap) {
|
|
20
22
|
return await tap.readInt();
|
|
21
23
|
}
|
|
22
|
-
/** Writes a 32-bit integer to the tap. */
|
|
23
|
-
async
|
|
24
|
-
if (!this.check(value)) {
|
|
25
|
-
throwInvalidError([], value, this);
|
|
26
|
-
}
|
|
24
|
+
/** Writes a 32-bit integer to the tap without validation. */
|
|
25
|
+
async writeUnchecked(tap, value) {
|
|
27
26
|
await tap.writeInt(value);
|
|
28
27
|
}
|
|
28
|
+
/** Returns the encoded byte length of the given value. */
|
|
29
|
+
byteLength(value) {
|
|
30
|
+
return calculateVarintSize(value);
|
|
31
|
+
}
|
|
29
32
|
/** Skips a 32-bit integer in the tap. */
|
|
30
33
|
async skip(tap) {
|
|
31
34
|
await tap.skipInt();
|
|
32
35
|
}
|
|
33
|
-
/** Converts a 32-bit integer to its buffer representation. */
|
|
34
|
-
async toBuffer(value) {
|
|
35
|
-
this.check(value, throwInvalidError, []);
|
|
36
|
-
// For int, allocate exact size based on value
|
|
37
|
-
const size = calculateVarintSize(value);
|
|
38
|
-
const buf = new ArrayBuffer(size);
|
|
39
|
-
const tap = new WritableTap(buf);
|
|
40
|
-
await this.write(tap, value);
|
|
41
|
-
return buf;
|
|
42
|
-
}
|
|
43
36
|
/**
|
|
44
37
|
* Compares two int values.
|
|
45
38
|
*/
|
|
@@ -60,4 +53,20 @@ export class IntType extends PrimitiveType {
|
|
|
60
53
|
async match(tap1, tap2) {
|
|
61
54
|
return await tap1.matchInt(tap2);
|
|
62
55
|
}
|
|
56
|
+
/** Reads a 32-bit integer synchronously from the tap. */
|
|
57
|
+
readSync(tap) {
|
|
58
|
+
return tap.readInt();
|
|
59
|
+
}
|
|
60
|
+
/** Writes a 32-bit integer synchronously to the tap without validation. */
|
|
61
|
+
writeSyncUnchecked(tap, value) {
|
|
62
|
+
tap.writeInt(value);
|
|
63
|
+
}
|
|
64
|
+
/** Skips a 32-bit integer synchronously in the tap. */
|
|
65
|
+
skipSync(tap) {
|
|
66
|
+
tap.skipInt();
|
|
67
|
+
}
|
|
68
|
+
/** Matches two 32-bit integers synchronously in the taps. */
|
|
69
|
+
matchSync(tap1, tap2) {
|
|
70
|
+
return tap1.matchInt(tap2);
|
|
71
|
+
}
|
|
63
72
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ReadableTapLike, WritableTapLike } from "../../serialization/tap.js";
|
|
2
|
+
import type { SyncReadableTapLike, SyncWritableTapLike } from "../../serialization/tap_sync.js";
|
|
2
3
|
import { PrimitiveType } from "./primitive_type.js";
|
|
3
4
|
import type { JSONType, Type } from "../type.js";
|
|
4
5
|
import { Resolver } from "../resolver.js";
|
|
@@ -7,16 +8,18 @@ import { type ErrorHook } from "../error.js";
|
|
|
7
8
|
* Long type (64-bit).
|
|
8
9
|
*/
|
|
9
10
|
export declare class LongType extends PrimitiveType<bigint> {
|
|
11
|
+
/** Creates a new long type. */
|
|
12
|
+
constructor(validate?: boolean);
|
|
10
13
|
/** Checks if the value is a valid long. */
|
|
11
14
|
check(value: unknown, errorHook?: ErrorHook, path?: string[]): boolean;
|
|
12
15
|
/** Reads a long value from the tap. */
|
|
13
16
|
read(tap: ReadableTapLike): Promise<bigint>;
|
|
14
|
-
/** Writes a long value to the tap. */
|
|
15
|
-
|
|
17
|
+
/** Writes a long value to the tap without validation. */
|
|
18
|
+
writeUnchecked(tap: WritableTapLike, value: bigint): Promise<void>;
|
|
19
|
+
/** Returns the encoded byte length of the given value. */
|
|
20
|
+
protected byteLength(value: bigint): number;
|
|
16
21
|
/** Skips a long value in the tap. */
|
|
17
22
|
skip(tap: ReadableTapLike): Promise<void>;
|
|
18
|
-
/** Converts a bigint value to its buffer representation. */
|
|
19
|
-
toBuffer(value: bigint): Promise<ArrayBuffer>;
|
|
20
23
|
/**
|
|
21
24
|
* Compares two long values.
|
|
22
25
|
*/
|
|
@@ -33,4 +36,12 @@ export declare class LongType extends PrimitiveType<bigint> {
|
|
|
33
36
|
toJSON(): JSONType;
|
|
34
37
|
/** Compares two taps for long equality. */
|
|
35
38
|
match(tap1: ReadableTapLike, tap2: ReadableTapLike): Promise<number>;
|
|
39
|
+
/** Reads a long value synchronously from the tap. */
|
|
40
|
+
readSync(tap: SyncReadableTapLike): bigint;
|
|
41
|
+
/** Writes a long value synchronously to the tap without validation. */
|
|
42
|
+
writeSyncUnchecked(tap: SyncWritableTapLike, value: bigint): void;
|
|
43
|
+
/** Skips a long value synchronously in the tap. */
|
|
44
|
+
skipSync(tap: SyncReadableTapLike): void;
|
|
45
|
+
/** Compares two taps synchronously for long equality. */
|
|
46
|
+
matchSync(tap1: SyncReadableTapLike, tap2: SyncReadableTapLike): number;
|
|
36
47
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { WritableTap, } from "../../serialization/tap.js";
|
|
2
1
|
import { PrimitiveType } from "./primitive_type.js";
|
|
3
2
|
import { Resolver } from "../resolver.js";
|
|
4
3
|
import { IntType } from "./int_type.js";
|
|
@@ -10,6 +9,10 @@ const MAX_LONG = (1n << 63n) - 1n;
|
|
|
10
9
|
* Long type (64-bit).
|
|
11
10
|
*/
|
|
12
11
|
export class LongType extends PrimitiveType {
|
|
12
|
+
/** Creates a new long type. */
|
|
13
|
+
constructor(validate = true) {
|
|
14
|
+
super(validate);
|
|
15
|
+
}
|
|
13
16
|
/** Checks if the value is a valid long. */
|
|
14
17
|
check(value, errorHook, path = []) {
|
|
15
18
|
const isValid = typeof value === "bigint" && value >= MIN_LONG &&
|
|
@@ -23,27 +26,18 @@ export class LongType extends PrimitiveType {
|
|
|
23
26
|
async read(tap) {
|
|
24
27
|
return await tap.readLong();
|
|
25
28
|
}
|
|
26
|
-
/** Writes a long value to the tap. */
|
|
27
|
-
async
|
|
28
|
-
if (!this.check(value)) {
|
|
29
|
-
throwInvalidError([], value, this);
|
|
30
|
-
}
|
|
29
|
+
/** Writes a long value to the tap without validation. */
|
|
30
|
+
async writeUnchecked(tap, value) {
|
|
31
31
|
await tap.writeLong(value);
|
|
32
32
|
}
|
|
33
|
+
/** Returns the encoded byte length of the given value. */
|
|
34
|
+
byteLength(value) {
|
|
35
|
+
return calculateVarintSize(value);
|
|
36
|
+
}
|
|
33
37
|
/** Skips a long value in the tap. */
|
|
34
38
|
async skip(tap) {
|
|
35
39
|
await tap.skipLong();
|
|
36
40
|
}
|
|
37
|
-
/** Converts a bigint value to its buffer representation. */
|
|
38
|
-
async toBuffer(value) {
|
|
39
|
-
this.check(value, throwInvalidError, []);
|
|
40
|
-
// For long, allocate exact size based on value
|
|
41
|
-
const size = calculateVarintSize(value);
|
|
42
|
-
const buf = new ArrayBuffer(size);
|
|
43
|
-
const tap = new WritableTap(buf);
|
|
44
|
-
await this.write(tap, value);
|
|
45
|
-
return buf;
|
|
46
|
-
}
|
|
47
41
|
/**
|
|
48
42
|
* Compares two long values.
|
|
49
43
|
*/
|
|
@@ -78,6 +72,10 @@ export class LongType extends PrimitiveType {
|
|
|
78
72
|
const intValue = await tap.readInt();
|
|
79
73
|
return BigInt(intValue);
|
|
80
74
|
}
|
|
75
|
+
readSync(tap) {
|
|
76
|
+
const intValue = tap.readInt();
|
|
77
|
+
return BigInt(intValue);
|
|
78
|
+
}
|
|
81
79
|
}(this);
|
|
82
80
|
}
|
|
83
81
|
else {
|
|
@@ -92,4 +90,20 @@ export class LongType extends PrimitiveType {
|
|
|
92
90
|
async match(tap1, tap2) {
|
|
93
91
|
return await tap1.matchLong(tap2);
|
|
94
92
|
}
|
|
93
|
+
/** Reads a long value synchronously from the tap. */
|
|
94
|
+
readSync(tap) {
|
|
95
|
+
return tap.readLong();
|
|
96
|
+
}
|
|
97
|
+
/** Writes a long value synchronously to the tap without validation. */
|
|
98
|
+
writeSyncUnchecked(tap, value) {
|
|
99
|
+
tap.writeLong(value);
|
|
100
|
+
}
|
|
101
|
+
/** Skips a long value synchronously in the tap. */
|
|
102
|
+
skipSync(tap) {
|
|
103
|
+
tap.skipLong();
|
|
104
|
+
}
|
|
105
|
+
/** Compares two taps synchronously for long equality. */
|
|
106
|
+
matchSync(tap1, tap2) {
|
|
107
|
+
return tap1.matchLong(tap2);
|
|
108
|
+
}
|
|
95
109
|
}
|
|
@@ -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 { FixedSizeBaseType } from "./fixed_size_base_type.js";
|
|
3
4
|
import type { JSONType } from "../type.js";
|
|
4
5
|
import { type ErrorHook } from "../error.js";
|
|
@@ -6,6 +7,8 @@ import { type ErrorHook } from "../error.js";
|
|
|
6
7
|
* Null type.
|
|
7
8
|
*/
|
|
8
9
|
export declare class NullType extends FixedSizeBaseType<null> {
|
|
10
|
+
/** Creates a new null type. */
|
|
11
|
+
constructor(validate?: boolean);
|
|
9
12
|
/**
|
|
10
13
|
* Checks if the value is null.
|
|
11
14
|
*/
|
|
@@ -14,10 +17,8 @@ export declare class NullType extends FixedSizeBaseType<null> {
|
|
|
14
17
|
* Reads a null value from the tap.
|
|
15
18
|
*/
|
|
16
19
|
read(_tap: ReadableTapLike): Promise<null>;
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
*/
|
|
20
|
-
write(_tap: WritableTapLike, value: null): Promise<void>;
|
|
20
|
+
/** Writes a null value to the tap without validation. */
|
|
21
|
+
writeUnchecked(_tap: WritableTapLike, _value: null): Promise<void>;
|
|
21
22
|
/**
|
|
22
23
|
* Skips a null value in the tap.
|
|
23
24
|
*/
|
|
@@ -42,4 +43,14 @@ export declare class NullType extends FixedSizeBaseType<null> {
|
|
|
42
43
|
toJSON(): JSONType;
|
|
43
44
|
/** Compares two null values in the taps. */
|
|
44
45
|
match(_tap1: ReadableTapLike, _tap2: ReadableTapLike): Promise<number>;
|
|
46
|
+
/**
|
|
47
|
+
* Reads a null value synchronously from the tap.
|
|
48
|
+
*/
|
|
49
|
+
readSync(_tap: SyncReadableTapLike): null;
|
|
50
|
+
/** Writes a null value synchronously to the tap without validation. */
|
|
51
|
+
writeSyncUnchecked(_tap: SyncWritableTapLike, _value: null): void;
|
|
52
|
+
/**
|
|
53
|
+
* Compares two null values synchronously in the taps.
|
|
54
|
+
*/
|
|
55
|
+
matchSync(_tap1: SyncReadableTapLike, _tap2: SyncReadableTapLike): number;
|
|
45
56
|
}
|
|
@@ -4,6 +4,10 @@ import { throwInvalidError } from "../error.js";
|
|
|
4
4
|
* Null type.
|
|
5
5
|
*/
|
|
6
6
|
export class NullType extends FixedSizeBaseType {
|
|
7
|
+
/** Creates a new null type. */
|
|
8
|
+
constructor(validate = true) {
|
|
9
|
+
super(validate);
|
|
10
|
+
}
|
|
7
11
|
/**
|
|
8
12
|
* Checks if the value is null.
|
|
9
13
|
*/
|
|
@@ -20,13 +24,8 @@ export class NullType extends FixedSizeBaseType {
|
|
|
20
24
|
async read(_tap) {
|
|
21
25
|
return await Promise.resolve(null);
|
|
22
26
|
}
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
*/
|
|
26
|
-
async write(_tap, value) {
|
|
27
|
-
if (value !== null) {
|
|
28
|
-
throwInvalidError([], value, this);
|
|
29
|
-
}
|
|
27
|
+
/** Writes a null value to the tap without validation. */
|
|
28
|
+
async writeUnchecked(_tap, _value) {
|
|
30
29
|
await Promise.resolve();
|
|
31
30
|
}
|
|
32
31
|
/**
|
|
@@ -68,4 +67,18 @@ export class NullType extends FixedSizeBaseType {
|
|
|
68
67
|
async match(_tap1, _tap2) {
|
|
69
68
|
return await Promise.resolve(0);
|
|
70
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Reads a null value synchronously from the tap.
|
|
72
|
+
*/
|
|
73
|
+
readSync(_tap) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
/** Writes a null value synchronously to the tap without validation. */
|
|
77
|
+
writeSyncUnchecked(_tap, _value) { }
|
|
78
|
+
/**
|
|
79
|
+
* Compares two null values synchronously in the taps.
|
|
80
|
+
*/
|
|
81
|
+
matchSync(_tap1, _tap2) {
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
71
84
|
}
|
|
@@ -3,6 +3,8 @@ import { BaseType } from "../base_type.js";
|
|
|
3
3
|
* Abstract base class for primitive Avro types.
|
|
4
4
|
*/
|
|
5
5
|
export declare abstract class PrimitiveType<T = unknown> extends BaseType<T> {
|
|
6
|
+
/** Creates a new primitive type. */
|
|
7
|
+
constructor(validate?: boolean);
|
|
6
8
|
/**
|
|
7
9
|
* Clones a primitive value (primitives are immutable).
|
|
8
10
|
*/
|
|
@@ -4,6 +4,10 @@ import { throwInvalidError } from "../error.js";
|
|
|
4
4
|
* Abstract base class for primitive Avro types.
|
|
5
5
|
*/
|
|
6
6
|
export class PrimitiveType extends BaseType {
|
|
7
|
+
/** Creates a new primitive type. */
|
|
8
|
+
constructor(validate = true) {
|
|
9
|
+
super(validate);
|
|
10
|
+
}
|
|
7
11
|
/**
|
|
8
12
|
* Clones a primitive value (primitives are immutable).
|
|
9
13
|
*/
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ReadableTapLike, WritableTapLike } from "../../serialization/tap.js";
|
|
2
|
+
import type { SyncReadableTapLike, SyncWritableTapLike } from "../../serialization/tap_sync.js";
|
|
2
3
|
import { PrimitiveType } from "./primitive_type.js";
|
|
3
4
|
import type { JSONType, Type } from "../type.js";
|
|
4
5
|
import { Resolver } from "../resolver.js";
|
|
5
|
-
import {
|
|
6
|
+
import type { ErrorHook } from "../error.js";
|
|
6
7
|
/**
|
|
7
8
|
* String type.
|
|
8
9
|
*/
|
|
9
10
|
export declare class StringType extends PrimitiveType<string> {
|
|
11
|
+
/** Creates a new string type. */
|
|
12
|
+
constructor(validate?: boolean);
|
|
10
13
|
/** Checks if the value is a valid string. */
|
|
11
14
|
check(value: unknown, errorHook?: ErrorHook, path?: string[]): boolean;
|
|
12
|
-
/** Converts a string value to its Avro-encoded buffer representation. */
|
|
13
|
-
toBuffer(value: string): Promise<ArrayBuffer>;
|
|
14
15
|
/** Reads a string value from the tap. */
|
|
15
16
|
read(tap: ReadableTapLike): Promise<string>;
|
|
16
|
-
/** Writes a string value to the tap. */
|
|
17
|
-
|
|
17
|
+
/** Writes a string value to the tap without validation. */
|
|
18
|
+
writeUnchecked(tap: WritableTapLike, value: string): Promise<void>;
|
|
19
|
+
/** Returns the encoded byte length of the given value. */
|
|
20
|
+
protected byteLength(value: string): number;
|
|
18
21
|
/** Skips a string value in the tap. */
|
|
19
22
|
skip(tap: ReadableTapLike): Promise<void>;
|
|
20
23
|
/**
|
|
@@ -31,4 +34,12 @@ export declare class StringType extends PrimitiveType<string> {
|
|
|
31
34
|
toJSON(): JSONType;
|
|
32
35
|
/** Matches two readable taps for string equality. */
|
|
33
36
|
match(tap1: ReadableTapLike, tap2: ReadableTapLike): Promise<number>;
|
|
37
|
+
/** Reads a string value synchronously from the tap. */
|
|
38
|
+
readSync(tap: SyncReadableTapLike): string;
|
|
39
|
+
/** Writes a string value synchronously to the tap without validation. */
|
|
40
|
+
writeSyncUnchecked(tap: SyncWritableTapLike, value: string): void;
|
|
41
|
+
/** Skips a string value synchronously in the tap. */
|
|
42
|
+
skipSync(tap: SyncReadableTapLike): void;
|
|
43
|
+
/** Matches two readable taps synchronously for string equality. */
|
|
44
|
+
matchSync(tap1: SyncReadableTapLike, tap2: SyncReadableTapLike): number;
|
|
34
45
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { WritableTap, } from "../../serialization/tap.js";
|
|
2
1
|
import { PrimitiveType } from "./primitive_type.js";
|
|
3
2
|
import { Resolver } from "../resolver.js";
|
|
4
|
-
import {
|
|
3
|
+
import { decode, utf8ByteLength } from "../../serialization/text_encoding.js";
|
|
5
4
|
import { calculateVarintSize } from "../../internal/varint.js";
|
|
6
|
-
import { decode, encode } from "../../serialization/text_encoding.js";
|
|
7
5
|
/**
|
|
8
6
|
* String type.
|
|
9
7
|
*/
|
|
10
8
|
export class StringType extends PrimitiveType {
|
|
9
|
+
/** Creates a new string type. */
|
|
10
|
+
constructor(validate = true) {
|
|
11
|
+
super(validate);
|
|
12
|
+
}
|
|
11
13
|
/** Checks if the value is a valid string. */
|
|
12
14
|
check(value, errorHook, path = []) {
|
|
13
15
|
const isValid = typeof value === "string";
|
|
@@ -16,27 +18,19 @@ export class StringType extends PrimitiveType {
|
|
|
16
18
|
}
|
|
17
19
|
return isValid;
|
|
18
20
|
}
|
|
19
|
-
/** Converts a string value to its Avro-encoded buffer representation. */
|
|
20
|
-
async toBuffer(value) {
|
|
21
|
-
this.check(value, throwInvalidError, []);
|
|
22
|
-
const strBytes = encode(value);
|
|
23
|
-
const lengthSize = calculateVarintSize(strBytes.length);
|
|
24
|
-
const buf = new ArrayBuffer(lengthSize + strBytes.length);
|
|
25
|
-
const tap = new WritableTap(buf);
|
|
26
|
-
await this.write(tap, value);
|
|
27
|
-
return buf;
|
|
28
|
-
}
|
|
29
21
|
/** Reads a string value from the tap. */
|
|
30
22
|
async read(tap) {
|
|
31
23
|
return await tap.readString();
|
|
32
24
|
}
|
|
33
|
-
/** Writes a string value to the tap. */
|
|
34
|
-
async
|
|
35
|
-
if (typeof value !== "string") {
|
|
36
|
-
throwInvalidError([], value, this);
|
|
37
|
-
}
|
|
25
|
+
/** Writes a string value to the tap without validation. */
|
|
26
|
+
async writeUnchecked(tap, value) {
|
|
38
27
|
await tap.writeString(value);
|
|
39
28
|
}
|
|
29
|
+
/** Returns the encoded byte length of the given value. */
|
|
30
|
+
byteLength(value) {
|
|
31
|
+
const length = utf8ByteLength(value);
|
|
32
|
+
return calculateVarintSize(length) + length;
|
|
33
|
+
}
|
|
40
34
|
/** Skips a string value in the tap. */
|
|
41
35
|
async skip(tap) {
|
|
42
36
|
await tap.skipString();
|
|
@@ -64,6 +58,11 @@ export class StringType extends PrimitiveType {
|
|
|
64
58
|
// Convert bytes to string (assuming UTF-8)
|
|
65
59
|
return decode(bytes);
|
|
66
60
|
}
|
|
61
|
+
readSync(tap) {
|
|
62
|
+
const bytes = tap.readBytes();
|
|
63
|
+
// Convert bytes to string (assuming UTF-8)
|
|
64
|
+
return decode(bytes);
|
|
65
|
+
}
|
|
67
66
|
}(this);
|
|
68
67
|
}
|
|
69
68
|
else {
|
|
@@ -78,4 +77,20 @@ export class StringType extends PrimitiveType {
|
|
|
78
77
|
async match(tap1, tap2) {
|
|
79
78
|
return await tap1.matchString(tap2);
|
|
80
79
|
}
|
|
80
|
+
/** Reads a string value synchronously from the tap. */
|
|
81
|
+
readSync(tap) {
|
|
82
|
+
return tap.readString();
|
|
83
|
+
}
|
|
84
|
+
/** Writes a string value synchronously to the tap without validation. */
|
|
85
|
+
writeSyncUnchecked(tap, value) {
|
|
86
|
+
tap.writeString(value);
|
|
87
|
+
}
|
|
88
|
+
/** Skips a string value synchronously in the tap. */
|
|
89
|
+
skipSync(tap) {
|
|
90
|
+
tap.skipString();
|
|
91
|
+
}
|
|
92
|
+
/** Matches two readable taps synchronously for string equality. */
|
|
93
|
+
matchSync(tap1, tap2) {
|
|
94
|
+
return tap1.matchString(tap2);
|
|
95
|
+
}
|
|
81
96
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReadableTapLike } from "../serialization/tap.js";
|
|
2
|
+
import type { SyncReadableTapLike } from "../serialization/tap_sync.js";
|
|
2
3
|
import type { Type } from "./type.js";
|
|
3
4
|
/**
|
|
4
5
|
* Base resolver for schema evolution, allowing reading data written with one schema
|
|
@@ -22,4 +23,9 @@ export declare abstract class Resolver<T = unknown> {
|
|
|
22
23
|
* @param tap The tap to read from.
|
|
23
24
|
*/
|
|
24
25
|
abstract read(tap: ReadableTapLike): Promise<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Reads a value from the sync tap using the resolution logic.
|
|
28
|
+
* @param tap The sync tap to read from.
|
|
29
|
+
*/
|
|
30
|
+
abstract readSync(tap: SyncReadableTapLike): T;
|
|
25
31
|
}
|
package/esm/schemas/type.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReadableTapLike, type WritableTapLike } from "../serialization/tap.js";
|
|
2
|
+
import { type SyncReadableTapLike, type SyncWritableTapLike } from "../serialization/tap_sync.js";
|
|
2
3
|
import type { Resolver } from "./resolver.js";
|
|
3
|
-
import type
|
|
4
|
+
import { type ErrorHook } from "./error.js";
|
|
4
5
|
/**
|
|
5
6
|
* Options for validation, including an optional error hook.
|
|
6
7
|
*/
|
|
@@ -18,12 +19,16 @@ export type JSONType = string | number | boolean | null | {
|
|
|
18
19
|
* Provides the common interface for serialization, deserialization, validation, and cloning.
|
|
19
20
|
*/
|
|
20
21
|
export declare abstract class Type<T = unknown> {
|
|
22
|
+
/** Controls whether write operations validate values before serialization. */
|
|
23
|
+
protected readonly validateWrites: boolean;
|
|
24
|
+
/** Creates a new Type instance. */
|
|
25
|
+
protected constructor(validate?: boolean);
|
|
21
26
|
/**
|
|
22
27
|
* Serializes a value into an ArrayBuffer using the schema.
|
|
23
28
|
* @param value The value to serialize.
|
|
24
29
|
* @returns The serialized ArrayBuffer.
|
|
25
30
|
*/
|
|
26
|
-
|
|
31
|
+
toBuffer(value: T): Promise<ArrayBuffer>;
|
|
27
32
|
/**
|
|
28
33
|
* Deserializes an ArrayBuffer into a value using the schema.
|
|
29
34
|
* @param buffer The ArrayBuffer to deserialize.
|
|
@@ -54,7 +59,15 @@ export declare abstract class Type<T = unknown> {
|
|
|
54
59
|
* @param tap The tap to write to.
|
|
55
60
|
* @param value The value to write.
|
|
56
61
|
*/
|
|
57
|
-
|
|
62
|
+
write(tap: WritableTapLike, value: T): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Writes a value to the tap without performing runtime validation.
|
|
65
|
+
*
|
|
66
|
+
* This is used to implement `createType(schema, { validate: false })`
|
|
67
|
+
* efficiently and recursively. The default implementation delegates to
|
|
68
|
+
* {@link write}.
|
|
69
|
+
*/
|
|
70
|
+
abstract writeUnchecked(tap: WritableTapLike, value: T): Promise<void>;
|
|
58
71
|
/**
|
|
59
72
|
* Reads a value from the tap. Must be implemented by subclasses.
|
|
60
73
|
* @param tap The tap to read from.
|
|
@@ -98,4 +111,51 @@ export declare abstract class Type<T = unknown> {
|
|
|
98
111
|
* @returns -1 if tap1 < tap2, 0 if equal, 1 if tap1 > tap2.
|
|
99
112
|
*/
|
|
100
113
|
abstract match(tap1: ReadableTapLike, tap2: ReadableTapLike): Promise<number>;
|
|
114
|
+
/**
|
|
115
|
+
* Serializes a value into an ArrayBuffer synchronously using the schema.
|
|
116
|
+
* @param value The value to serialize.
|
|
117
|
+
* @returns The serialized ArrayBuffer.
|
|
118
|
+
*/
|
|
119
|
+
toSyncBuffer(value: T): ArrayBuffer;
|
|
120
|
+
/**
|
|
121
|
+
* Deserializes an ArrayBuffer into a value synchronously using the schema.
|
|
122
|
+
* @param buffer The ArrayBuffer to deserialize.
|
|
123
|
+
* @returns The deserialized value.
|
|
124
|
+
*/
|
|
125
|
+
abstract fromSyncBuffer(buffer: ArrayBuffer): T;
|
|
126
|
+
/**
|
|
127
|
+
* Writes a value to the sync tap. Must be implemented by subclasses.
|
|
128
|
+
* @param tap The sync tap to write to.
|
|
129
|
+
* @param value The value to write.
|
|
130
|
+
*/
|
|
131
|
+
writeSync(tap: SyncWritableTapLike, value: T): void;
|
|
132
|
+
/**
|
|
133
|
+
* Writes a value to the sync tap without performing runtime validation.
|
|
134
|
+
*
|
|
135
|
+
* The default implementation delegates to {@link writeSync}.
|
|
136
|
+
*/
|
|
137
|
+
abstract writeSyncUnchecked(tap: SyncWritableTapLike, value: T): void;
|
|
138
|
+
/**
|
|
139
|
+
* Reads a value from the sync tap. Must be implemented by subclasses.
|
|
140
|
+
* @param tap The sync tap to read from.
|
|
141
|
+
* @returns The read value.
|
|
142
|
+
*/
|
|
143
|
+
abstract readSync(tap: SyncReadableTapLike): T;
|
|
144
|
+
/**
|
|
145
|
+
* Skips a value in the sync tap. Must be implemented by subclasses.
|
|
146
|
+
* @param tap The sync tap to skip from.
|
|
147
|
+
*/
|
|
148
|
+
abstract skipSync(tap: SyncReadableTapLike): void;
|
|
149
|
+
/**
|
|
150
|
+
* Compares two encoded buffers synchronously. Must be implemented by subclasses.
|
|
151
|
+
* @param tap1 The first sync tap.
|
|
152
|
+
* @param tap2 The second sync tap.
|
|
153
|
+
* @returns -1 if tap1 < tap2, 0 if equal, 1 if tap1 > tap2.
|
|
154
|
+
*/
|
|
155
|
+
abstract matchSync(tap1: SyncReadableTapLike, tap2: SyncReadableTapLike): number;
|
|
156
|
+
/**
|
|
157
|
+
* Returns the encoded byte length for the value when it is cheap to compute.
|
|
158
|
+
* Override in types with fixed or easily derived sizes to skip counting taps.
|
|
159
|
+
*/
|
|
160
|
+
protected byteLength(_value: T): number | undefined;
|
|
101
161
|
}
|