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