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,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;