opcua-webapi-ts 1.1.23 → 1.1.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.
Files changed (34) hide show
  1. package/dist/cjs/client/utils/UaDataTypeDictionary.js +1 -1
  2. package/dist/cjs/client/utils/UaModelling.js +2 -2
  3. package/dist/cjs/client/utils/UaNodeBrowser.js +7 -36
  4. package/dist/cjs/client/utils/UaNodeReader.js +102 -144
  5. package/dist/cjs/client/utils/UaNodeSerializer.js +166 -0
  6. package/dist/cjs/client/utils/UaObjectTypeDictionary.js +1 -1
  7. package/dist/cjs/client/utils/UaReferenceTypeDictionary.js +1 -1
  8. package/dist/cjs/client/utils/index.js +1 -0
  9. package/dist/cjs/common/nodes/UaMethod.js +22 -0
  10. package/dist/cjs/common/nodes/UaNode.js +0 -13
  11. package/dist/cjs/common/nodes/UaObject.js +3 -10
  12. package/dist/cjs/common/nodes/UaObjectType.js +3 -12
  13. package/dist/cjs/common/nodes/UaVariable.js +12 -5
  14. package/dist/client/utils/UaDataTypeDictionary.js +1 -1
  15. package/dist/client/utils/UaModelling.js +2 -2
  16. package/dist/client/utils/UaNodeBrowser.d.ts +3 -8
  17. package/dist/client/utils/UaNodeBrowser.js +7 -36
  18. package/dist/client/utils/UaNodeReader.d.ts +15 -18
  19. package/dist/client/utils/UaNodeReader.js +102 -144
  20. package/dist/client/utils/UaNodeSerializer.d.ts +14 -0
  21. package/dist/client/utils/UaNodeSerializer.js +166 -0
  22. package/dist/client/utils/UaObjectTypeDictionary.js +1 -1
  23. package/dist/client/utils/UaReferenceTypeDictionary.js +1 -1
  24. package/dist/client/utils/index.d.ts +1 -0
  25. package/dist/client/utils/index.js +1 -0
  26. package/dist/common/nodes/UaMethod.d.ts +1 -0
  27. package/dist/common/nodes/UaMethod.js +22 -0
  28. package/dist/common/nodes/UaNode.d.ts +0 -5
  29. package/dist/common/nodes/UaNode.js +0 -13
  30. package/dist/common/nodes/UaObject.js +3 -10
  31. package/dist/common/nodes/UaObjectType.js +3 -12
  32. package/dist/common/nodes/UaVariable.d.ts +4 -1
  33. package/dist/common/nodes/UaVariable.js +12 -5
  34. package/package.json +1 -1
@@ -9,17 +9,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.UaObjectDataReader = exports.UaTypeReader = exports.UaObjectReader = exports.UaNodeReader = void 0;
12
+ exports.UaTypeReader = exports.UaFullObjectReader = exports.UaObjectReader = exports.UaNodeReader = void 0;
13
13
  const opcua_webapi_1 = require("opcua-webapi");
14
14
  const common_1 = require("../../common");
15
15
  const UaNodeBrowser_1 = require("./UaNodeBrowser");
