Skip to main content

Class: DataItemUtils

Defined in: src/sdk/data/DataItemUtils.ts:6

A utility class for working with DataItems.

Constructors​

Constructor​

new DataItemUtils(): DataItemUtils

Returns​

DataItemUtils

Methods​

createEquals()​

static createEquals<T>(valueEqualityFunc): (a, b) => boolean

Defined in: src/sdk/data/DataItemUtils.ts:42

Creates a function that evaluates the equality of two data items given value equality semantics defined by a supplied function.

Type Parameters​

Type ParameterDescription
TThe value type of the data items to compare.

Parameters​

ParameterTypeDefault valueDescription
valueEqualityFunc(a, b) => booleanDataItemUtils.defaultValueEqualsThe function to use to check whether two data item values are equal. Defaults to a function that implements default equality semantics: two values a and b are equal if and only if the strict equality operator (===) evaluates to true for a and b, or both a and b are the numeric value NaN.

Returns​

A function that evaluates the equality of two data items given the value equality semantics defined by the specified function.

(a, b): boolean

Parameters​
ParameterType
aReadonly<DataItem<T>>
bReadonly<DataItem<T>>
Returns​

boolean


createIsStatusValid()​

static createIsStatusValid<S>(validStatuses): (status) => status is S

Defined in: src/sdk/data/DataItemUtils.ts:103

Creates a function that checks whether data item statuses are valid.

Type Parameters​

Type ParameterDescription
S extends DataItemStatusThe type of the data item statuses that should be considered valid.

Parameters​

ParameterTypeDescription
validStatusesreadonly S[]An array of data item statuses that should be considered valid. The returned function will consider a data item status to be valid if and only if it is contained in this array.

Returns​

A function that checks whether data item statuses are valid given the specified array of valid statuses.

(status): status is S

Parameters​
ParameterType
statusDataItemStatus
Returns​

status is S


createIsValid()​

static createIsValid<S>(validStatuses): DataItemStatusGuard<S>

Defined in: src/sdk/data/DataItemUtils.ts:92

Creates a function that checks whether data items are valid.

Type Parameters​

Type ParameterDescription
S extends DataItemStatusThe type of the data item statuses that should be considered valid.

Parameters​

ParameterTypeDescription
validStatusesreadonly S[]An array of data item statuses that should be considered valid. The returned function will consider a data item to be valid if and only if its status is contained in this array.

Returns​

DataItemStatusGuard<S>

A function that checks whether data items are valid given the specified array of valid statuses.


defaultEquals()​

static defaultEquals(a, b): boolean

Defined in: src/sdk/data/DataItemUtils.ts:27

Checks whether two data items are equal using default equality semantics for data item values: values for two data items a.value and b.value are equal if and only if the strict equality operator (===) evaluates to true for a.value and b.value, or both a.value and b.value are the numeric value NaN.

Parameters​

ParameterTypeDescription
aReadonly<DataItem<unknown>>The first data item to check.
bReadonly<DataItem<unknown>>The second data item to check.

Returns​

boolean

Whether the two specified data items are equal using default equality semantics for their data item values.


defaultIsStatusValid()​

static defaultIsStatusValid(status): status is Normal | Testing

Defined in: src/sdk/data/DataItemUtils.ts:81

Checks if a data item status is either DataItemStatus.Normal or DataItemStatus.Testing.

Parameters​

ParameterTypeDescription
statusDataItemStatusThe data item status to check.

Returns​

status is Normal | Testing

Whether the specified data item's status is either DataItemStatus.Normal or DataItemStatus.Testing.


defaultIsValid()​

static defaultIsValid(dataItem): dataItem is Readonly<FilledDataItem<unknown> & { status: Normal | Testing }>

Defined in: src/sdk/data/DataItemUtils.ts:71

Checks if a data item is valid. A valid data item's status is either DataItemStatus.Normal or DataItemStatus.Testing.

Parameters​

ParameterTypeDescription
dataItemReadonly<DataItem<unknown>>The data item to check.

Returns​

dataItem is Readonly<FilledDataItem<unknown> & { status: Normal | Testing }>

Whether the specified data item's status is either DataItemStatus.Normal or DataItemStatus.Testing.


defaultValueEquals()​

static defaultValueEquals(a, b): boolean

Defined in: src/sdk/data/DataItemUtils.ts:59

Checks whether two data item values are equal using default equality semantics: two values a and b are equal if and only if the strict equality operator (===) evaluates to true for a and b, or both a and b are the numeric value NaN.

Parameters​

ParameterTypeDescription
aunknownThe first data item value to check.
bunknownThe second data item value to check.

Returns​

boolean

Whether the two specified values are equal using default equality semantics.


emptyItem()​

static emptyItem(): EmptyDataItem

Defined in: src/sdk/data/DataItemUtils.ts:11

Creates a new empty data item.

Returns​

EmptyDataItem

A new empty data item.


valueOr()​

static valueOr<Item, D>(dataItem, defaultValue, isValid): DataItemValueType<Item> | D

Defined in: src/sdk/data/DataItemUtils.ts:118

Gets the value of a data item if it is valid or a default value if it is not valid.

Type Parameters​

Type ParameterDefault typeDescription
Item extends Readonly<DataItem<unknown>>-The type of the data item for which to get a value.
DDataItemValueType<Item>The type of the default value.

Parameters​

ParameterTypeDefault valueDescription
dataItemItemundefinedThe data item for which to get a value.
defaultValueDundefinedThe default value returned when the data item is invalid.
isValidDataItemStatusGuard<Normal | Failed | NoComputedValue | Testing>DataItemUtils.defaultIsValidA function that checks whether the data item is valid. Defaults to a function that considers a data item to be valid if and only if its status is DataItemStatus.Normal or DataItemStatus.Testing.

Returns​

DataItemValueType<Item> | D

The value of the specified data item if it is valid (according to the isValid argument), or the specified default value if the item is invalid.