node-opcua-client 2.166.0 → 2.167.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.
Files changed (102) hide show
  1. package/dist/alarms_and_conditions/client_alarm_tools.d.ts +1 -1
  2. package/dist/alarms_and_conditions/client_alarm_tools.js +2 -2
  3. package/dist/alarms_and_conditions/client_alarm_tools.js.map +1 -1
  4. package/dist/alarms_and_conditions/client_tools.d.ts +3 -0
  5. package/dist/alarms_and_conditions/client_tools.js +2 -2
  6. package/dist/alarms_and_conditions/client_tools.js.map +1 -1
  7. package/dist/client_base.d.ts +47 -40
  8. package/dist/client_base.js +5 -6
  9. package/dist/client_base.js.map +1 -1
  10. package/dist/client_monitored_item.d.ts +7 -7
  11. package/dist/client_monitored_item.js.map +1 -1
  12. package/dist/client_monitored_item_base.d.ts +12 -13
  13. package/dist/client_monitored_item_group.d.ts +5 -5
  14. package/dist/client_monitored_item_toolbox.d.ts +6 -7
  15. package/dist/client_monitored_item_toolbox.js.map +1 -1
  16. package/dist/client_session.d.ts +19 -23
  17. package/dist/client_session.js.map +1 -1
  18. package/dist/client_session_keepalive_manager.d.ts +1 -1
  19. package/dist/client_session_keepalive_manager.js +6 -6
  20. package/dist/client_session_keepalive_manager.js.map +1 -1
  21. package/dist/client_subscription.d.ts +11 -12
  22. package/dist/client_subscription.js.map +1 -1
  23. package/dist/client_utils.d.ts +3 -3
  24. package/dist/client_utils.js.map +1 -1
  25. package/dist/common.d.ts +12 -12
  26. package/dist/index.d.ts +26 -27
  27. package/dist/index.js +65 -66
  28. package/dist/index.js.map +1 -1
  29. package/dist/opcua_client.d.ts +17 -19
  30. package/dist/opcua_client.js.map +1 -1
  31. package/dist/private/client_base_impl.d.ts +19 -18
  32. package/dist/private/client_base_impl.js +140 -119
  33. package/dist/private/client_base_impl.js.map +1 -1
  34. package/dist/private/client_monitored_item_group_impl.d.ts +4 -5
  35. package/dist/private/client_monitored_item_group_impl.js +1 -1
  36. package/dist/private/client_monitored_item_group_impl.js.map +1 -1
  37. package/dist/private/client_monitored_item_impl.d.ts +9 -10
  38. package/dist/private/client_monitored_item_impl.js.map +1 -1
  39. package/dist/private/client_publish_engine.d.ts +3 -3
  40. package/dist/private/client_publish_engine.js +6 -7
  41. package/dist/private/client_publish_engine.js.map +1 -1
  42. package/dist/private/client_session_impl.d.ts +24 -25
  43. package/dist/private/client_session_impl.js +14 -10
  44. package/dist/private/client_session_impl.js.map +1 -1
  45. package/dist/private/client_subscription_impl.d.ts +10 -11
  46. package/dist/private/client_subscription_impl.js +12 -11
  47. package/dist/private/client_subscription_impl.js.map +1 -1
  48. package/dist/private/i_private_client.d.ts +7 -7
  49. package/dist/private/opcua_client_impl.d.ts +12 -9
  50. package/dist/private/opcua_client_impl.js +58 -48
  51. package/dist/private/opcua_client_impl.js.map +1 -1
  52. package/dist/private/performance.js.map +1 -1
  53. package/dist/private/reconnection/client_publish_engine_reconnection.d.ts +1 -1
  54. package/dist/private/reconnection/client_publish_engine_reconnection.js +4 -2
  55. package/dist/private/reconnection/client_publish_engine_reconnection.js.map +1 -1
  56. package/dist/private/reconnection/client_reconnection.d.ts +1 -1
  57. package/dist/private/reconnection/client_subscription_reconnection.d.ts +1 -1
  58. package/dist/private/reconnection/client_subscription_reconnection.js +2 -2
  59. package/dist/private/reconnection/client_subscription_reconnection.js.map +1 -1
  60. package/dist/private/reconnection/reconnection.d.ts +3 -3
  61. package/dist/private/reconnection/reconnection.js +1 -1
  62. package/dist/private/reconnection/reconnection.js.map +1 -1
  63. package/dist/tools/findservers.d.ts +7 -2
  64. package/dist/tools/findservers.js +41 -53
  65. package/dist/tools/findservers.js.map +1 -1
  66. package/dist/tools/read_history_server_capabilities.d.ts +1 -1
  67. package/dist/tools/read_history_server_capabilities.js +9 -8
  68. package/dist/tools/read_history_server_capabilities.js.map +1 -1
  69. package/dist/user_identity_info.d.ts +1 -1
  70. package/dist/verify.js.map +1 -1
  71. package/package.json +41 -40
  72. package/source/alarms_and_conditions/client_alarm_tools.ts +14 -8
  73. package/source/alarms_and_conditions/client_tools.ts +7 -6
  74. package/source/client_base.ts +93 -79
  75. package/source/client_monitored_item.ts +7 -8
  76. package/source/client_monitored_item_base.ts +12 -14
  77. package/source/client_monitored_item_group.ts +5 -5
  78. package/source/client_monitored_item_toolbox.ts +13 -14
  79. package/source/client_session.ts +37 -40
  80. package/source/client_session_keepalive_manager.ts +7 -10
  81. package/source/client_subscription.ts +11 -12
  82. package/source/client_utils.ts +6 -6
  83. package/source/common.ts +12 -12
  84. package/source/index.ts +44 -40
  85. package/source/opcua_client.ts +24 -23
  86. package/source/private/client_base_impl.ts +276 -186
  87. package/source/private/client_monitored_item_group_impl.ts +10 -14
  88. package/source/private/client_monitored_item_impl.ts +17 -17
  89. package/source/private/client_publish_engine.ts +11 -12
  90. package/source/private/client_session_impl.ts +85 -82
  91. package/source/private/client_subscription_impl.ts +42 -41
  92. package/source/private/i_private_client.ts +8 -8
  93. package/source/private/opcua_client_impl.ts +118 -97
  94. package/source/private/performance.ts +2 -3
  95. package/source/private/reconnection/client_publish_engine_reconnection.ts +16 -15
  96. package/source/private/reconnection/client_reconnection.ts +1 -1
  97. package/source/private/reconnection/client_subscription_reconnection.ts +16 -13
  98. package/source/private/reconnection/reconnection.ts +130 -33
  99. package/source/tools/findservers.ts +43 -62
  100. package/source/tools/read_history_server_capabilities.ts +20 -22
  101. package/source/user_identity_info.ts +5 -5
  102. package/source/verify.ts +25 -25