16
16
  class UaNodeReader {
17
- constructor(client, returnDescription, returnVariable, returnMethod, returnAttributes, returnValue, referenceTypeToReturn) {
17
+ constructor(client, returnDescription, returnVariable, returnMethod, referenceTypeToReturn, returnObjectAttributes, returnVariableAttributes, returnVariableValue, returnPropertyAttributes, returnPropertyValue) {
18
18
  this._client = client;
19
- this._returnDescription = (returnDescription) ? returnDescription : false;
20
- this._returnAttributes = (returnAttributes) ? returnAttributes : false;
21
- this._returnValue = (returnValue) ? returnValue : false;
22
- this._referenceTypeToReturn = (referenceTypeToReturn) ? referenceTypeToReturn : common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences);
19
+ this._returnDescription = returnDescription;
20
+ this._referenceTypeToReturn = referenceTypeToReturn;
21
+ this._returnObjectAttributes = returnObjectAttributes;
22
+ this._returnVariableAttributes = returnVariableAttributes;
23
+ this._returnVariableValue = returnVariableValue;
24
+ this._returnPropertyAttributes = returnPropertyAttributes;
25
+ this._returnPropertyValue = returnPropertyValue;
23
26
  this._nodeClassToReturn = 0;
24
27
  if (returnVariable)
25
28
  this._nodeClassToReturn += opcua_webapi_1.NodeClass.Variable;
@@ -59,17 +62,15 @@ class UaNodeReader {
59
62
  return __awaiter(this, void 0, void 0, function* () {
60
63
  if (references.length == 0)
61
64
  return [];
62
- let referencesToRead = [];
63
65
  let nodeIdsToBrowse = [];
64
66
  let nodeIdsSet = new Set();
65
67
  for (let item of references) {
66
68
  if (nodeIdsSet.has(item.nodeId.toString()))
67
69
  continue;
68
- referencesToRead.push(item);
69
70
  nodeIdsToBrowse.push(item.nodeId);
70
71
  nodeIdsSet.add(item.nodeId.toString());
71
72
  }
72
- let nodeReferenceBrowser = new UaNodeBrowser_1.UaNodeBrowser(this._client, nodeIdsToBrowse, this._referenceTypeToReturn, this._nodeClassToReturn, false);
73
+ let nodeReferenceBrowser = new UaNodeBrowser_1.UaNodeBrowser(this._client, nodeIdsToBrowse, this._referenceTypeToReturn, this._nodeClassToReturn);
73
74
  yield nodeReferenceBrowser.browse();
74
75
  let childReferences = nodeReferenceBrowser.results();
75
76
  let childNodesToBrowse = [];
@@ -86,7 +87,7 @@ class UaNodeReader {
86
87
  }
87
88
  let variableReferences = [];
88
89
  if (childNodesToBrowse.length != 0) {
89
- let childReferenceBrowser = new UaNodeBrowser_1.UaNodeBrowser(this._client, childNodesToBrowse, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), opcua_webapi_1.NodeClass.Variable, false);
90
+ let childReferenceBrowser = new UaNodeBrowser_1.UaNodeBrowser(this._client, childNodesToBrowse, common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), opcua_webapi_1.NodeClass.Variable);
90
91
  yield childReferenceBrowser.browse();
91
92
  variableReferences = childReferenceBrowser.results();
92
93
  }
@@ -194,7 +195,6 @@ class UaNodeReader {
194
195
  _readTypes(references, nodes) {
195
196
  return __awaiter(this, void 0, void 0, function* () {
196
197
  let typesToRead = [];
197
- let needReadAttributes = this._returnAttributes || this._returnDescription;
198
198
  for (let item of references) {
199
199
  if (item.nodeClass != opcua_webapi_1.NodeClass.ObjectType &&
200
200
  item.nodeClass != opcua_webapi_1.NodeClass.DataType &&
@@ -206,49 +206,45 @@ class UaNodeReader {
206
206
  if (0 == typesToRead.length)
207
207
  return;
208
208
  let dataValues = [];
209
- if (needReadAttributes) {
210
- let nodesToRead = [];
211
- for (let item of typesToRead) {
212
- nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.IsAbstract));
213
- nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
214
- if (item.nodeClass == opcua_webapi_1.NodeClass.VariableType) {
215
- nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.DataType));
216
- nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.ValueRank));
217
- }
209
+ let nodesToRead = [];
210
+ for (let item of typesToRead) {
211
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.IsAbstract));
212
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
213
+ if (item.nodeClass == opcua_webapi_1.NodeClass.VariableType) {
214
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.DataType));
215
+ nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.ValueRank));
218
216
  }
219
- dataValues = yield this._client.read(nodesToRead);
220
217
  }
