opcua-webapi-ts 1.1.18 → 1.1.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.
@@ -9,181 +9,10 @@ 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 = exports.UaSubtypeBrowser = exports.UaLinkBrowser = exports.UaChildBrowser = exports.UaNodeReferenceBrowser = void 0;
12
+ 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
- class UaNodeReferenceBrowser {
16
- constructor(client, nodeIds, referenceType, nodeClassToReturn, returnDescription, maxNodesPerBrowse, maxReferencesPerNode) {
17
- this._client = client;
18
- this._nodesToBrowse = [];
19
- this._referenceType = referenceType;
20
- this._nodeClassToReturn = nodeClassToReturn;
21
- this._continuationPointToBrowse = [];
22
- this._returnDescription = returnDescription !== null && returnDescription !== void 0 ? returnDescription : false;
23
- this._maxNodesPerBrowse = (null == maxNodesPerBrowse || maxNodesPerBrowse <= 0) ? 50 : maxNodesPerBrowse;
24
- this._maxReferencesPerNode = (null == maxReferencesPerNode || maxReferencesPerNode < 0) ? 50 : maxReferencesPerNode;
25
- this._readResults = new Map();
26
- if (this._nodeClassToReturn != 0) {
27
- let nodeIdSet = new Set;
28
- for (let item of nodeIds) {
29
- if (nodeIdSet.has(item.toString()))
30
- continue;
31
- nodeIdSet.add(item.toString());
32
- this._nodesToBrowse.push(item);
33
- }
34
- }
35
- }
36
- browse() {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- if (this.isFinish())
39
- return;
40
- yield this.browseOnce();
41
- yield this.browse();
42
- });
43
- }
44
- browseOnce() {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- if (this._continuationPointToBrowse.length != 0) {
47
- yield this._browseContinuationPoints();
48
- }
49
- else if (this._nodesToBrowse.length != 0) {
50
- yield this._browseNodes();
51
- }
52
- });
53
- }
54
- results() {
55
- let results = [];
56
- for (let item of this._readResults) {
57
- results.push({
58
- nodeId: (0, common_1.parseUaNodeId)(item[0]),
59
- references: item[1]
60
- });
61
- }
62
- this._readResults.clear();
63
- return results;
64
- }
65
- isFinish() {
66
- return (this._nodesToBrowse.length == 0) && (this._continuationPointToBrowse.length == 0);
67
- }
68
- _browseNodes() {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- var _a;
71
- let nodesToBrowse = this._nodesToBrowse.splice(0, this._maxNodesPerBrowse);
72
- let browseDescriptions = [];
73
- for (let item of nodesToBrowse) {
74
- let browseDescription = new common_1.UaBrowseDescription(item, opcua_webapi_1.BrowseDirection.Forward, this._referenceType, true, this._nodeClassToReturn, 63);
75
- browseDescriptions.push(browseDescription);
76
- }
77
- let results = yield this._client.browse(browseDescriptions, this._maxReferencesPerNode);
78
- for (let i = 0; i < nodesToBrowse.length; ++i) {
79
- let currentNodeId = nodesToBrowse[i];
80
- let currentResult = results[i];
81
- if (currentResult.statusCode.isNotGood())
82
- throw new common_1.UaError(currentResult.statusCode);
83
- let currentReferences = this._readResults.get(currentNodeId.toString());
84
- if (!currentReferences) {
85
- currentReferences = [];
86
- this._readResults.set(currentNodeId.toString(), currentReferences);
87
- }
88
- let newReferences = [];
89
- for (let item of currentResult.references) {
90
- let nodeId = item.nodeId.getNodeId();
91
- let typeDefinition = (_a = item.typeDefinition) === null || _a === void 0 ? void 0 : _a.getNodeId();
92
- if (null == nodeId || null === typeDefinition)
93
- continue;
94
- let reference = new common_1.UaReference(nodeId, (item.nodeClass) ? item.nodeClass : opcua_webapi_1.NodeClass.Unspecified, item.browseName ? item.browseName : "", item.displayName ? item.displayName : common_1.UaLocalizedText.nullText, item.referenceTypeId ? item.referenceTypeId : common_1.UaNodeId.nullNodeId, (typeDefinition) ? typeDefinition : common_1.UaNodeId.nullNodeId);
95
- currentReferences.push(reference);
96
- newReferences.push(reference);
97
- }
98
- if (currentResult.continuationPoint) {
99
- this._continuationPointToBrowse.push({
100
- nodeId: currentNodeId,
101
- continuationPoint: currentResult.continuationPoint
102
- });
103
- }
104
- if (this._returnDescription)
105
- yield this._readDescriptions(newReferences);
106
- }
107
- });
108
- }
109
- _browseContinuationPoints() {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- var _a;
112
- let cpsToBrowse = this._continuationPointToBrowse.splice(0, this._maxNodesPerBrowse);
113
- let continuationPoints = [];
114
- for (let item of cpsToBrowse) {
115
- continuationPoints.push(item.continuationPoint);
116
- }
117
- let results = yield this._client.browseNext(continuationPoints, false);
118
- for (let i = 0; i < cpsToBrowse.length; ++i) {
119
- let currentNodeId = cpsToBrowse[i].nodeId;
120
- let currentResult = results[i];
121
- if (currentResult.statusCode.isNotGood())
122
- throw new common_1.UaError(currentResult.statusCode);
123
- let newReferences = [];
124
- for (let item of currentResult.references) {
125
- let nodeId = item.nodeId.getNodeId();
126
- let typeDefinition = (_a = item.typeDefinition) === null || _a === void 0 ? void 0 : _a.getNodeId();
127
- if (null == nodeId || null === typeDefinition)
128
- continue;
129
- let currentReferences = this._readResults.get(currentNodeId.toString());
130
- if (!currentReferences) {
131
- currentReferences = [];
132
- this._readResults.set(currentNodeId.toString(), currentReferences);
133
- }
134
- let reference = new common_1.UaReference(nodeId, (item.nodeClass) ? item.nodeClass : opcua_webapi_1.NodeClass.Unspecified, item.browseName ? item.browseName : "", item.displayName ? item.displayName : common_1.UaLocalizedText.nullText, item.referenceTypeId ? item.referenceTypeId : common_1.UaNodeId.nullNodeId, (typeDefinition) ? typeDefinition : common_1.UaNodeId.nullNodeId);
135
- currentReferences.push(reference);
136
- newReferences.push(reference);
137
- }
138
- if (currentResult.continuationPoint) {
139
- this._continuationPointToBrowse.push({
140
- nodeId: currentNodeId,
141
- continuationPoint: currentResult.continuationPoint
142
- });
143
- }
144
- if (this._returnDescription)
145
- yield this._readDescriptions(newReferences);
146
- }
147
- });
148
- }
149
- _readDescriptions(references) {
150
- return __awaiter(this, void 0, void 0, function* () {
151
- if (references.length === 0)
152
- return;
153
- let nodesToRead = [];
154
- for (let item of references) {
155
- nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
156
- }
157
- let dataValues = yield this._client.read(nodesToRead);
158
- for (let i = 0; i < references.length; ++i) {
159
- if (dataValues[i].statusCode.isGood()) {
160
- let description = dataValues[i].value.toLocalizedText();
161
- if (description)
162
- references[i].description = description;
163
- }
164
- }
165
- });
166
- }
167
- }
168
- exports.UaNodeReferenceBrowser = UaNodeReferenceBrowser;
169
- class UaChildBrowser extends UaNodeReferenceBrowser {
170
- constructor(client, nodeIds, returnDescription) {
171
- super(client, nodeIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), opcua_webapi_1.NodeClass.Object, returnDescription !== null && returnDescription !== void 0 ? returnDescription : false, 20);
172
- }
173
- }
174
- exports.UaChildBrowser = UaChildBrowser;
175
- class UaLinkBrowser extends UaNodeReferenceBrowser {
176
- constructor(client, nodeIds, returnDescription) {
177
- super(client, nodeIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.NonHierarchicalReferences), opcua_webapi_1.NodeClass.Object, returnDescription !== null && returnDescription !== void 0 ? returnDescription : false, 20);
178
- }
179
- }
180
- exports.UaLinkBrowser = UaLinkBrowser;
181
- class UaSubtypeBrowser extends UaNodeReferenceBrowser {
182
- constructor(client, nodeIds, returnDescription) {
183
- super(client, nodeIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), opcua_webapi_1.NodeClass.ObjectType | opcua_webapi_1.NodeClass.VariableType | opcua_webapi_1.NodeClass.DataType | opcua_webapi_1.NodeClass.ReferenceType, returnDescription !== null && returnDescription !== void 0 ? returnDescription : false, 20);
184
- }
185
- }
186
- exports.UaSubtypeBrowser = UaSubtypeBrowser;
15
+ const UaNodeBrowser_1 = require("./UaNodeBrowser");
187
16
  class UaNodeReader {
188
17
  constructor(client, returnDescription, returnVariable, returnMethod, returnAttributes, returnValue) {
189
18
  this._client = client;
@@ -239,7 +68,7 @@ class UaNodeReader {
239
68
  nodeIdsToBrowse.push(item.nodeId);
240
69
  nodeIdsSet.add(item.nodeId.toString());
241
70
  }
242
- let nodeReferenceBrowser = new UaNodeReferenceBrowser(this._client, nodeIdsToBrowse, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), this._nodeClassToReturn, false);
71
+ let nodeReferenceBrowser = new UaNodeBrowser_1.UaNodeBrowser(this._client, nodeIdsToBrowse, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), this._nodeClassToReturn, false);
243
72
  yield nodeReferenceBrowser.browse();
