@sapphire/string-store 3.0.1-next.e6d4bac4 → 4.0.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.
@@ -1,1410 +0,0 @@
1
- 'use strict';
2
-
3
- var __defProp = Object.defineProperty;
4
- var __typeError = (msg) => {
5
- throw TypeError(msg);
6
- };
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
10
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
11
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
12
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
14
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
15
- var __privateWrapper = (obj, member, setter, getter) => ({
16
- set _(value) {
17
- __privateSet(obj, member, value);
18
- },
19
- get _() {
20
- return __privateGet(obj, member, getter);
21
- }
22
- });
23
-
24
- // src/lib/shared/codepoints.ts
25
- var codepointRanges = [
26
- {
27
- start: 19968,
28
- end: 40956,
29
- indexStart: 0,
30
- indexEnd: 20988
31
- },
32
- {
33
- start: 94208,
34
- end: 100343,
35
- indexStart: 20989,
36
- indexEnd: 27125
37
- },
38
- {
39
- start: 131072,
40
- end: 169482,
41
- indexStart: 27126,
42
- indexEnd: 65536
43
- }
44
- ];
45
-
46
- // src/lib/shared/_common.ts
47
- function isArrayLike(object) {
48
- if (!isObject(object)) return false;
49
- if (Array.isArray(object)) return true;
50
- if (!hasLength(object)) return false;
51
- if (!isValidLength(object.length)) return false;
52
- return object.length === 0 || object.length - 1 in object;
53
- }
54
- __name(isArrayLike, "isArrayLike");
55
- function isObject(item) {
56
- return typeof item === "object" && item !== null;
57
- }
58
- __name(isObject, "isObject");
59
- function hasLength(item) {
60
- return "length" in item && typeof item.length === "number";
61
- }
62
- __name(hasLength, "hasLength");
63
- function isValidLength(length) {
64
- return Number.isSafeInteger(length) && length >= 0 && length < 2147483648;
65
- }
66
- __name(isValidLength, "isValidLength");
67
-
68
- // src/lib/shared/Pointer.ts
69
- var _value;
70
- var _Pointer = class _Pointer {
71
- constructor() {
72
- __privateAdd(this, _value, 0);
73
- }
74
- get value() {
75
- return __privateGet(this, _value);
76
- }
77
- add(value) {
78
- const added = __privateGet(this, _value) + value;
79
- if (!isValidLength(added)) {
80
- throw new RangeError(`The pointer value cannot be an invalid length value`);
81
- }
82
- __privateSet(this, _value, added);
83
- return this;
84
- }
85
- static from(pointer) {
86
- if (pointer instanceof _Pointer) {
87
- return pointer;
88
- }
89
- const instance = new _Pointer();
90
- instance.add(Number(pointer));
91
- return instance;
92
- }
93
- };
94
- _value = new WeakMap();
95
- __name(_Pointer, "Pointer");
96
- var Pointer = _Pointer;
97
-
98
- // src/lib/buffer/UnalignedUint16Array.ts
99
- var ConverterUint8 = new Uint8Array(8);
100
- var ConverterUint16 = new Uint16Array(ConverterUint8.buffer);
101
- var ConverterUint32 = new Uint32Array(ConverterUint8.buffer);
102
- var ConverterUint64 = new BigUint64Array(ConverterUint8.buffer);
103
- var ConverterInt32 = new Int32Array(ConverterUint8.buffer);
104
- var ConverterInt64 = new BigInt64Array(ConverterUint8.buffer);
105
- var ConverterFloat = new Float32Array(ConverterUint8.buffer);
106
- var ConverterDouble = new Float64Array(ConverterUint8.buffer);
107
- var _buffer, _bitLength, _wordIndex, _wordLength, _UnalignedUint16Array_instances, uint16ToCodepoint_fn, readBit_fn, readByte_fn, bufferRead16_fn, bufferRead32_fn, bufferRead64_fn, writeBit_fn, bufferWrite16_fn, _UnalignedUint16Array_static, codepointToUint16_fn;
108
- var _UnalignedUint16Array = class _UnalignedUint16Array {
109
- constructor(maxLength) {
110
- __privateAdd(this, _UnalignedUint16Array_instances);
111
- __privateAdd(this, _buffer);
112
- __privateAdd(this, _bitLength, 0);
113
- __privateAdd(this, _wordIndex, 0);
114
- __privateAdd(this, _wordLength, 0);
115
- __privateSet(this, _buffer, new Uint16Array(maxLength));
116
- }
117
- at(index) {
118
- return __privateGet(this, _buffer).at(index);
119
- }
120
- get maxLength() {
121
- return __privateGet(this, _buffer).length;
122
- }
123
- get maxBitLength() {
124
- return __privateGet(this, _buffer).length * 16;
125
- }
126
- get length() {
127
- return __privateGet(this, _wordLength);
128
- }
129
- get bitLength() {
130
- return __privateGet(this, _bitLength);
131
- }
132
- writeBit(value) {
133
- __privateMethod(this, _UnalignedUint16Array_instances, writeBit_fn).call(this, value);
134
- }
135
- writeInt2(value) {
136
- this.writeBit(value & 1);
137
- this.writeBit(value >> 1);
138
- }
139
- writeInt4(value) {
140
- this.writeInt2(value & 3);
141
- this.writeInt2(value >> 2);
142
- }
143
- writeInt8(value) {
144
- this.writeInt4(value & 15);
145
- this.writeInt4(value >> 4);
146
- }
147
- writeInt16(value) {
148
- __privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, value);
149
- }
150
- writeInt32(value) {
151
- __privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, value);
152
- __privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, value >> 16);
153
- }
154
- writeInt64(value) {
155
- this.writeBigInt64(BigInt(value));
156
- }
157
- writeBigInt32(value) {
158
- ConverterInt64[0] = value;
159
- __privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[0]);
160
- __privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[1]);
161
- }
162
- writeBigInt64(value) {
163
- ConverterInt64[0] = value;
164
- __privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[0]);
165
- __privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[1]);
166
- __privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[2]);
167
- __privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[3]);
168
- }
169
- writeFloat32(value) {
170
- ConverterFloat[0] = value;
171
- __privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[0]);
172
- __privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[1]);
173
- }
174
- writeFloat64(value) {
175
- ConverterDouble[0] = value;
176
- __privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[0]);
177
- __privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[1]);
178
- __privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[2]);
179
- __privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[3]);
180
- }
181
- readBit(offset) {
182
- const ptr = Pointer.from(offset);
183
- return __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr);
184
- }
185
- readInt2(offset) {
186
- return this.readUint2(offset) << 30 >> 30;
187
- }
188
- readUint2(offset) {
189
- const ptr = Pointer.from(offset);
190
- return __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 1;
191
- }
192
- readInt4(offset) {
193
- return this.readUint4(offset) << 28 >> 28;
194
- }
195
- readUint4(offset) {
196
- const ptr = Pointer.from(offset);
197
- return __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 1 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 2 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 3;
198
- }
199
- readInt8(offset) {
200
- return this.readUint8(offset) << 24 >> 24;
201
- }
202
- readUint8(offset) {
203
- const ptr = Pointer.from(offset);
204
- return __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
205
- }
206
- readInt16(offset) {
207
- return this.readUint16(offset) << 16 >> 16;
208
- }
209
- readUint16(offset) {
210
- __privateMethod(this, _UnalignedUint16Array_instances, bufferRead16_fn).call(this, Pointer.from(offset));
211
- return ConverterUint16[0];
212
- }
213
- readInt32(offset) {
214
- __privateMethod(this, _UnalignedUint16Array_instances, bufferRead32_fn).call(this, Pointer.from(offset));
215
- return ConverterInt32[0];
216
- }
217
- readUint32(offset) {
218
- __privateMethod(this, _UnalignedUint16Array_instances, bufferRead32_fn).call(this, Pointer.from(offset));
219
- return ConverterUint32[0];
220
- }
221
- readInt64(offset) {
222
- return Number(this.readBigInt64(offset));
223
- }
224
- readUint64(offset) {
225
- return Number(this.readBigUint64(offset));
226
- }
227
- readBigInt32(offset) {
228
- __privateMethod(this, _UnalignedUint16Array_instances, bufferRead32_fn).call(this, Pointer.from(offset));
229
- return BigInt(ConverterInt32[0]);
230
- }
231
- readBigUint32(offset) {
232
- __privateMethod(this, _UnalignedUint16Array_instances, bufferRead32_fn).call(this, Pointer.from(offset));
233
- return BigInt(ConverterUint32[0]);
234
- }
235
- readBigInt64(offset) {
236
- __privateMethod(this, _UnalignedUint16Array_instances, bufferRead64_fn).call(this, Pointer.from(offset));
237
- return ConverterInt64[0];
238
- }
239
- readBigUint64(offset) {
240
- __privateMethod(this, _UnalignedUint16Array_instances, bufferRead64_fn).call(this, Pointer.from(offset));
241
- return ConverterUint64[0];
242
- }
243
- readFloat32(offset) {
244
- __privateMethod(this, _UnalignedUint16Array_instances, bufferRead32_fn).call(this, Pointer.from(offset));
245
- return ConverterFloat[0];
246
- }
247
- readFloat64(offset) {
248
- __privateMethod(this, _UnalignedUint16Array_instances, bufferRead64_fn).call(this, Pointer.from(offset));
249
- return ConverterDouble[0];
250
- }
251
- toString() {
252
- let result = "";
253
- for (let i = 0; i < this.length; i++) {
254
- result += String.fromCodePoint(__privateMethod(this, _UnalignedUint16Array_instances, uint16ToCodepoint_fn).call(this, __privateGet(this, _buffer)[i]));
255
- }
256
- return result;
257
- }
258
- toArray() {
259
- return __privateGet(this, _buffer).slice(0, this.length);
260
- }
261
- static from(value) {
262
- var _a;
263
- if (typeof value !== "string") return value;
264
- const codepoints = Array.from(value, (char) => char.codePointAt(0));
265
- const buffer = new _UnalignedUint16Array(value.length);
266
- for (let i = 0; i < codepoints.length; i++) {
267
- const index = __privateMethod(_a = _UnalignedUint16Array, _UnalignedUint16Array_static, codepointToUint16_fn).call(_a, codepoints[i]);
268
- __privateGet(buffer, _buffer)[i] = index;
269
- }
270
- __privateSet(buffer, _bitLength, value.length << 4);
271
- return buffer;
272
- }
273
- };
274
- _buffer = new WeakMap();
275
- _bitLength = new WeakMap();
276
- _wordIndex = new WeakMap();
277
- _wordLength = new WeakMap();
278
- _UnalignedUint16Array_instances = new WeakSet();
279
- uint16ToCodepoint_fn = /* @__PURE__ */ __name(function(index) {
280
- for (const range of codepointRanges) {
281
- if (index >= range.indexStart && index <= range.indexEnd) {
282
- return range.start + (index - range.indexStart);
283
- }
284
- }
285
- throw new RangeError(`Index ${index} is out of range`);
286
- }, "#uint16ToCodepoint");
287
- readBit_fn = /* @__PURE__ */ __name(function(pointer) {
288
- const bitOffset = pointer.value;
289
- const index = bitOffset >> 4;
290
- const bitIndex = bitOffset & 15;
291
- pointer.add(1);
292
- return __privateGet(this, _buffer)[index] >> bitIndex & 1;
293
- }, "#readBit");
294
- readByte_fn = /* @__PURE__ */ __name(function(ptr) {
295
- return __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 1 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 2 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 3 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 4 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 5 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 6 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 7;
296
- }, "#readByte");
297
- bufferRead16_fn = /* @__PURE__ */ __name(function(ptr) {
298
- ConverterUint8[0] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
299
- ConverterUint8[1] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
300
- }, "#bufferRead16");
301
- bufferRead32_fn = /* @__PURE__ */ __name(function(ptr) {
302
- ConverterUint8[0] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
303
- ConverterUint8[1] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
304
- ConverterUint8[2] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
305
- ConverterUint8[3] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
306
- }, "#bufferRead32");
307
- bufferRead64_fn = /* @__PURE__ */ __name(function(ptr) {
308
- ConverterUint8[0] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
309
- ConverterUint8[1] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
310
- ConverterUint8[2] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
311
- ConverterUint8[3] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
312
- ConverterUint8[4] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
313
- ConverterUint8[5] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
314
- ConverterUint8[6] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
315
- ConverterUint8[7] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
316
- }, "#bufferRead64");
317
- writeBit_fn = /* @__PURE__ */ __name(function(value) {
318
- if (__privateGet(this, _wordIndex) === this.maxLength) {
319
- throw new RangeError(`The buffer is full`);
320
- }
321
- if (value) {
322
- const index = __privateGet(this, _wordIndex);
323
- const bitIndex = this.bitLength & 15;
324
- __privateGet(this, _buffer)[index] |= 1 << bitIndex;
325
- }
326
- if ((__privateGet(this, _bitLength) & 15) === 0) __privateWrapper(this, _wordLength)._++;
327
- __privateWrapper(this, _bitLength)._++;
328
- if ((__privateGet(this, _bitLength) & 15) === 0) __privateWrapper(this, _wordIndex)._++;
329
- }, "#writeBit");
330
- bufferWrite16_fn = /* @__PURE__ */ __name(function(value) {
331
- const wordIndex = __privateGet(this, _wordIndex);
332
- const bitIndex = this.bitLength & 15;
333
- if (wordIndex + (bitIndex === 0 ? 0 : 1) === this.maxLength) {
334
- throw new RangeError(`The buffer is full`);
335
- }
336
- if (bitIndex === 0) {
337
- __privateGet(this, _buffer)[wordIndex] = value;
338
- } else {
339
- value &= 65535;
340
- __privateGet(this, _buffer)[wordIndex] |= value << bitIndex;
341
- __privateGet(this, _buffer)[wordIndex + 1] = value >> 16 - bitIndex;
342
- }
343
- __privateSet(this, _bitLength, __privateGet(this, _bitLength) + 16);
344
- __privateWrapper(this, _wordIndex)._++;
345
- __privateWrapper(this, _wordLength)._++;
346
- }, "#bufferWrite16");
347
- _UnalignedUint16Array_static = new WeakSet();
348
- codepointToUint16_fn = /* @__PURE__ */ __name(function(codepoint) {
349
- for (const range of codepointRanges) {
350
- if (codepoint >= range.start && codepoint <= range.end) {
351
- return range.indexStart + (codepoint - range.start);
352
- }
353
- }
354
- throw new RangeError(`Codepoint ${codepoint} is out of range`);
355
- }, "#codepointToUint16");
356
- __privateAdd(_UnalignedUint16Array, _UnalignedUint16Array_static);
357
- __name(_UnalignedUint16Array, "UnalignedUint16Array");
358
- var UnalignedUint16Array = _UnalignedUint16Array;
359
-
360
- // src/lib/types/Array.ts
361
- function ArrayType(type) {
362
- return {
363
- serialize(buffer, values) {
364
- if (!isArrayLike(values)) {
365
- throw new TypeError(`Expected an array, got ${values}`);
366
- }
367
- buffer.writeInt16(values.length);
368
- for (const value of values) {
369
- type.serialize(buffer, value);
370
- }
371
- },
372
- deserialize(buffer, pointer) {
373
- const length = buffer.readUint16(pointer);
374
- const value = [];
375
- for (let i = 0; i < length; i++) {
376
- value.push(type.deserialize(buffer, pointer));
377
- }
378
- return value;
379
- },
380
- BIT_SIZE: null
381
- };
382
- }
383
- __name(ArrayType, "ArrayType");
384
-
385
- // src/lib/types/BigInt32.ts
386
- var BigInt32Type = {
387
- serialize(buffer, value) {
388
- buffer.writeBigInt32(value);
389
- },
390
- deserialize(buffer, pointer) {
391
- return buffer.readBigInt32(pointer);
392
- },
393
- BIT_SIZE: 32
394
- };
395
-
396
- // src/lib/types/BigInt64.ts
397
- var BigInt64Type = {
398
- serialize(buffer, value) {
399
- buffer.writeBigInt64(value);
400
- },
401
- deserialize(buffer, pointer) {
402
- return buffer.readBigInt64(pointer);
403
- },
404
- BIT_SIZE: 64
405
- };
406
-
407
- // src/lib/types/BigUint32.ts
408
- var BigUint32Type = {
409
- serialize(buffer, value) {
410
- buffer.writeBigInt32(value);
411
- },
412
- deserialize(buffer, pointer) {
413
- return buffer.readBigUint32(pointer);
414
- },
415
- BIT_SIZE: 32
416
- };
417
-
418
- // src/lib/types/BigUint64.ts
419
- var BigUint64Type = {
420
- serialize(buffer, value) {
421
- buffer.writeBigInt64(value);
422
- },
423
- deserialize(buffer, pointer) {
424
- return buffer.readBigUint64(pointer);
425
- },
426
- BIT_SIZE: 64
427
- };
428
-
429
- // src/lib/types/Bit.ts
430
- var BitType = {
431
- serialize(buffer, value) {
432
- buffer.writeBit(value & 1);
433
- },
434
- deserialize(buffer, pointer) {
435
- return buffer.readBit(pointer);
436
- },
437
- BIT_SIZE: 1
438
- };
439
-
440
- // src/lib/types/Boolean.ts
441
- var BooleanType = {
442
- serialize(buffer, value) {
443
- buffer.writeBit(Number(value));
444
- },
445
- deserialize(buffer, pointer) {
446
- return buffer.readBit(pointer) === 1;
447
- },
448
- BIT_SIZE: 1
449
- };
450
-
451
- // src/lib/types/Constant.ts
452
- function ConstantType(constantValue) {
453
- return {
454
- serialize(_buffer2, _value2) {
455
- },
456
- deserialize(_buffer2, _pointer) {
457
- return constantValue;
458
- },
459
- BIT_SIZE: 0
460
- };
461
- }
462
- __name(ConstantType, "ConstantType");
463
-
464
- // src/lib/types/FixedLengthArray.ts
465
- function FixedLengthArrayType(type, length) {
466
- return {
467
- serialize(buffer, values) {
468
- if (!isArrayLike(values) || values.length !== length) {
469
- throw new TypeError(`Expected array of length ${length}, got ${values.length}`);
470
- }
471
- for (let i = 0; i < length; i++) {
472
- type.serialize(buffer, values[i]);
473
- }
474
- },
475
- deserialize(buffer, pointer) {
476
- const value = [];
477
- for (let i = 0; i < length; i++) {
478
- value.push(type.deserialize(buffer, pointer));
479
- }
480
- return value;
481
- },
482
- BIT_SIZE: typeof type.BIT_SIZE === "number" ? type.BIT_SIZE * length : null
483
- };
484
- }
485
- __name(FixedLengthArrayType, "FixedLengthArrayType");
486
-
487
- // src/lib/types/Float32.ts
488
- var Float32Type = {
489
- serialize(buffer, value) {
490
- buffer.writeFloat32(value);
491
- },
492
- deserialize(buffer, pointer) {
493
- return buffer.readFloat32(pointer);
494
- },
495
- BIT_SIZE: 32
496
- };
497
-
498
- // src/lib/types/Float64.ts
499
- var Float64Type = {
500
- serialize(buffer, value) {
501
- buffer.writeFloat64(value);
502
- },
503
- deserialize(buffer, pointer) {
504
- return buffer.readFloat64(pointer);
505
- },
506
- BIT_SIZE: 64
507
- };
508
-
509
- // src/lib/types/Int16.ts
510
- var Int16Type = {
511
- serialize(buffer, value) {
512
- buffer.writeInt16(value);
513
- },
514
- deserialize(buffer, pointer) {
515
- return buffer.readInt16(pointer);
516
- },
517
- BIT_SIZE: 16
518
- };
519
-
520
- // src/lib/types/Int2.ts
521
- var Int2Type = {
522
- serialize(buffer, value) {
523
- buffer.writeInt2(value);
524
- },
525
- deserialize(buffer, pointer) {
526
- return buffer.readInt2(pointer);
527
- },
528
- BIT_SIZE: 2
529
- };
530
-
531
- // src/lib/types/Int32.ts
532
- var Int32Type = {
533
- serialize(buffer, value) {
534
- buffer.writeInt32(value);
535
- },
536
- deserialize(buffer, pointer) {
537
- return buffer.readInt32(pointer);
538
- },
539
- BIT_SIZE: 32
540
- };
541
-
542
- // src/lib/types/Int4.ts
543
- var Int4Type = {
544
- serialize(buffer, value) {
545
- buffer.writeInt4(value);
546
- },
547
- deserialize(buffer, pointer) {
548
- return buffer.readInt4(pointer);
549
- },
550
- BIT_SIZE: 4
551
- };
552
-
553
- // src/lib/types/Int64.ts
554
- var Int64Type = {
555
- serialize(buffer, value) {
556
- buffer.writeInt64(value);
557
- },
558
- deserialize(buffer, pointer) {
559
- return buffer.readInt64(pointer);
560
- },
561
- BIT_SIZE: 64
562
- };
563
-
564
- // src/lib/types/Int8.ts
565
- var Int8Type = {
566
- serialize(buffer, value) {
567
- buffer.writeInt8(value);
568
- },
569
- deserialize(buffer, pointer) {
570
- return buffer.readInt8(pointer);
571
- },
572
- BIT_SIZE: 8
573
- };
574
-
575
- // src/lib/types/Nullable.ts
576
- function NullableType(type) {
577
- return {
578
- serialize(buffer, value) {
579
- if (value === null || value === void 0) {
580
- buffer.writeBit(0);
581
- } else {
582
- buffer.writeBit(1);
583
- type.serialize(buffer, value);
584
- }
585
- },
586
- deserialize(buffer, pointer) {
587
- return buffer.readBit(pointer) ? type.deserialize(buffer, pointer) : null;
588
- },
589
- BIT_SIZE: null
590
- };
591
- }
592
- __name(NullableType, "NullableType");
593
-
594
- // src/lib/types/Snowflake.ts
595
- var SnowflakeType = {
596
- serialize(buffer, value) {
597
- buffer.writeBigInt64(BigInt(value));
598
- },
599
- deserialize(buffer, offset) {
600
- return buffer.readBigUint64(offset);
601
- },
602
- BIT_SIZE: 64
603
- };
604
-
605
- // src/lib/types/String.ts
606
- var encoder = new TextEncoder();
607
- var decoder = new TextDecoder();
608
- var StringType = {
609
- serialize(buffer, value) {
610
- const encoded = encoder.encode(value);
611
- buffer.writeInt16(encoded.length);
612
- for (const byte of encoded) {
613
- buffer.writeInt8(byte);
614
- }
615
- },
616
- deserialize(buffer, pointer) {
617
- const length = buffer.readInt16(pointer);
618
- const bytes = new Uint8Array(length);
619
- for (let i = 0; i < length; i++) {
620
- bytes[i] = buffer.readInt8(pointer);
621
- }
622
- return decoder.decode(bytes);
623
- },
624
- BIT_SIZE: null
625
- };
626
-
627
- // src/lib/types/Uint16.ts
628
- var Uint16Type = {
629
- serialize(buffer, value) {
630
- buffer.writeInt16(value);
631
- },
632
- deserialize(buffer, pointer) {
633
- return buffer.readUint16(pointer);
634
- },
635
- BIT_SIZE: 16
636
- };
637
-
638
- // src/lib/types/Uint2.ts
639
- var Uint2Type = {
640
- serialize(buffer, value) {
641
- buffer.writeInt2(value);
642
- },
643
- deserialize(buffer, pointer) {
644
- return buffer.readUint2(pointer);
645
- },
646
- BIT_SIZE: 2
647
- };
648
-
649
- // src/lib/types/Uint32.ts
650
- var Uint32Type = {
651
- serialize(buffer, value) {
652
- buffer.writeInt32(value);
653
- },
654
- deserialize(buffer, pointer) {
655
- return buffer.readUint32(pointer);
656
- },
657
- BIT_SIZE: 32
658
- };
659
-
660
- // src/lib/types/Uint4.ts
661
- var Uint4Type = {
662
- serialize(buffer, value) {
663
- buffer.writeInt4(value);
664
- },
665
- deserialize(buffer, pointer) {
666
- return buffer.readUint4(pointer);
667
- },
668
- BIT_SIZE: 4
669
- };
670
-
671
- // src/lib/types/Uint64.ts
672
- var Uint64Type = {
673
- serialize(buffer, value) {
674
- buffer.writeInt64(value);
675
- },
676
- deserialize(buffer, pointer) {
677
- return buffer.readUint64(pointer);
678
- },
679
- BIT_SIZE: 64
680
- };
681
-
682
- // src/lib/types/Uint8.ts
683
- var Uint8Type = {
684
- serialize(buffer, value) {
685
- buffer.writeInt8(value);
686
- },
687
- deserialize(buffer, pointer) {
688
- return buffer.readUint8(pointer);
689
- },
690
- BIT_SIZE: 8
691
- };
692
-
693
- // src/lib/types/index.ts
694
- var t = {
695
- array: ArrayType,
696
- bigInt32: BigInt32Type,
697
- bigInt64: BigInt64Type,
698
- bigUint32: BigUint32Type,
699
- bigUint64: BigUint64Type,
700
- bit: BitType,
701
- boolean: BooleanType,
702
- constant: ConstantType,
703
- fixedLengthArray: FixedLengthArrayType,
704
- float32: Float32Type,
705
- float64: Float64Type,
706
- int16: Int16Type,
707
- int2: Int2Type,
708
- int32: Int32Type,
709
- int4: Int4Type,
710
- int64: Int64Type,
711
- int8: Int8Type,
712
- nullable: NullableType,
713
- snowflake: SnowflakeType,
714
- string: StringType,
715
- uint16: Uint16Type,
716
- uint2: Uint2Type,
717
- uint32: Uint32Type,
718
- uint4: Uint4Type,
719
- uint64: Uint64Type,
720
- uint8: Uint8Type
721
- };
722
-
723
- // src/lib/schema/Schema.ts
724
- var _id, _types, _bitSize, _Schema_instances, addType_fn;
725
- var _Schema = class _Schema {
726
- /**
727
- * Creates a new schema.
728
- *
729
- * @param id The id of the schema
730
- */
731
- constructor(id) {
732
- __privateAdd(this, _Schema_instances);
733
- __privateAdd(this, _id);
734
- __privateAdd(this, _types, /* @__PURE__ */ new Map());
735
- __privateAdd(this, _bitSize, 0);
736
- __privateSet(this, _id, id);
737
- }
738
- /**
739
- * The id of the schema.
740
- */
741
- get id() {
742
- return __privateGet(this, _id);
743
- }
744
- /**
745
- * The bit size of the entries in the schema.
746
- *
747
- * @remarks
748
- *
749
- * If any of the entries have a bit size of `null`, the bit size of the
750
- * schema will also be `null`.
751
- */
752
- get bitSize() {
753
- return __privateGet(this, _bitSize);
754
- }
755
- /**
756
- * The total bit size of the entries in the schema and the ID.
757
- *
758
- * @remarks
759
- *
760
- * If any of the entries have a bit size of `null`, the total bit size of
761
- * the schema will also be `null`.
762
- */
763
- get totalBitSize() {
764
- return __privateGet(this, _bitSize) === null ? null : __privateGet(this, _bitSize) + 16;
765
- }
766
- /**
767
- * Get a property from the schema.
768
- *
769
- * @param name The name of the property
770
- * @returns The specified property
771
- *
772
- * @remarks
773
- *
774
- * If the property does not exist, an error will be thrown.
775
- */
776
- get(name) {
777
- const type = __privateGet(this, _types).get(name);
778
- if (!type) throw new Error(`Schema with id ${__privateGet(this, _id)} does not have a property with name "${name}"`);
779
- return type;
780
- }
781
- /**
782
- * Create a buffer and serialize a value into it, then convert it to a string
783
- *
784
- * @param value The value to serialize into the buffer
785
- * @param defaultMaximumArrayLength The default maximum array length, if any
786
- * @returns The newly created string.
787
- *
788
- * @seealso This method calls {@link Schema.serializeRaw} before calling `toString()` to its result.
789
- */
790
- serialize(value, defaultMaximumArrayLength = 100) {
791
- return this.serializeRaw(value, defaultMaximumArrayLength).toString();
792
- }
793
- /**
794
- * Create a buffer and serialize a value into it.
795
- *
796
- * @param value The value to serialize into the buffer
797
- * @param defaultMaximumArrayLength The default maximum array length, if any
798
- * @returns The newly created buffer.
799
- */
800
- serializeRaw(value, defaultMaximumArrayLength = 100) {
801
- const buffer = new UnalignedUint16Array(this.totalBitSize ?? defaultMaximumArrayLength);
802
- this.serializeInto(buffer, value);
803
- return buffer;
804
- }
805
- /**
806
- * Serialize a value into a buffer.
807
- *
808
- * @param buffer The buffer to serialize
809
- * @param value The value to serialize into the buffer
810
- *
811
- * @remarks
812
- *
813
- * The schema's ID is written to the buffer first, followed by each property
814
- * in the schema.
815
- */
816
- serializeInto(buffer, value) {
817
- buffer.writeInt16(__privateGet(this, _id));
818
- for (const [name, type] of this) {
819
- type.serialize(buffer, value[name]);
820
- }
821
- }
822
- /**
823
- * Deserialize a value from a buffer.
824
- *
825
- * @param buffer The buffer to deserialize
826
- * @param pointer The pointer to where the buffer should be read from
827
- * @returns The deserialized value
828
- *
829
- * @remarks
830
- *
831
- * Unlike {@link Schema.serializeInto}, this method does not read the schema's ID
832
- * from the buffer, that is reserved for the {@link SchemaStore}.
833
- */
834
- deserialize(buffer, pointer) {
835
- buffer = UnalignedUint16Array.from(buffer);
836
- pointer = Pointer.from(pointer);
837
- const result = /* @__PURE__ */ Object.create(null);
838
- for (const [name, type] of this) {
839
- result[name] = type.deserialize(buffer, pointer);
840
- }
841
- return result;
842
- }
843
- /**
844
- * Adds an array property to the schema.
845
- *
846
- * @seealso {@link Schema.fixedLengthArray} for a fixed length array
847
- *
848
- * @param name The name of the property
849
- * @param type The type of the entry in the array
850
- * @returns The modified schema
851
- */
852
- array(name, type) {
853
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.array(type));
854
- }
855
- /**
856
- * Adds a fixed length array property to the schema.
857
- *
858
- * @seealso {@link Schema.array} for a dynamic length array
859
- *
860
- * @param name The name of the property
861
- * @param type The type of the entry in the array
862
- * @param length The length of the array
863
- * @returns The modified schema
864
- */
865
- fixedLengthArray(name, type, length) {
866
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.fixedLengthArray(type, length));
867
- }
868
- /**
869
- * Adds a string property to the schema.
870
- *
871
- * @param name The name of the property
872
- * @returns The modified schema
873
- */
874
- string(name) {
875
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.string);
876
- }
877
- /**
878
- * Adds a boolean property to the schema.
879
- *
880
- * @param name The name of the property
881
- * @returns The modified schema
882
- */
883
- boolean(name) {
884
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.boolean);
885
- }
886
- /**
887
- * Adds a bit property to the schema.
888
- *
889
- * @param name The name of the property
890
- * @returns The modified schema
891
- */
892
- bit(name) {
893
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.bit);
894
- }
895
- /**
896
- * Adds a 2-bit integer property to the schema.
897
- *
898
- * @remarks
899
- *
900
- * The range of values is from -2 to 1, inclusive.
901
- *
902
- * @param name The name of the property
903
- * @returns The modified schema
904
- */
905
- int2(name) {
906
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.int2);
907
- }
908
- /**
909
- * Adds a 2-bit unsigned integer property to the schema.
910
- *
911
- * @remarks
912
- *
913
- * The range of values is from 0 to 3, inclusive.
914
- *
915
- * @param name The name of the property
916
- * @returns The modified schema
917
- */
918
- uint2(name) {
919
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.uint2);
920
- }
921
- /**
922
- * Adds a 4-bit integer property to the schema.
923
- *
924
- * @remarks
925
- *
926
- * The range of values is from -8 to 7, inclusive.
927
- *
928
- * @param name The name of the property
929
- * @returns The modified schema
930
- */
931
- int4(name) {
932
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.int4);
933
- }
934
- /**
935
- * Adds a 4-bit unsigned integer property to the schema.
936
- *
937
- * @remarks
938
- *
939
- * The range of values is from 0 to 15, inclusive.
940
- *
941
- * @param name The name of the property
942
- * @returns The modified schema
943
- */
944
- uint4(name) {
945
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.uint4);
946
- }
947
- /**
948
- * Adds a 8-bit integer property to the schema.
949
- *
950
- * @remarks
951
- *
952
- * The range of values is from -128 to 127, inclusive.
953
- *
954
- * @param name The name of the property
955
- * @returns The modified schema
956
- */
957
- int8(name) {
958
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.int8);
959
- }
960
- /**
961
- * Adds a 8-bit unsigned integer property to the schema.
962
- *
963
- * @remarks
964
- *
965
- * The range of values is from 0 to 255, inclusive.
966
- *
967
- * @param name The name of the property
968
- * @returns The modified schema
969
- */
970
- uint8(name) {
971
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.uint8);
972
- }
973
- /**
974
- * Adds a 16-bit integer property to the schema.
975
- *
976
- * @remarks
977
- *
978
- * The range of values is from -32768 to 32767, inclusive.
979
- *
980
- * @param name The name of the property
981
- * @returns The modified schema
982
- */
983
- int16(name) {
984
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.int16);
985
- }
986
- /**
987
- * Adds a 16-bit unsigned integer property to the schema.
988
- *
989
- * @remarks
990
- *
991
- * The range of values is from 0 to 65535, inclusive.
992
- *
993
- * @param name The name of the property
994
- * @returns The modified schema
995
- */
996
- uint16(name) {
997
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.uint16);
998
- }
999
- /**
1000
- * Adds a 32-bit integer property to the schema.
1001
- *
1002
- * @remarks
1003
- *
1004
- * The range of values is from -2_147_483_648 to 2_147_483_647, inclusive.
1005
- *
1006
- * @param name The name of the property
1007
- * @returns The modified schema
1008
- */
1009
- int32(name) {
1010
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.int32);
1011
- }
1012
- /**
1013
- * Adds a 32-bit unsigned integer property to the schema.
1014
- *
1015
- * @remarks
1016
- *
1017
- * The range of values is from 0 to 4_294_967_295, inclusive.
1018
- *
1019
- * @param name The name of the property
1020
- * @returns The modified schema
1021
- */
1022
- uint32(name) {
1023
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.uint32);
1024
- }
1025
- /**
1026
- * Adds a 64-bit integer property to the schema.
1027
- *
1028
- * @remarks
1029
- *
1030
- * The range of values is from -9_223_372_036_854_775_808 to 9_223_372_036_854_775_807, inclusive.
1031
- *
1032
- * However, it may run into precision issues past the range of `-9_007_199_254_740_991` to `9_007_199_254_740_991`
1033
- *
1034
- * @param name The name of the property
1035
- * @returns The modified schema
1036
- */
1037
- int64(name) {
1038
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.int64);
1039
- }
1040
- /**
1041
- * Adds a 64-bit unsigned integer property to the schema.
1042
- *
1043
- * @remarks
1044
- *
1045
- * The range of values is from 0 to 18_446_744_073_709_551_615, inclusive.
1046
- *
1047
- * However, it may run into precision issues past `9_007_199_254_740_991`
1048
- *
1049
- * @param name The name of the property
1050
- * @returns The modified schema
1051
- */
1052
- uint64(name) {
1053
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.uint64);
1054
- }
1055
- /**
1056
- * Adds a 32-bit big integer property to the schema.
1057
- *
1058
- * @remarks
1059
- *
1060
- * The range of values is from -2_147_483_648n to 2_147_483_647n, inclusive.
1061
- *
1062
- * @param name The name of the property
1063
- * @returns The modified schema
1064
- */
1065
- bigInt32(name) {
1066
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.bigInt32);
1067
- }
1068
- /**
1069
- * Adds a 32-bit big integer property to the schema.
1070
- *
1071
- * @remarks
1072
- *
1073
- * The range of values is from 0n to 4_294_967_295n, inclusive.
1074
- *
1075
- * @param name The name of the property
1076
- * @returns The modified schema
1077
- */
1078
- bigUint32(name) {
1079
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.bigUint32);
1080
- }
1081
- /**
1082
- * Adds a 64-bit big integer property to the schema.
1083
- *
1084
- * @remarks
1085
- *
1086
- * The range of values is from -9_223_372_036_854_775_808n to 9_223_372_036_854_775_807n, inclusive.
1087
- *
1088
- * @param name The name of the property
1089
- * @returns The modified schema
1090
- */
1091
- bigInt64(name) {
1092
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.bigInt64);
1093
- }
1094
- /**
1095
- * Adds a 64-bit big integer property to the schema.
1096
- *
1097
- * @remarks
1098
- *
1099
- * The range of values is from 0n to 18_446_744_073_709_551_615n, inclusive.
1100
- *
1101
- * @param name The name of the property
1102
- * @returns The modified schema
1103
- */
1104
- bigUint64(name) {
1105
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.bigUint64);
1106
- }
1107
- /**
1108
- * Adds a 32-bit floating point number property to the schema.
1109
- *
1110
- * @remarks
1111
- *
1112
- * The range of values is from -3.4028234663852886e+38 to 3.4028234663852886e+38, inclusive.
1113
- *
1114
- * @param name The name of the property
1115
- * @returns The modified schema
1116
- */
1117
- float32(name) {
1118
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.float32);
1119
- }
1120
- /**
1121
- * Adds a 64-bit floating point number property to the schema.
1122
- *
1123
- * @remarks
1124
- *
1125
- * The range of values is from -1.7976931348623157e+308 to 1.7976931348623157e+308, inclusive.
1126
- *
1127
- * @param name The name of the property
1128
- * @returns The modified schema
1129
- */
1130
- float64(name) {
1131
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.float64);
1132
- }
1133
- /**
1134
- * Adds a nullable property to the schema.
1135
- *
1136
- * @param name The name of the property
1137
- * @param type The type of the underlying value
1138
- * @returns The modified schema
1139
- */
1140
- nullable(name, type) {
1141
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.nullable(type));
1142
- }
1143
- /**
1144
- * Adds a 64-bit big integer property to the schema, similar to {@link Schema.bigUint64}.
1145
- *
1146
- * @remarks
1147
- *
1148
- * The range of values is from 0n to 18_446_744_073_709_551_615n, inclusive.
1149
- *
1150
- * @param name The name of the property
1151
- * @returns The modified schema
1152
- */
1153
- snowflake(name) {
1154
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.snowflake);
1155
- }
1156
- /**
1157
- * Adds a constant value in the schema, this will **not** be serialized and
1158
- * can be used to add extra data without making the payload bigger.
1159
- *
1160
- * @param name The name of the property
1161
- * @param constantValue The value to add to the schema
1162
- * @returns The modified schema
1163
- */
1164
- constant(name, constantValue) {
1165
- return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.constant(constantValue));
1166
- }
1167
- /**
1168
- * Iterates over the schema's property names.
1169
- *
1170
- * @returns An iterator for the schema's property names
1171
- */
1172
- keys() {
1173
- return __privateGet(this, _types).keys();
1174
- }
1175
- /**
1176
- * Iterates over the schema's property values
1177
- *
1178
- * @returns An iterator for the schema's property values
1179
- */
1180
- values() {
1181
- return __privateGet(this, _types).values();
1182
- }
1183
- /**
1184
- * Iterates over the schema's property entries
1185
- *
1186
- * @returns An iterator for the schema's property entries
1187
- */
1188
- entries() {
1189
- return __privateGet(this, _types).entries();
1190
- }
1191
- /**
1192
- * Iterates over the schema's property entries
1193
- *
1194
- * @returns An iterator for the schema's property entries
1195
- */
1196
- [Symbol.iterator]() {
1197
- return this.entries();
1198
- }
1199
- };
1200
- _id = new WeakMap();
1201
- _types = new WeakMap();
1202
- _bitSize = new WeakMap();
1203
- _Schema_instances = new WeakSet();
1204
- addType_fn = /* @__PURE__ */ __name(function(name, type) {
1205
- if (__privateGet(this, _types).has(name)) {
1206
- throw new Error(`Schema with id ${__privateGet(this, _id)} already has a property with name "${name}"`);
1207
- }
1208
- __privateGet(this, _types).set(name, type);
1209
- if (type.BIT_SIZE === null) {
1210
- __privateSet(this, _bitSize, null);
1211
- } else if (__privateGet(this, _bitSize) !== null) {
1212
- __privateSet(this, _bitSize, __privateGet(this, _bitSize) + type.BIT_SIZE);
1213
- }
1214
- return this;
1215
- }, "#addType");
1216
- __name(_Schema, "Schema");
1217
- var Schema = _Schema;
1218
-
1219
- // src/lib/schema/SchemaStore.ts
1220
- var _schemas;
1221
- var _SchemaStore = class _SchemaStore {
1222
- /**
1223
- * Creates a new schema store
1224
- *
1225
- * @param defaultMaximumArrayLength The default maximum array length for schemas
1226
- */
1227
- constructor(defaultMaximumArrayLength = 100) {
1228
- /**
1229
- * The default maximum array length for schemas
1230
- */
1231
- __publicField(this, "defaultMaximumArrayLength");
1232
- __privateAdd(this, _schemas, /* @__PURE__ */ new Map());
1233
- this.defaultMaximumArrayLength = defaultMaximumArrayLength;
1234
- }
1235
- /**
1236
- * Adds a schema to the store
1237
- *
1238
- * @param schema The schema to add to the store
1239
- * @returns The modified store
1240
- *
1241
- * @remarks
1242
- *
1243
- * An error will be thrown if a schema with the same id already exists in the store.
1244
- */
1245
- add(schema) {
1246
- if (__privateGet(this, _schemas).has(schema.id)) {
1247
- throw new Error(`Schema with id ${schema.id} already exists`);
1248
- }
1249
- __privateGet(this, _schemas).set(schema.id, schema);
1250
- return this;
1251
- }
1252
- /**
1253
- * Gets a schema from the store
1254
- *
1255
- * @param id The id of the schema to get
1256
- * @returns The schema with the given id
1257
- *
1258
- * @remarks
1259
- *
1260
- * An error will be thrown if a schema with the given id does not exist in the store.
1261
- */
1262
- get(id) {
1263
- const schema = __privateGet(this, _schemas).get(id);
1264
- if (!schema) throw new Error(`Schema with id ${id} does not exist`);
1265
- return schema;
1266
- }
1267
- /**
1268
- * Serializes a value using the schema with the given id
1269
- *
1270
- * @param id The id of the schema to use for serialization
1271
- * @param value The value to serialize
1272
- * @returns The serialized string
1273
- */
1274
- serialize(id, value) {
1275
- return this.serializeRaw(id, value).toString();
1276
- }
1277
- /**
1278
- * Serializes a value using the schema with the given id
1279
- *
1280
- * @param id The id of the schema to use for serialization
1281
- * @param value The value to serialize
1282
- * @returns The serialized buffer
1283
- */
1284
- serializeRaw(id, value) {
1285
- const schema = this.get(id);
1286
- return schema.serializeRaw(value, this.defaultMaximumArrayLength);
1287
- }
1288
- /**
1289
- * Deserializes a buffer
1290
- *
1291
- * @param buffer The buffer to deserialize
1292
- * @returns The resolved value, including the id of the schema used for deserialization
1293
- */
1294
- deserialize(buffer) {
1295
- buffer = UnalignedUint16Array.from(buffer);
1296
- const pointer = new Pointer();
1297
- const id = buffer.readInt16(pointer);
1298
- const schema = this.get(id);
1299
- return { id, data: schema.deserialize(buffer, pointer) };
1300
- }
1301
- /**
1302
- * Gets the serialized ID from a buffer
1303
- *
1304
- * @param buffer The buffer to read the ID from
1305
- * @returns The deserialized ID
1306
- *
1307
- * @remarks
1308
- *
1309
- * If an empty value is passed, a {@linkcode RangeError} will be thrown.
1310
- */
1311
- getIdentifier(buffer) {
1312
- if (buffer.length === 0) {
1313
- throw new RangeError("Expected a non-empty value");
1314
- }
1315
- if (typeof buffer === "string") {
1316
- buffer = UnalignedUint16Array.from(buffer[0]);
1317
- }
1318
- return buffer.at(0);
1319
- }
1320
- /**
1321
- * Iterates over the stores's schema identifiers.
1322
- *
1323
- * @returns An iterator for the stores's schema identifiers
1324
- */
1325
- keys() {
1326
- return __privateGet(this, _schemas).keys();
1327
- }
1328
- /**
1329
- * Iterates over the stores's schemas.
1330
- *
1331
- * @returns An iterator for the stores's schemas
1332
- */
1333
- values() {
1334
- return __privateGet(this, _schemas).values();
1335
- }
1336
- /**
1337
- * Iterates over the stores's schema entries.
1338
- *
1339
- * @returns An iterator for the stores's schema entries
1340
- */
1341
- entries() {
1342
- return __privateGet(this, _schemas).entries();
1343
- }
1344
- /**
1345
- * Iterates over the stores's schema entries.
1346
- *
1347
- * @returns An iterator for the stores's schema entries
1348
- */
1349
- [Symbol.iterator]() {
1350
- return this.entries();
1351
- }
1352
- };
1353
- _schemas = new WeakMap();
1354
- __name(_SchemaStore, "SchemaStore");
1355
- var SchemaStore = _SchemaStore;
1356
-
1357
- // src/lib/utilities.ts
1358
- function toUTF16(buffer) {
1359
- let result = "";
1360
- for (const value of new Uint16Array(buffer.buffer)) {
1361
- result += String.fromCharCode(value);
1362
- }
1363
- return result;
1364
- }
1365
- __name(toUTF16, "toUTF16");
1366
- function fromUTF16(buffer) {
1367
- const result = new Uint16Array(buffer.length);
1368
- for (let i = 0; i < buffer.length; i++) {
1369
- result[i] = buffer.charCodeAt(i);
1370
- }
1371
- return result;
1372
- }
1373
- __name(fromUTF16, "fromUTF16");
1374
-
1375
- exports.ArrayType = ArrayType;
1376
- exports.BigInt32Type = BigInt32Type;
1377
- exports.BigInt64Type = BigInt64Type;
1378
- exports.BigUint32Type = BigUint32Type;
1379
- exports.BigUint64Type = BigUint64Type;
1380
- exports.BitType = BitType;
1381
- exports.BooleanType = BooleanType;
1382
- exports.ConstantType = ConstantType;
1383
- exports.FixedLengthArrayType = FixedLengthArrayType;
1384
- exports.Float32Type = Float32Type;
1385
- exports.Float64Type = Float64Type;
1386
- exports.Int16Type = Int16Type;
1387
- exports.Int2Type = Int2Type;
1388
- exports.Int32Type = Int32Type;
1389
- exports.Int4Type = Int4Type;
1390
- exports.Int64Type = Int64Type;
1391
- exports.Int8Type = Int8Type;
1392
- exports.NullableType = NullableType;
1393
- exports.Pointer = Pointer;
1394
- exports.Schema = Schema;
1395
- exports.SchemaStore = SchemaStore;
1396
- exports.SnowflakeType = SnowflakeType;
1397
- exports.StringType = StringType;
1398
- exports.Uint16Type = Uint16Type;
1399
- exports.Uint2Type = Uint2Type;
1400
- exports.Uint32Type = Uint32Type;
1401
- exports.Uint4Type = Uint4Type;
1402
- exports.Uint64Type = Uint64Type;
1403
- exports.Uint8Type = Uint8Type;
1404
- exports.UnalignedUint16Array = UnalignedUint16Array;
1405
- exports.codepointRanges = codepointRanges;
1406
- exports.fromUTF16 = fromUTF16;
1407
- exports.t = t;
1408
- exports.toUTF16 = toUTF16;
1409
- //# sourceMappingURL=index.cjs.map
1410
- //# sourceMappingURL=index.cjs.map