opcua-webapi-ts 1.1.5 → 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.
Files changed (29) hide show
  1. package/dist/cjs/client/utils/UaDataTypeDictionary.js +38 -91
  2. package/dist/cjs/client/utils/UaNodeReader.js +459 -530
  3. package/dist/cjs/client/utils/UaObjectTypeDictionary.js +37 -29
  4. package/dist/cjs/client/utils/UaReferenceTypeDictionary.js +37 -29
  5. package/dist/cjs/common/nodes/UaDataType.js +35 -34
  6. package/dist/cjs/common/nodes/UaMethod.js +2 -2
  7. package/dist/cjs/common/nodes/UaObject.js +1 -1
  8. package/dist/cjs/common/nodes/UaVariable.js +10 -6
  9. package/dist/cjs/common/types/UaReference.js +59 -0
  10. package/dist/cjs/common/types/index.js +1 -1
  11. package/dist/client/utils/UaDataTypeDictionary.d.ts +3 -6
  12. package/dist/client/utils/UaDataTypeDictionary.js +38 -91
  13. package/dist/client/utils/UaNodeReader.d.ts +45 -73
  14. package/dist/client/utils/UaNodeReader.js +459 -530
  15. package/dist/client/utils/UaObjectTypeDictionary.d.ts +3 -3
  16. package/dist/client/utils/UaObjectTypeDictionary.js +37 -29
  17. package/dist/client/utils/UaReferenceTypeDictionary.d.ts +3 -3
  18. package/dist/client/utils/UaReferenceTypeDictionary.js +37 -29
  19. package/dist/common/nodes/UaDataType.d.ts +2 -2
  20. package/dist/common/nodes/UaDataType.js +35 -34
  21. package/dist/common/nodes/UaMethod.js +2 -2
  22. package/dist/common/nodes/UaObject.js +1 -1
  23. package/dist/common/nodes/UaVariable.d.ts +5 -4
  24. package/dist/common/nodes/UaVariable.js +10 -6
  25. package/dist/common/types/UaReference.d.ts +23 -0
  26. package/dist/common/types/UaReference.js +59 -0
  27. package/dist/common/types/index.d.ts +1 -1
  28. package/dist/common/types/index.js +1 -1
  29. package/package.json +1 -1
