node-opcua-address-space 2.140.0 → 2.141.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-opcua-address-space",
3
- "version": "2.140.0",
3
+ "version": "2.141.0",
4
4
  "description": "pure nodejs OPCUA SDK - module address-space",
5
5
  "main": "./dist/src/index_current.js",
6
6
  "types": "./dist/source/index.d.ts",
@@ -18,18 +18,17 @@
18
18
  "dependencies": {
19
19
  "@types/lodash": "4.17.13",
20
20
  "@types/semver": "^7.5.8",
21
- "async": "^3.2.6",
22
21
  "chalk": "4.1.2",
23
22
  "dequeue": "^1.0.5",
24
23
  "lodash": "4.17.21",
25
- "node-opcua-address-space-base": "2.139.0",
24
+ "node-opcua-address-space-base": "2.141.0",
26
25
  "node-opcua-assert": "2.139.0",
27
26
  "node-opcua-basic-types": "2.139.0",
28
27
  "node-opcua-binary-stream": "2.139.0",
29
- "node-opcua-client-dynamic-extension-object": "2.140.0",
28
+ "node-opcua-client-dynamic-extension-object": "2.141.0",
30
29
  "node-opcua-constants": "2.139.0",
31
30
  "node-opcua-crypto": "4.15.0",
32
- "node-opcua-data-access": "2.139.0",
31
+ "node-opcua-data-access": "2.141.0",
33
32
  "node-opcua-data-model": "2.139.0",
34
33
  "node-opcua-data-value": "2.139.0",
35
34
  "node-opcua-date-time": "2.139.0",
@@ -38,23 +37,23 @@
38
37
  "node-opcua-extension-object": "2.139.0",
39
38
  "node-opcua-factory": "2.139.0",
40
39
  "node-opcua-nodeid": "2.139.0",
41
- "node-opcua-nodeset-ua": "2.139.0",
40
+ "node-opcua-nodeset-ua": "2.141.0",
42
41
  "node-opcua-numeric-range": "2.139.0",
43
42
  "node-opcua-object-registry": "2.139.0",
44
- "node-opcua-pseudo-session": "2.140.0",
45
- "node-opcua-service-browse": "2.139.0",
46
- "node-opcua-service-call": "2.139.0",
47
- "node-opcua-service-history": "2.139.0",
48
- "node-opcua-service-translate-browse-path": "2.139.0",
49
- "node-opcua-service-write": "2.139.0",
43
+ "node-opcua-pseudo-session": "2.141.0",
44
+ "node-opcua-service-browse": "2.141.0",
45
+ "node-opcua-service-call": "2.141.0",
46
+ "node-opcua-service-history": "2.141.0",
47
+ "node-opcua-service-translate-browse-path": "2.141.0",
48
+ "node-opcua-service-write": "2.141.0",
50
49
  "node-opcua-status-code": "2.139.0",
51
- "node-opcua-types": "2.139.0",
50
+ "node-opcua-types": "2.141.0",
52
51
  "node-opcua-utils": "2.139.0",
53
52
  "node-opcua-variant": "2.139.0",
54
- "node-opcua-xml2json": "2.139.0",
53
+ "node-opcua-xml2json": "2.141.0",
55
54
  "semver": "^7.6.3",
56
55
  "set-prototype-of": "^1.0.0",
57
- "thenify": "^3.3.1",
56
+ "thenify-ex": "4.2.0",
58
57
  "xml-writer": "^1.7.0"
59
58
  },
60
59
  "devDependencies": {
@@ -62,8 +61,8 @@
62
61
  "node-opcua-leak-detector": "2.139.0",
63
62
  "node-opcua-nodesets": "2.139.0",
64
63
  "node-opcua-packet-analyzer": "2.139.0",
65
- "node-opcua-service-filter": "2.139.0",
66
- "node-opcua-test-fixtures": "2.139.0",
64
+ "node-opcua-service-filter": "2.141.0",
65
+ "node-opcua-test-fixtures": "2.141.0",
67
66
  "source-map-support": "^0.5.21"
68
67
  },
