node-opcua-client 2.168.0 → 2.169.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/dist/client_monitored_item.d.ts +4 -4
- package/dist/client_monitored_item.js +6 -5
- package/dist/client_monitored_item.js.map +1 -1
- package/dist/client_monitored_item_base.d.ts +7 -7
- package/dist/client_monitored_item_toolbox.d.ts +5 -5
- package/dist/client_monitored_item_toolbox.js +26 -19
- package/dist/client_monitored_item_toolbox.js.map +1 -1
- package/dist/private/client_base_impl.js +28 -4
- package/dist/private/client_base_impl.js.map +1 -1
- package/dist/private/client_monitored_item_group_impl.d.ts +7 -6
- package/dist/private/client_monitored_item_group_impl.js +6 -8
- package/dist/private/client_monitored_item_group_impl.js.map +1 -1
- package/dist/private/client_monitored_item_impl.d.ts +10 -9
- package/dist/private/client_monitored_item_impl.js +40 -26
- package/dist/private/client_monitored_item_impl.js.map +1 -1
- package/dist/private/client_session_impl.d.ts +1 -0
- package/dist/private/client_session_impl.js +12 -0
- package/dist/private/client_session_impl.js.map +1 -1
- package/dist/private/client_subscription_impl.d.ts +7 -4
- package/dist/private/client_subscription_impl.js +101 -77
- package/dist/private/client_subscription_impl.js.map +1 -1
- package/dist/private/opcua_client_impl.d.ts +1 -0
- package/dist/private/opcua_client_impl.js +11 -0
- package/dist/private/opcua_client_impl.js.map +1 -1
- package/package.json +42 -42
- package/source/client_monitored_item.ts +5 -4
- package/source/client_monitored_item_base.ts +13 -8
- package/source/client_monitored_item_toolbox.ts +24 -20
- package/source/private/client_base_impl.ts +27 -6
- package/source/private/client_monitored_item_group_impl.ts +15 -16
- package/source/private/client_monitored_item_impl.ts +56 -38
- package/source/private/client_session_impl.ts +29 -14
- package/source/private/client_subscription_impl.ts +151 -91
- package/source/private/opcua_client_impl.ts +13 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
// tslint:disable:unified-signatures
|
|
5
5
|
// tslint:disable:no-empty
|
|
6
|
-
import { EventEmitter } from "events";
|
|
6
|
+
import { EventEmitter } from "node:events";
|
|
7
7
|
import { assert } from "node-opcua-assert";
|
|
8
8
|
|
|
9
9
|
import { AttributeIds } from "node-opcua-data-model";
|
|
@@ -11,7 +11,7 @@ import { coerceTimestampsToReturn, type DataValue } from "node-opcua-data-value"
|
|
|
11
11
|
import { checkDebugFlag, make_debugLog, make_warningLog } from "node-opcua-debug";
|
|
12
12
|
import type { ExtensionObject } from "node-opcua-extension-object";
|
|
13
13
|
import { EventFilter } from "node-opcua-service-filter";
|
|
14
|
-
import { ReadValueId, type ReadValueIdOptions,
|
|
14
|
+
import { ReadValueId, type ReadValueIdOptions, TimestampsToReturn } from "node-opcua-service-read";
|
|
15
15
|
import {
|
|
16
16
|
type MonitoredItemCreateResult,
|
|
17
17
|
type MonitoredItemModifyResult,
|
|
@@ -27,9 +27,9 @@ import { type ClientMonitoredItemBaseEx, ClientMonitoredItemToolbox } from "../c
|
|
|
27
27
|
import type { ClientSubscription } from "../client_subscription";
|
|
28
28
|
import { ClientMonitoredItem_create, type ClientSubscriptionImpl } from "./client_subscription_impl";
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const _debugLog = make_debugLog(__filename);
|
|
31
31
|
const warningLog = make_warningLog(__filename);
|
|
32
|
-
const
|
|
32
|
+
const _doDebug = checkDebugFlag(__filename);
|
|
33
33
|
|
|
34
34
|
export type PrepareForMonitoringResult =
|
|
35
35
|
| { error: string }
|
|
@@ -58,7 +58,7 @@ export class ClientMonitoredItemImpl extends EventEmitter implements ClientMonit
|
|
|
58
58
|
public subscription: ClientSubscriptionImpl;
|
|
59
59
|
public monitoringMode: MonitoringMode;
|
|
60
60
|
public statusCode: StatusCode;
|
|
61
|
-
public monitoredItemId?:
|
|
61
|
+
public monitoredItemId?: number;
|
|
62
62
|
public result?: MonitoredItemCreateResult;
|
|
63
63
|
public filterResult?: ExtensionObject;
|
|
64
64
|
public timestampsToReturn: TimestampsToReturn;
|
|
@@ -66,6 +66,8 @@ export class ClientMonitoredItemImpl extends EventEmitter implements ClientMonit
|
|
|
66
66
|
#pendingDataValue?: DataValue[];
|
|
67
67
|
#pendingEvents?: Variant[][];
|
|
68
68
|
|
|
69
|
+
#terminated?: boolean;
|
|
70
|
+
|
|
69
71
|
public internalSetMonitoringMode(monitoringMode: MonitoringMode): void {
|
|
70
72
|
this.monitoringMode = monitoringMode;
|
|
71
73
|
}
|
|
@@ -93,49 +95,67 @@ export class ClientMonitoredItemImpl extends EventEmitter implements ClientMonit
|
|
|
93
95
|
this.timestampsToReturn = timestampsToReturn;
|
|
94
96
|
}
|
|
95
97
|
|
|
98
|
+
public toJSON(): Record<string, string | number | undefined> {
|
|
99
|
+
return {
|
|
100
|
+
itemToMonitor: this.itemToMonitor.toString(),
|
|
101
|
+
monitoringParameters: this.monitoringParameters.toString(),
|
|
102
|
+
timestampsToReturn: TimestampsToReturn[this.timestampsToReturn],
|
|
103
|
+
monitoredItemId: this.monitoredItemId,
|
|
104
|
+
statusCode: this.statusCode?.toString(),
|
|
105
|
+
result: this.result?.toString()
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
96
109
|
public toString(): string {
|
|
97
110
|
let ret = "";
|
|
98
|
-
ret +=
|
|
99
|
-
ret +=
|
|
100
|
-
ret +=
|
|
101
|
-
ret +=
|
|
102
|
-
ret +=
|
|
103
|
-
ret +=
|
|
111
|
+
ret += `itemToMonitor: ${this.itemToMonitor.toString()}\n`;
|
|
112
|
+
ret += `monitoringParameters: ${this.monitoringParameters.toString()}\n`;
|
|
113
|
+
ret += `timestampsToReturn: ${TimestampsToReturn[this.timestampsToReturn]}\n`;
|
|
114
|
+
ret += `monitoredItemId: ${this.monitoredItemId}\n`;
|
|
115
|
+
ret += `statusCode: ${this.statusCode?.toString()}\n`;
|
|
116
|
+
ret += `result: ${this.result?.toString()}\n`;
|
|
104
117
|
return ret;
|
|
105
118
|
}
|
|
106
119
|
|
|
120
|
+
public [Symbol.for("nodejs.util.inspect.custom")](): string {
|
|
121
|
+
return this.toString();
|
|
122
|
+
}
|
|
123
|
+
|
|
107
124
|
/**
|
|
108
125
|
* terminate the monitored item by removing the MonitoredItem from its subscription
|
|
109
126
|
*/
|
|
110
127
|
public async terminate(): Promise<void>;
|
|
111
|
-
public terminate(
|
|
112
|
-
public terminate(
|
|
113
|
-
const done = args[0];
|
|
114
|
-
assert(typeof done === "function");
|
|
115
|
-
|
|
128
|
+
public terminate(callback: ErrorCallback): void;
|
|
129
|
+
public terminate(callback?: ErrorCallback): Promise<void> | undefined {
|
|
116
130
|
const subscription = this.subscription as ClientSubscriptionImpl;
|
|
117
131
|
subscription._delete_monitored_items([this], (err?: Error) => {
|
|
118
|
-
if (
|
|
119
|
-
|
|
132
|
+
if (callback) {
|
|
133
|
+
callback(err);
|
|
120
134
|
}
|
|
121
135
|
});
|
|
136
|
+
return undefined;
|
|
122
137
|
}
|
|
123
138
|
|
|
124
|
-
public async modify(parameters: MonitoringParametersOptions): Promise<
|
|
125
|
-
public async modify(
|
|
126
|
-
|
|
139
|
+
public async modify(parameters: MonitoringParametersOptions): Promise<MonitoredItemModifyResult>;
|
|
140
|
+
public async modify(
|
|
141
|
+
parameters: MonitoringParametersOptions,
|
|
142
|
+
timestampsToReturn: TimestampsToReturn
|
|
143
|
+
): Promise<MonitoredItemModifyResult>;
|
|
144
|
+
public modify(parameters: MonitoringParametersOptions, callback: Callback<MonitoredItemModifyResult>): void;
|
|
127
145
|
public modify(
|
|
128
146
|
parameters: MonitoringParametersOptions,
|
|
129
147
|
timestampsToReturn: TimestampsToReturn | null,
|
|
130
|
-
callback:
|
|
148
|
+
callback: Callback<MonitoredItemModifyResult>
|
|
131
149
|
): void;
|
|
132
|
-
public modify(...args:
|
|
150
|
+
public modify(...args: unknown[]): undefined | Promise<MonitoredItemModifyResult> {
|
|
151
|
+
// remember we are garantied to be in a callback env here.
|
|
133
152
|
if (args.length === 2) {
|
|
134
|
-
|
|
153
|
+
this.modify(args[0] as MonitoringParametersOptions, null, args[1] as Callback<MonitoredItemModifyResult>);
|
|
154
|
+
return undefined;
|
|
135
155
|
}
|
|
136
156
|
const parameters = args[0] as MonitoringParametersOptions;
|
|
137
157
|
const timestampsToReturn = args[1] as TimestampsToReturn;
|
|
138
|
-
const callback = args[2]
|
|
158
|
+
const callback = args[2] as Callback<MonitoredItemModifyResult>;
|
|
139
159
|
this.timestampsToReturn = timestampsToReturn || this.timestampsToReturn;
|
|
140
160
|
ClientMonitoredItemToolbox._toolbox_modify(
|
|
141
161
|
this.subscription,
|
|
@@ -149,26 +169,25 @@ export class ClientMonitoredItemImpl extends EventEmitter implements ClientMonit
|
|
|
149
169
|
if (!results) {
|
|
150
170
|
return callback(new Error("internal error"));
|
|
151
171
|
}
|
|
152
|
-
assert(results
|
|
153
|
-
callback(null, results
|
|
172
|
+
assert(results?.length === 1);
|
|
173
|
+
callback(null, results[0]);
|
|
154
174
|
}
|
|
155
175
|
);
|
|
176
|
+
return undefined;
|
|
156
177
|
}
|
|
157
178
|
|
|
158
179
|
public async setMonitoringMode(monitoringMode: MonitoringMode): Promise<StatusCode>;
|
|
159
180
|
public setMonitoringMode(monitoringMode: MonitoringMode, callback: Callback<StatusCode>): void;
|
|
160
|
-
public setMonitoringMode(
|
|
161
|
-
const monitoringMode = args[0] as MonitoringMode;
|
|
162
|
-
const callback = args[1] as Callback<StatusCode>;
|
|
163
|
-
|
|
181
|
+
public setMonitoringMode(monitoringMode: MonitoringMode, callback?: Callback<StatusCode>): undefined | Promise<StatusCode> {
|
|
164
182
|
ClientMonitoredItemToolbox._toolbox_setMonitoringMode(
|
|
165
183
|
this.subscription,
|
|
166
184
|
[this],
|
|
167
185
|
monitoringMode,
|
|
168
186
|
(err?: Error | null, statusCodes?: StatusCode[]) => {
|
|
169
|
-
callback(err ? err : null, statusCodes ? statusCodes[0] : undefined);
|
|
187
|
+
callback?.(err ? err : null, statusCodes ? statusCodes[0] : undefined);
|
|
170
188
|
}
|
|
171
189
|
);
|
|
190
|
+
return undefined;
|
|
172
191
|
}
|
|
173
192
|
|
|
174
193
|
/**
|
|
@@ -260,7 +279,7 @@ export class ClientMonitoredItemImpl extends EventEmitter implements ClientMonit
|
|
|
260
279
|
// toDO
|
|
261
280
|
|
|
262
281
|
// note : the EventFilter is used when monitoring Events.
|
|
263
|
-
this.monitoringParameters.filter = this.monitoringParameters.filter
|
|
282
|
+
this.monitoringParameters.filter = this.monitoringParameters.filter || new EventFilter({});
|
|
264
283
|
|
|
265
284
|
const filter = this.monitoringParameters.filter;
|
|
266
285
|
|
|
@@ -365,14 +384,13 @@ export class ClientMonitoredItemImpl extends EventEmitter implements ClientMonit
|
|
|
365
384
|
}
|
|
366
385
|
|
|
367
386
|
public _terminate_and_emit(err?: Error): void {
|
|
368
|
-
if (
|
|
387
|
+
if (this.#terminated) {
|
|
369
388
|
return; // already terminated
|
|
370
389
|
}
|
|
371
390
|
if (err) {
|
|
372
391
|
this.emit("err", err.message);
|
|
373
392
|
}
|
|
374
|
-
|
|
375
|
-
(this as any)._terminated = true;
|
|
393
|
+
this.#terminated = true;
|
|
376
394
|
/**
|
|
377
395
|
* Notify the observer that this monitored item has been terminated.
|
|
378
396
|
* @event terminated
|
|
@@ -390,7 +408,7 @@ export class ClientMonitoredItemImpl extends EventEmitter implements ClientMonit
|
|
|
390
408
|
// tslint:disable:max-line-length
|
|
391
409
|
import { withCallback } from "thenify-ex";
|
|
392
410
|
|
|
393
|
-
const
|
|
411
|
+
const _opts = { multiArgs: false };
|
|
394
412
|
|
|
395
413
|
ClientMonitoredItemImpl.prototype.terminate = withCallback(ClientMonitoredItemImpl.prototype.terminate);
|
|
396
414
|
ClientMonitoredItemImpl.prototype.setMonitoringMode = withCallback(ClientMonitoredItemImpl.prototype.setMonitoringMode);
|
|
@@ -400,7 +418,7 @@ ClientMonitoredItem.create = (
|
|
|
400
418
|
subscription: ClientSubscription,
|
|
401
419
|
itemToMonitor: ReadValueIdOptions,
|
|
402
420
|
monitoringParameters: MonitoringParametersOptions,
|
|
403
|
-
timestampsToReturn: TimestampsToReturn,
|
|
421
|
+
timestampsToReturn: TimestampsToReturn = TimestampsToReturn.Neither,
|
|
404
422
|
monitoringMode: MonitoringMode = MonitoringMode.Reporting
|
|
405
423
|
): ClientMonitoredItem => {
|
|
406
424
|
return ClientMonitoredItem_create(subscription, itemToMonitor, monitoringParameters, timestampsToReturn, monitoringMode);
|
|
@@ -268,6 +268,21 @@ export class ClientSessionImpl extends EventEmitter implements ClientSession, Re
|
|
|
268
268
|
return this._client ? this._client.isReconnecting || this._reconnecting?.reconnecting : false;
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
+
public toJSON(): Record<string, string | number | boolean> {
|
|
272
|
+
return {
|
|
273
|
+
name: this.name,
|
|
274
|
+
sessionId: this.sessionId.toString(),
|
|
275
|
+
timeout: this.timeout,
|
|
276
|
+
state: this._closed ? "closed" : "active",
|
|
277
|
+
isReconnecting: this.isReconnecting ? "true" : "false"
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
public [Symbol.for("nodejs.util.inspect.custom")](): string {
|
|
283
|
+
return this.toString();
|
|
284
|
+
}
|
|
285
|
+
|
|
271
286
|
protected resolveNodeId(nodeId: NodeIdLike): NodeIdLike {
|
|
272
287
|
return resolveNodeId(nodeId);
|
|
273
288
|
}
|
|
@@ -405,8 +420,8 @@ export class ClientSessionImpl extends EventEmitter implements ClientSession, Re
|
|
|
405
420
|
if (r.references && r.references.length > this.requestedMaxReferencesPerNode) {
|
|
406
421
|
warningLog(
|
|
407
422
|
chalk.yellow("warning") +
|
|
408
|
-
|
|
409
|
-
|
|
423
|
+
" BrowseResponse : the server didn't take into" +
|
|
424
|
+
" account our requestedMaxReferencesPerNode "
|
|
410
425
|
);
|
|
411
426
|
warningLog(" this.requestedMaxReferencesPerNode= " + this.requestedMaxReferencesPerNode);
|
|
412
427
|
warningLog(" got " + r.references.length + "for " + nodesToBrowse[i].nodeId.toString());
|
|
@@ -415,7 +430,7 @@ export class ClientSessionImpl extends EventEmitter implements ClientSession, Re
|
|
|
415
430
|
}
|
|
416
431
|
}
|
|
417
432
|
for (const r of results) {
|
|
418
|
-
r.references = r.references || /* c8 ignore next */
|
|
433
|
+
r.references = r.references || /* c8 ignore next */[];
|
|
419
434
|
}
|
|
420
435
|
assert(results[0] instanceof BrowseResult);
|
|
421
436
|
return callback(null, isArray ? results : results[0]);
|
|
@@ -710,7 +725,7 @@ export class ClientSessionImpl extends EventEmitter implements ClientSession, Re
|
|
|
710
725
|
return callback(new Error(response.responseHeader.serviceResult.toString()));
|
|
711
726
|
}
|
|
712
727
|
|
|
713
|
-
response.results = response.results || /* c8 ignore next */
|
|
728
|
+
response.results = response.results || /* c8 ignore next */[];
|
|
714
729
|
|
|
715
730
|
// perform ExtensionObject resolution
|
|
716
731
|
const promises = response.results.map(async (result) => {
|
|
@@ -855,7 +870,7 @@ export class ClientSessionImpl extends EventEmitter implements ClientSession, Re
|
|
|
855
870
|
return callback(new Error(response.responseHeader.serviceResult.toString()));
|
|
856
871
|
}
|
|
857
872
|
|
|
858
|
-
response.results = response.results || /* c8 ignore next */
|
|
873
|
+
response.results = response.results || /* c8 ignore next */[];
|
|
859
874
|
|
|
860
875
|
assert(nodesToRead.length === response.results.length);
|
|
861
876
|
|
|
@@ -994,7 +1009,7 @@ export class ClientSessionImpl extends EventEmitter implements ClientSession, Re
|
|
|
994
1009
|
if (response.responseHeader.serviceResult.isNot(StatusCodes.Good)) {
|
|
995
1010
|
return callback(new Error(response.responseHeader.serviceResult.toString()));
|
|
996
1011
|
}
|
|
997
|
-
response.results = response.results || /* c8 ignore next */
|
|
1012
|
+
response.results = response.results || /* c8 ignore next */[];
|
|
998
1013
|
assert(nodesToWrite.length === response.results.length);
|
|
999
1014
|
callback(null, isArray ? response.results : response.results[0]);
|
|
1000
1015
|
});
|
|
@@ -1189,7 +1204,7 @@ export class ClientSessionImpl extends EventEmitter implements ClientSession, Re
|
|
|
1189
1204
|
warningLog(
|
|
1190
1205
|
chalk.yellow(
|
|
1191
1206
|
"please make sure to refactor your code and check that " +
|
|
1192
|
-
|
|
1207
|
+
"the second argument of your callback function is named"
|
|
1193
1208
|
),
|
|
1194
1209
|
chalk.cyan("dataValue" + (isArray ? "s" : ""))
|
|
1195
1210
|
);
|
|
@@ -1223,7 +1238,7 @@ export class ClientSessionImpl extends EventEmitter implements ClientSession, Re
|
|
|
1223
1238
|
// perform ExtensionObject resolution
|
|
1224
1239
|
promoteOpaqueStructure(this, response.results!)
|
|
1225
1240
|
.then(() => {
|
|
1226
|
-
response.results = response.results || /* c8 ignore next */
|
|
1241
|
+
response.results = response.results || /* c8 ignore next */[];
|
|
1227
1242
|
callback(null, isArray ? response.results : response.results[0]);
|
|
1228
1243
|
})
|
|
1229
1244
|
.catch((err) => {
|
|
@@ -1401,7 +1416,7 @@ export class ClientSessionImpl extends EventEmitter implements ClientSession, Re
|
|
|
1401
1416
|
if (!response) {
|
|
1402
1417
|
return callback(new Error("Internal Error"));
|
|
1403
1418
|
}
|
|
1404
|
-
response.results = response.results || /* c8 ignore next */
|
|
1419
|
+
response.results = response.results || /* c8 ignore next */[];
|
|
1405
1420
|
callback(err, isArray ? response.results : response.results[0]);
|
|
1406
1421
|
}
|
|
1407
1422
|
);
|
|
@@ -1437,7 +1452,7 @@ export class ClientSessionImpl extends EventEmitter implements ClientSession, Re
|
|
|
1437
1452
|
if (!response || !(response instanceof TranslateBrowsePathsToNodeIdsResponse)) {
|
|
1438
1453
|
return callback(new Error("Internal Error"));
|
|
1439
1454
|
}
|
|
1440
|
-
response.results = response.results || /* c8 ignore next */
|
|
1455
|
+
response.results = response.results || /* c8 ignore next */[];
|
|
1441
1456
|
|
|
1442
1457
|
callback(null, isArray ? response.results : response.results[0]);
|
|
1443
1458
|
});
|
|
@@ -1586,9 +1601,9 @@ export class ClientSessionImpl extends EventEmitter implements ClientSession, Re
|
|
|
1586
1601
|
if (response.responseHeader.serviceResult.isNot(StatusCodes.Good)) {
|
|
1587
1602
|
err = new Error(
|
|
1588
1603
|
" ServiceResult is " +
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1604
|
+
response.responseHeader.serviceResult.toString() +
|
|
1605
|
+
" request was " +
|
|
1606
|
+
request.constructor.name
|
|
1592
1607
|
);
|
|
1593
1608
|
|
|
1594
1609
|
if (response && response.responseHeader.serviceDiagnostics) {
|
|
@@ -1837,7 +1852,7 @@ export class ClientSessionImpl extends EventEmitter implements ClientSession, Re
|
|
|
1837
1852
|
return callback(new Error("Internal Error"));
|
|
1838
1853
|
}
|
|
1839
1854
|
|
|
1840
|
-
response.registeredNodeIds = response.registeredNodeIds || /* c8 ignore next */
|
|
1855
|
+
response.registeredNodeIds = response.registeredNodeIds || /* c8 ignore next */[];
|
|
1841
1856
|
|
|
1842
1857
|
callback(null, response.registeredNodeIds);
|
|
1843
1858
|
});
|