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