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,481 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UaPayloadMapper = void 0;
|
|
4
|
+
const opcua_webapi_1 = require("opcua-webapi");
|
|
5
|
+
const opcua_webapi_2 = require("opcua-webapi");
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
const types_2 = require("../types");
|
|
8
|
+
class UaPayloadMapper {
|
|
9
|
+
static statusCodeFromWebApi(statusCode) {
|
|
10
|
+
if (!statusCode)
|
|
11
|
+
return (0, types_1.makeUaStatusCode)();
|
|
12
|
+
return (0, types_1.makeUaStatusCode)(statusCode.Code);
|
|
13
|
+
}
|
|
14
|
+
static statusCodeToWebApi(statusCode) {
|
|
15
|
+
return { Code: statusCode.value };
|
|
16
|
+
}
|
|
17
|
+
static localizedTextFromWebApi(text) {
|
|
18
|
+
if (!text || !text.Text)
|
|
19
|
+
return null;
|
|
20
|
+
return new types_2.UaLocalizedText(text.Text, text.Locale);
|
|
21
|
+
}
|
|
22
|
+
static localizedTextToWebApi(text) {
|
|
23
|
+
return {
|
|
24
|
+
Text: text.text,
|
|
25
|
+
Locale: (text.locale) ? text.locale : undefined
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
static extensionObjectFromWebApi(json) {
|
|
29
|
+
try {
|
|
30
|
+
let extensionObject = (0, opcua_webapi_1.ExtensionObjectFromJSON)(json);
|
|
31
|
+
if (null !== extensionObject) {
|
|
32
|
+
let typeId = (0, types_1.parseUaNodeId)(extensionObject.UaTypeId);
|
|
33
|
+
let jsonStr = atob(extensionObject.UaBody);
|
|
34
|
+
let body = JSON.parse(jsonStr);
|
|
35
|
+
return new types_2.UaExtensionObject(typeId, body);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
static extensionObjectToWebApi(extentionObject) {
|
|
43
|
+
return {
|
|
44
|
+
UaTypeId: extentionObject.typeId.toString(),
|
|
45
|
+
UaBody: btoa(JSON.stringify(extentionObject.body))
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
static variantFromWebApi(variant) {
|
|
49
|
+
let dataType = variant.UaType;
|
|
50
|
+
let value = variant.Value;
|
|
51
|
+
let variantToReturn = new types_2.UaVariant();
|
|
52
|
+
if (undefined == dataType || null == dataType || types_1.UaVariantType.Null == dataType ||
|
|
53
|
+
undefined == value || null == value)
|
|
54
|
+
return variantToReturn;
|
|
55
|
+
let isArray = Array.isArray(value);
|
|
56
|
+
try {
|
|
57
|
+
if (types_1.UaVariantType.Int32 == dataType ||
|
|
58
|
+
types_1.UaVariantType.UInt32 == dataType ||
|
|
59
|
+
types_1.UaVariantType.Int16 == dataType ||
|
|
60
|
+
types_1.UaVariantType.UInt16 == dataType ||
|
|
61
|
+
types_1.UaVariantType.SByte == dataType ||
|
|
62
|
+
types_1.UaVariantType.Byte == dataType ||
|
|
63
|
+
types_1.UaVariantType.Int64 == dataType ||
|
|
64
|
+
types_1.UaVariantType.UInt64 == dataType) {
|
|
65
|
+
if (!isArray) {
|
|
66
|
+
if (typeof value === "number") {
|
|
67
|
+
return types_2.UaVariant.integer(value, dataType);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
if (value.every(item => typeof item === 'number')) {
|
|
75
|
+
return types_2.UaVariant.integers(value, dataType);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (types_1.UaVariantType.Double == dataType) {
|
|
83
|
+
if (!isArray) {
|
|
84
|
+
if (typeof value === "number") {
|
|
85
|
+
return types_2.UaVariant.double(value);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
if (value.every(item => typeof item === 'number')) {
|
|
93
|
+
return types_2.UaVariant.doubles(value);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (types_1.UaVariantType.Float == dataType) {
|
|
101
|
+
if (!isArray) {
|
|
102
|
+
if (typeof value === "number") {
|
|
103
|
+
return types_2.UaVariant.float(value);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
if (value.every(item => typeof item === 'number')) {
|
|
111
|
+
return types_2.UaVariant.floats(value);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else if (types_1.UaVariantType.Boolean == dataType) {
|
|
119
|
+
if (!isArray) {
|
|
120
|
+
if (typeof value === "boolean") {
|
|
121
|
+
return types_2.UaVariant.boolean(value);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
if (value.every(item => typeof item === 'boolean')) {
|
|
129
|
+
return types_2.UaVariant.booleans(value);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else if (types_1.UaVariantType.String == dataType) {
|
|
137
|
+
if (!isArray) {
|
|
138
|
+
if (typeof value === "string") {
|
|
139
|
+
return types_2.UaVariant.string(value);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
if (value.every(item => typeof item === 'string')) {
|
|
147
|
+
return types_2.UaVariant.strings(value);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else if (types_1.UaVariantType.NodeId == dataType) {
|
|
155
|
+
if (!isArray) {
|
|
156
|
+
if (typeof value === "string") {
|
|
157
|
+
return types_2.UaVariant.nodeId((0, types_1.parseUaNodeId)(value));
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
if (value.every(item => typeof item === 'string')) {
|
|
165
|
+
let nodeIds = [];
|
|
166
|
+
for (let item of value) {
|
|
167
|
+
nodeIds.push((0, types_1.parseUaNodeId)(item));
|
|
168
|
+
}
|
|
169
|
+
return types_2.UaVariant.nodeIds(nodeIds);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else if (types_1.UaVariantType.ExpandedNodeId == dataType) {
|
|
177
|
+
if (!isArray) {
|
|
178
|
+
if (typeof value === "string") {
|
|
179
|
+
return types_2.UaVariant.expandedNodeId((0, types_1.parseUaExpandedNodeId)(value));
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
if (value.every(item => typeof item === 'string')) {
|
|
187
|
+
let nodeIds = [];
|
|
188
|
+
for (let item of value) {
|
|
189
|
+
nodeIds.push((0, types_1.parseUaExpandedNodeId)(item));
|
|
190
|
+
}
|
|
191
|
+
return types_2.UaVariant.expandedNodeIds(nodeIds);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else if (types_1.UaVariantType.DateTime == dataType) {
|
|
199
|
+
if (!isArray) {
|
|
200
|
+
if (typeof value === "string") {
|
|
201
|
+
return types_2.UaVariant.dateTime(new Date(value));
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
if (value.every(item => typeof item === 'string')) {
|
|
209
|
+
let datetimes = [];
|
|
210
|
+
for (let item of value) {
|
|
211
|
+
datetimes.push(new Date(item));
|
|
212
|
+
}
|
|
213
|
+
return types_2.UaVariant.dateTimes(datetimes);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
else if (types_1.UaVariantType.ByteString == dataType) {
|
|
221
|
+
if (!isArray) {
|
|
222
|
+
if (typeof value === "string") {
|
|
223
|
+
return types_2.UaVariant.byteString(value);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
if (value.every(item => typeof item === 'string')) {
|
|
231
|
+
let byteStrings = [];
|
|
232
|
+
for (let item of value) {
|
|
233
|
+
byteStrings.push(item);
|
|
234
|
+
}
|
|
235
|
+
return types_2.UaVariant.byteStrings(byteStrings);
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else if (types_1.UaVariantType.QualifiedName == dataType) {
|
|
243
|
+
if (!isArray) {
|
|
244
|
+
if (typeof value === "string") {
|
|
245
|
+
return types_2.UaVariant.qualifiedName(value);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
if (value.every(item => typeof item === 'string')) {
|
|
253
|
+
let qualifiedNames = [];
|
|
254
|
+
for (let item of value) {
|
|
255
|
+
qualifiedNames.push(item);
|
|
256
|
+
}
|
|
257
|
+
return types_2.UaVariant.qualifiedNames(qualifiedNames);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
else if (types_1.UaVariantType.Guid == dataType) {
|
|
265
|
+
if (!isArray) {
|
|
266
|
+
if (typeof value === "string") {
|
|
267
|
+
return types_2.UaVariant.guid(value);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
if (value.every(item => typeof item === 'string')) {
|
|
275
|
+
let guids = [];
|
|
276
|
+
for (let item of value) {
|
|
277
|
+
guids.push(item);
|
|
278
|
+
}
|
|
279
|
+
return types_2.UaVariant.guids(guids);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
else if (types_1.UaVariantType.StatusCode == dataType) {
|
|
287
|
+
if (!isArray) {
|
|
288
|
+
let statusCode = value;
|
|
289
|
+
if (typeof statusCode.Code === "number") {
|
|
290
|
+
return types_2.UaVariant.statusCode((0, types_1.makeUaStatusCode)(statusCode.Code));
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
let statusCodes = [];
|
|
298
|
+
for (let item of value) {
|
|
299
|
+
let statusCode = item;
|
|
300
|
+
if (typeof statusCode.Code === "number") {
|
|
301
|
+
statusCodes.push((0, types_1.makeUaStatusCode)(statusCode.Code));
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return types_2.UaVariant.statusCodes(statusCodes);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
else if (types_1.UaVariantType.LocalizedText == dataType) {
|
|
311
|
+
if (!isArray) {
|
|
312
|
+
return types_2.UaVariant.localizedText(UaPayloadMapper.localizedTextFromWebApi(value));
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
let localizedTexts = [];
|
|
316
|
+
for (let item of value) {
|
|
317
|
+
localizedTexts.push(UaPayloadMapper.localizedTextFromWebApi(item));
|
|
318
|
+
}
|
|
319
|
+
return types_2.UaVariant.localizedTexts(localizedTexts);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
else if (types_1.UaVariantType.ExtensionObject == dataType) {
|
|
323
|
+
if (!isArray) {
|
|
324
|
+
return types_2.UaVariant.extensionObject(UaPayloadMapper.extensionObjectFromWebApi(value));
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
let extensionObjects = [];
|
|
328
|
+
for (let item of value) {
|
|
329
|
+
extensionObjects.push(UaPayloadMapper.extensionObjectFromWebApi(item));
|
|
330
|
+
}
|
|
331
|
+
return types_2.UaVariant.extensionObjects(extensionObjects);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
return variantToReturn;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
catch (e) {
|
|
339
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
static variantToWebApi(variant) {
|
|
343
|
+
let dataType = variant.type;
|
|
344
|
+
if (types_1.UaVariantType.NodeId == dataType) {
|
|
345
|
+
if (variant.isScalar()) {
|
|
346
|
+
return { Value: variant.value.toString(), UaType: dataType };
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
let nodeIds = variant.value;
|
|
350
|
+
let value = [];
|
|
351
|
+
for (let item of nodeIds) {
|
|
352
|
+
value.push(item.toString());
|
|
353
|
+
}
|
|
354
|
+
return { Value: value, UaType: dataType };
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
else if (types_1.UaVariantType.ExpandedNodeId == dataType) {
|
|
358
|
+
if (variant.isScalar()) {
|
|
359
|
+
return { Value: variant.value.toString(), UaType: dataType };
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
let nodeIds = variant.value;
|
|
363
|
+
let value = [];
|
|
364
|
+
for (let item of nodeIds) {
|
|
365
|
+
value.push(item.toString());
|
|
366
|
+
}
|
|
367
|
+
return { Value: value, UaType: dataType };
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
else if (types_1.UaVariantType.DateTime == dataType) {
|
|
371
|
+
if (variant.isScalar()) {
|
|
372
|
+
return { Value: variant.value.toISOString(), UaType: dataType };
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
let dateTimes = variant.value;
|
|
376
|
+
let value = [];
|
|
377
|
+
for (let item of dateTimes) {
|
|
378
|
+
value.push(item.toISOString());
|
|
379
|
+
}
|
|
380
|
+
return { Value: value, UaType: dataType };
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
else if (types_1.UaVariantType.LocalizedText == dataType) {
|
|
384
|
+
if (variant.isScalar()) {
|
|
385
|
+
return { Value: UaPayloadMapper.localizedTextToWebApi(variant.value), UaType: dataType };
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
let localizedTexts = variant.value;
|
|
389
|
+
let value = [];
|
|
390
|
+
for (let item of localizedTexts) {
|
|
391
|
+
value.push(UaPayloadMapper.localizedTextToWebApi(item));
|
|
392
|
+
}
|
|
393
|
+
return { Value: value, UaType: dataType };
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
else if (types_1.UaVariantType.StatusCode == dataType) {
|
|
397
|
+
if (variant.isScalar()) {
|
|
398
|
+
return { Value: UaPayloadMapper.statusCodeToWebApi(variant.value), UaType: dataType };
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
let statusCodes = variant.value;
|
|
402
|
+
let value = [];
|
|
403
|
+
for (let item of statusCodes) {
|
|
404
|
+
value.push(UaPayloadMapper.statusCodeToWebApi(item));
|
|
405
|
+
}
|
|
406
|
+
return { Value: value, UaType: dataType };
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
else if (types_1.UaVariantType.ExtensionObject == dataType) {
|
|
410
|
+
if (variant.isScalar()) {
|
|
411
|
+
return { Value: UaPayloadMapper.extensionObjectToWebApi(variant.value), UaType: dataType };
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
let extensionObjects = variant.value;
|
|
415
|
+
let value = [];
|
|
416
|
+
for (let item of extensionObjects) {
|
|
417
|
+
value.push(UaPayloadMapper.extensionObjectToWebApi(item));
|
|
418
|
+
}
|
|
419
|
+
return { Value: value, UaType: dataType };
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
return { Value: variant.value, UaType: dataType };
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
static dataValueFromWebApi(dataValue) {
|
|
427
|
+
let variant = { Value: dataValue.Value, UaType: dataValue.UaType };
|
|
428
|
+
let value = UaPayloadMapper.variantFromWebApi(variant);
|
|
429
|
+
let ret = new types_2.UaDataValue(value, UaPayloadMapper.statusCodeFromWebApi(dataValue.StatusCode), dataValue.SourceTimestamp, dataValue.ServerTimestamp);
|
|
430
|
+
return ret;
|
|
431
|
+
}
|
|
432
|
+
static dataValueToWebApi(dataValue) {
|
|
433
|
+
let variant = UaPayloadMapper.variantToWebApi(dataValue.value);
|
|
434
|
+
let ret = {
|
|
435
|
+
Value: variant.Value,
|
|
436
|
+
UaType: variant.UaType,
|
|
437
|
+
StatusCode: (dataValue.statusCode.value == 0) ? undefined : UaPayloadMapper.statusCodeToWebApi(dataValue.statusCode),
|
|
438
|
+
SourceTimestamp: (null != dataValue.sourceTimestamp) ? dataValue.sourceTimestamp : undefined,
|
|
439
|
+
ServerTimestamp: (null != dataValue.serverTimestamp) ? dataValue.serverTimestamp : undefined
|
|
440
|
+
};
|
|
441
|
+
return ret;
|
|
442
|
+
}
|
|
443
|
+
static referenceDescriptionFromWebApi(referenceDesc) {
|
|
444
|
+
if (!referenceDesc.NodeId)
|
|
445
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
446
|
+
try {
|
|
447
|
+
let nodeId = (0, types_1.parseUaExpandedNodeId)(referenceDesc.NodeId);
|
|
448
|
+
let nodeClass = (referenceDesc.NodeClass) ? referenceDesc.NodeClass : 0;
|
|
449
|
+
let referenceTypeId = (referenceDesc.ReferenceTypeId) ? (0, types_1.parseUaNodeId)(referenceDesc.ReferenceTypeId) : types_2.UaNodeId.nullNodeId;
|
|
450
|
+
let isForward = (referenceDesc.IsForward) ? true : false;
|
|
451
|
+
let browseName = (referenceDesc.BrowseName) ? referenceDesc.BrowseName : "";
|
|
452
|
+
let displayName = (referenceDesc.DisplayName) ? UaPayloadMapper.localizedTextFromWebApi(referenceDesc.DisplayName) : types_2.UaLocalizedText.nullText;
|
|
453
|
+
let typeDefinitionId = (referenceDesc.TypeDefinition) ? (0, types_1.parseUaExpandedNodeId)(referenceDesc.TypeDefinition) : undefined;
|
|
454
|
+
return {
|
|
455
|
+
nodeId: nodeId,
|
|
456
|
+
nodeClass: nodeClass,
|
|
457
|
+
referenceTypeId: referenceTypeId,
|
|
458
|
+
isForward: isForward,
|
|
459
|
+
browseName: browseName,
|
|
460
|
+
displayName: displayName,
|
|
461
|
+
typeDefinition: typeDefinitionId
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
catch (e) {
|
|
465
|
+
throw new types_1.UaError((0, types_1.makeUaStatusCode)(opcua_webapi_2.StatusCodes.BadDecodingError));
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
static browseResultFromWebApi(browseResult) {
|
|
469
|
+
let results = [];
|
|
470
|
+
if (browseResult.References) {
|
|
471
|
+
for (let item of browseResult.References) {
|
|
472
|
+
results.push(UaPayloadMapper.referenceDescriptionFromWebApi(item));
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return {
|
|
476
|
+
results: results,
|
|
477
|
+
continuationPoint: browseResult.ContinuationPoint
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
exports.UaPayloadMapper = UaPayloadMapper;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./UaPayloadMapper";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./UaPayloadMapper"), exports);
|