node-opcua-address-space 2.68.0 → 2.69.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.
@@ -13,7 +13,7 @@ import {
13
13
  NodeClass,
14
14
  ResultMask
15
15
  } from "node-opcua-data-model";
16
- import { make_warningLog } from "node-opcua-debug";
16
+ import { checkDebugFlag, make_warningLog } from "node-opcua-debug";
17
17
  import { NodeId, resolveNodeId, sameNodeId } from "node-opcua-nodeid";
18
18
  import { ReferenceDescription } from "node-opcua-types";
19
19
  import {
@@ -42,7 +42,7 @@ import { BaseNodeImpl, getReferenceType } from "./base_node_impl";
42
42
  import { AddressSpacePrivate } from "./address_space_private";
43
43
 
44
44
  // eslint-disable-next-line prefer-const
45
- let dotrace = false;
45
+ let doTrace = checkDebugFlag("INSTANTIATE");
46
46
  const traceLog = console.log.bind(console);
47
47
 
48
48
  const g_weakMap = new WeakMap();
@@ -484,7 +484,7 @@ function _clone_collection_new(
484
484
  }
485
485
 
486
486
  if (optionalFilter && node && !optionalFilter.shouldKeep(node)) {
487
- dotrace && traceLog(extraInfo.pad(), "skipping ", node.browseName.toString());
487
+ doTrace && traceLog(extraInfo.pad(), "skipping optional ", node.browseName.toString(), "that doesn't appear in the filter");
488
488
  continue; // skip this node
489
489
  }
490
490
  const key = node.browseName.toString();
@@ -501,7 +501,7 @@ function _clone_collection_new(
501
501
  copyAlsoModellingRules
502
502
  };
503
503
 
504
- dotrace &&
504
+ doTrace &&
505
505
  traceLog(
506
506
  extraInfo.pad(),
507
507
  "cloning => ",
@@ -554,7 +554,7 @@ function _extractInterfaces2(typeDefinitionNode: UAObjectType | UAVariableType,
554
554
 
555
555
  const baseInterfaces: UAInterface[] = [];
556
556
  for (const iface of interfaces) {
557
- dotrace &&
557
+ doTrace &&
558
558
  traceLog(
559
559
  extraInfo.pad(),
560
560
  typeDefinitionNode.browseName.toString(),
@@ -570,7 +570,7 @@ function _extractInterfaces2(typeDefinitionNode: UAObjectType | UAVariableType,
570
570
  }
571
571
  interfaces.push(...baseInterfaces);
572
572
  if (typeDefinitionNode.subtypeOfObj) {
573
- dotrace &&
573
+ doTrace &&
574
574
  traceLog(
575
575
  extraInfo.pad(),
576
576
  typeDefinitionNode.browseName.toString(),
@@ -583,7 +583,7 @@ function _extractInterfaces2(typeDefinitionNode: UAObjectType | UAVariableType,
583
583
  }
584
584
  const dedupedInterfaces = [...new Set(interfaces)];
585
585
 
586
- dotrace &&
586
+ doTrace &&
587
587
  traceLog(
588
588
  extraInfo.pad(),
589
589
  chalk.yellow("Interface for ", typeDefinitionNode.browseName.toString()),
@@ -635,7 +635,7 @@ function _crap_extractInterfaces(typeDefinitionNode: UAObjectType | UAVariableTy
635
635
  const interfacesRef = typeDefinitionNode.findReferencesEx("HasInterface", BrowseDirection.Forward);
636
636
  const interfaces = interfacesRef.map((r) => r.node! as UAInterface);
637
637
  for (const iface of interfaces) {
638
- dotrace && traceLog(extraInfo.pad(), " interface ", iface.browseName.toString());
638
+ doTrace && traceLog(extraInfo.pad(), " interface ", iface.browseName.toString());
639
639
  }
640
640
 
641
641
  return interfaces;
@@ -648,7 +648,7 @@ function _cloneInterface(
648
648
  extraInfo: CloneExtraInfo,
649
649
  browseNameMap: Set<string>
650
650
  ): void {
651
- dotrace &&
651
+ doTrace &&
652
652
  traceLog(
653
653
  extraInfo?.pad(),
654
654
  chalk.green("-------------------- now cloning interfaces of ", node.browseName.toString(), node.nodeId.toString())
@@ -660,23 +660,30 @@ function _cloneInterface(
660
660
  if (!typeDefinitionNode) {
661
661
  return;
662
662
  }
663
- dotrace && traceLog(extraInfo.pad(), " --- {");
664
663
  const interfaces = _extractInterfaces2(typeDefinitionNode, extraInfo);
665
- dotrace && traceLog(extraInfo.pad(), " --- }");
666
- dotrace && traceLog(extraInfo?.pad(), chalk.green("-------------------- interfaces are ", interfaces.length));
664
+ if (interfaces.length === 0) {
665
+ if (doTrace) {
666
+ traceLog(
667
+ extraInfo.pad(),
668
+ chalk.yellow("No interface for ", node.browseName.toString(), node.nodeId.toString())
669
+ );
670
+ }
671
+ return;
672
+ }
673
+ doTrace && traceLog(extraInfo?.pad(), chalk.green("-------------------- interfaces are ", interfaces.length));
667
674
 
668
675
  const localFilter = optionalFilter.filterFor(node);
669
676
 
670
677
  for (const iface of interfaces) {
671
678
  const aggregates = iface.findReferencesEx("Aggregates", BrowseDirection.Forward);
672
- dotrace &&
679
+ doTrace &&
673
680
  traceLog(
674
681
  extraInfo.pad(),
675
682
  chalk.magentaBright(" interface ", iface.browseName.toString()),
676
683
  "\n" + extraInfo?.pad(),
677
684
  aggregates.map((r) => r.toString({ addressSpace })).join("\n" + extraInfo?.pad())
678
685
  );
679
- _clone_collection_new(newParent, aggregates, false, localFilter, extraInfo, browseNameMap);
686
+ _clone_collection_new(node, aggregates, false, localFilter, extraInfo, browseNameMap);
680
687
  }
681
688
  }
682
689
  export function _clone_children_references(
@@ -775,36 +782,37 @@ export function _clone<T extends UAObject | UAVariable | UAMethod>(
775
782
  const cloneObj = new Constructor(constructorOptions);
776
783
  (this.addressSpace as AddressSpacePrivate)._register(cloneObj);
777
784
 
778
- options.copyAlsoModellingRules = options.copyAlsoModellingRules || false;
785
+ if (!options.ignoreChildren) {
786
+ // clone children and the rest ....
787
+ options.copyAlsoModellingRules = options.copyAlsoModellingRules || false;
779
788
 
780
- const newFilter = optionalFilter.filterFor(cloneObj);
789
+ const newFilter = optionalFilter.filterFor(cloneObj);
781
790
 
782
- const browseNameMap = new Set<string>();
783
- _clone_children_references(this, cloneObj, options.copyAlsoModellingRules, newFilter!, extraInfo, browseNameMap);
791
+ const browseNameMap = new Set<string>();
792
+ _clone_children_references(this, cloneObj, options.copyAlsoModellingRules, newFilter!, extraInfo, browseNameMap);
784
793
 
785
- //
786
- let typeDefinitionNode: UAVariableType | UAObjectType | null = this.typeDefinitionObj;
787
- while (typeDefinitionNode) {
788
- dotrace &&
789
- traceLog(
790
- extraInfo?.pad(),
791
- chalk.blueBright("---------------------- Exploring ", typeDefinitionNode.browseName.toString())
794
+ //
795
+ let typeDefinitionNode: UAVariableType | UAObjectType | null = this.typeDefinitionObj;
796
+ while (typeDefinitionNode) {
797
+ doTrace &&
798
+ traceLog(
799
+ extraInfo?.pad(),
800
+ chalk.blueBright("---------------------- Exploring ", typeDefinitionNode.browseName.toString())
801
+ );
802
+ _clone_children_references(
803
+ typeDefinitionNode,
804
+ cloneObj,
805
+ options.copyAlsoModellingRules,
806
+ newFilter,
807
+ extraInfo,
808
+ browseNameMap
792
809
  );
793
- _clone_children_references(
794
- typeDefinitionNode,
795
- cloneObj,
796
- options.copyAlsoModellingRules,
797
- newFilter,
798
- extraInfo,
799
- browseNameMap
800
- );
801
- typeDefinitionNode = typeDefinitionNode.subtypeOfObj;
802
- }
803
-
804
- _clone_non_hierarchical_references(this, cloneObj, options.copyAlsoModellingRules, newFilter, extraInfo, browseNameMap);
810
+ typeDefinitionNode = typeDefinitionNode.subtypeOfObj;
811
+ }
805
812
 
813
+ _clone_non_hierarchical_references(this, cloneObj, options.copyAlsoModellingRules, newFilter, extraInfo, browseNameMap);
814
+ }
806
815
  cloneObj.propagate_back_references();
807
-
808
816
  cloneObj.install_extra_properties();
809
817
 
810
818
  return cloneObj;
@@ -243,11 +243,14 @@ function _dumpVariantInnerExtensionObject(
243
243
  const lowerFieldName = utils.lowerFirstLetter(fieldName);
244
244
  const v = (value as unknown as Record<string, unknown>)[lowerFieldName];
245
245
  if (v !== null && v !== undefined) {
246
-
247
- if (dataTypeNodeId.namespace === 0 && dataTypeNodeId.value ===0 && dataTypeNodeId.identifierType === NodeIdType.NUMERIC) {
246
+ if (
247
+ dataTypeNodeId.namespace === 0 &&
248
+ dataTypeNodeId.value === 0 &&
249
+ dataTypeNodeId.identifierType === NodeIdType.NUMERIC
250
+ ) {
248
251
  // to do ?? shall we do a extension Object here ?
249
252
  continue; // ns=0;i=0 is reserved
250
- }
253
+ }
251
254
  const { name, definition } = definitionMap.findDefinition(dataTypeNodeId);
252
255
  xw.startElement(fieldName);
253
256
 
@@ -324,7 +327,9 @@ function _dumpVariantInnerValue(
324
327
  xw.text(value[1].toString());
325
328
  break;
326
329
  case DataType.Boolean:
330
+ case DataType.SByte:
327
331
  case DataType.Byte:
332
+ case DataType.SByte:
328
333
  case DataType.Float:
329
334
  case DataType.Double:
330
335
  case DataType.Int16:
@@ -628,7 +633,10 @@ function dumpReferencedNodes(xw: XmlWriter, node: BaseNode, forward: boolean) {
628
633
  const typeDefinitionObj = ReferenceImpl.resolveReferenceNode(addressSpace, r[0])! as BaseNode;
629
634
  if (!typeDefinitionObj) {
630
635
  warningLog(node.toString());
631
- warningLog("dumpReferencedNodes: Warning : " + node.browseName.toString() + " unknown typeDefinition, ", r[0].toString());
636
+ warningLog(
637
+ "dumpReferencedNodes: Warning : " + node.browseName.toString() + " unknown typeDefinition, ",
638
+ r[0].toString()
639
+ );
632
640
  } else {
633
641
  assert(typeDefinitionObj instanceof BaseNodeImpl);
634
642
  if (typeDefinitionObj.nodeId.namespace === node.nodeId.namespace) {
@@ -89,7 +89,15 @@ import { BaseNodeImpl, InternalBaseNodeOptions } from "./base_node_impl";
89
89
  import { _clone, ToStringBuilder, UAVariable_toString, valueRankToString } from "./base_node_private";
90
90
  import { EnumerationInfo, IEnumItem, UADataTypeImpl } from "./ua_data_type_impl";
91
91
  import { apply_condition_refresh, ConditionRefreshCache } from "./apply_condition_refresh";
92
- import { extractPartialData, propagateTouchValueUpward, setExtensionObjectValue, _bindExtensionObject, _installExtensionObjectBindingOnProperties, _setExtensionObject, _touchValue } from "./ua_variable_impl_ext_obj";
92
+ import {
93
+ extractPartialData,
94
+ propagateTouchValueUpward,
95
+ setExtensionObjectValue,
96
+ _bindExtensionObject,
97
+ _installExtensionObjectBindingOnProperties,
98
+ _setExtensionObject,
99
+ _touchValue
100
+ } from "./ua_variable_impl_ext_obj";
93
101
 
94
102
  const debugLog = make_debugLog(__filename);
95
103
  const warningLog = make_warningLog(__filename);
@@ -774,7 +782,6 @@ export class UAVariableImpl extends BaseNodeImpl implements UAVariable {
774
782
  } else {
775
783
  this._internal_set_dataValue(dataValue);
776
784
  }
777
-
778
785
  } catch (err) {
779
786
  errorLog("UAVariable#setValueFromString Error : ", this.browseName.toString(), this.nodeId.toString());
780
787
  errorLog((err as Error).message);
@@ -1167,7 +1174,7 @@ export class UAVariableImpl extends BaseNodeImpl implements UAVariable {
1167
1174
  if (!context) {
1168
1175
  context = SessionContext.defaultContext;
1169
1176
  }
1170
- assert(typeof callback === 'function');
1177
+ assert(typeof callback === "function");
1171
1178
 
1172
1179
  this.__waiting_callbacks = this.__waiting_callbacks || [];
1173
1180
  this.__waiting_callbacks.push(callback);
@@ -1324,8 +1331,8 @@ export class UAVariableImpl extends BaseNodeImpl implements UAVariable {
1324
1331
 
1325
1332
  /**
1326
1333
  * @private
1327
- * install UAVariable to exposed th
1328
- *
1334
+ * install UAVariable to exposed th
1335
+ *
1329
1336
  * precondition:
1330
1337
  */
1331
1338
  public installExtensionObjectVariables(): void {
@@ -1347,10 +1354,9 @@ export class UAVariableImpl extends BaseNodeImpl implements UAVariable {
1347
1354
  optionalExtensionObject?: ExtensionObject,
1348
1355
  options?: BindExtensionObjectOptions
1349
1356
  ): ExtensionObject | null {
1350
- return _bindExtensionObject(this, optionalExtensionObject, options);
1357
+ return _bindExtensionObject(this, optionalExtensionObject, options);
1351
1358
  }
1352
1359
 
1353
-
1354
1360
  public updateExtensionObjectPartial(partialExtensionObject?: { [key: string]: any }): ExtensionObject {
1355
1361
  setExtensionObjectValue(this, partialExtensionObject);
1356
1362
  return this.$extensionObject;
@@ -1412,7 +1418,7 @@ export class UAVariableImpl extends BaseNodeImpl implements UAVariable {
1412
1418
  callback?: CallbackT<HistoryReadResult>
1413
1419
  ): any {
1414
1420
  assert(context instanceof SessionContext);
1415
- assert(typeof callback === 'function');
1421
+ assert(typeof callback === "function");
1416
1422
  if (typeof this._historyRead !== "function") {
1417
1423
  return callback!(null, new HistoryReadResult({ statusCode: StatusCodes.BadNotReadable }));
1418
1424
  }
@@ -1505,7 +1511,6 @@ export class UAVariableImpl extends BaseNodeImpl implements UAVariable {
1505
1511
  this.$dataValue.value = value;
1506
1512
  }
1507
1513
 
1508
-
1509
1514
  public _internal_set_dataValue(dataValue: DataValue, indexRange?: NumericRange | null): void {
1510
1515
  assert(dataValue, "expecting a dataValue");
1511
1516
  assert(dataValue instanceof DataValue, "expecting dataValue to be a DataValue");
@@ -1686,7 +1691,6 @@ export interface UAVariableImpl {
1686
1691
  $$indexPropertyName: any;
1687
1692
  }
1688
1693
 
1689
-
1690
1694
  function check_valid_array(dataType: DataType, array: any): boolean {
1691
1695
  if (Array.isArray(array)) {
1692
1696
  return true;
@@ -21,7 +21,7 @@ import {
21
21
  UAVariableType,
22
22
  CloneFilter
23
23
  } from "node-opcua-address-space-base";
24
- import { ObjectTypeIds, ReferenceTypeIds, VariableTypeIds } from "node-opcua-constants";
24
+ import { ReferenceTypeIds } from "node-opcua-constants";
25
25
  import { coerceQualifiedName, NodeClass, QualifiedName, BrowseDirection, AttributeIds } from "node-opcua-data-model";
26
26
  import { DataValue, DataValueLike } from "node-opcua-data-value";
27
27
  import { checkDebugFlag, make_debugLog, make_warningLog, make_errorLog } from "node-opcua-debug";
@@ -40,7 +40,6 @@ import { _clone_children_references, ToStringBuilder, UAVariableType_toString }
40
40
  import * as tools from "./tool_isSupertypeOf";
41
41
  import { get_subtypeOfObj } from "./tool_isSupertypeOf";
42
42
  import { get_subtypeOf } from "./tool_isSupertypeOf";
43
- import { resolveReferenceNode } from "./reference_impl";
44
43
 
45
44
  const debugLog = make_debugLog(__filename);
46
45
  const doDebug = checkDebugFlag(__filename);
@@ -48,7 +47,7 @@ const warningLog = make_warningLog(__filename);
48
47
  const errorLog = make_errorLog(__filename);
49
48
 
50
49
  // eslint-disable-next-line prefer-const
51
- let doTrace = false;
50
+ let doTrace = checkDebugFlag("INSTANTIATE");
52
51
  const traceLog = errorLog;
53
52
 
54
53
  interface InstantiateS {