node-opcua-address-space 2.112.0 → 2.114.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 (113) hide show
  1. package/dist/source/helpers/call_helpers.js +1 -2
  2. package/dist/source/helpers/call_helpers.js.map +1 -1
  3. package/dist/source/helpers/resolve_opaque_on_address_space.js +15 -26
  4. package/dist/source/helpers/resolve_opaque_on_address_space.js.map +1 -1
  5. package/dist/source/loader/decode_xml_extension_object.js +0 -2
  6. package/dist/source/loader/decode_xml_extension_object.js.map +1 -1
  7. package/dist/source/loader/ensure_datatype_extracted.js +19 -30
  8. package/dist/source/loader/ensure_datatype_extracted.js.map +1 -1
  9. package/dist/source/loader/generateAddressSpaceRaw.js +16 -27
  10. package/dist/source/loader/generateAddressSpaceRaw.js.map +1 -1
  11. package/dist/source/loader/load_nodeset2.js +101 -98
  12. package/dist/source/loader/load_nodeset2.js.map +1 -1
  13. package/dist/source/loader/make_xml_extension_object_parser.js +2 -4
  14. package/dist/source/loader/make_xml_extension_object_parser.js.map +1 -1
  15. package/dist/source/loader/namespace_post_step.js +24 -37
  16. package/dist/source/loader/namespace_post_step.js.map +1 -1
  17. package/dist/source/session_context.js +3 -6
  18. package/dist/source/session_context.js.map +1 -1
  19. package/dist/source/set_namespace_meta_data.js +2 -3
  20. package/dist/source/set_namespace_meta_data.js.map +1 -1
  21. package/dist/src/address_space.js +18 -37
  22. package/dist/src/address_space.js.map +1 -1
  23. package/dist/src/address_space_change_event_tools.js +1 -1
  24. package/dist/src/address_space_change_event_tools.js.map +1 -1
  25. package/dist/src/alarms_and_conditions/condition_snapshot_impl.js +2 -5
  26. package/dist/src/alarms_and_conditions/condition_snapshot_impl.js.map +1 -1
  27. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js +7 -4
  28. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js.map +1 -1
  29. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js +6 -7
  30. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js.map +1 -1
  31. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.js +2 -5
  32. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.js.map +1 -1
  33. package/dist/src/alarms_and_conditions/ua_condition_impl.js +3 -7
  34. package/dist/src/alarms_and_conditions/ua_condition_impl.js.map +1 -1
  35. package/dist/src/base_node_impl.js +9 -19
  36. package/dist/src/base_node_impl.js.map +1 -1
  37. package/dist/src/base_node_private.js +17 -11
  38. package/dist/src/base_node_private.js.map +1 -1
  39. package/dist/src/data_access/ua_multistate_discrete_impl.js +7 -1
  40. package/dist/src/data_access/ua_multistate_discrete_impl.js.map +1 -1
  41. package/dist/src/data_access/ua_multistate_value_discrete_impl.d.ts +2 -2
  42. package/dist/src/data_access/ua_multistate_value_discrete_impl.js +10 -5
  43. package/dist/src/data_access/ua_multistate_value_discrete_impl.js.map +1 -1
  44. package/dist/src/extension_object_array_node.js +1 -2
  45. package/dist/src/extension_object_array_node.js.map +1 -1
  46. package/dist/src/get_basic_datatype.d.ts +8 -0
  47. package/dist/src/get_basic_datatype.js +26 -0
  48. package/dist/src/get_basic_datatype.js.map +1 -0
  49. package/dist/src/historical_access/address_space_historical_data_node.js +31 -48
  50. package/dist/src/historical_access/address_space_historical_data_node.js.map +1 -1
  51. package/dist/src/namespace_impl.js +17 -13
  52. package/dist/src/namespace_impl.js.map +1 -1
  53. package/dist/src/nodeset_tools/construct_namespace_dependency.js +58 -9
  54. package/dist/src/nodeset_tools/construct_namespace_dependency.js.map +1 -1
  55. package/dist/src/nodeset_tools/dump_to_bsd.js +4 -6
  56. package/dist/src/nodeset_tools/dump_to_bsd.js.map +1 -1
  57. package/dist/src/nodeset_tools/nodeset_to_xml.js +36 -35
  58. package/dist/src/nodeset_tools/nodeset_to_xml.js.map +1 -1
  59. package/dist/src/private_namespace.js +1 -1
  60. package/dist/src/private_namespace.js.map +1 -1
  61. package/dist/src/reference_impl.js +5 -2
  62. package/dist/src/reference_impl.js.map +1 -1
  63. package/dist/src/state_machine/finite_state_machine.js +2 -3
  64. package/dist/src/state_machine/finite_state_machine.js.map +1 -1
  65. package/dist/src/state_machine/ua_shelving_state_machine_ex.js +2 -2
  66. package/dist/src/state_machine/ua_shelving_state_machine_ex.js.map +1 -1
  67. package/dist/src/state_machine/ua_two_state_variable.js +1 -3
  68. package/dist/src/state_machine/ua_two_state_variable.js.map +1 -1
  69. package/dist/src/ua_data_type_impl.js +6 -29
  70. package/dist/src/ua_data_type_impl.js.map +1 -1
  71. package/dist/src/ua_method_impl.js +6 -4
  72. package/dist/src/ua_method_impl.js.map +1 -1
  73. package/dist/src/ua_object_impl.js +5 -1
  74. package/dist/src/ua_object_impl.js.map +1 -1
  75. package/dist/src/ua_object_type_impl.js +1 -2
  76. package/dist/src/ua_object_type_impl.js.map +1 -1
  77. package/dist/src/ua_variable_impl.js +18 -26
  78. package/dist/src/ua_variable_impl.js.map +1 -1
  79. package/dist/src/ua_variable_impl_ext_obj.js +25 -17
  80. package/dist/src/ua_variable_impl_ext_obj.js.map +1 -1
  81. package/dist/src/ua_variable_type_impl.d.ts +2 -0
  82. package/dist/src/ua_variable_type_impl.js +7 -6
  83. package/dist/src/ua_variable_type_impl.js.map +1 -1
  84. package/dist/tsconfig_common.tsbuildinfo +1 -1
  85. package/distHelpers/add_event_generator_object.js +0 -4
  86. package/distHelpers/add_event_generator_object.js.map +1 -1
  87. package/distNodeJS/generate_address_space.js +10 -21
  88. package/distNodeJS/generate_address_space.js.map +1 -1
  89. package/package.json +39 -39
  90. package/source/loader/decode_xml_extension_object.ts +0 -2
  91. package/source/loader/load_nodeset2.ts +16 -12
  92. package/source/loader/make_xml_extension_object_parser.ts +1 -4
  93. package/source/loader/namespace_post_step.ts +1 -0
  94. package/src/address_space.ts +7 -15
  95. package/src/alarms_and_conditions/condition_snapshot_impl.ts +2 -6
  96. package/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.ts +6 -3
  97. package/src/alarms_and_conditions/ua_alarm_condition_impl.ts +6 -6
  98. package/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.ts +0 -1
  99. package/src/alarms_and_conditions/ua_condition_impl.ts +3 -7
  100. package/src/base_node_impl.ts +12 -20
  101. package/src/data_access/ua_multistate_value_discrete_impl.ts +9 -11
  102. package/src/get_basic_datatype.ts +32 -0
  103. package/src/namespace_impl.ts +5 -6
  104. package/src/nodeset_tools/construct_namespace_dependency.ts +60 -18
  105. package/src/nodeset_tools/nodeset_to_xml.ts +42 -39
  106. package/src/reference_impl.ts +5 -1
  107. package/src/state_machine/finite_state_machine.ts +3 -4
  108. package/src/state_machine/ua_shelving_state_machine_ex.ts +2 -3
  109. package/src/state_machine/ua_two_state_variable.ts +0 -1
  110. package/src/ua_data_type_impl.ts +6 -26
  111. package/src/ua_variable_impl.ts +5 -22
  112. package/src/ua_variable_impl_ext_obj.ts +119 -86
  113. package/src/ua_variable_type_impl.ts +5 -4