@@ -1,18 +1,21 @@
1
1
  import { promisify } from "node:util";
2
2
  import assert from "node-opcua-assert";
3
3
  import { TimestampsToReturn } from "node-opcua-data-value";
4
- import { make_debugLog, checkDebugFlag, make_warningLog } from "node-opcua-debug";
5
- import { MonitoredItemCreateRequestOptions, CreateMonitoredItemsRequest, CreateMonitoredItemsResponse } from "node-opcua-types";
6
-
4
+ import { checkDebugFlag, make_debugLog, make_warningLog } from "node-opcua-debug";
7
5
  import {
8
- IBasicSessionReadAsync,
9
- IBasicSessionWithSubscription,
10
6
  createMonitoredItemsLimit,
7
+ type IBasicSessionReadAsync,
8
+ type IBasicSessionWithSubscription,
11
9
  readOperationLimits
12
10
  } from "node-opcua-pseudo-session";
13
- import { ClientSubscription } from "../../client_subscription";
14
- import { ClientMonitoredItemImpl } from "../client_monitored_item_impl";
15
- import { ClientSubscriptionImpl, TERMINATED_SUBSCRIPTION_ID, __create_subscription } from "../client_subscription_impl";
11
+ import {
12
+ CreateMonitoredItemsRequest,
13
+ type CreateMonitoredItemsResponse,
14
+ type MonitoredItemCreateRequestOptions
15
+ } from "node-opcua-types";
16
+ import type { ClientSubscription } from "../../client_subscription";
17
+ import type { ClientMonitoredItemImpl } from "../client_monitored_item_impl";
18
+ import { __create_subscription, type ClientSubscriptionImpl, TERMINATED_SUBSCRIPTION_ID } from "../client_subscription_impl";
16
19
  import { _shouldNotContinue } from "./reconnection";
17
20
 
18
21
  const debugLog = make_debugLog("RECONNECTION");
@@ -33,7 +36,7 @@ async function createMonitoredItemsAndRespectOperationalLimits(
33
36
  }
