node-opcua-server 2.111.0 → 2.113.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.
@@ -18,7 +18,7 @@ import {
18
18
  coerceTimestampsToReturn,
19
19
  sameStatusCode
20
20
  } from "node-opcua-data-value";
21
- import { checkDebugFlag, make_debugLog, make_warningLog } from "node-opcua-debug";
21
+ import { checkDebugFlag, make_debugLog, make_errorLog, make_warningLog } from "node-opcua-debug";
22
22
  import { ExtensionObject } from "node-opcua-extension-object";
23
23
  import { NodeId } from "node-opcua-nodeid";
24
24
  import { NumericalRange0, NumericRange } from "node-opcua-numeric-range";
@@ -57,6 +57,8 @@ import { validateFilter } from "./validate_filter";
57
57
  import { checkWhereClauseOnAdressSpace as checkWhereClauseOnAddressSpace } from "./filter/check_where_clause_on_address_space";
58
58
  import { SamplingFunc } from "./sampling_func";
59
59
 
60
+ const errorLog = make_errorLog(__filename);
61
+
60
62
  export type QueueItem = MonitoredItemNotification | EventFieldList;
61
63
 
62
64
  const defaultItemToMonitor: ReadValueIdOptions = new ReadValueId({
@@ -163,7 +165,7 @@ function valueHasChanged(
163
165
  rangeVariant.value as PseudoRange
164
166
  );
165
167
  } else {
166
- console.log("EURange is not of type Variable");
168
+ errorLog("EURange is not of type Variable");
167
169
  }
168
170
  return true;
169
171
  }
