opcua-webapi-ts 1.1.17 → 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.
Files changed (41) hide show
  1. package/dist/cjs/client/UaWebClient.js +95 -101
  2. package/dist/cjs/client/utils/UaDataTypeDictionary.js +11 -11
  3. package/dist/cjs/client/utils/UaModelling.js +137 -0
  4. package/dist/cjs/client/utils/UaNodeBrowser.js +186 -0
  5. package/dist/cjs/client/utils/UaNodeReader.js +38 -203
  6. package/dist/cjs/client/utils/UaObjectTypeDictionary.js +12 -11
  7. package/dist/cjs/client/utils/UaReferenceTypeDictionary.js +12 -11
  8. package/dist/cjs/client/utils/index.js +2 -0
  9. package/dist/cjs/common/nodes/UaDataType.js +2 -2
  10. package/dist/cjs/common/nodes/UaNode.js +27 -6
  11. package/dist/cjs/common/nodes/UaObjectType.js +7 -0
  12. package/dist/cjs/common/types/UaModellingRule.js +10 -0
  13. package/dist/cjs/common/types/index.js +1 -1
  14. package/dist/client/UaWebClient.d.ts +15 -6
  15. package/dist/client/UaWebClient.js +95 -101
  16. package/dist/client/utils/UaDataTypeDictionary.d.ts +3 -3
  17. package/dist/client/utils/UaDataTypeDictionary.js +11 -11
  18. package/dist/client/utils/UaModelling.d.ts +14 -0
  19. package/dist/client/utils/UaModelling.js +137 -0
  20. package/dist/client/utils/UaNodeBrowser.d.ts +34 -0
  21. package/dist/client/utils/UaNodeBrowser.js +186 -0
  22. package/dist/client/utils/UaNodeReader.d.ts +8 -39
  23. package/dist/client/utils/UaNodeReader.js +38 -203
  24. package/dist/client/utils/UaObjectTypeDictionary.d.ts +3 -3
  25. package/dist/client/utils/UaObjectTypeDictionary.js +12 -11
  26. package/dist/client/utils/UaReferenceTypeDictionary.d.ts +3 -3
  27. package/dist/client/utils/UaReferenceTypeDictionary.js +12 -11
  28. package/dist/client/utils/index.d.ts +2 -0
  29. package/dist/client/utils/index.js +2 -0
  30. package/dist/common/nodes/UaAttributes.d.ts +0 -4
  31. package/dist/common/nodes/UaDataType.d.ts +1 -1
  32. package/dist/common/nodes/UaDataType.js +2 -2
  33. package/dist/common/nodes/UaNode.d.ts +10 -6
  34. package/dist/common/nodes/UaNode.js +27 -6
  35. package/dist/common/nodes/UaObjectType.d.ts +3 -0
  36. package/dist/common/nodes/UaObjectType.js +7 -0
  37. package/dist/common/types/UaModellingRule.d.ts +6 -0
  38. package/dist/common/types/UaModellingRule.js +10 -0
  39. package/dist/common/types/index.d.ts +1 -1
  40. package/dist/common/types/index.js +1 -1
  41. package/package.json +2 -2
@@ -1,7 +1,17 @@
1
1
  import { ViewDescription, RequestHeader, ApplicationDescription, BrowseDirection, EndpointDescription } from "opcua-webapi";
2
- import { UaBrowseResult, OpcUaNodeAttributes, OpcUaVariableAttributes, UaNodeId, UaDataValue, UaVariant, UaStatusCode, UaExtensionObject, UaHistoryDataResult, UaQuery, UaMethodArguments, UaApplicationDescriptor, UaBrowseDescription, UaReadValueId, UaWriteValue, UaHistoryReadValueId, UaHistoryReadResult, UaLocalizedText, UaAddNodesItem, UaAddNodesResult, OpcUaObjectAttributes, UaDeleteNodesItem, UaAddReferencesItem, UaDeleteReferencesItem } from "../common";
2
+ import { UaBrowseResult, OpcUaNodeAttributes, OpcUaVariableAttributes, UaNodeId, UaDataValue, UaVariant, UaStatusCode, UaArgument, UaExtensionObject, UaHistoryDataResult, UaQuery, UaBrowseDescription, UaReadValueId, UaWriteValue, UaHistoryReadValueId, UaHistoryReadResult, UaLocalizedText, UaAddNodesItem, UaAddNodesResult, UaDeleteNodesItem, UaAddReferencesItem, UaDeleteReferencesItem } from "../common";
3
3
  import { UaClientConfiguration, UaClientParameters, UaWebClientApi } from "..";