34
37
 
35
38
  async function adjustMonitoredItemNodeIds(subscription: ClientSubscription, oldMonitoredItems: any) {
36
- // to Do
39
+ // to Do
37
40
  }
38
41
  /**
39
42
  * utility function to recreate new subscription
@@ -56,7 +59,9 @@ export async function recreateSubscriptionAndMonitoredItem(_subscription: Client
56
59
  await promisify(__create_subscription)(subscription);
57
60
 
58
61
  const _err = _shouldNotContinue(subscription.session);
59
- if (_err) { throw _err; }
62
+ if (_err) {
63
+ throw _err;
64
+ }
60
65
 
61
66
  const test = subscription.publishEngine.getSubscription(subscription.subscriptionId);
62
67
 
@@ -89,9 +94,7 @@ export async function recreateSubscriptionAndMonitoredItem(_subscription: Client
89
94
 
90
95
  debugLog("Recreating ", itemsToCreate.length, " monitored items");
91
96
 
92
- const response = await createMonitoredItemsAndRespectOperationalLimits(
93
- session,
94
- createMonitorItemsRequest);
97
+ const response = await createMonitoredItemsAndRespectOperationalLimits(session, createMonitorItemsRequest);
95
98
  const monitoredItemResults = response.results || [];
96
99
 
97
100
  let _errCount = 0;
@@ -6,17 +6,16 @@
6
6
  import async from "async";
7
7
  import chalk from "chalk";
8
8
  import { assert } from "node-opcua-assert";
9
+ import { invalidateExtraDataTypeManager } from "node-opcua-client-dynamic-extension-object";
9
10
  import { checkDebugFlag, make_debugLog, make_errorLog, make_warningLog } from "node-opcua-debug";
10
- import { TransferSubscriptionsRequest, TransferSubscriptionsResponse } from "node-opcua-service-subscription";
11
- import { CallbackT, StatusCode, StatusCodes } from "node-opcua-status-code";
12
- import { ErrorCallback } from "node-opcua-status-code";
11
+ import { TransferSubscriptionsRequest, type TransferSubscriptionsResponse } from "node-opcua-service-subscription";
12
+ import { type CallbackT, type ErrorCallback, StatusCode, StatusCodes } from "node-opcua-status-code";
13
13
  import { CloseSessionRequest } from "node-opcua-types";
14
- import { invalidateExtraDataTypeManager } from "node-opcua-client-dynamic-extension-object";
15
14
 
16
- import { SubscriptionId } from "../../client_session";
17
- import { ClientSessionImpl, Reconnectable } from "../client_session_impl";
18
- import { ClientSubscriptionImpl } from "../client_subscription_impl";
19
- import { IClientBase } from "../i_private_client";
15
+ import type { SubscriptionId } from "../../client_session";
16
+ import type { ClientSessionImpl, Reconnectable } from "../client_session_impl";
17
+ import type { ClientSubscriptionImpl } from "../client_subscription_impl";
18
+ import type { IClientBase } from "../i_private_client";
20
19
  import { republish } from "./client_publish_engine_reconnection";
21
20
  import { recreateSubscriptionAndMonitoredItem } from "./client_subscription_reconnection";
22
21
 
@@ -131,7 +130,12 @@ export function _shouldNotContinue2(subscription: ClientSubscriptionImpl) {
131
130
 
132
131
  function _ask_for_subscription_republish(session: ClientSessionImpl, callback: (err?: Error) => void) {
133
132
  // prettier-ignore
134
- { const err = _shouldNotContinue(session); if (err) { return callback(err); } }
133
+ {
134
+ const err = _shouldNotContinue(session);
135
+ if (err) {
136
+ return callback(err);
137
+ }
138
+ }
135
139
 
136
140
  doDebug && debugLog(chalk.bgCyan.yellow.bold("_ask_for_subscription_republish "));
137
141
  // assert(session.getPublishEngine().nbPendingPublishRequests === 0,
@@ -141,7 +145,12 @@ function _ask_for_subscription_republish(session: ClientSessionImpl, callback: (
141
145
  republish(engine, (err?: Error) => {
142
146
  doDebug && debugLog("_ask_for_subscription_republish : republish sent");
143
147
  // prettier-ignore
144
- { const err = _shouldNotContinue(session); if (err) { return callback(err); } }
148
+ {
149
+ const err = _shouldNotContinue(session);
150
+ if (err) {
151
+ return callback(err);
152
+ }
153
+ }
145
154
 
146
155
  doDebug && debugLog(chalk.bgCyan.green.bold("_ask_for_subscription_republish done "), err ? err.message : "OK");
147
156
  if (err) {
@@ -160,14 +169,24 @@ function create_session_and_repeat_if_failed(
160
169
  callback: CallbackT<ClientSessionImpl>
161
170
  ) {
162
171
  // prettier-ignore
163
- { const err = _shouldNotContinue(session); if (err) { return callback(err); } }
172
+ {
173
+ const err = _shouldNotContinue(session);
174
+ if (err) {
175
+ return callback(err);
176
+ }
177
+ }
164
178
 
165
179
  doDebug && debugLog(chalk.bgWhite.red(" => creating a new session ...."));
166
180
  // create new session, based on old session,
167
181
  // so we can reuse subscriptions data
168
182
  client.__createSession_step2(session, (err: Error | null, session1?: ClientSessionImpl) => {
169
183
  // prettier-ignore
170
- { const err = _shouldNotContinue(session); if (err) { return callback(err); } }
184
+ {
185
+ const err = _shouldNotContinue(session);
186
+ if (err) {
187
+ return callback(err);
188
+ }
189
+ }
171
190
 
172
191
  if (!err && session1) {
173
192
  assert(session === session1, "session should have been recycled");
@@ -186,7 +205,12 @@ function repair_client_session_by_recreating_a_new_session(
186
205
  callback: (err?: Error) => void
187
206
  ) {
188
207
  // prettier-ignore
189
- { const err = _shouldNotContinue(session); if (err) { return callback(err); } }
208
+ {
209
+ const err = _shouldNotContinue(session);
210
+ if (err) {
211
+ return callback(err);
212
+ }
213
+ }
190
214
 
191
215
  // As we don"t know if server has been rebooted or not,
192
216
  // and may be upgraded in between, we have to invalidate the extra data type manager
@@ -206,7 +230,12 @@ function repair_client_session_by_recreating_a_new_session(
206
230
  subscriptionsToRecreate,
207
231
  (subscriptionId: SubscriptionId, next: ErrorCallback) => {
208
232
  // prettier-ignore
209
- { const err = _shouldNotContinue(session); if (err) { return next(err); } }
233
+ {
234
+ const err = _shouldNotContinue(session);
235
+ if (err) {
236
+ return next(err);
237
+ }
238
+ }
210
239
 
211
240
  if (!session.getPublishEngine().hasSubscription(subscriptionId)) {
212
241
  doDebug && debugLog(chalk.red(" => CANNOT RECREATE SUBSCRIPTION "), subscriptionId);
@@ -232,7 +261,12 @@ function repair_client_session_by_recreating_a_new_session(
232
261
  },
233
262
  (err1?: Error | null) => {
234
263
  // prettier-ignore
235
- { const err = _shouldNotContinue(session); if (err) { return innerCallback(err); } }
264
+ {
265
+ const err = _shouldNotContinue(session);
266
+ if (err) {
267
+ return innerCallback(err);
268
+ }
269
+ }
236
270
  if (!err1) {
237
271
  // prettier-ignore
238
272
  }
@@ -245,7 +279,12 @@ function repair_client_session_by_recreating_a_new_session(
245
279
  [
246
280
  function suspend_old_session_publish_engine(innerCallback: ErrorCallback) {
247
281
  // prettier-ignore
248
- { const err = _shouldNotContinue(session); if (err) { return innerCallback(err); } }
282
+ {
283
+ const err = _shouldNotContinue(session);
284
+ if (err) {
285
+ return innerCallback(err);
286
+ }
287
+ }
249
288
 
250
289
  // c8 ignore next
251
290
  doDebug && debugLog(chalk.bgWhite.red(" => suspend old session publish engine...."));
@@ -256,7 +295,12 @@ function repair_client_session_by_recreating_a_new_session(
256
295
  function create_new_session(innerCallback: ErrorCallback) {
257
296
  create_session_and_repeat_if_failed(client, session, (err?: Error | null, _newSession?: ClientSessionImpl) => {
258
297
  // prettier-ignore
259
- { const err = _shouldNotContinue(session); if (err) { return innerCallback(err); } }
298
+ {
299
+ const err = _shouldNotContinue(session);
300
+ if (err) {
301
+ return innerCallback(err);
302
+ }
303
+ }
260
304
 
261
305
  if (_newSession) {
262
306
  newSession = _newSession;
@@ -267,7 +311,12 @@ function repair_client_session_by_recreating_a_new_session(
267
311
 
268
312
  function activate_new_session(innerCallback: ErrorCallback) {
269
313
  // prettier-ignore
270
- { const err = _shouldNotContinue(session); if (err) { return innerCallback(err); } }
314
+ {
315
+ const err = _shouldNotContinue(session);
316
+ if (err) {
317
+ return innerCallback(err);
318
+ }
319
+ }
271
320
 
272
321
  doDebug && debugLog(chalk.bgWhite.red(" => activating a new session ...."));
273
322
 
@@ -333,7 +382,12 @@ function repair_client_session_by_recreating_a_new_session(
333
382
 
334
383
  function attempt_subscription_transfer(innerCallback: ErrorCallback) {
335
384
  // prettier-ignore
336
- { const err = _shouldNotContinue(session); if (err) { return innerCallback(err); } }
385
+ {
386
+ const err = _shouldNotContinue(session);
387
+ if (err) {
388
+ return innerCallback(err);
389
+ }
390
+ }
337
391
 
338
392
  // get the old subscriptions id from the old session
339
393
  const subscriptionsIds = session.getPublishEngine().getSubscriptionIds();
@@ -359,7 +413,12 @@ function repair_client_session_by_recreating_a_new_session(
359
413
  (err: Error | null, transferSubscriptionsResponse?: TransferSubscriptionsResponse) => {
360
414
  // may be the connection with server has been disconnected
361
415
  // prettier-ignore
362
- { const err = _shouldNotContinue(session); if (err) { return innerCallback(err); } }
416
+ {
417
+ const err = _shouldNotContinue(session);
418
+ if (err) {
419
+ return innerCallback(err);
420
+ }
421
+ }
363
422
 
364
423
  if (err || !transferSubscriptionsResponse) {
365
424
  warningLog(chalk.bgCyan("May be the server is not supporting this feature"));
@@ -418,7 +477,12 @@ function repair_client_session_by_recreating_a_new_session(
418
477
 
419
478
  function ask_for_subscription_republish(innerCallback: ErrorCallback) {
420
479
  // prettier-ignore
421
- { const err = _shouldNotContinue(session); if (err) { return innerCallback(err); } }
480
+ {
481
+ const err = _shouldNotContinue(session);
482
+ if (err) {
483
+ return innerCallback(err);
484
+ }
485
+ }
422
486
 
423
487
  // assert(newSession.getPublishEngine().nbPendingPublishRequests === 0, "we should not be publishing here");
424
488
  // call Republish
@@ -432,7 +496,12 @@ function repair_client_session_by_recreating_a_new_session(
432
496
 
433
497
  function start_publishing_as_normal(innerCallback: ErrorCallback) {
434
498
  // prettier-ignore
435
- { const err = _shouldNotContinue(session); if (err) { return innerCallback(err); } }
499
+ {
500
+ const err = _shouldNotContinue(session);
501
+ if (err) {
502
+ return innerCallback(err);
503
+ }
504
+ }
436
505
 
437
506
  newSession.getPublishEngine().suspend(false);
438
507
 
@@ -467,11 +536,21 @@ function _repair_client_session(client: IClientBase, session: ClientSessionImpl,
467
536
  }
468
537
 
469
538
  // prettier-ignore
470
- { const err = _shouldNotContinue(session); if (err) { return callback(err); } }
539
+ {
540
+ const err = _shouldNotContinue(session);
541
+ if (err) {
542
+ return callback(err);
543
+ }
544
+ }
471
545
 
472
546
  client._activateSession(session, session.userIdentityInfo!, (err: Error | null, session2?: ClientSessionImpl) => {
473
547
  // prettier-ignore
474
- { const err = _shouldNotContinue(session); if (err) { return callback(err); } }
548
+ {
549
+ const err = _shouldNotContinue(session);
550
+ if (err) {
551
+ return callback(err);
552
+ }
553
+ }
475
554
  //
476
555
  // Note: current limitation :
477
556
  // - The reconnection doesn't work yet, if connection break is caused by a server that crashes and restarts.
@@ -513,15 +592,25 @@ export function repair_client_session(client: IClientBase, session: ClientSessio
513
592
  privateSession._reconnecting.reconnecting = true;
514
593
 
515
594
  // get old transaction queue ...
516
- const transactionQueue = privateSession._reconnecting.pendingTransactions.splice(0);
595
+ const transactionQueue = privateSession._reconnecting.pendingTransactions.splice(0);
517
596
 
518
597
  const repeatedAction = (callback: EmptyCallback) => {
519
598
  // prettier-ignore
520
- { const err = _shouldNotContinue(session); if (err) { return callback(err); } }
599
+ {
600
+ const err = _shouldNotContinue(session);
601
+ if (err) {
602
+ return callback(err);
603
+ }
604
+ }
521
605
 
522
606
  _repair_client_session(client, session, (err) => {
523
607
  // prettier-ignore
524
- { const err = _shouldNotContinue(session); if (err) { return callback(err); } }
608
+ {
609
+ const err = _shouldNotContinue(session);
610
+ if (err) {
611
+ return callback(err);
612
+ }
613
+ }
525
614
 
526
615
  if (err) {
527
616
  errorLog(
@@ -534,10 +623,13 @@ export function repair_client_session(client: IClientBase, session: ClientSessio
534
623
  const delay = 2000;
535
624
  errorLog(chalk.red(`... will retry session repair... in ${delay} ms`));
536
625
  setTimeout(() => {
537
- { const err = _shouldNotContinue(session); if (err) {
538
- warningLog("cancelling session repair");
539
- return callback(err);
540
- } }
626
+ {
627
+ const err = _shouldNotContinue(session);
628
+ if (err) {
629
+ warningLog("cancelling session repair");
630
+ return callback(err);
631
+ }
632
+ }
541
633
  errorLog(chalk.red("Retrying session repair..."));
542
634
  repeatedAction(callback);
543
635
  }, delay);
@@ -560,7 +652,7 @@ export function repair_client_session(client: IClientBase, session: ClientSessio
560
652
  privateSession._reconnecting.reconnecting = false;
561
653
  const otherCallbacks = privateSession._reconnecting.pendingCallbacks.splice(0);
562
654
  // re-inject element in queue
563
-
655
+
564
656
  // c8 ignore next
565
657
  if (transactionQueue.length > 0) {
566
658
  doDebug && debugLog(chalk.yellow("re-injecting transaction queue"), transactionQueue.length);
@@ -585,7 +677,12 @@ export function repair_client_sessions(client: IClientBase, callback: (err?: Err
585
677
  (err, allErrors: (undefined | Error | null)[] | undefined) => {
586
678
  err && errorLog("sessions reactivation completed with err: err ", err ? err.message : "null");
587
679
  // prettier-ignore
588
- { const err = _shouldNotContinue3(client); if (err) { return callback(err); } }
680
+ {
681
+ const err = _shouldNotContinue3(client);
682
+ if (err) {
683
+ return callback(err);
684
+ }
685
+ }
589
686
 
590
687
  return callback(err!);
591
688
  }
@@ -1,17 +1,29 @@
1
1
  /**
2
2
  * @module node-opcua-client
3
3
  */
