Skip to main content

Class: SchemaStore<Entries>

Defined in: schema/SchemaStore.ts:5

Type Parameters

Type ParameterDefault type
Entries extends objectobject

Constructors

new SchemaStore()

new SchemaStore<Entries>(defaultMaximumArrayLength: number): SchemaStore<Entries>

Defined in: schema/SchemaStore.ts:18

Creates a new schema store

Parameters

ParameterTypeDefault valueDescription
defaultMaximumArrayLengthnumber100The default maximum array length for schemas

Returns

SchemaStore<Entries>

Properties

#schemas

private readonly #schemas: Map<number, Schema>

Defined in: schema/SchemaStore.ts:11


defaultMaximumArrayLength

defaultMaximumArrayLength: number

Defined in: schema/SchemaStore.ts:9

The default maximum array length for schemas

Methods

[iterator]()

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

Defined in: schema/SchemaStore.ts:140

Iterates over the stores's schema entries.

Returns

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

An iterator for the stores's schema entries


add()

add<Id, SchemaType>(schema: Schema<Id, SchemaType>): Merge<Entries, Id, Schema<Id, SchemaType>>

Defined in: schema/SchemaStore.ts:32

Adds a schema to the store

Type Parameters

Type Parameter
Id extends number
SchemaType extends object

Parameters

ParameterTypeDescription
schemaSchema<Id, SchemaType>The schema to add to the store

Returns

Merge<Entries, Id, Schema<Id, SchemaType>>

The modified store

Remarks

An error will be thrown if a schema with the same id already exists in the store.


deserialize()

deserialize(buffer: string | UnalignedUint16Array): DeserializationResult<Entries>

Defined in: schema/SchemaStore.ts:77

Deserializes a buffer

Parameters

ParameterTypeDescription
bufferstring | UnalignedUint16ArrayThe buffer to deserialize

Returns

DeserializationResult<Entries>

The resolved value, including the id of the schema used for deserialization


entries()

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

Defined in: schema/SchemaStore.ts:131

Iterates over the stores's schema entries.

Returns

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

An iterator for the stores's schema entries


get()

get<Id>(id: Id): Entries[Id]

Defined in: schema/SchemaStore.ts:51

Gets a schema from the store

Type Parameters

Type Parameter
Id extends number

Parameters

ParameterTypeDescription
idIdThe id of the schema to get

Returns

Entries[Id]

The schema with the given id

Remarks

An error will be thrown if a schema with the given id does not exist in the store.


getIdentifier()

getIdentifier(buffer: string | UnalignedUint16Array): keyof Entries & number

Defined in: schema/SchemaStore.ts:95

Gets the serialized ID from a buffer

Parameters

ParameterTypeDescription
bufferstring | UnalignedUint16ArrayThe buffer to read the ID from

Returns

keyof Entries & number

The deserialized ID

Remarks

If an empty value is passed, a RangeError will be thrown.


keys()

keys(): IterableIterator<keyof Entries & number>

Defined in: schema/SchemaStore.ts:113

Iterates over the stores's schema identifiers.

Returns

IterableIterator<keyof Entries & number>

An iterator for the stores's schema identifiers


serialize()

serialize<Id>(id: Id, value: SerializeValue<Entries[Id] & object>): UnalignedUint16Array

Defined in: schema/SchemaStore.ts:64

Serializes a value using the schema with the given id

Type Parameters

Type Parameter
Id extends number

Parameters

ParameterTypeDescription
idIdThe id of the schema to use for serialization
valueSerializeValue<Entries[Id] & object>The value to serialize

Returns

UnalignedUint16Array

The serialized buffer


values()

values(): IterableIterator<Entries[keyof Entries & number]>

Defined in: schema/SchemaStore.ts:122

Iterates over the stores's schemas.

Returns

IterableIterator<Entries[keyof Entries & number]>

An iterator for the stores's schemas