opcua-webapi-ts 1.0.22 → 1.0.24
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/dist/cjs/client/UaWebClient.d.ts +10 -11
- package/dist/cjs/client/UaWebClient.js +156 -174
- package/dist/cjs/client/utils/UaDataTypeDictionary.js +15 -27
- package/dist/cjs/client/utils/UaNodeReader.d.ts +1 -1
- package/dist/cjs/client/utils/UaNodeReader.js +95 -145
- package/dist/cjs/client/utils/UaObjectTypeDictionary.js +8 -15
- package/dist/cjs/client/utils/UaReferenceTypeDictionary.js +8 -15
- package/dist/cjs/common/index.d.ts +1 -1
- package/dist/cjs/common/index.js +1 -1
- package/dist/cjs/common/payload/UaBrowseDescription.d.ts +20 -0
- package/dist/cjs/common/payload/UaBrowseDescription.js +58 -0
- package/dist/cjs/common/payload/UaBrowseResult.d.ts +16 -0
- package/dist/cjs/common/payload/UaBrowseResult.js +52 -0
- package/dist/cjs/common/payload/UaCallMethodRequest.d.ts +14 -0
- package/dist/cjs/common/payload/UaCallMethodRequest.js +50 -0
- package/dist/cjs/common/payload/UaCallMethodResult.d.ts +14 -0
- package/dist/cjs/common/payload/UaCallMethodResult.js +61 -0
- package/dist/cjs/common/payload/UaHistoryReadResult.d.ts +14 -0
- package/dist/cjs/common/payload/UaHistoryReadResult.js +41 -0
- package/dist/cjs/common/payload/UaHistoryReadValueId.d.ts +14 -0
- package/dist/cjs/common/payload/UaHistoryReadValueId.js +39 -0
- package/dist/cjs/common/payload/UaPayloadMapper.d.ts +15 -0
- package/dist/cjs/common/payload/UaPayloadMapper.js +444 -0
- package/dist/cjs/common/payload/UaReadValueId.d.ts +14 -0
- package/dist/cjs/common/payload/UaReadValueId.js +39 -0
- package/dist/cjs/common/payload/UaReferenceDescription.d.ts +22 -0
- package/dist/cjs/common/payload/UaReferenceDescription.js +61 -0
- package/dist/cjs/common/payload/UaWriteValue.d.ts +16 -0
- package/dist/cjs/common/payload/UaWriteValue.js +49 -0
- package/dist/cjs/common/payload/index.d.ts +10 -0
- package/dist/cjs/common/payload/index.js +26 -0
- package/dist/cjs/common/structure/UaArgument.js +3 -3
- package/dist/cjs/common/structure/UaContentFilterElement.js +3 -3
- package/dist/cjs/common/structure/UaEUInformation.js +5 -5
- package/dist/cjs/common/structure/UaEnumValueType.js +5 -5
- package/dist/cjs/common/structure/UaHistoryData.js +3 -3
- package/dist/cjs/common/structure/UaHistoryEvent.js +3 -3
- package/dist/cjs/common/structure/UaLiteralOperand.js +3 -3
- package/dist/cjs/common/types/UaExpandedNodeId.d.ts +1 -0
- package/dist/cjs/common/types/UaExpandedNodeId.js +11 -0
- package/dist/cjs/common/types/index.d.ts +0 -1
- package/dist/cjs/common/types/index.js +0 -1
- package/dist/client/UaWebClient.d.ts +10 -11
- package/dist/client/UaWebClient.js +156 -174
- package/dist/client/utils/UaDataTypeDictionary.js +15 -27
- package/dist/client/utils/UaNodeReader.d.ts +1 -1
- package/dist/client/utils/UaNodeReader.js +95 -145
- package/dist/client/utils/UaObjectTypeDictionary.js +8 -15
- package/dist/client/utils/UaReferenceTypeDictionary.js +8 -15
- package/dist/common/index.d.ts +1 -1
- package/dist/common/index.js +1 -1
- package/dist/common/payload/UaBrowseDescription.d.ts +20 -0
- package/dist/common/payload/UaBrowseDescription.js +58 -0
- package/dist/common/payload/UaBrowseResult.d.ts +16 -0
- package/dist/common/payload/UaBrowseResult.js +52 -0
- package/dist/common/payload/UaCallMethodRequest.d.ts +14 -0
- package/dist/common/payload/UaCallMethodRequest.js +50 -0
- package/dist/common/payload/UaCallMethodResult.d.ts +14 -0
- package/dist/common/payload/UaCallMethodResult.js +61 -0
- package/dist/common/payload/UaHistoryReadResult.d.ts +14 -0
- package/dist/common/payload/UaHistoryReadResult.js +41 -0
- package/dist/common/payload/UaHistoryReadValueId.d.ts +14 -0
- package/dist/common/payload/UaHistoryReadValueId.js +39 -0
- package/dist/common/payload/UaPayloadMapper.d.ts +15 -0
- package/dist/common/payload/UaPayloadMapper.js +444 -0
- package/dist/common/payload/UaReadValueId.d.ts +14 -0
- package/dist/common/payload/UaReadValueId.js +39 -0
- package/dist/common/payload/UaReferenceDescription.d.ts +22 -0
- package/dist/common/payload/UaReferenceDescription.js +61 -0
- package/dist/common/payload/UaWriteValue.d.ts +16 -0
- package/dist/common/payload/UaWriteValue.js +49 -0
- package/dist/common/payload/index.d.ts +10 -0
- package/dist/common/payload/index.js +26 -0
- package/dist/common/structure/UaArgument.js +3 -3
- package/dist/common/structure/UaContentFilterElement.js +3 -3
- package/dist/common/structure/UaEUInformation.js +5 -5
- package/dist/common/structure/UaEnumValueType.js +5 -5
- package/dist/common/structure/UaHistoryData.js +3 -3
- package/dist/common/structure/UaHistoryEvent.js +3 -3
- package/dist/common/structure/UaLiteralOperand.js +3 -3
- package/dist/common/types/UaExpandedNodeId.d.ts +1 -0
- package/dist/common/types/UaExpandedNodeId.js +11 -0
- package/dist/common/types/index.d.ts +0 -1
- package/dist/common/types/index.js +0 -1
- package/package.json +1 -1
|
@@ -0,0 +1,444 @@
|
|
|
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)
|
|
19
|
+
return null;
|
|
20
|
+
return new types_2.UaLocalizedText((text.Text) ? text.Text : "", (text.Locale) ? text.Locale : undefined);
|
|
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
|
+
}
|
|
444
|
+
exports.UaPayloadMapper = UaPayloadMapper;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ReadValueId } from "opcua-webapi";
|
|
2
|
+
import { UaNodeId } from "../types";
|
|
3
|
+
export declare class UaReadValueId {
|
|
4
|
+
static dataTypeId: UaNodeId;
|
|
5
|
+
private _nodeId;
|
|
6
|
+
private _attributeId;
|
|
7
|
+
private _indexRange?;
|
|
8
|
+
constructor(nodeId: UaNodeId, attributeId: number, indexRange?: string);
|
|
9
|
+
get nodeId(): UaNodeId;
|
|
10
|
+
get attributeId(): number;
|
|
11
|
+
get indexRange(): string | undefined;
|
|
12
|
+
toStruct(): ReadValueId;
|
|
13
|
+
static fromStruct(readValueId: ReadValueId): UaReadValueId | null;
|
|
14
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UaReadValueId = void 0;
|
|
4
|
+
const nodes_1 = require("../nodes");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
class UaReadValueId {
|
|
7
|
+
constructor(nodeId, attributeId, indexRange) {
|
|
8
|
+
this._nodeId = nodeId;
|
|
9
|
+
this._attributeId = attributeId;
|
|
10
|
+
this._indexRange = indexRange;
|
|
11
|
+
}
|
|
12
|
+
get nodeId() {
|
|
13
|
+
return this._nodeId;
|
|
14
|
+
}
|
|
15
|
+
get attributeId() {
|
|
16
|
+
return this._attributeId;
|
|
17
|
+
}
|
|
18
|
+
get indexRange() {
|
|
19
|
+
return this._indexRange;
|
|
20
|
+
}
|
|
21
|
+
toStruct() {
|
|
22
|
+
let readValueId = {
|
|
23
|
+
NodeId: this._nodeId.toString(),
|
|
24
|
+
AttributeId: this._attributeId,
|
|
25
|
+
IndexRange: this._indexRange
|
|
26
|
+
};
|
|
27
|
+
return readValueId;
|
|
28
|
+
}
|
|
29
|
+
static fromStruct(readValueId) {
|
|
30
|
+
let nodeId = (0, types_1.parseUaNodeIdOrNull)(readValueId.NodeId);
|
|
31
|
+
let attributeId = readValueId.AttributeId;
|
|
32
|
+
let indexRange = readValueId.IndexRange;
|
|
33
|
+
if (null == nodeId || null == attributeId)
|
|
34
|
+
return null;
|
|
35
|
+
return new UaReadValueId(nodeId, attributeId, indexRange);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.UaReadValueId = UaReadValueId;
|
|
39
|
+
UaReadValueId.dataTypeId = new types_1.UaNodeId(nodes_1.DataTypeIds.ReadValueId);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ReferenceDescription } from "opcua-webapi";
|
|
2
|
+
import { UaExpandedNodeId, UaLocalizedText, UaNodeId } from "../types";
|
|
3
|
+
export declare class UaReferenceDescription {
|
|
4
|
+
static dataTypeId: UaNodeId;
|
|
5
|
+
private _nodeId;
|
|
6
|
+
private _nodeClass?;
|
|
7
|
+
private _browseName?;
|
|
8
|
+
private _displayName?;
|
|
9
|
+
private _referenceTypeId?;
|
|
10
|
+
private _isForward?;
|
|
11
|
+
private _typeDefinition?;
|
|
12
|
+
constructor(nodeId: UaExpandedNodeId, nodeClass?: number, browseName?: string, displayName?: UaLocalizedText, referenceTypeId?: UaNodeId, isForward?: boolean, typeDefinition?: UaExpandedNodeId);
|
|
13
|
+
get nodeId(): UaExpandedNodeId;
|
|
14
|
+
get nodeClass(): number | undefined;
|
|
15
|
+
get browseName(): string | undefined;
|
|
16
|
+
get displayName(): UaLocalizedText | undefined;
|
|
17
|
+
get referenceTypeId(): UaNodeId | undefined;
|
|
18
|
+
get isForward(): boolean | undefined;
|
|
19
|
+
get typeDefinition(): UaExpandedNodeId | undefined;
|
|
20
|
+
toStruct(): ReferenceDescription;
|
|
21
|
+
static fromStruct(referenceDescription: ReferenceDescription): UaReferenceDescription | null;
|
|
22
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UaReferenceDescription = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const nodes_1 = require("../nodes");
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
class UaReferenceDescription {
|
|
8
|
+
constructor(nodeId, nodeClass, browseName, displayName, referenceTypeId, isForward, typeDefinition) {
|
|
9
|
+
this._nodeId = nodeId;
|
|
10
|
+
this._nodeClass = nodeClass;
|
|
11
|
+
this._browseName = browseName;
|
|
12
|
+
this._displayName = displayName;
|
|
13
|
+
this._referenceTypeId = referenceTypeId;
|
|
14
|
+
this._isForward = isForward;
|
|
15
|
+
this._typeDefinition = typeDefinition;
|
|
16
|
+
}
|
|
17
|
+
get nodeId() {
|
|
18
|
+
return this._nodeId;
|
|
19
|
+
}
|
|
20
|
+
get nodeClass() {
|
|
21
|
+
return this._nodeClass;
|
|
22
|
+
}
|
|
23
|
+
get browseName() {
|
|
24
|
+
return this._browseName;
|
|
25
|
+
}
|
|
26
|
+
get displayName() {
|
|
27
|
+
return this._displayName;
|
|
28
|
+
}
|
|
29
|
+
get referenceTypeId() {
|
|
30
|
+
return this._referenceTypeId;
|
|
31
|
+
}
|
|
32
|
+
get isForward() {
|
|
33
|
+
return this._isForward;
|
|
34
|
+
}
|
|
35
|
+
get typeDefinition() {
|
|
36
|
+
return this._typeDefinition;
|
|
37
|
+
}
|
|
38
|
+
toStruct() {
|
|
39
|
+
let referenceDescription = {
|
|
40
|
+
ReferenceTypeId: (this._referenceTypeId) ? this._referenceTypeId.toString() : undefined,
|
|
41
|
+
IsForward: this._isForward,
|
|
42
|
+
NodeId: this._nodeId.toString(),
|
|
43
|
+
BrowseName: this._browseName,
|
|
44
|
+
DisplayName: (this._displayName) ? _1.UaPayloadMapper.localizedTextToWebApi(this._displayName) : undefined,
|
|
45
|
+
NodeClass: this._nodeClass,
|
|
46
|
+
TypeDefinition: (this._typeDefinition) ? this._typeDefinition.toString() : undefined
|
|
47
|
+
};
|
|
48
|
+
return referenceDescription;
|
|
49
|
+
}
|
|
50
|
+
static fromStruct(referenceDescription) {
|
|
51
|
+
let nodeId = (0, types_1.parseUaExpandedNodeIdOrNull)(referenceDescription.NodeId);
|
|
52
|
+
let displayName = (referenceDescription.DisplayName) ? _1.UaPayloadMapper.localizedTextFromWebApi(referenceDescription.DisplayName) : undefined;
|
|
53
|
+
let referenceTypeId = (referenceDescription.ReferenceTypeId) ? (0, types_1.parseUaNodeIdOrNull)(referenceDescription.ReferenceTypeId) : undefined;
|
|
54
|
+
let typeDefinition = (referenceDescription.TypeDefinition) ? (0, types_1.parseUaExpandedNodeIdOrNull)(referenceDescription.TypeDefinition) : undefined;
|
|
55
|
+
if (null == nodeId || null == displayName || null == referenceTypeId || null == typeDefinition)
|
|
56
|
+
return null;
|
|
57
|
+
return new UaReferenceDescription(nodeId, referenceDescription.NodeClass, referenceDescription.BrowseName, displayName, referenceTypeId, referenceDescription.IsForward, typeDefinition);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.UaReferenceDescription = UaReferenceDescription;
|
|
61
|
+
UaReferenceDescription.dataTypeId = new types_1.UaNodeId(nodes_1.DataTypeIds.ReferenceDescription);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { WriteValue } from "opcua-webapi";
|
|
2
|
+
import { UaNodeId, UaVariant } from "../types";
|
|
3
|
+
export declare class UaWriteValue {
|
|
4
|
+
static dataTypeId: UaNodeId;
|
|
5
|
+
private _nodeId;
|
|
6
|
+
private _value;
|
|
7
|
+
private _attributeId;
|
|
8
|
+
private _indexRange?;
|
|
9
|
+
constructor(nodeId: UaNodeId, value: UaVariant, attributeId?: number, indexRange?: string);
|
|
10
|
+
get nodeId(): UaNodeId;
|
|
11
|
+
get value(): UaVariant;
|
|
12
|
+
get attributeId(): number;
|
|
13
|
+
get indexRange(): string | undefined;
|
|
14
|
+
toStruct(): WriteValue;
|
|
15
|
+
static fromStruct(writeValueId: WriteValue): UaWriteValue | null;
|
|
16
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UaWriteValue = void 0;
|
|
4
|
+
const opcua_webapi_1 = require("opcua-webapi");
|
|
5
|
+
const nodes_1 = require("../nodes");
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
const _1 = require(".");
|
|
8
|
+
class UaWriteValue {
|
|
9
|
+
constructor(nodeId, value, attributeId, indexRange) {
|
|
10
|
+
this._nodeId = nodeId;
|
|
11
|
+
this._value = value;
|
|
12
|
+
this._attributeId = (attributeId) ? attributeId : opcua_webapi_1.Attributes.Value;
|
|
13
|
+
this._indexRange = indexRange;
|
|
14
|
+
}
|
|
15
|
+
get nodeId() {
|
|
16
|
+
return this._nodeId;
|
|
17
|
+
}
|
|
18
|
+
get value() {
|
|
19
|
+
return this._value;
|
|
20
|
+
}
|
|
21
|
+
get attributeId() {
|
|
22
|
+
return this._attributeId;
|
|
23
|
+
}
|
|
24
|
+
get indexRange() {
|
|
25
|
+
return this._indexRange;
|
|
26
|
+
}
|
|
27
|
+
toStruct() {
|
|
28
|
+
let writeValue = {
|
|
29
|
+
NodeId: this._nodeId.toString(),
|
|
30
|
+
Value: _1.UaPayloadMapper.variantToWebApi(this._value),
|
|
31
|
+
AttributeId: this._attributeId,
|
|
32
|
+
IndexRange: this._indexRange
|
|
33
|
+
};
|
|
34
|
+
return writeValue;
|
|
35
|
+
}
|
|
36
|
+
static fromStruct(writeValueId) {
|
|
37
|
+
if (!writeValueId.Value || !writeValueId.AttributeId)
|
|
38
|
+
return null;
|
|
39
|
+
let nodeId = (0, types_1.parseUaNodeIdOrNull)(writeValueId.NodeId);
|
|
40
|
+
let value = _1.UaPayloadMapper.variantFromWebApi(writeValueId.Value);
|
|
41
|
+
let attributeId = writeValueId.AttributeId;
|
|
42
|
+
let indexRange = writeValueId.IndexRange;
|
|
43
|
+
if (null == nodeId)
|
|
44
|
+
return null;
|
|
45
|
+
return new UaWriteValue(nodeId, value, attributeId, indexRange);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.UaWriteValue = UaWriteValue;
|
|
49
|
+
UaWriteValue.dataTypeId = new types_1.UaNodeId(nodes_1.DataTypeIds.WriteValue);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./UaPayloadMapper";
|
|
2
|
+
export * from "./UaWriteValue";
|
|
3
|
+
export * from "./UaReadValueId";
|
|
4
|
+
export * from "./UaBrowseDescription";
|
|
5
|
+
export * from "./UaReferenceDescription";
|
|
6
|
+
export * from "./UaBrowseResult";
|
|
7
|
+
export * from "./UaHistoryReadValueId";
|
|
8
|
+
export * from "./UaHistoryReadResult";
|
|
9
|
+
export * from "./UaCallMethodRequest";
|
|
10
|
+
export * from "./UaCallMethodResult";
|