4
- import async from "async";
5
4
 
6
- import { ErrorCallback } from "node-opcua-status-code";
7
- import { ServerOnNetwork } from "node-opcua-service-discovery";
8
- import { ApplicationDescription, EndpointDescription } from "node-opcua-service-endpoints";
5
+ import type { ServerOnNetwork } from "node-opcua-service-discovery";
6
+ import type { ApplicationDescription, EndpointDescription } from "node-opcua-service-endpoints";
7
+
8
+
9
9
  import { ClientBaseImpl } from "../private/client_base_impl";
10
10
 
11
11
  export interface FindServerResults {
12
12
  servers: ApplicationDescription[];
13
13
  endpoints: EndpointDescription[];
14
14
  }
15
+ export async function findServersAsync(discoveryServerEndpointUri: string): Promise<FindServerResults> {
16
+ const client = new ClientBaseImpl({ connectionStrategy: { maxRetry: 3 } });
17
+ try {
18
+ await client.connect(discoveryServerEndpointUri);
19
+ const servers = await client.findServers();
20
+ const endpoints = await client.getEndpoints({ endpointUrl: undefined });
21
+ return { servers, endpoints };
22
+ } finally {
23
+ await client.disconnect();
24
+ }
25
+ }
26
+
15
27
  /**
16
28
  * extract the server endpoints exposed by a discovery server
17
29
  */