4
4
  import { UaHistoryEventResult, UaCallMethodRequest, UaCallMethodResult } from "../common";
5
+ export type UaApplicationDescriptor = {
6
+ urls: Array<string>;
7
+ applicationUri: string;
8
+ applicationName: UaLocalizedText;
9
+ productUri: string;
10
+ };
11
+ export type UaMethodArguments = {
12
+ inputArguments: Array<UaArgument>;
13
+ outputArguments: Array<UaArgument>;
14
+ };
5
15
  export declare class UaWebClient {
6
16
  private api;
7
17
  private clientConfig;
@@ -14,18 +24,17 @@ export declare class UaWebClient {
14
24
  browseNextByCP(continuationPoint: string): Promise<UaBrowseResult>;
15
25
  readValues(nodeIds: Array<UaNodeId>, timestampsToReturn?: number): Promise<Array<UaDataValue>>;
16
26
  writeValue(nodeId: UaNodeId, value: UaVariant): Promise<void>;
27
+ methodCall(objectId: UaNodeId, methodId: UaNodeId, inputArguments: Array<UaVariant>): Promise<Array<UaVariant>>;
17
28
  readNodeAttributes(nodeId: UaNodeId, returnDescription?: boolean): Promise<OpcUaNodeAttributes>;
18
- readVariableAttributes(nodeIds: Array<UaNodeId>): Promise<Array<OpcUaVariableAttributes>>;
19
29
  readMethodArguments(nodeId: UaNodeId): Promise<UaMethodArguments>;
20
- readObjectAttributes(nodeId: UaNodeId): Promise<OpcUaObjectAttributes>;
21
- methodCall(objectId: UaNodeId, methodId: UaNodeId, inputArguments: Array<UaVariant>): Promise<Array<UaVariant>>;
30
+ readObjectEventNotifier(nodeId: UaNodeId): Promise<number>;
31
+ readVariableAttributes(nodeIds: Array<UaNodeId>): Promise<Array<OpcUaVariableAttributes>>;
32
+ readWriteMasks(nodeIds: Array<UaNodeId>): Promise<Array<number>>;
22
33
  getGeneratedEventType(typeId: UaNodeId): Promise<Array<UaNodeId>>;
23
34
  historyReadRawData(nodeId: UaNodeId, startTime: Date, endTime: Date, numValuesPerNode?: number | null, continuationPoint?: string | null, returnBounds?: boolean | null, isReadModified?: boolean | null, timestampsToReturn?: number | null, releaseContinuationPoints?: boolean | null): Promise<UaHistoryDataResult>;
24
35
  historyReadAtTime(nodeId: UaNodeId, requiredTimes: Array<Date>, useSimpleBounds?: boolean | null, continuationPoint?: string | null, timestampsToReturn?: number | null, releaseContinuationPoints?: boolean | null): Promise<UaHistoryDataResult>;
25
36
  historyReadProcessed(nodeId: UaNodeId, startTime: Date, endTime: Date, processingInterval: number, aggregateType?: UaNodeId | null, continuationPoint?: string | null, timestampsToReturn?: number | null, releaseContinuationPoints?: boolean | null): Promise<UaHistoryDataResult>;
26
37
  historyReadEvent(nodeId: UaNodeId, startTime: Date, endTime: Date, select: Array<string>, where?: UaQuery | null, numValuesPerNode?: number | null, continuationPoint?: string | null, releaseContinuationPoints?: boolean | null): Promise<UaHistoryEventResult>;
27
- addObject(parentNodeId: UaNodeId, typeDefinitionNodeId: UaNodeId, displayName: UaLocalizedText, browseName?: string, referenceTypeId?: UaNodeId): Promise<UaNodeId>;
28
- deleteNode(nodeId: UaNodeId): Promise<void>;
29
38
  browse(nodesToBrowse: Array<UaBrowseDescription>, maxReferencesPerNode?: number, view?: ViewDescription, additionalParameters?: UaClientParameters): Promise<Array<UaBrowseResult>>;
30
39
  browseNext(continuationPoints: Array<string>, releaseContinuationPoints: boolean, additionalParameters?: UaClientParameters): Promise<Array<UaBrowseResult>>;
31
40
  read(nodesToRead: Array<UaReadValueId>, timestampsToReturn?: number, maxAge?: number, additionalParameters?: UaClientParameters): Promise<Array<UaDataValue>>;
@@ -89,13 +89,28 @@ class UaWebClient {
89
89
  throw new common_1.UaError(results[0]);
90
90
  });
91
91
  }
