node-opcua-client 2.97.0 → 2.98.1

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 (78) hide show
  1. package/dist/alarms_and_conditions/client_alarm.d.ts +49 -49
  2. package/dist/alarms_and_conditions/client_alarm.js +109 -109
  3. package/dist/alarms_and_conditions/client_alarm_list.d.ts +25 -25
  4. package/dist/alarms_and_conditions/client_alarm_list.js +97 -97
  5. package/dist/alarms_and_conditions/client_alarm_tools.d.ts +4 -4
  6. package/dist/alarms_and_conditions/client_alarm_tools.js +156 -156
  7. package/dist/alarms_and_conditions/client_alarm_tools_acknowledge_all_conditions.d.ts +18 -18
  8. package/dist/alarms_and_conditions/client_alarm_tools_acknowledge_all_conditions.js +192 -192
  9. package/dist/alarms_and_conditions/client_alarm_tools_dump_event.d.ts +9 -9
  10. package/dist/alarms_and_conditions/client_alarm_tools_dump_event.js +72 -72
  11. package/dist/alarms_and_conditions/client_alarm_tools_dump_event.js.map +1 -1
  12. package/dist/alarms_and_conditions/client_alarm_tools_extractConditionFields.d.ts +3 -3
  13. package/dist/alarms_and_conditions/client_alarm_tools_extractConditionFields.js +118 -118
  14. package/dist/alarms_and_conditions/client_tools.d.ts +7 -7
  15. package/dist/alarms_and_conditions/client_tools.js +179 -179
  16. package/dist/client_base.d.ts +277 -277
  17. package/dist/client_base.js +14 -14
  18. package/dist/client_base.js.map +1 -1
  19. package/dist/client_monitored_item.d.ts +21 -21
  20. package/dist/client_monitored_item.js +11 -11
  21. package/dist/client_monitored_item_base.d.ts +39 -39
  22. package/dist/client_monitored_item_base.js +2 -2
  23. package/dist/client_monitored_item_group.d.ts +21 -21
  24. package/dist/client_monitored_item_group.js +13 -13
  25. package/dist/client_monitored_item_toolbox.d.ts +15 -15
  26. package/dist/client_monitored_item_toolbox.js +116 -116
  27. package/dist/client_session.d.ts +529 -529
  28. package/dist/client_session.js +10 -10
  29. package/dist/client_session_keepalive_manager.d.ts +34 -34
  30. package/dist/client_session_keepalive_manager.js +149 -149
  31. package/dist/client_subscription.d.ts +241 -241
  32. package/dist/client_subscription.js +14 -14
  33. package/dist/client_subscription.js.map +1 -1
  34. package/dist/client_utils.d.ts +22 -22
  35. package/dist/client_utils.js +87 -87
  36. package/dist/common.d.ts +17 -17
  37. package/dist/common.js +5 -5
  38. package/dist/index.d.ts +56 -56
  39. package/dist/index.js +94 -94
  40. package/dist/opcua_client.d.ts +118 -118
  41. package/dist/opcua_client.js +33 -33
  42. package/dist/private/client_base_impl.d.ts +160 -160
  43. package/dist/private/client_base_impl.js +1348 -1348
  44. package/dist/private/client_monitored_item_base_impl.d.ts +3 -3
  45. package/dist/private/client_monitored_item_base_impl.js +4 -4
  46. package/dist/private/client_monitored_item_group_impl.d.ts +53 -53
  47. package/dist/private/client_monitored_item_group_impl.js +159 -159
  48. package/dist/private/client_monitored_item_impl.d.ts +93 -93
  49. package/dist/private/client_monitored_item_impl.js +304 -304
  50. package/dist/private/client_publish_engine.d.ts +62 -62
  51. package/dist/private/client_publish_engine.js +408 -408
  52. package/dist/private/client_publish_engine.js.map +1 -1
  53. package/dist/private/client_session_impl.d.ts +631 -631
  54. package/dist/private/client_session_impl.js +1348 -1348
  55. package/dist/private/client_subscription_impl.d.ts +93 -93
  56. package/dist/private/client_subscription_impl.js +763 -763
  57. package/dist/private/i_private_client.d.ts +21 -21
  58. package/dist/private/i_private_client.js +2 -2
  59. package/dist/private/opcua_client_impl.d.ts +166 -166
  60. package/dist/private/opcua_client_impl.js +1000 -1000
  61. package/dist/private/opcua_client_impl.js.map +1 -1
  62. package/dist/private/performance.d.ts +1 -1
  63. package/dist/private/performance.js +18 -18
  64. package/dist/reconnection.d.ts +9 -9
  65. package/dist/reconnection.js +381 -381
  66. package/dist/tools/findservers.d.ts +20 -20
  67. package/dist/tools/findservers.js +61 -61
  68. package/dist/tools/read_history_server_capabilities.d.ts +6 -6
  69. package/dist/tools/read_history_server_capabilities.js +98 -98
  70. package/dist/user_identity_info.d.ts +1 -1
  71. package/dist/user_identity_info.js +2 -2
  72. package/dist/verify.d.ts +5 -5
  73. package/dist/verify.js +134 -134
  74. package/package.json +49 -45
  75. package/source/alarms_and_conditions/client_alarm_tools_dump_event.ts +1 -1
  76. package/.nycrc.json +0 -14
  77. package/test_helpers/create_certificates.js +0 -1
  78. package/typedoc.js +0 -20
