Skip to main content

Class: Schema<Id, Entries>

Type Parameters​

Type ParameterDefault type
Id extends numbernumber
Entries extends objectobject

Constructors​

new Schema()​

new Schema<Id, Entries>(id: Id): Schema<Id, Entries>

Creates a new schema.

Parameters​

ParameterTypeDescription
idIdThe id of the schema

Returns​

Schema<Id, Entries>

Defined in​

schema/Schema.ts:15

Properties​

#bitSize​

private #bitSize: null | number = 0

Defined in​

schema/Schema.ts:8


#id​

private readonly #id: Id

Defined in​

schema/Schema.ts:6


#types​

private readonly #types: Map<string, IType<any, null | number>>

Defined in​

schema/Schema.ts:7

Accessors​

bitSize​

Get Signature​

get bitSize(): null | number

The total bit size of 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

Defined in​

schema/Schema.ts:34


id​

Get Signature​

get id(): Id

The id of the schema.

Returns​

Id

Defined in​

schema/Schema.ts:22

Methods​

[iterator]()​

[iterator](): IterableIterator<{ [K in string | number | symbol]: readonly [K, Entries[K]] }[keyof Entries]>

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

Defined in​

schema/Schema.ts:460


#addType()​

private #addType<EntryName, ValueType, ValueBitSize>(name: EntryName, type: IType<ValueType, ValueBitSize>): Merge<Id, Entries, EntryName, IType<ValueType, ValueBitSize>>

Type Parameters​

Type Parameter
EntryName extends string
ValueType
ValueBitSize extends null | number

Parameters​

ParameterType
nameEntryName
typeIType<ValueType, ValueBitSize>

Returns​

Merge<Id, Entries, EntryName, IType<ValueType, ValueBitSize>>

Defined in​

schema/Schema.ts:464


array()​

array<Name, ValueType, ValueBitSize>(name: Name, type: IType<ValueType, ValueBitSize>): Merge<Id, Entries, Name, IType<ValueType[], null>>

Adds an array property to the schema.

Type Parameters​

Type Parameter
Name extends string
ValueType
ValueBitSize extends null | number

Parameters​

ParameterTypeDescription
nameNameThe name of the property
typeIType<ValueType, ValueBitSize>The type of the entry in the array

Returns​

Merge<Id, Entries, Name, IType<ValueType[], null>>

The modified schema

Seealso​

Schema.fixedLengthArray for a fixed length array

Defined in​

schema/Schema.ts:103


bigInt32()​

bigInt32<Name>(name: Name): Merge<Id, Entries, Name, IType<bigint, 32>>

Adds a 32-bit big integer property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<bigint, 32>>

The modified schema

Remarks​

The range of values is from -2_147_483_648n to 2_147_483_647n, inclusive.

Defined in​

schema/Schema.ts:340


bigInt64()​

bigInt64<Name>(name: Name): Merge<Id, Entries, Name, IType<bigint, 64>>

Adds a 64-bit big integer property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<bigint, 64>>

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.

Defined in​

schema/Schema.ts:368


bigUint32()​

bigUint32<Name>(name: Name): Merge<Id, Entries, Name, IType<bigint, 32>>

Adds a 32-bit big integer property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<bigint, 32>>

The modified schema

Remarks​

The range of values is from 0n to 4_294_967_295n, inclusive.

Defined in​

schema/Schema.ts:354


bigUint64()​

bigUint64<Name>(name: Name): Merge<Id, Entries, Name, IType<bigint, 64>>

Adds a 64-bit big integer property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<bigint, 64>>

The modified schema

Remarks​

The range of values is from 0n to 18_446_744_073_709_551_615n, inclusive.

Defined in​

schema/Schema.ts:382


bit()​

bit<Name>(name: Name): Merge<Id, Entries, Name, IType<number, 1>>

Adds a bit property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<number, 1>>

The modified schema

Defined in​

schema/Schema.ts:154


boolean()​

boolean<Name>(name: Name): Merge<Id, Entries, Name, IType<boolean, 1>>

Adds a boolean property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<boolean, 1>>

The modified schema

Defined in​

schema/Schema.ts:144


deserialize()​

deserialize(buffer: UnalignedUint16Array, pointer: PointerLike): UnwrapSchemaEntries<Entries>

Deserialize a value from a buffer.

Parameters​

ParameterTypeDescription
bufferUnalignedUint16ArrayThe buffer to deserialize
pointerPointerLikeThe pointer to where the buffer should be read from

Returns​

UnwrapSchemaEntries<Entries>

The deserialized value

Remarks​

Unlike Schema.serialize, this method does not read the schema's ID from the buffer, that is reserved for the SchemaStore.

Defined in​

schema/Schema.ts:84


entries()​

entries(): IterableIterator<{ [K in string | number | symbol]: readonly [K, Entries[K]] }[keyof Entries]>

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

Defined in​

schema/Schema.ts:451


fixedLengthArray()​

fixedLengthArray<Name, ValueType, ValueBitSize>(name: Name, type: IType<ValueType, ValueBitSize>, length: number): Merge<Id, Entries, Name, IType<ValueType[], ValueBitSize extends null ? null : number>>

Adds a fixed length array property to the schema.

Type Parameters​

Type Parameter
Name extends string
ValueType
ValueBitSize extends null | number

Parameters​

ParameterTypeDescription
nameNameThe name of the property
typeIType<ValueType, ValueBitSize>The type of the entry in the array
lengthnumberThe length of the array

Returns​

Merge<Id, Entries, Name, IType<ValueType[], ValueBitSize extends null ? null : number>>

The modified schema

Seealso​

Schema.array for a dynamic length array

Defined in​

schema/Schema.ts:120


float32()​

