@sapphire/string-store 1.2.0-next.3b1a353c → 1.2.0-next.86690e35

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.
@@ -66,14 +66,14 @@ declare class UnalignedUint16Array {
66
66
  static from(value: string | UnalignedUint16Array): UnalignedUint16Array;
67
67
  }
68
68
 
69
- interface IType<ValueType, BitSize extends number | null> {
69
+ interface IType<ValueType, BitSize extends number | null, InputValue = ValueType> {
70
70
  /**
71
71
  * Serialize a value to a buffer.
72
72
  *
73
73
  * @param buffer The buffer to write to
74
74
  * @param value The value to write
75
75
  */
76
- serialize(buffer: UnalignedUint16Array, value: Readonly<ValueType>): void;
76
+ serialize(buffer: UnalignedUint16Array, value: InputValue): void;
77
77
  /**
78
78
  * Deserialize a value from a buffer.
79
79
  *
@@ -97,10 +97,12 @@ declare const BigUint32Type: IType<bigint, 32>;
97
97
 
98
98
  declare const BigUint64Type: IType<bigint, 64>;
99
99
 
100
- declare const BitType: IType<number, 1>;
100
+ declare const BitType: IType<0 | 1, 1, number>;
101
101
 
102
102
  declare const BooleanType: IType<boolean, 1>;
103
103
 
104
+ declare function ConstantType<const ValueType>(constantValue: ValueType): IType<ValueType, 0, never>;
105
+
104
106
  declare function FixedLengthArrayType<ValueType, ValueBitSize extends number | null>(type: IType<ValueType, ValueBitSize>, length: number): IType<ValueType[], ValueBitSize extends null ? null : number>;
105
107
 
106
108
  declare const Float32Type: IType<number, 32>;
@@ -121,11 +123,7 @@ declare const Int8Type: IType<number, 8>;
121
123
 
122
124
  declare function NullableType<ValueType, ValueBitSize extends number | null>(type: IType<ValueType, ValueBitSize>): IType<ValueType | null | undefined, null>;
123
125
 
124
- declare const SnowflakeType: {
125
- readonly serialize: (buffer: UnalignedUint16Array, value: bigint | string) => void;
126
- readonly deserialize: (buffer: UnalignedUint16Array, offset: Pointer) => bigint;
127
- readonly BIT_SIZE: 64;
128
- };
126
+ declare const SnowflakeType: IType<bigint, 64, bigint | string>;
129
127
 
130
128
  declare const StringType: IType<string, null>;
131
129
 
@@ -143,34 +141,31 @@ declare const Uint8Type: IType<number, 8>;
143
141
 
144
142
  declare const t: {
145
143
  array: typeof ArrayType;
146
- bigInt32: IType<bigint, 32>;
147
- bigInt64: IType<bigint, 64>;
148
- bigUint32: IType<bigint, 32>;
149
- bigUint64: IType<bigint, 64>;
150
- bit: IType<number, 1>;
151
- boolean: IType<boolean, 1>;
144
+ bigInt32: IType<bigint, 32, bigint>;
145
+ bigInt64: IType<bigint, 64, bigint>;
146
+ bigUint32: IType<bigint, 32, bigint>;
147
+ bigUint64: IType<bigint, 64, bigint>;
148
+ bit: IType<0 | 1, 1, number>;
149
+ boolean: IType<boolean, 1, boolean>;
150
+ constant: typeof ConstantType;
152
151
  fixedLengthArray: typeof FixedLengthArrayType;
153
- float32: IType<number, 32>;
154
- float64: IType<number, 64>;
155
- int16: IType<number, 16>;
156
- int2: IType<number, 2>;
157
- int32: IType<number, 32>;
158
- int4: IType<number, 4>;
159
- int64: IType<number, 64>;
160
- int8: IType<number, 8>;
152
+ float32: IType<number, 32, number>;
153
+ float64: IType<number, 64, number>;
154
+ int16: IType<number, 16, number>;
155
+ int2: IType<number, 2, number>;
156
+ int32: IType<number, 32, number>;
157
+ int4: IType<number, 4, number>;
158
+ int64: IType<number, 64, number>;
159
+ int8: IType<number, 8, number>;
161
160
  nullable: typeof NullableType;
162
- snowflake: {
163
- readonly serialize: (buffer: UnalignedUint16Array, value: string | bigint) => void;
164
- readonly deserialize: (buffer: UnalignedUint16Array, offset: Pointer) => bigint;
165
- readonly BIT_SIZE: 64;
166
- };
167
- string: IType<string, null>;
168
- uint16: IType<number, 16>;
169
- uint2: IType<number, 2>;
170
- uint32: IType<number, 32>;
171
- uint4: IType<number, 4>;
172
- uint64: IType<number, 64>;
173
- uint8: IType<number, 8>;
161
+ snowflake: IType<bigint, 64, string | bigint>;
162
+ string: IType<string, null, string>;
163
+ uint16: IType<number, 16, number>;
164
+ uint2: IType<number, 2, number>;
165
+ uint32: IType<number, 32, number>;
166
+ uint4: IType<number, 4, number>;
167
+ uint64: IType<number, 64, number>;
168
+ uint8: IType<number, 8, number>;
174
169
  };
175
170
 
176
171
  declare class Schema<Id extends number = number, Entries extends object = object> {
@@ -186,7 +181,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
186
181
  */
187
182
  get id(): Id;
188
183
  /**
189
- * The total bit size of the schema.
184
+ * The bit size of the entries in the schema.
190
185
  *
191
186
  * @remarks
192
187
  *
@@ -194,6 +189,15 @@ declare class Schema<Id extends number = number, Entries extends object = object
194
189
  * schema will also be `null`.
195
190
  */
196
191
  get bitSize(): number | null;
192
+ /**
193
+ * The total bit size of the entries in the schema and the ID.
194
+ *
195
+ * @remarks
196
+ *
197
+ * If any of the entries have a bit size of `null`, the total bit size of
198
+ * the schema will also be `null`.
199
+ */
200
+ get totalBitSize(): number | null;
197
201
  /**
198
202
  * Get a property from the schema.
199
203
  *
@@ -216,7 +220,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
216
220
  * The schema's ID is written to the buffer first, followed by each property
217
221
  * in the schema.
218
222
  */
219
- serialize(buffer: UnalignedUint16Array, value: Readonly<UnwrapSchemaEntries<Entries>>): void;
223
+ serialize(buffer: UnalignedUint16Array, value: Readonly<SerializeValueEntries<Entries>>): void;
220
224
  /**
221
225
  * Deserialize a value from a buffer.
222
226
  *
@@ -239,7 +243,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
239
243
  * @param type The type of the entry in the array
240
244
  * @returns The modified schema
241
245
  */
242
- 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>>;
246
+ 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[]>>;
243
247
  /**
244
248
  * Adds a fixed length array property to the schema.
245
249
  *
@@ -250,28 +254,28 @@ declare class Schema<Id extends number = number, Entries extends object = object
250
254
  * @param length The length of the array
251
255
  * @returns The modified schema
252
256
  */
253
- 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>>;
257
+ 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[]>>;
254
258
  /**
255
259
  * Adds a string property to the schema.
256
260
  *
257
261
  * @param name The name of the property
258
262
  * @returns The modified schema
259
263
  */
260
- string<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<string, null>>;
264
+ string<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<string, null, string>>;
261
265
  /**
262
266
  * Adds a boolean property to the schema.
263
267
  *
264
268
  * @param name The name of the property
265
269
  * @returns The modified schema
266
270
  */
267
- boolean<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<boolean, 1>>;
271
+ boolean<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<boolean, 1, boolean>>;
268
272
  /**
269
273
  * Adds a bit property to the schema.
270
274
  *
271
275
  * @param name The name of the property
272
276
  * @returns The modified schema
273
277
  */
274
- bit<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 1>>;
278
+ bit<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<0 | 1, 1, number>>;
275
279
  /**
276
280
  * Adds a 2-bit integer property to the schema.
277
281
  *
@@ -282,7 +286,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
282
286
  * @param name The name of the property
283
287
  * @returns The modified schema
284
288
  */
285
- int2<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 2>>;
289
+ int2<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 2, number>>;
286
290
  /**
287
291
  * Adds a 2-bit unsigned integer property to the schema.
288
292
  *
@@ -293,7 +297,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
293
297
  * @param name The name of the property
294
298
  * @returns The modified schema
295
299
  */
296
- uint2<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 2>>;
300
+ uint2<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 2, number>>;
297
301
  /**
298
302
  * Adds a 4-bit integer property to the schema.
299
303
  *
@@ -304,7 +308,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
304
308
  * @param name The name of the property
305
309
  * @returns The modified schema
306
310
  */
307
- int4<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 4>>;
311
+ int4<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 4, number>>;
308
312
  /**
309
313
  * Adds a 4-bit unsigned integer property to the schema.
310
314
  *
@@ -315,7 +319,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
315
319
  * @param name The name of the property
316
320
  * @returns The modified schema
317
321
  */
318
- uint4<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 4>>;
322
+ uint4<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 4, number>>;
319
323
  /**
320
324
  * Adds a 8-bit integer property to the schema.
321
325
  *
@@ -326,7 +330,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
326
330
  * @param name The name of the property
327
331
  * @returns The modified schema
328
332
  */
329
- int8<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 8>>;
333
+ int8<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 8, number>>;
330
334
  /**
331
335
  * Adds a 8-bit unsigned integer property to the schema.
332
336
  *
@@ -337,7 +341,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
337
341
  * @param name The name of the property
338
342
  * @returns The modified schema
339
343
  */
340
- uint8<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 8>>;
344
+ uint8<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 8, number>>;
341
345
  /**
342
346
  * Adds a 16-bit integer property to the schema.
343
347
  *
@@ -348,7 +352,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
348
352
  * @param name The name of the property
349
353
  * @returns The modified schema
350
354
  */
351
- int16<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 16>>;
355
+ int16<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 16, number>>;
352
356
  /**
353
357
  * Adds a 16-bit unsigned integer property to the schema.
354
358
  *
@@ -359,7 +363,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
359
363
  * @param name The name of the property
360
364
  * @returns The modified schema
361
365
  */
362
- uint16<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 16>>;
366
+ uint16<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 16, number>>;
363
367
  /**
364
368
  * Adds a 32-bit integer property to the schema.
365
369
  *
@@ -370,7 +374,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
370
374
  * @param name The name of the property
371
375
  * @returns The modified schema
372
376
  */
373
- int32<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 32>>;
377
+ int32<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 32, number>>;
374
378
  /**
375
379
  * Adds a 32-bit unsigned integer property to the schema.
376
380
  *
@@ -381,7 +385,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
381
385
  * @param name The name of the property
382
386
  * @returns The modified schema
383
387
  */
384
- uint32<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 32>>;
388
+ uint32<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 32, number>>;
385
389
  /**
386
390
  * Adds a 64-bit integer property to the schema.
387
391
  *
@@ -394,7 +398,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
394
398
  * @param name The name of the property
395
399
  * @returns The modified schema
396
400
  */
397
- int64<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 64>>;
401
+ int64<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 64, number>>;
398
402
  /**
399
403
  * Adds a 64-bit unsigned integer property to the schema.
400
404
  *
@@ -407,7 +411,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
407
411
  * @param name The name of the property
408
412
  * @returns The modified schema
409
413
  */
410
- uint64<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 64>>;
414
+ uint64<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 64, number>>;
411
415
  /**
412
416
  * Adds a 32-bit big integer property to the schema.
413
417
  *
@@ -418,7 +422,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
418
422
  * @param name The name of the property
419
423
  * @returns The modified schema
420
424
  */
421
- bigInt32<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<bigint, 32>>;
425
+ bigInt32<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<bigint, 32, bigint>>;
422
426
  /**
423
427
  * Adds a 32-bit big integer property to the schema.
424
428
  *
@@ -429,7 +433,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
429
433
  * @param name The name of the property
430
434
  * @returns The modified schema
431
435
  */
432
- bigUint32<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<bigint, 32>>;
436
+ bigUint32<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<bigint, 32, bigint>>;
433
437
  /**
434
438
  * Adds a 64-bit big integer property to the schema.
435
439
  *
@@ -440,7 +444,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
440
444
  * @param name The name of the property
441
445
  * @returns The modified schema
442
446
  */
443
- bigInt64<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<bigint, 64>>;
447
+ bigInt64<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<bigint, 64, bigint>>;
444
448
  /**
445
449
  * Adds a 64-bit big integer property to the schema.
446
450
  *
@@ -451,7 +455,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
451
455
  * @param name The name of the property
452
456
  * @returns The modified schema
453
457
  */
454
- bigUint64<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<bigint, 64>>;
458
+ bigUint64<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<bigint, 64, bigint>>;
455
459
  /**
456
460
  * Adds a 32-bit floating point number property to the schema.
457
461
  *
@@ -462,7 +466,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
462
466
  * @param name The name of the property
463
467
  * @returns The modified schema
464
468
  */
465
- float32<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 32>>;
469
+ float32<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 32, number>>;
466
470
  /**
467
471
  * Adds a 64-bit floating point number property to the schema.
468
472
  *
@@ -473,7 +477,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
473
477
  * @param name The name of the property
474
478
  * @returns The modified schema
475
479
  */
476
- float64<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 64>>;
480
+ float64<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<number, 64, number>>;
477
481
  /**
478
482
  * Adds a nullable property to the schema.
479
483
  *
@@ -481,7 +485,7 @@ declare class Schema<Id extends number = number, Entries extends object = object
481
485
  * @param type The type of the underlying value
482
486
  * @returns The modified schema
483
487
  */
484
- 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 | undefined, null>>;
488
+ 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 | undefined, null, ValueType | null | undefined>>;
485
489
  /**
486
490
  * Adds a 64-bit big integer property to the schema, similar to {@link Schema.bigUint64}.
487
491
  *
@@ -492,7 +496,16 @@ declare class Schema<Id extends number = number, Entries extends object = object
492
496
  * @param name The name of the property
493
497
  * @returns The modified schema
494
498
  */
495
- snowflake<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<bigint, 64>>;
499
+ snowflake<const Name extends string>(name: Name): Merge$1<Id, Entries, Name, IType<bigint, 64, string | bigint>>;
500
+ /**
501
+ * Adds a constant value in the schema, this will **not** be serialized and
502
+ * can be used to add extra data without making the payload bigger.
503
+ *
504
+ * @param name The name of the property
505
+ * @param constantValue The value to add to the schema
506
+ * @returns The modified schema
507
+ */
508
+ constant<const Name extends string, const ValueType>(name: Name, constantValue: ValueType): Merge$1<Id, Entries, Name, IType<ValueType, 0, never>>;
496
509
  /**
497
510
  * Iterates over the schema's property names.
498
511
  *
@@ -528,11 +541,19 @@ type ValueOfSchema<SchemaValue extends object> = SchemaValue extends Schema<infe
528
541
  type EntryOfSchema<SchemaValue extends object> = SchemaValue extends Schema<infer _, infer Type> ? {
529
542
  [K in keyof Type]: readonly [K, Type[K]];
530
543
  }[keyof Type] : never;
531
- type UnwrapSchemaType<Type extends object> = Type extends IType<infer T, infer _> ? T : never;
544
+ type UnwrapSchemaType<Type extends object> = Type extends IType<infer ValueType, infer _BitSize, infer _InputType> ? ValueType : never;
532
545
  type UnwrapSchemaEntries<Entries extends object> = {
533
546
  [K in keyof Entries]: UnwrapSchemaType<Entries[K] & object>;
534
547
  } & object;
535
- type UnwrapSchema<SchemaValue extends object> = SchemaValue extends Schema<infer _, infer Type> ? UnwrapSchemaEntries<Type> : never;
548
+ type UnwrapSchema<SchemaValue extends object> = SchemaValue extends Schema<infer _Id, infer Type> ? UnwrapSchemaEntries<Type> : never;
549
+ type OmitNever<T> = {
550
+ [K in keyof T as T[K] extends never ? never : K]: T[K];
551
+ };
552
+ type SerializeValueType<Type extends object> = Type extends IType<infer _ValueType, infer _BitSize, infer InputType> ? InputType : never;
553
+ type SerializeValueEntries<Entries extends object> = OmitNever<{
554
+ [K in keyof Entries]: SerializeValueType<Entries[K] & object>;
555
+ }>;
556
+ type SerializeValue<SchemaValue extends object> = SchemaValue extends Schema<infer _Id, infer Type> ? SerializeValueEntries<Type> : never;
536
557
 
537
558
  declare class SchemaStore<Entries extends object = object> {
538
559
  #private;
@@ -575,7 +596,7 @@ declare class SchemaStore<Entries extends object = object> {
575
596
  * @param value The value to serialize
576
597
  * @returns The serialized buffer
577
598
  */
578
- serialize<const Id extends KeyOfStore<this>>(id: Id, value: Readonly<UnwrapSchema<Entries[Id] & object>>): UnalignedUint16Array;
599
+ serialize<const Id extends KeyOfStore<this>>(id: Id, value: SerializeValue<Entries[Id] & object>): UnalignedUint16Array;
579
600
  /**
580
601
  * Deserializes a buffer
581
602
  *
@@ -650,4 +671,4 @@ declare function toUTF16(buffer: TypedArray): string;
650
671
  */
651
672
  declare function fromUTF16(buffer: string): Uint16Array;
652
673
 
653
- export { ArrayType, BigInt32Type, BigInt64Type, BigUint32Type, BigUint64Type, BitType, BooleanType, 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, SnowflakeType, StringType, type TypedArray, Uint16Type, Uint2Type, Uint32Type, Uint4Type, Uint64Type, Uint8Type, UnalignedUint16Array, type UnwrapSchema, type UnwrapSchemaEntries, type UnwrapSchemaType, type ValueOfSchema, type ValueOfStore, fromUTF16, t, toUTF16 };
674
+ 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 };
@@ -162,6 +162,19 @@ var BooleanType = {
162
162
  BIT_SIZE: 1
163
163
  };
164
164
 
165
+ // src/lib/types/Constant.ts
166
+ function ConstantType(constantValue) {
167
+ return {
168
+ serialize(_buffer2, _value2) {
169
+ },
170
+ deserialize(_buffer2, _pointer) {
171
+ return constantValue;
172
+ },
173
+ BIT_SIZE: 0
174
+ };
175
+ }
176
+ __name(ConstantType, "ConstantType");
177
+
165
178
  // src/lib/types/FixedLengthArray.ts
166
179
  function FixedLengthArrayType(type, length) {
167
180
  return {
@@ -400,6 +413,7 @@ var t = {
400
413
  bigUint64: BigUint64Type,
401
414
  bit: BitType,
402
415
  boolean: BooleanType,
416
+ constant: ConstantType,
403
417
  fixedLengthArray: FixedLengthArrayType,
404
418
  float32: Float32Type,
405
419
  float64: Float64Type,
@@ -442,7 +456,7 @@ var _Schema = class _Schema {
442
456
  return __privateGet(this, _id);
443
457
  }
444
458
  /**
445
- * The total bit size of the schema.
459
+ * The bit size of the entries in the schema.
446
460
  *
447
461
  * @remarks
448
462
  *
@@ -452,6 +466,17 @@ var _Schema = class _Schema {
452
466
  get bitSize() {
453
467
  return __privateGet(this, _bitSize);
454
468
  }
469
+ /**
470
+ * The total bit size of the entries in the schema and the ID.
471
+ *
472
+ * @remarks
473
+ *
474
+ * If any of the entries have a bit size of `null`, the total bit size of
475
+ * the schema will also be `null`.
476
+ */
477
+ get totalBitSize() {
478
+ return __privateGet(this, _bitSize) === null ? null : __privateGet(this, _bitSize) + 16;
479
+ }
455
480
  /**
456
481
  * Get a property from the schema.
457
482
  *
@@ -817,6 +842,17 @@ var _Schema = class _Schema {
817
842
  snowflake(name) {
818
843
  return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.snowflake);
819
844
  }
845
+ /**
846
+ * Adds a constant value in the schema, this will **not** be serialized and
847
+ * can be used to add extra data without making the payload bigger.
848
+ *
849
+ * @param name The name of the property
850
+ * @param constantValue The value to add to the schema
851
+ * @returns The modified schema
852
+ */
853
+ constant(name, constantValue) {
854
+ return __privateMethod(this, _Schema_instances, addType_fn).call(this, name, t.constant(constantValue));
855
+ }
820
856
  /**
821
857
  * Iterates over the schema's property names.
822
858
  *
@@ -1167,7 +1203,7 @@ var _SchemaStore = class _SchemaStore {
1167
1203
  */
1168
1204
  serialize(id, value) {
1169
1205
  const schema = this.get(id);
1170
- const buffer = new UnalignedUint16Array(schema.bitSize ?? this.defaultMaximumArrayLength);
1206
+ const buffer = new UnalignedUint16Array(schema.totalBitSize ?? this.defaultMaximumArrayLength);
1171
1207
  schema.serialize(buffer, value);
1172
1208
  return buffer;
1173
1209
  }
@@ -1258,6 +1294,6 @@ function fromUTF16(buffer) {
1258
1294
  }
1259
1295
  __name(fromUTF16, "fromUTF16");
1260
1296
 
1261
- export { ArrayType, BigInt32Type, BigInt64Type, BigUint32Type, BigUint64Type, BitType, BooleanType, FixedLengthArrayType, Float32Type, Float64Type, Int16Type, Int2Type, Int32Type, Int4Type, Int64Type, Int8Type, NullableType, Pointer, Schema, SchemaStore, SnowflakeType, StringType, Uint16Type, Uint2Type, Uint32Type, Uint4Type, Uint64Type, Uint8Type, UnalignedUint16Array, fromUTF16, t, toUTF16 };
1297
+ export { ArrayType, BigInt32Type, BigInt64Type, BigUint32Type, BigUint64Type, BitType, BooleanType, ConstantType, FixedLengthArrayType, Float32Type, Float64Type, Int16Type, Int2Type, Int32Type, Int4Type, Int64Type, Int8Type, NullableType, Pointer, Schema, SchemaStore, SnowflakeType, StringType, Uint16Type, Uint2Type, Uint32Type, Uint4Type, Uint64Type, Uint8Type, UnalignedUint16Array, fromUTF16, t, toUTF16 };
1262
1298
  //# sourceMappingURL=index.mjs.map
1263
1299
  //# sourceMappingURL=index.mjs.map