opcua-webapi-ts 1.1.18 → 1.1.19

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.
@@ -89,6 +89,22 @@ class UaWebClient {
89
89
  throw new common_1.UaError(results[0]);
90
90
  });
91
91
  }
92
+ methodCall(objectId, methodId, inputArguments) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ let inputs = [];
95
+ for (let item of inputArguments) {
96
+ inputs.push(common_1.UaPayloadMapper.variantToWebApi(item));
97
+ }
98
+ let methodsToCall = [
99
+ new common_2.UaCallMethodRequest(objectId, methodId, inputArguments)
100
+ ];
101
+ let results = yield this.call(methodsToCall);
102
+ if (results[0].statusCode.isNotGood())
103
+ throw new common_1.UaError(results[0].statusCode);
104
+ let outputs = results[0].outputArguments;
105
+ return outputs;
106
+ });
107
+ }
92
108
  readNodeAttributes(nodeId, returnDescription) {
93
109
  return __awaiter(this, void 0, void 0, function* () {
94
110
  let nodesToRead = [
@@ -125,6 +141,67 @@ class UaWebClient {
125
141
  return ret;
126
142
  });
127
143
  }
144
+ readMethodArguments(nodeId) {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ let ret = { inputArguments: [], outputArguments: [] };
147
+ let browseResult = yield this.browseChild(nodeId, opcua_webapi_1.NodeClass.Variable);
148
+ let inputArgumentsId = null;
149
+ let outputArgumentsId = null;
150
+ for (let item of browseResult.results) {
151
+ if ("InputArguments" == item.browseName)
152
+ inputArgumentsId = item.nodeId.getNodeId();
153
+ if ("OutputArguments" == item.browseName)
154
+ outputArgumentsId = item.nodeId.getNodeId();
155
+ }
156
+ let nodesToRead = [];
157
+ if (inputArgumentsId)
158
+ nodesToRead.push(inputArgumentsId);
159
+ if (outputArgumentsId)
160
+ nodesToRead.push(outputArgumentsId);
161
+ if (0 == nodesToRead.length)
162
+ return ret;
163
+ let readResults = yield this.readValues(nodesToRead);
164
+ let argsArr = [];
165
+ for (let item of readResults) {
166
+ if (item.statusCode.isNotGood() ||
167
+ common_1.UaVariantType.ExtensionObject != item.value.type ||
168
+ common_1.UaArrayType.Array != item.value.arrayType)
169
+ throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadInvalidArgument));
170
+ let extensionObjects = item.value.value;
171
+ let args = [];
172
+ for (let itemL2 of extensionObjects) {
173
+ let arg = common_1.UaArgument.fromExtensionObject(itemL2);
174
+ if (!arg)
175
+ throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadInvalidArgument));
176
+ args.push(arg);
177
+ }
178
+ argsArr.push(args);
179
+ }
180
+ if (inputArgumentsId && outputArgumentsId) {
181
+ ret.inputArguments = argsArr[0];
182
+ ret.outputArguments = argsArr[1];
183
+ }
184
+ else if (inputArgumentsId) {
185
+ ret.inputArguments = argsArr[0];
186
+ }
187
+ else if (outputArgumentsId) {
188
+ ret.outputArguments = argsArr[0];
189
+ }
190
+ return ret;
191
+ });
192
+ }
193
+ readObjectEventNotifier(nodeId) {
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ let nodesToRead = [];
196
+ nodesToRead.push(new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.EventNotifier));
197
+ let results = yield this.read(nodesToRead);
198
+ if (results[0].statusCode.isNotGood())
199
+ throw new common_1.UaError(results[0].statusCode);
200
+ if (common_1.UaVariantType.Byte == results[0].value.type)
201
+ return results[0].value.value;
202
+ return 0;
203
+ });
204
+ }
128
205
  readVariableAttributes(nodeIds) {
129
206
  return __awaiter(this, void 0, void 0, function* () {
130
207
  if (nodeIds.length == 0)
@@ -179,20 +256,26 @@ class UaWebClient {
179
256
  return ret;
180
257
  });
181
258
  }
182
- methodCall(objectId, methodId, inputArguments) {
259
+ readWriteMasks(nodeIds) {
183
260
  return __awaiter(this, void 0, void 0, function* () {
184
- let inputs = [];
185
- for (let item of inputArguments) {
186
- inputs.push(common_1.UaPayloadMapper.variantToWebApi(item));
261
+ if (nodeIds.length == 0)
262
+ return [];
263
+ let nodesToRead = [];
264
+ for (let item of nodeIds) {
265
+ let nodeIdToRead = new common_1.UaReadValueId(item, opcua_webapi_1.Attributes.UserWriteMask);
266
+ nodesToRead.push(nodeIdToRead);
187
267
  }
188
- let methodsToCall = [
189
- new common_2.UaCallMethodRequest(objectId, methodId, inputArguments)
190
- ];
191
- let results = yield this.call(methodsToCall);
192
- if (results[0].statusCode.isNotGood())
193
- throw new common_1.UaError(results[0].statusCode);
194
- let outputs = results[0].outputArguments;
195
- return outputs;
268
+ let results = yield this.read(nodesToRead);
269
+ let writeMasks = [];
270
+ for (let result of results) {
271
+ if (result.statusCode.isGood() && result.value.type == common_1.UaVariantType.UInt32) {
272
+ writeMasks.push(result.value.value);
273
+ }
274
+ else {
275
+ writeMasks.push(0);
276
+ }
277
+ }
278
+ return writeMasks;
196
279
  });
197
280
  }
198
281
  getGeneratedEventType(typeId) {
@@ -706,6 +789,7 @@ class UaWebClient {
706
789
  response = yield this.api.addNodes(request, { signal: controller.signal });
707
790
  }
708
791
  catch (error) {
792
+ console.error(error);
709
793
  throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadCommunicationError));
710
794
  }
711
795
  finally {
@@ -22,7 +22,7 @@ class UaDataTypeDictionary {
22
22
  }
23
23
  read() {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
- let browser = new __1.UaChildBrowser(this._client, [common_1.UaNodeId.from(common_1.DataTypeIds.BaseDataType)]);
25
+ let browser = new __1.UaTypeBrowser(this._client, [common_1.UaNodeId.from(common_1.DataTypeIds.BaseDataType)]);
26
26
  yield this._read(browser);
27
27
  });
28
28
  }
@@ -71,7 +71,7 @@ class UaDataTypeDictionary {
71
71
  return;
72
72
  yield this.__delay(20);
73
73
  // Continue to browse and read child type
74
- let childBrowser = new __1.UaChildBrowser(this._client, nodeIdsToBrowse);
74
+ let childBrowser = new __1.UaTypeBrowser(this._client, nodeIdsToBrowse);
75
75
  yield this._read(childBrowser);
76
76
  });
