opcua-webapi-ts 1.1.6 → 1.1.7

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.
@@ -12,27 +12,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.UaDataTypeDictionary = void 0;
13
13
  const opcua_webapi_1 = require("opcua-webapi");
14
14
  const common_1 = require("../../common");
15
+ const __1 = require("../..");
15
16
  class UaDataTypeDictionary {
16
- constructor() {
17
- if (null == UaDataTypeDictionary._abstractDataTypeIds) {
18
- UaDataTypeDictionary._abstractDataTypeIds = new Set;
19
- UaDataTypeDictionary._abstractDataTypeIds.add(common_1.DataTypeIds.BaseDataType);
20
- UaDataTypeDictionary._abstractDataTypeIds.add(common_1.DataTypeIds.Number);
21
- UaDataTypeDictionary._abstractDataTypeIds.add(common_1.DataTypeIds.Structure);
22
- UaDataTypeDictionary._abstractDataTypeIds.add(common_1.DataTypeIds.Integer);
23
- UaDataTypeDictionary._abstractDataTypeIds.add(common_1.DataTypeIds.UInteger);
24
- UaDataTypeDictionary._abstractDataTypeIds.add(common_1.DataTypeIds.Enumeration);
25
- }
17
+ constructor(simpleMode) {
26
18
  this._dataTypes = new Map;
19
+ this._returnAllAttributes = (null == simpleMode) ? false : !simpleMode;
27
20
  let baseDataTypeId = new common_1.UaNodeId(common_1.DataTypeIds.BaseDataType);
28
21
  this._dataTypes.set(baseDataTypeId.toString(), new common_1.UaDataType(baseDataTypeId, "BaseDataType", new common_1.UaLocalizedText("BaseDataType"), true));
29
- this._remainingNodesToBrowse = [new common_1.UaNodeId(common_1.DataTypeIds.BaseDataType)];
30
- this._remainingEnumerationToRead = [];
31
22
  }
32
23
  read(client) {
33
24
  return __awaiter(this, void 0, void 0, function* () {
34
- yield this.__browseDataTypes(client);
35
- yield this.__readEnumValues(client);
25
+ let browser = new __1.UaChildBrowser([common_1.UaNodeId.from(common_1.DataTypeIds.BaseDataType)]);
26
+ yield this._read(browser, client);
36
27
  });
37
28
  }
38
29
  getDataType(nodeId) {
@@ -42,89 +33,46 @@ class UaDataTypeDictionary {
42
33
  getDataTypes() {
43
34
  return [...this._dataTypes.values()];
44
35
  }
45
- __browseDataTypes(client) {
36
+ _read(browser, client) {
46
37
  return __awaiter(this, void 0, void 0, function* () {
47
- if (0 == this._remainingNodesToBrowse.length)
48
- return;
49
- let nodeIds = this._remainingNodesToBrowse.splice(0, 15);
50
- let nodesToBrowse = [];
51
- for (let item of nodeIds) {
52
- let browseDescription = new common_1.UaBrowseDescription(item, opcua_webapi_1.BrowseDirection.Forward, new common_1.UaNodeId(common_1.ReferenceTypeIds.HasSubtype), false, opcua_webapi_1.NodeClass.DataType, 31);
53
- nodesToBrowse.push(browseDescription);
38
+ // Browse child type
39
+ yield browser.browse(client);
40
+ let results = browser.results();
41
+ let referencesToRead = [];
42
+ let needToReadEnumValue = false;
43
+ for (let item of results) {
44
+ for (let reference of item.references)
45
+ referencesToRead.push(reference);
46
+ if (item.nodeId.equal(common_1.UaNodeId.from(common_1.DataTypeIds.Enumeration)))
47
+ needToReadEnumValue = true;
54
48
  }
55
- let results = yield client.browse(nodesToBrowse);
56
- for (let i = 0; i < nodeIds.length; ++i) {
57
- if (results[i].statusCode.isNotGood())
58
- continue;
59
- let parentType = this._dataTypes.get(nodeIds[i].toString());
60
- for (let item of results[i].references) {
61
- let dataTypeId = item.nodeId.getNodeId();
62
- if (null == dataTypeId ||
63
- opcua_webapi_1.NodeClass.DataType != item.nodeClass ||
64
- !item.browseName || !item.displayName)
65
- continue;
66
- let isAbstract = false;
67
- if (dataTypeId.nsIndex == 0 &&
68
- UaDataTypeDictionary._abstractDataTypeIds.has(dataTypeId.numericId()))
69
- isAbstract = true;
70
- let dataType = new common_1.UaDataType(dataTypeId, item.browseName, item.displayName, isAbstract);
71
- this._dataTypes.set(dataTypeId.toString(), dataType);
72
- this._remainingNodesToBrowse.push(dataTypeId);
73
- if (parentType)
74
- dataType.setParentType(parentType);
75
- dataType.classify();
76
- if (common_1.DataTypeIds.Enumeration == dataType.valueType) {
77
- this._remainingEnumerationToRead.push(dataType.nodeId);
78
- }
79
- }
80
- }
81
- if (this._remainingNodesToBrowse.length != 0) {
82
- yield this.__delay(20);
83
- yield this.__browseDataTypes(client);
84
- }
85
- });
86
- }
87
- __readEnumValues(client) {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- if (this._remainingEnumerationToRead.length == 0)
49
+ if (0 == referencesToRead.length)
90
50
  return;
91
- let nodeIds = this._remainingEnumerationToRead.splice(0, 20);
92
- let nodesToBrowse = [];
93
- for (let item of nodeIds) {
94
- let browseDescription = new common_1.UaBrowseDescription(item, opcua_webapi_1.BrowseDirection.Forward, new common_1.UaNodeId(common_1.ReferenceTypeIds.HasProperty), false, opcua_webapi_1.NodeClass.Variable, 8);
95
- nodesToBrowse.push(browseDescription);
96
- }
97
- let results = yield client.browse(nodesToBrowse);
98
- let enumDataTypeIds = [];
99
- let enumValueIds = [];
100
- for (let i = 0; i < nodeIds.length; ++i) {
101
- if (results[i].statusCode.isNotGood() ||
102
- results[i].references.length == 0)
51
+ // Read child type
52
+ let nodeIdsToBrowse = [];
53
+ let nodeReader = new __1.UaNodeReader(this._returnAllAttributes, needToReadEnumValue, false, this._returnAllAttributes);
54
+ let nodes = yield nodeReader.readByReferences(referencesToRead, client);
55
+ for (let node of nodes) {
56
+ if (opcua_webapi_1.NodeClass.DataType != node.nodeClass)
103
57
  continue;
104
- if (results[i].references[0].browseName == "EnumStrings" || results[i].references[0].browseName == "EnumValues") {
105
- let enumValueId = results[i].references[0].nodeId.getNodeId();
106
- if (enumValueId) {
107
- enumDataTypeIds.push(nodeIds[i]);
108
- enumValueIds.push(enumValueId);
109
- }
110
- }
58
+ nodeIdsToBrowse.push(node.nodeId);
59
+ this._dataTypes.set(node.nodeId.toString(), node);
111
60
  }
112
- if (enumDataTypeIds.length != 0) {
113
- let values = yield client.readValues(enumValueIds);
114
- for (let i = 0; i < enumValueIds.length; ++i) {
115
- if (values[i].statusCode.isNotGood() ||
116
- values[i].value.arrayType != common_1.UaArrayType.Array)
117
- continue;
118
- let dataType = this._dataTypes.get(enumDataTypeIds[i].toString());
119
- if (!dataType)
120
- continue;
121
- dataType.setEnumValues(values[i].value);
61
+ // Build parent-child relationship
62
+ for (let item of results) {
63
+ let parentType = this._dataTypes.get(item.nodeId.toString());
64
+ for (let reference of item.references) {
65
+ let dataType = this._dataTypes.get(reference.nodeId.toString());
66
+ if (dataType && parentType)
67
+ dataType.setParentType(parentType);
122
68
  }
123
69
  }
124
- if (this._remainingEnumerationToRead.length != 0) {
125
- yield this.__delay(20);
126
- yield this.__readEnumValues(client);
127
- }
70
+ if (0 == nodeIdsToBrowse.length)
71
+ return;
72
+ yield this.__delay(20);
73
+ // Continue to browse and read child type
74
+ let childBrowser = new __1.UaChildBrowser(nodeIdsToBrowse);
75
+ yield this._read(childBrowser, client);
128
76
  });
129
77
  }
130
78
  __delay(ms) {
@@ -134,4 +82,3 @@ class UaDataTypeDictionary {
134
82
  }
135
83
  }
136
84
  exports.UaDataTypeDictionary = UaDataTypeDictionary;
137
- UaDataTypeDictionary._abstractDataTypeIds = null;
@@ -358,6 +358,7 @@ class UaNodeReader {
358
358
  _readTypes(references, nodes, client) {
359
359
  return __awaiter(this, void 0, void 0, function* () {
360
360
  let typesToRead = [];
361
+ let needReadAttributes = this._returnAttributes || this._returnDescription;
361
362
  for (let item of references) {
362
363
  if (item.nodeClass != opcua_webapi_1.NodeClass.ObjectType &&
363
364
  item.nodeClass != opcua_webapi_1.NodeClass.DataType &&
@@ -368,44 +369,50 @@ class UaNodeReader {
368
369
  }
369
370
  if (0 == typesToRead.length)
370
371
  return;
371
- let nodesToRead = [];
372
- for (let item of typesToRead) {
373
- nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.IsAbstract));
374
- nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
375
- if (item.nodeClass == opcua_webapi_1.NodeClass.VariableType) {
376
- nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.DataType));
377
- nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.ValueRank));
372
+ let dataValues = [];
373
+ if (needReadAttributes) {
374
+ let nodesToRead = [];
375
+ for (let item of typesToRead) {
376
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.IsAbstract));
377
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
378
+ if (item.nodeClass == opcua_webapi_1.NodeClass.VariableType) {
379
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.DataType));
380
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.ValueRank));
381
+ }
378
382
  }
383
+ dataValues = yield client.read(nodesToRead);
379
384
  }
380
- let dataValues = yield client.read(nodesToRead);
381
385
  for (let i = 0; i < typesToRead.length; ++i) {
382
- let dataIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? i * 4 : i * 2;
383
- if (dataValues[dataIndex].statusCode.isNotGood())
384
- throw new common_1.UaError(dataValues[dataIndex].statusCode);
385
- let isAbstract = dataValues[dataIndex].value.toBoolean();
386
- if (null == isAbstract)
387
- throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
388
- dataIndex++;
386
+ let isAbstract = false;
389
387
  let description = undefined;
390
- if (this._returnDescription && dataValues[dataIndex].statusCode.isGood()) {
391
- description = dataValues[dataIndex].value.toLocalizedText();
392
- if (null == description)
393
- description = undefined;
394
- }
395
- dataIndex++;
396
388
  let dataType = common_1.UaNodeId.nullNodeId;
397
389
  let valueRank = -1;
398
- if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) {
390
+ if (needReadAttributes) {
391
+ let dataIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? i * 4 : i * 2;
399
392
  if (dataValues[dataIndex].statusCode.isNotGood())
400
393
  throw new common_1.UaError(dataValues[dataIndex].statusCode);
401
- dataType = dataValues[dataIndex].value.toNodeId();
394
+ isAbstract = dataValues[dataIndex].value.toBoolean();
395
+ if (null == isAbstract)
396
+ throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
402
397
  dataIndex++;
403
- if (dataValues[dataIndex].statusCode.isNotGood())
404
- throw new common_1.UaError(dataValues[dataIndex].statusCode);
405
- valueRank = dataValues[dataIndex].value.toNumber();
398
+ if (this._returnDescription && dataValues[dataIndex].statusCode.isGood()) {
399
+ description = dataValues[dataIndex].value.toLocalizedText();
400
+ if (null == description)
401
+ description = undefined;
402
+ }
406
403
  dataIndex++;
407
- if (null == dataType || null == valueRank)
408
- throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
404
+ if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) {
405
+ if (dataValues[dataIndex].statusCode.isNotGood())
406
+ throw new common_1.UaError(dataValues[dataIndex].statusCode);
407
+ dataType = dataValues[dataIndex].value.toNodeId();
408
+ dataIndex++;
409
+ if (dataValues[dataIndex].statusCode.isNotGood())
410
+ throw new common_1.UaError(dataValues[dataIndex].statusCode);
411
+ valueRank = dataValues[dataIndex].value.toNumber();
412
+ dataIndex++;
413
+ if (null == dataType || null == valueRank)
414
+ throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
415
+ }
409
416
  }
410
417
  let typeNode;
411
418
  if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.ObjectType) {
@@ -12,16 +12,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.UaObjectTypeDictionary = void 0;
13
13
  const opcua_webapi_1 = require("opcua-webapi");
14
14
  const common_1 = require("../../common");
15
+ const UaNodeReader_1 = require("./UaNodeReader");
15
16
  class UaObjectTypeDictionary {
16
- constructor() {
17
+ constructor(simpleMode) {
17
18
  this._objectTypes = new Map;
18
- let baseObjectTypeId = new common_1.UaNodeId(common_1.ObjectTypeIds.BaseObjectType);
19
+ this._returnAllAttributes = (null == simpleMode) ? false : !simpleMode;
20
+ let baseObjectTypeId = common_1.UaNodeId.from(common_1.ObjectTypeIds.BaseObjectType);
19
21
  this._objectTypes.set(baseObjectTypeId.toString(), new common_1.UaObjectType(baseObjectTypeId, "BaseObjectType", new common_1.UaLocalizedText("BaseObjectType"), false));
20
- this._remainingNodesToBrowse = [baseObjectTypeId];
21
22
  }
22
23
  read(client) {
23
24
  return __awaiter(this, void 0, void 0, function* () {
24
- yield this.__browseObjectTypes(client);
25
+ let browser = new UaNodeReader_1.UaChildBrowser([common_1.UaNodeId.from(common_1.ObjectTypeIds.BaseObjectType)]);
26
+ yield this._read(browser, client);
25
27
  });
26
28
  }
27
29
  getObjectType(nodeId) {
@@ -31,37 +33,43 @@ class UaObjectTypeDictionary {
31
33
  getObjectTypes() {
32
34
  return [...this._objectTypes.values()];
33
35
  }
34
- __browseObjectTypes(client) {
36
+ _read(browser, client) {
35
37
  return __awaiter(this, void 0, void 0, function* () {
36
- if (0 == this._remainingNodesToBrowse.length)
37
- return;
38
- let nodeIds = this._remainingNodesToBrowse.splice(0, 15);
39
- let nodesToBrowse = [];
40
- for (let item of nodeIds) {
41
- let browseDescription = new common_1.UaBrowseDescription(item, opcua_webapi_1.BrowseDirection.Forward, new common_1.UaNodeId(common_1.ReferenceTypeIds.HasSubtype), false, opcua_webapi_1.NodeClass.ObjectType, 63);
42
- nodesToBrowse.push(browseDescription);
38
+ // Browse child type
39
+ yield browser.browse(client);
40
+ let results = browser.results();
41
+ let referencesToRead = [];
42
+ for (let item of results) {
43
+ for (let reference of item.references)
44
+ referencesToRead.push(reference);
43
45
  }
44
- let results = yield client.browse(nodesToBrowse);
45
- for (let i = 0; i < nodeIds.length; ++i) {
46
- if (results[i].statusCode.isNotGood())
46
+ if (0 == referencesToRead.length)
47
+ return;
48
+ // Read child type
49
+ let nodeIdsToBrowse = [];
50
+ let nodeReader = new UaNodeReader_1.UaNodeReader(this._returnAllAttributes, false, false, this._returnAllAttributes);
51
+ let nodes = yield nodeReader.readByReferences(referencesToRead, client);
52
+ for (let node of nodes) {
53
+ if (opcua_webapi_1.NodeClass.ObjectType != node.nodeClass)
47
54
  continue;
48
- let parentType = this._objectTypes.get(nodeIds[i].toString());
49
- for (let item of results[i].references) {
50
- let objectTypeId = item.nodeId.getNodeId();
51
- if (null == objectTypeId || opcua_webapi_1.NodeClass.ObjectType != item.nodeClass ||
52
- !item.browseName || !item.displayName)
53
- continue;
54
- let objectType = new common_1.UaObjectType(objectTypeId, item.browseName, item.displayName, false);
55
- this._objectTypes.set(objectTypeId.toString(), objectType);
56
- this._remainingNodesToBrowse.push(objectTypeId);
57
- if (parentType)
55
+ nodeIdsToBrowse.push(node.nodeId);
56
+ this._objectTypes.set(node.nodeId.toString(), node);
57
+ }
58
+ // Build parent-child relationship
59
+ for (let item of results) {
60
+ let parentType = this._objectTypes.get(item.nodeId.toString());
61
+ for (let reference of item.references) {
62
+ let objectType = this._objectTypes.get(reference.nodeId.toString());
63
+ if (objectType && parentType)
58
64
  objectType.setParentType(parentType);
59
65
  }
60
66
  }
61
- if (this._remainingNodesToBrowse.length != 0) {
62
- yield this.__delay(20);
63
- yield this.__browseObjectTypes(client);
64
- }
67
+ if (0 == nodeIdsToBrowse.length)
68
+ return;
69
+ yield this.__delay(20);
70
+ // Continue to browse and read child type
71
+ let childBrowser = new UaNodeReader_1.UaChildBrowser(nodeIdsToBrowse);
72
+ yield this._read(childBrowser, client);
65
73
  });
66
74
  }
67
75
  __delay(ms) {
@@ -12,16 +12,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.UaReferenceTypeDictionary = void 0;
13
13
  const opcua_webapi_1 = require("opcua-webapi");
14
14
  const common_1 = require("../../common");
15
+ const UaNodeReader_1 = require("./UaNodeReader");
15
16
  class UaReferenceTypeDictionary {
16
- constructor() {
17
+ constructor(simpleMode) {
17
18
  this._referenceTypes = new Map;
18
- let referencesId = new common_1.UaNodeId(common_1.ReferenceTypeIds.References);
19
+ this._returnAllAttributes = (null == simpleMode) ? false : !simpleMode;
20
+ let referencesId = common_1.UaNodeId.from(common_1.ReferenceTypeIds.References);
19
21
  this._referenceTypes.set(referencesId.toString(), new common_1.UaReferenceType(referencesId, "References", new common_1.UaLocalizedText("References"), true, common_1.UaLocalizedText.nullText, true));
20
- this._remainingNodesToBrowse = [referencesId];
21
22
  }
22
23
  read(client) {
23
24
  return __awaiter(this, void 0, void 0, function* () {
24
- yield this.__browseReferenceTypes(client);
25
+ let browser = new UaNodeReader_1.UaChildBrowser([common_1.UaNodeId.from(common_1.ReferenceTypeIds.References)]);
26
+ yield this._read(browser, client);
25
27
  });
26
28
  }
27
29
  getReferenceType(nodeId) {
@@ -31,37 +33,43 @@ class UaReferenceTypeDictionary {
31
33
  getReferenceTypes() {
32
34
  return [...this._referenceTypes.values()];
33
35
  }
34
- __browseReferenceTypes(client) {
36
+ _read(browser, client) {
35
37
  return __awaiter(this, void 0, void 0, function* () {
36
- if (0 == this._remainingNodesToBrowse.length)
37
- return;
38
- let nodeIds = this._remainingNodesToBrowse.splice(0, 15);
39
- let nodesToBrowse = [];
40
- for (let item of nodeIds) {
41
- let browseDescription = new common_1.UaBrowseDescription(item, opcua_webapi_1.BrowseDirection.Forward, new common_1.UaNodeId(common_1.ReferenceTypeIds.HasSubtype), false, opcua_webapi_1.NodeClass.ReferenceType, 31);
42
- nodesToBrowse.push(browseDescription);
38
+ // Browse child type
39
+ yield browser.browse(client);
40
+ let results = browser.results();
41
+ let referencesToRead = [];
42
+ for (let item of results) {
43
+ for (let reference of item.references)
44
+ referencesToRead.push(reference);
43
45
  }
44
- let results = yield client.browse(nodesToBrowse);
45
- for (let i = 0; i < nodeIds.length; ++i) {
46
- if (results[i].statusCode.isNotGood())
46
+ if (0 == referencesToRead.length)
47
+ return;
48
+ // Read child type
49
+ let nodeIdsToBrowse = [];
50
+ let nodeReader = new UaNodeReader_1.UaNodeReader(this._returnAllAttributes, false, false, this._returnAllAttributes);
51
+ let nodes = yield nodeReader.readByReferences(referencesToRead, client);
52
+ for (let node of nodes) {
53
+ if (opcua_webapi_1.NodeClass.ReferenceType != node.nodeClass)
47
54
  continue;
48
- let parentType = this._referenceTypes.get(nodeIds[i].toString());
49
- for (let item of results[i].references) {
50
- let referenceTypeId = item.nodeId.getNodeId();
51
- if (null == referenceTypeId || opcua_webapi_1.NodeClass.ReferenceType != item.nodeClass ||
52
- !item.browseName || !item.displayName)
53
- continue;
54
- let referenceType = new common_1.UaReferenceType(referenceTypeId, item.browseName, item.displayName, false, common_1.UaLocalizedText.nullText, false);
55
- this._referenceTypes.set(referenceTypeId.toString(), referenceType);
56
- this._remainingNodesToBrowse.push(referenceTypeId);
57
- if (parentType)
55
+ nodeIdsToBrowse.push(node.nodeId);
56
+ this._referenceTypes.set(node.nodeId.toString(), node);
57
+ }
58
+ // Build parent-child relationship
59
+ for (let item of results) {
60
+ let parentType = this._referenceTypes.get(item.nodeId.toString());
61
+ for (let reference of item.references) {
62
+ let referenceType = this._referenceTypes.get(reference.nodeId.toString());
63
+ if (referenceType && parentType)
58
64
  referenceType.setParentType(parentType);
59
65
  }
60
66
  }
61
- if (this._remainingNodesToBrowse.length != 0) {
62
- yield this.__delay(20);
63
- yield this.__browseReferenceTypes(client);
64
- }
67
+ if (0 == nodeIdsToBrowse.length)
68
+ return;
69
+ yield this.__delay(20);
70
+ // Continue to browse and read child type
71
+ let childBrowser = new UaNodeReader_1.UaChildBrowser(nodeIdsToBrowse);
72
+ yield this._read(childBrowser, client);
65
73
  });
66
74
  }
67
75
  __delay(ms) {
@@ -1,15 +1,12 @@
1
1
  import { UaDataType, UaNodeId } from "../../common";
2
2
  import { UaWebClient } from "../UaWebClient";
3
3
  export declare class UaDataTypeDictionary {
4
- private static _abstractDataTypeIds;
5
4
  private _dataTypes;
6
- private _remainingNodesToBrowse;
7
- private _remainingEnumerationToRead;
8
- constructor();
5
+ private _returnAllAttributes;
6
+ constructor(simpleMode?: boolean);
9
7
  read(client: UaWebClient): Promise<void>;
10
8
  getDataType(nodeId: UaNodeId): UaDataType | null;
11
9
  getDataTypes(): Array<UaDataType>;
12
- private __browseDataTypes;
13
- private __readEnumValues;
10
+ private _read;
14
11
  private __delay;
15
12
  }
@@ -12,27 +12,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.UaDataTypeDictionary = void 0;
13
13
  const opcua_webapi_1 = require("opcua-webapi");
14
14
  const common_1 = require("../../common");
15
+ const __1 = require("../..");
15
16
  class UaDataTypeDictionary {
16
- constructor() {
17
- if (null == UaDataTypeDictionary._abstractDataTypeIds) {
18
- UaDataTypeDictionary._abstractDataTypeIds = new Set;
19
- UaDataTypeDictionary._abstractDataTypeIds.add(common_1.DataTypeIds.BaseDataType);
20
- UaDataTypeDictionary._abstractDataTypeIds.add(common_1.DataTypeIds.Number);
21
- UaDataTypeDictionary._abstractDataTypeIds.add(common_1.DataTypeIds.Structure);
22
- UaDataTypeDictionary._abstractDataTypeIds.add(common_1.DataTypeIds.Integer);
23
- UaDataTypeDictionary._abstractDataTypeIds.add(common_1.DataTypeIds.UInteger);
24
- UaDataTypeDictionary._abstractDataTypeIds.add(common_1.DataTypeIds.Enumeration);
25
- }
17
+ constructor(simpleMode) {
26
18
  this._dataTypes = new Map;
19
+ this._returnAllAttributes = (null == simpleMode) ? false : !simpleMode;
27
20
  let baseDataTypeId = new common_1.UaNodeId(common_1.DataTypeIds.BaseDataType);
28
21
  this._dataTypes.set(baseDataTypeId.toString(), new common_1.UaDataType(baseDataTypeId, "BaseDataType", new common_1.UaLocalizedText("BaseDataType"), true));
29
- this._remainingNodesToBrowse = [new common_1.UaNodeId(common_1.DataTypeIds.BaseDataType)];
30
- this._remainingEnumerationToRead = [];
31
22
  }
32
23
  read(client) {
33
24
  return __awaiter(this, void 0, void 0, function* () {
34
- yield this.__browseDataTypes(client);
35
- yield this.__readEnumValues(client);
25
+ let browser = new __1.UaChildBrowser([common_1.UaNodeId.from(common_1.DataTypeIds.BaseDataType)]);
26
+ yield this._read(browser, client);
36
27
  });
37
28
  }
38
29
  getDataType(nodeId) {
@@ -42,89 +33,46 @@ class UaDataTypeDictionary {
42
33
  getDataTypes() {
43
34
  return [...this._dataTypes.values()];
44
35
  }
45
- __browseDataTypes(client) {
36
+ _read(browser, client) {
46
37
  return __awaiter(this, void 0, void 0, function* () {
47
- if (0 == this._remainingNodesToBrowse.length)
48
- return;
49
- let nodeIds = this._remainingNodesToBrowse.splice(0, 15);
50
- let nodesToBrowse = [];
51
- for (let item of nodeIds) {
52
- let browseDescription = new common_1.UaBrowseDescription(item, opcua_webapi_1.BrowseDirection.Forward, new common_1.UaNodeId(common_1.ReferenceTypeIds.HasSubtype), false, opcua_webapi_1.NodeClass.DataType, 31);
53
- nodesToBrowse.push(browseDescription);
38
+ // Browse child type
39
+ yield browser.browse(client);
40
+ let results = browser.results();
41
+ let referencesToRead = [];
42
+ let needToReadEnumValue = false;
43
+ for (let item of results) {
44
+ for (let reference of item.references)
45
+ referencesToRead.push(reference);
46
+ if (item.nodeId.equal(common_1.UaNodeId.from(common_1.DataTypeIds.Enumeration)))
47
+ needToReadEnumValue = true;
54
48
  }
55
- let results = yield client.browse(nodesToBrowse);
56
- for (let i = 0; i < nodeIds.length; ++i) {
57
- if (results[i].statusCode.isNotGood())
58
- continue;
59
- let parentType = this._dataTypes.get(nodeIds[i].toString());
60
- for (let item of results[i].references) {
61
- let dataTypeId = item.nodeId.getNodeId();
62
- if (null == dataTypeId ||
63
- opcua_webapi_1.NodeClass.DataType != item.nodeClass ||
64
- !item.browseName || !item.displayName)
65
- continue;
66
- let isAbstract = false;
67
- if (dataTypeId.nsIndex == 0 &&
68
- UaDataTypeDictionary._abstractDataTypeIds.has(dataTypeId.numericId()))
69
- isAbstract = true;
70
- let dataType = new common_1.UaDataType(dataTypeId, item.browseName, item.displayName, isAbstract);
71
- this._dataTypes.set(dataTypeId.toString(), dataType);
72
- this._remainingNodesToBrowse.push(dataTypeId);
73
- if (parentType)
74
- dataType.setParentType(parentType);
75
- dataType.classify();
76
- if (common_1.DataTypeIds.Enumeration == dataType.valueType) {
77
- this._remainingEnumerationToRead.push(dataType.nodeId);
78
- }
79
- }
80
- }
81
- if (this._remainingNodesToBrowse.length != 0) {
82
- yield this.__delay(20);
83
- yield this.__browseDataTypes(client);
84
- }
85
- });
86
- }
87
- __readEnumValues(client) {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- if (this._remainingEnumerationToRead.length == 0)
49
+ if (0 == referencesToRead.length)
90
50
  return;
91
- let nodeIds = this._remainingEnumerationToRead.splice(0, 20);
92
- let nodesToBrowse = [];
93
- for (let item of nodeIds) {
94
- let browseDescription = new common_1.UaBrowseDescription(item, opcua_webapi_1.BrowseDirection.Forward, new common_1.UaNodeId(common_1.ReferenceTypeIds.HasProperty), false, opcua_webapi_1.NodeClass.Variable, 8);
95
- nodesToBrowse.push(browseDescription);
96
- }
97
- let results = yield client.browse(nodesToBrowse);
98
- let enumDataTypeIds = [];
99
- let enumValueIds = [];
100
- for (let i = 0; i < nodeIds.length; ++i) {
101
- if (results[i].statusCode.isNotGood() ||
102
- results[i].references.length == 0)
51
+ // Read child type
52
+ let nodeIdsToBrowse = [];
53
+ let nodeReader = new __1.UaNodeReader(this._returnAllAttributes, needToReadEnumValue, false, this._returnAllAttributes);
54
+ let nodes = yield nodeReader.readByReferences(referencesToRead, client);
55
+ for (let node of nodes) {
56
+ if (opcua_webapi_1.NodeClass.DataType != node.nodeClass)
103
57
  continue;
104
- if (results[i].references[0].browseName == "EnumStrings" || results[i].references[0].browseName == "EnumValues") {
105
- let enumValueId = results[i].references[0].nodeId.getNodeId();
106
- if (enumValueId) {
107
- enumDataTypeIds.push(nodeIds[i]);
108
- enumValueIds.push(enumValueId);
109
- }
110
- }
58
+ nodeIdsToBrowse.push(node.nodeId);
59
+ this._dataTypes.set(node.nodeId.toString(), node);
111
60
  }
112
- if (enumDataTypeIds.length != 0) {
113
- let values = yield client.readValues(enumValueIds);
114
- for (let i = 0; i < enumValueIds.length; ++i) {
115
- if (values[i].statusCode.isNotGood() ||
116
- values[i].value.arrayType != common_1.UaArrayType.Array)
117
- continue;
118
- let dataType = this._dataTypes.get(enumDataTypeIds[i].toString());
119
- if (!dataType)
120
- continue;
121
- dataType.setEnumValues(values[i].value);
61
+ // Build parent-child relationship
62
+ for (let item of results) {
63
+ let parentType = this._dataTypes.get(item.nodeId.toString());
64
+ for (let reference of item.references) {
65
+ let dataType = this._dataTypes.get(reference.nodeId.toString());
66
+ if (dataType && parentType)
67
+ dataType.setParentType(parentType);
122
68
  }
123
69
  }
124
- if (this._remainingEnumerationToRead.length != 0) {
125
- yield this.__delay(20);
126
- yield this.__readEnumValues(client);
127
- }
70
+ if (0 == nodeIdsToBrowse.length)
71
+ return;
72
+ yield this.__delay(20);
73
+ // Continue to browse and read child type
74
+ let childBrowser = new __1.UaChildBrowser(nodeIdsToBrowse);
75
+ yield this._read(childBrowser, client);
128
76
  });
129
77
  }
130
78
  __delay(ms) {
@@ -134,4 +82,3 @@ class UaDataTypeDictionary {
134
82
  }
135
83
  }
136
84
  exports.UaDataTypeDictionary = UaDataTypeDictionary;
137
- UaDataTypeDictionary._abstractDataTypeIds = null;
@@ -358,6 +358,7 @@ class UaNodeReader {
358
358
  _readTypes(references, nodes, client) {
359
359
  return __awaiter(this, void 0, void 0, function* () {
360
360
  let typesToRead = [];
361
+ let needReadAttributes = this._returnAttributes || this._returnDescription;
361
362
  for (let item of references) {
362
363
  if (item.nodeClass != opcua_webapi_1.NodeClass.ObjectType &&
363
364
  item.nodeClass != opcua_webapi_1.NodeClass.DataType &&
@@ -368,44 +369,50 @@ class UaNodeReader {
368
369
  }
369
370
  if (0 == typesToRead.length)
370
371
  return;
371
- let nodesToRead = [];
372
- for (let item of typesToRead) {
373
- nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.IsAbstract));
374
- nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
375
- if (item.nodeClass == opcua_webapi_1.NodeClass.VariableType) {
376
- nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.DataType));
377
- nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.ValueRank));
372
+ let dataValues = [];
373
+ if (needReadAttributes) {
374
+ let nodesToRead = [];
375
+ for (let item of typesToRead) {
376
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.IsAbstract));
377
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
378
+ if (item.nodeClass == opcua_webapi_1.NodeClass.VariableType) {
379
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.DataType));
380
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.ValueRank));
381
+ }
378
382
  }
383
+ dataValues = yield client.read(nodesToRead);
379
384
  }
380
- let dataValues = yield client.read(nodesToRead);
381
385
  for (let i = 0; i < typesToRead.length; ++i) {
382
- let dataIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? i * 4 : i * 2;
383
- if (dataValues[dataIndex].statusCode.isNotGood())
384
- throw new common_1.UaError(dataValues[dataIndex].statusCode);
385
- let isAbstract = dataValues[dataIndex].value.toBoolean();
386
- if (null == isAbstract)
387
- throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
388
- dataIndex++;
386
+ let isAbstract = false;
389
387
  let description = undefined;
390
- if (this._returnDescription && dataValues[dataIndex].statusCode.isGood()) {
391
- description = dataValues[dataIndex].value.toLocalizedText();
392
- if (null == description)
393
- description = undefined;
394
- }
395
- dataIndex++;
396
388
  let dataType = common_1.UaNodeId.nullNodeId;
397
389
  let valueRank = -1;
398
- if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) {
390
+ if (needReadAttributes) {
391
+ let dataIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? i * 4 : i * 2;
399
392
  if (dataValues[dataIndex].statusCode.isNotGood())
400
393
  throw new common_1.UaError(dataValues[dataIndex].statusCode);
401
- dataType = dataValues[dataIndex].value.toNodeId();
394
+ isAbstract = dataValues[dataIndex].value.toBoolean();
395
+ if (null == isAbstract)
396
+ throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
402
397
  dataIndex++;
403
- if (dataValues[dataIndex].statusCode.isNotGood())
404
- throw new common_1.UaError(dataValues[dataIndex].statusCode);
405
- valueRank = dataValues[dataIndex].value.toNumber();
398
+ if (this._returnDescription && dataValues[dataIndex].statusCode.isGood()) {
399
+ description = dataValues[dataIndex].value.toLocalizedText();
400
+ if (null == description)
401
+ description = undefined;
402
+ }
406
403
  dataIndex++;
407
- if (null == dataType || null == valueRank)
408
- throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
404
+ if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) {
405
+ if (dataValues[dataIndex].statusCode.isNotGood())
406
+ throw new common_1.UaError(dataValues[dataIndex].statusCode);
407
+ dataType = dataValues[dataIndex].value.toNodeId();
408
+ dataIndex++;
409
+ if (dataValues[dataIndex].statusCode.isNotGood())
410
+ throw new common_1.UaError(dataValues[dataIndex].statusCode);
411
+ valueRank = dataValues[dataIndex].value.toNumber();
412
+ dataIndex++;
413
+ if (null == dataType || null == valueRank)
414
+ throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
415
+ }
409
416
  }
410
417
  let typeNode;
411
418
  if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.ObjectType) {
@@ -2,11 +2,11 @@ import { UaNodeId, UaObjectType } from "../../common";
2
2
  import { UaWebClient } from "../UaWebClient";
3
3
  export declare class UaObjectTypeDictionary {
4
4
  private _objectTypes;
5
- private _remainingNodesToBrowse;
6
- constructor();
5
+ private _returnAllAttributes;
6
+ constructor(simpleMode?: boolean);
7
7
  read(client: UaWebClient): Promise<void>;
8
8
  getObjectType(nodeId: UaNodeId): UaObjectType | null;
9
9
  getObjectTypes(): Array<UaObjectType>;
10
- private __browseObjectTypes;
10
+ private _read;
11
11
  private __delay;
12
12
  }
@@ -12,16 +12,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.UaObjectTypeDictionary = void 0;
13
13
  const opcua_webapi_1 = require("opcua-webapi");
14
14
  const common_1 = require("../../common");
15
+ const UaNodeReader_1 = require("./UaNodeReader");
15
16
  class UaObjectTypeDictionary {
16
- constructor() {
17
+ constructor(simpleMode) {
17
18
  this._objectTypes = new Map;
18
- let baseObjectTypeId = new common_1.UaNodeId(common_1.ObjectTypeIds.BaseObjectType);
19
+ this._returnAllAttributes = (null == simpleMode) ? false : !simpleMode;
20
+ let baseObjectTypeId = common_1.UaNodeId.from(common_1.ObjectTypeIds.BaseObjectType);
19
21
  this._objectTypes.set(baseObjectTypeId.toString(), new common_1.UaObjectType(baseObjectTypeId, "BaseObjectType", new common_1.UaLocalizedText("BaseObjectType"), false));
20
- this._remainingNodesToBrowse = [baseObjectTypeId];
21
22
  }
22
23
  read(client) {
23
24
  return __awaiter(this, void 0, void 0, function* () {
24
- yield this.__browseObjectTypes(client);
25
+ let browser = new UaNodeReader_1.UaChildBrowser([common_1.UaNodeId.from(common_1.ObjectTypeIds.BaseObjectType)]);
26
+ yield this._read(browser, client);
25
27
  });
26
28
  }
27
29
  getObjectType(nodeId) {
@@ -31,37 +33,43 @@ class UaObjectTypeDictionary {
31
33
  getObjectTypes() {
32
34
  return [...this._objectTypes.values()];
33
35
  }
34
- __browseObjectTypes(client) {
36
+ _read(browser, client) {
35
37
  return __awaiter(this, void 0, void 0, function* () {
36
- if (0 == this._remainingNodesToBrowse.length)
37
- return;
38
- let nodeIds = this._remainingNodesToBrowse.splice(0, 15);
39
- let nodesToBrowse = [];
40
- for (let item of nodeIds) {
41
- let browseDescription = new common_1.UaBrowseDescription(item, opcua_webapi_1.BrowseDirection.Forward, new common_1.UaNodeId(common_1.ReferenceTypeIds.HasSubtype), false, opcua_webapi_1.NodeClass.ObjectType, 63);
42
- nodesToBrowse.push(browseDescription);
38
+ // Browse child type
39
+ yield browser.browse(client);
40
+ let results = browser.results();
41
+ let referencesToRead = [];
42
+ for (let item of results) {
43
+ for (let reference of item.references)
44
+ referencesToRead.push(reference);
43
45
  }
44
- let results = yield client.browse(nodesToBrowse);
45
- for (let i = 0; i < nodeIds.length; ++i) {
46
- if (results[i].statusCode.isNotGood())
46
+ if (0 == referencesToRead.length)
47
+ return;
48
+ // Read child type
49
+ let nodeIdsToBrowse = [];
50
+ let nodeReader = new UaNodeReader_1.UaNodeReader(this._returnAllAttributes, false, false, this._returnAllAttributes);
51
+ let nodes = yield nodeReader.readByReferences(referencesToRead, client);
52
+ for (let node of nodes) {
53
+ if (opcua_webapi_1.NodeClass.ObjectType != node.nodeClass)
47
54
  continue;
48
- let parentType = this._objectTypes.get(nodeIds[i].toString());
49
- for (let item of results[i].references) {
50
- let objectTypeId = item.nodeId.getNodeId();
51
- if (null == objectTypeId || opcua_webapi_1.NodeClass.ObjectType != item.nodeClass ||
52
- !item.browseName || !item.displayName)
53
- continue;
54
- let objectType = new common_1.UaObjectType(objectTypeId, item.browseName, item.displayName, false);
55
- this._objectTypes.set(objectTypeId.toString(), objectType);
56
- this._remainingNodesToBrowse.push(objectTypeId);
57
- if (parentType)
55
+ nodeIdsToBrowse.push(node.nodeId);
56
+ this._objectTypes.set(node.nodeId.toString(), node);
57
+ }
58
+ // Build parent-child relationship
59
+ for (let item of results) {
60
+ let parentType = this._objectTypes.get(item.nodeId.toString());
61
+ for (let reference of item.references) {
62
+ let objectType = this._objectTypes.get(reference.nodeId.toString());
63
+ if (objectType && parentType)
58
64
  objectType.setParentType(parentType);
59
65
  }
60
66
  }
61
- if (this._remainingNodesToBrowse.length != 0) {
62
- yield this.__delay(20);
63
- yield this.__browseObjectTypes(client);
64
- }
67
+ if (0 == nodeIdsToBrowse.length)
68
+ return;
69
+ yield this.__delay(20);
70
+ // Continue to browse and read child type
71
+ let childBrowser = new UaNodeReader_1.UaChildBrowser(nodeIdsToBrowse);
72
+ yield this._read(childBrowser, client);
65
73
  });
66
74
  }
67
75
  __delay(ms) {
@@ -2,11 +2,11 @@ import { UaReferenceType, UaNodeId } from "../../common";
2
2
  import { UaWebClient } from "../UaWebClient";
3
3
  export declare class UaReferenceTypeDictionary {
4
4
  private _referenceTypes;
5
- private _remainingNodesToBrowse;
6
- constructor();
5
+ private _returnAllAttributes;
6
+ constructor(simpleMode?: boolean);
7
7
  read(client: UaWebClient): Promise<void>;
8
8
  getReferenceType(nodeId: UaNodeId): UaReferenceType | null;
9
9
  getReferenceTypes(): Array<UaReferenceType>;
10
- private __browseReferenceTypes;
10
+ private _read;
11
11
  private __delay;
12
12
  }
@@ -12,16 +12,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.UaReferenceTypeDictionary = void 0;
13
13
  const opcua_webapi_1 = require("opcua-webapi");
14
14
  const common_1 = require("../../common");
15
+ const UaNodeReader_1 = require("./UaNodeReader");
15
16
  class UaReferenceTypeDictionary {
16
- constructor() {
17
+ constructor(simpleMode) {
17
18
  this._referenceTypes = new Map;
18
- let referencesId = new common_1.UaNodeId(common_1.ReferenceTypeIds.References);
19
+ this._returnAllAttributes = (null == simpleMode) ? false : !simpleMode;
20
+ let referencesId = common_1.UaNodeId.from(common_1.ReferenceTypeIds.References);
19
21
  this._referenceTypes.set(referencesId.toString(), new common_1.UaReferenceType(referencesId, "References", new common_1.UaLocalizedText("References"), true, common_1.UaLocalizedText.nullText, true));
20
- this._remainingNodesToBrowse = [referencesId];
21
22
  }
22
23
  read(client) {
23
24
  return __awaiter(this, void 0, void 0, function* () {
24
- yield this.__browseReferenceTypes(client);
25
+ let browser = new UaNodeReader_1.UaChildBrowser([common_1.UaNodeId.from(common_1.ReferenceTypeIds.References)]);
26
+ yield this._read(browser, client);
25
27
  });
26
28
  }
27
29
  getReferenceType(nodeId) {
@@ -31,37 +33,43 @@ class UaReferenceTypeDictionary {
31
33
  getReferenceTypes() {
32
34
  return [...this._referenceTypes.values()];
33
35
  }
34
- __browseReferenceTypes(client) {
36
+ _read(browser, client) {
35
37
  return __awaiter(this, void 0, void 0, function* () {
36
- if (0 == this._remainingNodesToBrowse.length)
37
- return;
38
- let nodeIds = this._remainingNodesToBrowse.splice(0, 15);
39
- let nodesToBrowse = [];
40
- for (let item of nodeIds) {
41
- let browseDescription = new common_1.UaBrowseDescription(item, opcua_webapi_1.BrowseDirection.Forward, new common_1.UaNodeId(common_1.ReferenceTypeIds.HasSubtype), false, opcua_webapi_1.NodeClass.ReferenceType, 31);
42
- nodesToBrowse.push(browseDescription);
38
+ // Browse child type
39
+ yield browser.browse(client);
40
+ let results = browser.results();
41
+ let referencesToRead = [];
42
+ for (let item of results) {
43
+ for (let reference of item.references)
44
+ referencesToRead.push(reference);
43
45
  }
44
- let results = yield client.browse(nodesToBrowse);
45
- for (let i = 0; i < nodeIds.length; ++i) {
46
- if (results[i].statusCode.isNotGood())
46
+ if (0 == referencesToRead.length)
47
+ return;
48
+ // Read child type
49
+ let nodeIdsToBrowse = [];
50
+ let nodeReader = new UaNodeReader_1.UaNodeReader(this._returnAllAttributes, false, false, this._returnAllAttributes);
51
+ let nodes = yield nodeReader.readByReferences(referencesToRead, client);
52
+ for (let node of nodes) {
53
+ if (opcua_webapi_1.NodeClass.ReferenceType != node.nodeClass)
47
54
  continue;
48
- let parentType = this._referenceTypes.get(nodeIds[i].toString());
49
- for (let item of results[i].references) {
50
- let referenceTypeId = item.nodeId.getNodeId();
51
- if (null == referenceTypeId || opcua_webapi_1.NodeClass.ReferenceType != item.nodeClass ||
52
- !item.browseName || !item.displayName)
53
- continue;
54
- let referenceType = new common_1.UaReferenceType(referenceTypeId, item.browseName, item.displayName, false, common_1.UaLocalizedText.nullText, false);
55
- this._referenceTypes.set(referenceTypeId.toString(), referenceType);
56
- this._remainingNodesToBrowse.push(referenceTypeId);
57
- if (parentType)
55
+ nodeIdsToBrowse.push(node.nodeId);
56
+ this._referenceTypes.set(node.nodeId.toString(), node);
57
+ }
58
+ // Build parent-child relationship
59
+ for (let item of results) {
60
+ let parentType = this._referenceTypes.get(item.nodeId.toString());
61
+ for (let reference of item.references) {
62
+ let referenceType = this._referenceTypes.get(reference.nodeId.toString());
63
+ if (referenceType && parentType)
58
64
  referenceType.setParentType(parentType);
59
65
  }
60
66
  }
61
- if (this._remainingNodesToBrowse.length != 0) {
62
- yield this.__delay(20);
63
- yield this.__browseReferenceTypes(client);
64
- }
67
+ if (0 == nodeIdsToBrowse.length)
68
+ return;
69
+ yield this.__delay(20);
70
+ // Continue to browse and read child type
71
+ let childBrowser = new UaNodeReader_1.UaChildBrowser(nodeIdsToBrowse);
72
+ yield this._read(childBrowser, client);
65
73
  });
66
74
  }
67
75
  __delay(ms) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opcua-webapi-ts",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
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",