@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,208 @@
|
|
|
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 _a, _FixedType_size, _FixedType_fromJsonString;
|
|
13
|
+
import { WritableTap, } from "../../serialization/tap.js";
|
|
14
|
+
import { NamedType } from "./named_type.js";
|
|
15
|
+
import { Resolver } from "../resolver.js";
|
|
16
|
+
import { throwInvalidError } from "../error.js";
|
|
17
|
+
import { compareUint8Arrays } from "../../serialization/compare_bytes.js";
|
|
18
|
+
/**
|
|
19
|
+
* Avro `fixed` type representing a fixed-length byte sequence.
|
|
20
|
+
*/
|
|
21
|
+
export class FixedType extends NamedType {
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new FixedType.
|
|
24
|
+
* @param params The fixed type parameters.
|
|
25
|
+
*/
|
|
26
|
+
constructor(params) {
|
|
27
|
+
const { size, ...names } = params;
|
|
28
|
+
if (!Number.isInteger(size) || size < 1) {
|
|
29
|
+
throw new Error(`Invalid fixed size: ${size}. Size must be a positive integer.`);
|
|
30
|
+
}
|
|
31
|
+
super(names);
|
|
32
|
+
_FixedType_size.set(this, void 0);
|
|
33
|
+
__classPrivateFieldSet(this, _FixedType_size, size, "f");
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Gets the size in bytes.
|
|
37
|
+
*/
|
|
38
|
+
sizeBytes() {
|
|
39
|
+
return __classPrivateFieldGet(this, _FixedType_size, "f");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Serializes a value into an ArrayBuffer using the exact fixed size.
|
|
43
|
+
* @param value The value to serialize.
|
|
44
|
+
* @returns The serialized ArrayBuffer.
|
|
45
|
+
*/
|
|
46
|
+
async toBuffer(value) {
|
|
47
|
+
this.check(value, throwInvalidError, []);
|
|
48
|
+
const size = this.sizeBytes();
|
|
49
|
+
const buf = new ArrayBuffer(size);
|
|
50
|
+
const tap = new WritableTap(buf);
|
|
51
|
+
await this.write(tap, value);
|
|
52
|
+
return buf;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Skips a fixed-size value by advancing the tap by the fixed size.
|
|
56
|
+
* @param tap The tap to skip from.
|
|
57
|
+
*/
|
|
58
|
+
async skip(tap) {
|
|
59
|
+
await tap.skipFixed(this.sizeBytes());
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Gets the size in bytes.
|
|
63
|
+
*/
|
|
64
|
+
getSize() {
|
|
65
|
+
return __classPrivateFieldGet(this, _FixedType_size, "f");
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Checks if the value is a valid fixed-size byte array.
|
|
69
|
+
* @param value The value to check.
|
|
70
|
+
* @param errorHook Optional error hook for invalid values.
|
|
71
|
+
* @param path The path for error reporting.
|
|
72
|
+
* @returns True if valid, false otherwise.
|
|
73
|
+
*/
|
|
74
|
+
check(value, errorHook, path = []) {
|
|
75
|
+
const isValid = value instanceof Uint8Array && value.length === __classPrivateFieldGet(this, _FixedType_size, "f");
|
|
76
|
+
if (!isValid && errorHook) {
|
|
77
|
+
errorHook(path.slice(), value, this);
|
|
78
|
+
}
|
|
79
|
+
return isValid;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Reads a fixed-size byte array from the tap.
|
|
83
|
+
* @param tap The tap to read from.
|
|
84
|
+
* @returns The read byte array.
|
|
85
|
+
*/
|
|
86
|
+
async read(tap) {
|
|
87
|
+
return await tap.readFixed(__classPrivateFieldGet(this, _FixedType_size, "f"));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Writes a fixed-size byte array to the tap.
|
|
91
|
+
* @param tap The tap to write to.
|
|
92
|
+
* @param value The byte array to write.
|
|
93
|
+
*/
|
|
94
|
+
async write(tap, value) {
|
|
95
|
+
if (!(value instanceof Uint8Array) || value.length !== __classPrivateFieldGet(this, _FixedType_size, "f")) {
|
|
96
|
+
throwInvalidError([], value, this);
|
|
97
|
+
}
|
|
98
|
+
await tap.writeFixed(value, __classPrivateFieldGet(this, _FixedType_size, "f"));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Matches two fixed-size byte arrays from the taps.
|
|
102
|
+
* @param tap1 The first tap.
|
|
103
|
+
* @param tap2 The second tap.
|
|
104
|
+
* @returns The comparison result.
|
|
105
|
+
*/
|
|
106
|
+
async match(tap1, tap2) {
|
|
107
|
+
return await tap1.matchFixed(tap2, __classPrivateFieldGet(this, _FixedType_size, "f"));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Compares two fixed values for ordering.
|
|
111
|
+
* @param val1 The first value to compare.
|
|
112
|
+
* @param val2 The second value to compare.
|
|
113
|
+
* @returns A negative number if val1 < val2, zero if equal, positive if val1 > val2.
|
|
114
|
+
*/
|
|
115
|
+
compare(val1, val2) {
|
|
116
|
+
if (!(val1 instanceof Uint8Array) || !(val2 instanceof Uint8Array)) {
|
|
117
|
+
throw new Error("Fixed comparison requires Uint8Array values.");
|
|
118
|
+
}
|
|
119
|
+
if (val1.length !== __classPrivateFieldGet(this, _FixedType_size, "f") || val2.length !== __classPrivateFieldGet(this, _FixedType_size, "f")) {
|
|
120
|
+
throw new Error(`Fixed values must be exactly ${__classPrivateFieldGet(this, _FixedType_size, "f")} bytes.`);
|
|
121
|
+
}
|
|
122
|
+
return compareUint8Arrays(val1, val2);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Clones a value into a Uint8Array, validating it against the fixed size.
|
|
126
|
+
* @param value The value to clone, either a Uint8Array or a string.
|
|
127
|
+
* @returns A new Uint8Array copy of the value.
|
|
128
|
+
*/
|
|
129
|
+
cloneFromValue(value) {
|
|
130
|
+
let bytes;
|
|
131
|
+
if (value instanceof Uint8Array) {
|
|
132
|
+
bytes = value;
|
|
133
|
+
}
|
|
134
|
+
else if (typeof value === "string") {
|
|
135
|
+
bytes = __classPrivateFieldGet(_a, _a, "m", _FixedType_fromJsonString).call(_a, value);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
throwInvalidError([], value, this);
|
|
139
|
+
}
|
|
140
|
+
this.check(bytes, throwInvalidError, []);
|
|
141
|
+
return new Uint8Array(bytes);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Generates a random Uint8Array of the fixed size.
|
|
145
|
+
* @returns A random Uint8Array with the fixed length.
|
|
146
|
+
*/
|
|
147
|
+
random() {
|
|
148
|
+
const bytes = new Uint8Array(__classPrivateFieldGet(this, _FixedType_size, "f"));
|
|
149
|
+
for (let i = 0; i < __classPrivateFieldGet(this, _FixedType_size, "f"); i++) {
|
|
150
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
151
|
+
}
|
|
152
|
+
return bytes;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Converts the fixed type to its JSON schema representation.
|
|
156
|
+
* @returns The JSON type object.
|
|
157
|
+
*/
|
|
158
|
+
toJSON() {
|
|
159
|
+
return {
|
|
160
|
+
name: this.getFullName(),
|
|
161
|
+
type: "fixed",
|
|
162
|
+
size: __classPrivateFieldGet(this, _FixedType_size, "f"),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Creates a resolver for schema evolution between fixed types.
|
|
167
|
+
* @param writerType The writer's type to resolve against.
|
|
168
|
+
* @returns A resolver for reading data written with the writer type.
|
|
169
|
+
*/
|
|
170
|
+
createResolver(writerType) {
|
|
171
|
+
if (!(writerType instanceof _a)) {
|
|
172
|
+
return super.createResolver(writerType);
|
|
173
|
+
}
|
|
174
|
+
const acceptableNames = new Set([
|
|
175
|
+
this.getFullName(),
|
|
176
|
+
...this.getAliases(),
|
|
177
|
+
]);
|
|
178
|
+
const writerNames = new Set([
|
|
179
|
+
writerType.getFullName(),
|
|
180
|
+
...writerType.getAliases(),
|
|
181
|
+
]);
|
|
182
|
+
const hasCompatibleName = Array.from(writerNames).some((name) => acceptableNames.has(name));
|
|
183
|
+
if (!hasCompatibleName) {
|
|
184
|
+
throw new Error(`Schema evolution not supported from writer type: ${writerType.getFullName()} to reader type: ${this.getFullName()}`);
|
|
185
|
+
}
|
|
186
|
+
if (__classPrivateFieldGet(this, _FixedType_size, "f") !== writerType.getSize()) {
|
|
187
|
+
throw new Error(`Cannot resolve fixed types with different sizes: writer has ${writerType.getSize()}, reader has ${__classPrivateFieldGet(this, _FixedType_size, "f")}`);
|
|
188
|
+
}
|
|
189
|
+
// If sizes match and names are compatible, we can use the reader's read method directly
|
|
190
|
+
return new FixedResolver(this);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
_a = FixedType, _FixedType_size = new WeakMap(), _FixedType_fromJsonString = function _FixedType_fromJsonString(value) {
|
|
194
|
+
const bytes = new Uint8Array(value.length);
|
|
195
|
+
for (let i = 0; i < value.length; i++) {
|
|
196
|
+
bytes[i] = value.charCodeAt(i) & 0xff;
|
|
197
|
+
}
|
|
198
|
+
return bytes;
|
|
199
|
+
};
|
|
200
|
+
class FixedResolver extends Resolver {
|
|
201
|
+
constructor(reader) {
|
|
202
|
+
super(reader);
|
|
203
|
+
}
|
|
204
|
+
async read(tap) {
|
|
205
|
+
const reader = this.readerType;
|
|
206
|
+
return await reader.read(tap);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { type ReadableTapLike, type WritableTapLike } from "../../serialization/tap.js";
|
|
2
|
+
import { BaseType } from "../base_type.js";
|
|
3
|
+
import { Resolver } from "../resolver.js";
|
|
4
|
+
import type { JSONType, Type } from "../type.js";
|
|
5
|
+
import { type ErrorHook } from "../error.js";
|
|
6
|
+
/**
|
|
7
|
+
* Parameters for creating a MapType.
|
|
8
|
+
*/
|
|
9
|
+
export interface MapTypeParams<T> {
|
|
10
|
+
/** The type of values in the map. */
|
|
11
|
+
values: Type<T>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Helper function to read a map from a tap.
|
|
15
|
+
* @param tap The tap to read from.
|
|
16
|
+
* @param readValue Function to read a single value.
|
|
17
|
+
* @param collect Function to collect each key-value pair.
|
|
18
|
+
*/
|
|
19
|
+
export declare function readMapInto<T>(tap: ReadableTapLike, readValue: (tap: ReadableTapLike) => Promise<T>, collect: (key: string, value: T) => void): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Avro `map` type for string-keyed collections of values matching a schema.
|
|
22
|
+
*/
|
|
23
|
+
export declare class MapType<T = unknown> extends BaseType<Map<string, T>> {
|
|
24
|
+
#private;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new MapType.
|
|
27
|
+
* @param params The map type parameters.
|
|
28
|
+
*/
|
|
29
|
+
constructor(params: MapTypeParams<T>);
|
|
30
|
+
/**
|
|
31
|
+
* Gets the type of values in the map.
|
|
32
|
+
*/
|
|
33
|
+
getValuesType(): Type<T>;
|
|
34
|
+
/**
|
|
35
|
+
* Validates if the value is a valid map according to the schema.
|
|
36
|
+
*/
|
|
37
|
+
check(value: unknown, errorHook?: ErrorHook, path?: string[]): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Writes the map value to the tap.
|
|
40
|
+
* @param tap The writable tap to write to.
|
|
41
|
+
* @param value The map value to write.
|
|
42
|
+
*/
|
|
43
|
+
write(tap: WritableTapLike, value: Map<string, T>): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Reads a map value from the provided tap.
|
|
46
|
+
*/
|
|
47
|
+
read(tap: ReadableTapLike): Promise<Map<string, T>>;
|
|
48
|
+
/**
|
|
49
|
+
* Skips over a map value in the tap without reading it.
|
|
50
|
+
* @param tap The readable tap to skip from.
|
|
51
|
+
*/
|
|
52
|
+
skip(tap: ReadableTapLike): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Serializes the map value to an ArrayBuffer.
|
|
55
|
+
* @param value The map value to serialize.
|
|
56
|
+
* @returns The serialized ArrayBuffer.
|
|
57
|
+
*/
|
|
58
|
+
toBuffer(value: Map<string, T>): Promise<ArrayBuffer>;
|
|
59
|
+
/**
|
|
60
|
+
* Creates a deep clone of the map from the given value.
|
|
61
|
+
* @param value The value to clone, which can be a Map or a plain object.
|
|
62
|
+
* @returns A new Map instance with cloned values.
|
|
63
|
+
*/
|
|
64
|
+
cloneFromValue(value: unknown): Map<string, T>;
|
|
65
|
+
/**
|
|
66
|
+
* Compares two map values. Always throws an error as maps cannot be compared.
|
|
67
|
+
* @param _val1 First map value.
|
|
68
|
+
* @param _val2 Second map value.
|
|
69
|
+
* @returns Never returns, always throws.
|
|
70
|
+
* @throws Always throws an error.
|
|
71
|
+
*/
|
|
72
|
+
compare(_val1: Map<string, T>, _val2: Map<string, T>): number;
|
|
73
|
+
/**
|
|
74
|
+
* Generates a random map value.
|
|
75
|
+
* @returns A random Map with string keys and values of the map's value type.
|
|
76
|
+
*/
|
|
77
|
+
random(): Map<string, T>;
|
|
78
|
+
/**
|
|
79
|
+
* Returns the JSON schema representation of the map type.
|
|
80
|
+
* @returns The JSON representation as JSONType.
|
|
81
|
+
*/
|
|
82
|
+
toJSON(): JSONType;
|
|
83
|
+
/**
|
|
84
|
+
* Compares two encoded buffers. Always throws an error as maps cannot be compared.
|
|
85
|
+
* @param _tap1 The first tap.
|
|
86
|
+
* @param _tap2 The second tap.
|
|
87
|
+
* @returns Never returns, always throws.
|
|
88
|
+
* @throws Always throws an error.
|
|
89
|
+
*/
|
|
90
|
+
match(_tap1: ReadableTapLike, _tap2: ReadableTapLike): Promise<number>;
|
|
91
|
+
/**
|
|
92
|
+
* Creates a resolver for schema evolution from a writer type to this reader type.
|
|
93
|
+
* @param writerType The writer schema type.
|
|
94
|
+
* @returns A resolver for reading the writer type as this type.
|
|
95
|
+
*/
|
|
96
|
+
createResolver(writerType: Type): Resolver;
|
|
97
|
+
}
|
|
@@ -0,0 +1,290 @@
|
|
|
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 _MapType_valuesType, _MapResolver_valueResolver;
|
|
13
|
+
import { WritableTap, } from "../../serialization/tap.js";
|
|
14
|
+
import { encode } from "../../serialization/text_encoding.js";
|
|
15
|
+
import { bigIntToSafeNumber } from "../../serialization/conversion.js";
|
|
16
|
+
import { BaseType } from "../base_type.js";
|
|
17
|
+
import { Resolver } from "../resolver.js";
|
|
18
|
+
import { throwInvalidError } from "../error.js";
|
|
19
|
+
import { calculateVarintSize } from "../../internal/varint.js";
|
|
20
|
+
/**
|
|
21
|
+
* Helper function to read a map from a tap.
|
|
22
|
+
* @param tap The tap to read from.
|
|
23
|
+
* @param readValue Function to read a single value.
|
|
24
|
+
* @param collect Function to collect each key-value pair.
|
|
25
|
+
*/
|
|
26
|
+
export async function readMapInto(tap, readValue, collect) {
|
|
27
|
+
while (true) {
|
|
28
|
+
let rawCount = await tap.readLong();
|
|
29
|
+
if (rawCount === 0n) {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
if (rawCount < 0n) {
|
|
33
|
+
rawCount = -rawCount;
|
|
34
|
+
await tap.skipLong(); // skip block size
|
|
35
|
+
}
|
|
36
|
+
const count = bigIntToSafeNumber(rawCount, "Map block length");
|
|
37
|
+
for (let i = 0; i < count; i++) {
|
|
38
|
+
const key = await tap.readString();
|
|
39
|
+
const value = await readValue(tap);
|
|
40
|
+
collect(key, value);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Avro `map` type for string-keyed collections of values matching a schema.
|
|
46
|
+
*/
|
|
47
|
+
export class MapType extends BaseType {
|
|
48
|
+
/**
|
|
49
|
+
* Creates a new MapType.
|
|
50
|
+
* @param params The map type parameters.
|
|
51
|
+
*/
|
|
52
|
+
constructor(params) {
|
|
53
|
+
super();
|
|
54
|
+
_MapType_valuesType.set(this, void 0);
|
|
55
|
+
if (!params.values) {
|
|
56
|
+
throw new Error("MapType requires a values type.");
|
|
57
|
+
}
|
|
58
|
+
__classPrivateFieldSet(this, _MapType_valuesType, params.values, "f");
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Gets the type of values in the map.
|
|
62
|
+
*/
|
|
63
|
+
getValuesType() {
|
|
64
|
+
return __classPrivateFieldGet(this, _MapType_valuesType, "f");
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Validates if the value is a valid map according to the schema.
|
|
68
|
+
*/
|
|
69
|
+
check(value, errorHook, path = []) {
|
|
70
|
+
if (!(value instanceof Map)) {
|
|
71
|
+
if (errorHook) {
|
|
72
|
+
errorHook(path.slice(), value, this);
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
let isValid = true;
|
|
77
|
+
for (const [key, entry] of value.entries()) {
|
|
78
|
+
if (typeof key !== "string") {
|
|
79
|
+
if (errorHook) {
|
|
80
|
+
errorHook(path.slice(), value, this);
|
|
81
|
+
isValid = false;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
const entryPath = errorHook ? [...path, key] : undefined;
|
|
87
|
+
const validEntry = __classPrivateFieldGet(this, _MapType_valuesType, "f").check(entry, errorHook, entryPath);
|
|
88
|
+
if (!validEntry) {
|
|
89
|
+
if (!errorHook) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
isValid = false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return isValid;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Writes the map value to the tap.
|
|
99
|
+
* @param tap The writable tap to write to.
|
|
100
|
+
* @param value The map value to write.
|
|
101
|
+
*/
|
|
102
|
+
async write(tap, value) {
|
|
103
|
+
if (!(value instanceof Map)) {
|
|
104
|
+
throwInvalidError([], value, this);
|
|
105
|
+
}
|
|
106
|
+
if (value.size > 0) {
|
|
107
|
+
await tap.writeLong(BigInt(value.size));
|
|
108
|
+
for (const [key, entry] of value) {
|
|
109
|
+
if (typeof key !== "string") {
|
|
110
|
+
throwInvalidError([], value, this);
|
|
111
|
+
}
|
|
112
|
+
await tap.writeString(key);
|
|
113
|
+
await __classPrivateFieldGet(this, _MapType_valuesType, "f").write(tap, entry);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
await tap.writeLong(0n);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Reads a map value from the provided tap.
|
|
120
|
+
*/
|
|
121
|
+
async read(tap) {
|
|
122
|
+
const result = new Map();
|
|
123
|
+
await readMapInto(tap, async (innerTap) => await __classPrivateFieldGet(this, _MapType_valuesType, "f").read(innerTap), (key, value) => {
|
|
124
|
+
result.set(key, value);
|
|
125
|
+
});
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Skips over a map value in the tap without reading it.
|
|
130
|
+
* @param tap The readable tap to skip from.
|
|
131
|
+
*/
|
|
132
|
+
async skip(tap) {
|
|
133
|
+
while (true) {
|
|
134
|
+
const rawCount = await tap.readLong();
|
|
135
|
+
if (rawCount === 0n) {
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
if (rawCount < 0n) {
|
|
139
|
+
const blockSize = await tap.readLong();
|
|
140
|
+
const size = bigIntToSafeNumber(blockSize, "Map block size");
|
|
141
|
+
if (size > 0) {
|
|
142
|
+
await tap.skipFixed(size);
|
|
143
|
+
}
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const count = bigIntToSafeNumber(rawCount, "Map block length");
|
|
147
|
+
for (let i = 0; i < count; i++) {
|
|
148
|
+
await tap.skipString();
|
|
149
|
+
await __classPrivateFieldGet(this, _MapType_valuesType, "f").skip(tap);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Serializes the map value to an ArrayBuffer.
|
|
155
|
+
* @param value The map value to serialize.
|
|
156
|
+
* @returns The serialized ArrayBuffer.
|
|
157
|
+
*/
|
|
158
|
+
async toBuffer(value) {
|
|
159
|
+
if (!(value instanceof Map)) {
|
|
160
|
+
throwInvalidError([], value, this);
|
|
161
|
+
}
|
|
162
|
+
const serializedEntries = [];
|
|
163
|
+
let totalSize = 1; // final zero block terminator
|
|
164
|
+
for (const [key, entry] of value.entries()) {
|
|
165
|
+
if (typeof key !== "string") {
|
|
166
|
+
throwInvalidError([], value, this);
|
|
167
|
+
}
|
|
168
|
+
const keyBytes = encode(key);
|
|
169
|
+
const valueBytes = new Uint8Array(await __classPrivateFieldGet(this, _MapType_valuesType, "f").toBuffer(entry));
|
|
170
|
+
totalSize += calculateVarintSize(keyBytes.length) + keyBytes.length;
|
|
171
|
+
totalSize += valueBytes.length;
|
|
172
|
+
serializedEntries.push({ keyBytes, valueBytes });
|
|
173
|
+
}
|
|
174
|
+
if (serializedEntries.length > 0) {
|
|
175
|
+
totalSize += calculateVarintSize(serializedEntries.length);
|
|
176
|
+
}
|
|
177
|
+
const buffer = new ArrayBuffer(totalSize);
|
|
178
|
+
const tap = new WritableTap(buffer);
|
|
179
|
+
if (serializedEntries.length > 0) {
|
|
180
|
+
await tap.writeLong(BigInt(serializedEntries.length));
|
|
181
|
+
for (const { keyBytes, valueBytes } of serializedEntries) {
|
|
182
|
+
await tap.writeLong(BigInt(keyBytes.length));
|
|
183
|
+
await tap.writeFixed(keyBytes);
|
|
184
|
+
await tap.writeFixed(valueBytes);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
await tap.writeLong(0n);
|
|
188
|
+
return buffer;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Creates a deep clone of the map from the given value.
|
|
192
|
+
* @param value The value to clone, which can be a Map or a plain object.
|
|
193
|
+
* @returns A new Map instance with cloned values.
|
|
194
|
+
*/
|
|
195
|
+
cloneFromValue(value) {
|
|
196
|
+
const copy = new Map();
|
|
197
|
+
if (value instanceof Map) {
|
|
198
|
+
for (const [key, entry] of value.entries()) {
|
|
199
|
+
if (typeof key !== "string") {
|
|
200
|
+
throw new Error("Map keys must be strings to clone.");
|
|
201
|
+
}
|
|
202
|
+
copy.set(key, __classPrivateFieldGet(this, _MapType_valuesType, "f").cloneFromValue(entry));
|
|
203
|
+
}
|
|
204
|
+
return copy;
|
|
205
|
+
}
|
|
206
|
+
if (!isPlainObject(value)) {
|
|
207
|
+
throw new Error("Cannot clone non-map value.");
|
|
208
|
+
}
|
|
209
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
210
|
+
copy.set(key, __classPrivateFieldGet(this, _MapType_valuesType, "f").cloneFromValue(entry));
|
|
211
|
+
}
|
|
212
|
+
return copy;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Compares two map values. Always throws an error as maps cannot be compared.
|
|
216
|
+
* @param _val1 First map value.
|
|
217
|
+
* @param _val2 Second map value.
|
|
218
|
+
* @returns Never returns, always throws.
|
|
219
|
+
* @throws Always throws an error.
|
|
220
|
+
*/
|
|
221
|
+
compare(_val1, _val2) {
|
|
222
|
+
throw new Error("maps cannot be compared");
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Generates a random map value.
|
|
226
|
+
* @returns A random Map with string keys and values of the map's value type.
|
|
227
|
+
*/
|
|
228
|
+
random() {
|
|
229
|
+
const result = new Map();
|
|
230
|
+
// There should be at least one entry.
|
|
231
|
+
const entries = Math.ceil(Math.random() * 10);
|
|
232
|
+
for (let i = 0; i < entries; i++) {
|
|
233
|
+
const key = crypto.randomUUID();
|
|
234
|
+
result.set(key, __classPrivateFieldGet(this, _MapType_valuesType, "f").random());
|
|
235
|
+
}
|
|
236
|
+
return result;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Returns the JSON schema representation of the map type.
|
|
240
|
+
* @returns The JSON representation as JSONType.
|
|
241
|
+
*/
|
|
242
|
+
toJSON() {
|
|
243
|
+
return {
|
|
244
|
+
type: "map",
|
|
245
|
+
values: __classPrivateFieldGet(this, _MapType_valuesType, "f").toJSON(),
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Compares two encoded buffers. Always throws an error as maps cannot be compared.
|
|
250
|
+
* @param _tap1 The first tap.
|
|
251
|
+
* @param _tap2 The second tap.
|
|
252
|
+
* @returns Never returns, always throws.
|
|
253
|
+
* @throws Always throws an error.
|
|
254
|
+
*/
|
|
255
|
+
// deno-lint-ignore require-await
|
|
256
|
+
async match(_tap1, _tap2) {
|
|
257
|
+
throw new Error("maps cannot be compared");
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Creates a resolver for schema evolution from a writer type to this reader type.
|
|
261
|
+
* @param writerType The writer schema type.
|
|
262
|
+
* @returns A resolver for reading the writer type as this type.
|
|
263
|
+
*/
|
|
264
|
+
createResolver(writerType) {
|
|
265
|
+
if (!(writerType instanceof MapType)) {
|
|
266
|
+
return super.createResolver(writerType);
|
|
267
|
+
}
|
|
268
|
+
const valueResolver = __classPrivateFieldGet(this, _MapType_valuesType, "f").createResolver(writerType.getValuesType());
|
|
269
|
+
return new MapResolver(this, valueResolver);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
_MapType_valuesType = new WeakMap();
|
|
273
|
+
function isPlainObject(value) {
|
|
274
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
275
|
+
}
|
|
276
|
+
class MapResolver extends Resolver {
|
|
277
|
+
constructor(reader, valueResolver) {
|
|
278
|
+
super(reader);
|
|
279
|
+
_MapResolver_valueResolver.set(this, void 0);
|
|
280
|
+
__classPrivateFieldSet(this, _MapResolver_valueResolver, valueResolver, "f");
|
|
281
|
+
}
|
|
282
|
+
async read(tap) {
|
|
283
|
+
const result = new Map();
|
|
284
|
+
await readMapInto(tap, async (innerTap) => await __classPrivateFieldGet(this, _MapResolver_valueResolver, "f").read(innerTap), (key, value) => {
|
|
285
|
+
result.set(key, value);
|
|
286
|
+
});
|
|
287
|
+
return result;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
_MapResolver_valueResolver = new WeakMap();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseType } from "../base_type.js";
|
|
2
|
+
import type { ResolvedNames } from "./resolve_names.js";
|
|
3
|
+
/**
|
|
4
|
+
* Base class for Avro types that carry a schema name (`record`, `enum`, `fixed`).
|
|
5
|
+
* Resolves the primary name, namespace, and aliases to fully qualified names.
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class NamedType<T = unknown> extends BaseType<T> {
|
|
8
|
+
#private;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new NamedType.
|
|
11
|
+
* @param resolvedNames The resolved names (full name, namespace, aliases).
|
|
12
|
+
*/
|
|
13
|
+
protected constructor(resolvedNames: ResolvedNames);
|
|
14
|
+
/**
|
|
15
|
+
* Fully qualified schema name.
|
|
16
|
+
*/
|
|
17
|
+
getFullName(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Namespace associated with this type (empty string when unspecified).
|
|
20
|
+
*/
|
|
21
|
+
getNamespace(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Fully qualified aliases for this type.
|
|
24
|
+
*/
|
|
25
|
+
getAliases(): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Checks whether the provided name matches either the full name or any alias.
|
|
28
|
+
*/
|
|
29
|
+
matchesName(name: string): boolean;
|
|
30
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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 _NamedType_fullName, _NamedType_namespace, _NamedType_aliases;
|
|
13
|
+
import { BaseType } from "../base_type.js";
|
|
14
|
+
/**
|
|
15
|
+
* Base class for Avro types that carry a schema name (`record`, `enum`, `fixed`).
|
|
16
|
+
* Resolves the primary name, namespace, and aliases to fully qualified names.
|
|
17
|
+
*/
|
|
18
|
+
export class NamedType extends BaseType {
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new NamedType.
|
|
21
|
+
* @param resolvedNames The resolved names (full name, namespace, aliases).
|
|
22
|
+
*/
|
|
23
|
+
constructor(resolvedNames) {
|
|
24
|
+
super();
|
|
25
|
+
_NamedType_fullName.set(this, void 0);
|
|
26
|
+
_NamedType_namespace.set(this, void 0);
|
|
27
|
+
_NamedType_aliases.set(this, void 0);
|
|
28
|
+
__classPrivateFieldSet(this, _NamedType_fullName, resolvedNames.fullName, "f");
|
|
29
|
+
__classPrivateFieldSet(this, _NamedType_namespace, resolvedNames.namespace, "f");
|
|
30
|
+
__classPrivateFieldSet(this, _NamedType_aliases, resolvedNames.aliases, "f");
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Fully qualified schema name.
|
|
34
|
+
*/
|
|
35
|
+
getFullName() {
|
|
36
|
+
return __classPrivateFieldGet(this, _NamedType_fullName, "f");
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Namespace associated with this type (empty string when unspecified).
|
|
40
|
+
*/
|
|
41
|
+
getNamespace() {
|
|
42
|
+
return __classPrivateFieldGet(this, _NamedType_namespace, "f");
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Fully qualified aliases for this type.
|
|
46
|
+
*/
|
|
47
|
+
getAliases() {
|
|
48
|
+
return __classPrivateFieldGet(this, _NamedType_aliases, "f").slice();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Checks whether the provided name matches either the full name or any alias.
|
|
52
|
+
*/
|
|
53
|
+
matchesName(name) {
|
|
54
|
+
return name === __classPrivateFieldGet(this, _NamedType_fullName, "f") || __classPrivateFieldGet(this, _NamedType_aliases, "f").includes(name);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
_NamedType_fullName = new WeakMap(), _NamedType_namespace = new WeakMap(), _NamedType_aliases = new WeakMap();
|