Class: DatumStreamMetadataRegistry

util~ DatumStreamMetadataRegistry

A registry of datum stream metadata instances for object (node or location) and source ID combinations.

This registry acts like a map of (stream ID) -> metadata as well as (object ID, source ID) -> metadata.


new DatumStreamMetadataRegistry( [metas])

Constructor.

Parameters:
Name Type Argument Description
metas Array.<DatumStreamMetadata> <optional>

optional list of metadata to start with

Methods


<static> fromJsonEncoding(json)

Parse a JSON string into a DatumStreamMetadataRegistry instance.

The JSON must be encoded the same way DatumStreamMetadataRegistry#toJsonEncoding() does.

Parameters:
Name Type Description
json string

the JSON to parse

Returns:

the stream metadata registry instance

Type
module:util~DatumStreamMetadataRegistry

<static> fromJsonObject(data)

Create a registry instance from an array parsed from a JSON string of datum stream metadata objects.

The array must be structured in the same way DatumStreamMetadataRegistry#toJsonEncoding() does.

Parameters:
Name Type Description
data array

the array data to parse

Returns:

the stream metadata registry instance

Type
module:util~DatumStreamMetadataRegistry

addMetadata(meta)

Add metadata to the registry.

Parameters:
Name Type Description
meta DatumStreamMetadata

the metadata to add to the registry

Returns:

this object

Type
DatumStreamMetadata

indexOfMetadataStreamId(streamId)

Get the index of the metadata with a specific stream ID.

Parameters:
Name Type Description
streamId string

the stream ID to get the index of

Returns:

the found index, or -1 if not found

Type
number

metadataAt(index)

Get the metadata at a specific index, based on insertion order.

Parameters:
Name Type Description
index number

the index of the metadata to get

Returns:

the metadata at the given index, or undefined

Type
DatumStreamMetadata

metadataForObjectSource(objectId, sourceId)

Get the first available metadata for a given object and source ID combination.

Parameters:
Name Type Description
objectId number

the object ID of the metadata to get

sourceId string

the source ID of the metadata to get

Returns:

the associated metadata, or undefined if none available

Type
DatumStreamMetadata

metadataForStreamId(streamId)

Get the metadta for a given stream ID.

Parameters:
Name Type Description
streamId string

the stream ID of the metadata to get

Returns:

the associated metadata, or undefined if none available

Type
DatumStreamMetadata

metadataStreamIds()

Get a set of all available stream IDs.

Returns:

all available metadata stream ID values

Type
Set.<string>

metadataStreamIdsList()

Get a list of all available stream IDs in insertion order.

Returns:

all available metadata stream ID values in the same order as added to this registry

Type
Array.<string>

toJsonEncoding()

Get this object as a standard JSON encoded string value.

The returned JSON is an array of the DatumStreamMetadata#toJsonEncoding() result of all metadata in the registry. An example result looks like this:

[
    {
      "streamId": "7714f762-2361-4ec2-98ab-7e96807b32a6",
      "zone": "Pacific/Auckland",
      "kind": "n",
      "objectId": 123,
      "sourceId": "/power/1",
      "i": ["watts", "current",  "voltage", "frequency"],
      "a": ["wattHours"]
    },
    {
      "streamId": "5514f762-2361-4ec2-98ab-7e96807b3255",
      "zone": "America/New_York",
      "kind": "n",
      "objectId": 456,
      "sourceId": "/irradiance/2",
      "i": ["irradiance", "temperature"],
      "a": ["irradianceHours"]
    }
]
Returns:

the JSON encoded string

Type
string