opcua-webapi-ts 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,16 +13,17 @@ exports.UaNodeLinkReader = exports.UaNodeChildReader = exports.UaNodeReader = ex
13
13
  const opcua_webapi_1 = require("opcua-webapi");
14
14
  const common_1 = require("../../common");
15
15
  class UaNodeReaderBase {
16
- constructor(returnVariables, returnMethod) {
16
+ constructor(returnDescription, returnVariables, returnMethod) {
17
17
  this._finished = false;
18
18
  this._nodesToBrowse = [];
19
19
  this._continuationPointToBrowse = [];
20
20
  this._browseResults = [];
21
21
  this._readResults = new Map;
22
+ this._returnDescription = returnDescription;
22
23
  this._nodeClassToReturn = 0;
23
- if (false != returnVariables)
24
+ if (returnVariables)
24
25
  this._nodeClassToReturn += opcua_webapi_1.NodeClass.Variable;
25
- if (false != returnMethod)
26
+ if (returnMethod)
26
27
  this._nodeClassToReturn += opcua_webapi_1.NodeClass.Method;
27
28
  if (null == UaNodeReaderBase.s_variableTypeWithoutMember) {
28
29
  UaNodeReaderBase.s_variableTypeWithoutMember = new Set;
@@ -193,16 +194,24 @@ class UaNodeReaderBase {
193
194
  return;
194
195
  let nodesToRead = [];
195
196
  for (let item of typesToRead) {
196
- let nodeToRead = new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.IsAbstract);
197
- nodesToRead.push(nodeToRead);
197
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.IsAbstract));
198
198
  if (item.nodeClass == opcua_webapi_1.NodeClass.VariableType) {
199
199
  nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.DataType));
200
200
  nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.ValueRank));
201
201
  }
202
+ if (this._returnDescription) {
203
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
204
+ }
202
205
  }
203
206
  let dataValues = yield client.read(nodesToRead);