float32<Name>(name: Name): Merge<Id, Entries, Name, IType<number, 32>>

Adds a 32-bit floating point number property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<number, 32>>

The modified schema

Remarks​

The range of values is from -3.4028234663852886e+38 to 3.4028234663852886e+38, inclusive.

Defined in​

schema/Schema.ts:396


float64()​

float64<Name>(name: Name): Merge<Id, Entries, Name, IType<number, 64>>

Adds a 64-bit floating point number property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<number, 64>>

The modified schema

Remarks​

The range of values is from -1.7976931348623157e+308 to 1.7976931348623157e+308, inclusive.

Defined in​

schema/Schema.ts:410


get()​

get<Name>(name: Name): Entries[Name]

Get a property from the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Entries[Name]

The specified property

Remarks​

If the property does not exist, an error will be thrown.

Defined in​

schema/Schema.ts:48


int16()​

int16<Name>(name: Name): Merge<Id, Entries, Name, IType<number, 16>>

Adds a 16-bit integer property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<number, 16>>

The modified schema

Remarks​

The range of values is from -32768 to 32767, inclusive.

Defined in​

schema/Schema.ts:252


int2()​

int2<Name>(name: Name): Merge<Id, Entries, Name, IType<number, 2>>

Adds a 2-bit integer property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<number, 2>>

The modified schema

Remarks​

The range of values is from -2 to 1, inclusive.

Defined in​

schema/Schema.ts:168


int32()​

int32<Name>(name: Name): Merge<Id, Entries, Name, IType<number, 32>>

Adds a 32-bit integer property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<number, 32>>

The modified schema

Remarks​

The range of values is from -2_147_483_648 to 2_147_483_647, inclusive.

Defined in​

schema/Schema.ts:280


int4()​

int4<Name>(name: Name): Merge<Id, Entries, Name, IType<number, 4>>

Adds a 4-bit integer property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<number, 4>>

The modified schema

Remarks​

The range of values is from -8 to 7, inclusive.

Defined in​

schema/Schema.ts:196


int64()​

int64<Name>(name: Name): Merge<Id, Entries, Name, IType<number, 64>>

Adds a 64-bit integer property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<number, 64>>

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

Defined in​

schema/Schema.ts:310


int8()​

int8<Name>(name: Name): Merge<Id, Entries, Name, IType<number, 8>>

Adds a 8-bit integer property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<number, 8>>

The modified schema

Remarks​

The range of values is from -128 to 127, inclusive.

Defined in​

schema/Schema.ts:224


keys()​

keys(): IterableIterator<keyof Entries & string>

Iterates over the schema's property names.

Returns​

IterableIterator<keyof Entries & string>

An iterator for the schema's property names

Defined in​

schema/Schema.ts:433


serialize()​

serialize(buffer: UnalignedUint16Array, value: Readonly<UnwrapSchemaEntries<Entries>>): void

Serialize a value into a buffer.

Parameters​

ParameterTypeDescription
bufferUnalignedUint16ArrayThe buffer to serialize
valueReadonly<UnwrapSchemaEntries<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.

Defined in​

schema/Schema.ts:65


snowflake()​

snowflake<Name>(name: Name): Merge<Id, Entries, Name, IType<bigint, 64>>

Adds a 64-bit big integer property to the schema, similar to Schema.bigUint64.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<bigint, 64>>

The modified schema

Remarks​

The range of values is from 0n to 18_446_744_073_709_551_615n, inclusive.

Defined in​

schema/Schema.ts:424


string()​

string<Name>(name: Name): Merge<Id, Entries, Name, IType<string, null>>

Adds a string property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<string, null>>

The modified schema

Defined in​

schema/Schema.ts:134


uint16()​

uint16<Name>(name: Name): Merge<Id, Entries, Name, IType<number, 16>>

Adds a 16-bit unsigned integer property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<number, 16>>

The modified schema

Remarks​

The range of values is from 0 to 65535, inclusive.

Defined in​

schema/Schema.ts:266


uint2()​

uint2<Name>(name: Name): Merge<Id, Entries, Name, IType<number, 2>>

Adds a 2-bit unsigned integer property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<number, 2>>

The modified schema

Remarks​

The range of values is from 0 to 3, inclusive.

Defined in​

schema/Schema.ts:182


uint32()​

uint32<Name>(name: Name): Merge<Id, Entries, Name, IType<number, 32>>

Adds a 32-bit unsigned integer property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<number, 32>>

The modified schema

Remarks​

The range of values is from 0 to 4_294_967_295, inclusive.

Defined in​

schema/Schema.ts:294


uint4()​

uint4<Name>(name: Name): Merge<Id, Entries, Name, IType<number, 4>>

Adds a 4-bit unsigned integer property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<number, 4>>

The modified schema

Remarks​

The range of values is from 0 to 15, inclusive.

Defined in​

schema/Schema.ts:210


uint64()​

uint64<Name>(name: Name): Merge<Id, Entries, Name, IType<number, 64>>

Adds a 64-bit unsigned integer property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<number, 64>>

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

Defined in​

schema/Schema.ts:326


uint8()​

uint8<Name>(name: Name): Merge<Id, Entries, Name, IType<number, 8>>

Adds a 8-bit unsigned integer property to the schema.

Type Parameters​

Type Parameter
Name extends string

Parameters​

ParameterTypeDescription
nameNameThe name of the property

Returns​

Merge<Id, Entries, Name, IType<number, 8>>

The modified schema

Remarks​

The range of values is from 0 to 255, inclusive.

Defined in​

schema/Schema.ts:238


values()​

values(): IterableIterator<{ [K in string | number | symbol]: Entries[K] }[keyof Entries]>

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

Defined in​

schema/Schema.ts:442