Skip to main content

@terascope/utils / entities/data-entity / DataEntity

Class: DataEntity<T, M>

A wrapper for data that can hold additional metadata properties. A DataEntity should be essentially transparent to use within operations.

NOTE: Use DataEntity.make, DataEntity.fromBuffer and DataEntity.makeArray in production for potential performance gains

Type parameters

Type parameterValue
TRecord<string, any>
M_DataEntityMetadata<Record<string, any>>

Indexable

[prop: string]: any

Constructors

new DataEntity()

new DataEntity<T, M>(data, metadata?): DataEntity<T, M>

Parameters

ParameterType
dataundefined | null | T
metadata?M

Returns

DataEntity<T, M>

Source

packages/utils/src/entities/data-entity.ts:183

Methods

getCreateTime()

getCreateTime(): Date

Get the time at which this entity was created.

Returns

Date

Source

packages/utils/src/entities/data-entity.ts:263


getEventTime()

getEventTime(): undefined | false | Date

Get time associated from a specific field on source data or message

If none is found, undefined will be returned. If an invalid date is found, false will be returned.

Returns

undefined | false | Date

Source

packages/utils/src/entities/data-entity.ts:335


getIngestTime()

getIngestTime(): undefined | false | Date

Get the time at which the data was ingested into the source data

If none is found, undefined will be returned. If an invalid date is found, false will be returned.

Returns

undefined | false | Date

Source

packages/utils/src/entities/data-entity.ts:279


getKey()

getKey(): string | number

Get the unique document _key from the metadata. If no _key is found, an error will be thrown

Returns

string | number

Source

packages/utils/src/entities/data-entity.ts:239


getMetadata()

getMetadata(key)

getMetadata(key?): _DataEntityMetadata<M>

Get the metadata for the DataEntity. If a field is specified, it will get that property of the metadata

Parameters
ParameterType
key?undefined
Returns

_DataEntityMetadata<M>

Source

packages/utils/src/entities/data-entity.ts:202

getMetadata(key)

getMetadata<K>(key): EntityMetadataValue<M, K>

Type parameters
Type parameter
K extends string | number | symbol
Parameters
ParameterType
keyK
Returns

EntityMetadataValue<M, K>

Source

packages/utils/src/entities/data-entity.ts:203


getProcessTime()

getProcessTime(): undefined | false | Date

Get the time at which the data was consumed by the reader.

If none is found, undefined will be returned. If an invalid date is found, false will be returned.

Returns

undefined | false | Date

Source

packages/utils/src/entities/data-entity.ts:307


getRawData()

getRawData(): Buffer

Get the raw data, usually used for encoding type raw. If there is no data, an error will be thrown

Returns

Buffer

Source

packages/utils/src/entities/data-entity.ts:361


setEventTime()

setEventTime(val?): void

Set time associated from a specific field on source data or message

If the value is empty it will set the time to now. If an invalid date is given, an error will be thrown.

Parameters

ParameterType
val?string | number | Date

Returns

void

Source

packages/utils/src/entities/data-entity.ts:348


setIngestTime()

setIngestTime(val?): void

Set the time at which the data was ingested into the source data

If the value is empty it will set the time to now. If an invalid date is given, an error will be thrown.

Parameters

ParameterType
val?string | number | Date

Returns

void

Source

packages/utils/src/entities/data-entity.ts:292


setKey()

setKey(key): void

Set the unique document _key from the metadata. If no _key is found, an error will be thrown

Parameters

ParameterType
keystring | number

Returns

void

Source

packages/utils/src/entities/data-entity.ts:252


setMetadata()

setMetadata<K, V>(field, value): void

Given a field and value set the metadata on the record

Type parameters

Type parameter
K extends string | number | symbol
V

Parameters

ParameterType
fieldK
valueV

Returns

void

Source

packages/utils/src/entities/data-entity.ts:219


setProcessTime()

setProcessTime(val?): void

Set the time at which the data was consumed by the reader

If the value is empty it will set the time to now. If an invalid date is given, an error will be thrown.

Parameters

ParameterType
val?string | number | Date

Returns

void

Source

packages/utils/src/entities/data-entity.ts:320


setRawData()

setRawData(buf): void

Set the raw data, usually used for encoding type raw If given null, it will unset the data