@@ -1,305 +1,305 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClientMonitoredItemImpl = void 0;
4
- /**
5
- * @module node-opcua-client-private
6
- */
7
- // tslint:disable:unified-signatures
8
- // tslint:disable:no-empty
9
- const events_1 = require("events");
10
- const node_opcua_assert_1 = require("node-opcua-assert");
11
- const node_opcua_data_model_1 = require("node-opcua-data-model");
12
- const node_opcua_data_value_1 = require("node-opcua-data-value");
13
- const node_opcua_debug_1 = require("node-opcua-debug");
14
- const node_opcua_service_filter_1 = require("node-opcua-service-filter");
15
- const node_opcua_service_read_1 = require("node-opcua-service-read");
16
- const node_opcua_service_subscription_1 = require("node-opcua-service-subscription");
17
- const node_opcua_status_code_1 = require("node-opcua-status-code");
18
- const client_monitored_item_1 = require("../client_monitored_item");
19
- const client_monitored_item_toolbox_1 = require("../client_monitored_item_toolbox");
20
- const client_subscription_impl_1 = require("./client_subscription_impl");
21
- const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
22
- const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
23
- const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
24
- /**
25
- * ClientMonitoredItem
26
- * @class ClientMonitoredItem
27
- * @extends ClientMonitoredItemBase
28
- *
29
- * event:
30
- * "initialized"
31
- * "err"
32
- * "changed"
33
- *
34
- * note: this.monitoringMode = subscription_service.MonitoringMode.Reporting;
35
- */
36
- class ClientMonitoredItemImpl extends events_1.EventEmitter {
37
- constructor(subscription, itemToMonitor, monitoringParameters, timestampsToReturn, monitoringMode = node_opcua_service_subscription_1.MonitoringMode.Reporting) {
38
- super();
39
- this.statusCode = node_opcua_status_code_1.StatusCodes.BadDataUnavailable;
40
- (0, node_opcua_assert_1.assert)(subscription.constructor.name === "ClientSubscriptionImpl");
41
- this.subscription = subscription;
42
- this.itemToMonitor = new node_opcua_service_read_1.ReadValueId(itemToMonitor);
43
- this.monitoringParameters = new node_opcua_service_subscription_1.MonitoringParameters(monitoringParameters);
44
- this.monitoringMode = monitoringMode;
45
- (0, node_opcua_assert_1.assert)(this.monitoringParameters.clientHandle === 0xffffffff, "should not have a client handle yet");
46
- (0, node_opcua_assert_1.assert)(subscription.session, "expecting session");
47
- timestampsToReturn = (0, node_opcua_data_value_1.coerceTimestampsToReturn)(timestampsToReturn);
48
- (0, node_opcua_assert_1.assert)(subscription.constructor.name === "ClientSubscriptionImpl");
49
- this.timestampsToReturn = timestampsToReturn;
50
- }
51
- toString() {
52
- var _a, _b;
53
- let ret = "";
54
- ret += "itemToMonitor: " + this.itemToMonitor.toString() + "\n";
55
- ret += "monitoringParameters: " + this.monitoringParameters.toString() + "\n";
56
- ret += "timestampsToReturn: " + this.timestampsToReturn.toString() + "\n";
57
- ret += "itemToMonitor " + this.itemToMonitor.nodeId + "\n";
58
- ret += "statusCode " + ((_a = this.statusCode) === null || _a === void 0 ? void 0 : _a.toString()) + "\n";
59
- ret += "result =" + ((_b = this.result) === null || _b === void 0 ? void 0 : _b.toString()) + "\n";
60
- return ret;
61
- }
62
- terminate(...args) {
63
- const done = args[0];
64
- (0, node_opcua_assert_1.assert)(typeof done === "function");
65
- const subscription = this.subscription;
66
- subscription._delete_monitored_items([this], (err) => {
67
- if (done) {
68
- done(err);
69
- }
70
- });
71
- }
72
- modify(...args) {
73
- if (args.length === 2) {
74
- return this.modify(args[0], null, args[1]);
75
- }
76
- const parameters = args[0];
77
- const timestampsToReturn = args[1];
78
- const callback = args[2];
79
- this.timestampsToReturn = timestampsToReturn || this.timestampsToReturn;
80
- client_monitored_item_toolbox_1.ClientMonitoredItemToolbox._toolbox_modify(this.subscription, [this], parameters, this.timestampsToReturn, (err, results) => {
81
- if (err) {
82
- return callback(err);
83
- }
84
- if (!results) {
85
- return callback(new Error("internal error"));
86
- }
87
- (0, node_opcua_assert_1.assert)(results.length === 1);
88
- callback(null, results[0]);
89
- });
90
- }
91
- setMonitoringMode(...args) {
92
- const monitoringMode = args[0];
93
- const callback = args[1];
94
- client_monitored_item_toolbox_1.ClientMonitoredItemToolbox._toolbox_setMonitoringMode(this.subscription, [this], monitoringMode, (err, statusCodes) => {
95
- callback(err ? err : null, statusCodes[0]);
96
- });
97
- }
98
- /**
99
- * @internal
100
- * @param value
101
- * @private
102
- */
103
- _notify_value_change(value) {
104
- var _a;
105
- // it is possible that the first notification arrives before the CreateMonitoredItemsRequest is fully proceed
106
- // in this case we need to put the dataValue aside so we can send the notification changed after
107
- // the node-opcua client had time to fully install the on("changed") event handler
108
- if (((_a = this.statusCode) === null || _a === void 0 ? void 0 : _a.value) === node_opcua_status_code_1.StatusCodes.BadDataUnavailable.value) {
109
- this._pendingDataValue = this._pendingDataValue || [];
110
- this._pendingDataValue.push(value);
111
- return;
112
- }
113
- /**
114
- * Notify the observers that the MonitoredItem value has changed on the server side.
115
- * @event changed
116
- * @param value
117
- */
118
- try {
119
- this.emit("changed", value);
120
- }
121
- catch (err) {
122
- warningLog("[NODE-OPCUA-W28] Exception raised inside the event handler called by ClientMonitoredItem.on('change')", err);
123
- warningLog(" Please verify the application using this node-opcua client");
124
- }
125
- }
126
- /**
127
- * @internal
128
- * @param eventFields
129
- * @private
130
- */
131
- _notify_event(eventFields) {
132
- var _a;
133
- if (((_a = this.statusCode) === null || _a === void 0 ? void 0 : _a.value) === node_opcua_status_code_1.StatusCodes.BadDataUnavailable.value) {
134
- this._pendingEvents = this._pendingEvents || [];
135
- this._pendingEvents.push(eventFields);
136
- return;
137
- }
138
- /**
139
- * Notify the observers that the MonitoredItem value has changed on the server side.
140
- * @event changed
141
- * @param value
142
- */
143
- try {
144
- this.emit("changed", eventFields);
145
- }
146
- catch (err) {
147
- warningLog("[NODE-OPCUA-W29] Exception raised inside the event handler called by ClientMonitoredItem.on('change')", err);
148
- warningLog(" Please verify the application using this node-opcua client");
149
- }
150
- }
151
- /**
152
- * @internal
153
- * @private
154
- */
155
- _prepare_for_monitoring() {
156
- (0, node_opcua_assert_1.assert)(this.monitoringParameters.clientHandle === 4294967295, "should not have a client handle yet");
157
- const subscription = this.subscription;
158
- this.monitoringParameters.clientHandle = subscription.nextClientHandle();
159
- (0, node_opcua_assert_1.assert)(this.monitoringParameters.clientHandle > 0 && this.monitoringParameters.clientHandle !== 4294967295);
160
- // If attributeId is EventNotifier then monitoring parameters need a filter.
161
- // The filter must then either be DataChangeFilter, EventFilter or AggregateFilter.
162
- // todo can be done in another way?
163
- // todo implement AggregateFilter
164
- // todo support DataChangeFilter
165
- // todo support whereClause
166
- if (this.itemToMonitor.attributeId === node_opcua_data_model_1.AttributeIds.EventNotifier) {
167
- //
168
- // see OPCUA Spec 1.02 part 4 page 65 : 5.12.1.4 Filter
169
- // see part 4 page 130: 7.16.3 EventFilter
170
- // part 3 page 11 : 4.6 Event Model
171
- // To monitor for Events, the attributeId element of the ReadValueId structure is the
172
- // the id of the EventNotifierAttribute
173
- // OPC Unified Architecture 1.02, Part 4 5.12.1.2 Sampling interval page 64:
174
- // "A Client shall define a sampling interval of 0 if it subscribes for Events."
175
- // toDO
176
- // note : the EventFilter is used when monitoring Events.
177
- this.monitoringParameters.filter = this.monitoringParameters.filter || new node_opcua_service_filter_1.EventFilter({});
178
- const filter = this.monitoringParameters.filter;
179
- // istanbul ignore next
180
- if (!filter) {
181
- return { error: "Internal Error" };
182
- }
183
- if (filter.schema.name !== "EventFilter") {
184
- return {
185
- error: "Mismatch between attributeId and filter in monitoring parameters : " +
186
- "Got a " +
187
- filter.schema.name +
188
- " but a EventFilter object is required " +
189
- "when itemToMonitor.attributeId== AttributeIds.EventNotifier"
190
- };
191
- }
192
- }
193
- else if (this.itemToMonitor.attributeId === node_opcua_data_model_1.AttributeIds.Value) {
194
- // the DataChangeFilter and the AggregateFilter are used when monitoring Variable Values
195
- // The Value Attribute is used when monitoring Variables. Variable values are monitored for a change
196
- // in value or a change in their status. The filters defined in this standard (see 7.16.2) and in Part 8 are
197
- // used to determine if the value change is large enough to cause a Notification to be generated for the
198
- // to do : check 'DataChangeFilter' && 'AggregateFilter'
199
- }
200
- else {
201
- if (this.monitoringParameters.filter) {
202
- return {
203
- error: "Mismatch between attributeId and filter in monitoring parameters : " +
204
- "no filter expected when attributeId is not Value or EventNotifier"
205
- };
206
- }
207
- }
208
- return {
209
- itemToMonitor: this.itemToMonitor,
210
- monitoringMode: this.monitoringMode,
211
- requestedParameters: this.monitoringParameters
212
- };
213
- }
214
- /**
215
- * @internal
216
- * @param monitoredItemResult
217
- * @private
218
- */
219
- _applyResult(monitoredItemResult) {
220
- this.statusCode = monitoredItemResult.statusCode;
221
- /* istanbul ignore else */
222
- if (monitoredItemResult.statusCode.isGood()) {
223
- this.result = monitoredItemResult;
224
- this.monitoredItemId = monitoredItemResult.monitoredItemId;
225
- this.monitoringParameters.samplingInterval = monitoredItemResult.revisedSamplingInterval;
226
- this.monitoringParameters.queueSize = monitoredItemResult.revisedQueueSize;
227
- this.filterResult = monitoredItemResult.filterResult || undefined;
228
- }
229
- // some PublishRequest with DataNotificationChange might have been sent by the server, before the monitored
230
- // item has been fully initialized it is time to process now any pending notification that were put on hold.
231
- if (this._pendingDataValue) {
232
- const dataValues = this._pendingDataValue;
233
- this._pendingDataValue = undefined;
234
- setImmediate(() => {
235
- dataValues.map((dataValue) => this._notify_value_change(dataValue));
236
- });
237
- }
238
- if (this._pendingEvents) {
239
- const events = this._pendingEvents;
240
- this._pendingEvents = undefined;
241
- setImmediate(() => {
242
- events.map((event) => this._notify_event(event));
243
- });
244
- }
245
- }
246
- _before_create() {
247
- const subscription = this.subscription;
248
- subscription._add_monitored_item(this.monitoringParameters.clientHandle, this);
249
- }
250
- /**
251
- * @internal
252
- * @param monitoredItemResult
253
- * @private
254
- */
255
- _after_create(monitoredItemResult) {
256
- this._applyResult(monitoredItemResult);
257
- if (this.statusCode.isGood()) {
258
- /**
259
- * Notify the observers that the monitored item is now fully initialized.
260
- * @event initialized
261
- */
262
- this.emit("initialized");
263
- }
264
- else {
265
- /**
266
- * Notify the observers that the monitored item has failed to initialize.
267
- * @event err
268
- * @param statusCode {StatusCode}
269
- */
270
- const err = new Error(monitoredItemResult.statusCode.toString());
271
- this._terminate_and_emit(err);
272
- }
273
- }
274
- _terminate_and_emit(err) {
275
- if (this._terminated) {
276
- return; // already terminated
277
- }
278
- if (err) {
279
- this.emit("err", err.message);
280
- }
281
- (0, node_opcua_assert_1.assert)(!this._terminated);
282
- this._terminated = true;
283
- /**
284
- * Notify the observer that this monitored item has been terminated.
285
- * @event terminated
286
- */
287
- this.emit("terminated", err);
288
- this.removeAllListeners();
289
- // also remove from subscription
290
- const clientHandle = this.monitoringParameters.clientHandle;
291
- delete this.subscription.monitoredItems[clientHandle];
292
- }
293
- }
294
- exports.ClientMonitoredItemImpl = ClientMonitoredItemImpl;
295
- // tslint:disable:no-var-requires
296
- // tslint:disable:max-line-length
297
- const thenify = require("thenify");
298
- const opts = { multiArgs: false };
299
- ClientMonitoredItemImpl.prototype.terminate = thenify.withCallback(ClientMonitoredItemImpl.prototype.terminate);
300
- ClientMonitoredItemImpl.prototype.setMonitoringMode = thenify.withCallback(ClientMonitoredItemImpl.prototype.setMonitoringMode);
301
- ClientMonitoredItemImpl.prototype.modify = thenify.withCallback(ClientMonitoredItemImpl.prototype.modify);
302
- client_monitored_item_1.ClientMonitoredItem.create = (subscription, itemToMonitor, monitoringParameters, timestampsToReturn, monitoringMode = node_opcua_service_subscription_1.MonitoringMode.Reporting) => {
303
- return (0, client_subscription_impl_1.ClientMonitoredItem_create)(subscription, itemToMonitor, monitoringParameters, timestampsToReturn, monitoringMode);
304
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClientMonitoredItemImpl = void 0;
4
+ /**
5
+ * @module node-opcua-client-private
6
+ */
7
+ // tslint:disable:unified-signatures
8
+ // tslint:disable:no-empty
9
+ const events_1 = require("events");
10
+ const node_opcua_assert_1 = require("node-opcua-assert");
11
+ const node_opcua_data_model_1 = require("node-opcua-data-model");
12
+ const node_opcua_data_value_1 = require("node-opcua-data-value");
13
+ const node_opcua_debug_1 = require("node-opcua-debug");
14
+ const node_opcua_service_filter_1 = require("node-opcua-service-filter");
15
+ const node_opcua_service_read_1 = require("node-opcua-service-read");
16
+ const node_opcua_service_subscription_1 = require("node-opcua-service-subscription");
17
+ const node_opcua_status_code_1 = require("node-opcua-status-code");
18
+ const client_monitored_item_1 = require("../client_monitored_item");
19
+ const client_monitored_item_toolbox_1 = require("../client_monitored_item_toolbox");
20
+ const client_subscription_impl_1 = require("./client_subscription_impl");
21
+ const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
22
+ const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
23
+ const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
24
+ /**
25
+ * ClientMonitoredItem
26
+ * @class ClientMonitoredItem
27
+ * @extends ClientMonitoredItemBase
28
+ *
29
+ * event:
30
+ * "initialized"
31
+ * "err"
32
+ * "changed"
33
+ *
34
+ * note: this.monitoringMode = subscription_service.MonitoringMode.Reporting;
35
+ */
36
+ class ClientMonitoredItemImpl extends events_1.EventEmitter {
37
+ constructor(subscription, itemToMonitor, monitoringParameters, timestampsToReturn, monitoringMode = node_opcua_service_subscription_1.MonitoringMode.Reporting) {
38
+ super();
39
+ this.statusCode = node_opcua_status_code_1.StatusCodes.BadDataUnavailable;
40
+ (0, node_opcua_assert_1.assert)(subscription.constructor.name === "ClientSubscriptionImpl");
41
+ this.subscription = subscription;
42
+ this.itemToMonitor = new node_opcua_service_read_1.ReadValueId(itemToMonitor);
43
+ this.monitoringParameters = new node_opcua_service_subscription_1.MonitoringParameters(monitoringParameters);
44
+ this.monitoringMode = monitoringMode;
45
+ (0, node_opcua_assert_1.assert)(this.monitoringParameters.clientHandle === 0xffffffff, "should not have a client handle yet");
46
+ (0, node_opcua_assert_1.assert)(subscription.session, "expecting session");
47
+ timestampsToReturn = (0, node_opcua_data_value_1.coerceTimestampsToReturn)(timestampsToReturn);
48
+ (0, node_opcua_assert_1.assert)(subscription.constructor.name === "ClientSubscriptionImpl");
49
+ this.timestampsToReturn = timestampsToReturn;
50
+ }
51
+ toString() {
52
+ var _a, _b;
53
+ let ret = "";
54
+ ret += "itemToMonitor: " + this.itemToMonitor.toString() + "\n";
55
+ ret += "monitoringParameters: " + this.monitoringParameters.toString() + "\n";
56
+ ret += "timestampsToReturn: " + this.timestampsToReturn.toString() + "\n";
57
+ ret += "itemToMonitor " + this.itemToMonitor.nodeId + "\n";
58
+ ret += "statusCode " + ((_a = this.statusCode) === null || _a === void 0 ? void 0 : _a.toString()) + "\n";
59
+ ret += "result =" + ((_b = this.result) === null || _b === void 0 ? void 0 : _b.toString()) + "\n";
60
+ return ret;
61
+ }
62
+ terminate(...args) {
63
+ const done = args[0];
64
+ (0, node_opcua_assert_1.assert)(typeof done === "function");
65
+ const subscription = this.subscription;
66
+ subscription._delete_monitored_items([this], (err) => {
67
+ if (done) {
68
+ done(err);
69
+ }
70
+ });
71
+ }
72
+ modify(...args) {
73
+ if (args.length === 2) {
74
+ return this.modify(args[0], null, args[1]);
75
+ }
76
+ const parameters = args[0];
77
+ const timestampsToReturn = args[1];
78
+ const callback = args[2];
79
+ this.timestampsToReturn = timestampsToReturn || this.timestampsToReturn;
80
+ client_monitored_item_toolbox_1.ClientMonitoredItemToolbox._toolbox_modify(this.subscription, [this], parameters, this.timestampsToReturn, (err, results) => {
81
+ if (err) {
82
+ return callback(err);
83
+ }
84
+ if (!results) {
85
+ return callback(new Error("internal error"));
86
+ }
87
+ (0, node_opcua_assert_1.assert)(results.length === 1);
88
+ callback(null, results[0]);
89
+ });
90
+ }
91
+ setMonitoringMode(...args) {
92
+ const monitoringMode = args[0];
93
+ const callback = args[1];
94
+ client_monitored_item_toolbox_1.ClientMonitoredItemToolbox._toolbox_setMonitoringMode(this.subscription, [this], monitoringMode, (err, statusCodes) => {
95
+ callback(err ? err : null, statusCodes[0]);
96
+ });
97
+ }
98
+ /**
99
+ * @internal
100
+ * @param value
101
+ * @private
102
+ */
103
+ _notify_value_change(value) {
104
+ var _a;
105
+ // it is possible that the first notification arrives before the CreateMonitoredItemsRequest is fully proceed
106
+ // in this case we need to put the dataValue aside so we can send the notification changed after
107
+ // the node-opcua client had time to fully install the on("changed") event handler
108
+ if (((_a = this.statusCode) === null || _a === void 0 ? void 0 : _a.value) === node_opcua_status_code_1.StatusCodes.BadDataUnavailable.value) {
109
+ this._pendingDataValue = this._pendingDataValue || [];
110
+ this._pendingDataValue.push(value);
111
+ return;
112
+ }
113
+ /**
114
+ * Notify the observers that the MonitoredItem value has changed on the server side.
115
+ * @event changed
116
+ * @param value
117
+ */
118
+ try {
119
+ this.emit("changed", value);
120
+ }
121
+ catch (err) {
122
+ warningLog("[NODE-OPCUA-W28] Exception raised inside the event handler called by ClientMonitoredItem.on('change')", err);
123
+ warningLog(" Please verify the application using this node-opcua client");
124
+ }
125
+ }
126
+ /**
127
+ * @internal
128
+ * @param eventFields
129
+ * @private
130
+ */
131
+ _notify_event(eventFields) {
132
+ var _a;
133
+ if (((_a = this.statusCode) === null || _a === void 0 ? void 0 : _a.value) === node_opcua_status_code_1.StatusCodes.BadDataUnavailable.value) {
134
+ this._pendingEvents = this._pendingEvents || [];
135
+ this._pendingEvents.push(eventFields);
136
+ return;
137
+ }
138
+ /**
139
+ * Notify the observers that the MonitoredItem value has changed on the server side.
140
+ * @event changed
141
+ * @param value
142
+ */
143
+ try {
144
+ this.emit("changed", eventFields);
145
+ }
146
+ catch (err) {
147
+ warningLog("[NODE-OPCUA-W29] Exception raised inside the event handler called by ClientMonitoredItem.on('change')", err);
148
+ warningLog(" Please verify the application using this node-opcua client");
149
+ }
150
+ }
151
+ /**
152
+ * @internal
153
+ * @private
154
+ */
155
+ _prepare_for_monitoring() {
156
+ (0, node_opcua_assert_1.assert)(this.monitoringParameters.clientHandle === 4294967295, "should not have a client handle yet");
157
+ const subscription = this.subscription;
158
+ this.monitoringParameters.clientHandle = subscription.nextClientHandle();
159
+ (0, node_opcua_assert_1.assert)(this.monitoringParameters.clientHandle > 0 && this.monitoringParameters.clientHandle !== 4294967295);
160
+ // If attributeId is EventNotifier then monitoring parameters need a filter.
161
+ // The filter must then either be DataChangeFilter, EventFilter or AggregateFilter.
162
+ // todo can be done in another way?
163
+ // todo implement AggregateFilter
164
+ // todo support DataChangeFilter
165
+ // todo support whereClause
166
+ if (this.itemToMonitor.attributeId === node_opcua_data_model_1.AttributeIds.EventNotifier) {
167
+ //
168
+ // see OPCUA Spec 1.02 part 4 page 65 : 5.12.1.4 Filter
169
+ // see part 4 page 130: 7.16.3 EventFilter
170
+ // part 3 page 11 : 4.6 Event Model
171
+ // To monitor for Events, the attributeId element of the ReadValueId structure is the
172
+ // the id of the EventNotifierAttribute
173
+ // OPC Unified Architecture 1.02, Part 4 5.12.1.2 Sampling interval page 64:
174
+ // "A Client shall define a sampling interval of 0 if it subscribes for Events."
175
+ // toDO
176
+ // note : the EventFilter is used when monitoring Events.
177
+ this.monitoringParameters.filter = this.monitoringParameters.filter || new node_opcua_service_filter_1.EventFilter({});
178
+ const filter = this.monitoringParameters.filter;
179
+ // istanbul ignore next
180
+ if (!filter) {
181
+ return { error: "Internal Error" };
182
+ }
183
+ if (filter.schema.name !== "EventFilter") {
184
+ return {
185
+ error: "Mismatch between attributeId and filter in monitoring parameters : " +
186
+ "Got a " +
187
+ filter.schema.name +
188
+ " but a EventFilter object is required " +
189
+ "when itemToMonitor.attributeId== AttributeIds.EventNotifier"
190
+ };
191
+ }
192
+ }
193
+ else if (this.itemToMonitor.attributeId === node_opcua_data_model_1.AttributeIds.Value) {
194
+ // the DataChangeFilter and the AggregateFilter are used when monitoring Variable Values
195
+ // The Value Attribute is used when monitoring Variables. Variable values are monitored for a change
196
+ // in value or a change in their status. The filters defined in this standard (see 7.16.2) and in Part 8 are
197
+ // used to determine if the value change is large enough to cause a Notification to be generated for the
198
+ // to do : check 'DataChangeFilter' && 'AggregateFilter'
199
+ }
200
+ else {
201
+ if (this.monitoringParameters.filter) {
202
+ return {
203
+ error: "Mismatch between attributeId and filter in monitoring parameters : " +
204
+ "no filter expected when attributeId is not Value or EventNotifier"
205
+ };
206
+ }
207
+ }
208
+ return {
209
+ itemToMonitor: this.itemToMonitor,
210
+ monitoringMode: this.monitoringMode,
211
+ requestedParameters: this.monitoringParameters
212
+ };
213
+ }
214
+ /**
215
+ * @internal
216
+ * @param monitoredItemResult
217
+ * @private
218
+ */
219
+ _applyResult(monitoredItemResult) {
220
+ this.statusCode = monitoredItemResult.statusCode;
221
+ /* istanbul ignore else */
222
+ if (monitoredItemResult.statusCode.isGood()) {
223
+ this.result = monitoredItemResult;
224
+ this.monitoredItemId = monitoredItemResult.monitoredItemId;
225
+ this.monitoringParameters.samplingInterval = monitoredItemResult.revisedSamplingInterval;
226
+ this.monitoringParameters.queueSize = monitoredItemResult.revisedQueueSize;
227
+ this.filterResult = monitoredItemResult.filterResult || undefined;
228
+ }
229
+ // some PublishRequest with DataNotificationChange might have been sent by the server, before the monitored
230
+ // item has been fully initialized it is time to process now any pending notification that were put on hold.
231
+ if (this._pendingDataValue) {
232
+ const dataValues = this._pendingDataValue;
233
+ this._pendingDataValue = undefined;
234
+ setImmediate(() => {
235
+ dataValues.map((dataValue) => this._notify_value_change(dataValue));
236
+ });
237
+ }
238
+ if (this._pendingEvents) {
239
+ const events = this._pendingEvents;
240
+ this._pendingEvents = undefined;
241
+ setImmediate(() => {
242
+ events.map((event) => this._notify_event(event));
243
+ });
244
+ }
245
+ }
246
+ _before_create() {
247
+ const subscription = this.subscription;
248
+ subscription._add_monitored_item(this.monitoringParameters.clientHandle, this);
249
+ }
250
+ /**
251
+ * @internal
252
+ * @param monitoredItemResult
253
+ * @private
254
+ */
255
+ _after_create(monitoredItemResult) {
256
+ this._applyResult(monitoredItemResult);
257
+ if (this.statusCode.isGood()) {
258
+ /**
259
+ * Notify the observers that the monitored item is now fully initialized.
260
+ * @event initialized
261
+ */
262
+ this.emit("initialized");
263
+ }
264
+ else {
265
+ /**
266
+ * Notify the observers that the monitored item has failed to initialize.
267
+ * @event err
268
+ * @param statusCode {StatusCode}
269
+ */
270
+ const err = new Error(monitoredItemResult.statusCode.toString());
271
+ this._terminate_and_emit(err);
272
+ }
273
+ }
274
+ _terminate_and_emit(err) {
275
+ if (this._terminated) {
276
+ return; // already terminated
277
+ }
278
+ if (err) {
279
+ this.emit("err", err.message);
280
+ }
281
+ (0, node_opcua_assert_1.assert)(!this._terminated);
282
+ this._terminated = true;
283
+ /**
284
+ * Notify the observer that this monitored item has been terminated.
285
+ * @event terminated
286
+ */
287
+ this.emit("terminated", err);
288
+ this.removeAllListeners();
289
+ // also remove from subscription
290
+ const clientHandle = this.monitoringParameters.clientHandle;
291
+ delete this.subscription.monitoredItems[clientHandle];
292
+ }
293
+ }
294
+ exports.ClientMonitoredItemImpl = ClientMonitoredItemImpl;
295
+ // tslint:disable:no-var-requires
296
+ // tslint:disable:max-line-length
297
+ const thenify = require("thenify");
298
+ const opts = { multiArgs: false };
299
+ ClientMonitoredItemImpl.prototype.terminate = thenify.withCallback(ClientMonitoredItemImpl.prototype.terminate);
300
+ ClientMonitoredItemImpl.prototype.setMonitoringMode = thenify.withCallback(ClientMonitoredItemImpl.prototype.setMonitoringMode);
301
+ ClientMonitoredItemImpl.prototype.modify = thenify.withCallback(ClientMonitoredItemImpl.prototype.modify);
302
+ client_monitored_item_1.ClientMonitoredItem.create = (subscription, itemToMonitor, monitoringParameters, timestampsToReturn, monitoringMode = node_opcua_service_subscription_1.MonitoringMode.Reporting) => {
303
+ return (0, client_subscription_impl_1.ClientMonitoredItem_create)(subscription, itemToMonitor, monitoringParameters, timestampsToReturn, monitoringMode);
304
+ };
305
305
  //# sourceMappingURL=client_monitored_item_impl.js.map