77
77
  }
@@ -14,13 +14,12 @@ const opcua_webapi_1 = require("opcua-webapi");
14
14
  const common_1 = require("../../common");
15
15
  const __1 = require("../..");
16
16
  class UaModelling {
17
- constructor(client, objectTypeDictionary) {
17
+ constructor(client) {
18
18
  this._client = client;
19
- this._objectTypeDictionary = objectTypeDictionary;
20
19
  }
21
- getObjectTypeToAdd(objectTypeId) {
20
+ getObjectTypeToAdd(objectTypeId, dictionary) {
22
21
  return __awaiter(this, void 0, void 0, function* () {
23
- let objectType = yield this._readObjectMembers(objectTypeId);
22
+ let objectType = yield this._readObjectMembers(objectTypeId, dictionary);
24
23
  if (!objectType)
25
24
  return [];
26
25
  let ret = [];
@@ -28,7 +27,7 @@ class UaModelling {
28
27
  for (let item of objectMembers) {
29
28
  if (item.modellingRule != common_1.UaModellingRule.PlaceHolder)
30
29
  continue;
31
- let childObjectType = this._objectTypeDictionary.getObjectType(item.typeDefinitionId);
30
+ let childObjectType = dictionary.getObjectType(item.typeDefinitionId);
32
31
  if (!childObjectType)
33
32
  continue;
34
33
  ret.push(childObjectType);
@@ -36,11 +35,31 @@ class UaModelling {
36
35
  return ret;
37
36
  });
38
37
  }
39
- addObject(parentNodeId, objectType, displayName, browseName) {
38
+ getWriteMask(nodes) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ let nodesToRead = [];
41
+ for (let node of nodes) {
42
+ if (node.writeMask != null)
43
+ continue;
44
+ nodesToRead.push(node.nodeId);
45
+ }
46
+ if (0 == nodesToRead.length)
47
+ return;
48
+ let results = yield this._client.readWriteMasks(nodesToRead);
49
+ let index = 0;
50
+ for (let node of nodes) {
51
+ if (node.writeMask != null)
52
+ continue;
53
+ node.writeMask = results[index];
54
+ index++;
55
+ }
56
+ });
57
+ }
58
+ addObject(parentNodeId, objectTypeId, displayName, browseName) {
40
59
  return __awaiter(this, void 0, void 0, function* () {
41
60
  let objectAttributes = new __1.UaObjectAttributes(displayName);
42
61
  let extensionObject = objectAttributes.toExtensionObject();
43
- let nodeToAdd = new common_1.UaAddNodesItem(new common_1.UaExpandedNodeId(parentNodeId), opcua_webapi_1.NodeClass.Object, extensionObject, new common_1.UaExpandedNodeId(objectType.nodeId), null, browseName !== null && browseName !== void 0 ? browseName : null, null);
62
+ let nodeToAdd = new common_1.UaAddNodesItem(new common_1.UaExpandedNodeId(parentNodeId), opcua_webapi_1.NodeClass.Object, extensionObject, new common_1.UaExpandedNodeId(objectTypeId), null, browseName !== null && browseName !== void 0 ? browseName : null, null);
44
63
  let results = yield this._client.addNodes([nodeToAdd]);
45
64
  if (results[0].statusCode.isNotGood())
46
65
  throw new common_1.UaError(results[0].statusCode);
@@ -56,41 +75,30 @@ class UaModelling {
56
75
  throw new common_1.UaError(results[0]);
57
76
  });
58
77
  }
59
- getWriteMask(nodes) {
78
+ rename(nodeId, name) {
60
79
  return __awaiter(this, void 0, void 0, function* () {
61
- let nodesToRead = [];
62
- for (let node of nodes) {
63
- if (node.writeMask != null)
64
- continue;
65
- let nodeIdToRead = new common_1.UaReadValueId(node.nodeId, opcua_webapi_1.Attributes.UserWriteMask);
66
- nodesToRead.push(nodeIdToRead);
67
- }
68
- if (0 == nodesToRead.length)
69
- return;
70
- let results = yield this._client.read(nodesToRead);
71
- let index = 0;
72
- for (let node of nodes) {
73
- if (node.writeMask != null)
74
- continue;
75
- let result = results[index];
76
- let writeMask = 0;
77
- if (result.statusCode.isGood() &&
78
- result.value.type == common_1.UaVariantType.UInt32) {
79
- writeMask = result.value.value;
80
- }
81
- node.writeMask = writeMask;
82
- index++;
83
- }
80
+ let writeValue = new common_1.UaWriteValue(nodeId, common_1.UaVariant.localizedText(name), opcua_webapi_1.Attributes.DisplayName);
81
+ let results = yield this._client.write([writeValue]);
82
+ if (results[0].isNotGood())
83
+ throw new common_1.UaError(results[0]);
84
+ });
85
+ }
86
+ setDescription(nodeId, description) {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ let writeValue = new common_1.UaWriteValue(nodeId, common_1.UaVariant.localizedText(description), opcua_webapi_1.Attributes.Description);
89
+ let results = yield this._client.write([writeValue]);
90
+ if (results[0].isNotGood())
91
+ throw new common_1.UaError(results[0]);
84
92
  });
85
93
  }
86
- _readObjectMembers(objectTypeId) {
94
+ _readObjectMembers(objectTypeId, dictionary) {
87
95
  return __awaiter(this, void 0, void 0, function* () {
88
- let objectType = this._objectTypeDictionary.getObjectType(objectTypeId);
96
+ let objectType = dictionary.getObjectType(objectTypeId);
89
97
  if (!objectType)
90
98
  return null;
91
99
  if (objectType.isObjectMemberRead)
92
100
  return objectType;
93
- let typeMemberBrowser = new __1.UaNodeReferenceBrowser(this._client, [objectType.nodeId], common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), opcua_webapi_1.NodeClass.Object, false);
101
+ let typeMemberBrowser = new __1.UaNodeBrowser(this._client, [objectType.nodeId], common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), opcua_webapi_1.NodeClass.Object, false);
94
102
  yield typeMemberBrowser.browse();
95
103
  let browseMemberResults = typeMemberBrowser.results();
96
104
  let instanceNodes = new Map();
@@ -105,7 +113,7 @@ class UaModelling {
105
113
  for (let node of instanceNodes) {
106
114
  memberObjectIds.push(node[1].nodeId);
107
115
  }
108
- let modellingRuleBrowser = new __1.UaNodeReferenceBrowser(this._client, memberObjectIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HasModellingRule), opcua_webapi_1.NodeClass.Object, false);
116
+ let modellingRuleBrowser = new __1.UaNodeBrowser(this._client, memberObjectIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HasModellingRule), opcua_webapi_1.NodeClass.Object, false);
109
117
  yield modellingRuleBrowser.browse();
110
118
  let browseModellingRuleResults = modellingRuleBrowser.results();
111
119
  for (let item of browseModellingRuleResults) {
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.UaTypeBrowser = exports.UaLinkBrowser = exports.UaObjectBrowser = exports.UaNodeBrowser = void 0;
13
+ const opcua_webapi_1 = require("opcua-webapi");
14
+ const common_1 = require("../../common");
15
+ class UaNodeBrowser {
16
+ constructor(client, nodeIds, referenceType, nodeClassToReturn, returnDescription, maxNodesPerBrowse, maxReferencesPerNode) {
17
+ this._client = client;
18
+ this._nodesToBrowse = [];
19
+ this._referenceType = referenceType;
20
+ this._nodeClassToReturn = nodeClassToReturn;
21
+ this._continuationPointToBrowse = [];
22
+ this._returnDescription = returnDescription !== null && returnDescription !== void 0 ? returnDescription : false;
23
+ this._maxNodesPerBrowse = (null == maxNodesPerBrowse || maxNodesPerBrowse <= 0) ? 50 : maxNodesPerBrowse;
24
+ this._maxReferencesPerNode = (null == maxReferencesPerNode || maxReferencesPerNode < 0) ? 50 : maxReferencesPerNode;
25
+ this._readResults = new Map();
26
+ if (this._nodeClassToReturn != 0) {
27
+ let nodeIdSet = new Set;
28
+ for (let item of nodeIds) {
29
+ if (nodeIdSet.has(item.toString()))
30
+ continue;
31
+ nodeIdSet.add(item.toString());
32
+ this._nodesToBrowse.push(item);
33
+ }
34
+ }
35
+ }
36
+ browse() {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ if (this.isFinish())
39
+ return;
40
+ yield this.browseOnce();
41
+ yield this.browse();
42
+ });
43
+ }
44
+ browseOnce() {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ if (this._continuationPointToBrowse.length != 0) {
47
+ yield this._browseContinuationPoints();
48
+ }
49
+ else if (this._nodesToBrowse.length != 0) {
50
+ yield this._browseNodes();
51
+ }
52
+ });
53
+ }
54
+ results() {
55
+ let results = [];
56
+ for (let item of this._readResults) {
57
+ results.push({
58
+ nodeId: (0, common_1.parseUaNodeId)(item[0]),
59
+ references: item[1]
60
+ });
61
+ }
62
+ this._readResults.clear();
63
+ return results;
64
+ }
65
+ isFinish() {
66
+ return (this._nodesToBrowse.length == 0) && (this._continuationPointToBrowse.length == 0);
67
+ }
68
+ _browseNodes() {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ var _a;
71
+ let nodesToBrowse = this._nodesToBrowse.splice(0, this._maxNodesPerBrowse);
72
+ let browseDescriptions = [];
73
+ for (let item of nodesToBrowse) {
74
+ let browseDescription = new common_1.UaBrowseDescription(item, opcua_webapi_1.BrowseDirection.Forward, this._referenceType, true, this._nodeClassToReturn, 63);
75
+ browseDescriptions.push(browseDescription);
76
+ }
77
+ let results = yield this._client.browse(browseDescriptions, this._maxReferencesPerNode);
78
+ for (let i = 0; i < nodesToBrowse.length; ++i) {
79
+ let currentNodeId = nodesToBrowse[i];
80
+ let currentResult = results[i];
81
+ if (currentResult.statusCode.isNotGood())
82
+ throw new common_1.UaError(currentResult.statusCode);
83
+ let currentReferences = this._readResults.get(currentNodeId.toString());
84
+ if (!currentReferences) {
85
+ currentReferences = [];
86
+ this._readResults.set(currentNodeId.toString(), currentReferences);
87
+ }
88
+ let newReferences = [];
89
+ for (let item of currentResult.references) {
90
+ let nodeId = item.nodeId.getNodeId();
91
+ let typeDefinition = (_a = item.typeDefinition) === null || _a === void 0 ? void 0 : _a.getNodeId();
92
+ if (null == nodeId || null === typeDefinition)
93
+ continue;
94
+ let reference = new common_1.UaReference(nodeId, (item.nodeClass) ? item.nodeClass : opcua_webapi_1.NodeClass.Unspecified, item.browseName ? item.browseName : "", item.displayName ? item.displayName : common_1.UaLocalizedText.nullText, item.referenceTypeId ? item.referenceTypeId : common_1.UaNodeId.nullNodeId, (typeDefinition) ? typeDefinition : common_1.UaNodeId.nullNodeId);
95
+ currentReferences.push(reference);
96
+ newReferences.push(reference);
97
+ }
98
+ if (currentResult.continuationPoint) {
99
+ this._continuationPointToBrowse.push({
100
+ nodeId: currentNodeId,
101
+ continuationPoint: currentResult.continuationPoint
102
+ });
103
+ }
104
+ if (this._returnDescription)
105
+ yield this._readDescriptions(newReferences);
106
+ }
107
+ });
108
+ }
109
+ _browseContinuationPoints() {
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ var _a;
112
+ let cpsToBrowse = this._continuationPointToBrowse.splice(0, this._maxNodesPerBrowse);
113
+ let continuationPoints = [];
114
+ for (let item of cpsToBrowse) {
115
+ continuationPoints.push(item.continuationPoint);
116
+ }
117
+ let results = yield this._client.browseNext(continuationPoints, false);
118
+ for (let i = 0; i < cpsToBrowse.length; ++i) {
119
+ let currentNodeId = cpsToBrowse[i].nodeId;
120
+ let currentResult = results[i];
121
+ if (currentResult.statusCode.isNotGood())
122
+ throw new common_1.UaError(currentResult.statusCode);
123
+ let newReferences = [];
124
+ for (let item of currentResult.references) {
125
+ let nodeId = item.nodeId.getNodeId();
126
+ let typeDefinition = (_a = item.typeDefinition) === null || _a === void 0 ? void 0 : _a.getNodeId();
127
+ if (null == nodeId || null === typeDefinition)
128
+ continue;
129
+ let currentReferences = this._readResults.get(currentNodeId.toString());
130
+ if (!currentReferences) {
131
+ currentReferences = [];
132
+ this._readResults.set(currentNodeId.toString(), currentReferences);
133
+ }
134
+ let reference = new common_1.UaReference(nodeId, (item.nodeClass) ? item.nodeClass : opcua_webapi_1.NodeClass.Unspecified, item.browseName ? item.browseName : "", item.displayName ? item.displayName : common_1.UaLocalizedText.nullText, item.referenceTypeId ? item.referenceTypeId : common_1.UaNodeId.nullNodeId, (typeDefinition) ? typeDefinition : common_1.UaNodeId.nullNodeId);
135
+ currentReferences.push(reference);
136
+ newReferences.push(reference);
137
+ }
138
+ if (currentResult.continuationPoint) {
139
+ this._continuationPointToBrowse.push({
140
+ nodeId: currentNodeId,
141
+ continuationPoint: currentResult.continuationPoint
142
+ });
143
+ }
144
+ if (this._returnDescription)
145
+ yield this._readDescriptions(newReferences);
146
+ }
147
+ });
148
+ }
149
+ _readDescriptions(references) {
150
+ return __awaiter(this, void 0, void 0, function* () {
151
+ if (references.length === 0)
152
+ return;
153
+ let nodesToRead = [];
154
+ for (let item of references) {
155
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
156
+ }
157
+ let dataValues = yield this._client.read(nodesToRead);
158
+ for (let i = 0; i < references.length; ++i) {
159
+ if (dataValues[i].statusCode.isGood()) {
160
+ let description = dataValues[i].value.toLocalizedText();
161
+ if (description)
162
+ references[i].description = description;
163
+ }
164
+ }
165
+ });
166
+ }
167
+ }
168
+ exports.UaNodeBrowser = UaNodeBrowser;
169
+ class UaObjectBrowser extends UaNodeBrowser {
170
+ constructor(client, nodeIds, returnDescription) {
171
+ super(client, nodeIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), opcua_webapi_1.NodeClass.Object, returnDescription !== null && returnDescription !== void 0 ? returnDescription : false, 20);
172
+ }
173
+ }
174
+ exports.UaObjectBrowser = UaObjectBrowser;
175
+ class UaLinkBrowser extends UaNodeBrowser {
176
+ constructor(client, nodeIds, returnDescription) {
177
+ super(client, nodeIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.NonHierarchicalReferences), opcua_webapi_1.NodeClass.Object, returnDescription !== null && returnDescription !== void 0 ? returnDescription : false, 20);
178
+ }
179
+ }
180
+ exports.UaLinkBrowser = UaLinkBrowser;
181
+ class UaTypeBrowser extends UaNodeBrowser {
182
+ constructor(client, nodeIds, returnDescription) {
183
+ super(client, nodeIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), opcua_webapi_1.NodeClass.ObjectType | opcua_webapi_1.NodeClass.VariableType | opcua_webapi_1.NodeClass.DataType | opcua_webapi_1.NodeClass.ReferenceType, returnDescription !== null && returnDescription !== void 0 ? returnDescription : false, 20);
184
+ }
185
+ }
186
+ exports.UaTypeBrowser = UaTypeBrowser;
@@ -9,181 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.UaTypeReader = exports.UaObjectReader = exports.UaNodeReader = exports.UaSubtypeBrowser = exports.UaLinkBrowser = exports.UaChildBrowser = exports.UaNodeReferenceBrowser = void 0;
12
+ exports.UaTypeReader = exports.UaObjectReader = exports.UaNodeReader = void 0;
13
13
  const opcua_webapi_1 = require("opcua-webapi");