244
73
  let childReferences = nodeReferenceBrowser.results();
245
74
  let childNodesToBrowse = [];
@@ -256,7 +85,7 @@ class UaNodeReader {
256
85
  }
257
86
  let variableReferences = [];
258
87
  if (childNodesToBrowse.length != 0) {
259
- let childReferenceBrowser = new UaNodeReferenceBrowser(this._client, childNodesToBrowse, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), opcua_webapi_1.NodeClass.Variable, false);
88
+ let childReferenceBrowser = new UaNodeBrowser_1.UaNodeBrowser(this._client, childNodesToBrowse, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), opcua_webapi_1.NodeClass.Variable, false);
260
89
  yield childReferenceBrowser.browse();
261
90
  variableReferences = childReferenceBrowser.results();
262
91
  }
@@ -13,6 +13,7 @@ exports.UaObjectTypeDictionary = void 0;
13
13
  const opcua_webapi_1 = require("opcua-webapi");
14
14
  const common_1 = require("../../common");
15
15
  const UaNodeReader_1 = require("./UaNodeReader");
16
+ const UaNodeBrowser_1 = require("./UaNodeBrowser");
16
17
  class UaObjectTypeDictionary {
17
18
  constructor(client) {
18
19
  this._client = client;
@@ -22,7 +23,7 @@ class UaObjectTypeDictionary {
22
23
  }
23
24
  read() {
24
25
  return __awaiter(this, void 0, void 0, function* () {
25
- let browser = new UaNodeReader_1.UaSubtypeBrowser(this._client, [common_1.UaNodeId.from(common_1.ObjectTypeIds.BaseObjectType)]);
26
+ let browser = new UaNodeBrowser_1.UaTypeBrowser(this._client, [common_1.UaNodeId.from(common_1.ObjectTypeIds.BaseObjectType)]);
26
27
  yield this._read(browser);
27
28
  });
28
29
  }
@@ -68,7 +69,7 @@ class UaObjectTypeDictionary {
68
69
  return;
69
70
  yield this.__delay(20);
70
71
  // Continue to browse and read child type
71
- let childBrowser = new UaNodeReader_1.UaSubtypeBrowser(this._client, nodeIdsToBrowse);
72
+ let childBrowser = new UaNodeBrowser_1.UaTypeBrowser(this._client, nodeIdsToBrowse);
72
73
  yield this._read(childBrowser);
73
74
  });
74
75
  }