92
+ methodCall(objectId, methodId, inputArguments) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ let inputs = [];
95
+ for (let item of inputArguments) {
96
+ inputs.push(common_1.UaPayloadMapper.variantToWebApi(item));
97
+ }
98
+ let methodsToCall = [
99
+ new common_2.UaCallMethodRequest(objectId, methodId, inputArguments)
100
+ ];
101
+ let results = yield this.call(methodsToCall);
102
+ if (results[0].statusCode.isNotGood())
103
+ throw new common_1.UaError(results[0].statusCode);
104
+ let outputs = results[0].outputArguments;
105
+ return outputs;
106
+ });
107
+ }
92
108
  readNodeAttributes(nodeId, returnDescription) {
93
109
  return __awaiter(this, void 0, void 0, function* () {
94
110
  let nodesToRead = [
95
111
  new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.NodeClass),
96
112
  new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.BrowseName),
97
113
  new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.DisplayName),
98
- new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.WriteMask)
99
114
  ];
100
115
  if (returnDescription) {
101
116
  nodesToRead.push(new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.Description));
@@ -114,21 +129,79 @@ class UaWebClient {
114
129
  common_1.UaVariantType.QualifiedName != browseNameValue.type ||
115
130
  common_1.UaVariantType.LocalizedText != displayNameValue.type)
116
131
  throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
117
- let writeMaskValue = (results[3].statusCode.isGood() &&
118
- results[3].value.type == common_1.UaVariantType.UInt32) ? results[3].value : undefined;
119
132
  let descriptionValue = (returnDescription &&
120
- results[4].statusCode.isGood() &&
121
- results[4].value.type == common_1.UaVariantType.LocalizedText) ? results[4].value : undefined;
133
+ results[3].statusCode.isGood() &&
134
+ results[3].value.type == common_1.UaVariantType.LocalizedText) ? results[3].value : undefined;
122
135
  let ret = {
123
136
  nodeClass: nodeClassValue.value,
124
137
  browseName: browseNameValue.value,
125
138
  displayName: displayNameValue.value,
126
- writeMask: (writeMaskValue) ? writeMaskValue.value : 0,
127
139
  description: (descriptionValue) ? descriptionValue.value : undefined
128
140
  };
129
141
  return ret;
130
142
  });
131
143
  }