Parameters

ParameterType
bufnull | string | Buffer

Returns

void

Source

packages/utils/src/entities/data-entity.ts:372


toBuffer()

toBuffer(opConfig): Buffer

Convert the DataEntity to an encoded buffer

Parameters

ParameterTypeDescription
opConfigEncodingConfigThe operation config used to get the encoding type of the buffer,

Returns

Buffer

Default

json

Source

packages/utils/src/entities/data-entity.ts:387


[hasInstance]()

static [hasInstance](instance): boolean

Parameters

ParameterType
instanceunknown

Returns

boolean

Source

packages/utils/src/entities/data-entity.ts:169


fork()

static fork<T>(input, withData): T

Create a new instance of a DataEntity.

If the second param withData is set to true both the data and metadata will be forked, if set to false only the metadata will be copied. Defaults to true

Type parameters

Type parameterValue
T extends DataEntity<any, any>DataEntity<Record<string, any>, _DataEntityMetadata<Record<string, any>>>

Parameters

ParameterTypeDefault value
inputTundefined
withDatabooleantrue

Returns

T

Source

packages/utils/src/entities/data-entity.ts:86


fromBuffer()

static fromBuffer<T, M>(input, opConfig?, metadata?): DataEntity<T, M>

A utility for converting a Buffer to a DataEntity, using the DataEntity encoding.

Type parameters

Type parameterValue
TRecord<string, any>
MRecord<string, any>

Parameters

ParameterTypeDescription
inputstring | BufferA Buffer to parse to JSON
opConfig?EncodingConfigThe operation config used to get the encoding type of the Buffer, defaults to "json"
metadata?MOptionally add any metadata

Returns

DataEntity<T, M>

Source

packages/utils/src/entities/data-entity.ts:109


getMetadata()

static getMetadata<V>(input, field?): undefined | V

Safely get the metadata from a DataEntity. If the input is object it will get the property from the object

DEPRECATED: Since this isn't recommended to be used, and will be removed in future releases.

Type parameters

Type parameterValue
Vany

Parameters

ParameterType
inputunknown
field?string

Returns

undefined | V

Deprecated

Source

packages/utils/src/entities/data-entity.ts:158


isDataEntity()

static isDataEntity<T, M>(input): input is DataEntity<T, M>

Verify that an input is the DataEntity

Type parameters

Type parameterValue
TRecord<string, any>
MRecord<string, any>

Parameters

ParameterType
inputunknown

Returns

input is DataEntity<T, M>

Source

packages/utils/src/entities/data-entity.ts:131


isDataEntityArray()

static isDataEntityArray<T, M>(input): input is DataEntity<T, M>[]

Verify that an input is an Array of DataEntities,

Type parameters

Type parameterValue
TRecord<string, any>
MRecord<string, any>

Parameters

ParameterType
inputunknown

Returns

input is DataEntity<T, M>[]

Source

packages/utils/src/entities/data-entity.ts:140


make()

make(input, metadata)

static make<T, M>(input, metadata?): T

A utility for safely converting an object a DataEntity. If the input is a DataEntity it will return it and have no side-effect. If you want a create new DataEntity from an existing DataEntity either use new DataEntity or shallow clone the input before passing it to DataEntity.make.

Type parameters
Type parameterValue
T extends DataEntity<any, any>-
MRecord<string, any>
Parameters
ParameterType
inputT
metadata?M
Returns

T

Source

packages/utils/src/entities/data-entity.ts:36

make(input, metadata)

static make<T, M>(input, metadata?): DataEntity<T, M>

Type parameters
Type parameterValue
TRecord<string, any>
MRecord<string, any>
Parameters
ParameterType
inputRecord<string, any>
metadata?M
Returns

DataEntity<T, M>

Source

packages/utils/src/entities/data-entity.ts:40


makeArray()

static makeArray<T, M>(input): DataEntity<T, M>[]

A utility for safely converting an input of an object, or an array of objects, to an array of DataEntities. This will detect if passed an already converted input and return it.

Type parameters

Type parameterValue
TRecord<string, any>
MRecord<string, any>

Parameters

ParameterType
inputDataArrayInput

Returns

DataEntity<T, M>[]

Source

packages/utils/src/entities/data-entity.ts:64