Class: DatumLoader

DatumLoader

Load data for a set of source IDs, date range, and aggregate level using either the listDatumUrl() or datumReadingUrl() URLs of NodeDatumUrlHelperMixin (the /datum/list or /datum/reading endpoints).

This object is designed to be used once per query. After creating the object and configuring an asynchronous callback function with DatumLoader#callback, call DatumLoader#load to start loading the data. The callback function will be called once all data has been loaded. The callback function can also be passed as an argument to the DatumLoader#load method directly.


new DatumLoader(urlHelper, filter [, authBuilder])

Constructor.

Parameters:
Name Type Argument Description
urlHelper NodeDatumUrlHelperMixin

a URL helper for accessing node datum via SolarQuery

filter DatumFilter

the filter parameters to use

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

Version:
  • 1.2.0
Implements:
Example
const filter = new DatumFilter();
filter.nodeId = 123;
// configure other filter settings here...

const urlHelper = new NodeDatumUrlHelper();

new DatumLoader(urlHelper, filter).load((error, results) => {
  // results is an array of Datum objects
});

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:

filter :DatumFilter

Type:
  • DatumFilter

urlHelper :NodeDatumUrlHelper

Type:
  • NodeDatumUrlHelper

Methods


callback( [value])

Get or set the callback function, invoked after all data has been loaded. The callback function will be passed two arguments: an error and the results. In incremental mode, the callback will also be passed a boolean that will be true on that last page of data, and a Pagination that details which page the callback represents.

Parameters:
Name Type Argument Description
value DatumLoader~dataCallback <optional>

the callback function to use

Returns:

when used as a getter, the current callback function, otherwise this object

Type
DatumLoader~dataCallback | DatumLoader

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

concurrency( [value])

Get or set the concurrency limit to use for parallel requests.

By default requests are not made in parallel (this property is configured as 0). Change to a positive number to enable parallel query mode.

When parallel mode is enabled the loader will make one request that includes the total result count and first page of results, followed by parallel requests for any remaining pages based on that total result count and configured page size.

Parameters:
Name Type Argument Description
value number <optional>

the concurrency level to use, or Infinity for no limit

Since:
  • 1.1.0
Returns:

when used as a getter, the current concurrency value, otherwise this object

Type
number | DatumLoader

fetch()

Asynchronously load the data.

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

Inherited From:
Returns:

the result promise

Type
Promise.<*>

includeTotalResultsCount( [value])

Get or set the flag for requesting the total results count.

By default the datum loader will not request the overal total result count when querying for data, as this speeds up queries. By setting this to true the total result count will be requested on the first query page.

Parameters:
Name Type Argument Description
value boolean <optional>

the flag to include total results count

Returns:

when used a a getter, the total results count inclusion mode; otherwise this object

Type
boolean | DatumLoader

incremental( [value])

Get or set incremental mode for loading the data.

When incremental mode is enabled (set to true) then the callback function will be invoked for each result page that is loaded. The function will be passed a second boolean argument that will be set to true only on the last page of result data, and a third Pagination` object argument that details the starting offset of the page.

When incremental mode is disabled (set to false, the default) then all result pages are combined into a single array and the callback will be invoked just once.

Parameters:
Name Type Argument Description
value boolean <optional>

the incremental mode to set

Returns:

when used a a getter, the incremental mode; otherwise this object

Type
boolean | DatumLoader

load( [callback])

Initiate loading the data.

As an alternative to configuring the callback function via the DatumLoader#callback method,a callback function can be passed as an argument to this function. That allows this function to be passed to things like queue.defer, for example.

Parameters:
Name Type Argument Description
callback DatumLoader~dataCallback <optional>

a callback function to use; either this argument must be provided or the function must have already been configured via DatumLoader#callback

Overrides:
Implements:
Returns:

this object

Type
DatumLoader

paginationSize( [value])

Get or set the result pagination size.

Parameters:
Name Type Argument Description
value number <optional>

the pagination size to set; defaults to 1000

Returns:

when used as a getter, the pagination size; otherwise this object

Type
number | DatumLoader

parameters( [value])

Get or set additional URL parameters. The parameters are set as object properties. If a property value is an array, multiple parameters for that property will be added.

Parameters:
Name Type Argument Description
value object <optional>

the URL parameters to include with the JSON request

Returns:

when used as a getter, the URL parameters, otherwise this object

Type
object | DatumLoader

readings( [value])

Get or set readings mode for loading the data.

When readings mode is enabled (set to true) then the /datum/reading endpoint will be invoked to load data.

When readings mode is disabled (set to false, the default) then the /datum/list endpoint will be invoked to load data.

Parameters:
Name Type Argument Description
value boolean <optional>

the readings mode to set

Returns:

when used a a getter, the readings mode; otherwise this object

Type
boolean | DatumLoader

Type Definitions


dataCallback( [error], data [, done] [, page])

The data callback function.

Parameters:
Name Type Argument Description
error Error <optional>

an error if a failure occurred

data Array.<Datum>

the result data

done boolean <optional>

in incremental mode, will be true when invoked on the last page of data

page Pagination <optional>

in incremental mode, the page associated with the data