Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface MutableRecordModel

This is a mutable data model of RecordV2 data based upon a Schema.

An initial version of such a model can be created from a schema using the Schema.createMutableModel method. A model created in this way will have all mandatory fields set to default values.

The model may then be updated as required and then at any time a RecordV2 object can be generated from the current state using the asValue method. The RecordV2 object may then be used to update a topic.

When values for integer or decimal type fields are supplied the values are validated and normalized. All number values will have any insignificant leading zeroes removed. A decimal value will also be rounded to its specified scale.

All mutator methods return the model so that calls can be chained.

since

6.0

Hierarchy

Index

Methods

add

  • Adds new values to the end of a variable length field list.

    This can only be used for a variable multiplicity field which can only be the last field in a record and therefore the field does not need to be named.

    If the record name and index are not supplied, this will add values to the last record in the model. If the model's schema does not specify a variable last field or record, an error will be thrown.

    throws

    a SchemaViolationError if adding the values would violate the schema

    Parameters

    • recordName: string

      the name of the record

    • recordIndex: number

      the index identifying the occurrence of the record

    • Rest ...values: string[]

      the values to add

    Returns MutableRecordModel

    this model

  • Parameters

    • recordName: string
    • Rest ...values: string[]

    Returns MutableRecordModel

addRecord

  • Adds a new initialized record occurrence to the end of a variable multiplicity record list.

    As the only variable multiplicity record can be the last one there is no need to name the record. This method will add to the list of occurrences of the last defined record. The record will be initialized with default values appropriate to the schema definition and may then have individual field items set separately.

    throws

    a SchemaViolationError if adding a record would violate the schema

    Returns MutableRecordModel

    this model

asValue

  • Creates an immutable RecordV2 object generated from the model.

    Returns RecordV2

    a new immutable instance

fieldCount

  • fieldCount(recordName: string, recordIndex?: undefined | number, fieldName?: undefined | string): number
  • Returns the actual number of occurrences of a named field within a specified record.

    For all but variable fields this simply returns the schema defined number of occurrences of the field.

    throws

    an SchemaViolationError if a record or field was requested that does not exist in the schema

    Parameters

    • recordName: string

      the record name

    • Optional recordIndex: undefined | number

      the record index

    • Optional fieldName: undefined | string

      the field name

    Returns number

    the actual number of occurrences of the field

get

  • get(recordName: string, recordIndex: number, fieldName: string, fieldIndex?: undefined | number): string | null
  • get(recordName: string, fieldName: string, fieldIndex?: undefined | number): string | null
  • get(recordKey: string): string | null
  • Get a field value.

    This allows an item to be addressed using a key of the form recordName(recordIndex).fieldName(fieldIndex). Indexes may be omitted in which case 0 is assumed.

    Example:

    // Get field value with record & field names and indices
    const value = model.get("record", 0, "field", 0);
    
    // Get field value with key
    const value = model.get("Address.Name");
    throws

    an IllegalArgumentError if recordName can not be parsed

    throws

    an OutOfBoundsError if recordIndex or fieldIndex is out of range

    throws

    an SchemaViolationError if a record or field was requested that does not exist in the schema

    Parameters

    • recordName: string

      the name of the record

    • recordIndex: number

      the index of the record

    • fieldName: string

      the name of the field

    • Optional fieldIndex: undefined | number

      the index of the field

    Returns string | null

    the field value

  • Parameters

    • recordName: string
    • fieldName: string
    • Optional fieldIndex: undefined | number

    Returns string | null

  • Parameters

    • recordKey: string

    Returns string | null

recordCount

  • recordCount(recordName: string): number
  • Returns the actual number of occurrences of a named record.

    If the record is not variable, this is the same as the defined number of occurrences in the schema

    Parameters

    • recordName: string

      the record name

    Returns number

    the actual number of occurrences of the record

removeField

  • removeField(recordName: string, recordIndex: number, fieldIndex: number): MutableRecordModel
  • Removes the specified occurrence of a variable multiplicity field.

    A variable multiplicity field must be the last or only field within a record and therefore the field name is not required.

    throws

    an IllegalArgumentError if one of the indices is out of range

    throws

    a OutOfBoundsError if recordIndex or fieldIndex is out of range

    throws

    a SchemaViolationError if removing the field would violate the schema

    Parameters

    • recordName: string

      the name of the record

    • recordIndex: number

      the record index

    • fieldIndex: number

      the index of the field to remove

    Returns MutableRecordModel

    this model

removeRecord

  • Removes the specified occurrence of a variable multiplicity record.

    A variable multiplicity record must be the last or only record within a schema and therefore the record name is not required.

    throws

    an IllegalArgumentError if the index is out of range

    throws

    a SchemaViolationError if removing the record would violate the schema

    Parameters

    • index: number

      the index of the record to remove

    Returns MutableRecordModel

    this model

set

  • Set a field value.

    This allows an item to be addressed using a key of the form recordName(recordIndex).fieldName(fieldIndex). Indexes may be omitted in which case 0 is assumed.

    Example:

    // Get field value with record & field names and indices
    var value = model.set("record", 0, "field", 0, "foo");
    throws

    an IllegalArgumentError if recordName is invalid

    throws

    an OutOfBoundsError if recordIndex or fieldIndex is out of range

    throws

    an SchemaViolationError if a record or field was requested that does not exist in the schema

    Parameters

    • recordName: string

      the name of the record

    • recordIndex: number

      the index of the record

    • fieldName: string

      the name of the field

    • fieldIndex: number

      the index of the field

    • value: string

      the value to be set

    Returns MutableRecordModel

    this model

  • Parameters

    • recordName: string
    • fieldName: string
    • value: string

    Returns MutableRecordModel

  • Parameters

    • recordName: string
    • value: string

    Returns MutableRecordModel