@@ -19,52 +31,34 @@ export function findServers(
19
31
  discoveryServerEndpointUri: string,
20
32
  callback: (err: Error | null, result?: FindServerResults) => void
21
33
  ): void;
22
- export async function findServers(discoveryServerEndpointUri: string): Promise<FindServerResults>;
34
+ export function findServers(discoveryServerEndpointUri: string): Promise<FindServerResults>;
23
35
  export function findServers(
24
36
  discoveryServerEndpointUri: string,
25
37
  callback?: (err: Error | null, result?: FindServerResults) => void
26
- ): any {
38
+ ): Promise<FindServerResults> | undefined {
39
+ if (!callback) {
40
+ return findServersAsync(discoveryServerEndpointUri);
41
+ }
42
+ findServersAsync(discoveryServerEndpointUri)
43
+ .then((result) => callback(null, result))
44
+ .catch((err) => callback(err));
45
+ return undefined;
46
+ }
47
+ export async function findServersOnNetworkAsync(discoveryServerEndpointUri: string): Promise<ServerOnNetwork[]> {
27
48
  const client = new ClientBaseImpl({ connectionStrategy: { maxRetry: 3 } });
28
-
29
- let servers: ApplicationDescription[] = [];
30
- let endpoints: EndpointDescription[] = [];
31
-
32
- async.series(
33
- [
34
- (innerCallback: ErrorCallback) => {
35
- client.connect(discoveryServerEndpointUri, innerCallback);
36
- },
37
-
38
- (innerCallback: ErrorCallback) => {
39
- client.findServers((err: Error | null, _servers?: ApplicationDescription[]) => {
40
- if (_servers) {
41
- servers = _servers;
42
- }
43
- innerCallback(err ? err : undefined);
44
- });
45
- },
46
-
47
- (innerCallback: ErrorCallback) => {
48
- client.getEndpoints({ endpointUrl: undefined }, (err: Error | null, _endpoints?: EndpointDescription[]) => {
49
- if (_endpoints) {
50
- endpoints = _endpoints;
51
- }
52
- innerCallback(err ? err : undefined);
53
- });
54
- }
55
- ],
56
- (err) => {
57
- client.disconnect(() => {
58
- callback!(err ? err : null, { servers, endpoints });
59
- });
60
- }
61
- );
49
+ try {
50
+ await client.connect(discoveryServerEndpointUri);
51
+ const servers = await client.findServersOnNetwork();
52
+ return servers;
53
+ } finally {
54
+ await client.disconnect();
55
+ }
62
56
  }