204
207
  for (let i = 0; i < typesToRead.length; ++i) {
205
- let dataIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? i * 3 : i;
208
+ let dataIndex;
209
+ if (this._returnDescription) {
210
+ dataIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? i * 4 : i * 2;
211
+ }
212
+ else {
213
+ dataIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? i * 3 : i;
214
+ }
206
215
  if (dataValues[dataIndex].statusCode.isNotGood())
207
216
  throw new common_1.UaError(dataValues[dataIndex].statusCode);
208
217
  let isAbstract = dataValues[dataIndex].value.toBoolean();
@@ -233,6 +242,14 @@ class UaNodeReaderBase {
233
242
  else if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.ReferenceType) {
234
243
  typeNode = new common_1.UaReferenceType(typesToRead[i].nodeId, typesToRead[i].browseName, typesToRead[i].displayName, isAbstract, common_1.UaLocalizedText.nullText, false);
235
244
  }
245
+ if (this._returnDescription) {
246
+ let descriptionIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? dataIndex + 3 : dataIndex + 1;
247
+ if (dataValues[descriptionIndex].statusCode.isGood()) {
248
+ let descriptionValue = dataValues[descriptionIndex].value.toLocalizedText();
249
+ if (null != descriptionValue)
250
+ typeNode.description = descriptionValue;
251
+ }
252
+ }
236
253
  typeNode.refToParent = typesToRead[i].referenceTypeId;
237
254
  this._readResults.set(typeNode.nodeId.toString(), {
238
255
  parentId: typesToRead[i].fromNodeId,
@@ -253,18 +270,30 @@ class UaNodeReaderBase {
253
270
  return;
254
271
  let nodesToRead = [];
255
272
  for (let item of objectsToRead) {
256
- let nodeToRead = new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.EventNotifier);
257
- nodesToRead.push(nodeToRead);
273
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.EventNotifier));
274
+ if (this._returnDescription) {
275
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
276
+ }
258
277
  }
259
278
  let dataValues = yield client.read(nodesToRead);
260
279
  for (let i = 0; i < objectsToRead.length; ++i) {
261
- if (dataValues[i].statusCode.isNotGood())
262
- throw new common_1.UaError(dataValues[i].statusCode);
263
- let eventNotifier = dataValues[i].value.toNumber();
264
- if (null == eventNotifier || undefined == objectsToRead[i].typeDefinitionId)
280
+ if (!objectsToRead[i].typeDefinitionId)
265
281
  throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
282
+ let dataIndex = (this._returnDescription) ? i * 2 : i;
283
+ let eventNotifier = 0;
284
+ if (dataValues[dataIndex].statusCode.isGood()) {
285
+ eventNotifier = dataValues[dataIndex].value.toNumber();
286
+ }
266
287
  let objectNode = new common_1.UaObject(objectsToRead[i].nodeId, objectsToRead[i].browseName, objectsToRead[i].displayName, eventNotifier, objectsToRead[i].typeDefinitionId);
267
288
  objectNode.refToParent = objectsToRead[i].referenceTypeId;
289
+ if (this._returnDescription) {
290
+ let descriptionIndex = dataIndex + 1;
291
+ if (dataValues[descriptionIndex].statusCode.isGood()) {
292
+ let descriptionValue = dataValues[descriptionIndex].value.toLocalizedText();
293
+ if (null != descriptionValue)
294
+ objectNode.description = descriptionValue;
295
+ }
296
+ }
268
297
  this._readResults.set(objectNode.nodeId.toString(), {
269
298
  parentId: objectsToRead[i].fromNodeId,
270
299
  node: objectNode
@@ -348,8 +377,8 @@ exports.UaNodeReaderBase = UaNodeReaderBase;
348
377
  UaNodeReaderBase.s_variableTypeWithoutMember = null;
349
378
  UaNodeReaderBase.s_variableNameToReadValue = null;
350
379
  class UaNodeReader extends UaNodeReaderBase {
351
- constructor(nodeIds, returnVariables, returnMethod) {
352
- super(returnVariables, returnMethod);
380
+ constructor(nodeIds, returnDescription, returnVariables, returnMethod) {
381
+ super(returnDescription ? returnDescription : false, returnVariables ? returnVariables : false, returnMethod ? returnMethod : false);
353
382
  if (nodeIds.length == 0)
354
383
  this._finished = true;
355
384
  this._nodeIds = new Set;
@@ -473,8 +502,8 @@ class UaNodeReader extends UaNodeReaderBase {
473
502
  }
474
503
  exports.UaNodeReader = UaNodeReader;
475
504
  class UaNodeChildReader extends UaNodeReaderBase {
476
- constructor(nodeIds, returnVariables, returnMethod) {
477
- super(returnVariables, returnMethod);
505
+ constructor(nodeIds, returnDescription, returnVariables, returnMethod) {
506
+ super((returnDescription) ? returnDescription : false, (returnVariables) ? returnVariables : false, (returnMethod) ? returnMethod : false);
478
507
  if (nodeIds.length == 0)
479
508
  this._finished = true;
480
509
  this._nodeIds = new Set;
@@ -37,9 +37,10 @@ export declare abstract class UaNodeReaderBase {
37
37
  protected _browseResults: Array<BrowseResult>;
38
38
  protected _readResults: Map<string, ReadResult>;
39
39
  protected _nodeClassToReturn: number;
40
+ protected _returnDescription: boolean;
40
41
  private static s_variableTypeWithoutMember;
41
42
  private static s_variableNameToReadValue;
42
- constructor(returnVariables?: boolean | null, returnMethod?: boolean | null);
43
+ constructor(returnDescription: boolean, returnVariables: boolean, returnMethod: boolean);
43
44
  protected _browseNodes(client: UaWebClient): Promise<void>;
44
45
  protected _browseContinuationPoints(client: UaWebClient): Promise<void>;
45
46
  protected _readNodes(client: UaWebClient): Promise<void>;
@@ -53,7 +54,7 @@ export declare abstract class UaNodeReaderBase {
53
54
  export declare class UaNodeReader extends UaNodeReaderBase {
54
55
  private _nodeIds;
55
56
  private _isRootNodeRead;
56
- constructor(nodeIds: Array<UaNodeId>, returnVariables?: boolean | null, returnMethod?: boolean | null);
57
+ constructor(nodeIds: Array<UaNodeId>, returnDescription?: boolean | null, returnVariables?: boolean | null, returnMethod?: boolean | null);
57
58
  readAll(client: UaWebClient): Promise<void>;
58
59
  read(client: UaWebClient): Promise<void>;
59
60
  isFinish(): boolean;
@@ -62,7 +63,7 @@ export declare class UaNodeReader extends UaNodeReaderBase {
62
63
  }
63
64
  export declare class UaNodeChildReader extends UaNodeReaderBase {
64
65
  private _nodeIds;
65
- constructor(nodeIds: Array<UaNodeId>, returnVariables?: boolean | null, returnMethod?: boolean | null);
66
+ constructor(nodeIds: Array<UaNodeId>, returnDescription?: boolean | null, returnVariables?: boolean | null, returnMethod?: boolean | null);
66
67
  readAll(client: UaWebClient): Promise<void>;
67
68
  read(client: UaWebClient): Promise<void>;
68
69
  isFinish(): boolean;
@@ -13,16 +13,17 @@ exports.UaNodeLinkReader = exports.UaNodeChildReader = exports.UaNodeReader = ex
13
13
  const opcua_webapi_1 = require("opcua-webapi");
14
14
  const common_1 = require("../../common");
15
15
  class UaNodeReaderBase {
16
- constructor(returnVariables, returnMethod) {
16
+ constructor(returnDescription, returnVariables, returnMethod) {
17
17
  this._finished = false;
18
18
  this._nodesToBrowse = [];
19
19
  this._continuationPointToBrowse = [];
20
20
  this._browseResults = [];
21
21
  this._readResults = new Map;
22
+ this._returnDescription = returnDescription;
22
23
  this._nodeClassToReturn = 0;
23
- if (false != returnVariables)
24
+ if (returnVariables)
24
25
  this._nodeClassToReturn += opcua_webapi_1.NodeClass.Variable;
25
- if (false != returnMethod)
26
+ if (returnMethod)
26
27
  this._nodeClassToReturn += opcua_webapi_1.NodeClass.Method;
27
28
  if (null == UaNodeReaderBase.s_variableTypeWithoutMember) {
28
29
  UaNodeReaderBase.s_variableTypeWithoutMember = new Set;
@@ -193,16 +194,24 @@ class UaNodeReaderBase {
193
194
  return;
194
195
  let nodesToRead = [];
195
196
  for (let item of typesToRead) {
196
- let nodeToRead = new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.IsAbstract);
197
- nodesToRead.push(nodeToRead);
197
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.IsAbstract));
198
198
  if (item.nodeClass == opcua_webapi_1.NodeClass.VariableType) {
199
199
  nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.DataType));
200
200
  nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.ValueRank));
201
201
  }
202
+ if (this._returnDescription) {
203
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
204
+ }
202
205
  }
203
206
  let dataValues = yield client.read(nodesToRead);
204
207
  for (let i = 0; i < typesToRead.length; ++i) {
205
- let dataIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? i * 3 : i;
208
+ let dataIndex;
209
+ if (this._returnDescription) {
210
+ dataIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? i * 4 : i * 2;
211
+ }
212
+ else {
213
+ dataIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? i * 3 : i;
214
+ }
206
215
  if (dataValues[dataIndex].statusCode.isNotGood())
207
216
  throw new common_1.UaError(dataValues[dataIndex].statusCode);
208
217
  let isAbstract = dataValues[dataIndex].value.toBoolean();
@@ -233,6 +242,14 @@ class UaNodeReaderBase {
233
242
  else if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.ReferenceType) {
234
243
  typeNode = new common_1.UaReferenceType(typesToRead[i].nodeId, typesToRead[i].browseName, typesToRead[i].displayName, isAbstract, common_1.UaLocalizedText.nullText, false);
235
244
  }
245
+ if (this._returnDescription) {
246
+ let descriptionIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? dataIndex + 3 : dataIndex + 1;
247
+ if (dataValues[descriptionIndex].statusCode.isGood()) {
248
+ let descriptionValue = dataValues[descriptionIndex].value.toLocalizedText();
249
+ if (null != descriptionValue)
250
+ typeNode.description = descriptionValue;
251
+ }
252
+ }
236
253
  typeNode.refToParent = typesToRead[i].referenceTypeId;
237
254
  this._readResults.set(typeNode.nodeId.toString(), {
238
255
  parentId: typesToRead[i].fromNodeId,
@@ -253,18 +270,30 @@ class UaNodeReaderBase {
253
270
  return;
254
271
  let nodesToRead = [];
255
272
  for (let item of objectsToRead) {
256
- let nodeToRead = new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.EventNotifier);
257
- nodesToRead.push(nodeToRead);
273
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.EventNotifier));
274
+ if (this._returnDescription) {
275
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
276
+ }
258
277
  }
259
278
  let dataValues = yield client.read(nodesToRead);
260
279
  for (let i = 0; i < objectsToRead.length; ++i) {
261
- if (dataValues[i].statusCode.isNotGood())
262
- throw new common_1.UaError(dataValues[i].statusCode);
263
- let eventNotifier = dataValues[i].value.toNumber();
264
- if (null == eventNotifier || undefined == objectsToRead[i].typeDefinitionId)
280
+ if (!objectsToRead[i].typeDefinitionId)
265
281
  throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
282
+ let dataIndex = (this._returnDescription) ? i * 2 : i;
283
+ let eventNotifier = 0;
284
+ if (dataValues[dataIndex].statusCode.isGood()) {
285
+ eventNotifier = dataValues[dataIndex].value.toNumber();
286
+ }
266
287
  let objectNode = new common_1.UaObject(objectsToRead[i].nodeId, objectsToRead[i].browseName, objectsToRead[i].displayName, eventNotifier, objectsToRead[i].typeDefinitionId);
267
288
  objectNode.refToParent = objectsToRead[i].referenceTypeId;
289
+ if (this._returnDescription) {
290
+ let descriptionIndex = dataIndex + 1;
291
+ if (dataValues[descriptionIndex].statusCode.isGood()) {
292
+ let descriptionValue = dataValues[descriptionIndex].value.toLocalizedText();
293
+ if (null != descriptionValue)
294
+ objectNode.description = descriptionValue;
295
+ }
296
+ }
268
297
  this._readResults.set(objectNode.nodeId.toString(), {
269
298
  parentId: objectsToRead[i].fromNodeId,
270
299
  node: objectNode
@@ -348,8 +377,8 @@ exports.UaNodeReaderBase = UaNodeReaderBase;
348
377
  UaNodeReaderBase.s_variableTypeWithoutMember = null;
349
378
  UaNodeReaderBase.s_variableNameToReadValue = null;
350
379
  class UaNodeReader extends UaNodeReaderBase {
351
- constructor(nodeIds, returnVariables, returnMethod) {
352
- super(returnVariables, returnMethod);
380
+ constructor(nodeIds, returnDescription, returnVariables, returnMethod) {
381
+ super(returnDescription ? returnDescription : false, returnVariables ? returnVariables : false, returnMethod ? returnMethod : false);
353
382
  if (nodeIds.length == 0)
354
383
  this._finished = true;
355
384
  this._nodeIds = new Set;
@@ -473,8 +502,8 @@ class UaNodeReader extends UaNodeReaderBase {
473
502
  }
474
503
  exports.UaNodeReader = UaNodeReader;
475
504
  class UaNodeChildReader extends UaNodeReaderBase {
476
- constructor(nodeIds, returnVariables, returnMethod) {
477
- super(returnVariables, returnMethod);
505
+ constructor(nodeIds, returnDescription, returnVariables, returnMethod) {
506
+ super((returnDescription) ? returnDescription : false, (returnVariables) ? returnVariables : false, (returnMethod) ? returnMethod : false);
478
507
  if (nodeIds.length == 0)
479
508
  this._finished = true;
480
509
  this._nodeIds = new Set;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opcua-webapi-ts",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Provides OPC UA WebAPI wrapper and client based on opcua-webapi-typescript",
5
5
  "author": "DingYan",
6
6
  "main": "./dist/cjs/index.js",