Class: Schema<Id, Entries>
Defined in: schema/Schema.ts:6
Type Parameters
| Type Parameter | Default type |
|---|---|
Id extends number | number |
Entries extends object | object |
Constructors
Constructor
new Schema<
Id,Entries>(id:Id):Schema<Id,Entries>
Defined in: schema/Schema.ts:16
Creates a new schema.
Parameters
| Parameter | Type | Description |
|---|---|---|
id | Id | The id of the schema |
Returns
Schema<Id, Entries>
Properties
#bitSize
private#bitSize:null|number=0
Defined in: schema/Schema.ts:9
#id
privatereadonly#id:Id
Defined in: schema/Schema.ts:7
#types
privatereadonly#types:Map<string,IType<any,null|number,any>>
Defined in: schema/Schema.ts:8
Accessors
bitSize
Get Signature
get bitSize():
null|number
Defined in: schema/Schema.ts:35
The bit size of the entries in the schema.
Remarks
If any of the entries have a bit size of null, the bit size of the
schema will also be null.
Returns
null | number
id
Get Signature
get id():
Id
Defined in: schema/Schema.ts:23
The id of the schema.
Returns
Id
totalBitSize
Get Signature
get totalBitSize():
null|number
Defined in: schema/Schema.ts:47
The total bit size of the entries in the schema and the ID.
Remarks
If any of the entries have a bit size of null, the total bit size of
the schema will also be null.
Returns
null | number
Methods
[iterator]()
[iterator]():
IterableIterator<{ [K in string | number | symbol]: readonly [K, Entries[K]] }[keyofEntries]>
Defined in: schema/Schema.ts:526
Iterates over the schema's property entries
Returns
IterableIterator<{ [K in string | number | symbol]: readonly [K, Entries[K]] }[keyof Entries]>
An iterator for the schema's property entries
#addType()
private#addType<EntryName,ValueType,ValueBitSize,InputValue>(name:EntryName,type:IType<ValueType,ValueBitSize,InputValue>):Merge<Id,Entries,EntryName,IType<ValueType,ValueBitSize,InputValue>>
Defined in: schema/Schema.ts:530
Type Parameters
| Type Parameter |
|---|
EntryName extends string |
ValueType |
ValueBitSize extends null | number |
InputValue |
Parameters
| Parameter | Type |
|---|---|
name | EntryName |
type | IType<ValueType, ValueBitSize, InputValue> |
Returns
Merge<Id, Entries, EntryName, IType<ValueType, ValueBitSize, InputValue>>
array()
array<
Name,ValueType,ValueBitSize>(name:Name,type:IType<ValueType,ValueBitSize>):Merge<Id,Entries,Name,IType<ValueType[],null,ValueType[]>>
Defined in: schema/Schema.ts:143
Adds an array property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
ValueType |
ValueBitSize extends null | number |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
type | IType<ValueType, ValueBitSize> | The type of the entry in the array |
Returns
Merge<Id, Entries, Name, IType<ValueType[], null, ValueType[]>>
The modified schema
Seealso
Schema.fixedLengthArray for a fixed length array
bigInt32()
bigInt32<
Name>(name:Name):Merge<Id,Entries,Name,IType<bigint,32,bigint>>
Defined in: schema/Schema.ts:380
Adds a 32-bit big integer property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<bigint, 32, bigint>>
The modified schema
Remarks
The range of values is from -2_147_483_648n to 2_147_483_647n, inclusive.
bigInt64()
bigInt64<
Name>(name:Name):Merge<Id,Entries,Name,IType<bigint,64,bigint>>
Defined in: schema/Schema.ts:408
Adds a 64-bit big integer property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<bigint, 64, bigint>>
The modified schema
Remarks
The range of values is from -9_223_372_036_854_775_808n to 9_223_372_036_854_775_807n, inclusive.
bigUint32()
bigUint32<
Name>(name:Name):Merge<Id,Entries,Name,IType<bigint,32,bigint>>
Defined in: schema/Schema.ts:394
Adds a 32-bit big integer property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<bigint, 32, bigint>>
The modified schema
Remarks
The range of values is from 0n to 4_294_967_295n, inclusive.
bigUint64()
bigUint64<
Name>(name:Name):Merge<Id,Entries,Name,IType<bigint,64,bigint>>
Defined in: schema/Schema.ts:422
Adds a 64-bit big integer property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<bigint, 64, bigint>>
The modified schema
Remarks
The range of values is from 0n to 18_446_744_073_709_551_615n, inclusive.
bit()
bit<
Name>(name:Name):Merge<Id,Entries,Name,IType<0|1,1,number>>
Defined in: schema/Schema.ts:194
Adds a bit property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<0 | 1, 1, number>>
The modified schema
boolean()
boolean<
Name>(name:Name):Merge<Id,Entries,Name,IType<boolean,1,boolean>>
Defined in: schema/Schema.ts:184
Adds a boolean property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<boolean, 1, boolean>>
The modified schema
constant()
constant<
Name,ValueType>(name:Name,constantValue:ValueType):Merge<Id,Entries,Name,IType<ValueType,0,never>>
Defined in: schema/Schema.ts:490
Adds a constant value in the schema, this will not be serialized and can be used to add extra data without making the payload bigger.
Type Parameters
| Type Parameter |
|---|
Name extends string |
ValueType |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
constantValue | ValueType | The value to add to the schema |
Returns
Merge<Id, Entries, Name, IType<ValueType, 0, never>>
The modified schema
deserialize()
deserialize(
buffer:string|DuplexBuffer,pointer:PointerLike):UnwrapSchemaEntries<Entries>
Defined in: schema/Schema.ts:123
Deserialize a value from a buffer.
Parameters
| Parameter | Type | Description |
|---|---|---|
buffer | string | DuplexBuffer | The buffer to deserialize |
pointer | PointerLike | The pointer to where the buffer should be read from |
Returns
UnwrapSchemaEntries<Entries>
The deserialized value
Remarks
Unlike Schema.serializeInto, this method does not read the schema's ID from the buffer, that is reserved for the SchemaStore.
entries()
entries():
IterableIterator<{ [K in string | number | symbol]: readonly [K, Entries[K]] }[keyofEntries]>
Defined in: schema/Schema.ts:517
Iterates over the schema's property entries
Returns
IterableIterator<{ [K in string | number | symbol]: readonly [K, Entries[K]] }[keyof Entries]>
An iterator for the schema's property entries
fixedLengthArray()
fixedLengthArray<
Name,ValueType,ValueBitSize>(name:Name,type:IType<ValueType,ValueBitSize>,length:number):Merge<Id,Entries,Name,IType<ValueType[],ValueBitSizeextendsnull?null:number,ValueType[]>>
Defined in: schema/Schema.ts:160
Adds a fixed length array property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
ValueType |
ValueBitSize extends null | number |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
type | IType<ValueType, ValueBitSize> | The type of the entry in the array |
length | number | The length of the array |
Returns
Merge<Id, Entries, Name, IType<ValueType[], ValueBitSize extends null ? null : number, ValueType[]>>
The modified schema
Seealso
Schema.array for a dynamic length array
float32()
float32<
Name>(name:Name):Merge<Id,Entries,Name,IType<number,32,number>>
Defined in: schema/Schema.ts:436
Adds a 32-bit floating point number property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<number, 32, number>>
The modified schema
Remarks
The range of values is from -3.4028234663852886e+38 to 3.4028234663852886e+38, inclusive.
float64()
float64<
Name>(name:Name):Merge<Id,Entries,Name,IType<number,64,number>>
Defined in: schema/Schema.ts:450
Adds a 64-bit floating point number property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<number, 64, number>>
The modified schema
Remarks
The range of values is from -1.7976931348623157e+308 to 1.7976931348623157e+308, inclusive.
get()
get<
Name>(name:Name):Entries[Name]
Defined in: schema/Schema.ts:61
Get a property from the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Entries[Name]
The specified property
Remarks
If the property does not exist, an error will be thrown.
int16()
int16<
Name>(name:Name):Merge<Id,Entries,Name,IType<number,16,number>>
Defined in: schema/Schema.ts:292
Adds a 16-bit integer property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<number, 16, number>>
The modified schema
Remarks
The range of values is from -32768 to 32767, inclusive.
int2()
int2<
Name>(name:Name):Merge<Id,Entries,Name,IType<number,2,number>>
Defined in: schema/Schema.ts:208
Adds a 2-bit integer property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<number, 2, number>>
The modified schema
Remarks
The range of values is from -2 to 1, inclusive.
int32()
int32<
Name>(name:Name):Merge<Id,Entries,Name,IType<number,32,number>>
Defined in: schema/Schema.ts:320
Adds a 32-bit integer property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<number, 32, number>>
The modified schema
Remarks
The range of values is from -2_147_483_648 to 2_147_483_647, inclusive.
int4()
int4<
Name>(name:Name):Merge<Id,Entries,Name,IType<number,4,number>>
Defined in: schema/Schema.ts:236
Adds a 4-bit integer property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<number, 4, number>>
The modified schema
Remarks
The range of values is from -8 to 7, inclusive.
int64()
int64<
Name>(name:Name):Merge<Id,Entries,Name,IType<number,64,number>>
Defined in: schema/Schema.ts:350
Adds a 64-bit integer property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<number, 64, number>>
The modified schema
Remarks
The range of values is from -9_223_372_036_854_775_808 to 9_223_372_036_854_775_807, inclusive.
However, it may run into precision issues past the range of -9_007_199_254_740_991 to 9_007_199_254_740_991
int8()
int8<
Name>(name:Name):Merge<Id,Entries,Name,IType<number,8,number>>
Defined in: schema/Schema.ts:264
Adds a 8-bit integer property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<number, 8, number>>
The modified schema
Remarks
The range of values is from -128 to 127, inclusive.
keys()
keys():
IterableIterator<keyofEntries&string>
Defined in: schema/Schema.ts:499
Iterates over the schema's property names.
Returns
IterableIterator<keyof Entries & string>
An iterator for the schema's property names
nullable()
nullable<
Name,ValueType,ValueBitSize>(name:Name,type:IType<ValueType,ValueBitSize>):Merge<Id,Entries,Name,IType<null|ValueType,null,undefined|null|ValueType>>
Defined in: schema/Schema.ts:461
Adds a nullable property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
ValueType |
ValueBitSize extends null | number |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
type | IType<ValueType, ValueBitSize> | The type of the underlying value |
Returns
Merge<Id, Entries, Name, IType<null | ValueType, null, undefined | null | ValueType>>
The modified schema
serialize()
serialize(
value:Readonly<SerializeValueEntries<Entries>>,defaultMaximumArrayLength:number):string
Defined in: schema/Schema.ts:76
Create a buffer and serialize a value into it, then convert it to a string
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
value | Readonly<SerializeValueEntries<Entries>> | undefined | The value to serialize into the buffer |
defaultMaximumArrayLength | number | 100 | The default maximum array length, if any |
Returns
string
The newly created string.
Seealso
This method calls Schema.serializeRaw before calling toString() to its result.
serializeInto()
serializeInto(
buffer:DuplexBuffer,value:Readonly<SerializeValueEntries<Entries>>):void
Defined in: schema/Schema.ts:104
Serialize a value into a buffer.
Parameters
| Parameter | Type | Description |
|---|---|---|
buffer | DuplexBuffer | The buffer to serialize |
value | Readonly<SerializeValueEntries<Entries>> | The value to serialize into the buffer |
Returns
void
Remarks
The schema's ID is written to the buffer first, followed by each property in the schema.
serializeRaw()
serializeRaw(
value:Readonly<SerializeValueEntries<Entries>>,defaultMaximumArrayLength:number):DuplexBuffer
Defined in: schema/Schema.ts:87
Create a buffer and serialize a value into it.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
value | Readonly<SerializeValueEntries<Entries>> | undefined | The value to serialize into the buffer |
defaultMaximumArrayLength | number | 100 | The default maximum array length, if any |
Returns
The newly created buffer.
snowflake()
snowflake<
Name>(name:Name):Merge<Id,Entries,Name,IType<bigint,64,string|bigint>>
Defined in: schema/Schema.ts:478
Adds a 64-bit big integer property to the schema, similar to Schema.bigUint64.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<bigint, 64, string | bigint>>
The modified schema
Remarks
The range of values is from 0n to 18_446_744_073_709_551_615n, inclusive.
string()
string<
Name>(name:Name):Merge<Id,Entries,Name,IType<string,null,string>>
Defined in: schema/Schema.ts:174
Adds a string property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<string, null, string>>
The modified schema
uint16()
uint16<
Name>(name:Name):Merge<Id,Entries,Name,IType<number,16,number>>
Defined in: schema/Schema.ts:306
Adds a 16-bit unsigned integer property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<number, 16, number>>
The modified schema
Remarks
The range of values is from 0 to 65535, inclusive.
uint2()
uint2<
Name>(name:Name):Merge<Id,Entries,Name,IType<number,2,number>>
Defined in: schema/Schema.ts:222
Adds a 2-bit unsigned integer property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<number, 2, number>>
The modified schema
Remarks
The range of values is from 0 to 3, inclusive.
uint32()
uint32<
Name>(name:Name):Merge<Id,Entries,Name,IType<number,32,number>>
Defined in: schema/Schema.ts:334
Adds a 32-bit unsigned integer property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<number, 32, number>>
The modified schema
Remarks
The range of values is from 0 to 4_294_967_295, inclusive.
uint4()
uint4<
Name>(name:Name):Merge<Id,Entries,Name,IType<number,4,number>>
Defined in: schema/Schema.ts:250
Adds a 4-bit unsigned integer property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<number, 4, number>>
The modified schema
Remarks
The range of values is from 0 to 15, inclusive.
uint64()
uint64<
Name>(name:Name):Merge<Id,Entries,Name,IType<number,64,number>>
Defined in: schema/Schema.ts:366
Adds a 64-bit unsigned integer property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<number, 64, number>>
The modified schema
Remarks
The range of values is from 0 to 18_446_744_073_709_551_615, inclusive.
However, it may run into precision issues past 9_007_199_254_740_991
uint8()
uint8<
Name>(name:Name):Merge<Id,Entries,Name,IType<number,8,number>>
Defined in: schema/Schema.ts:278
Adds a 8-bit unsigned integer property to the schema.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | Name | The name of the property |
Returns
Merge<Id, Entries, Name, IType<number, 8, number>>
The modified schema
Remarks
The range of values is from 0 to 255, inclusive.
values()
values():
IterableIterator<{ [K in string | number | symbol]: Entries[K] }[keyofEntries]>
Defined in: schema/Schema.ts:508
Iterates over the schema's property values
Returns
IterableIterator<{ [K in string | number | symbol]: Entries[K] }[keyof Entries]>
An iterator for the schema's property values