144
+ readMethodArguments(nodeId) {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ let ret = { inputArguments: [], outputArguments: [] };
147
+ let browseResult = yield this.browseChild(nodeId, opcua_webapi_1.NodeClass.Variable);
148
+ let inputArgumentsId = null;
149
+ let outputArgumentsId = null;
150
+ for (let item of browseResult.results) {
151
+ if ("InputArguments" == item.browseName)
152
+ inputArgumentsId = item.nodeId.getNodeId();
153
+ if ("OutputArguments" == item.browseName)
154
+ outputArgumentsId = item.nodeId.getNodeId();
155
+ }
156
+ let nodesToRead = [];
157
+ if (inputArgumentsId)
158
+ nodesToRead.push(inputArgumentsId);
159
+ if (outputArgumentsId)
160
+ nodesToRead.push(outputArgumentsId);
161
+ if (0 == nodesToRead.length)
162
+ return ret;
163
+ let readResults = yield this.readValues(nodesToRead);
164
+ let argsArr = [];
165
+ for (let item of readResults) {
166
+ if (item.statusCode.isNotGood() ||
167
+ common_1.UaVariantType.ExtensionObject != item.value.type ||
168
+ common_1.UaArrayType.Array != item.value.arrayType)
169
+ throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadInvalidArgument));
170
+ let extensionObjects = item.value.value;
171
+ let args = [];
172
+ for (let itemL2 of extensionObjects) {
173
+ let arg = common_1.UaArgument.fromExtensionObject(itemL2);
174
+ if (!arg)
175
+ throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadInvalidArgument));
176
+ args.push(arg);
177
+ }
178
+ argsArr.push(args);
179
+ }
180
+ if (inputArgumentsId && outputArgumentsId) {
181
+ ret.inputArguments = argsArr[0];
182
+ ret.outputArguments = argsArr[1];
183
+ }
184
+ else if (inputArgumentsId) {
185
+ ret.inputArguments = argsArr[0];
186
+ }
187
+ else if (outputArgumentsId) {
188
+ ret.outputArguments = argsArr[0];
189
+ }
190
+ return ret;
191
+ });
192
+ }
193
+ readObjectEventNotifier(nodeId) {
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ let nodesToRead = [];
196
+ nodesToRead.push(new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.EventNotifier));
197
+ let results = yield this.read(nodesToRead);
198
+ if (results[0].statusCode.isNotGood())
199
+ throw new common_1.UaError(results[0].statusCode);
200
+ if (common_1.UaVariantType.Byte == results[0].value.type)
201
+ return results[0].value.value;
202
+ return 0;
203
+ });
204
+ }
132
205
  readVariableAttributes(nodeIds) {
133
206
  return __awaiter(this, void 0, void 0, function* () {
134
207
  if (nodeIds.length == 0)
@@ -183,86 +256,26 @@ class UaWebClient {
183
256
  return ret;
184
257
  });
185
258
  }
186
- readMethodArguments(nodeId) {
259
+ readWriteMasks(nodeIds) {
187
260
  return __awaiter(this, void 0, void 0, function* () {
188
- let ret = { inputArguments: [], outputArguments: [] };
189
- let browseResult = yield this.browseChild(nodeId, opcua_webapi_1.NodeClass.Variable);
190
- let inputArgumentsId = null;
191
- let outputArgumentsId = null;
192
- for (let item of browseResult.results) {
193
- if ("InputArguments" == item.browseName)
194
- inputArgumentsId = item.nodeId.getNodeId();
195
- if ("OutputArguments" == item.browseName)
196
- outputArgumentsId = item.nodeId.getNodeId();
197
- }
261
+ if (nodeIds.length == 0)
262
+ return [];
198
263
  let nodesToRead = [];
199
- if (inputArgumentsId)
200
- nodesToRead.push(inputArgumentsId);
201
- if (outputArgumentsId)
202
- nodesToRead.push(outputArgumentsId);
203
- if (0 == nodesToRead.length)
204
- return ret;
205
- let readResults = yield this.readValues(nodesToRead);
206
- let argsArr = [];
207
- for (let item of readResults) {
208
- if (item.statusCode.isNotGood() ||
209
- common_1.UaVariantType.ExtensionObject != item.value.type ||
210
- common_1.UaArrayType.Array != item.value.arrayType)
211
- throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadInvalidArgument));
212
- let extensionObjects = item.value.value;
213
- let args = [];
214
- for (let itemL2 of extensionObjects) {
215
- let arg = common_1.UaArgument.fromExtensionObject(itemL2);
216
- if (!arg)
217
- throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadInvalidArgument));
218
- args.push(arg);
219
- }
220
- argsArr.push(args);
221
- }
222
- if (inputArgumentsId && outputArgumentsId) {
223
- ret.inputArguments = argsArr[0];
224
- ret.outputArguments = argsArr[1];
225
- }
226
- else if (inputArgumentsId) {
227
- ret.inputArguments = argsArr[0];
228
- }
229
- else if (outputArgumentsId) {
230
- ret.outputArguments = argsArr[0];
264
+ for (let item of nodeIds) {
265
+ let nodeIdToRead = new common_1.UaReadValueId(item, opcua_webapi_1.Attributes.UserWriteMask);
266
+ nodesToRead.push(nodeIdToRead);
231
267
  }
232
- return ret;
233
- });
234
- }
235
- readObjectAttributes(nodeId) {
236
- return __awaiter(this, void 0, void 0, function* () {
237
- let nodesToRead = [
238
- new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.EventNotifier)
239
- ];
240
268
  let results = yield this.read(nodesToRead);
241
- if (results[0].statusCode.isNotGood())
242
- throw new common_1.UaError(results[0].statusCode);
243
- let eventNotifierValue = results[0].value;
244
- if (common_1.UaVariantType.Byte != eventNotifierValue.type)
245
- throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
246
- let ret = {
247
- eventNotifier: eventNotifierValue.value
248
- };
249
- return ret;
250
- });
251
- }
252
- methodCall(objectId, methodId, inputArguments) {
253
- return __awaiter(this, void 0, void 0, function* () {
254
- let inputs = [];
255
- for (let item of inputArguments) {
256
- inputs.push(common_1.UaPayloadMapper.variantToWebApi(item));
269
+ let writeMasks = [];
270
+ for (let result of results) {
271
+ if (result.statusCode.isGood() && result.value.type == common_1.UaVariantType.UInt32) {
272
+ writeMasks.push(result.value.value);
273
+ }
274
+ else {
275
+ writeMasks.push(0);
276
+ }
257
277
  }
258
- let methodsToCall = [
259
- new common_2.UaCallMethodRequest(objectId, methodId, inputArguments)
260
- ];
261
- let results = yield this.call(methodsToCall);
262
- if (results[0].statusCode.isNotGood())
263
- throw new common_1.UaError(results[0].statusCode);
264
- let outputs = results[0].outputArguments;
265
- return outputs;
278
+ return writeMasks;
266
279
  });
267
280
  }
268
281
  getGeneratedEventType(typeId) {
@@ -369,26 +382,6 @@ class UaWebClient {
369
382
  return ret;
370
383
  });
371
384
  }
