Home Manual Reference Source

Datapoints

Initialization

Initialize a Datapoint, either empty, or with a type or format:

// An empty Datapoint
const dp1 = new Datapoint();

// A Datapoint with a type
const dp2 = new Datapoint('sample-type');

// A Datapoint with a type and format
const dp3 = new Datapoint('sample-type', 'string');

Set type and format fields in a Datapoint

const dp1 = new Datapoint();
dp1.setType('sample-type');
dp1.setFormat('string');

Set content

Content must match the Datapoint's format

// Set content as a JSON
const dp1 = new Datapoint();
dp1.setFormat('string');
dp1.setContent({ title: 'a_number', value: 'fifty-two' });

// Set content with a string value
const dp2 = new Datapoint();
dp2.setFormat('string');
dp2.setContent('fifty-two');

// Set content with a number value
const dp3 = new Datapoint();
dp3.setFormat('number');
dp3.setContent(52);

Set permissions

Standard permissions have GET, PUT, and DELETE parameters. They can be set at once or added one at a time.

// Set all permissions at once
const newPerms = {
    GET: ['bruce'],
    PUT: ['clark'],
    DELETE: ['diana']
};
const dp1 = new Datapoint();
dp1.setPermissions(newPerms);

// Add permissions one at a time
const dp2 = new Datapoint();
dp2.addPermission('GET', 'bruce');
dp2.addPermission('PUT', 'clark');
dp2.addPermission('DELETE', 'diana');

Custom permissions can take any format:

const dp1 = new Datapoint();
dp1.setCustomPermissions('my-custom-permissions');

Chain commands

You can chain functions for readability:

const dp1 = new Datapoint().setType('sample-type').setFormat('string').setContent('fifty-two');

Generate a Datapoint

The generate() function validates a Datapoint and returns its data.

const dp1 = new Datapoint('sample-type', 'string').setContent({ value: 'hello' });
dp1.addPermission('GET', 'bruce')
    .addPermission('PUT', 'clark')
    .addPermission('DELETE', 'diana');
dp1.setParent('DC52');

const mydata = dp1.generate();

TaskOutput

Initialization

Initialize a TaskOutput object:

const tout = new TaskOutput();

Add Datapoints

The type of content must match the Datapoint's format.

// Create a Datapoint
const dp1 = new Datapoint();
dp1.setFormat('string');
dp1.setContent({ title: 'a_number', value: 'fifty-two' });

// Add the Datapoint to the TaskOutput
const tout = new TaskOutput();
tout.addDatapoint(dp1);

Add notifications

const tout = new TaskOutput();
const nt1 = { value: 'hello' };
const nt2 = { value: 'world' };
tout.addNotification(nt1).addNotification(nt2);

Add assignments

const tout = new TaskOutput();
const as1 = { value: 'goodnight' };
const as2 = { value: 'moon' };
tout.addAssignment(as1).addAssignment(as2);

Generate a TaskOutput object

The generate() function validates a TaskOutput and returns its data.

// Sample Datapoint
const dp1 = new Datapoint('sample-type', 'string').setContent({ value: 'hello' });
dp1.addPermission('GET', 'bruce')
    .addPermission('PUT', 'clark')
    .addPermission('DELETE', 'diana');
dp1.setParent('DC52');

// Sample notifications
const nt1 = { value: 'hello' };
const nt2 = { value: 'world' };

// Sample assignments
const as1 = { value: 'goodnight' };
const as2 = { value: 'moon' };

// Add them all to a TaskOutput object. Note that commands can be chained for readibility and ease of use.
const tout = new TaskOutput();
// Datapoints can be added using either the Datapoint object or just the data
tout.addDatapoint(dp1).addDatapoint(dp1.data);
tout.addNotification(nt1).addNotification(nt2);
tout.addAssignment(as1).addAssignment(as2);

// Generate to validate fields and return the data
const myTaskOutput = tout.generate();