@@ -13,6 +13,7 @@ exports.UaReferenceTypeDictionary = void 0;
13
13
  const opcua_webapi_1 = require("opcua-webapi");
14
14
  const common_1 = require("../../common");
15
15
  const UaNodeReader_1 = require("./UaNodeReader");
16
+ const UaNodeBrowser_1 = require("./UaNodeBrowser");
16
17
  class UaReferenceTypeDictionary {
17
18
  constructor(client) {
18
19
  this._client = client;
@@ -22,7 +23,7 @@ class UaReferenceTypeDictionary {
22
23
  }
23
24
  read() {
24
25
  return __awaiter(this, void 0, void 0, function* () {
25
- let browser = new UaNodeReader_1.UaChildBrowser(this._client, [common_1.UaNodeId.from(common_1.ReferenceTypeIds.References)]);
26
+ let browser = new UaNodeBrowser_1.UaTypeBrowser(this._client, [common_1.UaNodeId.from(common_1.ReferenceTypeIds.References)]);
26
27
  yield this._read(browser);
27
28
  });
28
29
  }
@@ -68,7 +69,7 @@ class UaReferenceTypeDictionary {
68
69
  return;
69
70
  yield this.__delay(20);
70
71
  // Continue to browse and read child type
71
- let childBrowser = new UaNodeReader_1.UaChildBrowser(this._client, nodeIdsToBrowse);
72
+ let childBrowser = new UaNodeBrowser_1.UaTypeBrowser(this._client, nodeIdsToBrowse);
72
73
  yield this._read(childBrowser);
73
74
  });
74
75
  }
@@ -1,4 +1,6 @@
1
1
  export * from "./UaDataTypeDictionary";
2
2
  export * from "./UaObjectTypeDictionary";
3
3
  export * from "./UaReferenceTypeDictionary";
4
+ export * from "./UaNodeBrowser";
4
5
  export * from "./UaNodeReader";
6
+ export * from "./UaModelling";
@@ -17,4 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./UaDataTypeDictionary"), exports);
18
18
  __exportStar(require("./UaObjectTypeDictionary"), exports);
19
19
  __exportStar(require("./UaReferenceTypeDictionary"), exports);
20
+ __exportStar(require("./UaNodeBrowser"), exports);
20
21
  __exportStar(require("./UaNodeReader"), exports);
22
+ __exportStar(require("./UaModelling"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opcua-webapi-ts",
3
- "version": "1.1.18",
3
+ "version": "1.1.19",
4
4
  "description": "Provides OPC UA WebAPI wrapper and client based on opcua-webapi-typescript",
5
5
  "author": "DingYan",
6
6
  "license": "MIT",
@@ -25,7 +25,7 @@
25
25
  "scripts": {
26
26
  "build": "tsc && tsc -p tsconfig.cjs.json",
27
27
  "prepare": "npm run build",
28
- "dev": "tsx watch --clear-screen=false test/test.ts"
28
+ "test": "tsx test/test.ts"
29
29
  },
30
30
  "devDependencies": {
31
31
  "tsx": "^4.22.3",