218
+ dataValues = yield this._client.read(nodesToRead);
221
219
  for (let i = 0; i < typesToRead.length; ++i) {
222
220
  let isAbstract = false;
223
221
  let description = undefined;
224
222
  let dataType = common_1.UaNodeId.nullNodeId;
225
223
  let valueRank = -1;
226
- if (needReadAttributes) {
227
- let dataIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? i * 4 : i * 2;
224
+ let dataIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? i * 4 : i * 2;
225
+ if (dataValues[dataIndex].statusCode.isNotGood())
226
+ throw new common_1.UaError(dataValues[dataIndex].statusCode);
227
+ 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
+ dataIndex++;
231
+ if (dataValues[dataIndex].statusCode.isGood()) {
232
+ description = dataValues[dataIndex].value.toLocalizedText();
233
+ if (null == description)
234
+ description = undefined;
235
+ }
236
+ dataIndex++;
237
+ if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) {
228
238
  if (dataValues[dataIndex].statusCode.isNotGood())
229
239
  throw new common_1.UaError(dataValues[dataIndex].statusCode);
230
- isAbstract = dataValues[dataIndex].value.toBoolean();
231
- if (null == isAbstract)
232
- throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
240
+ dataType = dataValues[dataIndex].value.toNodeId();
233
241
  dataIndex++;
234
- if (this._returnDescription && dataValues[dataIndex].statusCode.isGood()) {
235
- description = dataValues[dataIndex].value.toLocalizedText();
236
- if (null == description)
237
- description = undefined;
238
- }
242
+ if (dataValues[dataIndex].statusCode.isNotGood())
243
+ throw new common_1.UaError(dataValues[dataIndex].statusCode);
244
+ valueRank = dataValues[dataIndex].value.toNumber();
239
245
  dataIndex++;
240
- if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) {
241
- if (dataValues[dataIndex].statusCode.isNotGood())
242
- throw new common_1.UaError(dataValues[dataIndex].statusCode);
243
- dataType = dataValues[dataIndex].value.toNodeId();
244
- dataIndex++;
245
- if (dataValues[dataIndex].statusCode.isNotGood())
246
- throw new common_1.UaError(dataValues[dataIndex].statusCode);
247
- valueRank = dataValues[dataIndex].value.toNumber();
248
- dataIndex++;
249
- if (null == dataType || null == valueRank)
250
- throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
251
- }
246
+ if (null == dataType || null == valueRank)
247
+ throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
252
248
  }
253
249
  let typeNode;
254
250
  if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.ObjectType) {
@@ -263,10 +259,9 @@ class UaNodeReader {
263
259
  else if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.ReferenceType) {
264
260
  typeNode = new common_1.UaReferenceType(typesToRead[i].nodeId, typesToRead[i].browseName, typesToRead[i].displayName, isAbstract, common_1.UaLocalizedText.nullText, false);
265
261
  }
266
- if (this._returnDescription && description) {
262
+ if (description) {
267
263
  typeNode.description = description;
268
264
  }
269
- typeNode.refToParent = typesToRead[i].referenceTypeId;
270
265
  nodes.set(typeNode.nodeId.toString(), typeNode);
271
266
  }
272
267
  });
