v0.2.0 adding Promise & async/await support
Version 0.2.0 introduces a new way to call asynchronous methods on OPCUAClient and ClientSession objects
- node style async method with callback
- async method returning a Promise
see article
Promised version can be chained more easily. They can also be used with async/await on nodeJS > 8 or Typescript (with ES2015 support enabled)
💔 Breaking changes:
some breaking changes have been necessary to normalize all async function and make sure they only provide a single output value. As such, old code using ClientSession#read, #read #browse #readVariableValue #readHistoryValue #readAllAttributes will have to be fixed.
Each OPCUAClient ClientSession async methods comes in two forms:
- the first form allow multiple read/write/browse operation to be performed in a single operation.
example form1: reading many dataValue at once
var nodesToRead = [
{ nodeId: "ns=2;s=Furnace_1.Temperature",attributeId: AttributeIds.Value},
{ nodeId: "ns=2;s=Furnace_2.Temperature",attributeId: AttributeIds.Value}
];
session.read(nodesToRead,function(err,dataValues,diagnosticInfos) {
if (!err) {
dataValues.forEach(dataValue=>console.log(dataValue.toString()));
}
});
or with the Promise version:
session.read(nodesToRead).then(function(dataValues) {
//...
});
or with the async/await version (node >8)
const dataValues = async session.read(nodesToRead); // an Array
- the second form is used to read/write/browse a single element
example form2: reading a single node
var nodeToRead = {
nodeId: "ns=2;s=Furnace_1.Temperature",
attributeId: AttributeIds.BrowseName
};
session.read(nodeToRead,function(err,dataValue,diagnosticInfos) {
if (!err) {
console.log(dataValue.toString());
}
});
or with the Promise version:
session.read(nodeToRead).then(function(dataValue) {
//...
});
or with the async/await version (node >8)
const dataValue = async session.read(nodeToRead);
🆕 new features:
- updated typescript declaration file
- add new async method extension for node 8 & above (896b323)
- use thenify to provide Promise version of async methods (c18cdd4)
- [Breaking Change] fix ClientSession#read callback parameters allow ClientSession#read #browse #readVariableValue #readHistoryValue #readAllAttributes to handle a single element or an array of element.
#readAllAttributes now return json object with node attributes (649d0a8)
🐛 bug fixing
- #413 fix wrong assert (c1afc23)
- #416 fix certificate generation issue on MacOS and LibreSLL - use node-opcua-pki@0.0.29 (357823e)
- add sample images for server simulation (98a29cd)
- fix makeBrowsePath access (4f45ff3)
👬 contributors
- @bompi88 for adding support for LibreSSL node-opcua-pki