opcua-webapi-ts 1.1.22 → 1.1.23

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.
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.UaTypeReader = exports.UaObjectReader = exports.UaNodeReader = void 0;
12
+ exports.UaObjectDataReader = exports.UaTypeReader = exports.UaObjectReader = exports.UaNodeReader = void 0;
13
13
  const opcua_webapi_1 = require("opcua-webapi");
14
14
  const common_1 = require("../../common");
15
15
  const UaNodeBrowser_1 = require("./UaNodeBrowser");
@@ -458,15 +458,35 @@ class UaObjectReader extends UaNodeReader {
458
458
  });
459
459
  return __awaiter(this, void 0, void 0, function* () {
460
460
  let nodes = yield _super.read.call(this, nodeIds);
461
- let objectNodes = [];
462
- for (let item of nodes) {
461
+ return this._processResult(nodes);
462
+ });
463
+ }
464
+ readByReferences(references) {
465
+ const _super = Object.create(null, {
466
+ readByReferences: { get: () => super.readByReferences }
467
+ });
468
+ return __awaiter(this, void 0, void 0, function* () {
469
+ let objectReferences = [];
470
+ for (let item of references) {
463
471
  if (item.nodeClass == opcua_webapi_1.NodeClass.Object) {
464
- objectNodes.push(item);
472
+ objectReferences.push(item);
465
473
  }
466
474
  }
467
- return objectNodes;
475
+ if (0 == objectReferences.length)
476
+ return [];
477
+ let nodes = yield _super.readByReferences.call(this, objectReferences);
478
+ return this._processResult(nodes);
468
479
  });
469
480
  }
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
+ }
470
490
  }
471
491
  exports.UaObjectReader = UaObjectReader;
472
492
  class UaTypeReader extends UaNodeReader {
@@ -479,17 +499,83 @@ class UaTypeReader extends UaNodeReader {
479
499
  });
480
500
  return __awaiter(this, void 0, void 0, function* () {
481
501
  let nodes = yield _super.read.call(this, nodeIds);
482
- let typeNodes = [];
483
- for (let item of nodes) {
502
+ return this._processResult(nodes);
503
+ });
504
+ }
505
+ readByReferences(references) {
506
+ const _super = Object.create(null, {
507
+ readByReferences: { get: () => super.readByReferences }
508
+ });
509
+ return __awaiter(this, void 0, void 0, function* () {
510
+ let typeReferences = [];
511
+ for (let item of references) {
484
512
  if (item.nodeClass == opcua_webapi_1.NodeClass.ObjectType ||
485
513
  item.nodeClass == opcua_webapi_1.NodeClass.VariableType ||
486
514
  item.nodeClass == opcua_webapi_1.NodeClass.DataType ||
487
515
  item.nodeClass == opcua_webapi_1.NodeClass.ReferenceType) {
488
- typeNodes.push(item);
516
+ typeReferences.push(item);
489
517
  }
490
518
  }
491
- return typeNodes;
519
+ if (0 == typeReferences.length)
520
+ return [];
521
+ let nodes = yield _super.readByReferences.call(this, typeReferences);
522
+ return this._processResult(nodes);
492
523
  });
493
524
  }
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
+ }
494
537
  }
495
538
  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;
@@ -49,9 +49,15 @@ class UaObject extends _1.UaInstanceNode {
49
49
  return ret;
50
50
  }