@@ -262,7 +264,7 @@ function safeGuardVerify(monitoredItem: MonitoredItem) {
262
264
  if ((monitoredItem as any)._$safeGuard) {
263
265
  const verif = s(monitoredItem.oldDataValue|| "");
264
266
  if (verif !== (monitoredItem as any)._$safeGuard) {
265
- console.log(verif, (monitoredItem as any)._$safeGuard);
267
+ errorLog(verif, (monitoredItem as any)._$safeGuard);
266
268
  throw new Error("Internal error: DataValue has been altereed !!!");
267
269
  }
268
270
  }
@@ -443,6 +445,7 @@ export class MonitoredItem extends EventEmitter {
443
445
  this._node = null;
444
446
  this._semantic_version = 0;
445
447
 
448
+ // istanbul ignore next
446
449
  if (doDebug) {
447
450
  debugLog("Monitoring ", options.itemToMonitor.toString());
448
451
  }
@@ -504,6 +507,7 @@ export class MonitoredItem extends EventEmitter {
504
507
  }
505
508
 
506
509
  public dispose(): void {
510
+ // istanbul ignore next
507
511
  if (doDebug) {
508
512
  debugLog("DISPOSING MONITORED ITEM", this._node!.nodeId.toString());
509
513
  }
@@ -595,12 +599,7 @@ export class MonitoredItem extends EventEmitter {
595
599
 
596
600
  const hasSemanticChanged = this.node && (this.node as any).semantic_version !== this._semantic_version;
597
601
 
598
- // xx console.log("`\n----------------------------",skipChangeTest,this.clientHandle,
599
- // this.node.listenerCount("value_changed"),this.node.nodeId.toString());
600
- // xx console.log("events ---- ",this.node.eventNames().join("-"));
601
- // xx console.log("indexRange = ",indexRange ? indexRange.toString() :"");
602
- // xx console.log("this.itemToMonitor.indexRange = ",this.itemToMonitor.indexRange.toString());
603
-
602
+
604
603
  if (!hasSemanticChanged && indexRange && this.itemToMonitor.indexRange) {
605
604
  // we just ignore changes that do not fall within our range
606
605
  // ( unless semantic bit has changed )
@@ -885,7 +884,6 @@ export class MonitoredItem extends EventEmitter {
885
884
 
886
885
  return;
887
886
  }
888
- // xx console.log("xxxx ON SAMPLING");
889
887
  assert(!this._is_sampling, "sampling func shall not be re-entrant !! fix it");
890
888
 
891
889
  // istanbul ignore next
@@ -903,7 +901,7 @@ export class MonitoredItem extends EventEmitter {
903
901
  }
904
902
  // istanbull ignore next
905
903
  if (err) {
906
- console.log(" SAMPLING ERROR =>", err);
904
+ errorLog(" SAMPLING ERROR =>", err);
907
905
  } else {
908
906
  // only record value if source timestamp is newer
909
907
  // xx if (newDataValue && isSourceNewerThan(newDataValue, this.oldDataValue)) {
@@ -1001,10 +999,10 @@ export class MonitoredItem extends EventEmitter {
1001
999
 
1002
1000
  // istanbul ignore next
1003
1001
  if (doDebug) {
1004
- console.log(" RECEIVED INTERNAL EVENT THAT WE ARE MONITORING");
1005
- console.log(this.filter ? this.filter.toString() : "no filter");
1002
+ debugLog(" RECEIVED INTERNAL EVENT THAT WE ARE MONITORING");
1003
+ debugLog(this.filter ? this.filter.toString() : "no filter");
1006
1004
  eventFields.forEach((e: any) => {
1007
- console.log(e.toString());
1005
+ debugLog(e.toString());
1008
1006
  });
1009
1007
  }
1010
1008
 
@@ -1173,11 +1171,10 @@ export class MonitoredItem extends EventEmitter {
1173
1171
  assert(sameStatusCode(notification.value.statusCode, StatusCodes.GoodWithOverflowBit));
1174
1172
  assert(notification.value.statusCode.hasOverflowBit);
1175
1173
  }
1176
- // console.log(chalk.cyan("Setting Over"), !!this.$subscription, !!this.$subscription!.subscriptionDiagnostics);
1177
1174
  if (this.$subscription && this.$subscription.subscriptionDiagnostics) {
1178
1175
  this.$subscription.subscriptionDiagnostics.monitoringQueueOverflowCount++;
1179
1176
  }
1180
- // to do eventQueueOverFlowCount
1177
+ // to do: eventQueueOverFlowCount
1181
1178
  }
1182
1179
 
1183
1180
  private _enqueue_notification(notification: QueueItem) {
@@ -1313,6 +1310,7 @@ export class MonitoredItem extends EventEmitter {
1313
1310
  }
1314
1311
 
1315
1312
  private _enqueue_event(eventFields: any[]) {
1313
+ // istanbul ignore next
1316
1314
  if (doDebug) {
1317
1315
  debugLog(" MonitoredItem#_enqueue_event");
1318
1316
  }
@@ -1355,7 +1353,6 @@ export class MonitoredItem extends EventEmitter {
1355
1353
  this._on_sampling_timer();
1356
1354
  }, this.samplingInterval);
1357
1355
  }
1358
- // xx console.log("MonitoredItem#_set_timer",this._samplingId);
1359
1356
  }
1360
1357
 
1361
1358
  private _adjust_queue_to_match_new_queue_size() {
@@ -55,6 +55,7 @@ export function appendToTimer(monitoredItem: MonitoredItem): string {
55
55
  counter++;
56
56
  }
57
57
  }
58
+ // istanbul ignore next
58
59
  if (doDebug) {
59
60
  const elapsed = hrtime(start);
60
61
  debugLog(
@@ -636,10 +636,18 @@ function validate_security_endpoint(
636
636
  // The Server uses this information for diagnostics and to determine the set of
637
637
  // EndpointDescriptions to return in the response.
638
638
  // ToDo: check endpointUrl validity and emit an AuditUrlMismatchEventType event if not
639
+
640
+ // sometime endpoints have a extra leading "/" that can be ignored
641
+ // don't be too harsh.
642
+ if (endpoints.length === 0 && request.endpointUrl?.endsWith("/")) {
643
+ endpoints = server._get_endpoints(request.endpointUrl.slice(0, -1));
644
+ }
645
+
639
646
  if (endpoints.length === 0) {
640
647
  // we have a UrlMismatch here
641
648
  const ua_server = server.engine.addressSpace!.rootFolder.objects.server;
642
- errorLog("Cannot find suitable endpoints in available endpoints. endpointUri =", request.endpointUrl);
649
+ warningLog("Cannot find suitable endpoints in available endpoints. endpointUri =", request.endpointUrl);
650
+ // e
643
651
  ua_server.raiseEvent("AuditUrlMismatchEventType", {
644
652
  endpointUrl: { dataType: DataType.String, value: request.endpointUrl }
645
653
  });
@@ -899,6 +907,7 @@ export interface OPCUAServerOptions extends OPCUABaseServerOptions, OPCUAServerE
899
907
  onDeleteMonitoredItem?: DeleteMonitoredItemHook;
900
908
  }
901
909
 
910
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
902
911
  export interface OPCUAServer {
903
912
  /**
904
913
  *
@@ -2659,7 +2668,6 @@ export class OPCUAServer extends OPCUABaseServer {
2659
2668
 
2660
2669
  // ask for a refresh of asynchronous variables
2661
2670
  this.engine.refreshValues(request.nodesToRead, request.maxAge, (err?: Error | null) => {
2662
-
2663
2671
  this.engine.read(context, request).then((results) => {
2664
2672
  assert(results[0].schema.name === "DataValue");
2665
2673
  assert(results.length === request.nodesToRead!.length);
@@ -3797,6 +3805,7 @@ export interface OPCUAServer {
3797
3805
  raiseEvent(eventType: "AuditCertificateMismatchEventType", options: RaiseAuditCertificateMismatchEventData): void;
3798
3806
  }
3799
3807
 
3808
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
3800
3809
  export interface OPCUAServer extends EventEmitter {
3801
3810
  on(event: "create_session", eventHandler: (session: ServerSession) => void): this;
3802
3811
 
@@ -1552,7 +1552,7 @@ export class ServerEngine extends EventEmitter implements IAddressSpaceAccessor
1552
1552
 
1553
1553
  // now check that new session has sufficient right
1554
1554
  // if (session.authenticationToken.toString() !== subscription.authenticationToken.toString()) {
1555
- // console.log("ServerEngine#transferSubscription => BadUserAccessDenied");
1555
+ // warningLog("ServerEngine#transferSubscription => BadUserAccessDenied");
1556
1556
  // return new TransferResult({ statusCode: StatusCodes.BadUserAccessDenied });
1557
1557
  // }
1558
1558
  if ((session.publishEngine as any) === subscription.publishEngine) {
@@ -1717,7 +1717,7 @@ export class ServerEngine extends EventEmitter implements IAddressSpaceAccessor
1717
1717
  addElement(subscriptionDiagnostics, subscriptionDiagnosticsArray);
1718
1718
  }
1719
1719
  } catch (err) {
1720
- console.log("err", err);
1720
+ errorLog("_exposeSubscriptionDiagnostics err", err);
1721
1721
  }
1722
1722
  }
1723
1723
 
@@ -651,6 +651,7 @@ export class ServerSidePublishEngine extends EventEmitter implements IServerSide
651
651
 
652
652
  const invalid_published_request = parts[0];
653
653
  for (const publishData of invalid_published_request) {
654
+ // istanbul ignore next
654
655
  if (doDebug) {
655
656
  debugLog(chalk.cyan(" CANCELING TIMEOUT PUBLISH REQUEST "));
656
657
  }
@@ -662,6 +663,7 @@ export class ServerSidePublishEngine extends EventEmitter implements IServerSide
662
663
  publishData.callback(publishData.request, response);
663
664
  }
664
665
  public _send_valid_response_for_request(publishData: PublishData, response: PublishResponse): void {
666
+ // istanbul ignore next
665
667
  if (doDebug) {
666
668
  debugLog("_send_response_for_request ", response.toString());
667
669
  }
@@ -901,6 +901,7 @@ export class ServerSession extends EventEmitter implements ISubscriber, ISession
901
901
  */
902
902
  private _getSubscriptionDiagnosticsArray() {
903
903
  if (!this.addressSpace) {
904
+ // istanbul ignore next
904
905
  if (doDebug) {
905
906
  console.warn("ServerSession#_getSubscriptionDiagnosticsArray : no addressSpace");
906
907
  }
@@ -853,6 +853,7 @@ export class Subscription extends EventEmitter {
853
853
  };
854
854
  }
855
855
  public dispose(): void {
856
+ // istanbul ignore next
856
857
  if (doDebug) {
857
858
  debugLog("Subscription#dispose", this.id, this.monitoredItemCount);
858
859
  }
@@ -1201,11 +1202,13 @@ export class Subscription extends EventEmitter {
1201
1202
  });
1202
1203
 
1203
1204
  if (foundIndex === -1) {
1205
+ // istanbul ignore next
1204
1206
  if (doDebug) {
1205
1207
  debugLog(chalk.red("acknowledging sequence FAILED !!! "), chalk.cyan(sequenceNumber.toString()));
1206
1208
  }
1207
1209
  return StatusCodes.BadSequenceNumberUnknown;
1208
1210
  } else {
1211
+ // istanbul ignore next
1209
1212
  if (doDebug) {
1210
1213
  debugLog(chalk.yellow("acknowledging sequence "), chalk.cyan(sequenceNumber.toString()));
1211
1214
  }
@@ -1377,6 +1380,8 @@ export class Subscription extends EventEmitter {
1377
1380
 
1378
1381
  this.resetLifeTimeAndKeepAliveCounters();
1379
1382
 
1383
+
1384
+ // istanbul ignore next
1380
1385
  if (doDebug) {
1381
1386
  debugLog(
1382
1387
  "Subscription sending a notificationMessage subscriptionId=",
@@ -13,6 +13,9 @@ import { DeadbandType } from "node-opcua-service-subscription";
13
13
  import { StatusCode, StatusCodes } from "node-opcua-status-code";
14
14
  import { ReadValueIdOptions } from "node-opcua-types";
15
15
  import { DataType } from "node-opcua-basic-types";
16
+ import { make_warningLog } from "node-opcua-debug";
17
+
18
+ const warningLog = make_warningLog(__filename);
16
19
 
17
20
  function isNumberDataType(node: UAVariable): boolean {
18
21
 
@@ -60,8 +63,7 @@ function __validateDataChangeFilter(filter: DataChangeFilter, itemToMonitor: Rea
60
63
 
61
64
  // node must also have a valid euRange
62
65
  if (!node.getChildByName("EURange", 0)) {
63
- // tslint:disable:no-console
64
- console.log(" node has no euRange ! Dead band Percent cannot be used on node " + node.nodeId.toString());
66
+ warningLog(" node has no euRange ! Dead band Percent cannot be used on node " + node.nodeId.toString());
65
67
  return StatusCodes.BadMonitoredItemFilterUnsupported;
66
68
  }
67
69
  }