372
- addObject(parentNodeId, typeDefinitionNodeId, displayName, browseName, referenceTypeId) {
373
- return __awaiter(this, void 0, void 0, function* () {
374
- let objectAttributes = new common_1.UaObjectAttributes(displayName);
375
- let extensionObject = objectAttributes.toExtensionObject();
376
- let nodeToAdd = new common_1.UaAddNodesItem(new common_1.UaExpandedNodeId(parentNodeId), opcua_webapi_1.NodeClass.Object, extensionObject, new common_1.UaExpandedNodeId(typeDefinitionNodeId), null, browseName, referenceTypeId);
377
- let results = yield this.addNodes([nodeToAdd]);
378
- if (results[0].statusCode.isNotGood())
379
- throw new common_1.UaError(results[0].statusCode);
380
- let newNodeId = results[0].addedNodeId;
381
- return newNodeId;
382
- });
383
- }
384
- deleteNode(nodeId) {
385
- return __awaiter(this, void 0, void 0, function* () {
386
- let nodeToDelete = new common_1.UaDeleteNodesItem(nodeId);
387
- let results = yield this.deleteNodes([nodeToDelete]);
388
- if (results[0].isNotGood())
389
- throw new common_1.UaError(results[0]);
390
- });
391
- }
392
385
  // Native APIs
