StructInfo

View source

ExtendsTypeInfo

Describes the named fields in structured reflection metadata.

The constructor turns a field record into ordered metadata: each property name is mapped to the corresponding Field position in fields. Look up metadata by name with StructInfo#get, by position with StructInfo#getByIndex, or inspect the complete field layout with the other accessors. The record’s property order becomes the field order used by serialization and index lookups.

Examples

import { Field, StructInfo } from '@wimaengine/reflect'
import { typeid } from '@wimaengine/type'

const info = new StructInfo({
  id: new Field(typeid(Number)),
  label: new Field(typeid(String), true)
})

info.get('id') === info.getByIndex(0) // true
info.size() // 2
info.serialize() // { kind: 'struct', fields: ... }

Constructor


constructor(record: Record<string, Field>)

View source

Creates structured metadata from a name-to-field record.

Property insertion order determines each field’s index. The record is read immediately; later changes to it do not change this metadata.

Parameters

NameDescriptionDefault
record——

Methods


get(name: string): Field

View source

Returns the field metadata registered under a name.

Parameters

NameDescriptionDefault
name——

Returns

The field, or undefined when the name is not registered.

getByIndex(index: number): Field

View source

Returns the field metadata at a zero-based position.

Parameters

NameDescriptionDefault
index——

Returns

The field at the position, or undefined outside the field array.

getFields(): Field[]

View source

Returns the internal ordered field array.

The returned array is live, so callers that need to preserve the metadata layout should treat it as read-only.

fieldNames(): MapIterator<string>

View source

Returns an iterator over field names in insertion order.

staticserialize(value: StructInfo): StructInfoSerial

View source

Serializes structured metadata, including each field’s type ID and optional flag.

Parameters

NameDescriptionDefault
value——

staticdeserialize(value: StructInfoSerial, out?: StructInfo): StructInfo

View source

Restores structured metadata from its serialized field record.

The target instance is cleared and repopulated in serialized property order. Pass out to reuse an existing instance; otherwise a new empty StructInfo is created. The serial is assumed to have been validated.

Parameters

NameDescriptionDefault
value——
out?—...

staticvalidateSerial(value: unknown): value is StructInfoSerial

View source

Checks whether a value has the structured metadata serial shape.

Validation requires a non-null, non-array object with kind: 'struct' and a non-null, non-array fields object. Every field entry must pass Field.validateSerial.

Parameters

NameDescriptionDefault
value——