@@ -143,7 +143,6 @@ export class UAConditionImpl extends UABaseEventImpl implements UAConditionEx {
143
143
  ): void {
144
144
  const conditionNode = context.object;
145
145
 
146
- // xx console.log(inputArguments.map(function(a){return a.toString()}));
147
146
  if (!(conditionNode instanceof UAConditionImpl)) {
148
147
  callback(null, {
149
148
  statusCode: StatusCodes.BadNodeIdInvalid
@@ -426,7 +425,6 @@ export class UAConditionImpl extends UABaseEventImpl implements UAConditionEx {
426
425
  branch.renewEventId();
427
426
  }
428
427
 
429
- // xx console.log("MMMMMMMM%%%%%%%%%%%%%%%%%%%%% branch " +
430
428
  // branch.getBranchId().toString() + " eventId = " + branch.getEventId().toString("hex"));
431
429
 
432
430
  assert(branch instanceof ConditionSnapshotImpl);
@@ -462,7 +460,6 @@ export class UAConditionImpl extends UABaseEventImpl implements UAConditionEx {
462
460
  "therefore event cannot bubble-up to the server object"
463
461
  );
464
462
  }
465
- // xx console.log("MMMMMMMM%%%%%%%%%%%%%%%%%%%%% branch " +
466
463
  // branch.getBranchId().toString() + " eventId = " + branch.getEventId().toString("hex"));
467
464
  }
468
465
 
@@ -536,7 +533,6 @@ export class UAConditionImpl extends UABaseEventImpl implements UAConditionEx {
536
533
  this.raiseConditionEvent(branch, true);
537
534
 
538
535
  if (!sameNodeId(branch.getBranchId(), NodeId.nullNodeId) && !branch.getRetain()) {
539
- // xx console.log(" Deleting not longer needed branch ", branch.getBranchId().toString());
540
536
  // branch can be deleted
541
537
  this.deleteBranch(branch);
542
538
  }
@@ -854,8 +850,7 @@ function UACondition_instantiate(
854
850
  if (options.conditionSource) {
855
851
  options.conditionSource = addressSpace._coerceNode(options.conditionSource)!;
856
852
  if (options.conditionSource.nodeClass !== NodeClass.Object && options.conditionSource.nodeClass !== NodeClass.Variable) {
857
- // tslint:disable:no-console
858
- console.log(options.conditionSource);
853
+ debugLog(options.conditionSource);
859
854
  throw new Error("Expecting condition source to be NodeClass.Object or Variable");
860
855
  }
861
856
 
@@ -1013,7 +1008,7 @@ function _disable_method(inputArguments: VariantLike[], context: ISessionContext
1013
1008
 
1014
1009
  // istanbul ignore next
1015
1010
  if (!(conditionNode instanceof UAConditionImpl)) {
1016
- console.log("conditionNode is not a UACondition ", conditionNode?.toString());
1011
+ debugLog("conditionNode is not a UACondition ", conditionNode?.toString());
1017
1012
  return callback(null, {
1018
1013
  statusCode: StatusCodes.BadNodeIdInvalid
1019
1014
  });
@@ -1048,6 +1043,7 @@ function _condition_refresh_method(
1048
1043
  // arguments : IntegerId SubscriptionId
1049
1044
  assert(inputArguments.length === 1);
1050
1045
  const addressSpace = context.object!.addressSpace as AddressSpacePrivate;
1046
+ // istanbul ignore next
1051
1047
  if (doDebug) {
1052
1048
  debugLog(chalk.red(" ConditionType.ConditionRefresh ! subscriptionId ="), inputArguments[0].toString());
1053
1049
  }
@@ -38,7 +38,7 @@ import {
38
38
  AccessRestrictionsFlag
39
39
  } from "node-opcua-data-model";
40
40
  import { DataValue } from "node-opcua-data-value";
41
- import { dumpIf, make_warningLog, make_errorLog } from "node-opcua-debug";
41
+ import { dumpIf, make_debugLog, make_warningLog, make_errorLog } from "node-opcua-debug";
42
42
  import { coerceNodeId, makeNodeId, NodeId, NodeIdLike, resolveNodeId, sameNodeId } from "node-opcua-nodeid";
43
43
  import { NumericRange } from "node-opcua-numeric-range";
44
44
  import { ReferenceDescription } from "node-opcua-service-browse";
@@ -85,6 +85,8 @@ import { coerceRolePermissions } from "./role_permissions";
85
85
  const doDebug = false;
86
86
  const warningLog = make_warningLog(__filename);
87
87
  const errorLog = make_errorLog(__filename);
88
+ const debugLog = make_debugLog(__filename);
89
+
88
90
 
89
91
  function defaultBrowseFilterFunc(context?: ISessionContext): boolean {
90
92
  return true;
@@ -867,7 +869,7 @@ export class BaseNodeImpl extends EventEmitter implements BaseNode {
867
869
 
868
870
  /* istanbul ignore next */
869
871
  if (do_debug) {
870
- console.log("all references :", this.nodeId.toString(), this.browseName.toString());
872
+ debugLog("all references :", this.nodeId.toString(), this.browseName.toString());
871
873
  dumpReferences(addressSpace, (Object as any).values(_private._referenceIdx));
872
874
  }
873
875
 
@@ -940,7 +942,7 @@ export class BaseNodeImpl extends EventEmitter implements BaseNode {
940
942
 
941
943
  // istanbul ignore next
942
944
  if (!addressSpace) {
943
- console.log(" Where is addressSpace ?");
945
+ debugLog("Where is addressSpace ?");
944
946
  }
945
947
  const reference = addressSpace.normalizeReferenceTypes([referenceOpts!])![0];
946
948
  const h = (<ReferenceImpl>reference).hash;
@@ -1021,7 +1023,7 @@ export class BaseNodeImpl extends EventEmitter implements BaseNode {
1021
1023
  // istanbul ignore next
1022
1024
  if (doDebug) {
1023
1025
  // tslint:disable-next-line:no-console
1024
- console.log(chalk.bgWhite.red("Ignoring reserved keyword " + name));
1026
+ debugLog(chalk.bgWhite.red("Ignoring reserved keyword " + name));
1025
1027
  }
1026
1028
  return;
1027
1029
  }
@@ -1508,9 +1510,8 @@ function _asObject<T extends BaseNode>(references: UAReference[], addressSpace:
1508
1510
  function toObject(reference: UAReference): T {
1509
1511
  const obj = resolveReferenceNode(addressSpace, reference);
1510
1512
  // istanbul ignore next
1511
- if (false && !obj) {
1512
- // tslint:disable-next-line:no-console
1513
- console.log(
1513
+ if (doDebug&& !obj) {
1514
+ debugLog(
1514
1515
  chalk.red(" Warning : object with nodeId ") +
1515
1516
  chalk.cyan(reference.nodeId.toString()) +
1516
1517
  chalk.red(" cannot be found in the address space !")
@@ -1584,16 +1585,7 @@ function _propagate_ref(this: BaseNode, addressSpace: MinimalistAddressSpace, re
1584
1585
  displayWarningReferencePointingToItSelf = false;
1585
1586
  }
1586
1587
  }
1587
- // xx ignore this assert(reference.nodeId.toString() !== this.nodeId.toString());
1588
- // function w(s,l) { return (s+" ").substring(0,l);}
1589
- // if (reference.isForward) {
1590
- // console.log(" CHILD => ",w(related_node.browseName + " " + related_node.nodeId.toString(),30),
1591
- // " PARENT ",w(this.browseName + " " + this.nodeId.toString(),30) , reference.toString());
1592
- // } else {
1593
- // console.log(" CHILD => ",w(this.browseName + " " + this.nodeId.toString(),30),
1594
- // " PARENT ",w(related_node.browseName + " " + related_node.nodeId.toString(),30) , reference.toString());
1595
- //
1596
- // }
1588
+
1597
1589
  (related_node as BaseNodeImpl)._add_backward_reference(
1598
1590
  new ReferenceImpl({
1599
1591
  _referenceType: getReferenceType(reference),
@@ -1630,7 +1622,7 @@ function normalize_referenceTypeId(addressSpace: IAddressSpace, referenceTypeId?
1630
1622
  try {
1631
1623
  nodeId = addressSpace.resolveNodeId(referenceTypeId);
1632
1624
  } catch (err) {
1633
- console.log("cannot normalize_referenceTypeId", referenceTypeId);
1625
+ errorLog("cannot normalize_referenceTypeId", referenceTypeId);
1634
1626
  throw err;
1635
1627
  }
1636
1628
  assert(nodeId);
@@ -1790,14 +1782,14 @@ function install_components_as_object_properties(parentObj: BaseNode) {
1790
1782
  if (Object.prototype.hasOwnProperty.call(reservedNames, name)) {
1791
1783
  // ignore reserved names
1792
1784
  if (doDebug) {
1793
- console.log(chalk.bgWhite.red("Ignoring reserved keyword " + name));
1785
+ debugLog(chalk.bgWhite.red("Ignoring reserved keyword " + name));
1794
1786
  }
1795
1787
  continue;
1796
1788
  }
1797
1789
 
1798
1790
  // ignore reserved names
1799
1791
  if (doDebug) {
1800
- console.log("Installing property " + name, " on ", parentObj.browseName.toString());
1792
+ debugLog("Installing property " + name, " on ", parentObj.browseName.toString());
1801
1793
  }
1802
1794
 
1803
1795
  /* istanbul ignore next */
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import { assert } from "node-opcua-assert";
5
5
  import { DataType, Variant, VariantArrayType } from "node-opcua-variant";
6
- import { coerceInt32, coerceUInt64, Int64, isValidUInt64 } from "node-opcua-basic-types";
6
+ import { coerceInt32, coerceInt64toInt32, coerceUInt64, Int32, Int64, isValidUInt64 } from "node-opcua-basic-types";
7
7
  import { coerceLocalizedText, LocalizedText, QualifiedNameLike } from "node-opcua-data-model";
8
8
  import { DataValue, DataValueT } from "node-opcua-data-value";
9
9
  import { StatusCodes } from "node-opcua-status-code";
@@ -46,10 +46,7 @@ export interface UAMultiStateValueDiscreteImpl<T, DT extends DataType> {
46
46
 
47
47
  readValueAsync(context: ISessionContext | null, callback?: any): any;
48
48
  }
49
- export class UAMultiStateValueDiscreteImpl<T, DT extends DataType>
50
- extends UAVariableImpl
51
- implements UAMultiStateValueDiscreteEx<T, DT>
52
- {
49
+ export class UAMultiStateValueDiscreteImpl<T, DT extends DataType> extends UAVariableImpl implements UAMultiStateValueDiscreteEx<T, DT> {
53
50
  public setValue(value: string | number | Int64): void {
54
51
  if (typeof value === "string") {
55
52
  const enumValues = this.enumValues.readValue().value.value;
@@ -99,15 +96,16 @@ export class UAMultiStateValueDiscreteImpl<T, DT extends DataType>
99
96
  *
100
97
  * @private
101
98
  */
102
- public _enumValueIndex(): any {
99
+ public _enumValueIndex(): Record<Int32, DTEnumValue> {
103
100
  // construct an index to quickly find a EnumValue from a value
104
- const enumValues = this.enumValues.readValue().value.value;
105
- const enumValueIndex: any = {};
101
+ const enumValues: DTEnumValue[] = this.enumValues.readValue().value.value;
102
+ const enumValueIndex: Record<Int32, DTEnumValue> = {};
106
103
  if (!enumValues || !enumValues.forEach) {
107
104
  return enumValueIndex;
108
105
  }
109
- enumValues.forEach((e: any) => {
110
- enumValueIndex[e.value[1]] = e;
106
+ enumValues.forEach((e: DTEnumValue) => {
107
+ const index = coerceInt64toInt32(e.value);
108
+ enumValueIndex[index] = e;
111
109
  });
112
110
  return enumValueIndex;
113
111
  }
@@ -147,7 +145,7 @@ export class UAMultiStateValueDiscreteImpl<T, DT extends DataType>
147
145
  assert(!((value as any) instanceof Variant));
148
146
  let valueAsText1 = "Invalid";
149
147
  if (enumValueIndex[value]) {
150
- valueAsText1 = enumValueIndex[value].displayName;
148
+ valueAsText1 = enumValueIndex[value].displayName.text || `Invalid:${value}`;
151
149
  }
152
150
  const result = new Variant({
153
151
  dataType: DataType.LocalizedText,
@@ -0,0 +1,32 @@
1
+ import { IAddressSpace } from "node-opcua-address-space-base";
2
+ import { DataType } from "node-opcua-basic-types";
3
+ import { NodeClass } from "node-opcua-data-model";
4
+ import { NodeId } from "node-opcua-nodeid";
5
+
6
+ export interface IBaseNodeVariableOrVariableType {
7
+ addressSpace: IAddressSpace;
8
+ dataType: NodeId;
9
+ }
10
+ interface IBaseNodeVariableOrVariableTypeEx extends IBaseNodeVariableOrVariableType {
11
+ _basicDataType: DataType;
12
+ }
13
+ export function _getBasicDataType(uaNode: IBaseNodeVariableOrVariableType): DataType {
14
+ const _uaNode = uaNode as IBaseNodeVariableOrVariableTypeEx;
15
+ if (_uaNode._basicDataType) {
16
+ return _uaNode._basicDataType;
17
+ }
18
+ if (_uaNode.dataType.namespace === 0 && _uaNode.dataType.value === 0) {
19
+ return DataType.Null;
20
+ }
21
+ const addressSpace = _uaNode.addressSpace;
22
+ if (!addressSpace) {
23
+ // may be node has been deleted already
24
+ return DataType.Null;
25
+ }
26
+ const dataTypeNode = addressSpace.findDataType(_uaNode.dataType)!;
27
+ const basicDataType =
28
+ dataTypeNode && dataTypeNode.nodeClass === NodeClass.DataType ? dataTypeNode.getBasicDataType() : DataType.Null;
29
+ // const basicDataType = addressSpace.findCorrespondingBasicDataType(uaNode.dataType);
30
+ _uaNode._basicDataType = basicDataType;
31
+ return basicDataType;
32
+ }
@@ -1709,7 +1709,7 @@ export class NamespaceImpl implements NamespacePrivate {
1709
1709
  break;
1710
1710
  default:
1711
1711
  // tslint:disable-next-line:no-console
1712
- console.log("Invalid class Name", node.nodeClass);
1712
+ errorLog("Invalid class Name", node.nodeClass);
1713
1713
  throw new Error("Invalid class name specified");
1714
1714
  }
1715
1715
  }
@@ -1733,13 +1733,13 @@ export class NamespaceImpl implements NamespacePrivate {
1733
1733
  if (match) {
1734
1734
  const correctedName = match[1];
1735
1735
  // the application is using an old scheme
1736
- console.log(
1736
+ warningLog(
1737
1737
  chalk.green(
1738
1738
  "Warning : since node-opcua 0.4.2 " + "namespace index should not be prepended to the browse name anymore"
1739
1739
  )
1740
1740
  );
1741
- console.log(" ", options.browseName, " will be replaced with ", correctedName);
1742
- console.log(" Please update your code");
1741
+ warningLog(" ", options.browseName, " will be replaced with ", correctedName);
1742
+ warningLog(" Please update your code");
1743
1743
 
1744
1744
  const indexVerify = parseInt(match[0], 10);
1745
1745
  if (indexVerify !== this.index) {
@@ -1819,7 +1819,7 @@ export class NamespaceImpl implements NamespacePrivate {
1819
1819
  break;
1820
1820
  default:
1821
1821
  // tslint:disable:no-console
1822
- console.log("Invalid class Name", node.nodeClass);
1822
+ warningLog("Invalid class Name", node.nodeClass);
1823
1823
  throw new Error("Invalid class name specified");
1824
1824
  }
1825
1825
  const deleted = this._nodeid_index.delete(hashKey);
@@ -2234,7 +2234,6 @@ function _create_node_version_if_needed(node: BaseNode, options: { nodeVersion:
2234
2234
  propertyOf: node
2235
2235
  });
2236
2236
  const initialValue = typeof options.nodeVersion === "string" ? options.nodeVersion : "0";
2237
- // xx console.log(" init value =",initialValue);
2238
2237
  nodeVersion.setValueFromSource({ dataType: "String", value: initialValue });
2239
2238
  }
2240
2239
  }
@@ -1,11 +1,17 @@
1
1
  import { INamespace, UADataType, UAVariable, UAVariableType } from "node-opcua-address-space-base";
2
2
  import { NodeClass } from "node-opcua-data-model";
3
3
  import { StructureField } from "node-opcua-types";
4
- import { make_warningLog } from "node-opcua-debug";
4
+ import { DataType } from "node-opcua-basic-types";
5
+ import { ExtensionObject } from "node-opcua-extension-object";
6
+ import { Variant } from "node-opcua-variant";
7
+ import assert from "node-opcua-assert";
8
+ import { make_debugLog, make_warningLog } from "node-opcua-debug";
5
9
  import { NamespacePrivate } from "../namespace_private";
6
10
  import { BaseNodeImpl, getReferenceType } from "../base_node_impl";
11
+ import { UAVariableImpl } from "../ua_variable_impl";
7
12
 
8
13
  const warningLog = make_warningLog(__filename);
14
+ const debugLog = make_debugLog(__filename);
9
15
 
10
16
  function _constructNamespaceDependency(
11
17
  namespace: INamespace,
@@ -42,6 +48,9 @@ function _constructNamespaceDependency(
42
48
  }
43
49
  }
44
50
  function exploreDataTypes(dataTypeNode: UADataType): void {
51
+ if (!dataTypeNode) {
52
+ return;
53
+ }
45
54
  const dataType = dataTypeNode.nodeId;
46
55
  if (_visitedDataType.has(dataType.toString())) {
47
56
  return;
@@ -62,6 +71,35 @@ function _constructNamespaceDependency(
62
71
  }
63
72
  _visitedDataType.add(dataType.toString());
64
73
  }
74
+
75
+ function exploreExtensionObject(e: ExtensionObject) {
76
+ assert(!(e instanceof Variant));
77
+ const nodeId = e.schema.encodingDefaultXml || e.schema.dataTypeNodeId || e.schema.dataTypeNodeId;
78
+ consider(nodeId.namespace);
79
+ // istanbul ignore next
80
+ if (e.schema.dataTypeNodeId.isEmpty()) {
81
+ warningLog("Cannot find dataTypeNodeId for ", e.schema.name);
82
+ }
83
+ const d = addressSpace.findNode(e.schema.dataTypeNodeId) as UADataType | null;
84
+ // istanbul ignore next
85
+ if (!d) return;
86
+ exploreDataTypes(d);
87
+ }
88
+ function exploreDataValue(uaVariable: UAVariableImpl) {
89
+ if (uaVariable.getBasicDataType() !== DataType.ExtensionObject) {
90
+ return;
91
+ }
92
+ if (!uaVariable.$dataValue) return;
93
+ const variant = uaVariable.$dataValue.value;
94
+ if (!variant) return;
95
+ const value: any | any[] = variant.value;
96
+ if (!value) return;
97
+ if (Array.isArray(value)) {
98
+ value.forEach(exploreExtensionObject);
99
+ } else {
100
+ exploreExtensionObject(value);
101
+ }
102
+ }
65
103
  for (const node of namespace_.nodeIterator()) {
66
104
  if (node.nodeClass === NodeClass.Variable || node.nodeClass === NodeClass.VariableType) {
67
105
  const dataTypeNodeId = (node as UAVariable | UAVariableType).dataType;
@@ -71,9 +109,11 @@ function _constructNamespaceDependency(
71
109
  } else {
72
110
  // istanbul ignore next
73
111
  if (dataTypeNodeId.value != 0) {
74
- console.log("Internal error: Cannot find dataType", dataTypeNodeId.toString());
112
+ warningLog("Warning: Cannot find dataType", dataTypeNodeId.toString());
75
113
  }
76
114
  }
115
+ const nodeV = node as UAVariableImpl;
116
+ exploreDataValue(nodeV);
77
117
  }
78
118
  // visit all references
79
119
  const references = (<BaseNodeImpl>node).ownReferences();
@@ -87,7 +127,6 @@ function _constructNamespaceDependency(
87
127
  }
88
128
  }
89
129
 
90
-
91
130
  export function hasHigherPriorityThan(namespaceIndex1: number, namespaceIndex2: number, priorityTable: number[]) {
92
131
  const order1 = priorityTable[namespaceIndex1];
93
132
  const order2 = priorityTable[namespaceIndex2];
@@ -95,22 +134,21 @@ export function hasHigherPriorityThan(namespaceIndex1: number, namespaceIndex2:
95
134
  }
96
135
 
97
136
  /**
98
- *
99
- * @param namespace
100
- * @returns the order
101
- *
137
+ *
138
+ * @param namespace
139
+ * @returns the order
140
+ *
102
141
  * ---
103
142
  * ua, own , di => 0 , 2, 1
104
- *
143
+ *
105
144
  * ---
106
145
  * ua, own , di , kitchen , own2, adi => 0 , 2, 3, 1
107
- *
146
+ *
108
147
  * ---
109
148
  * ua, own , di , kitchen , own2, adi => 0 , 2, 3, 5, 1
110
149
  */
111
150
  export function constructNamespacePriorityTable(namespace: INamespace): number[] {
112
-
113
- // Namespace 0 will always be 0
151
+ // Namespace 0 will always be 0
114
152
  // Namespaces with no requiredModel will be considered as instance namespaces and will added at the end
115
153
  // in the same order as they appear,
116
154
  // Namespace with requiredModels are considered to be companion specification, so already loaded in the correct order
@@ -118,8 +156,8 @@ export function constructNamespacePriorityTable(namespace: INamespace): number[]
118
156
  const addressSpace = namespace.addressSpace;
119
157
  const namespaces = addressSpace.getNamespaceArray();
120
158
 
121
- const namespaceWithReq = namespaces.filter((n) => (n.getRequiredModels() !== undefined) && n.index !== 0);
122
- const namespaceWithoutReq = namespaces.filter((n) => (n.getRequiredModels() === undefined) && n.index !== 0);
159
+ const namespaceWithReq = namespaces.filter((n) => n.getRequiredModels() !== undefined && n.index !== 0);
160
+ const namespaceWithoutReq = namespaces.filter((n) => n.getRequiredModels() === undefined && n.index !== 0);
123
161
 
124
162
  const priorityList: number[] = [0];
125
163
  let counter = 1;
@@ -151,12 +189,16 @@ export function constructNamespaceDependency(namespace: INamespace, priorityTabl
151
189
 
152
190
  _constructNamespaceDependency(namespace, dependency, depMap, _visitedDataType, priorityTable);
153
191
 
154
- doDebug && console.log("namespace : ", namespace.index, namespace.namespaceUri);
155
- doDebug && console.log(" ", dependency.map((d)=>d.index + " " + d.namespaceUri).join("\n "));
192
+ // istanbul ignore next
193
+ doDebug && debugLog("namespace : ", namespace.index, namespace.namespaceUri);
194
+ // istanbul ignore next
195
+ doDebug && debugLog(" ", dependency.map((d) => d.index + " " + d.namespaceUri).join("\n "));
156
196
 
157
- const sorted = dependency.sort((a, b) => priorityTable![a.index] < priorityTable![b.index] ? -1 : 1);
158
- doDebug && console.log("sorted:")
159
- doDebug && console.log(" ", sorted.map((d)=>d.index + " " + d.namespaceUri).join("\n "));
197
+ const sorted = dependency.sort((a, b) => (priorityTable![a.index] < priorityTable![b.index] ? -1 : 1));
198
+ // istanbul ignore next
199
+ doDebug && debugLog("sorted:");
200
+ // istanbul ignore next
201
+ doDebug && debugLog(" ", sorted.map((d) => d.index + " " + d.namespaceUri).join("\n "));
160
202
 
161
203
  return sorted;
162
204
  }
@@ -48,6 +48,7 @@ import { UAMethodImpl } from "../ua_method_impl";
48
48
  import { UADataTypeImpl } from "../ua_data_type_impl";
49
49
  import { UAVariableTypeImpl } from "../ua_variable_type_impl";
50
50
  import { SessionContext } from "../index_current";
51
+ import { UAViewImpl } from "../ua_view_impl";
51
52
 
52
53
  import { DefinitionMap2, TypeInfo } from "../../source/loader/make_xml_extension_object_parser";
53
54
  import { makeDefinitionMap } from "../../source/loader/decode_xml_extension_object";
@@ -56,7 +57,6 @@ import {
56
57
  constructNamespacePriorityTable,
57
58
  hasHigherPriorityThan
58
59
  } from "./construct_namespace_dependency";
59
- import { UAViewImpl } from "../ua_view_impl";
60
60
 
61
61
  // tslint:disable:no-var-requires
62
62
  const XMLWriter = require("xml-writer");
@@ -141,7 +141,6 @@ function _dumpReferences(xw: XmlWriter, node: BaseNode) {
141
141
  if (reference.nodeId.namespace !== node.nodeId.namespace) {
142
142
  // todo: may be check that reference.nodeId.namespace is one of the namespace
143
143
  // on which our namespace is build and not a derived one !
144
- // xx console.log("xxxxxxxxxxxxxx Keeping => ", referenceType.toString(), reference.node?.nodeId.toString());
145
144
  return true;
146
145
  }
147
146
  }
@@ -374,8 +373,8 @@ function _dumpVariantInnerExtensionObject(
374
373
  if (types.isNativeError(err)) {
375
374
  errorLog("Error in _dumpVariantExtensionObjectValue_Body !!!", err.message);
376
375
  }
377
- console.log(name);
378
- console.log(field);
376
+ debugLog(name);
377
+ debugLog(field);
379
378
  // throw err;
380
379
  }
381
380
  restoreDefaultNamespace(xw);
@@ -503,7 +502,7 @@ function _dumpVariantExtensionObjectValue(
503
502
  const { name, definition } = definitionMap.findDefinition(dataTypeNodeId);
504
503
  // const encodingDefaultXml = (getStructureTypeConstructor(schema.name) as any).encodingDefaultXml;
505
504
  const encodingDefaultXml = value.schema.encodingDefaultXml;
506
- if (!encodingDefaultXml) {
505
+ if (!encodingDefaultXml || encodingDefaultXml.isEmpty()) {
507
506
  warningLog("dataType Name ", name, "with ", dataTypeNodeId.toString(), " does not have xml encoding");
508
507
  // throw new Error("Extension Object doesn't provide a XML ");
509
508
  return;
@@ -532,9 +531,10 @@ function _dumpVariantExtensionObjectValue(
532
531
  xw.endElement();
533
532
  }
534
533
 
535
- function _dumpVariantExtensionObjectValue2(xw: XmlWriter, dataTypeNode: UADataType, value: ExtensionObject) {
536
- const addressSpace = dataTypeNode.addressSpace;
534
+ function _dumpVariantExtensionObjectValue2(xw: XmlWriter, addressSpace: IAddressSpace, value: ExtensionObject) {
535
+ const dataTypeNodeId = value.schema.dataTypeNodeId;
537
536
  const definitionMap = makeDefinitionMap(addressSpace);
537
+ const dataTypeNode = addressSpace.findDataType(dataTypeNodeId)!;
538
538
  _dumpVariantExtensionObjectValue(xw, dataTypeNode.nodeId, definitionMap, value);
539
539
  }
540
540
 
@@ -605,22 +605,25 @@ function _isDefaultValue(value: Variant): boolean {
605
605
  }
606
606
 
607
607
  // eslint-disable-next-line max-statements
608
- function _dumpValue(xw: XmlWriter, node: UAVariable | UAVariableType, value: Variant) {
608
+ function _dumpValue(xw: XmlWriter, node: UAVariable | UAVariableType, variant: Variant) {
609
609
  const addressSpace = node.addressSpace;
610
610
 
611
611
  // istanbul ignore next
612
- if (value === null || value === undefined) {
612
+ if (variant === null || variant === undefined) {
613
613
  return;
614
614
  }
615
- assert(value instanceof Variant);
615
+ assert(variant instanceof Variant);
616
616
 
617
617
  const dataTypeNode = addressSpace.findDataType(node.dataType);
618
+
619
+ // istanbul ignore next
618
620
  if (!dataTypeNode) {
619
- console.log("Cannot find dataType:", node.dataType);
621
+ debugLog("Cannot find dataType:", node.dataType.toString());
620
622
  return;
621
623
  }
624
+
622
625
  const dataTypeName = dataTypeNode.browseName.name!.toString();
623
- const baseDataTypeName = DataType[value.dataType];
626
+ const baseDataTypeName = DataType[variant.dataType];
624
627
 
625
628
  if (baseDataTypeName === "Null") {
626
629
  return;
@@ -628,48 +631,48 @@ function _dumpValue(xw: XmlWriter, node: UAVariable | UAVariableType, value: Var
628
631
  assert(typeof baseDataTypeName === "string");
629
632
 
630
633
  // determine if dataTypeName is a ExtensionObject
631
- const isExtensionObject = value.dataType === DataType.ExtensionObject;
634
+ const isExtensionObject = variant.dataType === DataType.ExtensionObject;
632
635
 
633
- if (_isDefaultValue(value)) {
636
+ if (_isDefaultValue(variant)) {
634
637
  return;
635
638
  }
636
639
  xw.startElement("Value");
637
640
 
638
641
  const uax = getPrefix(xw, "http://opcfoundation.org/UA/2008/02/Types.xsd");
639
642
  if (isExtensionObject) {
640
- const encodeXml = _dumpVariantExtensionObjectValue2.bind(null, xw, dataTypeNode);
643
+ const encodeXml = _dumpVariantExtensionObjectValue2.bind(null, xw, node.addressSpace);
641
644
 
642
- switch (value.arrayType) {
645
+ switch (variant.arrayType) {
643
646
  case VariantArrayType.Matrix:
644
647
  case VariantArrayType.Array:
645
648
  startElementEx(xw, uax, `ListOf${baseDataTypeName}`, "http://opcfoundation.org/UA/2008/02/Types.xsd");
646
- value.value.forEach(encodeXml);
649
+ variant.value.forEach(encodeXml);
647
650
  restoreDefaultNamespace(xw);
648
651
  xw.endElement();
649
652
  break;
650
653
  case VariantArrayType.Scalar:
651
- encodeXml(value.value);
654
+ encodeXml(variant.value);
652
655
  break;
653
656
  default:
654
657
  errorLog(node.toString());
655
- errorLog("_dumpValue : unsupported arrayType: ", value.arrayType);
658
+ errorLog("_dumpValue : unsupported arrayType: ", variant.arrayType);
656
659
  }
657
660
  } else {
658
- const encodeXml = _dumpVariantValue.bind(null, xw, value.dataType, node);
659
- switch (value.arrayType) {
661
+ const encodeXml = _dumpVariantValue.bind(null, xw, variant.dataType, node);
662
+ switch (variant.arrayType) {
660
663
  case VariantArrayType.Matrix:
661
664
  case VariantArrayType.Array:
662
665
  startElementEx(xw, uax, `ListOf${dataTypeName}`, "http://opcfoundation.org/UA/2008/02/Types.xsd");
663
- value.value.forEach(encodeXml);
666
+ variant.value.forEach(encodeXml);
664
667
  restoreDefaultNamespace(xw);
665
668
  xw.endElement();
666
669
  break;
667
670
  case VariantArrayType.Scalar:
668
- encodeXml(value.value);
671
+ encodeXml(variant.value);
669
672
  break;
670
673
  default:
671
674
  errorLog(node.toString());
672
- errorLog("_dumpValue : unsupported arrayType: ", value.arrayType);
675
+ errorLog("_dumpValue : unsupported arrayType: ", variant.arrayType);
673
676
  }
674
677
  }
675
678
 
@@ -764,7 +767,7 @@ function dumpReferencedNodes(xw: XmlWriter, node: BaseNode, forward: boolean) {
764
767
  assert(nodeChild instanceof BaseNodeImpl);
765
768
  if (nodeChild.nodeId.namespace === node.nodeId.namespace) {
766
769
  if (!xw.visitedNode[_hash(nodeChild)]) {
767
- console.log(
770
+ debugLog(
768
771
  node.nodeId.toString(),
769
772
  " dumping child ",
770
773
  nodeChild.browseName.toString(),
@@ -953,7 +956,6 @@ function dumpUAView(xw: XmlWriter, node: UAView) {
953
956
  xw.endElement();
954
957
 
955
958
  dumpAggregates(xw, node);
956
-
957
959
  }
958
960
 
959
961
  function dumpUADataType(xw: XmlWriter, node: UADataType) {
@@ -1053,13 +1055,13 @@ function dumpUAVariableType(xw: XmlWriter, node: UAVariableType) {
1053
1055
  const dataTypeNode = addressSpace.findNode(node.dataType);
1054
1056
  if (!dataTypeNode) {
1055
1057
  // throw new Error(" cannot find datatype " + node.dataType);
1056
- console.log(
1058
+ debugLog(
1057
1059
  " cannot find datatype " +
1058
- node.dataType +
1059
- " for node " +
1060
- node.browseName.toString() +
1061
- " id =" +
1062
- node.nodeId.toString()
1060
+ node.dataType +
1061
+ " for node " +
1062
+ node.browseName.toString() +
1063
+ " id =" +
1064
+ node.nodeId.toString()
1063
1065
  );
1064
1066
  } else {
1065
1067
  const dataTypeName = b(xw, resolveDataTypeName(addressSpace, dataTypeNode.nodeId));
@@ -1267,7 +1269,6 @@ function writeAliases(xw: XmlWriter, aliases: Record<string, NodeIdString>) {
1267
1269
  }
1268
1270
 
1269
1271
  function constructNamespaceTranslationTable(dependency: INamespace[], exportedNamespace: INamespace): ITranslationTable {
1270
-
1271
1272
  const translationTable: ITranslationTable = {};
1272
1273
  assert(dependency[0].namespaceUri === "http://opcfoundation.org/UA/");
1273
1274
 
@@ -1279,7 +1280,9 @@ function constructNamespaceTranslationTable(dependency: INamespace[], exportedNa
1279
1280
  }
1280
1281
  for (let i = 1; i < dependency.length; i++) {
1281
1282
  const dep = dependency[i];
1282
- if (exportedNamespace && exportedNamespace === dep) { continue; }
1283
+ if (exportedNamespace && exportedNamespace === dep) {
1284
+ continue;
1285
+ }
1283
1286
  translationTable[dep.index] = counter++;
1284
1287
  }
1285
1288
  return translationTable;
@@ -1291,7 +1294,7 @@ function dumpReferenceType(xw: XmlWriter, referenceType: UAReferenceType) {
1291
1294
 
1292
1295
  dumpCommonAttributes(xw, referenceType);
1293
1296
 
1294
- const isSymmetric = (!referenceType.inverseName || referenceType.inverseName?.text === referenceType.browseName?.name);
1297
+ const isSymmetric = !referenceType.inverseName || referenceType.inverseName?.text === referenceType.browseName?.name;
1295
1298
  if (isSymmetric) {
1296
1299
  xw.writeAttribute("Symmetric", "true");
1297
1300
  }
@@ -1364,7 +1367,7 @@ UADataTypeImpl.prototype.dumpXML = function (xw: XmlWriter) {
1364
1367
 
1365
1368
  UAViewImpl.prototype.dumpXML = function (xw: XmlWriter) {
1366
1369
  dumpUAView(xw, this);
1367
- }
1370
+ };
1368
1371
 
1369
1372
  function makeTypeXsd(namespaceUri: string): string {
1370
1373
  return namespaceUri.replace(/\/$/, "") + "/Type.xsd";
@@ -1416,10 +1419,10 @@ NamespaceImpl.prototype.toNodeset2XML = function (this: NamespaceImpl) {
1416
1419
  xw.startElement("NamespaceUris");
1417
1420
 
1418
1421
  // let's sort the dependencies in the same order as the translation table
1419
- const sortedDependencies = dependency.sort((a, b) => translationTable[a.index] > translationTable[b.index] ? 1 : -1);
1422
+ const sortedDependencies = dependency.sort((a, b) => (translationTable[a.index] > translationTable[b.index] ? 1 : -1));
1420
1423
 
1421
- doDebug && console.log(sortedDependencies.map((a) => a.index + " + " + a.namespaceUri).join("\n"));
1422
- doDebug && console.log("translation table ", translationTable);
1424
+ doDebug && debugLog(sortedDependencies.map((a) => a.index + " + " + a.namespaceUri).join("\n"));
1425
+ doDebug && debugLog("translation table ", translationTable);
1423
1426
 
1424
1427
  for (const depend of sortedDependencies) {
1425
1428
  if (depend.index === 0) {