Class: SchemaStore<Entries>
Defined in: schema/SchemaStore.ts:6
Type Parameters
| Type Parameter | Default type |
|---|---|
Entries extends object | object |
Constructors
Constructor
new SchemaStore<
Entries>(defaultMaximumArrayLength:number):SchemaStore<Entries>
Defined in: schema/SchemaStore.ts:19
Creates a new schema store
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
defaultMaximumArrayLength | number | 100 | The default maximum array length for schemas |
Returns
SchemaStore<Entries>
Properties
#schemas
privatereadonly#schemas:Map<number,Schema<number,object>>
Defined in: schema/SchemaStore.ts:12
defaultMaximumArrayLength
defaultMaximumArrayLength:
number
Defined in: schema/SchemaStore.ts:10
The default maximum array length for schemas
Methods
[iterator]()
[iterator]():
IterableIterator<{ [K in string | number | symbol]: readonly [K & number, Entries[K]] }[keyofEntries]>
Defined in: schema/SchemaStore.ts:150
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:33
Adds a schema to the store
Type Parameters
| Type Parameter |
|---|
Id extends number |
SchemaType extends object |
Parameters
| Parameter | Type | Description |
|---|---|---|
schema | Schema<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|DuplexBuffer):DeserializationResult<Entries>
Defined in: schema/SchemaStore.ts:87
Deserializes a buffer
Parameters
| Parameter | Type | Description |
|---|---|---|
buffer | string | DuplexBuffer | The 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]] }[keyofEntries]>
Defined in: schema/SchemaStore.ts:141
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:52
Gets a schema from the store
Type Parameters
| Type Parameter |
|---|
Id extends number |
Parameters
| Parameter | Type | Description |
|---|---|---|
id | Id | The 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|DuplexBuffer): keyofEntries&number
Defined in: schema/SchemaStore.ts:105
Gets the serialized ID from a buffer
Parameters
| Parameter | Type | Description |
|---|---|---|
buffer | string | DuplexBuffer | The 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<keyofEntries&number>
Defined in: schema/SchemaStore.ts:123
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>):string
Defined in: schema/SchemaStore.ts:65
Serializes a value using the schema with the given id
Type Parameters
| Type Parameter |
|---|
Id extends number |
Parameters
| Parameter | Type | Description |
|---|---|---|
id | Id | The id of the schema to use for serialization |
value | SerializeValue<Entries[Id] & object> | The value to serialize |
Returns
string
The serialized string
serializeRaw()
serializeRaw<
Id>(id:Id,value:SerializeValue<Entries[Id] &object>):DuplexBuffer
Defined in: schema/SchemaStore.ts:76
Serializes a value using the schema with the given id
Type Parameters
| Type Parameter |
|---|
Id extends number |
Parameters
| Parameter | Type | Description |
|---|---|---|
id | Id | The id of the schema to use for serialization |
value | SerializeValue<Entries[Id] & object> | The value to serialize |
Returns
The serialized buffer
values()
values():
IterableIterator<Entries[keyofEntries&number]>
Defined in: schema/SchemaStore.ts:132
Iterates over the stores's schemas.
Returns
IterableIterator<Entries[keyof Entries & number]>
An iterator for the stores's schemas