51
51
  toJson() {
52
- let children = [];
52
+ let variables = [];
53
+ let methods = [];
53
54
  for (let item of this._children) {
54
- children.push(item.toJson());
55
+ if (opcua_webapi_1.NodeClass.Variable == item.nodeClass) {
56
+ variables.push(item.toJson());
57
+ }
58
+ else if (opcua_webapi_1.NodeClass.Method == item.nodeClass) {
59
+ methods.push(item.toJson());
60
+ }
55
61
  }
56
62
  let ret = {
57
63
  nodeId: this._nodeId.toString(),
@@ -60,8 +66,9 @@ class UaObject extends _1.UaInstanceNode {
60
66
  displayName: this._displayName.text,
61
67
  description: (this._description) ? this._description.text : undefined,
62
68
  typeDefinitionId: this._typeDefinitionId.toString(),
63
- eventNotifier: this._eventNotifier,
64
- children: (children.length != 0) ? children : undefined
69
+ eventNotifier: (this._eventNotifier != 0) ? this._eventNotifier : undefined,
70
+ variables: (variables.length != 0) ? variables : undefined,
71
+ methods: (methods.length != 0) ? methods : undefined
65
72
  };
66
73
  return ret;
67
74
  }
@@ -48,11 +48,17 @@ class UaObjectType extends _1.UaDefintionNode {
48
48
  this._isObjectMemberRead = value;
49
49
  }
50
50
  toJson() {
51
- let children = [];
51
+ let variables = [];
52
+ let methods = [];
52
53
  for (let item of this._children) {
53
54
  if (item.nodeClass == opcua_webapi_1.NodeClass.ObjectType)
54
55
  continue;
55
- children.push(item.toJson());
56
+ if (opcua_webapi_1.NodeClass.Variable == item.nodeClass) {
57
+ variables.push(item.toJson());
58
+ }
59
+ else if (opcua_webapi_1.NodeClass.Method == item.nodeClass) {
60
+ methods.push(item.toJson());
61
+ }
56
62
  }
57
63
  let ret = {
58
64
  nodeId: this._nodeId.toString(),
@@ -61,7 +67,8 @@ class UaObjectType extends _1.UaDefintionNode {
61
67
  displayName: this._displayName.text,
62
68
  description: (this._description) ? this._description.text : undefined,
63
69
  isAbstract: this._isAbstract,
64
- children: (children.length != 0) ? children : undefined
70
+ variables: (variables.length != 0) ? variables : undefined,
71
+ methods: (methods.length != 0) ? methods : undefined
65
72
  };
66
73
  return ret;
67
74
  }
@@ -68,9 +68,9 @@ class UaVariable extends _1.UaInstanceNode {
68
68
  displayName: this._displayName.text,
69
69
  typeDefinitionId: this._typeDefinitionId.toString(),
70
70
  dataType: this._dataType.toString(),
71
- valueRank: this._valueRank,
71
+ valueRank: (this._valueRank != 0) ? this._valueRank : undefined,
72
72
  accessLevel: this._accessLevel,
73
- historizing: this._historizing,
73
+ historizing: (this._historizing) ? true : undefined,
74
74
  value: this._dataValue ? this._dataValue.value.value : undefined,
75
75
  children: (children.length != 0) ? children : undefined
76
76
  };
@@ -23,8 +23,18 @@ export declare class UaNodeReader {
23
23
  export declare class UaObjectReader extends UaNodeReader {
24
24
  constructor(client: UaWebClient, returnDescription?: boolean | null, returnValue?: boolean | null);
25
25
  read(nodeIds: Array<UaNodeId>): Promise<Array<UaObject>>;
26
+ readByReferences(references: Array<UaReference>): Promise<Array<UaObject>>;
27
+ private _processResult;
26
28
  }
27
29
  export declare class UaTypeReader extends UaNodeReader {
28
30
  constructor(client: UaWebClient);
29
31
  read(nodeIds: Array<UaNodeId>): Promise<Array<UaDefintionNode>>;
32
+ readByReferences(references: Array<UaReference>): Promise<Array<UaDefintionNode>>;
33
+ private _processResult;
34
+ }
35
+ export declare class UaObjectDataReader extends UaNodeReader {
36
+ constructor(client: UaWebClient);
37
+ readValues(nodeIds: Array<UaNodeId>): Promise<Map<string, any>>;
38
+ readValuesByReferences(references: Array<UaReference>): Promise<Map<string, any>>;
39
+ private _processResult;
30
40
  }
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.UaTypeReader = exports.UaObjectReader = exports.UaNodeReader = void 0;
12
+ exports.UaObjectDataReader = exports.UaTypeReader = exports.UaObjectReader = exports.UaNodeReader = void 0;
13
13
  const opcua_webapi_1 = require("opcua-webapi");
14
14
  const common_1 = require("../../common");
15
15
  const UaNodeBrowser_1 = require("./UaNodeBrowser");
@@ -458,15 +458,35 @@ class UaObjectReader extends UaNodeReader {
458
458
  });
459
459
  return __awaiter(this, void 0, void 0, function* () {
460
460
  let nodes = yield _super.read.call(this, nodeIds);
461
- let objectNodes = [];
462
- for (let item of nodes) {
461
+ return this._processResult(nodes);
462
+ });
463
+ }
464
+ readByReferences(references) {
465
+ const _super = Object.create(null, {
466
+ readByReferences: { get: () => super.readByReferences }
467
+ });
468
+ return __awaiter(this, void 0, void 0, function* () {
469
+ let objectReferences = [];
470
+ for (let item of references) {
463
471
  if (item.nodeClass == opcua_webapi_1.NodeClass.Object) {
464
- objectNodes.push(item);
472
+ objectReferences.push(item);
465
473
  }
466
474
  }
467
- return objectNodes;
475
+ if (0 == objectReferences.length)
476
+ return [];
477
+ let nodes = yield _super.readByReferences.call(this, objectReferences);
478
+ return this._processResult(nodes);
468
479
  });
469
480
  }
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
+ }
470
490
  }
471
491
  exports.UaObjectReader = UaObjectReader;
472
492
  class UaTypeReader extends UaNodeReader {
@@ -479,17 +499,83 @@ class UaTypeReader extends UaNodeReader {
479
499
  });