14
14
  const common_1 = require("../../common");
15
- class UaNodeReferenceBrowser {
16
- constructor(client, nodeIds, referenceType, nodeClassToReturn, returnDescription, maxNodesPerBrowse, maxReferencesPerNode) {
17
- this._client = client;
18
- this._nodesToBrowse = [];
19
- this._referenceType = referenceType;
20
- this._nodeClassToReturn = nodeClassToReturn;
21
- this._continuationPointToBrowse = [];
22
- this._returnDescription = returnDescription !== null && returnDescription !== void 0 ? returnDescription : false;
23
- this._maxNodesPerBrowse = (null == maxNodesPerBrowse || maxNodesPerBrowse <= 0) ? 50 : maxNodesPerBrowse;
24
- this._maxReferencesPerNode = (null == maxReferencesPerNode || maxReferencesPerNode < 0) ? 50 : maxReferencesPerNode;
25
- this._readResults = new Map();
26
- if (this._nodeClassToReturn != 0) {
27
- let nodeIdSet = new Set;
28
- for (let item of nodeIds) {
29
- if (nodeIdSet.has(item.toString()))
30
- continue;
31
- nodeIdSet.add(item.toString());
32
- this._nodesToBrowse.push(item);
33
- }
34
- }
35
- }
36
- browse() {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- if (this.isFinish())
39
- return;
40
- yield this.browseOnce();
41
- yield this.browse();
42
- });
43
- }
44
- browseOnce() {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- if (this._continuationPointToBrowse.length != 0) {
47
- yield this._browseContinuationPoints();
48
- }
49
- else if (this._nodesToBrowse.length != 0) {
50
- yield this._browseNodes();
51
- }
52
- });
53
- }
54
- results() {
55
- let results = [];
56
- for (let item of this._readResults) {
57
- results.push({
58
- nodeId: (0, common_1.parseUaNodeId)(item[0]),
59
- references: item[1]
60
- });
61
- }
62
- this._readResults.clear();
63
- return results;
64
- }
65
- isFinish() {
66
- return (this._nodesToBrowse.length == 0) && (this._continuationPointToBrowse.length == 0);
67
- }
68
- _browseNodes() {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- var _a;
71
- let nodesToBrowse = this._nodesToBrowse.splice(0, this._maxNodesPerBrowse);
72
- let browseDescriptions = [];
73
- for (let item of nodesToBrowse) {
74
- let browseDescription = new common_1.UaBrowseDescription(item, opcua_webapi_1.BrowseDirection.Forward, this._referenceType, true, this._nodeClassToReturn, 63);
75
- browseDescriptions.push(browseDescription);
76
- }
77
- let results = yield this._client.browse(browseDescriptions, this._maxReferencesPerNode);
78
- for (let i = 0; i < nodesToBrowse.length; ++i) {
79
- let currentNodeId = nodesToBrowse[i];
80
- let currentResult = results[i];
81
- if (currentResult.statusCode.isNotGood())
82
- throw new common_1.UaError(currentResult.statusCode);
83
- let currentReferences = this._readResults.get(currentNodeId.toString());
84
- if (!currentReferences) {
85
- currentReferences = [];
86
- this._readResults.set(currentNodeId.toString(), currentReferences);
87
- }
88
- let newReferences = [];
89
- for (let item of currentResult.references) {
90
- let nodeId = item.nodeId.getNodeId();
91
- let typeDefinition = (_a = item.typeDefinition) === null || _a === void 0 ? void 0 : _a.getNodeId();
92
- if (null == nodeId || null === typeDefinition)
93
- continue;
94
- let reference = new common_1.UaReference(nodeId, (item.nodeClass) ? item.nodeClass : opcua_webapi_1.NodeClass.Unspecified, item.browseName ? item.browseName : "", item.displayName ? item.displayName : common_1.UaLocalizedText.nullText, item.referenceTypeId ? item.referenceTypeId : common_1.UaNodeId.nullNodeId, (typeDefinition) ? typeDefinition : common_1.UaNodeId.nullNodeId);
95
- currentReferences.push(reference);
96
- newReferences.push(reference);
97
- }
98
- if (currentResult.continuationPoint) {
99
- this._continuationPointToBrowse.push({
100
- nodeId: currentNodeId,
101
- continuationPoint: currentResult.continuationPoint
102
- });
103
- }
104
- if (this._returnDescription)
105
- yield this._readDescriptions(newReferences);
106
- }
107
- });
108
- }
109
- _browseContinuationPoints() {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- var _a;
112
- let cpsToBrowse = this._continuationPointToBrowse.splice(0, this._maxNodesPerBrowse);
113
- let continuationPoints = [];
114
- for (let item of cpsToBrowse) {
115
- continuationPoints.push(item.continuationPoint);
116
- }
117
- let results = yield this._client.browseNext(continuationPoints, false);
118
- for (let i = 0; i < cpsToBrowse.length; ++i) {
119
- let currentNodeId = cpsToBrowse[i].nodeId;
120
- let currentResult = results[i];
121
- if (currentResult.statusCode.isNotGood())
122
- throw new common_1.UaError(currentResult.statusCode);
123
- let newReferences = [];
124
- for (let item of currentResult.references) {
125
- let nodeId = item.nodeId.getNodeId();
126
- let typeDefinition = (_a = item.typeDefinition) === null || _a === void 0 ? void 0 : _a.getNodeId();
127
- if (null == nodeId || null === typeDefinition)
128
- continue;
129
- let currentReferences = this._readResults.get(currentNodeId.toString());
130
- if (!currentReferences) {
131
- currentReferences = [];
132
- this._readResults.set(currentNodeId.toString(), currentReferences);
133
- }
134
- let reference = new common_1.UaReference(nodeId, (item.nodeClass) ? item.nodeClass : opcua_webapi_1.NodeClass.Unspecified, item.browseName ? item.browseName : "", item.displayName ? item.displayName : common_1.UaLocalizedText.nullText, item.referenceTypeId ? item.referenceTypeId : common_1.UaNodeId.nullNodeId, (typeDefinition) ? typeDefinition : common_1.UaNodeId.nullNodeId);
135
- currentReferences.push(reference);
136
- newReferences.push(reference);
137
- }
138
- if (currentResult.continuationPoint) {
139
- this._continuationPointToBrowse.push({
140
- nodeId: currentNodeId,
141
- continuationPoint: currentResult.continuationPoint
142
- });
143
- }
144
- if (this._returnDescription)
145
- yield this._readDescriptions(newReferences);
146
- }
147
- });
148
- }
149
- _readDescriptions(references) {
150
- return __awaiter(this, void 0, void 0, function* () {
151
- if (references.length === 0)
152
- return;
153
- let nodesToRead = [];
154
- for (let item of references) {
155
- nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
156
- }
157
- let dataValues = yield this._client.read(nodesToRead);
158
- for (let i = 0; i < references.length; ++i) {
159
- if (dataValues[i].statusCode.isGood()) {
160
- let description = dataValues[i].value.toLocalizedText();
161
- if (description)
162
- references[i].description = description;
163
- }
164
- }
165
- });
166
- }
167
- }
168
- exports.UaNodeReferenceBrowser = UaNodeReferenceBrowser;
169
- class UaChildBrowser extends UaNodeReferenceBrowser {
170
- constructor(client, nodeIds, returnDescription) {
171
- super(client, nodeIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), opcua_webapi_1.NodeClass.Object, returnDescription !== null && returnDescription !== void 0 ? returnDescription : false, 20);
172
- }
173
- }
174
- exports.UaChildBrowser = UaChildBrowser;
175
- class UaLinkBrowser extends UaNodeReferenceBrowser {
176
- constructor(client, nodeIds, returnDescription) {
177
- super(client, nodeIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.NonHierarchicalReferences), opcua_webapi_1.NodeClass.Object, returnDescription !== null && returnDescription !== void 0 ? returnDescription : false, 20);
178
- }
179
- }
180
- exports.UaLinkBrowser = UaLinkBrowser;
181
- class UaSubtypeBrowser extends UaNodeReferenceBrowser {
182
- constructor(client, nodeIds, returnDescription) {
183
- super(client, nodeIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), opcua_webapi_1.NodeClass.ObjectType | opcua_webapi_1.NodeClass.VariableType | opcua_webapi_1.NodeClass.DataType | opcua_webapi_1.NodeClass.ReferenceType, returnDescription !== null && returnDescription !== void 0 ? returnDescription : false, 20);
184
- }
185
- }
186
- exports.UaSubtypeBrowser = UaSubtypeBrowser;
15
+ const UaNodeBrowser_1 = require("./UaNodeBrowser");
187
16
  class UaNodeReader {
188
17
  constructor(client, returnDescription, returnVariable, returnMethod, returnAttributes, returnValue) {
189
18
  this._client = client;
@@ -239,7 +68,7 @@ class UaNodeReader {
239
68
  nodeIdsToBrowse.push(item.nodeId);
240
69
  nodeIdsSet.add(item.nodeId.toString());
241
70
  }
242
- let nodeReferenceBrowser = new UaNodeReferenceBrowser(this._client, nodeIdsToBrowse, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), this._nodeClassToReturn, false);
71
+ let nodeReferenceBrowser = new UaNodeBrowser_1.UaNodeBrowser(this._client, nodeIdsToBrowse, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), this._nodeClassToReturn, false);
243
72
  yield nodeReferenceBrowser.browse();
244
73
  let childReferences = nodeReferenceBrowser.results();
245
74
  let childNodesToBrowse = [];
@@ -256,7 +85,7 @@ class UaNodeReader {
256
85
  }
257
86
  let variableReferences = [];
258
87
  if (childNodesToBrowse.length != 0) {
259
- let childReferenceBrowser = new UaNodeReferenceBrowser(this._client, childNodesToBrowse, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), opcua_webapi_1.NodeClass.Variable, false);
88
+ let childReferenceBrowser = new UaNodeBrowser_1.UaNodeBrowser(this._client, childNodesToBrowse, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), opcua_webapi_1.NodeClass.Variable, false);
260
89
  yield childReferenceBrowser.browse();
261
90
  variableReferences = childReferenceBrowser.results();
262
91
  }