A Nodejs library for interfacing with Databox APIs.
To use this library in your node project, run:
npm install --save node-databox
and then within your project:
const databox = require('node-databox');
⚠️ While this library is at 0.X.X the API may change.
Examples of usage are provided in the ./samples directory.
Returns An object containing the HTTPS credentials to pass to https.createServer when offering an https server. These are read form /run/secrets/DATABOX.pem and are generated by the container-manger at run time.
Name | Type | Description |
---|---|---|
href | String |
The store or datasource href |
status | String |
The status to wait for (e.g. 'active' or 'standby') |
maxRetries | Number |
Optional number of times to retry before timing out (default 10) |
Returns A Promise
that resolves when a store status matches status
or rejects with an error.
Returns A Promise
that resolves with a JSON object of root catalog or rejects with an error.
Parameters
Name | Type | Description |
---|---|---|
href | String |
The store or datasource href |
Returns A Promise
that resolves with a JSON object of a store catalog or rejects with an error.
A convenience function for listing available stores.
Returns A Promise
that resolves with an array of objects with a store description
, hostname
, and href
, or rejects with an error
Returns A Promise
that resolves with a JSON array of all store catalogs the calling container has access to or rejects with an error
Parameters
Name | Type | Description |
---|---|---|
callback | Function |
A function to map onto each store catalog |
thisArg | Object |
The value of this in the context of the callback function |
Returns A Promise
that resolves with an array of return values of the callback called on each catalog or rejects with an error
Parameters
Name | Type | Description |
---|---|---|
href | String |
The store or datasource href |
metadata | Object |
Dataource metadata |
Example
catalog.registerDatasource('https://some-store:8080', {
description: 'Test item',
contentType: 'text/plain',
vendor: 'Databox Inc.',
tyoe: 'Test',
datasourceid: 'MyLongId',
storeType: 'databox-store-blob',
// Optional
isActuator: false,
// Optional
unit: 'cm',
// Optional
location: 'kitchen'
});
Returns A Promise
that resolves or rejects with an error
Reads the latest entry from a given time series datasource
Parameters
Name | Type | Description |
---|---|---|
href | String |
The target datasource href |
Returns A Promise
that resolves with the latest entry for this timeseries datasource or rejects with an error
⚠️ Deprecated
Reads the latest entry from a given time series store
Parameters
Name | Type | Description |
---|---|---|
href | String |
The target store href |
dataSourceID | String |
The target datasource ID |
Returns A Promise
that resolves with the latest entry for this timeseries data store endpoint or rejects with an error
Reads since a given range from a given time series datasource
Parameters
Name | Type | Description |
---|---|---|
href | String |
The target datasource href |
startTimestamp | Number |
The timestamp from which to query time series data (inclusive) |
Returns A Promise
that resolves with an array of data for this timeseries datasource or rejects with an error
⚠️ Deprecated
Reads since a given range from a given time series store
Parameters
Name | Type | Description |
---|---|---|
href | String |
The target store href |
dataSourceID | String |
The target datasource ID |
startTimestamp | Number |
The timestamp from which to query time series data (inclusive) |
Returns A Promise
that resolves with an array of data for this timeseries data store endpoint or rejects with an error
Reads in given range from a given time series datasource
Parameters
Name | Type | Description |
---|---|---|
href | String |
The target datasource href |
startTimestamp | Number |
The timestamp from which to query time series data (inclusive) |
endTimestamp | Number |
The timestamp to which to query time series data (inclusive) |
Returns A Promise
that resolves with an array of data for this timeseries datasource or rejects with an error
⚠️ Deprecated
Reads in given range from a given time series store
Parameters
Name | Type | Description |
---|---|---|
href | String |
The target store href |
dataSourceID | String |
The target datasource ID |
startTimestamp | Number |
The timestamp from which to query time series data (inclusive) |
endTimestamp | Number |
The timestamp to which to query time series data (inclusive) |
Returns A Promise
that resolves with an array of data for this timeseries data store endpoint or rejects with an error
Writes to a given time series datasource
Parameters
Name | Type | Description |
---|---|---|
href | String |
The target datasource href |
data | Object |
An object to write to a datasource time series |
Returns A Promise
that resolves with the document written to the store (including automatically added timestamp) or rejects with an error
⚠️ Deprecated
Writes to a given time series store
Parameters
Name | Type | Description |
---|---|---|
href | String |
The target store href |
dataSourceID | String |
The target datasource ID |
data | Object |
An object to write to a datasource time series |
Returns A Promise
that resolves with the document written to the store (including automatically added timestamp) or rejects with an error
Reads from a given key-value datasource
Parameters
Name | Type | Description |
---|---|---|
href | String |
The target datasource href |
Returns A Promise
that resolves with the document at this endpoint or rejects with an error
⚠️ Deprecated
Reads from a given key-value store
Parameters
Name | Type | Description |
---|---|---|
href | String |
The target store href |
key | String |
The target key |
Returns A Promise
that resolves with the document at this endpoint or rejects with an error
Writes to a given key-value datasource
Parameters
Name | Type | Description |
---|---|---|
href | String |
The target datasource href |
data | Object |
The value to write |
Returns A Promise
that resolves with the document written to the store or rejects with an error
⚠️ Deprecated
Writes to a given key-value store
Parameters
Name | Type | Description |
---|---|---|
href | String |
The target store href |
key | String |
The target key |
data | Object |
The value to write |
Returns A Promise
that resolves with the document written to the store or rejects with an error
Connects to a target store's notification service
Parameters
Name | Type | Description |
---|---|---|
href | String |
The target store or datasource href |
Returns A Promise
that resolves with an EventEmitter
that emits open
when the notification stream is opened, and data
with store write event notifications of data for every route the connecting container is subscribed to. The callback function for that event has three parameters: hostname
(the source store), datasourceID
(the triggering datasource), and data
which is the data actually written to the store. Otherwise if there's an error setting up the connection, the Promise
rejects with an error.
Subscribes the caller to write notifications for a given route
Parameters
Name | Type | Description |
---|---|---|
href | String |
The target datasource href |
type | String |
"ts" for time series stores or "kv" for key-value stores |
Returns A Promise
that resolves silently if the subscription was a success or rejects with an error
⚠️ Deprecated
Subscribes the caller to write notifications for a given route
Parameters
Name | Type | Description |
---|---|---|
href | String |
The target store href |
dataSourceID | String |
The target datasource ID |
type | String |
"ts" for time series stores or "kv" for key-value stores |
Returns A Promise
that resolves silently if the subscription was a success or rejects with an error
Unsubscribes the caller to write notifications for a given route
Parameters
Name | Type | Description |
---|---|---|
href | String |
The target datasource href |
type | String |
"ts" for time series stores or "kv" for key-value stores |
Returns A Promise
that resolves silently if the unsubscription was a success or rejects with an error
⚠️ Deprecated
Unsubscribes the caller to write notifications for a given route
Parameters
Name | Type | Description |
---|---|---|
href | String |
The target store href |
dataSourceID | String |
The target datasource ID |
type | String |
"ts" for time series stores or "kv" for key-value stores |
Returns A Promise
that resolves silently if the unsubscription was a success or rejects with an error
Exports data and retrieves response via long polling
Parameters
Name | Type | Description |
---|---|---|
destination | String |
An HTTPS URL to the export destination |
payload | Object |
Data to POST to destination |
Returns A Promise
that resolves with the destination server's response or rejects with an error
⚠️ Currently unimplemented
Pushes data to an export queue and retrieves response via polling
Parameters
Name | Type | Description |
---|---|---|
destination | String |
An HTTPS URL to the export destination |
payload | Object |
Data to POST to destination |
Returns A Promise
that resolves with the destination server's response or rejects with an error