@sapphire/string-store 1.1.0-next.7c2bed20

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.
@@ -0,0 +1,896 @@
1
+ var SapphireStringStore = (function (exports) {
2
+ 'use strict';
3
+
4
+ var __defProp = Object.defineProperty;
5
+ var __typeError = (msg) => {
6
+ throw TypeError(msg);
7
+ };
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
11
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
12
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
13
+ 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);
14
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
15
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
16
+ var __privateWrapper = (obj, member, setter, getter) => ({
17
+ set _(value) {
18
+ __privateSet(obj, member, value);
19
+ },
20
+ get _() {
21
+ return __privateGet(obj, member, getter);
22
+ }
23
+ });
24
+
25
+ // src/lib/shared/_common.ts
26
+ function isArrayLike(object) {
27
+ if (!isObject(object)) return false;
28
+ if (Array.isArray(object)) return true;
29
+ if (!hasLength(object)) return false;
30
+ if (!isValidLength(object.length)) return false;
31
+ return object.length === 0 || object.length - 1 in object;
32
+ }
33
+ __name(isArrayLike, "isArrayLike");
34
+ function isObject(item) {
35
+ return typeof item === "object" && item !== null;
36
+ }
37
+ __name(isObject, "isObject");
38
+ function hasLength(item) {
39
+ return "length" in item && typeof item.length === "number";
40
+ }
41
+ __name(hasLength, "hasLength");
42
+ function isValidLength(length) {
43
+ return Number.isSafeInteger(length) && length >= 0 && length < 2147483648;
44
+ }
45
+ __name(isValidLength, "isValidLength");
46
+
47
+ // src/lib/shared/Pointer.ts
48
+ var _value;
49
+ var _Pointer = class _Pointer {
50
+ constructor() {
51
+ __privateAdd(this, _value, 0);
52
+ }
53
+ get value() {
54
+ return __privateGet(this, _value);
55
+ }
56
+ add(value) {
57
+ const added = __privateGet(this, _value) + value;
58
+ if (!isValidLength(added)) {
59
+ throw new RangeError(`The pointer value cannot be an invalid length value`);
60
+ }
61
+ __privateSet(this, _value, added);
62
+ return this;
63
+ }
64
+ static from(pointer) {
65
+ if (pointer instanceof _Pointer) {
66
+ return pointer;
67
+ }
68
+ const instance = new _Pointer();
69
+ instance.add(Number(pointer));
70
+ return instance;
71
+ }
72
+ };
73
+ _value = new WeakMap();
74
+ __name(_Pointer, "Pointer");
75
+ var Pointer = _Pointer;
76
+
77
+ // src/lib/types/Array.ts
78
+ function ArrayType(type) {
79
+ return {
80
+ serialize(buffer, values) {
81
+ if (!isArrayLike(values)) {
82
+ throw new TypeError(`Expected an array, got ${values}`);
83
+ }
84
+ buffer.writeInt16(values.length);
85
+ for (const value of values) {
86
+ type.serialize(buffer, value);
87
+ }
88
+ },
89
+ deserialize(buffer, pointer) {
90
+ const length = buffer.readInt16(pointer);
91
+ const value = [];
92
+ for (let i = 0; i < length; i++) {
93
+ value.push(type.deserialize(buffer, pointer));
94
+ }
95
+ return value;
96
+ },
97
+ BIT_SIZE: null
98
+ };
99
+ }
100
+ __name(ArrayType, "ArrayType");
101
+
102
+ // src/lib/types/BigInt32.ts
103
+ var BigInt32Type = {
104
+ serialize(buffer, value) {
105
+ buffer.writeBigInt32(value);
106
+ },
107
+ deserialize(buffer, pointer) {
108
+ return buffer.readBigInt32(pointer);
109
+ },
110
+ BIT_SIZE: 32
111
+ };
112
+
113
+ // src/lib/types/BigInt64.ts
114
+ var BigInt64Type = {
115
+ serialize(buffer, value) {
116
+ buffer.writeBigInt64(value);
117
+ },
118
+ deserialize(buffer, pointer) {
119
+ return buffer.readBigInt64(pointer);
120
+ },
121
+ BIT_SIZE: 64
122
+ };
123
+
124
+ // src/lib/types/Bit.ts
125
+ var BitType = {
126
+ serialize(buffer, value) {
127
+ buffer.writeBit(value & 1);
128
+ },
129
+ deserialize(buffer, pointer) {
130
+ return buffer.readBit(pointer);
131
+ },
132
+ BIT_SIZE: 1
133
+ };
134
+
135
+ // src/lib/types/Boolean.ts
136
+ var BooleanType = {
137
+ serialize(buffer, value) {
138
+ buffer.writeBit(Number(value));
139
+ },
140
+ deserialize(buffer, pointer) {
141
+ return buffer.readBit(pointer) === 1;
142
+ },
143
+ BIT_SIZE: 1
144
+ };
145
+
146
+ // src/lib/types/FixedLengthArray.ts
147
+ function FixedLengthArrayType(type, length) {
148
+ return {
149
+ serialize(buffer, values) {
150
+ if (!isArrayLike(values) || values.length !== length) {
151
+ throw new TypeError(`Expected array of length ${length}, got ${values.length}`);
152
+ }
153
+ for (let i = 0; i < length; i++) {
154
+ type.serialize(buffer, values[i]);
155
+ }
156
+ },
157
+ deserialize(buffer, pointer) {
158
+ const value = [];
159
+ for (let i = 0; i < length; i++) {
160
+ value.push(type.deserialize(buffer, pointer));
161
+ }
162
+ return value;
163
+ },
164
+ BIT_SIZE: typeof type.BIT_SIZE === "number" ? type.BIT_SIZE * length : null
165
+ };
166
+ }
167
+ __name(FixedLengthArrayType, "FixedLengthArrayType");
168
+
169
+ // src/lib/types/Float32.ts
170
+ var Float32Type = {
171
+ serialize(buffer, value) {
172
+ buffer.writeFloat32(value);
173
+ },
174
+ deserialize(buffer, pointer) {
175
+ return buffer.readFloat32(pointer);
176
+ },
177
+ BIT_SIZE: 32
178
+ };
179
+
180
+ // src/lib/types/Float64.ts
181
+ var Float64Type = {
182
+ serialize(buffer, value) {
183
+ buffer.writeFloat64(value);
184
+ },
185
+ deserialize(buffer, pointer) {
186
+ return buffer.readFloat64(pointer);
187
+ },
188
+ BIT_SIZE: 64
189
+ };
190
+
191
+ // src/lib/types/Int16.ts
192
+ var Int16Type = {
193
+ serialize(buffer, value) {
194
+ buffer.writeInt16(value);
195
+ },
196
+ deserialize(buffer, pointer) {
197
+ return buffer.readInt16(pointer);
198
+ },
199
+ BIT_SIZE: 16
200
+ };
201
+
202
+ // src/lib/types/Int2.ts
203
+ var Int2Type = {
204
+ serialize(buffer, value) {
205
+ buffer.writeInt2(value);
206
+ },
207
+ deserialize(buffer, pointer) {
208
+ return buffer.readInt2(pointer);
209
+ },
210
+ BIT_SIZE: 2
211
+ };
212
+
213
+ // src/lib/types/Int32.ts
214
+ var Int32Type = {
215
+ serialize(buffer, value) {
216
+ buffer.writeInt32(value);
217
+ },
218
+ deserialize(buffer, pointer) {
219
+ return buffer.readInt32(pointer);
220
+ },
221
+ BIT_SIZE: 32
222
+ };
223
+
224
+ // src/lib/types/Int4.ts
225
+ var Int4Type = {
226
+ serialize(buffer, value) {
227
+ buffer.writeInt4(value);
228
+ },
229
+ deserialize(buffer, pointer) {
230
+ return buffer.readInt4(pointer);
231
+ },
232
+ BIT_SIZE: 4
233
+ };
234
+
235
+ // src/lib/types/Int64.ts
236
+ var Int64Type = {
237
+ serialize(buffer, value) {
238
+ buffer.writeInt64(value);
239
+ },
240
+ deserialize(buffer, pointer) {
241
+ return buffer.readInt64(pointer);
242
+ },
243
+ BIT_SIZE: 64
244
+ };
245
+
246
+ // src/lib/types/Int8.ts
247
+ var Int8Type = {
248
+ serialize(buffer, value) {
249
+ buffer.writeInt8(value);
250
+ },
251
+ deserialize(buffer, pointer) {
252
+ return buffer.readInt8(pointer);
253
+ },
254
+ BIT_SIZE: 8
255
+ };
256
+
257
+ // src/lib/types/Snowflake.ts
258
+ var SnowflakeType = {
259
+ serialize(buffer, value) {
260
+ buffer.writeBigInt64(BigInt(value));
261
+ },
262
+ deserialize(buffer, offset) {
263
+ return buffer.readBigInt64(offset);
264
+ },
265
+ BIT_SIZE: 64
266
+ };
267
+
268
+ // src/lib/types/String.ts
269
+ var encoder = new TextEncoder();
270
+ var decoder = new TextDecoder();
271
+ var StringType = {
272
+ serialize(buffer, value) {
273
+ const encoded = encoder.encode(value);
274
+ buffer.writeInt16(encoded.length);
275
+ for (const byte of encoded) {
276
+ buffer.writeInt8(byte);
277
+ }
278
+ },
279
+ deserialize(buffer, pointer) {
280
+ const length = buffer.readInt16(pointer);
281
+ const bytes = new Uint8Array(length);
282
+ for (let i = 0; i < length; i++) {
283
+ bytes[i] = buffer.readInt8(pointer);
284
+ }
285
+ return decoder.decode(bytes);
286
+ },
287
+ BIT_SIZE: null
288
+ };
289
+
290
+ // src/lib/schema/Schema.ts
291
+ var _id, _types, _bitSize, _Schema_instances, addType_fn;
292
+ var _Schema = class _Schema {
293
+ /**
294
+ * Creates a new schema.
295
+ *
296
+ * @param id The id of the schema
297
+ */
298
+ constructor(id) {
299
+ __privateAdd(this, _Schema_instances);
300
+ __privateAdd(this, _id);
301
+ __privateAdd(this, _types, /* @__PURE__ */ new Map());
302
+ __privateAdd(this, _bitSize, 0);
303
+ __privateSet(this, _id, id);
304
+ }
305
+ /**
306
+ * The id of the schema.
307
+ */
308
+ get id() {
309
+ return __privateGet(this, _id);
310
+ }
311
+ /**
312
+ * The total bit size of the schema.
313
+ *
314
+ * @remarks
315
+ *
316
+ * If any of the entries have a bit size of `null`, the bit size of the
317
+ * schema will also be `null`.
318
+ */
319
+ get bitSize() {
320
+ return __privateGet(this, _bitSize);
321
+ }
322
+ /**
323
+ * Get a property from the schema.
324
+ *
325
+ * @param name The name of the property
326
+ * @returns The specified property
327
+ *
328
+ * @remarks
329
+ *
330
+ * If the property does not exist, an error will be thrown.
331
+ */
332
+ get(name) {
333
+ const type = __privateGet(this, _types).get(name);
334
+ if (!type) throw new Error(`Schema with id ${__privateGet(this, _id)} does not have a property with name "${name}"`);
335
+ return type;
336
+ }
337
+ /**
338
+ * Serialize a value into a buffer.
339
+ *
340
+ * @param buffer The buffer to serialize
341
+ * @param value The value to serialize into the buffer
342
+ *
343
+ * @remarks
344
+ *
345
+ * The schema's ID is written to the buffer first, followed by each property
346
+ * in the schema.
347
+ */
348
+ serialize(buffer, value) {
349
+ buffer.writeInt16(__privateGet(this, _id));
350
+ for (const [name, type] of this) {
351
+ type.serialize(buffer, value[name]);
352
+ }
353
+ }
354
+ /**
355
+ * Deserialize a value from a buffer.
356
+ *
357
+ * @param buffer The buffer to deserialize
358
+ * @param pointer The pointer to where the buffer should be read from
359
+ * @returns The deserialized value
360
+ *
361
+ * @remarks
362
+ *
363
+ * Unlike {@link Schema.serialize}, this method does not read the schema's ID
364
+ * from the buffer, that is reserved for the {@link SchemaStore}.
365
+ */
366
+ deserialize(buffer, pointer) {
367
+ const ptr = Pointer.from(pointer);
368
+ const result = /* @__PURE__ */ Object.create(null);
369
+ for (const [name, type] of this) {
370
+ result[name] = type.deserialize(buffer, ptr);
371
+ }
372
+ return result;
373
+ }
374
+ /**
375
+ * Adds an array property to the schema.
376
+ *
377
+ * @seealso {@link Schema.fixedLengthArray} for a fixed length array
378
+ *
379
+ * @param name The name of the property
380
+ * @param type The type of the entry in the array
381
+ * @returns The modified schema
382
+ */
383
+ array(name, type) {
384
+ return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, ArrayType(type));
385
+ }
386
+ /**
387
+ * Adds a fixed length array property to the schema.
388
+ *
389
+ * @seealso {@link Schema.array} for a dynamic length array
390
+ *
391
+ * @param name The name of the property
392
+ * @param type The type of the entry in the array
393
+ * @param length The length of the array
394
+ * @returns The modified schema
395
+ */
396
+ fixedLengthArray(name, type, length) {
397
+ return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, FixedLengthArrayType(type, length));
398
+ }
399
+ /**
400
+ * Adds a string property to the schema.
401
+ *
402
+ * @param name The name of the property
403
+ * @returns The modified schema
404
+ */
405
+ string(name) {
406
+ return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, StringType);
407
+ }
408
+ /**
409
+ * Adds a boolean property to the schema.
410
+ *
411
+ * @param name The name of the property
412
+ * @returns The modified schema
413
+ */
414
+ boolean(name) {
415
+ return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, BooleanType);
416
+ }
417
+ /**
418
+ * Adds a bit property to the schema.
419
+ *
420
+ * @param name The name of the property
421
+ * @returns The modified schema
422
+ */
423
+ bit(name) {
424
+ return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, BitType);
425
+ }
426
+ /**
427
+ * Adds a 2-bit integer property to the schema.
428
+ *
429
+ * @param name The name of the property
430
+ * @returns The modified schema
431
+ */
432
+ int2(name) {
433
+ return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, Int2Type);
434
+ }
435
+ /**
436
+ * Adds a 4-bit integer property to the schema.
437
+ *
438
+ * @param name The name of the property
439
+ * @returns The modified schema
440
+ */
441
+ int4(name) {
442
+ return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, Int4Type);
443
+ }
444
+ /**
445
+ * Adds a 8-bit integer property to the schema.
446
+ *
447
+ * @param name The name of the property
448
+ * @returns The modified schema
449
+ */
450
+ int8(name) {
451
+ return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, Int8Type);
452
+ }
453
+ /**
454
+ * Adds a 16-bit integer property to the schema.
455
+ *
456
+ * @param name The name of the property
457
+ * @returns The modified schema
458
+ */
459
+ int16(name) {
460
+ return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, Int16Type);
461
+ }
462
+ /**
463
+ * Adds a 32-bit integer property to the schema.
464
+ *
465
+ * @param name The name of the property
466
+ * @returns The modified schema
467
+ */
468
+ int32(name) {
469
+ return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, Int32Type);
470
+ }
471
+ /**
472
+ * Adds a 64-bit integer property to the schema.
473
+ *
474
+ * @param name The name of the property
475
+ * @returns The modified schema
476
+ */
477
+ int64(name) {
478
+ return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, Int64Type);
479
+ }
480
+ /**
481
+ * Adds a 32-bit big integer property to the schema.
482
+ *
483
+ * @param name The name of the property
484
+ * @returns The modified schema
485
+ */
486
+ bigInt32(name) {
487
+ return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, BigInt32Type);
488
+ }
489
+ /**
490
+ * Adds a 64-bit big integer property to the schema.
491
+ *
492
+ * @param name The name of the property
493
+ * @returns The modified schema
494
+ */
495
+ bigInt64(name) {
496
+ return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, BigInt64Type);
497
+ }
498
+ /**
499
+ * Adds a 32-bit floating point number property to the schema.
500
+ *
501
+ * @param name The name of the property
502
+ * @returns The modified schema
503
+ */
504
+ float32(name) {
505
+ return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, Float32Type);
506
+ }
507
+ /**
508
+ * Adds a 64-bit floating point number property to the schema.
509
+ *
510
+ * @param name The name of the property
511
+ * @returns The modified schema
512
+ */
513
+ float64(name) {
514
+ return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, Float64Type);
515
+ }
516
+ /**
517
+ * Adds a 64-bit big integer property to the schema, similar to {@link Schema.bigInt64}.
518
+ *
519
+ * @param name The name of the property
520
+ * @returns The modified schema
521
+ */
522
+ snowflake(name) {
523
+ return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, SnowflakeType);
524
+ }
525
+ /**
526
+ * Iterates over the schema's property names.
527
+ *
528
+ * @returns An iterator for the schema's property names
529
+ */
530
+ keys() {
531
+ return __privateGet(this, _types).keys();
532
+ }
533
+ /**
534
+ * Iterates over the schema's property values
535
+ *
536
+ * @returns An iterator for the schema's property values
537
+ */
538
+ values() {
539
+ return __privateGet(this, _types).values();
540
+ }
541
+ /**
542
+ * Iterates over the schema's property entries
543
+ *
544
+ * @returns An iterator for the schema's property entries
545
+ */
546
+ entries() {
547
+ return __privateGet(this, _types).entries();
548
+ }
549
+ /**
550
+ * Iterates over the schema's property entries
551
+ *
552
+ * @returns An iterator for the schema's property entries
553
+ */
554
+ [Symbol.iterator]() {
555
+ return this.entries();
556
+ }
557
+ };
558
+ _id = new WeakMap();
559
+ _types = new WeakMap();
560
+ _bitSize = new WeakMap();
561
+ _Schema_instances = new WeakSet();
562
+ addType_fn = /* @__PURE__ */ __name(function(name, type) {
563
+ if (__privateGet(this, _types).has(name)) {
564
+ throw new Error(`Schema with id ${__privateGet(this, _id)} already has a property with name "${name}"`);
565
+ }
566
+ __privateGet(this, _types).set(name, type);
567
+ if (type.BIT_SIZE === null) {
568
+ __privateSet(this, _bitSize, null);
569
+ } else if (__privateGet(this, _bitSize) !== null) {
570
+ __privateSet(this, _bitSize, __privateGet(this, _bitSize) + type.BIT_SIZE);
571
+ }
572
+ return this;
573
+ }, "#addType");
574
+ __name(_Schema, "Schema");
575
+ var Schema = _Schema;
576
+
577
+ // src/lib/UnalignedUint16Array.ts
578
+ var Converter8 = new Uint8Array(8);
579
+ var ConverterFloat = new Float32Array(Converter8.buffer);
580
+ var ConverterDouble = new Float64Array(Converter8.buffer);
581
+ var _buffer, _bitLength, _wordIndex, _wordLength, _UnalignedUint16Array_instances, readBit_fn, readByte_fn, writeBit_fn;
582
+ var _UnalignedUint16Array = class _UnalignedUint16Array {
583
+ constructor(maxLength) {
584
+ __privateAdd(this, _UnalignedUint16Array_instances);
585
+ __privateAdd(this, _buffer);
586
+ __privateAdd(this, _bitLength, 0);
587
+ __privateAdd(this, _wordIndex, 0);
588
+ __privateAdd(this, _wordLength, 0);
589
+ __privateSet(this, _buffer, new Uint16Array(maxLength));
590
+ }
591
+ get maxLength() {
592
+ return __privateGet(this, _buffer).length;
593
+ }
594
+ get maxBitLength() {
595
+ return __privateGet(this, _buffer).length * 16;
596
+ }
597
+ get length() {
598
+ return __privateGet(this, _wordLength);
599
+ }
600
+ get bitLength() {
601
+ return __privateGet(this, _bitLength);
602
+ }
603
+ writeBit(value) {
604
+ __privateMethod(this, _UnalignedUint16Array_instances, writeBit_fn).call(this, value);
605
+ }
606
+ writeInt2(value) {
607
+ this.writeBit(value & 1);
608
+ this.writeBit(value >> 1);
609
+ }
610
+ writeInt4(value) {
611
+ this.writeInt2(value & 3);
612
+ this.writeInt2(value >> 2);
613
+ }
614
+ writeInt8(value) {
615
+ this.writeInt4(value & 15);
616
+ this.writeInt4(value >> 4);
617
+ }
618
+ writeInt16(value) {
619
+ this.writeInt8(value & 255);
620
+ this.writeInt8(value >> 8);
621
+ }
622
+ writeInt32(value) {
623
+ this.writeInt16(value & 65535);
624
+ this.writeInt16(value >> 16);
625
+ }
626
+ writeInt64(value) {
627
+ this.writeBigInt64(BigInt(value));
628
+ }
629
+ writeBigInt32(value) {
630
+ this.writeInt16(Number(value & 0xffffn));
631
+ this.writeInt16(Number(value >> 16n));
632
+ }
633
+ writeBigInt64(value) {
634
+ this.writeInt32(Number(value & 0xffffffffn));
635
+ this.writeInt32(Number(value >> 32n));
636
+ }
637
+ writeFloat32(value) {
638
+ ConverterFloat[0] = value;
639
+ this.writeInt8(Converter8[0]);
640
+ this.writeInt8(Converter8[1]);
641
+ this.writeInt8(Converter8[2]);
642
+ this.writeInt8(Converter8[3]);
643
+ }
644
+ writeFloat64(value) {
645
+ ConverterDouble[0] = value;
646
+ this.writeInt8(Converter8[0]);
647
+ this.writeInt8(Converter8[1]);
648
+ this.writeInt8(Converter8[2]);
649
+ this.writeInt8(Converter8[3]);
650
+ this.writeInt8(Converter8[4]);
651
+ this.writeInt8(Converter8[5]);
652
+ this.writeInt8(Converter8[6]);
653
+ this.writeInt8(Converter8[7]);
654
+ }
655
+ readBit(offset) {
656
+ const ptr = Pointer.from(offset);
657
+ return __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr);
658
+ }
659
+ readInt2(offset) {
660
+ const ptr = Pointer.from(offset);
661
+ return __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 1;
662
+ }
663
+ readInt4(offset) {
664
+ const ptr = Pointer.from(offset);
665
+ 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;
666
+ }
667
+ readInt8(offset) {
668
+ const ptr = Pointer.from(offset);
669
+ return __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
670
+ }
671
+ readInt16(offset) {
672
+ const ptr = Pointer.from(offset);
673
+ return __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr) | __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr) << 8;
674
+ }
675
+ readInt32(offset) {
676
+ return Number(this.readBigInt32(offset));
677
+ }
678
+ readInt64(offset) {
679
+ return Number(this.readBigInt64(offset));
680
+ }
681
+ readBigInt32(offset) {
682
+ const ptr = Pointer.from(offset);
683
+ return BigInt(__privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr)) | BigInt(__privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr)) << 8n | BigInt(__privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr)) << 16n | BigInt(__privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr)) << 24n;
684
+ }
685
+ readBigInt64(offset) {
686
+ const ptr = Pointer.from(offset);
687
+ return BigInt(__privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr)) | BigInt(__privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr)) << 8n | BigInt(__privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr)) << 16n | BigInt(__privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr)) << 24n | BigInt(__privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr)) << 32n | BigInt(__privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr)) << 40n | BigInt(__privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr)) << 48n | BigInt(__privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr)) << 56n;
688
+ }
689
+ readFloat32(offset) {
690
+ const ptr = Pointer.from(offset);
691
+ Converter8[0] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
692
+ Converter8[1] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
693
+ Converter8[2] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
694
+ Converter8[3] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
695
+ return ConverterFloat[0];
696
+ }
697
+ readFloat64(offset) {
698
+ const ptr = Pointer.from(offset);
699
+ Converter8[0] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
700
+ Converter8[1] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
701
+ Converter8[2] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
702
+ Converter8[3] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
703
+ Converter8[4] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
704
+ Converter8[5] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
705
+ Converter8[6] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
706
+ Converter8[7] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
707
+ return ConverterDouble[0];
708
+ }
709
+ toString() {
710
+ let result = "";
711
+ for (let i = 0; i < this.length; i++) {
712
+ result += String.fromCharCode(__privateGet(this, _buffer)[i]);
713
+ }
714
+ return result;
715
+ }
716
+ toArray() {
717
+ return __privateGet(this, _buffer).slice(0, this.length);
718
+ }
719
+ static from(value) {
720
+ if (value instanceof _UnalignedUint16Array) return value;
721
+ const buffer = new _UnalignedUint16Array(value.length);
722
+ for (let i = 0; i < value.length; i++) {
723
+ __privateGet(buffer, _buffer)[i] = value.charCodeAt(i);
724
+ }
725
+ __privateSet(buffer, _bitLength, value.length << 4);
726
+ return buffer;
727
+ }
728
+ };
729
+ _buffer = new WeakMap();
730
+ _bitLength = new WeakMap();
731
+ _wordIndex = new WeakMap();
732
+ _wordLength = new WeakMap();
733
+ _UnalignedUint16Array_instances = new WeakSet();
734
+ readBit_fn = /* @__PURE__ */ __name(function(pointer) {
735
+ const bitOffset = pointer.value;
736
+ const index = bitOffset >> 4;
737
+ const bitIndex = bitOffset & 15;
738
+ pointer.add(1);
739
+ return __privateGet(this, _buffer)[index] >> bitIndex & 1;
740
+ }, "#readBit");
741
+ readByte_fn = /* @__PURE__ */ __name(function(ptr) {
742
+ 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;
743
+ }, "#readByte");
744
+ writeBit_fn = /* @__PURE__ */ __name(function(value) {
745
+ if (__privateGet(this, _wordIndex) === this.maxLength) {
746
+ throw new RangeError(`The buffer is full`);
747
+ }
748
+ if (value) {
749
+ const index = __privateGet(this, _wordIndex);
750
+ const bitIndex = this.bitLength & 15;
751
+ __privateGet(this, _buffer)[index] |= 1 << bitIndex;
752
+ }
753
+ if ((__privateGet(this, _bitLength) & 15) === 0) __privateWrapper(this, _wordLength)._++;
754
+ __privateWrapper(this, _bitLength)._++;
755
+ if ((__privateGet(this, _bitLength) & 15) === 0) __privateWrapper(this, _wordIndex)._++;
756
+ }, "#writeBit");
757
+ __name(_UnalignedUint16Array, "UnalignedUint16Array");
758
+ var UnalignedUint16Array = _UnalignedUint16Array;
759
+
760
+ // src/lib/schema/SchemaStore.ts
761
+ var _schemas;
762
+ var _SchemaStore = class _SchemaStore {
763
+ /**
764
+ * Creates a new schema store
765
+ *
766
+ * @param defaultMaximumArrayLength The default maximum array length for schemas
767
+ */
768
+ constructor(defaultMaximumArrayLength = 100) {
769
+ /**
770
+ * The default maximum array length for schemas
771
+ */
772
+ __publicField(this, "defaultMaximumArrayLength");
773
+ __privateAdd(this, _schemas, /* @__PURE__ */ new Map());
774
+ this.defaultMaximumArrayLength = defaultMaximumArrayLength;
775
+ }
776
+ /**
777
+ * Adds a schema to the store
778
+ *
779
+ * @param schema The schema to add to the store
780
+ * @returns The modified store
781
+ *
782
+ * @remarks
783
+ *
784
+ * An error will be thrown if a schema with the same id already exists in the store.
785
+ */
786
+ add(schema) {
787
+ if (__privateGet(this, _schemas).has(schema.id)) {
788
+ throw new Error(`Schema with id ${schema.id} already exists`);
789
+ }
790
+ __privateGet(this, _schemas).set(schema.id, schema);
791
+ return this;
792
+ }
793
+ /**
794
+ * Gets a schema from the store
795
+ *
796
+ * @param id The id of the schema to get
797
+ * @returns The schema with the given id
798
+ *
799
+ * @remarks
800
+ *
801
+ * An error will be thrown if a schema with the given id does not exist in the store.
802
+ */
803
+ get(id) {
804
+ const schema = __privateGet(this, _schemas).get(id);
805
+ if (!schema) throw new Error(`Schema with id ${id} does not exist`);
806
+ return schema;
807
+ }
808
+ /**
809
+ * Serializes a value using the schema with the given id
810
+ *
811
+ * @param id The id of the schema to use for serialization
812
+ * @param value The value to serialize
813
+ * @returns The serialized buffer
814
+ */
815
+ serialize(id, value) {
816
+ const schema = this.get(id);
817
+ const buffer = new UnalignedUint16Array(schema.bitSize ?? this.defaultMaximumArrayLength);
818
+ schema.serialize(buffer, value);
819
+ return buffer;
820
+ }
821
+ /**
822
+ * Deserializes a buffer
823
+ *
824
+ * @param buffer The buffer to deserialize
825
+ * @returns The resolved value, including the id of the schema used for deserialization
826
+ */
827
+ deserialize(buffer) {
828
+ buffer = UnalignedUint16Array.from(buffer);
829
+ const pointer = new Pointer();
830
+ const id = buffer.readInt16(pointer);
831
+ const schema = this.get(id);
832
+ return { id, data: schema.deserialize(buffer, pointer) };
833
+ }
834
+ /**
835
+ * Iterates over the stores's schema identifiers.
836
+ *
837
+ * @returns An iterator for the stores's schema identifiers
838
+ */
839
+ keys() {
840
+ return __privateGet(this, _schemas).keys();
841
+ }
842
+ /**
843
+ * Iterates over the stores's schemas.
844
+ *
845
+ * @returns An iterator for the stores's schemas
846
+ */
847
+ values() {
848
+ return __privateGet(this, _schemas).values();
849
+ }
850
+ /**
851
+ * Iterates over the stores's schema entries.
852
+ *
853
+ * @returns An iterator for the stores's schema entries
854
+ */
855
+ entries() {
856
+ return __privateGet(this, _schemas).entries();
857
+ }
858
+ /**
859
+ * Iterates over the stores's schema entries.
860
+ *
861
+ * @returns An iterator for the stores's schema entries
862
+ */
863
+ [Symbol.iterator]() {
864
+ return this.entries();
865
+ }
866
+ };
867
+ _schemas = new WeakMap();
868
+ __name(_SchemaStore, "SchemaStore");
869
+ var SchemaStore = _SchemaStore;
870
+
871
+ exports.ArrayType = ArrayType;
872
+ exports.BigInt32Type = BigInt32Type;
873
+ exports.BigInt64Type = BigInt64Type;
874
+ exports.BitType = BitType;
875
+ exports.BooleanType = BooleanType;
876
+ exports.FixedLengthArrayType = FixedLengthArrayType;
877
+ exports.Float32Type = Float32Type;
878
+ exports.Float64Type = Float64Type;
879
+ exports.Int16Type = Int16Type;
880
+ exports.Int2Type = Int2Type;
881
+ exports.Int32Type = Int32Type;
882
+ exports.Int4Type = Int4Type;
883
+ exports.Int64Type = Int64Type;
884
+ exports.Int8Type = Int8Type;
885
+ exports.Pointer = Pointer;
886
+ exports.Schema = Schema;
887
+ exports.SchemaStore = SchemaStore;
888
+ exports.SnowflakeType = SnowflakeType;
889
+ exports.StringType = StringType;
890
+ exports.UnalignedUint16Array = UnalignedUint16Array;
891
+
892
+ return exports;
893
+
894
+ })({});
895
+ //# sourceMappingURL=index.global.js.map
896
+ //# sourceMappingURL=index.global.js.map