@@ -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) {
@@ -20,38 +20,6 @@ class UaDataType extends _1.UaDefintionNode {
20
20
  get enumValues() {
21
21
  return this._enumValues;
22
22
  }
23
- setEnumVariable(node) {
24
- if ("EnumStrings" == node.browseName ||
25
- "EnumValues" == node.browseName) {
26
- this.setEnumValues(node.value);
27
- }
28
- }
29
- setEnumValues(value) {
30
- if (types_1.UaVariantType.LocalizedText == value.type) {
31
- let enumStrings = value.toLocalizedTexts();
32
- if (null == enumStrings)
33
- return;
34
- this._enumValues = new Map;
35
- let index = 0;
36
- for (let item of enumStrings) {
37
- this._enumValues.set(index, item);
38
- index++;
39
- }
40
- }
41
- else if (types_1.UaVariantType.ExtensionObject == value.type) {
42
- let extensionObjects = value.toExtensionObjects();
43
- if (null == extensionObjects)
44
- return;
45
- let enumValues = new Map;
46
- for (let item of extensionObjects) {
47
- let enumValue = structure_1.UaEnumValueType.fromExtensionObject(item);
48
- if (!enumValue)
49
- return;
50
- enumValues.set(enumValue.value, enumValue.displayName);
51
- }
52
- this._enumValues = enumValues;
53
- }
54
- }
55
23
  classify() {
56
24
  let isBasicDataType = false;
57
25
  if (0 == this._nodeId.nsIndex) {
@@ -73,7 +41,7 @@ class UaDataType extends _1.UaDefintionNode {
73
41
  if (this._enumValues) {
74
42
  for (let item of this._enumValues) {
75
43
  enumValues.push({
76
- value: item[0],
44
+ index: item[0],
77
45
  text: item[1].text
78
46
  });
79
47
  }
@@ -85,9 +53,42 @@ class UaDataType extends _1.UaDefintionNode {
85
53
  displayName: this._displayName.text,
86
54
  description: (this._description) ? this._description.text : undefined,
87
55
  isAbstract: this._isAbstract,
88
- enumValues: (enumValues.length == 0) ? enumValues : undefined
56
+ enumValues: (enumValues.length != 0) ? enumValues : undefined
89
57
  };
90
58
  return ret;
91
59
  }
60
+ setEnumVariable(node) {
61
+ if ("EnumStrings" == node.browseName ||
62
+ "EnumValues" == node.browseName) {
63
+ if (node.value)
64
+ this.setEnumValues(node.value);
65
+ }
66
+ }
67
+ setEnumValues(value) {
68
+ if (types_1.UaVariantType.LocalizedText == value.type) {
69
+ let enumStrings = value.toLocalizedTexts();
70
+ if (null == enumStrings)
71
+ return;
72
+ this._enumValues = new Map;
73
+ let index = 0;
74
+ for (let item of enumStrings) {
75
+ this._enumValues.set(index, item);
76
+ index++;
77
+ }
78
+ }
79
+ else if (types_1.UaVariantType.ExtensionObject == value.type) {
80
+ let extensionObjects = value.toExtensionObjects();
81
+ if (null == extensionObjects)
82
+ return;
83
+ let enumValues = new Map;
84
+ for (let item of extensionObjects) {
85
+ let enumValue = structure_1.UaEnumValueType.fromExtensionObject(item);
86
+ if (!enumValue)
87
+ return;
88
+ enumValues.set(enumValue.value, enumValue.displayName);
89
+ }
90
+ this._enumValues = enumValues;
91
+ }
92
+ }
92
93
  }
93
94
  exports.UaDataType = UaDataType;
@@ -66,8 +66,8 @@ class UaMethod extends _1.UaInstanceNode {
66
66
  name: this._browseName,
67
67
  displayName: this._displayName.text,
68
68
  description: (this._description) ? this._description.text : undefined,
69
- inputArguments: inputArgs,
70
- outputArguments: outputArgs
69
+ inputArguments: (inputArgs.length != 0) ? inputArgs : undefined,
70
+ outputArguments: (outputArgs.length != 0) ? outputArgs : undefined
71
71
  };
72
72
  return ret;
73
73
  }
@@ -59,7 +59,7 @@ class UaObject extends _1.UaInstanceNode {
59
59
  name: this._browseName,
60
60
  displayName: this._displayName.text,
61
61
  description: (this._description) ? this._description.text : undefined,
62
- typeDefinition: this._typeDefinitionId.toString(),
62
+ typeDefinitionId: this._typeDefinitionId.toString(),
63
63
  eventNotifier: this._eventNotifier,
64
64
  children: (children.length != 0) ? children : undefined
65
65
  };
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UaVariable = void 0;
4
4
  const opcua_webapi_1 = require("opcua-webapi");
5
- const types_1 = require("../types");
6
5
  const _1 = require(".");
7
6
  class UaVariable extends _1.UaInstanceNode {
8
7
  constructor(nodeId, browseName, displayName, dataType, valueRank, accessLevel, userAccessLevel, historizing, typeDefinitionId) {
@@ -12,8 +11,8 @@ class UaVariable extends _1.UaInstanceNode {
12
11
  this._accessLevel = accessLevel;
13
12
  this._userAccessLevel = userAccessLevel;
14
13
  this._historizing = historizing;
15
- this._value = types_1.UaVariant.null();
16
14
  this._typeDefinitionId = typeDefinitionId;
15
+ this._dataValue = null;
17
16
  }
18
17
  get nodeClass() {
19
18
  return opcua_webapi_1.NodeClass.Variable;
@@ -34,10 +33,13 @@ class UaVariable extends _1.UaInstanceNode {
34
33
  return this._historizing;
35
34
  }
36
35
  get value() {
37
- return this._value;
36
+ return (this._dataValue && this._dataValue.statusCode.isGood()) ? this._dataValue.value : null;
38
37
  }
39
- set value(val) {
40
- this._value = val;
38
+ get dataValue() {
39
+ return this._dataValue;
40
+ }
41
+ set dataValue(value) {
42
+ this._dataValue = value;
41
43
  }
42
44
  get typeDefinitionId() {
43
45
  return this._typeDefinitionId;
@@ -64,10 +66,12 @@ class UaVariable extends _1.UaInstanceNode {
64
66
  nodeClass: opcua_webapi_1.NodeClass.Variable,
65
67
  name: this._browseName,
66
68
  displayName: this._displayName.text,
67
- typeDefinition: this._typeDefinitionId.toString(),
69
+ typeDefinitionId: this._typeDefinitionId.toString(),
68
70
  dataType: this._dataType.toString(),
69
71
  valueRank: this._valueRank,
70
72
  accessLevel: this._accessLevel,
73
+ historizing: this._historizing,
74
+ value: this._dataValue ? this._dataValue.value.value : undefined,
71
75
  children: (children.length != 0) ? children : undefined
72
76
  };
73
77
  return ret;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UaReference = void 0;
4
+ const types_1 = require("../types");
5
+ class UaReference {
6
+ constructor(nodeId, nodeClass, browseName, displayName, referenceTypeId, typeDefinitionId) {
7
+ this._nodeId = nodeId;
8
+ this._nodeClass = nodeClass;
9
+ this._browseName = (browseName) ? browseName : "";
10
+ this._displayName = (displayName) ? displayName : types_1.UaLocalizedText.nullText;
11
+ this._referenceTypeId = (referenceTypeId) ? referenceTypeId : types_1.UaNodeId.nullNodeId;
12
+ this._typeDefinitionId = (typeDefinitionId) ? typeDefinitionId : types_1.UaNodeId.nullNodeId;
13
+ }
14
+ get nodeId() {
15
+ return this._nodeId;
16
+ }
17
+ get nodeClass() {
18
+ return this._nodeClass;
19
+ }
20
+ get browseName() {
21
+ return this._browseName;
22
+ }
23
+ get displayName() {
24
+ return this._displayName;
25
+ }
26
+ set displayName(value) {
27
+ this._displayName = value;
28
+ }
29
+ get referenceTypeId() {
30
+ return this._referenceTypeId;
31
+ }
32
+ set referenceTypeId(value) {
33
+ this._referenceTypeId = value;
34
+ }
35
+ get typeDefinitionId() {
36
+ return this._typeDefinitionId;
37
+ }
38
+ set typeDefinitionId(value) {
39
+ this._typeDefinitionId = value;
40
+ }
41
+ get description() {
42
+ return this._description;
43
+ }
44
+ set description(value) {
45
+ this._description = value;
46
+ }
47
+ toJson() {
48
+ let ret = {
49
+ nodeId: this._nodeId.toString(),
50
+ nodeClass: this._nodeClass,
51
+ name: this._browseName,
52
+ displayName: this._displayName.text,
53
+ description: (this._description) ? this._description.text : undefined,
54
+ typeDefinitionId: (!this._typeDefinitionId.isEmpty()) ? this._typeDefinitionId.toString() : undefined,
55
+ };
56
+ return ret;
57
+ }
58
+ }
59
+ exports.UaReference = UaReference;
@@ -23,7 +23,6 @@ __exportStar(require("./UaHistoryDataResult"), exports);
23
23
  __exportStar(require("./UaHistoryEventFieldList"), exports);
24
24
  __exportStar(require("./UaHistoryEventResult"), exports);
25
25
  __exportStar(require("./UaLocalizedText"), exports);
26
- __exportStar(require("./UaLink"), exports);
27
26
  __exportStar(require("./UaNodeId"), exports);
28
27
  __exportStar(require("./UaQuery"), exports);
29
28
  __exportStar(require("./UaQueryFilter"), exports);
@@ -34,3 +33,4 @@ __exportStar(require("./UaAccessLevel"), exports);
34
33
  __exportStar(require("./UaBrowseMask"), exports);
35
34
  __exportStar(require("./UaValueRank"), exports);
36
35
  __exportStar(require("./UaWriteMask"), exports);
36
+ __exportStar(require("./UaReference"), exports);
@@ -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;