Skip to content

@jimka/typescript-ui / data / Model

Class: Model

Defined in: src/typescript/lib/data/Model.ts:22

A concrete, configurable model created at runtime from a field array. Use this class when you do not need a dedicated model subclass.

Extends

Constructors

new Model()

ts
new Model(fields: 
  | (FieldOptions | Field)[]
  | ModelOptions, primaryKey?: string): Model

Defined in: src/typescript/lib/data/Model.ts:32

Constructs a Model with the specified fields and an optional primary key.

Parameters

fields

An array of Field instances or FieldOptions objects that define the schema, or a ModelOptions bag.

(FieldOptions | Field)[] | ModelOptions

primaryKey?

string

Optional. The name of the field to use as the primary key. Ignored when the first argument is a ModelOptions bag.

Returns

Model

Overrides

AbstractModel.constructor

Properties

fields

ts
readonly fields: (FieldOptions | Field)[];

Defined in: src/typescript/lib/data/Model.ts:24

Overrides

AbstractModel.fields

Methods

createRecord()

ts
createRecord(data: any[] | Record<string, any>): ModelRecord

Defined 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

ModelRecord

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().

Inherited from

AbstractModel.createRecord


getField()

ts
getField(name: string): undefined | Field

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

Inherited from

AbstractModel.getField


getFields()

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

Inherited from

AbstractModel.getFields


getPrimaryKeyField()

ts
getPrimaryKeyField(): undefined | Field

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

Inherited from

AbstractModel.getPrimaryKeyField


hasField()

ts
hasField(name: string): boolean

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

Inherited from

AbstractModel.hasField