@sapphire/string-store 3.0.1-next.e6d4bac4 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,747 +0,0 @@
1
- /**
2
- * A pointer to a position in a buffer.
3
- *
4
- * This is used to keep track of the current position in a buffer while allowing
5
- * the position to be updated by multiple different functions.
6
- *
7
- * @privateRemarks
8
- *
9
- * This class draws inspiration from the following constructs:
10
- * - `int*` in C/C++
11
- * - `ref int` in C#
12
- * - `*mut i32` in Rust
13
- */
14
- declare class Pointer {
15
- #private;
16
- get value(): number;
17
- add(value: number): this;
18
- static from(pointer: PointerLike): Pointer;
19
- }
20
- type PointerLike = Pointer | {
21
- valueOf(): number;
22
- } | {
23
- [Symbol.toPrimitive](hint: 'number'): number;
24
- };
25
-
26
- interface DuplexBuffer {
27
- at(index: number): number | undefined;
28
- get maxLength(): number;
29
- get maxBitLength(): number;
30
- get length(): number;
31
- get bitLength(): number;
32
- writeBit(value: number): void;
33
- writeInt2(value: number): void;
34
- writeInt4(value: number): void;
35
- writeInt8(value: number): void;
36
- writeInt16(value: number): void;
37
- writeInt32(value: number): void;
38
- writeInt64(value: number): void;
39
- writeBigInt32(value: bigint): void;
40
- writeBigInt64(value: bigint): void;
41
- writeFloat32(value: number): void;
42
- writeFloat64(value: number): void;
43
- readBit(offset: PointerLike): 0 | 1;
44
- readInt2(offset: PointerLike): number;
45
- readUint2(offset: PointerLike): number;
46
- readInt4(offset: PointerLike): number;
47
- readUint4(offset: PointerLike): number;
48
- readInt8(offset: PointerLike): number;
49
- readUint8(offset: PointerLike): number;
50
- readInt16(offset: PointerLike): number;
51
- readUint16(offset: PointerLike): number;
52
- readInt32(offset: PointerLike): number;
53
- readUint32(offset: PointerLike): number;
54
- readInt64(offset: PointerLike): number;
55
- readUint64(offset: PointerLike): number;
56
- readBigInt32(offset: PointerLike): bigint;
57
- readBigUint32(offset: PointerLike): bigint;
58
- readBigInt64(offset: PointerLike): bigint;
59
- readBigUint64(offset: PointerLike): bigint;
60
- readFloat32(offset: PointerLike): number;
61
- readFloat64(offset: PointerLike): number;
62
- toString(): string;
63
- toArray(): Uint16Array;
64
- }
65
-
66
- declare class UnalignedUint16Array implements DuplexBuffer {
67
- #private;
68
- constructor(maxLength: number);
69
- at(index: number): number | undefined;
70
- get maxLength(): number;
71
- get maxBitLength(): number;
72
- get length(): number;
73
- get bitLength(): number;
74
- writeBit(value: number): void;
75
- writeInt2(value: number): void;
76
- writeInt4(value: number): void;
77
- writeInt8(value: number): void;
78
- writeInt16(value: number): void;
79
- writeInt32(value: number): void;
80
- writeInt64(value: number): void;
81
- writeBigInt32(value: bigint): void;
82
- writeBigInt64(value: bigint): void;
83
- writeFloat32(value: number): void;
84
- writeFloat64(value: number): void;
85
- readBit(offset: PointerLike): 0 | 1;
86
- readInt2(offset: PointerLike): number;
87
- readUint2(offset: PointerLike): number;
88
- readInt4(offset: PointerLike): number;
89
- readUint4(offset: PointerLike): number;
90
- readInt8(offset: PointerLike): number;
91
- readUint8(offset: PointerLike): number;
92
- readInt16(offset: PointerLike): number;
93
- readUint16(offset: PointerLike): number;
94
- readInt32(offset: PointerLike): number;
95
- readUint32(offset: PointerLike): number;
96
- readInt64(offset: PointerLike): number;
97
- readUint64(offset: PointerLike): number;
98
- readBigInt32(offset: PointerLike): bigint;
99
- readBigUint32(offset: PointerLike): bigint;
100
- readBigInt64(offset: PointerLike): bigint;
101
- readBigUint64(offset: PointerLike): bigint;
102
- readFloat32(offset: PointerLike): number;
103
- readFloat64(offset: PointerLike): number;
104
- toString(): string;
105
- toArray(): Uint16Array;
106
- static from(value: string | DuplexBuffer): DuplexBuffer;
107
- }
108
-
109
- interface IType<ValueType, BitSize extends number | null, InputValue = ValueType> {
110
- /**
111
- * Serialize a value to a buffer.
112
- *
113
- * @param buffer The buffer to write to
114
- * @param value The value to write
115
- */
116
- serialize(buffer: DuplexBuffer, value: InputValue): void;
117
- /**
118
- * Deserialize a value from a buffer.
119
- *
120
- * @param buffer The buffer to read from
121
- * @param pointer The pointer indicating the current position in the buffer
122
- */
123
- deserialize(buffer: DuplexBuffer, pointer: Pointer): ValueType;
124
- /**
125
- * The size of the value in bits, or `null` if the size is variable.
126
- */
127
- readonly BIT_SIZE: BitSize;
128
- }
129
-
130
- declare function ArrayType<ValueType, ValueBitSize extends number | null>(type: IType<ValueType, ValueBitSize>): IType<ValueType[], null>;
131
-
132
- declare const BigInt32Type: IType<bigint, 32>;
133
-
134
- declare const BigInt64Type: IType<bigint, 64>;
135
-
136
- declare const BigUint32Type: IType<bigint, 32>;
137
-
138
- declare const BigUint64Type: IType<bigint, 64>;
139
-
140
- declare const BitType: IType<0 | 1, 1, number>;
141
-
142
- declare const BooleanType: IType<boolean, 1>;
143
-
144
- declare function ConstantType<const ValueType>(constantValue: ValueType): IType<ValueType, 0, never>;
145
-
146
- declare function FixedLengthArrayType<ValueType, ValueBitSize extends number | null>(type: IType<ValueType, ValueBitSize>, length: number): IType<ValueType[], ValueBitSize extends null ? null : number>;
147
-
148
- declare const Float32Type: IType<number, 32>;
149
-
150
- declare const Float64Type: IType<number, 64>;
151
-
152
- declare const Int16Type: IType<number, 16>;
153
-
154
- declare const Int2Type: IType<number, 2>;
155
-
156
- declare const Int32Type: IType<number, 32>;
157
-
158
- declare const Int4Type: IType<number, 4>;
159
-
160
- declare const Int64Type: IType<number, 64>;
161
-
162
- declare const Int8Type: IType<number, 8>;
163
-
164
- declare function NullableType<ValueType, ValueBitSize extends number | null>(type: IType<ValueType, ValueBitSize>): IType<ValueType | null, null, ValueType | null | undefined>;
165
-
166
- declare const SnowflakeType: IType<bigint, 64, bigint | string>;
167
-
168
- declare const StringType: IType<string, null>;
169
-
170
- declare const Uint16Type: IType<number, 16>;
171
-
172
- declare const Uint2Type: IType<number, 2>;
173
-
174
- declare const Uint32Type: IType<number, 32>;
175
-
176
- declare const Uint4Type: IType<number, 4>;
177
-
178
- declare const Uint64Type: IType<number, 64>;
179
-
180
- declare const Uint8Type: IType<number, 8>;
181
-
182
- declare const t: {
183
- array: typeof ArrayType;
184
- bigInt32: IType<bigint, 32, bigint>;
185
- bigInt64: IType<bigint, 64, bigint>;
186
- bigUint32: IType<bigint, 32, bigint>;
187
- bigUint64: IType<bigint, 64, bigint>;
188
- bit: IType<0 | 1, 1, number>;
189
- boolean: IType<boolean, 1, boolean>;
190
- constant: typeof ConstantType;
191
- fixedLengthArray: typeof FixedLengthArrayType;
192
- float32: IType<number, 32, number>;
193
- float64: IType<number, 64, number>;
194
- int16: IType<number, 16, number>;
195
- int2: IType<number, 2, number>;
196
- int32: IType<number, 32, number>;
197
- int4: IType<number, 4, number>;
198
- int64: IType<number, 64, number>;
199
- int8: IType<number, 8, number>;
200
- nullable: typeof NullableType;
201
- snowflake: IType<bigint, 64, string | bigint>;
202
- string: IType<string, null, string>;
203
- uint16: IType<number, 16, number>;
204
- uint2: IType<number, 2, number>;
205
- uint32: IType<number, 32, number>;
206
- uint4: IType<number, 4, number>;
207
- uint64: IType<number, 64, number>;
208
- uint8: IType<number, 8, number>;
209
- };
210
-
211
- declare class Schema<Id extends number = number, Entries extends object = object> {
212
- #private;
213
- /**
214
- * Creates a new schema.
215
- *
216
- * @param id The id of the schema
217
- */
218
- constructor(id: Id);
219
- /**
220
- * The id of the schema.
221
- */
222
- get id(): Id;
223
- /**
224
- * The bit size of the entries in the schema.
225
- *
226
- * @remarks
227
- *
228
- * If any of the entries have a bit size of `null`, the bit size of the
229
- * schema will also be `null`.
230
- */
231
- get bitSize(): number | null;
232
- /**
233
- * The total bit size of the entries in the schema and the ID.
234
- *
235
- * @remarks
236
- *
237
- * If any of the entries have a bit size of `null`, the total bit size of
238
- * the schema will also be `null`.
239
- */
240
- get totalBitSize(): number | null;
241
- /**
242
- * Get a property from the schema.
243
- *
244
- * @param name The name of the property
245
- * @returns The specified property
246
- *
247
- * @remarks
248
- *
249
- * If the property does not exist, an error will be thrown.
250
- */
251
- get<const Name extends keyof Entries & string>(name: Name): Entries[Name];
252
- /**
253
- * Create a buffer and serialize a value into it, then convert it to a string
254
- *
255
- * @param value The value to serialize into the buffer
256
- * @param defaultMaximumArrayLength The default maximum array length, if any
257
- * @returns The newly created string.
258
- *
259
- * @seealso This method calls {@link Schema.serializeRaw} before calling `toString()` to its result.
260
- */
261
- serialize(value: Readonly<SerializeValueEntries<Entries>>, defaultMaximumArrayLength?: number): string;
262
- /**
263
- * Create a buffer and serialize a value into it.
264
- *
265
- * @param value The value to serialize into the buffer
266
- * @param defaultMaximumArrayLength The default maximum array length, if any
267
- * @returns The newly created buffer.
268
- */
269
- serializeRaw(value: Readonly<SerializeValueEntries<Entries>>, defaultMaximumArrayLength?: number): DuplexBuffer;
270
- /**
271
- * Serialize a value into a buffer.
272
- *
273
- * @param buffer The buffer to serialize
274
- * @param value The value to serialize into the buffer
275
- *
276
- * @remarks
277
- *
278
- * The schema's ID is written to the buffer first, followed by each property
279
- * in the schema.
280
- */
281
- serializeInto(buffer: DuplexBuffer, value: Readonly<SerializeValueEntries<Entries>>): void;
282
- /**
283
- * Deserialize a value from a buffer.
284
- *
285
- * @param buffer The buffer to deserialize
286
- * @param pointer The pointer to where the buffer should be read from
287
- * @returns The deserialized value
288
- *
289
- * @remarks
290
- *
291
- * Unlike {@link Schema.serializeInto}, this method does not read the schema's ID
292
- * from the buffer, that is reserved for the {@link SchemaStore}.
293
- */
294
- deserialize(buffer: DuplexBuffer | string, pointer: PointerLike): UnwrapSchemaEntries<Entries>;
295
- /**
296
- * Adds an array property to the schema.
297
- *
298
- * @seealso {@link Schema.fixedLengthArray} for a fixed length array
299
- *
300
- * @param name The name of the property
301
- * @param type The type of the entry in the array
302
- * @returns The modified schema
303
- */
304
- array<const Name extends string, const ValueType, const ValueBitSize extends number | null>(name: Name, type: IType<ValueType, ValueBitSize>): Merge$1<Id, Entries, Name, IType<ValueType[], null, ValueType[]>>;
305
- /**
306
- * Adds a fixed length array property to the schema.
307
- *
308
- * @seealso {@link Schema.array} for a dynamic length array
309
- *
310
- * @param name The name of the property
311
- * @param type The type of the entry in the array
312
- * @param length The length of the array
313
- * @returns The modified schema
314
- */
315
- fixedLengthArray<const Name extends string, const ValueType, const ValueBitSize extends number | null>(name: Name, type: IType<ValueType, ValueBitSize>, length: number): Merge$1<Id, Entries, Name, IType<ValueType[], ValueBitSize extends null ? null : number, ValueType[]>>;
316
- /**
317
- * Adds a string property to the schema.
318
- *
319
- * @param name The name of the property
320
- * @returns The modified schema
321
- */
322
- string<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<string, null, string>>;
323
- /**
324
- * Adds a boolean property to the schema.
325
- *
326
- * @param name The name of the property
327
- * @returns The modified schema
328
- */
329
- boolean<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<boolean, 1, boolean>>;
330
- /**
331
- * Adds a bit property to the schema.
332
- *
333
- * @param name The name of the property
334
- * @returns The modified schema
335
- */
336
- bit<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<0 | 1, 1, number>>;
337
- /**
338
- * Adds a 2-bit integer property to the schema.
339
- *
340
- * @remarks
341
- *
342
- * The range of values is from -2 to 1, inclusive.
343
- *
344
- * @param name The name of the property
345
- * @returns The modified schema
346
- */
347
- int2<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 2, number>>;
348
- /**
349
- * Adds a 2-bit unsigned integer property to the schema.
350
- *
351
- * @remarks
352
- *
353
- * The range of values is from 0 to 3, inclusive.
354
- *
355
- * @param name The name of the property
356
- * @returns The modified schema
357
- */
358
- uint2<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 2, number>>;
359
- /**
360
- * Adds a 4-bit integer property to the schema.
361
- *
362
- * @remarks
363
- *
364
- * The range of values is from -8 to 7, inclusive.
365
- *
366
- * @param name The name of the property
367
- * @returns The modified schema
368
- */
369
- int4<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 4, number>>;
370
- /**
371
- * Adds a 4-bit unsigned integer property to the schema.
372
- *
373
- * @remarks
374
- *
375
- * The range of values is from 0 to 15, inclusive.
376
- *
377
- * @param name The name of the property
378
- * @returns The modified schema
379
- */
380
- uint4<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 4, number>>;
381
- /**
382
- * Adds a 8-bit integer property to the schema.
383
- *
384
- * @remarks
385
- *
386
- * The range of values is from -128 to 127, inclusive.
387
- *
388
- * @param name The name of the property
389
- * @returns The modified schema
390
- */
391
- int8<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 8, number>>;
392
- /**
393
- * Adds a 8-bit unsigned integer property to the schema.
394
- *
395
- * @remarks
396
- *
397
- * The range of values is from 0 to 255, inclusive.
398
- *
399
- * @param name The name of the property
400
- * @returns The modified schema
401
- */
402
- uint8<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 8, number>>;
403
- /**
404
- * Adds a 16-bit integer property to the schema.
405
- *
406
- * @remarks
407
- *
408
- * The range of values is from -32768 to 32767, inclusive.
409
- *
410
- * @param name The name of the property
411
- * @returns The modified schema
412
- */
413
- int16<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 16, number>>;
414
- /**
415
- * Adds a 16-bit unsigned integer property to the schema.
416
- *
417
- * @remarks
418
- *
419
- * The range of values is from 0 to 65535, inclusive.
420
- *
421
- * @param name The name of the property
422
- * @returns The modified schema
423
- */
424
- uint16<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 16, number>>;
425
- /**
426
- * Adds a 32-bit integer property to the schema.
427
- *
428
- * @remarks
429
- *
430
- * The range of values is from -2_147_483_648 to 2_147_483_647, inclusive.
431
- *
432
- * @param name The name of the property
433
- * @returns The modified schema
434
- */
435
- int32<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 32, number>>;
436
- /**
437
- * Adds a 32-bit unsigned integer property to the schema.
438
- *
439
- * @remarks
440
- *
441
- * The range of values is from 0 to 4_294_967_295, inclusive.
442
- *
443
- * @param name The name of the property
444
- * @returns The modified schema
445
- */
446
- uint32<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 32, number>>;
447
- /**
448
- * Adds a 64-bit integer property to the schema.
449
- *
450
- * @remarks
451
- *
452
- * The range of values is from -9_223_372_036_854_775_808 to 9_223_372_036_854_775_807, inclusive.
453
- *
454
- * However, it may run into precision issues past the range of `-9_007_199_254_740_991` to `9_007_199_254_740_991`
455
- *
456
- * @param name The name of the property
457
- * @returns The modified schema
458
- */
459
- int64<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 64, number>>;
460
- /**
461
- * Adds a 64-bit unsigned integer property to the schema.
462
- *
463
- * @remarks
464
- *
465
- * The range of values is from 0 to 18_446_744_073_709_551_615, inclusive.
466
- *
467
- * However, it may run into precision issues past `9_007_199_254_740_991`
468
- *
469
- * @param name The name of the property
470
- * @returns The modified schema
471
- */
472
- uint64<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 64, number>>;
473
- /**
474
- * Adds a 32-bit big integer property to the schema.
475
- *
476
- * @remarks
477
- *
478
- * The range of values is from -2_147_483_648n to 2_147_483_647n, inclusive.
479
- *
480
- * @param name The name of the property
481
- * @returns The modified schema
482
- */
483
- bigInt32<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<bigint, 32, bigint>>;
484
- /**
485
- * Adds a 32-bit big integer property to the schema.
486
- *
487
- * @remarks
488
- *
489
- * The range of values is from 0n to 4_294_967_295n, inclusive.
490
- *
491
- * @param name The name of the property
492
- * @returns The modified schema
493
- */
494
- bigUint32<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<bigint, 32, bigint>>;
495
- /**
496
- * Adds a 64-bit big integer property to the schema.
497
- *
498
- * @remarks
499
- *
500
- * The range of values is from -9_223_372_036_854_775_808n to 9_223_372_036_854_775_807n, inclusive.
501
- *
502
- * @param name The name of the property
503
- * @returns The modified schema
504
- */
505
- bigInt64<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<bigint, 64, bigint>>;
506
- /**
507
- * Adds a 64-bit big integer property to the schema.
508
- *
509
- * @remarks
510
- *
511
- * The range of values is from 0n to 18_446_744_073_709_551_615n, inclusive.
512
- *
513
- * @param name The name of the property
514
- * @returns The modified schema
515
- */
516
- bigUint64<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<bigint, 64, bigint>>;
517
- /**
518
- * Adds a 32-bit floating point number property to the schema.
519
- *
520
- * @remarks
521
- *
522
- * The range of values is from -3.4028234663852886e+38 to 3.4028234663852886e+38, inclusive.
523
- *
524
- * @param name The name of the property
525
- * @returns The modified schema
526
- */
527
- float32<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 32, number>>;
528
- /**
529
- * Adds a 64-bit floating point number property to the schema.
530
- *
531
- * @remarks
532
- *
533
- * The range of values is from -1.7976931348623157e+308 to 1.7976931348623157e+308, inclusive.
534
- *
535
- * @param name The name of the property
536
- * @returns The modified schema
537
- */
538
- float64<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 64, number>>;
539
- /**
540
- * Adds a nullable property to the schema.
541
- *
542
- * @param name The name of the property
543
- * @param type The type of the underlying value
544
- * @returns The modified schema
545
- */
546
- nullable<const Name extends string, const ValueType, const ValueBitSize extends number | null>(name: Name, type: IType<ValueType, ValueBitSize>): Merge$1<Id, Entries, Name, IType<ValueType | null, null, ValueType | null | undefined>>;
547
- /**
548
- * Adds a 64-bit big integer property to the schema, similar to {@link Schema.bigUint64}.
549
- *
550
- * @remarks
551
- *
552
- * The range of values is from 0n to 18_446_744_073_709_551_615n, inclusive.
553
- *
554
- * @param name The name of the property
555
- * @returns The modified schema
556
- */
557
- snowflake<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<bigint, 64, string | bigint>>;
558
- /**
559
- * Adds a constant value in the schema, this will **not** be serialized and
560
- * can be used to add extra data without making the payload bigger.
561
- *
562
- * @param name The name of the property
563
- * @param constantValue The value to add to the schema
564
- * @returns The modified schema
565
- */
566
- constant<const Name extends string, const ValueType>(name: Name, constantValue: ValueType): Merge$1<Id, Entries, Name, IType<ValueType, 0, never>>;
567
- /**
568
- * Iterates over the schema's property names.
569
- *
570
- * @returns An iterator for the schema's property names
571
- */
572
- keys(): IterableIterator<KeyOfSchema<this>>;
573
- /**
574
- * Iterates over the schema's property values
575
- *
576
- * @returns An iterator for the schema's property values
577
- */
578
- values(): IterableIterator<ValueOfSchema<this>>;
579
- /**
580
- * Iterates over the schema's property entries
581
- *
582
- * @returns An iterator for the schema's property entries
583
- */
584
- entries(): IterableIterator<EntryOfSchema<this>>;
585
- /**
586
- * Iterates over the schema's property entries
587
- *
588
- * @returns An iterator for the schema's property entries
589
- */
590
- [Symbol.iterator](): IterableIterator<EntryOfSchema<this>>;
591
- }
592
- type Merge$1<Id extends number, Entries extends object, EntryName extends string, EntryType extends IType<any, number | null>> = EntryName extends keyof Entries ? never : Schema<Id, {
593
- [K in EntryName | keyof Entries]: K extends keyof Entries ? Entries[K] : EntryType;
594
- }>;
595
- type KeyOfSchema<SchemaValue extends object> = SchemaValue extends Schema<infer _, infer Type> ? keyof Type & string : never;
596
- type ValueOfSchema<SchemaValue extends object> = SchemaValue extends Schema<infer _, infer Type> ? {
597
- [K in keyof Type]: Type[K];
598
- }[keyof Type] : never;
599
- type EntryOfSchema<SchemaValue extends object> = SchemaValue extends Schema<infer _, infer Type> ? {
600
- [K in keyof Type]: readonly [K, Type[K]];
601
- }[keyof Type] : never;
602
- type UnwrapSchemaType<Type extends object> = Type extends IType<infer ValueType, infer _BitSize, infer _InputType> ? ValueType : never;
603
- type UnwrapSchemaEntries<Entries extends object> = {
604
- [K in keyof Entries]: UnwrapSchemaType<Entries[K] & object>;
605
- } & object;
606
- type UnwrapSchema<SchemaValue extends object> = SchemaValue extends Schema<infer _Id, infer Type> ? UnwrapSchemaEntries<Type> : never;
607
- type OmitNever<T> = {
608
- [K in keyof T as T[K] extends never ? never : K]: T[K];
609
- };
610
- type SerializeValueType<Type extends object> = Type extends IType<infer _ValueType, infer _BitSize, infer InputType> ? InputType : never;
611
- type SerializeValueEntries<Entries extends object> = OmitNever<{
612
- [K in keyof Entries]: SerializeValueType<Entries[K] & object>;
613
- }>;
614
- type SerializeValue<SchemaValue extends object> = SchemaValue extends Schema<infer _Id, infer Type> ? SerializeValueEntries<Type> : never;
615
-
616
- declare class SchemaStore<Entries extends object = object> {
617
- #private;
618
- /**
619
- * The default maximum array length for schemas
620
- */
621
- defaultMaximumArrayLength: number;
622
- /**
623
- * Creates a new schema store
624
- *
625
- * @param defaultMaximumArrayLength The default maximum array length for schemas
626
- */
627
- constructor(defaultMaximumArrayLength?: number);
628
- /**
629
- * Adds a schema to the store
630
- *
631
- * @param schema The schema to add to the store
632
- * @returns The modified store
633
- *
634
- * @remarks
635
- *
636
- * An error will be thrown if a schema with the same id already exists in the store.
637
- */
638
- add<const Id extends number, const SchemaType extends object>(schema: Schema<Id, SchemaType>): Merge<Entries, Id, typeof schema>;
639
- /**
640
- * Gets a schema from the store
641
- *
642
- * @param id The id of the schema to get
643
- * @returns The schema with the given id
644
- *
645
- * @remarks
646
- *
647
- * An error will be thrown if a schema with the given id does not exist in the store.
648
- */
649
- get<const Id extends KeyOfStore<this>>(id: Id): Entries[Id];
650
- /**
651
- * Serializes a value using the schema with the given id
652
- *
653
- * @param id The id of the schema to use for serialization
654
- * @param value The value to serialize
655
- * @returns The serialized string
656
- */
657
- serialize<const Id extends KeyOfStore<this>>(id: Id, value: SerializeValue<Entries[Id] & object>): string;
658
- /**
659
- * Serializes a value using the schema with the given id
660
- *
661
- * @param id The id of the schema to use for serialization
662
- * @param value The value to serialize
663
- * @returns The serialized buffer
664
- */
665
- serializeRaw<const Id extends KeyOfStore<this>>(id: Id, value: SerializeValue<Entries[Id] & object>): DuplexBuffer;
666
- /**
667
- * Deserializes a buffer
668
- *
669
- * @param buffer The buffer to deserialize
670
- * @returns The resolved value, including the id of the schema used for deserialization
671
- */
672
- deserialize(buffer: string | DuplexBuffer): DeserializationResult<Entries>;
673
- /**
674
- * Gets the serialized ID from a buffer
675
- *
676
- * @param buffer The buffer to read the ID from
677
- * @returns The deserialized ID
678
- *
679
- * @remarks
680
- *
681
- * If an empty value is passed, a {@linkcode RangeError} will be thrown.
682
- */
683
- getIdentifier(buffer: string | DuplexBuffer): KeyOfStore<this>;
684
- /**
685
- * Iterates over the stores's schema identifiers.
686
- *
687
- * @returns An iterator for the stores's schema identifiers
688
- */
689
- keys(): IterableIterator<KeyOfStore<this>>;
690
- /**
691
- * Iterates over the stores's schemas.
692
- *
693
- * @returns An iterator for the stores's schemas
694
- */
695
- values(): IterableIterator<ValueOfStore<this>>;
696
- /**
697
- * Iterates over the stores's schema entries.
698
- *
699
- * @returns An iterator for the stores's schema entries
700
- */
701
- entries(): IterableIterator<EntryOfStore<this>>;
702
- /**
703
- * Iterates over the stores's schema entries.
704
- *
705
- * @returns An iterator for the stores's schema entries
706
- */
707
- [Symbol.iterator](): IterableIterator<EntryOfStore<this>>;
708
- }
709
- type Merge<Entries extends object, Id extends number, Type extends object> = Id extends keyof Entries ? never : SchemaStore<{
710
- [K in Id | keyof Entries]: K extends keyof Entries ? Entries[K] : Type;
711
- }>;
712
- type KeyOfStore<SchemaStoreValue extends object> = SchemaStoreValue extends SchemaStore<infer Schemas> ? keyof Schemas & number : never;
713
- type ValueOfStore<SchemaStoreValue extends object> = SchemaStoreValue extends SchemaStore<infer Schemas> ? Schemas[keyof Schemas & number] : never;
714
- type EntryOfStore<SchemaStoreValue extends object> = SchemaStoreValue extends SchemaStore<infer Schemas> ? {
715
- [K in keyof Schemas]: readonly [K & number, Schemas[K]];
716
- }[keyof Schemas] : never;
717
- type DeserializationResult<SchemaStoreEntries extends object> = {
718
- [K in keyof SchemaStoreEntries]: {
719
- id: K;
720
- data: UnwrapSchema<SchemaStoreEntries[K] & object>;
721
- };
722
- }[keyof SchemaStoreEntries];
723
-
724
- declare const codepointRanges: {
725
- start: number;
726
- end: number;
727
- indexStart: number;
728
- indexEnd: number;
729
- }[];
730
-
731
- type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
732
- /**
733
- * Converts a {@link TypedArray} to a string.
734
- *
735
- * @param buffer The buffer to convert
736
- * @returns The generated UTF16 string
737
- */
738
- declare function toUTF16(buffer: TypedArray): string;
739
- /**
740
- * Converts a string to a {@link Uint16Array}.
741
- *
742
- * @param buffer The string to convert
743
- * @returns The generated {@link Uint16Array}
744
- */
745
- declare function fromUTF16(buffer: string): Uint16Array;
746
-
747
- export { ArrayType, BigInt32Type, BigInt64Type, BigUint32Type, BigUint64Type, BitType, BooleanType, ConstantType, type DeserializationResult, type DuplexBuffer, type EntryOfSchema, type EntryOfStore, FixedLengthArrayType, Float32Type, Float64Type, type IType, Int16Type, Int2Type, Int32Type, Int4Type, Int64Type, Int8Type, type KeyOfSchema, type KeyOfStore, NullableType, Pointer, type PointerLike, Schema, SchemaStore, type SerializeValue, type SerializeValueEntries, type SerializeValueType, SnowflakeType, StringType, type TypedArray, Uint16Type, Uint2Type, Uint32Type, Uint4Type, Uint64Type, Uint8Type, UnalignedUint16Array, type UnwrapSchema, type UnwrapSchemaEntries, type UnwrapSchemaType, type ValueOfSchema, type ValueOfStore, codepointRanges, fromUTF16, t, toUTF16 };