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, any>>

Defined in

schema/Schema.ts:7

Accessors

bitSize

Get Signature

get bitSize(): null | number

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

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


totalBitSize

Get Signature

get totalBitSize(): null | number

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

Defined in

schema/Schema.ts:46

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:498


#addType()

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

Type Parameters

Type Parameter
EntryName extends string
ValueType
ValueBitSize extends null | number
InputValue

Parameters

ParameterType
nameEntryName
typeIType<ValueType, ValueBitSize, InputValue>

Returns

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

Defined in

schema/Schema.ts:502


array()

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

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, ValueType>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

Defined in

schema/Schema.ts:115


bigInt32()

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

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, bigint>>

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:352


bigInt64()

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

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, 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.

Defined in

schema/Schema.ts:380


bigUint32()

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

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, bigint>>

The modified schema

Remarks

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

Defined in

schema/Schema.ts:366


bigUint64()

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

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, bigint>>

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:394


bit()

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

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<0 | 1, 1, number>>

The modified schema

Defined in

schema/Schema.ts:166


boolean()

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

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, boolean>>

The modified schema

Defined in

schema/Schema.ts:156


constant()

constant<Name, ValueType>(name: Name, constantValue: ValueType): Merge<Id, Entries, Name, IType<ValueType, 0, never>>

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

ParameterTypeDescription
nameNameThe name of the property
constantValueValueTypeThe value to add to the schema

Returns

Merge<Id, Entries, Name, IType<ValueType, 0, never>>

The modified schema

Defined in

schema/Schema.ts:462


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:96


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:489


fixedLengthArray()

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

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, ValueType>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, ValueType[]>>

The modified schema

Seealso

Schema.array for a dynamic length array

Defined in

schema/Schema.ts:132


float32()

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

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, number>>

The modified schema

Remarks

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

Defined in

schema/Schema.ts:408


float64()

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

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, number>>

The modified schema

Remarks

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

Defined in

schema/Schema.ts:422


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:60


int16()

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

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, number>>

The modified schema

Remarks

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

Defined in

schema/Schema.ts:264


int2()

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

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, number>>

The modified schema

Remarks

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

Defined in

schema/Schema.ts:180


int32()

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

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, number>>

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:292


int4()

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

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, number>>

The modified schema

Remarks

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

Defined in

schema/Schema.ts:208


int64()

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

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, 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

Defined in

schema/Schema.ts:322


int8()

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

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, number>>

The modified schema

Remarks

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

Defined in

schema/Schema.ts:236


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:471


nullable()

nullable<Name, ValueType, ValueBitSize>(name: Name, type: IType<ValueType, ValueBitSize, ValueType>): Merge<Id, Entries, Name, IType<null | ValueType, null, undefined | null | ValueType>>

Adds a nullable 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, ValueType>The type of the underlying value

Returns

Merge<Id, Entries, Name, IType<null | ValueType, null, undefined | null | ValueType>>

The modified schema

Defined in

schema/Schema.ts:433


serialize()

serialize(buffer: UnalignedUint16Array, value: Readonly<OmitNever<{ [K in string | number | symbol]: SerializeValueType<Entries[K] & object> }>>): void

Serialize a value into a buffer.

Parameters

ParameterTypeDescription
bufferUnalignedUint16ArrayThe buffer to serialize
valueReadonly<OmitNever<{ [K in string | number | symbol]: SerializeValueType<Entries[K] & object> }>>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:77


snowflake()

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

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, string | bigint>>

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:450


string()

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

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, string>>

The modified schema

Defined in

schema/Schema.ts:146


uint16()

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

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, number>>

The modified schema

Remarks

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

Defined in

schema/Schema.ts:278


uint2()

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

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, number>>

The modified schema

Remarks

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

Defined in

schema/Schema.ts:194


uint32()

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

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, number>>

The modified schema

Remarks

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

Defined in

schema/Schema.ts:306


uint4()

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

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, number>>

The modified schema

Remarks

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

Defined in

schema/Schema.ts:222


uint64()

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

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, 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

Defined in

schema/Schema.ts:338


uint8()

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

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, number>>

The modified schema

Remarks

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

Defined in

schema/Schema.ts:250


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:480