@sapphire/string-store 2.0.0-next.598c24a3 → 2.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.
@@ -23,7 +23,47 @@ type PointerLike = Pointer | {
23
23
  [Symbol.toPrimitive](hint: 'number'): number;
24
24
  };
25
25
 
26
- declare class UnalignedUint16Array {
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 {
27
67
  #private;
28
68
  constructor(maxLength: number);
29
69
  at(index: number): number | undefined;
@@ -63,7 +103,7 @@ declare class UnalignedUint16Array {
63
103
  readFloat64(offset: PointerLike): number;
64
104
  toString(): string;
65
105
  toArray(): Uint16Array;
66
- static from(value: string | UnalignedUint16Array): UnalignedUint16Array;
106
+ static from(value: string | DuplexBuffer): DuplexBuffer;
67
107
  }
68
108
 
69
109
  interface IType<ValueType, BitSize extends number | null, InputValue = ValueType> {
@@ -73,14 +113,14 @@ interface IType<ValueType, BitSize extends number | null, InputValue = ValueType
73
113
  * @param buffer The buffer to write to
74
114
  * @param value The value to write
75
115
  */
76
- serialize(buffer: UnalignedUint16Array, value: InputValue): void;
116
+ serialize(buffer: DuplexBuffer, value: InputValue): void;
77
117
  /**
78
118
  * Deserialize a value from a buffer.
79
119
  *
80
120
  * @param buffer The buffer to read from
81
121
  * @param pointer The pointer indicating the current position in the buffer
82
122
  */
83
- deserialize(buffer: UnalignedUint16Array, pointer: Pointer): ValueType;
123
+ deserialize(buffer: DuplexBuffer, pointer: Pointer): ValueType;
84
124
  /**
85
125
  * The size of the value in bits, or `null` if the size is variable.
86
126
  */
@@ -209,6 +249,24 @@ declare class Schema<Id extends number = number, Entries extends object = object
209
249
  * If the property does not exist, an error will be thrown.
210
250
  */
211
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;
212
270
  /**
213
271
  * Serialize a value into a buffer.
214
272
  *
@@ -220,7 +278,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
220
278
  * The schema's ID is written to the buffer first, followed by each property
221
279
  * in the schema.
222
280
  */
223
- serialize(buffer: UnalignedUint16Array, value: Readonly<SerializeValueEntries<Entries>>): void;
281
+ serializeInto(buffer: DuplexBuffer, value: Readonly<SerializeValueEntries<Entries>>): void;
224
282
  /**
225
283
  * Deserialize a value from a buffer.
226
284
  *
@@ -230,10 +288,10 @@ declare class Schema<Id extends number = number, Entries extends object = object
230
288
  *
231
289
  * @remarks
232
290
  *
233
- * Unlike {@link Schema.serialize}, this method does not read the schema's ID
291
+ * Unlike {@link Schema.serializeInto}, this method does not read the schema's ID
234
292
  * from the buffer, that is reserved for the {@link SchemaStore}.
235
293
  */
236
- deserialize(buffer: UnalignedUint16Array, pointer: PointerLike): UnwrapSchemaEntries<Entries>;
294
+ deserialize(buffer: DuplexBuffer | string, pointer: PointerLike): UnwrapSchemaEntries<Entries>;
237
295
  /**
238
296
  * Adds an array property to the schema.
239
297
  *
@@ -604,14 +662,14 @@ declare class SchemaStore<Entries extends object = object> {
604
662
  * @param value The value to serialize
605
663
  * @returns The serialized buffer
606
664
  */
607
- serializeRaw<const Id extends KeyOfStore<this>>(id: Id, value: SerializeValue<Entries[Id] & object>): UnalignedUint16Array;
665
+ serializeRaw<const Id extends KeyOfStore<this>>(id: Id, value: SerializeValue<Entries[Id] & object>): DuplexBuffer;
608
666
  /**
609
667
  * Deserializes a buffer
610
668
  *
611
669
  * @param buffer The buffer to deserialize
612
670
  * @returns The resolved value, including the id of the schema used for deserialization
613
671
  */
614
- deserialize(buffer: string | UnalignedUint16Array): DeserializationResult<Entries>;
672
+ deserialize(buffer: string | DuplexBuffer): DeserializationResult<Entries>;
615
673
  /**
616
674
  * Gets the serialized ID from a buffer
617
675
  *
@@ -622,7 +680,7 @@ declare class SchemaStore<Entries extends object = object> {
622
680
  *
623
681
  * If an empty value is passed, a {@linkcode RangeError} will be thrown.
624
682
  */
625
- getIdentifier(buffer: string | UnalignedUint16Array): KeyOfStore<this>;
683
+ getIdentifier(buffer: string | DuplexBuffer): KeyOfStore<this>;
626
684
  /**
627
685
  * Iterates over the stores's schema identifiers.
628
686
  *
@@ -679,4 +737,4 @@ declare function toUTF16(buffer: TypedArray): string;
679
737
  */
680
738
  declare function fromUTF16(buffer: string): Uint16Array;
681
739
 
682
- export { ArrayType, BigInt32Type, BigInt64Type, BigUint32Type, BigUint64Type, BitType, BooleanType, ConstantType, type DeserializationResult, 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, fromUTF16, t, toUTF16 };
740
+ 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, fromUTF16, t, toUTF16 };