@@ -283,7 +278,7 @@ class UaNodeReader {
283
278
  return;
284
279
  let nodesToRead = [];
285
280
  for (let item of objectsToRead) {
286
- if (this._returnAttributes) {
281
+ if (this._returnObjectAttributes) {
287
282
  nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.EventNotifier));
288
283
  }
289
284
  if (this._returnDescription) {
@@ -295,10 +290,10 @@ class UaNodeReader {
295
290
  dataValues = yield this._client.read(nodesToRead);
296
291
  }
297
292
  for (let i = 0; i < objectsToRead.length; ++i) {
298
- let dataIndex = (this._returnAttributes && this._returnDescription) ? i * 2 : i;
293
+ let dataIndex = (this._returnObjectAttributes && this._returnDescription) ? i * 2 : i;
299
294
  let eventNotifier = 0;
300
295
  let description = undefined;
301
- if (this._returnAttributes && dataValues[dataIndex].statusCode.isGood()) {
296
+ if (this._returnObjectAttributes && dataValues[dataIndex].statusCode.isGood()) {
302
297
  eventNotifier = dataValues[dataIndex].value.toNumber();
303
298
  if (null == eventNotifier)
304
299
  eventNotifier = 0;
@@ -311,7 +306,6 @@ class UaNodeReader {
311
306
  dataIndex++;
312
307
  }
313
308
  let objectNode = new common_1.UaObject(objectsToRead[i].nodeId, objectsToRead[i].browseName, objectsToRead[i].displayName, eventNotifier, objectsToRead[i].typeDefinitionId);
314
- objectNode.refToParent = objectsToRead[i].referenceTypeId;
315
309
  if (this._returnDescription && description) {
316
310
  objectNode.description = description;
317
311
  }
@@ -322,30 +316,56 @@ class UaNodeReader {
322
316
  _readVariables(references, nodes) {
323
317
  return __awaiter(this, void 0, void 0, function* () {
324
318
  let variablesToRead = [];
325
- let nodeIds = [];
319
+ let nodeIdsToReadAttributes = [];
320
+ let variablesToReadValue = [];
326
321
  for (let item of references) {
327
322
  if (item.nodeClass != opcua_webapi_1.NodeClass.Variable)
328
323
  continue;
329
324
  variablesToRead.push(item);
330
- nodeIds.push(item.nodeId);
331
325
  }
332
- if (0 == nodeIds.length)
326
+ if (0 == variablesToRead.length)
333
327
  return;
328
+ let hasPropertyId = common_1.UaNodeId.from(common_1.ReferenceTypeIds.HasProperty);
329
+ let attributeIndexMap = new Map();
330
+ for (let i = 0; i < variablesToRead.length; ++i) {
331
+ let item = variablesToRead[i];
332
+ if (item.referenceTypeId.equal(hasPropertyId)) {
333
+ if (this._returnPropertyAttributes) {
334
+ attributeIndexMap.set(i, nodeIdsToReadAttributes.length);
335
+ nodeIdsToReadAttributes.push(item.nodeId);
336
+ }
337
+ }
338
+ else {
339
+ if (this._returnVariableAttributes) {
340
+ attributeIndexMap.set(i, nodeIdsToReadAttributes.length);
341
+ nodeIdsToReadAttributes.push(item.nodeId);
342
+ }
343
+ }
344
+ }
334
345
  let results = [];
335
- if (this._returnAttributes) {
336
- results = yield this._client.readVariableAttributes(nodeIds);
346
+ if (nodeIdsToReadAttributes.length != 0) {
347
+ results = yield this._client.readVariableAttributes(nodeIdsToReadAttributes);
337
348
  }
338
- let variablesToReadValue = [];
339
349
  for (let i = 0; i < variablesToRead.length; ++i) {
340
350
  let variableNode;
341
- if (this._returnAttributes) {
342
- 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);
351
+ let attributeIndex = attributeIndexMap.get(i);
352
+ if (null != attributeIndex) {
353
+ variableNode = new common_1.UaVariable(variablesToRead[i].nodeId, variablesToRead[i].browseName, variablesToRead[i].displayName, results[attributeIndex].dataType, results[attributeIndex].valueRank, results[attributeIndex].accessLevel, results[attributeIndex].userAccessLevel, results[attributeIndex].historizing, variablesToRead[i].typeDefinitionId);
343
354
  }
344
355
  else {
345
356
  variableNode = new common_1.UaVariable(variablesToRead[i].nodeId, variablesToRead[i].browseName, variablesToRead[i].displayName, common_1.UaNodeId.nullNodeId, -1, 0, 0, false, variablesToRead[i].typeDefinitionId);
346
357
  }
347
358
  nodes.set(variableNode.nodeId.toString(), variableNode);
348
- if (this._returnValue || (UaNodeReader.s_variablesNameToRead.has(variableNode.browseName))) {
359
+ if (variablesToRead[i].referenceTypeId.equal(hasPropertyId)) {
360
+ variableNode.isProperty = true;
361
+ }
362
+ if (this._returnVariableValue && !variableNode.isProperty) {
363
+ variablesToReadValue.push(variableNode);
364
+ }
365
+ else if (this._returnPropertyValue && variableNode.isProperty) {
366
+ variablesToReadValue.push(variableNode);
367
+ }
368
+ else if (UaNodeReader.s_variablesNameToRead.has(variableNode.browseName)) {
349
369
  variablesToReadValue.push(variableNode);
350
370
  }
351
371
  }
@@ -449,17 +469,8 @@ exports.UaNodeReader = UaNodeReader;
449
469
  UaNodeReader.s_variableTypeWithoutMember = null;
450
470
  UaNodeReader.s_variablesNameToRead = null;
451
471
  class UaObjectReader extends UaNodeReader {
452
- constructor(client, returnDescription, returnValue) {
453
- super(client, returnDescription !== null && returnDescription !== void 0 ? returnDescription : false, true, true, true, returnValue !== null && returnValue !== void 0 ? returnValue : false);
454
- }
455
- read(nodeIds) {
456
- const _super = Object.create(null, {
457
- read: { get: () => super.read }
458
- });
459
- return __awaiter(this, void 0, void 0, function* () {
460
- let nodes = yield _super.read.call(this, nodeIds);
461
- return this._processResult(nodes);
462
- });
472
+ constructor(client, returnVariable = true, returnMethod = true, returnDescription = false) {
473
+ super(client, returnDescription, returnVariable, returnMethod, common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), false, true, false, false, true);
463
474
  }
464
475
  readByReferences(references) {
465
476
  const _super = Object.create(null, {
@@ -474,34 +485,37 @@ class UaObjectReader extends UaNodeReader {
474
485
  }
475
486
  if (0 == objectReferences.length)
476
487
  return [];
477
- let nodes = yield _super.readByReferences.call(this, objectReferences);
478
- return this._processResult(nodes);
488
+ return yield _super.readByReferences.call(this, objectReferences);
479
489
  });
480
490
  }
481
- _processResult(nodes) {
482
- let objectNodes = [];
483
- for (let item of nodes) {
484
- if (item.nodeClass == opcua_webapi_1.NodeClass.Object) {
485
- objectNodes.push(item);
486
- }
487
- }
488
- return objectNodes;
489
- }
490
491
  }
491
492
  exports.UaObjectReader = UaObjectReader;
492
- class UaTypeReader extends UaNodeReader {
493
- constructor(client) {
494
- super(client, true, true, true, true, false);
493
+ class UaFullObjectReader extends UaNodeReader {
494
+ constructor(client, returnDescription = true, returnValue = false) {
495
+ super(client, returnDescription, true, true, common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), true, true, returnValue, true, returnValue);
495
496
  }
496
- read(nodeIds) {
497
+ readByReferences(references) {
497
498
  const _super = Object.create(null, {
498
- read: { get: () => super.read }
499
+ readByReferences: { get: () => super.readByReferences }
499
500
  });
500
501
  return __awaiter(this, void 0, void 0, function* () {
501
- let nodes = yield _super.read.call(this, nodeIds);
502
- return this._processResult(nodes);
502
+ let objectReferences = [];
503
+ for (let item of references) {
504
+ if (item.nodeClass == opcua_webapi_1.NodeClass.Object) {
505
+ objectReferences.push(item);
506
+ }
507
+ }
508
+ if (0 == objectReferences.length)
509
+ return [];
510
+ return yield _super.readByReferences.call(this, objectReferences);
503
511
  });
504
512
  }
513
+ }
514
+ exports.UaFullObjectReader = UaFullObjectReader;
515
+ class UaTypeReader extends UaNodeReader {
516
+ constructor(client, returnDescription = false) {
517
+ super(client, returnDescription, true, true, common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), false, true, false, true, false);
518
+ }
505
519
  readByReferences(references) {
506
520
  const _super = Object.create(null, {
507
521
  readByReferences: { get: () => super.readByReferences }
@@ -518,64 +532,8 @@ class UaTypeReader extends UaNodeReader {
518
532
  }
519
533
  if (0 == typeReferences.length)
520
534
  return [];
521
- let nodes = yield _super.readByReferences.call(this, typeReferences);
522
- return this._processResult(nodes);
535
+ return yield _super.readByReferences.call(this, typeReferences);
523
536
  });
524
537
  }
525
- _processResult(nodes) {
526
- let typeNodes = [];
527
- for (let item of nodes) {
528
- if (item.nodeClass == opcua_webapi_1.NodeClass.ObjectType ||
529
- item.nodeClass == opcua_webapi_1.NodeClass.VariableType ||
530
- item.nodeClass == opcua_webapi_1.NodeClass.DataType ||
531
- item.nodeClass == opcua_webapi_1.NodeClass.ReferenceType) {
532
- typeNodes.push(item);
533
- }
534
- }
535
- return typeNodes;
536
- }
537
538
  }
538
539
  exports.UaTypeReader = UaTypeReader;
539
- class UaObjectDataReader extends UaNodeReader {
540
- constructor(client) {
541
- super(client, false, true, false, false, true);
542
- }
543
- readValues(nodeIds) {
544
- const _super = Object.create(null, {
545
- read: { get: () => super.read }
546
- });
547
- return __awaiter(this, void 0, void 0, function* () {
548
- let nodes = yield _super.read.call(this, nodeIds);
549
- return this._processResult(nodes);
550
- });
551
- }
552
- readValuesByReferences(references) {
553
- const _super = Object.create(null, {
554
- readByReferences: { get: () => super.readByReferences }
555
- });
556
- return __awaiter(this, void 0, void 0, function* () {
557
- let nodes = yield _super.readByReferences.call(this, references);
558
- return this._processResult(nodes);
559
- });
560
- }
561
- _processResult(nodes) {
562
- let ret = new Map();
563
- for (let item of nodes) {
564
- if (item.nodeClass != opcua_webapi_1.NodeClass.Object)
565
- continue;
566
- let id = item.nodeId.toString();
567
- let objectNode = item;
568
- let members = objectNode.getMembers(opcua_webapi_1.NodeClass.Variable);
569
- let serializedObject = {};
570
- serializedObject["_id"] = id;
571
- serializedObject["_name"] = objectNode.displayName.text;
572
- for (let member of members) {
573
- let value = member.value;
574
- serializedObject[member.browseName] = (null == value) ? null : value.value;
575
- }
576
- ret.set(id, serializedObject);
577
- }
578
- return ret;
579
- }
580
- }
581
- exports.UaObjectDataReader = UaObjectDataReader;
@@ -0,0 +1,14 @@
1
+ import { UaObject, UaObjectType } from "../../common";
2
+ import { UaDataTypeDictionary } from "./UaDataTypeDictionary";
3
+ import { UaObjectTypeDictionary } from "./UaObjectTypeDictionary";
4
+ export declare class UaObjectSerializer {
5
+ private _objectDictionary;
6
+ private _dataTypeDictionary;
7
+ constructor(objectDictionary: UaObjectTypeDictionary, dataTypeDictionary: UaDataTypeDictionary);
8
+ toJson(object: UaObject): any;
9
+ }
10
+ export declare class UaObjectTypeSerializer {
11
+ private _dataTypeDictionary;
12
+ constructor(dataTypeDictionary: UaDataTypeDictionary);
13
+ toJson(objectType: UaObjectType): any;
14
+ }
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UaObjectTypeSerializer = exports.UaObjectSerializer = void 0;
4
+ class UaObjectSerializer {
5
+ constructor(objectDictionary, dataTypeDictionary) {
6
+ this._objectDictionary = objectDictionary;
7
+ this._dataTypeDictionary = dataTypeDictionary;
8
+ }
9
+ toJson(object) {
10
+ let variableMembers = object.variableMembers;
11
+ let methodMembers = object.methodMembers;
12
+ let objectType = this._objectDictionary.getObjectType(object.typeDefinitionId);
13
+ let variables = [];
14
+ let properties = [];
15
+ let methods = [];
16
+ for (let variable of variableMembers) {
17
+ if (variable.isProperty) {
18
+ let propertyJson = {
19
+ name: variable.browseName,
20
+ displayName: variable.displayName.text,
21
+ value: (variable.value) ? variable.value.value : null
22
+ };
23
+ properties.push(propertyJson);
24
+ }
25
+ else {
26
+ let dataType = this._dataTypeDictionary.getDataType(variable.dataType);
27
+ if (!dataType)
28
+ continue;
29
+ let variableJson = {
30
+ id: variable.nodeId.toString(),
31
+ name: variable.browseName,
32
+ displayName: variable.displayName.text,
33
+ dataType: dataType.browseName,
34
+ accessLevel: variable.accessLevel,
35
+ historizing: (variable.historizing) ? variable.historizing : undefined,
36
+ valueRank: (-1 != variable.valueRank) ? variable.valueRank : undefined
37
+ };
38
+ variables.push(variableJson);
39
+ }
40
+ }
41
+ for (let method of methodMembers) {
42
+ let inputArguments = [];
43
+ let outputArguments = [];
44
+ if (method.inputArguments) {
45
+ for (let inputArgument of method.inputArguments) {
46
+ let dataType = this._dataTypeDictionary.getDataType(inputArgument.dataType);
47
+ if (!dataType)
48
+ continue;
49
+ let inputArgumentJson = {
50
+ name: inputArgument.name,
51
+ dataType: dataType.browseName
52
+ };
53
+ inputArguments.push(inputArgumentJson);
54
+ }
55
+ }
56
+ if (method.outputArguments) {
57
+ for (let outputArgument of method.outputArguments) {
58
+ let dataType = this._dataTypeDictionary.getDataType(outputArgument.dataType);
59
+ if (!dataType)
60
+ continue;
61
+ let outputArgumentJson = {
62
+ name: outputArgument.name,
63
+ dataType: dataType.browseName
64
+ };
65
+ outputArguments.push(outputArgumentJson);
66
+ }
67
+ }
68
+ let methodJson = {
69
+ id: method.nodeId.toString(),
70
+ name: method.browseName,
71
+ displayName: method.displayName.text,
72
+ inputArguments: (inputArguments.length > 0) ? inputArguments : undefined,
73
+ outputArguments: (outputArguments.length > 0) ? outputArguments : undefined
74
+ };
75
+ methods.push(methodJson);
76
+ }
77
+ let ret = {
78
+ id: object.nodeId.toString(),
79
+ name: object.browseName,
80
+ displayName: object.displayName.text,
81
+ description: (object.description) ? object.description.text : undefined,
82
+ objectType: objectType.browseName,
83
+ variables: (variables.length > 0) ? variables : undefined,
84
+ properties: (properties.length > 0) ? properties : undefined,
85
+ methods: (methods.length > 0) ? methods : undefined
86
+ };
87
+ return ret;
88
+ }
89
+ }
90
+ exports.UaObjectSerializer = UaObjectSerializer;
91
+ class UaObjectTypeSerializer {
92
+ constructor(dataTypeDictionary) {
93
+ this._dataTypeDictionary = dataTypeDictionary;
94
+ }
95
+ toJson(objectType) {
96
+ let variableMembers = objectType.variableMembers;
97
+ let methodMembers = objectType.methodMembers;
98
+ let variables = [];
99
+ let properties = [];
100
+ let methods = [];
101
+ for (let variable of variableMembers) {
102
+ let dataType = this._dataTypeDictionary.getDataType(variable.dataType);
103
+ if (!dataType)
104
+ continue;
105
+ let variableJson = {
106
+ id: variable.nodeId.toString(),
107
+ name: variable.browseName,
108
+ displayName: variable.displayName.text,
109
+ dataType: dataType.browseName,
110
+ accessLevel: variable.accessLevel,
111
+ historizing: (variable.historizing) ? variable.historizing : undefined,
112
+ valueRank: (-1 != variable.valueRank) ? variable.valueRank : undefined
113
+ };
114
+ if (variable.isProperty) {
115
+ properties.push(variableJson);
116
+ }
117
+ else {
118
+ variables.push(variableJson);
119
+ }
120
+ }
121
+ for (let method of methodMembers) {
122
+ let inputArguments = [];
123
+ let outputArguments = [];
124
+ for (let inputArgument of method.inputArguments) {
125
+ let dataType = this._dataTypeDictionary.getDataType(inputArgument.dataType);
126
+ if (!dataType)
127
+ continue;
128
+ let inputArgumentJson = {
129
+ name: inputArgument.name,
130
+ dataType: dataType.browseName
131
+ };
132
+ inputArguments.push(inputArgumentJson);
133
+ }
134
+ for (let outputArgument of method.outputArguments) {
135
+ let dataType = this._dataTypeDictionary.getDataType(outputArgument.dataType);
136
+ if (!dataType)
137
+ continue;
138
+ let outputArgumentJson = {
139
+ name: outputArgument.name,
140
+ dataType: dataType.browseName
141
+ };
142
+ outputArguments.push(outputArgumentJson);
143
+ }
144
+ let methodJson = {
145
+ id: method.nodeId.toString(),
146
+ name: method.browseName,
147
+ displayName: method.displayName.text,
148
+ inputArguments: (inputArguments.length > 0) ? inputArguments : undefined,
149
+ outputArguments: (outputArguments.length > 0) ? outputArguments : undefined
150
+ };
151
+ methods.push(methodJson);
152
+ }
153
+ let ret = {
154
+ id: objectType.nodeId.toString(),
155
+ name: objectType.browseName,
156
+ displayName: objectType.displayName.text,
157
+ description: (objectType.description) ? objectType.description.text : undefined,
158
+ objectType: objectType.browseName,
159
+ variables: (variables.length > 0) ? variables : undefined,
160
+ properties: (properties.length > 0) ? properties : undefined,
161
+ methods: (methods.length > 0) ? methods : undefined
162
+ };
163
+ return ret;
164
+ }
165
+ }
166
+ exports.UaObjectTypeSerializer = UaObjectTypeSerializer;
@@ -48,7 +48,7 @@ class UaObjectTypeDictionary {
48
48
  return;
49
49
  // Read child type
50
50
  let nodeIdsToBrowse = [];
51
- let nodeReader = new UaNodeReader_1.UaNodeReader(this._client, false, false, false, false, false);
51
+ let nodeReader = new UaNodeReader_1.UaNodeReader(this._client, false, false, false, common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), false, false, false, false, true);
52
52
  let nodes = yield nodeReader.readByReferences(referencesToRead);
53
53
  for (let node of nodes) {
54
54
  if (opcua_webapi_1.NodeClass.ObjectType != node.nodeClass)
@@ -48,7 +48,7 @@ class UaReferenceTypeDictionary {
48
48
  return;
49
49
  // Read child type
50
50
  let nodeIdsToBrowse = [];
51
- let nodeReader = new UaNodeReader_1.UaNodeReader(this._client, false, false, false, false, false);
51
+ let nodeReader = new UaNodeReader_1.UaNodeReader(this._client, false, false, false, common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), false, false, false, false, false);
52
52
  let nodes = yield nodeReader.readByReferences(referencesToRead);
53
53
  for (let node of nodes) {
54
54
  if (opcua_webapi_1.NodeClass.ReferenceType != node.nodeClass)
@@ -5,3 +5,4 @@ export * from "./UaNodeBrowser";
5
5
  export * from "./UaNodeReader";
6
6
  export * from "./UaModelling";
7
7
  export * from "./UaReferenceToNode";
8
+ export * from "./UaNodeSerializer";
@@ -21,3 +21,4 @@ __exportStar(require("./UaNodeBrowser"), exports);
21
21
  __exportStar(require("./UaNodeReader"), exports);
22
22
  __exportStar(require("./UaModelling"), exports);
23
23
  __exportStar(require("./UaReferenceToNode"), exports);
24
+ __exportStar(require("./UaNodeSerializer"), exports);
@@ -13,4 +13,5 @@ export declare class UaMethod extends UaInstanceNode {
13
13
  get inputArguments(): Array<UaArgument> | null;
14
14
  get outputArguments(): Array<UaArgument> | null;
15
15
  toJson(): any;
16
+ toReadableJson(): any;
16
17
  }
@@ -71,6 +71,28 @@ class UaMethod extends _1.UaInstanceNode {
71
71
  };
72
72
  return ret;
73
73
  }
74
+ toReadableJson() {
75
+ let inputArgs = [];
76
+ let outputArgs = [];
77
+ if (this._inputArguments) {
78
+ for (let item of this._inputArguments) {
79
+ inputArgs.push(item.toJson());
80
+ }
81
+ }
82
+ if (this._outputArguments) {
83
+ for (let item of this._outputArguments) {
84
+ outputArgs.push(item.toJson());
85
+ }
86
+ }
87
+ return {
88
+ id: this._nodeId.toString(),
89
+ name: this._browseName,
90
+ displayName: this._displayName.text,
91
+ description: (this._description) ? this._description.text : undefined,
92
+ inputArguments: (inputArgs.length != 0) ? inputArgs : undefined,
93
+ outputArguments: (outputArgs.length != 0) ? outputArgs : undefined
94
+ };
95
+ }
74
96
  }
75
97
  exports.UaMethod = UaMethod;
76
98
  UaMethod.InputArguments = "InputArguments";