393
386
  browse(nodesToBrowse, maxReferencesPerNode, view, additionalParameters) {
394
387
  return __awaiter(this, void 0, void 0, function* () {
@@ -796,6 +789,7 @@ class UaWebClient {
796
789
  response = yield this.api.addNodes(request, { signal: controller.signal });
797
790
  }
798
791
  catch (error) {
792
+ console.error(error);
799
793
  throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadCommunicationError));
800
794
  }
801
795
  finally {
@@ -1,10 +1,10 @@
1
1
  import { UaDataType, UaNodeId } from "../../common";
2
2
  import { UaWebClient } from "../UaWebClient";
3
3
  export declare class UaDataTypeDictionary {
4
+ private _client;
4
5
  private _dataTypes;
5
- private _returnAllAttributes;
6
- constructor(simpleMode?: boolean);
7
- read(client: UaWebClient): Promise<void>;
6
+ constructor(client: UaWebClient);
7
+ read(): Promise<void>;
8
8
  getDataType(nodeId: UaNodeId): UaDataType | null;
9
9
  getDataTypes(): Array<UaDataType>;
10
10
  private _read;
@@ -14,16 +14,16 @@ const opcua_webapi_1 = require("opcua-webapi");
14
14
  const common_1 = require("../../common");
15
15
  const __1 = require("../..");
16
16
  class UaDataTypeDictionary {
17
- constructor(simpleMode) {
17
+ constructor(client) {
18
+ this._client = client;
18
19
  this._dataTypes = new Map;
19
- this._returnAllAttributes = (null == simpleMode) ? false : !simpleMode;
20
20
  let baseDataTypeId = new common_1.UaNodeId(common_1.DataTypeIds.BaseDataType);
21
21
  this._dataTypes.set(baseDataTypeId.toString(), new common_1.UaDataType(baseDataTypeId, "BaseDataType", new common_1.UaLocalizedText("BaseDataType"), true));
22
22
  }
23
- read(client) {
23
+ read() {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
- let browser = new __1.UaChildBrowser([common_1.UaNodeId.from(common_1.DataTypeIds.BaseDataType)]);
26
- yield this._read(browser, client);
25
+ let browser = new __1.UaTypeBrowser(this._client, [common_1.UaNodeId.from(common_1.DataTypeIds.BaseDataType)]);
26
+ yield this._read(browser);
27
27
  });
28
28
  }
29
29
  getDataType(nodeId) {
@@ -33,10 +33,10 @@ class UaDataTypeDictionary {
33
33
  getDataTypes() {
34
34
  return [...this._dataTypes.values()];
35
35
  }
36
- _read(browser, client) {
36
+ _read(browser) {
37
37
  return __awaiter(this, void 0, void 0, function* () {
38
38
  // Browse child type
39
- yield browser.browse(client);
39
+ yield browser.browse();
40
40
  let results = browser.results();
41
41
  let referencesToRead = [];
42
42
  let needToReadEnumValue = false;
@@ -50,8 +50,8 @@ class UaDataTypeDictionary {
50
50
  return;
51
51
  // Read child type
52
52
  let nodeIdsToBrowse = [];
53
- let nodeReader = new __1.UaNodeReader(this._returnAllAttributes, needToReadEnumValue, false, this._returnAllAttributes);
54
- let nodes = yield nodeReader.readByReferences(referencesToRead, client);
53
+ let nodeReader = new __1.UaNodeReader(this._client, false, needToReadEnumValue, false, false, true);
54
+ let nodes = yield nodeReader.readByReferences(referencesToRead);
55
55
  for (let node of nodes) {
56
56
  if (opcua_webapi_1.NodeClass.DataType != node.nodeClass)
57
57
  continue;
@@ -71,8 +71,8 @@ class UaDataTypeDictionary {
71
71
  return;
72
72
  yield this.__delay(20);
73
73
  // Continue to browse and read child type
74
- let childBrowser = new __1.UaChildBrowser(nodeIdsToBrowse);
75
- yield this._read(childBrowser, client);
74
+ let childBrowser = new __1.UaTypeBrowser(this._client, nodeIdsToBrowse);
75
+ yield this._read(childBrowser);
76
76
  });
77
77
  }
78
78
  __delay(ms) {
@@ -0,0 +1,14 @@
1
+ import { UaLocalizedText, UaNode, UaNodeId, UaObjectType } from "../../common";
2
+ import { UaWebClient } from "../UaWebClient";
3
+ import { UaObjectTypeDictionary } from "../..";
4
+ export declare class UaModelling {
5
+ private _client;
6
+ constructor(client: UaWebClient);
7
+ getObjectTypeToAdd(objectTypeId: UaNodeId, dictionary: UaObjectTypeDictionary): Promise<Array<UaObjectType>>;
8
+ getWriteMask(nodes: Array<UaNode>): Promise<void>;
9
+ addObject(parentNodeId: UaNodeId, objectTypeId: UaNodeId, displayName: UaLocalizedText, browseName?: string): Promise<UaNodeId>;
10
+ deleteNode(nodeId: UaNodeId): Promise<void>;
11
+ rename(nodeId: UaNodeId, name: UaLocalizedText): Promise<void>;
12
+ setDescription(nodeId: UaNodeId, description: UaLocalizedText): Promise<void>;
13
+ private _readObjectMembers;
14
+ }
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.UaModelling = void 0;
13
+ const opcua_webapi_1 = require("opcua-webapi");
14
+ const common_1 = require("../../common");
15
+ const __1 = require("../..");
16
+ class UaModelling {
17
+ constructor(client) {
18
+ this._client = client;
19
+ }
20
+ getObjectTypeToAdd(objectTypeId, dictionary) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ let objectType = yield this._readObjectMembers(objectTypeId, dictionary);
23
+ if (!objectType)
24
+ return [];
25
+ let ret = [];
26
+ let objectMembers = objectType.objectMembers;
27
+ for (let item of objectMembers) {
28
+ if (item.modellingRule != common_1.UaModellingRule.PlaceHolder)
29
+ continue;
30
+ let childObjectType = dictionary.getObjectType(item.typeDefinitionId);
31
+ if (!childObjectType)
32
+ continue;
33
+ ret.push(childObjectType);
34
+ }
35
+ return ret;
36
+ });
37
+ }
38
+ getWriteMask(nodes) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ let nodesToRead = [];
41
+ for (let node of nodes) {
42
+ if (node.writeMask != null)
43
+ continue;
44
+ nodesToRead.push(node.nodeId);
45
+ }
46
+ if (0 == nodesToRead.length)
47
+ return;
48
+ let results = yield this._client.readWriteMasks(nodesToRead);
49
+ let index = 0;
50
+ for (let node of nodes) {
51
+ if (node.writeMask != null)
52
+ continue;
53
+ node.writeMask = results[index];
54
+ index++;
55
+ }
56
+ });
57
+ }
58
+ addObject(parentNodeId, objectTypeId, displayName, browseName) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ let objectAttributes = new __1.UaObjectAttributes(displayName);
61
+ let extensionObject = objectAttributes.toExtensionObject();
62
+ let nodeToAdd = new common_1.UaAddNodesItem(new common_1.UaExpandedNodeId(parentNodeId), opcua_webapi_1.NodeClass.Object, extensionObject, new common_1.UaExpandedNodeId(objectTypeId), null, browseName !== null && browseName !== void 0 ? browseName : null, null);
63
+ let results = yield this._client.addNodes([nodeToAdd]);
64
+ if (results[0].statusCode.isNotGood())
65
+ throw new common_1.UaError(results[0].statusCode);
66
+ let newNodeId = results[0].addedNodeId;
67
+ return newNodeId;
68
+ });
69
+ }
70
+ deleteNode(nodeId) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ let nodeToDelete = new common_1.UaDeleteNodesItem(nodeId);
73
+ let results = yield this._client.deleteNodes([nodeToDelete]);
74
+ if (results[0].isNotGood())
75
+ throw new common_1.UaError(results[0]);
76
+ });
77
+ }
78
+ rename(nodeId, name) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ let writeValue = new common_1.UaWriteValue(nodeId, common_1.UaVariant.localizedText(name), opcua_webapi_1.Attributes.DisplayName);
81
+ let results = yield this._client.write([writeValue]);
82
+ if (results[0].isNotGood())
83
+ throw new common_1.UaError(results[0]);
84
+ });
85
+ }
86
+ setDescription(nodeId, description) {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ let writeValue = new common_1.UaWriteValue(nodeId, common_1.UaVariant.localizedText(description), opcua_webapi_1.Attributes.Description);
89
+ let results = yield this._client.write([writeValue]);
90
+ if (results[0].isNotGood())
91
+ throw new common_1.UaError(results[0]);
92
+ });
93
+ }
94
+ _readObjectMembers(objectTypeId, dictionary) {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ let objectType = dictionary.getObjectType(objectTypeId);
97
+ if (!objectType)
98
+ return null;
99
+ if (objectType.isObjectMemberRead)
100
+ return objectType;
101
+ let typeMemberBrowser = new __1.UaNodeBrowser(this._client, [objectType.nodeId], common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), opcua_webapi_1.NodeClass.Object, false);
102
+ yield typeMemberBrowser.browse();
103
+ let browseMemberResults = typeMemberBrowser.results();
104
+ let instanceNodes = new Map();
105
+ for (let item of browseMemberResults) {
106
+ for (let reference of item.references) {
107
+ if (reference.nodeClass != opcua_webapi_1.NodeClass.Object)
108
+ continue;
109
+ instanceNodes.set(reference.nodeId.toString(), new common_1.UaObject(reference.nodeId, reference.browseName, reference.displayName, 0, reference.typeDefinitionId));
110
+ }
111
+ }
112
+ let memberObjectIds = [];
113
+ for (let node of instanceNodes) {
114
+ memberObjectIds.push(node[1].nodeId);
115
+ }
116
+ let modellingRuleBrowser = new __1.UaNodeBrowser(this._client, memberObjectIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HasModellingRule), opcua_webapi_1.NodeClass.Object, false);
117
+ yield modellingRuleBrowser.browse();
118
+ let browseModellingRuleResults = modellingRuleBrowser.results();
119
+ for (let item of browseModellingRuleResults) {
120
+ let instanceNode = instanceNodes.get(item.nodeId.toString());
121
+ if (!instanceNode)
122
+ continue;
123
+ if (0 == item.references.length)
124
+ continue;
125
+ instanceNode.setModellingRule(item.references[0].nodeId);
126
+ }
127
+ for (let node of instanceNodes) {
128
+ if (node[1].modellingRule == common_1.UaModellingRule.None)
129
+ continue;
130
+ objectType.addMember(node[1]);
131
+ }
132
+ objectType.isObjectMemberRead = true;
133
+ return objectType;
134
+ });
135
+ }
136
+ }
137
+ exports.UaModelling = UaModelling;
@@ -0,0 +1,34 @@
1
+ import { UaNodeId, UaReference } from "../../common";
2
+ import { UaWebClient } from "../UaWebClient";
3
+ export type BrowseReferenceResult = {
4
+ nodeId: UaNodeId;
5
+ references: Array<UaReference>;
6
+ };
7
+ export declare class UaNodeBrowser {
8
+ private _client;
9
+ private _nodesToBrowse;
10
+ private _continuationPointToBrowse;
11
+ private _referenceType;
12
+ private _nodeClassToReturn;
13
+ private _returnDescription;
14
+ private _maxNodesPerBrowse;
15
+ private _maxReferencesPerNode;
16
+ private _readResults;
17
+ constructor(client: UaWebClient, nodeIds: Array<UaNodeId>, referenceType: UaNodeId, nodeClassToReturn: number, returnDescription?: boolean, maxNodesPerBrowse?: number | null, maxReferencesPerNode?: number | null);
18
+ browse(): Promise<void>;
19
+ browseOnce(): Promise<void>;
20
+ results(): Array<BrowseReferenceResult>;
21
+ isFinish(): boolean;
22
+ private _browseNodes;
23
+ private _browseContinuationPoints;
24
+ private _readDescriptions;
25
+ }
26
+ export declare class UaObjectBrowser extends UaNodeBrowser {
27
+ constructor(client: UaWebClient, nodeIds: Array<UaNodeId>, returnDescription?: boolean);
28
+ }
29
+ export declare class UaLinkBrowser extends UaNodeBrowser {
30
+ constructor(client: UaWebClient, nodeIds: Array<UaNodeId>, returnDescription?: boolean);
31
+ }
32
+ export declare class UaTypeBrowser extends UaNodeBrowser {
33
+ constructor(client: UaWebClient, nodeIds: Array<UaNodeId>, returnDescription?: boolean);
34
+ }