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