@widesky/hiswrite-builder
v1.0.1
Published
A utility class to create hisWrite payload structures suitable for consumption by WideSky tools.
Downloads
7
Readme
README
This is a historical payload builder for WideSky applications. It currently is compatible with:
@widesky/widesky-edge-history
- Incoming payloads for History Write node
@widesky/jswidesky-client
Example Usage
Payload for WideSkyClient
const HisWriteBuilder = require("@widesky/hiswrite-builder");
const testID1Number = "5653e415-120a-44b0-9ca4-b21c8221c973";
const testID1Str = "15d96301-f180-4301-a0a9-b9b37387e3f7";
const testID1Bool = "bd1712fe-ac22-4d5a-984e-25afae90282e";
const builder = new HisWriteBuilder();
builder.add(testID1Number, [
[Date.now(), 123],
[Date.now() - 1000, 456]
]);
builder.add(testID1Str, [
[Date.now(), "123"],
[Date.now() - 1000, "456"]
]);
builder.add(testID1Bool, [
[Date.now(), true],
[Date.now() - 1000, false]
]);
console.log(JSON.stringify(builder.toWsClient(), null, 2));
/*
Outputs:
{
"t:2024-07-18T07:55:51.853Z": {
"r:5653e415-120a-44b0-9ca4-b21c8221c973": "n:456",
"r:15d96301-f180-4301-a0a9-b9b37387e3f7": "s:456",
"r:bd1712fe-ac22-4d5a-984e-25afae90282e": false
},
"t:2024-07-18T07:55:52.853Z": {
"r:5653e415-120a-44b0-9ca4-b21c8221c973": "n:123",
"r:15d96301-f180-4301-a0a9-b9b37387e3f7": "s:123",
"r:bd1712fe-ac22-4d5a-984e-25afae90282e": true
}
}
*/
Payload for History Write Node
const HisWriteBuilder = require("@widesky/hiswrite-builder");
const testID2Number = "15d96301-f180-4301-a0a9-b9b37387e3f7";
const testID2Str = "3ec6e43c-796b-462e-83c0-a0cee7dd4a25";
const testID2Bool = "15c0b9c4-2389-4d3d-850a-becb9691025a";
const builder = new HisWriteBuilder();
builder.add(testID2Number, [
[Date.now(), 4444444],
[Date.now() - 1000, 43433]
]);
builder.add(testID2Str, [
[Date.now(), "asdasd"],
[Date.now() - 1000, "qweqweqe"]
]);
builder.add(testID2Bool, [
[Date.now(), false],
[Date.now() - 1000, true]
]);
console.log(JSON.stringify(builder.toHistoryWriteNode(), null, 2));
/*
Outputs:
[
{
"id": "15d96301-f180-4301-a0a9-b9b37387e3f7",
"timeSeries": {
"dataPoints": [
{
"time": 1721289351854,
"value": 43433
},
{
"time": 1721289352854,
"value": 4444444
}
]
}
},
{
"id": "3ec6e43c-796b-462e-83c0-a0cee7dd4a25",
"timeSeries": {
"dataPoints": [
{
"time": 1721289351854,
"value": "qweqweqe"
},
{
"time": 1721289352854,
"value": "asdasd"
}
]
}
},
{
"id": "15c0b9c4-2389-4d3d-850a-becb9691025a",
"timeSeries": {
"dataPoints": [
{
"time": 1721289351854,
"value": true
},
{
"time": 1721289352854,
"value": false
}
]
}
}
]
*/