Class: DatumRangeFinder

DatumRangeFinder

Class to find the available datum date range for a set of node datum URL helpers.

This is useful when generating reports or charts for a set of SolarNode datum streams, so the overall start/end dates can be determined before requesting the actual data. It returns an object starting and ending date related properties, for example:

{
  "timeZone":        "Pacific/Auckland",
  "sDate":           Date(1248668709972),
  "startDate":       "2009-07-27 16:25",
  "startDateMillis": 1248668709972,
  "eDate":           Date(1379824746781),
  "endDate":         "2013-09-22 16:39",
  "endDateMillis":   1379824746781
}

new DatumRangeFinder(urlHelpers [, authBuilder])

Constructor.

Parameters:
Name Type Argument Description
urlHelpers NodeDatumUrlHelper | Array.<NodeDatumUrlHelper>

the helper(s) to find the avaialble data range for

authBuilder AuthorizationV2Builder <optional>

the auth builder to authenticate requests with; if not provided then only public data can be queried; when provided a pre-signed key must be available

Examples
// the simple case, for just one SolarNode
const urlHelper = new NodeDatumUrlHelper();
urlHelper.publicQuery = true;
urlHelper.nodeId = 123;
urlHelper.sourceIds = ['a', 'b'];
const range = await new DatumRangeFinder(urlHelper).fetch();
// more complex case, for multiple SolarNode / source ID combinations
const urlHelper2 = new NodeDatumUrlHelper();
urlHelper2.publicQuery = true;
urlHelper2.nodeId = 234;
urlHelper2.sourceId = 'c';
const range2 = await new DatumRangeFinder([urlHelper, urlHelper2]).fetch();
// with authentication; note the authentication must be valid for all SolarNodes!
const auth = new AuthorizationV2Builder('my-token');
auth.saveSigningKey('secret');
urlHelper.publicQuery = false;
urlHelper2.publicQuery = false;
const range3 = await new DatumRangeFinder([urlHelper, urlHelper2], auth).fetch();

Extends

Members


<static, readonly> version :string

The class version.

Type:
  • string

<protected> authBuilder :AuthorizationV2Builder

An authorization builder to use to make authenticated HTTP requests.

Type:
  • AuthorizationV2Builder
Inherited From:

Methods


client( [value])

Get or set a JSON HTTP client function to use.

The function must be compatible with d3.json and defaults to that. This provides a way to integrate a different HTTP client if needed, for example a mock implementation in tests.

Parameters:
Name Type Argument Description
value function <optional>

the JSON client function, compatible with d3.json

Inherited From:
Returns:

when used as a getter, the JSON client function, otherwise this object

Type
function | DatumSourceFinder

fetch()

Asynchronously load the data.

This method calls JsonClientSupport#load to perform the actual work.

Inherited From:
Returns:

the result promise

Type
Promise.<*>

load(callback)

Asynchronously find the available datum range using a callback.

Parameters:
Name Type Description
callback DatumRangeFinder~dataCallback

the callback function to invoke

Overrides:
Returns:
Type
void

Type Definitions


dataCallback( [error], data)

The data callback function.

Parameters:
Name Type Argument Description
error Error <optional>

an error if a failure occurred

data DatumRange

the result data