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