480
500
  return __awaiter(this, void 0, void 0, function* () {
481
501
  let nodes = yield _super.read.call(this, nodeIds);
482
- let typeNodes = [];
483
- for (let item of nodes) {
502
+ return this._processResult(nodes);
503
+ });
504
+ }
505
+ readByReferences(references) {
506
+ const _super = Object.create(null, {
507
+ readByReferences: { get: () => super.readByReferences }
508
+ });
509
+ return __awaiter(this, void 0, void 0, function* () {
510
+ let typeReferences = [];
511
+ for (let item of references) {
484
512
  if (item.nodeClass == opcua_webapi_1.NodeClass.ObjectType ||
485
513
  item.nodeClass == opcua_webapi_1.NodeClass.VariableType ||
486
514
  item.nodeClass == opcua_webapi_1.NodeClass.DataType ||
487
515
  item.nodeClass == opcua_webapi_1.NodeClass.ReferenceType) {
488
- typeNodes.push(item);
516
+ typeReferences.push(item);
489
517
  }
490
518
  }
491
- return typeNodes;
519
+ if (0 == typeReferences.length)
520
+ return [];
521
+ let nodes = yield _super.readByReferences.call(this, typeReferences);
522
+ return this._processResult(nodes);
492
523
  });
493
524
  }
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
+ }
494
537
  }
495
538
  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;
@@ -49,9 +49,15 @@ class UaObject extends _1.UaInstanceNode {
49
49
  return ret;
50
50
  }
51
51
  toJson() {
52
- let children = [];
52
+ let variables = [];
53
+ let methods = [];
53
54
  for (let item of this._children) {
54
- children.push(item.toJson());
55
+ if (opcua_webapi_1.NodeClass.Variable == item.nodeClass) {
56
+ variables.push(item.toJson());
57
+ }
58
+ else if (opcua_webapi_1.NodeClass.Method == item.nodeClass) {
59
+ methods.push(item.toJson());
60
+ }
55
61
  }
56
62
  let ret = {
57
63
  nodeId: this._nodeId.toString(),
@@ -60,8 +66,9 @@ class UaObject extends _1.UaInstanceNode {
60
66
  displayName: this._displayName.text,
61
67
  description: (this._description) ? this._description.text : undefined,
62
68
  typeDefinitionId: this._typeDefinitionId.toString(),
63
- eventNotifier: this._eventNotifier,
64
- children: (children.length != 0) ? children : undefined
69
+ eventNotifier: (this._eventNotifier != 0) ? this._eventNotifier : undefined,
70
+ variables: (variables.length != 0) ? variables : undefined,
71
+ methods: (methods.length != 0) ? methods : undefined
65
72
  };
66
73
  return ret;
67
74
  }
@@ -48,11 +48,17 @@ class UaObjectType extends _1.UaDefintionNode {
48
48
  this._isObjectMemberRead = value;
49
49
  }
50
50
  toJson() {
51
- let children = [];
51
+ let variables = [];
52
+ let methods = [];
52
53
  for (let item of this._children) {
53
54
  if (item.nodeClass == opcua_webapi_1.NodeClass.ObjectType)
54
55
  continue;
55
- children.push(item.toJson());
56
+ if (opcua_webapi_1.NodeClass.Variable == item.nodeClass) {
57
+ variables.push(item.toJson());
58
+ }
59
+ else if (opcua_webapi_1.NodeClass.Method == item.nodeClass) {
60
+ methods.push(item.toJson());
61
+ }
56
62
  }
57
63
  let ret = {
58
64
  nodeId: this._nodeId.toString(),
@@ -61,7 +67,8 @@ class UaObjectType extends _1.UaDefintionNode {
61
67
  displayName: this._displayName.text,
62
68
  description: (this._description) ? this._description.text : undefined,
63
69
  isAbstract: this._isAbstract,
64
- children: (children.length != 0) ? children : undefined
70
+ variables: (variables.length != 0) ? variables : undefined,
71
+ methods: (methods.length != 0) ? methods : undefined
65
72
  };
66
73
  return ret;
67
74
  }
@@ -68,9 +68,9 @@ class UaVariable extends _1.UaInstanceNode {
68
68
  displayName: this._displayName.text,
69
69
  typeDefinitionId: this._typeDefinitionId.toString(),
70
70
  dataType: this._dataType.toString(),
71
- valueRank: this._valueRank,
71
+ valueRank: (this._valueRank != 0) ? this._valueRank : undefined,
72
72
  accessLevel: this._accessLevel,
73
- historizing: this._historizing,
73
+ historizing: (this._historizing) ? true : undefined,
74
74
  value: this._dataValue ? this._dataValue.value.value : undefined,
75
75
  children: (children.length != 0) ? children : undefined
76
76
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opcua-webapi-ts",
3
- "version": "1.1.22",
3
+ "version": "1.1.23",
4
4
  "description": "Provides OPC UA WebAPI wrapper and client based on opcua-webapi-typescript",
5
5
  "author": "DingYan",
6
6
  "license": "MIT",