Job Components: `Index Data Entity`
index.DataEntity
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
Name | Type |
---|---|
T | Record <string , any > |
M | _DataEntityMetadata <Record <string , any >> |
Indexable
▪ [prop: string
]: any
Table of contents
Constructors
Methods
- getCreateTime
- getEventTime
- getIngestTime
- getKey
- getMetadata
- getProcessTime
- getRawData
- setEventTime
- setIngestTime
- setKey
- setMetadata
- setProcessTime
- setRawData
- toBuffer
- [hasInstance]
- fork
- fromBuffer
- getMetadata
- isDataEntity
- isDataEntityArray
- make
- makeArray
Constructors
constructor
• new DataEntity<T
, M
>(data
, metadata?
): DataEntity
<T
, M
>
Type parameters
Name | Type |
---|---|
T | Record <string , any > |
M | _DataEntityMetadata <Record <string , any >> |
Parameters
Name | Type | ||
---|---|---|---|
data | undefined \ | null \ | T |
metadata? | M |
Returns
DataEntity
<T
, M
>
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:66
Methods
getCreateTime
▸ getCreateTime(): Date
Get the time at which this entity was created.
Returns
Date
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:90
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
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:125
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
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:97
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
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:81
getMetadata
▸ getMetadata(key?
): _DataEntityMetadata
<M
>
Get the metadata for the DataEntity. If a field is specified, it will get that property of the metadata
Parameters
Name | Type |
---|---|
key? | undefined |
Returns
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:71
▸ getMetadata<K
>(key
): EntityMetadataValue
<M
, K
>
Type parameters
Name | Type | ||
---|---|---|---|
K | extends string \ | number \ | symbol |
Parameters
Name | Type |
---|---|
key | K |
Returns
EntityMetadataValue
<M
, K
>
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:72
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
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:111
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
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:137
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
Name | Type | ||
---|---|---|---|
val? | string \ | number \ | Date |
Returns
void
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:132
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
Name | Type | ||
---|---|---|---|
val? | string \ | number \ | Date |
Returns
void
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:104
setKey
▸ setKey(key
): void
Set the unique document _key
from the metadata.
If no _key
is found, an error will be thrown
Parameters
Name | Type | |
---|---|---|
key | string \ | number |
Returns
void
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:86
setMetadata
▸ setMetadata<K
, V
>(field
, value
): void
Given a field and value set the metadata on the record
Type parameters
Name | Type | ||
---|---|---|---|
K | extends string \ | number \ | symbol |
V | V |
Parameters
Name | Type |
---|---|
field | K |
value | V |
Returns
void
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:76
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
Name | Type | ||
---|---|---|---|
val? | string \ | number \ | Date |
Returns
void
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:118
setRawData
▸ setRawData(buf
): void
Set the raw data, usually used for encoding type raw
If given null
, it will unset the data
Parameters
Name | Type | ||
---|---|---|---|
buf | null \ | string \ | Buffer |
Returns
void
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:142
toBuffer
▸ toBuffer(opConfig?
): Buffer
Convert the DataEntity to an encoded buffer
Parameters
Name | Type | Description |
---|---|---|
opConfig? | EncodingConfig | The operation config used to get the encoding type of the buffer, |
Returns
Buffer
Default
json
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:149
[hasInstance]
▸ [hasInstance](instance
): boolean
Parameters
Name | Type |
---|---|
instance | unknown |
Returns
boolean
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:63
fork
▸ 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
Name | Type |
---|---|
T | extends DataEntity <any , any > = DataEntity <Record <string , any >, _DataEntityMetadata <Record <string , any >>> |
Parameters
Name | Type |
---|---|
input | T |
withData? | boolean |
Returns
T
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:34
fromBuffer
▸ fromBuffer<T
, M
>(input
, opConfig?
, metadata?
): DataEntity
<T
, M
>
A utility for converting a Buffer
to a DataEntity
,
using the DataEntity encoding.
Type parameters
Name | Type |
---|---|
T | Record <string , any > |
M | Record <string , any > |
Parameters
Name | Type | Description | |
---|---|---|---|
input | string \ | Buffer | A Buffer to parse to JSON |
opConfig? | EncodingConfig | The operation config used to get the encoding type of the Buffer, defaults to "json" | |
metadata? | M | Optionally add any metadata |
Returns
DataEntity
<T
, M
>
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:44
getMetadata
▸ 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
Name | Type |
---|---|
V | any |
Parameters
Name | Type |
---|---|
input | unknown |
field? | string |
Returns
undefined
| V
Deprecated
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:62
isDataEntity
▸ isDataEntity<T
, M
>(input
): input is DataEntity<T, M>
Verify that an input is the DataEntity
Type parameters
Name | Type |
---|---|
T | Record <string , any > |
M | Record <string , any > |
Parameters
Name | Type |
---|---|
input | unknown |
Returns
input is DataEntity<T, M>
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:48
isDataEntityArray
▸ isDataEntityArray<T
, M
>(input
): input is DataEntity<T, M>[]
Verify that an input is an Array of DataEntities,
Type parameters
Name | Type |
---|---|
T | Record <string , any > |
M | Record <string , any > |
Parameters
Name | Type |
---|---|
input | unknown |
Returns
input is DataEntity<T, M>[]
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:52
make
▸ 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
Name | Type |
---|---|
T | extends DataEntity <any , any > |
M | Record <string , any > |
Parameters
Name | Type |
---|---|
input | T |
metadata? | M |
Returns
T
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:18
▸ make<T
, M
>(input
, metadata?
): DataEntity
<T
, M
>
Type parameters
Name | Type |
---|---|
T | Record <string , any > |
M | Record <string , any > |
Parameters
Name | Type |
---|---|
input | Record <string , any > |
metadata? | M |
Returns
DataEntity
<T
, M
>
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:19
makeArray
▸ 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
Name | Type |
---|---|
T | Record <string , any > |
M | Record <string , any > |
Parameters
Name | Type |
---|---|
input | DataArrayInput |
Returns
DataEntity
<T
, M
>[]
Defined in
packages/utils/dist/src/entities/data-entity.d.ts:25