63
57
 
64
58
  /**
65
59
  * extract the server endpoints exposed by a discovery server
66
60
  */
67
- export async function findServersOnNetwork(discoveryServerEndpointUri: string): Promise<ServerOnNetwork[]>;
61
+ export function findServersOnNetwork(discoveryServerEndpointUri: string): Promise<ServerOnNetwork[]>;
68
62
  export function findServersOnNetwork(
69
63
  discoveryServerEndpointUri: string,
70
64
  callback: (err: Error | null, servers?: ServerOnNetwork[]) => void
@@ -72,25 +66,12 @@ export function findServersOnNetwork(
72
66
  export function findServersOnNetwork(
73
67
  discoveryServerEndpointUri: string,
74
68
  callback?: (err: Error | null, servers?: ServerOnNetwork[]) => void
75
- ): any {
76
- const client = new ClientBaseImpl({ connectionStrategy: { maxRetry: 3 } });
77
-
78
- client.connect(discoveryServerEndpointUri, (err?: Error) => {
79
- if (!err) {
80
- client.findServersOnNetwork((err1, servers) => {
81
- client.disconnect(() => {
82
- callback!(err1, servers);
83
- });
84
- });
85
- } else {
86
- client.disconnect(() => {
87
- callback!(err);
88
- });
89
- }
90
- });
69
+ ): Promise<ServerOnNetwork[]> | undefined {
70
+ if (!callback) {
71
+ return findServersOnNetworkAsync(discoveryServerEndpointUri);
72
+ }
73
+ findServersOnNetworkAsync(discoveryServerEndpointUri)
74
+ .then((servers) => callback(null, servers))
75
+ .catch((err) => callback(err));
76
+ return undefined;
91
77
  }
92
-
93
- // tslint:disable:no-var-requires
94
- import { withCallback } from "thenify-ex";
95
- (module.exports as any).findServersOnNetwork = withCallback((module.exports as any).findServersOnNetwork);
96
- (module.exports as any).findServers = withCallback((module.exports as any).findServers);
@@ -4,15 +4,15 @@
4
4
  import { assert } from "node-opcua-assert";
5
5
  import { ObjectIds } from "node-opcua-constants";
6
6
  import { AttributeIds } from "node-opcua-data-model";
7
- import { DataValue } from "node-opcua-data-value";
7
+ import type { DataValue } from "node-opcua-data-value";
8
8
  import { NodeId } from "node-opcua-nodeid";
9
- import { ReadValueIdOptions } from "node-opcua-service-read";
10
- import { BrowsePath, BrowsePathResult, makeBrowsePath } from "node-opcua-service-translate-browse-path";
9
+ import type { ReadValueIdOptions } from "node-opcua-service-read";
10
+ import { type BrowsePath, type BrowsePathResult, makeBrowsePath } from "node-opcua-service-translate-browse-path";
11
11
  import { StatusCodes } from "node-opcua-status-code";
12
12
  import { lowerFirstLetter } from "node-opcua-utils";
13
- import { Variant } from "node-opcua-variant";
13
+ import type { Variant } from "node-opcua-variant";
14
14
 
15
- import { ClientSession } from "../client_session";
15
+ import type { ClientSession } from "../client_session";
16
16
 
17
17
  export interface HistoryServerCapabilities {
18
18
  [key: string]: any;
@@ -28,7 +28,14 @@ export function readHistoryServerCapabilities(
28
28
  callback?: (err: Error | null, capabilities?: HistoryServerCapabilities) => void
29
29
  ): any {
30
30
  if (!callback) {
31
- throw new Error("Internal error");
31
+ return new Promise<HistoryServerCapabilities>((resolve, reject) => {
32
+ readHistoryServerCapabilities(session, (err, capabilities) => {
33
+ if (err) {
34
+ return reject(err);
35
+ }
36
+ resolve(capabilities!);
37
+ });
38
+ });
32
39
  }
33
40
  // display HistoryCapabilities of server
34
41
  const browsePath: BrowsePath = makeBrowsePath(ObjectIds.ObjectsFolder, "/Server/ServerCapabilities.HistoryServerCapabilities");
@@ -55,24 +62,24 @@ export function readHistoryServerCapabilities(
55
62
  const properties = [
56
63
  "AccessHistoryDataCapability",
57
64
  "AccessHistoryEventsCapability",
58
-
65
+
59
66
  "DeleteAtTimeCapability",
60
67
  "DeleteRawCapability",
61
68
  "DeleteEventCapability",
62
-
69
+
63
70
  "InsertAnnotationCapability",
64
71
  "InsertDataCapability",
65
72
  "InsertEventCapability",
66
-
73
+
67
74
  "ReplaceDataCapability",
68
75
  "ReplaceEventCapability",
69
-
76
+
70
77
  "UpdateDataCapability",
71
78
  "UpdateEventCapability",
72
-
79
+
73
80
  "MaxReturnDataValues",
74
81
  "MaxReturnEventValues",
75
-
82
+
76
83
  "AggregateFunctions/AnnotationCount",
77
84
  "AggregateFunctions/Average",
78
85
  "AggregateFunctions/Count",
@@ -95,9 +102,7 @@ export function readHistoryServerCapabilities(
95
102
  }
96
103
 
97
104
  const nodeIds = results.map((innerResult: BrowsePathResult) =>
98
- innerResult.statusCode.isGood() && innerResult.targets
99
- ? innerResult.targets[0].targetId
100
- : new NodeId()
105
+ innerResult.statusCode.isGood() && innerResult.targets ? innerResult.targets[0].targetId : new NodeId()
101
106
  );
102
107
 
103
108
  const nodesToRead: ReadValueIdOptions[] = nodeIds.map((nodeId: NodeId) => ({
@@ -125,10 +130,3 @@ export function readHistoryServerCapabilities(
125
130
  });
126
131
  });
127
132
  }
128
- // tslint:disable:no-var-requires
129
- import { withCallback } from "thenify-ex";
130
- const opts = { multiArgs: false };
131
- (module as any).exports.readHistoryServerCapabilities = withCallback(
132
- (module as any).exports.readHistoryServerCapabilities,
133
- opts
134
- );
@@ -1,6 +1,6 @@
1
- export {
2
- UserIdentityInfoUserName,
3
- UserIdentityInfoX509,
4
- AnonymousIdentity,
5
- UserIdentityInfo
1
+ export {
2
+ AnonymousIdentity,
3
+ UserIdentityInfo,
4
+ UserIdentityInfoUserName,
5
+ UserIdentityInfoX509
6
6
  } from "node-opcua-pseudo-session";