opcua-webapi-ts 1.0.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.
- package/README.md +34 -0
- package/dist/cjs/client/UaClientConfigure.d.ts +9 -0
- package/dist/cjs/client/UaClientConfigure.js +24 -0
- package/dist/cjs/client/UaWebClient.d.ts +38 -0
- package/dist/cjs/client/UaWebClient.js +590 -0
- package/dist/cjs/client/index.d.ts +3 -0
- package/dist/cjs/client/index.js +19 -0
- package/dist/cjs/client/utils/UaDataTypeDictionary.d.ts +15 -0
- package/dist/cjs/client/utils/UaDataTypeDictionary.js +149 -0
- package/dist/cjs/client/utils/UaNodeReader.d.ts +83 -0
- package/dist/cjs/client/utils/UaNodeReader.js +714 -0
- package/dist/cjs/client/utils/UaObjectTypeDictionary.d.ts +12 -0
- package/dist/cjs/client/utils/UaObjectTypeDictionary.js +80 -0
- package/dist/cjs/client/utils/UaReferenceTypeDictionary.d.ts +12 -0
- package/dist/cjs/client/utils/UaReferenceTypeDictionary.js +80 -0
- package/dist/cjs/client/utils/index.d.ts +4 -0
- package/dist/cjs/client/utils/index.js +20 -0
- package/dist/cjs/common/index.d.ts +4 -0
- package/dist/cjs/common/index.js +20 -0
- package/dist/cjs/common/mapper/UaPayloadMapper.d.ts +18 -0
- package/dist/cjs/common/mapper/UaPayloadMapper.js +481 -0
- package/dist/cjs/common/mapper/index.d.ts +1 -0
- package/dist/cjs/common/mapper/index.js +17 -0
- package/dist/cjs/common/nodes/Identifiers.d.ts +2458 -0
- package/dist/cjs/common/nodes/Identifiers.js +2470 -0
- package/dist/cjs/common/nodes/UaAttributes.d.ts +18 -0
- package/dist/cjs/common/nodes/UaAttributes.js +2 -0
- package/dist/cjs/common/nodes/UaDataType.d.ts +15 -0
- package/dist/cjs/common/nodes/UaDataType.js +93 -0
- package/dist/cjs/common/nodes/UaMethod.d.ts +16 -0
- package/dist/cjs/common/nodes/UaMethod.js +77 -0
- package/dist/cjs/common/nodes/UaNode.d.ts +38 -0
- package/dist/cjs/common/nodes/UaNode.js +94 -0
- package/dist/cjs/common/nodes/UaObject.d.ts +16 -0
- package/dist/cjs/common/nodes/UaObject.js +69 -0
- package/dist/cjs/common/nodes/UaObjectType.d.ts +12 -0
- package/dist/cjs/common/nodes/UaObjectType.js +62 -0
- package/dist/cjs/common/nodes/UaReferenceType.d.ts +12 -0
- package/dist/cjs/common/nodes/UaReferenceType.js +33 -0
- package/dist/cjs/common/nodes/UaVariable.d.ts +25 -0
- package/dist/cjs/common/nodes/UaVariable.js +76 -0
- package/dist/cjs/common/nodes/UaVariableType.d.ts +14 -0
- package/dist/cjs/common/nodes/UaVariableType.js +50 -0
- package/dist/cjs/common/nodes/index.d.ts +10 -0
- package/dist/cjs/common/nodes/index.js +26 -0
- package/dist/cjs/common/structure/UaArgument.d.ts +19 -0
- package/dist/cjs/common/structure/UaArgument.js +65 -0
- package/dist/cjs/common/structure/UaContentFilter.d.ts +13 -0
- package/dist/cjs/common/structure/UaContentFilter.js +48 -0
- package/dist/cjs/common/structure/UaContentFilterElement.d.ts +12 -0
- package/dist/cjs/common/structure/UaContentFilterElement.js +43 -0
- package/dist/cjs/common/structure/UaEUInformation.d.ts +18 -0
- package/dist/cjs/common/structure/UaEUInformation.js +56 -0
- package/dist/cjs/common/structure/UaElementOperand.d.ts +12 -0
- package/dist/cjs/common/structure/UaElementOperand.js +36 -0
- package/dist/cjs/common/structure/UaEnumValueType.d.ts +16 -0
- package/dist/cjs/common/structure/UaEnumValueType.js +48 -0
- package/dist/cjs/common/structure/UaEventFilter.d.ts +14 -0
- package/dist/cjs/common/structure/UaEventFilter.js +49 -0
- package/dist/cjs/common/structure/UaHistoryData.d.ts +12 -0
- package/dist/cjs/common/structure/UaHistoryData.js +43 -0
- package/dist/cjs/common/structure/UaHistoryEvent.d.ts +12 -0
- package/dist/cjs/common/structure/UaHistoryEvent.js +59 -0
- package/dist/cjs/common/structure/UaLiteralOperand.d.ts +12 -0
- package/dist/cjs/common/structure/UaLiteralOperand.js +43 -0
- package/dist/cjs/common/structure/UaRange.d.ts +14 -0
- package/dist/cjs/common/structure/UaRange.js +44 -0
- package/dist/cjs/common/structure/UaReadAtTimeDetails.d.ts +14 -0
- package/dist/cjs/common/structure/UaReadAtTimeDetails.js +41 -0
- package/dist/cjs/common/structure/UaReadEventDetails.d.ts +19 -0
- package/dist/cjs/common/structure/UaReadEventDetails.js +57 -0
- package/dist/cjs/common/structure/UaReadRawModifiedDetails.d.ts +20 -0
- package/dist/cjs/common/structure/UaReadRawModifiedDetails.js +58 -0
- package/dist/cjs/common/structure/UaSimpleAttributeOperand.d.ts +14 -0
- package/dist/cjs/common/structure/UaSimpleAttributeOperand.js +43 -0
- package/dist/cjs/common/structure/index.d.ts +15 -0
- package/dist/cjs/common/structure/index.js +31 -0
- package/dist/cjs/common/types/UaDataValue.d.ts +14 -0
- package/dist/cjs/common/types/UaDataValue.js +28 -0
- package/dist/cjs/common/types/UaError.d.ts +6 -0
- package/dist/cjs/common/types/UaError.js +15 -0
- package/dist/cjs/common/types/UaExpandedNodeId.d.ts +15 -0
- package/dist/cjs/common/types/UaExpandedNodeId.js +51 -0
- package/dist/cjs/common/types/UaExtensionObject.d.ts +9 -0
- package/dist/cjs/common/types/UaExtensionObject.js +19 -0
- package/dist/cjs/common/types/UaHistoryDataResult.d.ts +8 -0
- package/dist/cjs/common/types/UaHistoryDataResult.js +16 -0
- package/dist/cjs/common/types/UaHistoryEventFieldList.d.ts +7 -0
- package/dist/cjs/common/types/UaHistoryEventFieldList.js +23 -0
- package/dist/cjs/common/types/UaHistoryEventResult.d.ts +8 -0
- package/dist/cjs/common/types/UaHistoryEventResult.js +16 -0
- package/dist/cjs/common/types/UaLink.d.ts +12 -0
- package/dist/cjs/common/types/UaLink.js +24 -0
- package/dist/cjs/common/types/UaLocalizedText.d.ts +9 -0
- package/dist/cjs/common/types/UaLocalizedText.js +20 -0
- package/dist/cjs/common/types/UaNodeId.d.ts +23 -0
- package/dist/cjs/common/types/UaNodeId.js +154 -0
- package/dist/cjs/common/types/UaQuery.d.ts +11 -0
- package/dist/cjs/common/types/UaQuery.js +82 -0
- package/dist/cjs/common/types/UaQueryFilter.d.ts +27 -0
- package/dist/cjs/common/types/UaQueryFilter.js +74 -0
- package/dist/cjs/common/types/UaRequestPatameters.d.ts +11 -0
- package/dist/cjs/common/types/UaRequestPatameters.js +29 -0
- package/dist/cjs/common/types/UaServiceTypes.d.ts +18 -0
- package/dist/cjs/common/types/UaServiceTypes.js +2 -0
- package/dist/cjs/common/types/UaStatusCode.d.ts +24 -0
- package/dist/cjs/common/types/UaStatusCode.js +76 -0
- package/dist/cjs/common/types/UaTypes.d.ts +12 -0
- package/dist/cjs/common/types/UaTypes.js +2 -0
- package/dist/cjs/common/types/UaVariant.d.ts +89 -0
- package/dist/cjs/common/types/UaVariant.js +384 -0
- package/dist/cjs/common/types/index.d.ts +17 -0
- package/dist/cjs/common/types/index.js +33 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +18 -0
- package/dist/client/UaClientConfigure.d.ts +9 -0
- package/dist/client/UaClientConfigure.js +24 -0
- package/dist/client/UaWebClient.d.ts +38 -0
- package/dist/client/UaWebClient.js +590 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.js +19 -0
- package/dist/client/utils/UaDataTypeDictionary.d.ts +15 -0
- package/dist/client/utils/UaDataTypeDictionary.js +149 -0
- package/dist/client/utils/UaNodeReader.d.ts +83 -0
- package/dist/client/utils/UaNodeReader.js +714 -0
- package/dist/client/utils/UaObjectTypeDictionary.d.ts +12 -0
- package/dist/client/utils/UaObjectTypeDictionary.js +80 -0
- package/dist/client/utils/UaReferenceTypeDictionary.d.ts +12 -0
- package/dist/client/utils/UaReferenceTypeDictionary.js +80 -0
- package/dist/client/utils/index.d.ts +4 -0
- package/dist/client/utils/index.js +20 -0
- package/dist/common/index.d.ts +4 -0
- package/dist/common/index.js +20 -0
- package/dist/common/mapper/UaPayloadMapper.d.ts +18 -0
- package/dist/common/mapper/UaPayloadMapper.js +481 -0
- package/dist/common/mapper/index.d.ts +1 -0
- package/dist/common/mapper/index.js +17 -0
- package/dist/common/nodes/Identifiers.d.ts +2458 -0
- package/dist/common/nodes/Identifiers.js +2470 -0
- package/dist/common/nodes/UaAttributes.d.ts +18 -0
- package/dist/common/nodes/UaAttributes.js +2 -0
- package/dist/common/nodes/UaDataType.d.ts +15 -0
- package/dist/common/nodes/UaDataType.js +93 -0
- package/dist/common/nodes/UaMethod.d.ts +16 -0
- package/dist/common/nodes/UaMethod.js +77 -0
- package/dist/common/nodes/UaNode.d.ts +38 -0
- package/dist/common/nodes/UaNode.js +94 -0
- package/dist/common/nodes/UaObject.d.ts +16 -0
- package/dist/common/nodes/UaObject.js +69 -0
- package/dist/common/nodes/UaObjectType.d.ts +12 -0
- package/dist/common/nodes/UaObjectType.js +62 -0
- package/dist/common/nodes/UaReferenceType.d.ts +12 -0
- package/dist/common/nodes/UaReferenceType.js +33 -0
- package/dist/common/nodes/UaVariable.d.ts +25 -0
- package/dist/common/nodes/UaVariable.js +76 -0
- package/dist/common/nodes/UaVariableType.d.ts +14 -0
- package/dist/common/nodes/UaVariableType.js +50 -0
- package/dist/common/nodes/index.d.ts +10 -0
- package/dist/common/nodes/index.js +26 -0
- package/dist/common/structure/UaArgument.d.ts +19 -0
- package/dist/common/structure/UaArgument.js +65 -0
- package/dist/common/structure/UaContentFilter.d.ts +13 -0
- package/dist/common/structure/UaContentFilter.js +48 -0
- package/dist/common/structure/UaContentFilterElement.d.ts +12 -0
- package/dist/common/structure/UaContentFilterElement.js +43 -0
- package/dist/common/structure/UaEUInformation.d.ts +18 -0
- package/dist/common/structure/UaEUInformation.js +56 -0
- package/dist/common/structure/UaElementOperand.d.ts +12 -0
- package/dist/common/structure/UaElementOperand.js +36 -0
- package/dist/common/structure/UaEnumValueType.d.ts +16 -0
- package/dist/common/structure/UaEnumValueType.js +48 -0
- package/dist/common/structure/UaEventFilter.d.ts +14 -0
- package/dist/common/structure/UaEventFilter.js +49 -0
- package/dist/common/structure/UaHistoryData.d.ts +12 -0
- package/dist/common/structure/UaHistoryData.js +43 -0
- package/dist/common/structure/UaHistoryEvent.d.ts +12 -0
- package/dist/common/structure/UaHistoryEvent.js +59 -0
- package/dist/common/structure/UaLiteralOperand.d.ts +12 -0
- package/dist/common/structure/UaLiteralOperand.js +43 -0
- package/dist/common/structure/UaRange.d.ts +14 -0
- package/dist/common/structure/UaRange.js +44 -0
- package/dist/common/structure/UaReadAtTimeDetails.d.ts +14 -0
- package/dist/common/structure/UaReadAtTimeDetails.js +41 -0
- package/dist/common/structure/UaReadEventDetails.d.ts +19 -0
- package/dist/common/structure/UaReadEventDetails.js +57 -0
- package/dist/common/structure/UaReadRawModifiedDetails.d.ts +20 -0
- package/dist/common/structure/UaReadRawModifiedDetails.js +58 -0
- package/dist/common/structure/UaSimpleAttributeOperand.d.ts +14 -0
- package/dist/common/structure/UaSimpleAttributeOperand.js +43 -0
- package/dist/common/structure/index.d.ts +15 -0
- package/dist/common/structure/index.js +31 -0
- package/dist/common/types/UaDataValue.d.ts +14 -0
- package/dist/common/types/UaDataValue.js +28 -0
- package/dist/common/types/UaError.d.ts +6 -0
- package/dist/common/types/UaError.js +15 -0
- package/dist/common/types/UaExpandedNodeId.d.ts +15 -0
- package/dist/common/types/UaExpandedNodeId.js +51 -0
- package/dist/common/types/UaExtensionObject.d.ts +9 -0
- package/dist/common/types/UaExtensionObject.js +19 -0
- package/dist/common/types/UaHistoryDataResult.d.ts +8 -0
- package/dist/common/types/UaHistoryDataResult.js +16 -0
- package/dist/common/types/UaHistoryEventFieldList.d.ts +7 -0
- package/dist/common/types/UaHistoryEventFieldList.js +23 -0
- package/dist/common/types/UaHistoryEventResult.d.ts +8 -0
- package/dist/common/types/UaHistoryEventResult.js +16 -0
- package/dist/common/types/UaLink.d.ts +12 -0
- package/dist/common/types/UaLink.js +24 -0
- package/dist/common/types/UaLocalizedText.d.ts +9 -0
- package/dist/common/types/UaLocalizedText.js +20 -0
- package/dist/common/types/UaNodeId.d.ts +23 -0
- package/dist/common/types/UaNodeId.js +154 -0
- package/dist/common/types/UaQuery.d.ts +11 -0
- package/dist/common/types/UaQuery.js +82 -0
- package/dist/common/types/UaQueryFilter.d.ts +27 -0
- package/dist/common/types/UaQueryFilter.js +74 -0
- package/dist/common/types/UaRequestPatameters.d.ts +11 -0
- package/dist/common/types/UaRequestPatameters.js +29 -0
- package/dist/common/types/UaServiceTypes.d.ts +18 -0
- package/dist/common/types/UaServiceTypes.js +2 -0
- package/dist/common/types/UaStatusCode.d.ts +24 -0
- package/dist/common/types/UaStatusCode.js +76 -0
- package/dist/common/types/UaTypes.d.ts +12 -0
- package/dist/common/types/UaTypes.js +2 -0
- package/dist/common/types/UaVariant.d.ts +89 -0
- package/dist/common/types/UaVariant.js +384 -0
- package/dist/common/types/index.d.ts +17 -0
- package/dist/common/types/index.js +33 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/package.json +23 -0
|
@@ -0,0 +1,714 @@
|
|
|
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.UaNodeLinkReader = exports.UaNodeChildReader = exports.UaNodeReader = exports.UaNodeReaderBase = void 0;
|
|
13
|
+
const opcua_webapi_1 = require("opcua-webapi");
|
|
14
|
+
const common_1 = require("../../common");
|
|
15
|
+
class UaNodeReaderBase {
|
|
16
|
+
constructor(returnVariables, returnMethod) {
|
|
17
|
+
this._finished = false;
|
|
18
|
+
this._nodesToBrowse = [];
|
|
19
|
+
this._continuationPointToBrowse = [];
|
|
20
|
+
this._browseResults = [];
|
|
21
|
+
this._readResults = new Map;
|
|
22
|
+
this._nodeClassToReturn = 0;
|
|
23
|
+
if (false != returnVariables)
|
|
24
|
+
this._nodeClassToReturn += opcua_webapi_1.NodeClass.Variable;
|
|
25
|
+
if (false != returnMethod)
|
|
26
|
+
this._nodeClassToReturn += opcua_webapi_1.NodeClass.Method;
|
|
27
|
+
if (null == UaNodeReaderBase.s_variableTypeWithoutMember) {
|
|
28
|
+
UaNodeReaderBase.s_variableTypeWithoutMember = new Set;
|
|
29
|
+
UaNodeReaderBase.s_variableTypeWithoutMember.add(new common_1.UaNodeId(common_1.VariableTypeIds.BaseVariableType).toString());
|
|
30
|
+
UaNodeReaderBase.s_variableTypeWithoutMember.add(new common_1.UaNodeId(common_1.VariableTypeIds.PropertyType).toString());
|
|
31
|
+
UaNodeReaderBase.s_variableTypeWithoutMember.add(new common_1.UaNodeId(common_1.VariableTypeIds.BaseDataVariableType).toString());
|
|
32
|
+
}
|
|
33
|
+
if (null == UaNodeReaderBase.s_variableNameToReadValue) {
|
|
34
|
+
UaNodeReaderBase.s_variableNameToReadValue = new Set;
|
|
35
|
+
UaNodeReaderBase.s_variableNameToReadValue.add("InputArguments");
|
|
36
|
+
UaNodeReaderBase.s_variableNameToReadValue.add("OutputArguments");
|
|
37
|
+
UaNodeReaderBase.s_variableNameToReadValue.add("EnumStrings");
|
|
38
|
+
UaNodeReaderBase.s_variableNameToReadValue.add("EnumValues");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
_browseNodes(client) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
var _a;
|
|
44
|
+
let nodesToBrowse = this._nodesToBrowse.splice(0, 50);
|
|
45
|
+
let browseDescriptions = [];
|
|
46
|
+
for (let item of nodesToBrowse) {
|
|
47
|
+
browseDescriptions.push({
|
|
48
|
+
NodeId: item.nodeId.toString(),
|
|
49
|
+
BrowseDirection: opcua_webapi_1.BrowseDirection.Forward,
|
|
50
|
+
ReferenceTypeId: opcua_webapi_1.ReferenceTypeIds.HierarchicalReferences,
|
|
51
|
+
IncludeSubtypes: true,
|
|
52
|
+
NodeClassMask: item.nodeClassToReturn,
|
|
53
|
+
ResultMask: 63
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
let results = yield client.browse(browseDescriptions, 50);
|
|
57
|
+
for (let i = 0; i < nodesToBrowse.length; ++i) {
|
|
58
|
+
let currentNode = nodesToBrowse[i];
|
|
59
|
+
let currentResult = results[i];
|
|
60
|
+
let statusCode = common_1.UaPayloadMapper.statusCodeFromWebApi(currentResult.StatusCode);
|
|
61
|
+
if (statusCode.isNotGood())
|
|
62
|
+
throw new common_1.UaError(statusCode);
|
|
63
|
+
if (!currentResult.References)
|
|
64
|
+
continue;
|
|
65
|
+
for (let item of currentResult.References) {
|
|
66
|
+
let reference = common_1.UaPayloadMapper.referenceDescriptionFromWebApi(item);
|
|
67
|
+
this._browseResults.push({
|
|
68
|
+
fromNodeId: currentNode.nodeId,
|
|
69
|
+
nodeId: reference.nodeId.getNodeId(),
|
|
70
|
+
nodeClass: reference.nodeClass,
|
|
71
|
+
browseName: reference.browseName,
|
|
72
|
+
displayName: reference.displayName,
|
|
73
|
+
referenceTypeId: reference.referenceTypeId,
|
|
74
|
+
isForward: reference.isForward,
|
|
75
|
+
typeDefinitionId: (_a = reference.typeDefinition) === null || _a === void 0 ? void 0 : _a.getNodeId()
|
|
76
|
+
});
|
|
77
|
+
this._updateNodesToBrowse(reference);
|
|
78
|
+
}
|
|
79
|
+
if (currentResult.ContinuationPoint && currentResult.ContinuationPoint.length != 0) {
|
|
80
|
+
this._continuationPointToBrowse.push({
|
|
81
|
+
nodeId: currentNode.nodeId,
|
|
82
|
+
continuationPoint: currentResult.ContinuationPoint
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
_browseContinuationPoints(client) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
var _a;
|
|
91
|
+
let cpsToBrowse = this._continuationPointToBrowse.splice(0, 50);
|
|
92
|
+
let continuationPoints = [];
|
|
93
|
+
for (let item of cpsToBrowse) {
|
|
94
|
+
continuationPoints.push(item.continuationPoint);
|
|
95
|
+
}
|
|
96
|
+
let results = yield client.browseNext(continuationPoints, false);
|
|
97
|
+
for (let i = 0; i < cpsToBrowse.length; ++i) {
|
|
98
|
+
let currentNode = cpsToBrowse[i];
|
|
99
|
+
let currentResult = results[i];
|
|
100
|
+
let statusCode = common_1.UaPayloadMapper.statusCodeFromWebApi(currentResult.StatusCode);
|
|
101
|
+
if (statusCode.isNotGood())
|
|
102
|
+
throw new common_1.UaError(statusCode);
|
|
103
|
+
if (!currentResult.References)
|
|
104
|
+
continue;
|
|
105
|
+
for (let item of currentResult.References) {
|
|
106
|
+
let reference = common_1.UaPayloadMapper.referenceDescriptionFromWebApi(item);
|
|
107
|
+
this._browseResults.push({
|
|
108
|
+
fromNodeId: currentNode.nodeId,
|
|
109
|
+
nodeId: reference.nodeId.getNodeId(),
|
|
110
|
+
nodeClass: reference.nodeClass,
|
|
111
|
+
browseName: reference.browseName,
|
|
112
|
+
displayName: reference.displayName,
|
|
113
|
+
referenceTypeId: reference.referenceTypeId,
|
|
114
|
+
isForward: reference.isForward,
|
|
115
|
+
typeDefinitionId: (_a = reference.typeDefinition) === null || _a === void 0 ? void 0 : _a.getNodeId()
|
|
116
|
+
});
|
|
117
|
+
this._updateNodesToBrowse(reference);
|
|
118
|
+
}
|
|
119
|
+
if (currentResult.ContinuationPoint && currentResult.ContinuationPoint.length != 0) {
|
|
120
|
+
this._continuationPointToBrowse.push({
|
|
121
|
+
nodeId: currentNode.nodeId,
|
|
122
|
+
continuationPoint: currentResult.ContinuationPoint
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
_readNodes(client) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
if (this._browseResults.length == 0)
|
|
131
|
+
return;
|
|
132
|
+
let nodesToRead = this._browseResults.splice(0, 100);
|
|
133
|
+
yield this._readTypes(nodesToRead, client);
|
|
134
|
+
yield this._readObjects(nodesToRead, client);
|
|
135
|
+
yield this._readVariables(nodesToRead, client);
|
|
136
|
+
yield this._readMethods(nodesToRead, client);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
_buildNodeTree() {
|
|
140
|
+
if (this._finished)
|
|
141
|
+
return;
|
|
142
|
+
for (let item of this._readResults) {
|
|
143
|
+
let childNode = item[1].node;
|
|
144
|
+
let parentNode = this._readResults.get(item[1].parentId.toString());
|
|
145
|
+
if (!parentNode)
|
|
146
|
+
continue;
|
|
147
|
+
if (opcua_webapi_1.NodeClass.Object == parentNode.node.nodeClass) {
|
|
148
|
+
let parent = parentNode.node;
|
|
149
|
+
if (opcua_webapi_1.NodeClass.Variable == childNode.nodeClass ||
|
|
150
|
+
opcua_webapi_1.NodeClass.Method == childNode.nodeClass) {
|
|
151
|
+
parent.addMember(childNode);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else if (opcua_webapi_1.NodeClass.Variable == parentNode.node.nodeClass) {
|
|
155
|
+
let parent = parentNode.node;
|
|
156
|
+
if (opcua_webapi_1.NodeClass.Variable == childNode.nodeClass) {
|
|
157
|
+
parent.addMember(childNode);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else if (opcua_webapi_1.NodeClass.Method == parentNode.node.nodeClass) {
|
|
161
|
+
let parent = parentNode.node;
|
|
162
|
+
if (opcua_webapi_1.NodeClass.Variable == childNode.nodeClass) {
|
|
163
|
+
parent.addMember(childNode);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else if (opcua_webapi_1.NodeClass.ObjectType == parentNode.node.nodeClass) {
|
|
167
|
+
let parent = parentNode.node;
|
|
168
|
+
if (opcua_webapi_1.NodeClass.Variable == childNode.nodeClass ||
|
|
169
|
+
opcua_webapi_1.NodeClass.Method == childNode.nodeClass) {
|
|
170
|
+
parent.addMember(childNode);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else if (opcua_webapi_1.NodeClass.VariableType == parentNode.node.nodeClass) {
|
|
174
|
+
let parent = parentNode.node;
|
|
175
|
+
if (opcua_webapi_1.NodeClass.Variable == childNode.nodeClass) {
|
|
176
|
+
parent.addMember(childNode);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else if (opcua_webapi_1.NodeClass.DataType == parentNode.node.nodeClass) {
|
|
180
|
+
let parent = parentNode.node;
|
|
181
|
+
if (opcua_webapi_1.NodeClass.Variable == childNode.nodeClass) {
|
|
182
|
+
parent.setEnumVariable(childNode);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
this._finished = true;
|
|
187
|
+
}
|
|
188
|
+
_readTypes(references, client) {
|
|
189
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
+
let typesToRead = [];
|
|
191
|
+
for (let item of references) {
|
|
192
|
+
if (item.nodeClass != opcua_webapi_1.NodeClass.ObjectType &&
|
|
193
|
+
item.nodeClass != opcua_webapi_1.NodeClass.DataType &&
|
|
194
|
+
item.nodeClass != opcua_webapi_1.NodeClass.VariableType &&
|
|
195
|
+
item.nodeClass != opcua_webapi_1.NodeClass.ReferenceType)
|
|
196
|
+
continue;
|
|
197
|
+
typesToRead.push(item);
|
|
198
|
+
}
|
|
199
|
+
if (0 == typesToRead.length)
|
|
200
|
+
return;
|
|
201
|
+
let nodesToRead = [];
|
|
202
|
+
for (let item of typesToRead) {
|
|
203
|
+
nodesToRead.push({
|
|
204
|
+
NodeId: item.nodeId.toString(),
|
|
205
|
+
AttributeId: opcua_webapi_1.Attributes.IsAbstract
|
|
206
|
+
});
|
|
207
|
+
if (item.nodeClass == opcua_webapi_1.NodeClass.VariableType) {
|
|
208
|
+
nodesToRead.push({
|
|
209
|
+
NodeId: item.nodeId.toString(),
|
|
210
|
+
AttributeId: opcua_webapi_1.Attributes.DataType
|
|
211
|
+
});
|
|
212
|
+
nodesToRead.push({
|
|
213
|
+
NodeId: item.nodeId.toString(),
|
|
214
|
+
AttributeId: opcua_webapi_1.Attributes.ValueRank
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
let results = yield client.read(nodesToRead);
|
|
219
|
+
let dataValues = [];
|
|
220
|
+
for (let item of results) {
|
|
221
|
+
dataValues.push(common_1.UaPayloadMapper.dataValueFromWebApi(item));
|
|
222
|
+
}
|
|
223
|
+
for (let i = 0; i < typesToRead.length; ++i) {
|
|
224
|
+
let dataIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? i * 3 : i;
|
|
225
|
+
if (dataValues[dataIndex].statusCode.isNotGood())
|
|
226
|
+
throw new common_1.UaError(dataValues[dataIndex].statusCode);
|
|
227
|
+
let isAbstract = dataValues[dataIndex].value.toBoolean();
|
|
228
|
+
if (null == isAbstract)
|
|
229
|
+
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
230
|
+
let dataType = common_1.UaNodeId.nullNodeId;
|
|
231
|
+
let valueRank = -1;
|
|
232
|
+
if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) {
|
|
233
|
+
if (dataValues[dataIndex + 1].statusCode.isNotGood())
|
|
234
|
+
throw new common_1.UaError(dataValues[dataIndex + 1].statusCode);
|
|
235
|
+
if (dataValues[dataIndex + 2].statusCode.isNotGood())
|
|
236
|
+
throw new common_1.UaError(dataValues[dataIndex + 2].statusCode);
|
|
237
|
+
dataType = dataValues[dataIndex + 1].value.toNodeId();
|
|
238
|
+
valueRank = dataValues[dataIndex + 2].value.toNumber();
|
|
239
|
+
if (null == dataType || null == valueRank)
|
|
240
|
+
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
241
|
+
}
|
|
242
|
+
let typeNode;
|
|
243
|
+
if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.ObjectType) {
|
|
244
|
+
typeNode = new common_1.UaObjectType(typesToRead[i].nodeId, typesToRead[i].browseName, typesToRead[i].displayName, isAbstract);
|
|
245
|
+
}
|
|
246
|
+
else if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.DataType) {
|
|
247
|
+
typeNode = new common_1.UaDataType(typesToRead[i].nodeId, typesToRead[i].browseName, typesToRead[i].displayName, isAbstract);
|
|
248
|
+
}
|
|
249
|
+
else if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) {
|
|
250
|
+
typeNode = new common_1.UaVariableType(typesToRead[i].nodeId, typesToRead[i].browseName, typesToRead[i].displayName, isAbstract, dataType, valueRank);
|
|
251
|
+
}
|
|
252
|
+
else if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.ReferenceType) {
|
|
253
|
+
typeNode = new common_1.UaReferenceType(typesToRead[i].nodeId, typesToRead[i].browseName, typesToRead[i].displayName, isAbstract, common_1.UaLocalizedText.nullText, false);
|
|
254
|
+
}
|
|
255
|
+
typeNode.refToParent = typesToRead[i].referenceTypeId;
|
|
256
|
+
this._readResults.set(typeNode.nodeId.toString(), {
|
|
257
|
+
parentId: typesToRead[i].fromNodeId,
|
|
258
|
+
node: typeNode
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
_readObjects(references, client) {
|
|
264
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
265
|
+
let objectsToRead = [];
|
|
266
|
+
for (let item of references) {
|
|
267
|
+
if (item.nodeClass != opcua_webapi_1.NodeClass.Object)
|
|
268
|
+
continue;
|
|
269
|
+
objectsToRead.push(item);
|
|
270
|
+
}
|
|
271
|
+
if (0 == objectsToRead.length)
|
|
272
|
+
return;
|
|
273
|
+
let nodesToRead = [];
|
|
274
|
+
for (let item of objectsToRead) {
|
|
275
|
+
nodesToRead.push({
|
|
276
|
+
NodeId: item.nodeId.toString(),
|
|
277
|
+
AttributeId: opcua_webapi_1.Attributes.EventNotifier
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
let results = yield client.read(nodesToRead);
|
|
281
|
+
let dataValues = [];
|
|
282
|
+
for (let item of results) {
|
|
283
|
+
dataValues.push(common_1.UaPayloadMapper.dataValueFromWebApi(item));
|
|
284
|
+
}
|
|
285
|
+
for (let i = 0; i < objectsToRead.length; ++i) {
|
|
286
|
+
if (dataValues[i].statusCode.isNotGood())
|
|
287
|
+
throw new common_1.UaError(dataValues[i].statusCode);
|
|
288
|
+
let eventNotifier = dataValues[i].value.toNumber();
|
|
289
|
+
if (null == eventNotifier || undefined == objectsToRead[i].typeDefinitionId)
|
|
290
|
+
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
291
|
+
let objectNode = new common_1.UaObject(objectsToRead[i].nodeId, objectsToRead[i].browseName, objectsToRead[i].displayName, eventNotifier, objectsToRead[i].typeDefinitionId);
|
|
292
|
+
objectNode.refToParent = objectsToRead[i].referenceTypeId;
|
|
293
|
+
this._readResults.set(objectNode.nodeId.toString(), {
|
|
294
|
+
parentId: objectsToRead[i].fromNodeId,
|
|
295
|
+
node: objectNode
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
_readVariables(references, client) {
|
|
301
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
302
|
+
let variablesToRead = [];
|
|
303
|
+
let nodeIds = [];
|
|
304
|
+
for (let item of references) {
|
|
305
|
+
if (item.nodeClass != opcua_webapi_1.NodeClass.Variable)
|
|
306
|
+
continue;
|
|
307
|
+
variablesToRead.push(item);
|
|
308
|
+
nodeIds.push(item.nodeId);
|
|
309
|
+
}
|
|
310
|
+
if (0 == nodeIds.length)
|
|
311
|
+
return;
|
|
312
|
+
let results = yield client.readVariableAttributes(nodeIds);
|
|
313
|
+
let valuesToRead = [];
|
|
314
|
+
for (let i = 0; i < variablesToRead.length; ++i) {
|
|
315
|
+
let variableNode = new common_1.UaVariable(variablesToRead[i].nodeId, variablesToRead[i].browseName, variablesToRead[i].displayName, results[i].dataType, results[i].valueRank, results[i].accessLevel, results[i].userAccessLevel, results[i].historizing, variablesToRead[i].typeDefinitionId);
|
|
316
|
+
this._readResults.set(variableNode.nodeId.toString(), {
|
|
317
|
+
parentId: variablesToRead[i].fromNodeId,
|
|
318
|
+
node: variableNode
|
|
319
|
+
});
|
|
320
|
+
if (UaNodeReaderBase.s_variableNameToReadValue.has(variableNode.browseName))
|
|
321
|
+
valuesToRead.push(variableNode.nodeId);
|
|
322
|
+
}
|
|
323
|
+
if (valuesToRead.length != 0) {
|
|
324
|
+
let values = yield client.readValues(valuesToRead);
|
|
325
|
+
for (let i = 0; i < valuesToRead.length; ++i) {
|
|
326
|
+
if (values[i].statusCode.isNotGood())
|
|
327
|
+
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
328
|
+
let variableNode = this._readResults.get(valuesToRead[i].toString());
|
|
329
|
+
variableNode.node.value = values[i].value;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
_readMethods(references, client) {
|
|
335
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
336
|
+
for (let item of references) {
|
|
337
|
+
if (item.nodeClass != opcua_webapi_1.NodeClass.Method)
|
|
338
|
+
continue;
|
|
339
|
+
let methodNode = new common_1.UaMethod(item.nodeId, item.browseName, item.displayName);
|
|
340
|
+
this._readResults.set(methodNode.nodeId.toString(), {
|
|
341
|
+
parentId: item.fromNodeId,
|
|
342
|
+
node: methodNode
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
_updateNodesToBrowse(reference) {
|
|
348
|
+
let nodeClassToReturn = opcua_webapi_1.NodeClass.Unspecified;
|
|
349
|
+
if (reference.nodeClass == opcua_webapi_1.NodeClass.ObjectType ||
|
|
350
|
+
reference.nodeClass == opcua_webapi_1.NodeClass.Object) {
|
|
351
|
+
nodeClassToReturn = this._nodeClassToReturn;
|
|
352
|
+
}
|
|
353
|
+
else if (reference.nodeClass == opcua_webapi_1.NodeClass.Variable) {
|
|
354
|
+
if (reference.typeDefinition &&
|
|
355
|
+
!UaNodeReaderBase.s_variableTypeWithoutMember.has(reference.typeDefinition.getNodeId().toString())) {
|
|
356
|
+
nodeClassToReturn = opcua_webapi_1.NodeClass.Variable;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
else if (reference.nodeClass == opcua_webapi_1.NodeClass.Method ||
|
|
360
|
+
reference.nodeClass == opcua_webapi_1.NodeClass.VariableType ||
|
|
361
|
+
reference.nodeClass == opcua_webapi_1.NodeClass.DataType) {
|
|
362
|
+
nodeClassToReturn = opcua_webapi_1.NodeClass.Variable;
|
|
363
|
+
}
|
|
364
|
+
if (opcua_webapi_1.NodeClass.Unspecified != nodeClassToReturn) {
|
|
365
|
+
this._nodesToBrowse.push({
|
|
366
|
+
nodeId: reference.nodeId.getNodeId(),
|
|
367
|
+
nodeClassToReturn: nodeClassToReturn
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
exports.UaNodeReaderBase = UaNodeReaderBase;
|
|
373
|
+
UaNodeReaderBase.s_variableTypeWithoutMember = null;
|
|
374
|
+
UaNodeReaderBase.s_variableNameToReadValue = null;
|
|
375
|
+
class UaNodeReader extends UaNodeReaderBase {
|
|
376
|
+
constructor(nodeIds, returnVariables, returnMethod) {
|
|
377
|
+
super(returnVariables, returnMethod);
|
|
378
|
+
if (nodeIds.length == 0)
|
|
379
|
+
this._finished = true;
|
|
380
|
+
this._nodeIds = new Set;
|
|
381
|
+
for (let item of nodeIds) {
|
|
382
|
+
this._nodeIds.add(item.toString());
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
readAll(client) {
|
|
386
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
387
|
+
if (this.isFinish())
|
|
388
|
+
return;
|
|
389
|
+
yield this.read(client);
|
|
390
|
+
yield this.readAll(client);
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
read(client) {
|
|
394
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
395
|
+
if (this._finished)
|
|
396
|
+
return;
|
|
397
|
+
if (!this._isRootNodeRead) {
|
|
398
|
+
yield this._readRootNodes(client);
|
|
399
|
+
}
|
|
400
|
+
else if (this._continuationPointToBrowse.length != 0) {
|
|
401
|
+
yield this._browseContinuationPoints(client);
|
|
402
|
+
}
|
|
403
|
+
else if (this._nodesToBrowse.length != 0) {
|
|
404
|
+
yield this._browseNodes(client);
|
|
405
|
+
}
|
|
406
|
+
else if (this._browseResults.length != 0) {
|
|
407
|
+
yield this._readNodes(client);
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
this._buildNodeTree();
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
isFinish() {
|
|
415
|
+
return this._finished;
|
|
416
|
+
}
|
|
417
|
+
getResults() {
|
|
418
|
+
let ret = [];
|
|
419
|
+
for (let item of this._readResults) {
|
|
420
|
+
if (!this._nodeIds.has(item[1].node.nodeId.toString()))
|
|
421
|
+
continue;
|
|
422
|
+
ret.push(item[1].node);
|
|
423
|
+
}
|
|
424
|
+
return [...ret.values()];
|
|
425
|
+
}
|
|
426
|
+
_readRootNodes(client) {
|
|
427
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
428
|
+
if (this._isRootNodeRead)
|
|
429
|
+
return;
|
|
430
|
+
let nodeIds = [];
|
|
431
|
+
let nodesToRead = [];
|
|
432
|
+
for (let item of this._nodeIds) {
|
|
433
|
+
nodeIds.push((0, common_1.parseUaNodeId)(item));
|
|
434
|
+
nodesToRead.push({
|
|
435
|
+
NodeId: item,
|
|
436
|
+
AttributeId: opcua_webapi_1.Attributes.NodeClass
|
|
437
|
+
});
|
|
438
|
+
nodesToRead.push({
|
|
439
|
+
NodeId: item,
|
|
440
|
+
AttributeId: opcua_webapi_1.Attributes.BrowseName
|
|
441
|
+
});
|
|
442
|
+
nodesToRead.push({
|
|
443
|
+
NodeId: item,
|
|
444
|
+
AttributeId: opcua_webapi_1.Attributes.DisplayName
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
let results = yield client.read(nodesToRead);
|
|
448
|
+
let dataValues = [];
|
|
449
|
+
for (let item of results) {
|
|
450
|
+
dataValues.push(common_1.UaPayloadMapper.dataValueFromWebApi(item));
|
|
451
|
+
}
|
|
452
|
+
let browseResults = new Map;
|
|
453
|
+
for (let i = 0; i < nodeIds.length; ++i) {
|
|
454
|
+
let dataIndex = i * 3;
|
|
455
|
+
let currentNodeId = nodeIds[i];
|
|
456
|
+
if (dataValues[dataIndex].statusCode.isNotGood())
|
|
457
|
+
throw new common_1.UaError(dataValues[dataIndex].statusCode);
|
|
458
|
+
if (dataValues[dataIndex + 1].statusCode.isNotGood())
|
|
459
|
+
throw new common_1.UaError(dataValues[dataIndex + 1].statusCode);
|
|
460
|
+
if (dataValues[dataIndex + 2].statusCode.isNotGood())
|
|
461
|
+
throw new common_1.UaError(dataValues[dataIndex + 2].statusCode);
|
|
462
|
+
let nodeClass = dataValues[dataIndex].value.toNumber();
|
|
463
|
+
let browseName = dataValues[dataIndex + 1].value.toString();
|
|
464
|
+
let displayName = dataValues[dataIndex + 2].value.toLocalizedText();
|
|
465
|
+
if (null == nodeClass || null == browseName || null == displayName)
|
|
466
|
+
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
467
|
+
if (opcua_webapi_1.NodeClass.Unspecified != this._nodeClassToReturn) {
|
|
468
|
+
this._nodesToBrowse.push({
|
|
469
|
+
nodeId: currentNodeId,
|
|
470
|
+
nodeClassToReturn: this._nodeClassToReturn
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
browseResults.set(currentNodeId.toString(), {
|
|
474
|
+
fromNodeId: common_1.UaNodeId.nullNodeId,
|
|
475
|
+
nodeId: currentNodeId,
|
|
476
|
+
nodeClass: nodeClass,
|
|
477
|
+
browseName: browseName,
|
|
478
|
+
displayName: displayName,
|
|
479
|
+
referenceTypeId: common_1.UaNodeId.nullNodeId,
|
|
480
|
+
isForward: true,
|
|
481
|
+
typeDefinitionId: common_1.UaNodeId.nullNodeId
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
let browseDescriptions = [];
|
|
485
|
+
for (let item of browseResults) {
|
|
486
|
+
if (item[1].nodeClass != opcua_webapi_1.NodeClass.Object &&
|
|
487
|
+
item[1].nodeClass != opcua_webapi_1.NodeClass.Variable)
|
|
488
|
+
continue;
|
|
489
|
+
browseDescriptions.push({
|
|
490
|
+
NodeId: item[0],
|
|
491
|
+
BrowseDirection: opcua_webapi_1.BrowseDirection.Forward,
|
|
492
|
+
ReferenceTypeId: opcua_webapi_1.ReferenceTypeIds.HasTypeDefinition,
|
|
493
|
+
IncludeSubtypes: false,
|
|
494
|
+
NodeClassMask: opcua_webapi_1.NodeClass.ObjectType | opcua_webapi_1.NodeClass.VariableType,
|
|
495
|
+
ResultMask: 0
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
if (browseDescriptions.length != 0) {
|
|
499
|
+
let results = yield client.browse(browseDescriptions);
|
|
500
|
+
for (let i = 0; i < browseDescriptions.length; ++i) {
|
|
501
|
+
let browseResult = browseResults.get(browseDescriptions[i].NodeId);
|
|
502
|
+
if (undefined == browseResult)
|
|
503
|
+
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadUnexpectedError));
|
|
504
|
+
let statusCode = common_1.UaPayloadMapper.statusCodeFromWebApi(results[i].StatusCode);
|
|
505
|
+
if (statusCode.isNotGood())
|
|
506
|
+
throw new common_1.UaError(statusCode);
|
|
507
|
+
if (!results[i].References || results[i].References.length != 1)
|
|
508
|
+
continue;
|
|
509
|
+
let reference = common_1.UaPayloadMapper.referenceDescriptionFromWebApi(results[i].References[0]);
|
|
510
|
+
browseResult.typeDefinitionId = reference.nodeId.getNodeId();
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
this._browseResults = Array.from(browseResults.values());
|
|
514
|
+
this._isRootNodeRead = true;
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
exports.UaNodeReader = UaNodeReader;
|
|
519
|
+
class UaNodeChildReader extends UaNodeReaderBase {
|
|
520
|
+
constructor(nodeIds, returnVariables, returnMethod) {
|
|
521
|
+
super(returnVariables, returnMethod);
|
|
522
|
+
if (nodeIds.length == 0)
|
|
523
|
+
this._finished = true;
|
|
524
|
+
this._nodeIds = new Set;
|
|
525
|
+
for (let item of nodeIds) {
|
|
526
|
+
this._nodeIds.add(item.toString());
|
|
527
|
+
this._nodesToBrowse.push({
|
|
528
|
+
nodeId: item,
|
|
529
|
+
nodeClassToReturn: opcua_webapi_1.NodeClass.Object | opcua_webapi_1.NodeClass.ObjectType | opcua_webapi_1.NodeClass.VariableType | opcua_webapi_1.NodeClass.DataType
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
readAll(client) {
|
|
534
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
535
|
+
if (this.isFinish())
|
|
536
|
+
return;
|
|
537
|
+
yield this.read(client);
|
|
538
|
+
yield this.readAll(client);
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
read(client) {
|
|
542
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
543
|
+
if (this._finished)
|
|
544
|
+
return;
|
|
545
|
+
if (this._continuationPointToBrowse.length != 0) {
|
|
546
|
+
yield this._browseContinuationPoints(client);
|
|
547
|
+
}
|
|
548
|
+
else if (this._nodesToBrowse.length != 0) {
|
|
549
|
+
yield this._browseNodes(client);
|
|
550
|
+
}
|
|
551
|
+
else if (this._browseResults.length != 0) {
|
|
552
|
+
yield this._readNodes(client);
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
this._buildNodeTree();
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
isFinish() {
|
|
560
|
+
return this._finished;
|
|
561
|
+
}
|
|
562
|
+
getResults() {
|
|
563
|
+
let ret = new Map;
|
|
564
|
+
for (let item of this._readResults) {
|
|
565
|
+
if (!this._nodeIds.has(item[1].parentId.toString()))
|
|
566
|
+
continue;
|
|
567
|
+
let result;
|
|
568
|
+
let parentId = item[1].parentId.toString();
|
|
569
|
+
if (ret.has(parentId)) {
|
|
570
|
+
result = ret.get(parentId);
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
result = { nodeId: item[1].parentId, children: [] };
|
|
574
|
+
ret.set(parentId, result);
|
|
575
|
+
}
|
|
576
|
+
result.children.push(item[1].node);
|
|
577
|
+
}
|
|
578
|
+
return [...ret.values()];
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
exports.UaNodeChildReader = UaNodeChildReader;
|
|
582
|
+
class UaNodeLinkReader {
|
|
583
|
+
constructor(nodeIds) {
|
|
584
|
+
this._nodesToBrowse = nodeIds;
|
|
585
|
+
this._continuationPointToBrowse = [];
|
|
586
|
+
this._browseResults = [];
|
|
587
|
+
}
|
|
588
|
+
readAll(client) {
|
|
589
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
590
|
+
if (this.isFinish())
|
|
591
|
+
return;
|
|
592
|
+
yield this.read(client);
|
|
593
|
+
yield this.readAll(client);
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
read(client) {
|
|
597
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
598
|
+
if (this.isFinish())
|
|
599
|
+
return;
|
|
600
|
+
if (this._nodesToBrowse.length != 0) {
|
|
601
|
+
yield this._browseNodes(client);
|
|
602
|
+
}
|
|
603
|
+
else if (this._continuationPointToBrowse.length != 0) {
|
|
604
|
+
yield this._browseContinuationPoints(client);
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
isFinish() {
|
|
609
|
+
return this._nodesToBrowse.length == 0 && this._continuationPointToBrowse.length == 0;
|
|
610
|
+
}
|
|
611
|
+
getResults() {
|
|
612
|
+
let ret = new Map;
|
|
613
|
+
for (let item of this._browseResults) {
|
|
614
|
+
let result = ret.get(item.fromNodeId.toString());
|
|
615
|
+
if (!result) {
|
|
616
|
+
result = {
|
|
617
|
+
nodeId: item.fromNodeId,
|
|
618
|
+
links: []
|
|
619
|
+
};
|
|
620
|
+
ret.set(item.fromNodeId.toString(), result);
|
|
621
|
+
}
|
|
622
|
+
result.links.push(new common_1.UaLink(item.nodeId, item.nodeClass, item.referenceTypeId, item.isForward));
|
|
623
|
+
}
|
|
624
|
+
return [...ret.values()];
|
|
625
|
+
}
|
|
626
|
+
_browseNodes(client) {
|
|
627
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
628
|
+
var _a;
|
|
629
|
+
if (this._nodesToBrowse.length == 0)
|
|
630
|
+
return;
|
|
631
|
+
let nodesToBrowse = this._nodesToBrowse.splice(0, 50);
|
|
632
|
+
let browseDescriptions = [];
|
|
633
|
+
for (let item of nodesToBrowse) {
|
|
634
|
+
browseDescriptions.push({
|
|
635
|
+
NodeId: item.toString(),
|
|
636
|
+
BrowseDirection: opcua_webapi_1.BrowseDirection.Both,
|
|
637
|
+
ReferenceTypeId: opcua_webapi_1.ReferenceTypeIds.NonHierarchicalReferences,
|
|
638
|
+
IncludeSubtypes: true,
|
|
639
|
+
NodeClassMask: opcua_webapi_1.NodeClass.Object | opcua_webapi_1.NodeClass.Variable | opcua_webapi_1.NodeClass.Method,
|
|
640
|
+
ResultMask: 7
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
let results = yield client.browse(browseDescriptions, 50);
|
|
644
|
+
for (let i = 0; i < nodesToBrowse.length; ++i) {
|
|
645
|
+
let currentNodeId = nodesToBrowse[i];
|
|
646
|
+
let currentResult = results[i];
|
|
647
|
+
let statusCode = common_1.UaPayloadMapper.statusCodeFromWebApi(currentResult.StatusCode);
|
|
648
|
+
if (statusCode.isNotGood())
|
|
649
|
+
throw new common_1.UaError(statusCode);
|
|
650
|
+
if (!currentResult.References)
|
|
651
|
+
continue;
|
|
652
|
+
for (let item of currentResult.References) {
|
|
653
|
+
let reference = common_1.UaPayloadMapper.referenceDescriptionFromWebApi(item);
|
|
654
|
+
this._browseResults.push({
|
|
655
|
+
fromNodeId: currentNodeId,
|
|
656
|
+
nodeId: reference.nodeId.getNodeId(),
|
|
657
|
+
nodeClass: reference.nodeClass,
|
|
658
|
+
browseName: reference.browseName,
|
|
659
|
+
displayName: reference.displayName,
|
|
660
|
+
referenceTypeId: reference.referenceTypeId,
|
|
661
|
+
isForward: reference.isForward,
|
|
662
|
+
typeDefinitionId: (_a = reference.typeDefinition) === null || _a === void 0 ? void 0 : _a.getNodeId()
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
if (currentResult.ContinuationPoint && currentResult.ContinuationPoint.length != 0) {
|
|
666
|
+
this._continuationPointToBrowse.push({
|
|
667
|
+
nodeId: currentNodeId,
|
|
668
|
+
continuationPoint: currentResult.ContinuationPoint
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
_browseContinuationPoints(client) {
|
|
675
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
676
|
+
var _a;
|
|
677
|
+
let cpsToBrowse = this._continuationPointToBrowse.splice(0, 50);
|
|
678
|
+
let continuationPoints = [];
|
|
679
|
+
for (let item of cpsToBrowse) {
|
|
680
|
+
continuationPoints.push(item.continuationPoint);
|
|
681
|
+
}
|
|
682
|
+
let results = yield client.browseNext(continuationPoints, false);
|
|
683
|
+
for (let i = 0; i < cpsToBrowse.length; ++i) {
|
|
684
|
+
let currentNodeId = cpsToBrowse[i].nodeId;
|
|
685
|
+
let currentResult = results[i];
|
|
686
|
+
let statusCode = common_1.UaPayloadMapper.statusCodeFromWebApi(currentResult.StatusCode);
|
|
687
|
+
if (statusCode.isNotGood())
|
|
688
|
+
throw new common_1.UaError(statusCode);
|
|
689
|
+
if (!currentResult.References)
|
|
690
|
+
continue;
|
|
691
|
+
for (let item of currentResult.References) {
|
|
692
|
+
let reference = common_1.UaPayloadMapper.referenceDescriptionFromWebApi(item);
|
|
693
|
+
this._browseResults.push({
|
|
694
|
+
fromNodeId: currentNodeId,
|
|
695
|
+
nodeId: reference.nodeId.getNodeId(),
|
|
696
|
+
nodeClass: reference.nodeClass,
|
|
697
|
+
browseName: reference.browseName,
|
|
698
|
+
displayName: reference.displayName,
|
|
699
|
+
referenceTypeId: reference.referenceTypeId,
|
|
700
|
+
isForward: reference.isForward,
|
|
701
|
+
typeDefinitionId: (_a = reference.typeDefinition) === null || _a === void 0 ? void 0 : _a.getNodeId()
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
if (currentResult.ContinuationPoint && currentResult.ContinuationPoint.length != 0) {
|
|
705
|
+
this._continuationPointToBrowse.push({
|
|
706
|
+
nodeId: currentNodeId,
|
|
707
|
+
continuationPoint: currentResult.ContinuationPoint
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
exports.UaNodeLinkReader = UaNodeLinkReader;
|