69
68
  "author": "Etienne Rossignon",
@@ -81,7 +80,7 @@
81
80
  "internet of things"
82
81
  ],
83
82
  "homepage": "http://node-opcua.github.io/",
84
- "gitHead": "f966ee4ce83c1012795fbf030d261df091c3c189",
83
+ "gitHead": "7467e145ce9ebad2c80cabb096189bda7714083d",
85
84
  "files": [
86
85
  "dist",
87
86
  "distHelpers",
@@ -8,7 +8,6 @@ import { CallMethodRequest } from "node-opcua-service-call";
8
8
  import { StatusCode, StatusCodes } from "node-opcua-status-code";
9
9
  import { CallMethodResultOptions } from "node-opcua-types";
10
10
  import { Variant } from "node-opcua-variant";
11
- import { ResponseCallback } from "node-opcua-pseudo-session";
12
11
  import { ISessionContext, IAddressSpace, UAMethod, UAObject } from "node-opcua-address-space-base";
13
12
 
14
13
  import { getMethodDeclaration_ArgumentList, verifyArguments_ArgumentList } from "./argument_list";
@@ -30,12 +29,11 @@ import { resolveOpaqueOnAddressSpace } from "./resolve_opaque_on_address_space";
30
29
  // A server shall accept a ByteString if an array of Byte is expected.
31
30
  // BadNoCommunication
32
31
 
33
- export function callMethodHelper(
32
+ export async function callMethodHelper(
34
33
  context: ISessionContext,
35
34
  addressSpace: IAddressSpace,
36
- callMethodRequest: CallMethodRequest,
37
- callback: ResponseCallback<CallMethodResultOptions>
38
- ): void {
35
+ callMethodRequest: CallMethodRequest
36
+ ): Promise<CallMethodResultOptions> {
39
37
  const objectId = callMethodRequest.objectId;
40
38
  const methodId = callMethodRequest.methodId;
41
39
  const inputArguments = callMethodRequest.inputArguments || [];
@@ -45,24 +43,24 @@ export function callMethodHelper(
45
43
 
46
44
  const object = addressSpace.findNode(objectId) as UAObject;
47
45
  if (!object) {
48
- return callback(null, { statusCode: StatusCodes.BadNodeIdUnknown });
46
+ return { statusCode: StatusCodes.BadNodeIdUnknown };
49
47
  }
50
48
  if (object.nodeClass !== NodeClass.Object && object.nodeClass !== NodeClass.ObjectType) {
51
- return callback(null, { statusCode: StatusCodes.BadNodeIdInvalid });
49
+ return { statusCode: StatusCodes.BadNodeIdInvalid };
52
50
  }
53
51
 
54
52
  const methodObj = addressSpace.findNode(methodId) as UAMethod;
55
53
  if (!methodObj) {
56
- return callback(null, { statusCode: StatusCodes.BadMethodInvalid });
54
+ return { statusCode: StatusCodes.BadMethodInvalid };
57
55
  }
58
56
  if (methodObj.nodeClass !== NodeClass.Method) {
59
- return callback(null, { statusCode: StatusCodes.BadMethodInvalid });
57
+ return { statusCode: StatusCodes.BadMethodInvalid };
60
58
  }
61
59
 
62
60
  const response1 = getMethodDeclaration_ArgumentList(addressSpace, objectId, methodId);
63
61
 
64
62
  if (response1.statusCode.isNotGood()) {
65
- return callback(null, { statusCode: response1.statusCode });
63
+ return { statusCode: response1.statusCode };
66
64
  }
67
65
  const methodDeclaration = response1.methodDeclaration!;
68
66
 
@@ -71,41 +69,34 @@ export function callMethodHelper(
71
69
 
72
70
  const response = verifyArguments_ArgumentList(addressSpace, methodInputArguments, inputArguments);
73
71
  if (response.statusCode.isNotGood()) {
74
- return callback(null, response);
72
+ return response;
73
+ }
74
+
75
+
76
+ try {
77
+ await resolveOpaqueOnAddressSpace(addressSpace, inputArguments);
78
+
79
+ const callMethodResponse = await methodObj.execute(
80
+ object,
81
+ inputArguments,
82
+ context);
83
+ callMethodResponse.inputArgumentResults =
84
+ callMethodResponse.inputArgumentResults || response.inputArgumentResults || [];
85
+ assert(callMethodResponse.statusCode);
86
+
87
+ if (callMethodResponse.statusCode?.isGood()) {
88
+ assert(Array.isArray(callMethodResponse.outputArguments));
89
+ }
90
+
91
+ assert(Array.isArray(callMethodResponse.inputArgumentResults));
92
+ assert(callMethodResponse.inputArgumentResults!.length === methodInputArguments.length);
93
+
94
+ const outputArguments = callMethodResponse.outputArguments || [];
95
+ await resolveOpaqueOnAddressSpace(addressSpace, outputArguments as Variant[]);
96
+
97
+ return callMethodResponse;
98
+ } catch (err) {
99
+ return { statusCode: StatusCodes.BadInternalError };
75
100
  }
76
101
 
77
- resolveOpaqueOnAddressSpace(addressSpace, inputArguments)
78
- .then(() => {
79
- methodObj.execute(
80
- object,
81
- inputArguments,
82
- context,
83
- (err: Error | null, callMethodResponse?: CallMethodResultOptions) => {
84
- /* istanbul ignore next */
85
- if (err) {
86
- return callback(err);
87
- }
88
- if (!callMethodResponse) {
89
- return callback(new Error("internal Error"));
90
- }
91
-
92
- callMethodResponse.inputArgumentResults =
93
- callMethodResponse.inputArgumentResults || response.inputArgumentResults || [];
94
- assert(callMethodResponse.statusCode);
95
-
96
- if (callMethodResponse.statusCode?.isGood()) {
97
- assert(Array.isArray(callMethodResponse.outputArguments));
98
- }
99
-
100
- assert(Array.isArray(callMethodResponse.inputArgumentResults));
101
- assert(callMethodResponse.inputArgumentResults!.length === methodInputArguments.length);
102
-
103
- const outputArguments = callMethodResponse.outputArguments || [];
104
- resolveOpaqueOnAddressSpace(addressSpace, outputArguments as Variant[])
105
- .then(() => callback(null, callMethodResponse))
106
- .catch(callback);
107
- }
108
- );
109
- })
110
- .catch((err) => callback(err));
111
102
  }
@@ -2,8 +2,6 @@
2
2
  * @module node-opcua-address-space
3
3
  */
4
4
  import { promisify } from "util";
5
- import async from "async";
6
-
7
5
  import { assert } from "node-opcua-assert";
8
6
  import { DataValue } from "node-opcua-data-value";
9
7
  import { make_errorLog } from "node-opcua-debug";
@@ -198,38 +196,26 @@ export class PseudoSession implements IBasicSession {
198
196
  const _nodesToRead = nodesToRead as ReadValueIdOptions[];
199
197
  const context = this[$context];
200
198
 
201
- setImmediate(() => {
202
- async.map(
203
- _nodesToRead,
204
- (nodeToRead: ReadValueIdOptions, innerCallback: any) => {
205
- const obj = this[$addressSpace].findNode(nodeToRead.nodeId!);
206
- if (!obj || obj.nodeClass !== NodeClass.Variable || nodeToRead.attributeId !== AttributeIds.Value) {
207
- return innerCallback();
208
- }
209
- (obj as UAVariable).readValueAsync(context, innerCallback);
210
- },
211
- (err) => {
212
- const dataValues = _nodesToRead.map((nodeToRead: ReadValueIdOptions) => {
213
- assert(!!nodeToRead.nodeId, "expecting a nodeId");
214
- assert(!!nodeToRead.attributeId, "expecting a attributeId");
215
-
216
- const nodeId = nodeToRead.nodeId!;
217
- const attributeId = nodeToRead.attributeId!;
218
- const indexRange = nodeToRead.indexRange;
219
- const dataEncoding = nodeToRead.dataEncoding;
220
- const obj = this[$addressSpace].findNode(nodeId);
221
- if (!obj) {
222
- return new DataValue({ statusCode: StatusCodes.BadNodeIdUnknown });
223
- }
224
- const context = this[$context];
225
- const dataValue = obj.readAttribute(context, attributeId, indexRange, dataEncoding);
226
- return dataValue;
227
- });
228
-
229
- callback!(null, isArray ? dataValues : dataValues[0]);
230
- }
231
- );
232
- });
199
+ const readV = async (nodeToRead: ReadValueIdOptions): Promise<DataValue> => {
200
+ const obj = this[$addressSpace].findNode(nodeToRead.nodeId!);
201
+ if (!obj) {
202
+ return new DataValue({ statusCode: StatusCodes.BadNodeIdUnknown });
203
+ }
204
+ // refresh the variable value if the attribute to read is the Value attribute
205
+ if (obj.nodeClass === NodeClass.Variable && nodeToRead.attributeId == AttributeIds.Value) {
206
+ (obj as UAVariable).readValueAsync(context);
207
+ }
208
+ assert(!!nodeToRead.nodeId, "expecting a nodeId");
209
+ assert(!!nodeToRead.attributeId, "expecting a attributeId");
210
+ const attributeId = nodeToRead.attributeId!;
211
+ const indexRange = nodeToRead.indexRange;
212
+ const dataEncoding = nodeToRead.dataEncoding;
213
+ const dataValue = obj.readAttribute(context, attributeId, indexRange, dataEncoding);
214
+ return dataValue;
215
+ };
216
+ Promise.all(_nodesToRead.map(async (nodeToRead: ReadValueIdOptions) => await readV(nodeToRead)))
217
+ .then((dataValues) => callback!(null, isArray ? dataValues : dataValues[0]))
218
+ .catch((err) => callback!(err));
233
219
  }
234
220
 
235
221
  public browseNext(
@@ -280,34 +266,24 @@ export class PseudoSession implements IBasicSession {
280
266
  if (!isArray) {
281
267
  methodsToCall = [methodsToCall as CallMethodRequestLike];
282
268
  }
283
-
284
- async.map(
285
- methodsToCall as CallMethodRequestLike[],
286
- (methodToCall, innerCallback: (err: Error | null, result?: CallMethodResult) => void) => {
287
- const callMethodRequest = new CallMethodRequest(methodToCall);
288
-
289
- callMethodHelper(
290
- this[$context],
291
- this[$addressSpace],
292
- callMethodRequest,
293
- (err: Error | null, result?: CallMethodResultOptions) => {
294
- let callMethodResult: CallMethodResult;
295
- if (err) {
296
- errorLog("Internal Error = ", err);
297
- callMethodResult = new CallMethodResult({
298
- statusCode: StatusCodes.BadInternalError
299
- });
300
- } else {
301
- callMethodResult = new CallMethodResult(result);
302
- }
303
- innerCallback(null, callMethodResult);
304
- }
305
- );
306
- },
307
- (err?: Error | null, callMethodResults?: any) => {
308
- callback!(null, isArray ? callMethodResults! : callMethodResults![0]);
269
+ Promise.all((methodsToCall as CallMethodRequestLike[]).map(async (methodToCall) => {
270
+ const callMethodRequest = new CallMethodRequest(methodToCall);
271
+ try {
272
+ const result = await callMethodHelper(this[$context], this[$addressSpace], callMethodRequest);
273
+ return new CallMethodResult(result);
274
+ } catch (err) {
275
+ errorLog("Internal Error = ", err);
276
+ return new CallMethodResult({
277
+ statusCode: StatusCodes.BadInternalError
278
+ });
309
279
  }
310
- );
280
+ }))
281
+ .then((callMethodResults) => {
282
+ callback!(null, isArray ? callMethodResults : callMethodResults[0]);
283
+ })
284
+ .catch((err) => {
285
+ callback!(err);
286
+ });
311
287
  }
312
288
 
313
289
  public getArgumentDefinition(methodId: MethodId): Promise<ArgumentDefinition>;
@@ -373,11 +349,11 @@ export class PseudoSession implements IBasicSession {
373
349
 
374
350
  // tslint:disable:no-var-requires
375
351
  // tslint:disable:max-line-length
376
- const thenify = require("thenify");
377
- PseudoSession.prototype.read = thenify.withCallback(PseudoSession.prototype.read);
378
- PseudoSession.prototype.write = thenify.withCallback(PseudoSession.prototype.write);
379
- PseudoSession.prototype.browse = thenify.withCallback(PseudoSession.prototype.browse);
380
- PseudoSession.prototype.browseNext = thenify.withCallback(PseudoSession.prototype.browseNext);
381
- PseudoSession.prototype.getArgumentDefinition = thenify.withCallback(PseudoSession.prototype.getArgumentDefinition);
382
- PseudoSession.prototype.call = thenify.withCallback(PseudoSession.prototype.call);
383
- PseudoSession.prototype.translateBrowsePath = thenify.withCallback(PseudoSession.prototype.translateBrowsePath);
352
+ import { withCallback } from "thenify-ex";
353
+ PseudoSession.prototype.read = withCallback(PseudoSession.prototype.read);
354
+ PseudoSession.prototype.write = withCallback(PseudoSession.prototype.write);
355
+ PseudoSession.prototype.browse = withCallback(PseudoSession.prototype.browse);
356
+ PseudoSession.prototype.browseNext = withCallback(PseudoSession.prototype.browseNext);
357
+ PseudoSession.prototype.getArgumentDefinition = withCallback(PseudoSession.prototype.getArgumentDefinition);
358
+ PseudoSession.prototype.call = withCallback(PseudoSession.prototype.call);
359
+ PseudoSession.prototype.translateBrowsePath = withCallback(PseudoSession.prototype.translateBrowsePath);
@@ -307,5 +307,5 @@ export class UAMethodImpl extends BaseNodeImpl implements UAMethod {
307
307
 
308
308
  // tslint:disable:no-var-requires
309
309
  // tslint:disable:max-line-length
310
- const thenify = require("thenify");
311
- UAMethodImpl.prototype.execute = thenify.withCallback(UAMethodImpl.prototype.execute);
310
+ import { withCallback } from "thenify-ex";
311
+ UAMethodImpl.prototype.execute = withCallback(UAMethodImpl.prototype.execute);
@@ -1854,12 +1854,12 @@ export class UAVariableImpl extends BaseNodeImpl implements UAVariable {
1854
1854
  }
1855
1855
 
1856
1856
  // tslint:disable:no-var-requires
1857
- const thenify = require("thenify");
1858
- UAVariableImpl.prototype.asyncRefresh = thenify.withCallback(UAVariableImpl.prototype.asyncRefresh);
1859
- UAVariableImpl.prototype.writeValue = thenify.withCallback(UAVariableImpl.prototype.writeValue);
1860
- UAVariableImpl.prototype.writeAttribute = thenify.withCallback(UAVariableImpl.prototype.writeAttribute);
1861
- UAVariableImpl.prototype.historyRead = thenify.withCallback(UAVariableImpl.prototype.historyRead);
1862
- UAVariableImpl.prototype.readValueAsync = thenify.withCallback(UAVariableImpl.prototype.readValueAsync);
1857
+ import { withCallback } from "thenify-ex";
1858
+ UAVariableImpl.prototype.asyncRefresh = withCallback(UAVariableImpl.prototype.asyncRefresh);
1859
+ UAVariableImpl.prototype.writeValue = withCallback(UAVariableImpl.prototype.writeValue);
1860
+ UAVariableImpl.prototype.writeAttribute = withCallback(UAVariableImpl.prototype.writeAttribute);
1861
+ UAVariableImpl.prototype.historyRead = withCallback(UAVariableImpl.prototype.historyRead);
1862
+ UAVariableImpl.prototype.readValueAsync = withCallback(UAVariableImpl.prototype.readValueAsync);
1863
1863
 
1864
1864
  export interface UAVariableImplExtArray {
1865
1865
  $$variableType?: UAVariableType;