@jimka/typescript-ui / data / AbstractModel
Class: abstract AbstractModel
Defined in: src/typescript/lib/data/AbstractModel.ts:16
Base class for all data models. Defines the field schema used to create and validate ModelRecord instances.
Remarks
Subclasses must declare the fields array. Field resolution and the name-to-field index are built lazily on first access and cached for subsequent calls.
Extended by
Constructors
new AbstractModel()
new AbstractModel(): AbstractModelReturns
Properties
fields
abstract readonly fields: (FieldOptions | Field)[];Defined in: src/typescript/lib/data/AbstractModel.ts:18
Methods
createRecord()
createRecord(data: any[] | Record<string, any>): ModelRecordDefined in: src/typescript/lib/data/AbstractModel.ts:107
Creates a ModelRecord from a plain object or positional array, applying field mappings and defaults.
Parameters
data
Optional. The source data as a key/value object or a positional array. When an array is provided, values are assigned to fields ordered by their order property.
any[] | Record<string, any>
Returns
A new ModelRecord populated with mapped and defaulted field values.
Remarks
When data is an array, fields are sorted by their order value before being matched by position. Fields absent from data receive the value from field.getDefaultValue().
getField()
getField(name: string): undefined | FieldDefined in: src/typescript/lib/data/AbstractModel.ts:76
Returns the Field with the given name, or undefined if not found.
Parameters
name
string
The logical name of the field to look up.
Returns
undefined | Field
The matching Field, or undefined if no field with that name exists.
getFields()
getFields(): Field[]Defined in: src/typescript/lib/data/AbstractModel.ts:63
Returns all resolved Field instances for this model.
Returns
Field[]
An array of all Field instances defined on this model.
getPrimaryKeyField()
getPrimaryKeyField(): undefined | FieldDefined in: src/typescript/lib/data/AbstractModel.ts:50
Returns the Field designated as the primary key, or undefined if none is set.
Returns
undefined | Field
The primary key Field, or undefined if no primary key has been configured.
hasField()
hasField(name: string): booleanDefined in: src/typescript/lib/data/AbstractModel.ts:89
Returns true if the model contains a field with the given name.
Parameters
name
string
The logical name of the field to check.
Returns
boolean
True if a field with the given name exists, false otherwise.