node-opcua-address-space 2.178.0 → 2.179.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 (184) hide show
  1. package/dist/source/address_space_ts.d.ts +16 -6
  2. package/dist/source/address_space_ts.js +1 -1
  3. package/dist/source/address_space_ts.js.map +1 -1
  4. package/dist/source/helpers/argument_list.js +2 -2
  5. package/dist/source/helpers/argument_list.js.map +1 -1
  6. package/dist/source/helpers/call_helpers.js +3 -0
  7. package/dist/source/helpers/call_helpers.js.map +1 -1
  8. package/dist/source/helpers/dump_tools.js +6 -2
  9. package/dist/source/helpers/dump_tools.js.map +1 -1
  10. package/dist/source/helpers/make_optionals_map.d.ts +3 -1
  11. package/dist/source/helpers/make_optionals_map.js.map +1 -1
  12. package/dist/source/interfaces/extension_object_constructor.d.ts +1 -1
  13. package/dist/source/interfaces/state_machine/ua_state_machine_type.js +0 -1
  14. package/dist/source/interfaces/state_machine/ua_state_machine_type.js.map +1 -1
  15. package/dist/source/loader/decode_xml_extension_object.js.map +1 -1
  16. package/dist/source/loader/ensure_datatype_extracted.js.map +1 -1
  17. package/dist/source/loader/generateAddressSpaceRaw.js +2 -1
  18. package/dist/source/loader/generateAddressSpaceRaw.js.map +1 -1
  19. package/dist/source/loader/load_nodeset2.js +12 -8
  20. package/dist/source/loader/load_nodeset2.js.map +1 -1
  21. package/dist/source/loader/make_xml_extension_object_parser.js +26 -7
  22. package/dist/source/loader/make_xml_extension_object_parser.js.map +1 -1
  23. package/dist/source/loader/namespace_post_step.js.map +1 -1
  24. package/dist/source/loader/parsers/extension_object_parser.d.ts +6 -4
  25. package/dist/source/loader/parsers/extension_object_parser.js +12 -6
  26. package/dist/source/loader/parsers/extension_object_parser.js.map +1 -1
  27. package/dist/source/loader/parsers/localized_text_parser.d.ts +1 -1
  28. package/dist/source/loader/parsers/nodeid_parser.d.ts +10 -2
  29. package/dist/source/loader/parsers/nodeid_parser.js.map +1 -1
  30. package/dist/source/loader/parsers/qualified_name_parser.d.ts +1 -2
  31. package/dist/source/loader/parsers/variant_parser.d.ts +8 -2
  32. package/dist/source/loader/parsers/variant_parser.js +11 -8
  33. package/dist/source/loader/parsers/variant_parser.js.map +1 -1
  34. package/dist/source/pseudo_session.js +70 -24
  35. package/dist/source/pseudo_session.js.map +1 -1
  36. package/dist/source/session_context.js.map +1 -1
  37. package/dist/source/xml_writer.d.ts +1 -1
  38. package/dist/src/_instantiate_helpers.js +0 -3
  39. package/dist/src/_instantiate_helpers.js.map +1 -1
  40. package/dist/src/_mandatory_child_or_requested_optional_filter.d.ts +3 -2
  41. package/dist/src/_mandatory_child_or_requested_optional_filter.js +0 -2
  42. package/dist/src/_mandatory_child_or_requested_optional_filter.js.map +1 -1
  43. package/dist/src/address_space.d.ts +7 -2
  44. package/dist/src/address_space.js +36 -28
  45. package/dist/src/address_space.js.map +1 -1
  46. package/dist/src/address_space_private.d.ts +1 -0
  47. package/dist/src/alarms_and_conditions/condition_snapshot_impl.js +6 -9
  48. package/dist/src/alarms_and_conditions/condition_snapshot_impl.js.map +1 -1
  49. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js +6 -6
  50. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js.map +1 -1
  51. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js +8 -4
  52. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js.map +1 -1
  53. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.js.map +1 -1
  54. package/dist/src/alarms_and_conditions/ua_condition_impl.js +6 -5
  55. package/dist/src/alarms_and_conditions/ua_condition_impl.js.map +1 -1
  56. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.js +3 -0
  57. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.js.map +1 -1
  58. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.js +0 -1
  59. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.js.map +1 -1
  60. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js.map +1 -1
  61. package/dist/src/base_node_impl.js +17 -8
  62. package/dist/src/base_node_impl.js.map +1 -1
  63. package/dist/src/base_node_private.js +0 -6
  64. package/dist/src/base_node_private.js.map +1 -1
  65. package/dist/src/extension_object_array_node.d.ts +9 -1
  66. package/dist/src/extension_object_array_node.js +20 -3
  67. package/dist/src/extension_object_array_node.js.map +1 -1
  68. package/dist/src/get_basic_datatype.js +3 -1
  69. package/dist/src/get_basic_datatype.js.map +1 -1
  70. package/dist/src/historical_access/address_space_historical_data_node.js +2 -4
  71. package/dist/src/historical_access/address_space_historical_data_node.js.map +1 -1
  72. package/dist/src/namespace_impl.js +6 -5
  73. package/dist/src/namespace_impl.js.map +1 -1
  74. package/dist/src/nodeid_manager.js +4 -5
  75. package/dist/src/nodeid_manager.js.map +1 -1
  76. package/dist/src/nodeset_tools/construct_namespace_dependency.js +10 -11
  77. package/dist/src/nodeset_tools/construct_namespace_dependency.js.map +1 -1
  78. package/dist/src/nodeset_tools/dump_to_bsd.js +2 -4
  79. package/dist/src/nodeset_tools/dump_to_bsd.js.map +1 -1
  80. package/dist/src/nodeset_tools/nodeset_to_xml.d.ts +1 -1
  81. package/dist/src/nodeset_tools/nodeset_to_xml.js +71 -43
  82. package/dist/src/nodeset_tools/nodeset_to_xml.js.map +1 -1
  83. package/dist/src/private_namespace.js.map +1 -1
  84. package/dist/src/reference_impl.d.ts +2 -2
  85. package/dist/src/reference_impl.js +5 -4
  86. package/dist/src/reference_impl.js.map +1 -1
  87. package/dist/src/state_machine/finite_state_machine.js +1 -1
  88. package/dist/src/state_machine/finite_state_machine.js.map +1 -1
  89. package/dist/src/state_machine/ua_shelving_state_machine_ex.js.map +1 -1
  90. package/dist/src/state_machine/ua_two_state_variable.js +9 -7
  91. package/dist/src/state_machine/ua_two_state_variable.js.map +1 -1
  92. package/dist/src/tool_isSubtypeOf.js.map +1 -1
  93. package/dist/src/ua_data_type_impl.js +4 -4
  94. package/dist/src/ua_data_type_impl.js.map +1 -1
  95. package/dist/src/ua_method_impl.js +21 -11
  96. package/dist/src/ua_method_impl.js.map +1 -1
  97. package/dist/src/ua_object_type_impl.d.ts +5 -2
  98. package/dist/src/ua_object_type_impl.js +4 -3
  99. package/dist/src/ua_object_type_impl.js.map +1 -1
  100. package/dist/src/ua_reference_type_impl.js +1 -2
  101. package/dist/src/ua_reference_type_impl.js.map +1 -1
  102. package/dist/src/ua_variable_impl.d.ts +9 -11
  103. package/dist/src/ua_variable_impl.js +103 -65
  104. package/dist/src/ua_variable_impl.js.map +1 -1
  105. package/dist/src/ua_variable_impl_ext_obj.d.ts +6 -6
  106. package/dist/src/ua_variable_impl_ext_obj.js +33 -22
  107. package/dist/src/ua_variable_impl_ext_obj.js.map +1 -1
  108. package/dist/src/ua_variable_type_impl.js +6 -2
  109. package/dist/src/ua_variable_type_impl.js.map +1 -1
  110. package/dist/tsconfig_base.tsbuildinfo +1 -1
  111. package/distHelpers/add_event_generator_object.js +3 -0
  112. package/distHelpers/add_event_generator_object.js.map +1 -1
  113. package/distHelpers/boiler_system.js +27 -6
  114. package/distHelpers/boiler_system.js.map +1 -1
  115. package/distHelpers/create_minimalist_address_space_nodeset.js +3 -3
  116. package/distHelpers/create_minimalist_address_space_nodeset.js.map +1 -1
  117. package/distHelpers/date_utils.js.map +1 -1
  118. package/distHelpers/dump_statemachine.js +1 -1
  119. package/distHelpers/dump_statemachine.js.map +1 -1
  120. package/distHelpers/get_address_space_fixture.js +0 -1
  121. package/distHelpers/get_address_space_fixture.js.map +1 -1
  122. package/package.json +41 -41
  123. package/source/address_space_ts.ts +19 -9
  124. package/source/helpers/argument_list.ts +2 -2
  125. package/source/helpers/call_helpers.ts +4 -1
  126. package/source/helpers/dump_tools.ts +7 -3
  127. package/source/helpers/make_optionals_map.ts +4 -2
  128. package/source/interfaces/alarms_and_conditions/ua_acknowledgeable_condition_ex.ts +4 -3
  129. package/source/interfaces/alarms_and_conditions/ua_alarm_condition_ex.ts +10 -11
  130. package/source/interfaces/alarms_and_conditions/ua_condition_ex.ts +6 -7
  131. package/source/interfaces/extension_object_constructor.ts +1 -1
  132. package/source/interfaces/state_machine/ua_program_state_machine_type.ts +0 -1
  133. package/source/interfaces/state_machine/ua_state_machine_type.ts +0 -1
  134. package/source/loader/decode_xml_extension_object.ts +3 -3
  135. package/source/loader/ensure_datatype_extracted.ts +6 -2
  136. package/source/loader/generateAddressSpaceRaw.ts +5 -4
  137. package/source/loader/load_nodeset2.ts +12 -8
  138. package/source/loader/make_xml_extension_object_parser.ts +78 -45
  139. package/source/loader/namespace_post_step.ts +1 -1
  140. package/source/loader/parsers/extension_object_parser.ts +36 -27
  141. package/source/loader/parsers/localized_text_parser.ts +1 -1
  142. package/source/loader/parsers/nodeid_parser.ts +10 -2
  143. package/source/loader/parsers/qualified_name_parser.ts +1 -1
  144. package/source/loader/parsers/variant_parser.ts +53 -40
  145. package/source/pseudo_session.ts +81 -28
  146. package/source/session_context.ts +1 -0
  147. package/source/xml_writer.ts +1 -1
  148. package/src/_instantiate_helpers.ts +0 -3
  149. package/src/_mandatory_child_or_requested_optional_filter.ts +3 -4
  150. package/src/address_space.ts +58 -42
  151. package/src/address_space_private.ts +2 -0
  152. package/src/alarms_and_conditions/condition_snapshot_impl.ts +6 -10
  153. package/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.ts +5 -7
  154. package/src/alarms_and_conditions/ua_alarm_condition_impl.ts +20 -13
  155. package/src/alarms_and_conditions/ua_base_event_impl.ts +1 -1
  156. package/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.ts +1 -1
  157. package/src/alarms_and_conditions/ua_condition_impl.ts +12 -10
  158. package/src/alarms_and_conditions/ua_discrete_alarm_impl.ts +8 -5
  159. package/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.ts +0 -1
  160. package/src/alarms_and_conditions/ua_off_normal_alarm_impl.ts +0 -1
  161. package/src/apply_condition_refresh.ts +1 -1
  162. package/src/base_node_impl.ts +30 -35
  163. package/src/base_node_private.ts +0 -6
  164. package/src/extension_object_array_node.ts +44 -15
  165. package/src/get_basic_datatype.ts +4 -1
  166. package/src/historical_access/address_space_historical_data_node.ts +2 -5
  167. package/src/namespace_impl.ts +24 -17
  168. package/src/nodeid_manager.ts +8 -11
  169. package/src/nodeset_tools/construct_namespace_dependency.ts +18 -15
  170. package/src/nodeset_tools/dump_to_bsd.ts +6 -8
  171. package/src/nodeset_tools/nodeset_to_xml.ts +105 -75
  172. package/src/private_namespace.ts +7 -2
  173. package/src/reference_impl.ts +11 -10
  174. package/src/state_machine/finite_state_machine.ts +12 -10
  175. package/src/state_machine/ua_shelving_state_machine_ex.ts +4 -4
  176. package/src/state_machine/ua_two_state_variable.ts +12 -9
  177. package/src/tool_isSubtypeOf.ts +2 -9
  178. package/src/ua_data_type_impl.ts +4 -4
  179. package/src/ua_method_impl.ts +24 -14
  180. package/src/ua_object_type_impl.ts +12 -6
  181. package/src/ua_reference_type_impl.ts +2 -3
  182. package/src/ua_variable_impl.ts +142 -96
  183. package/src/ua_variable_impl_ext_obj.ts +110 -82
  184. package/src/ua_variable_type_impl.ts +17 -5
@@ -1,4 +1,3 @@
1
- /* eslint-disable max-statements */
2
1
  /**
3
2
  * @module node-opcua-address-space
4
3
  */
@@ -27,7 +26,8 @@ import {
27
26
  makeDefaultCloneExtraInfo,
28
27
  type SetFunc,
29
28
  type VariableDataValueGetterSync,
30
- type VariableDataValueSetterWithCallback
29
+ type VariableDataValueSetterWithCallback,
30
+ type VariableSetter
31
31
  } from "node-opcua-address-space-base";
32
32
  import { assert } from "node-opcua-assert";
33
33
  import {
@@ -197,14 +197,13 @@ interface UAVariableOptions extends InternalBaseNodeOptions {
197
197
  * indicates if the history of the Variable is available via the OPC UA server.
198
198
  *
199
199
  */
200
- export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T> = UAVariableEvents>
200
+ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T> = UAVariableEvents>
201
201
  extends BaseNodeImpl<T>
202
202
  implements UAVariable<T>, UAVariableImplExtArray
203
203
  {
204
-
205
204
  // -------------- UAvaraibleImplExArray
206
205
  $$variableType?: UAVariableType;
207
- $$dataType?: UADataType = undefined;
206
+ $$dataType?: UADataType = undefined;
208
207
  $$getElementBrowseName?: (extObject: ExtensionObject, index: number | number[]) => QualifiedName;
209
208
  $$extensionObjectArray?: ExtensionObject[];
210
209
  $$indexPropertyName?: string;
@@ -215,6 +214,10 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
215
214
  public dataType: NodeId;
216
215
  private _basicDataType?: DataType;
217
216
 
217
+ // narrowing this to ExtensionObject breaks declaration-merging in ua_two_state_variable.ts and elsewhere
218
+ // (concrete *T variants bind $extensionObject to a different, more specific shape) — see the matching
219
+ // comment on UAVariable.$extensionObject in node-opcua-address-space-base for the documented precedent.
220
+ // biome-ignore lint/suspicious/noExplicitAny: see comment above
218
221
  public $extensionObject?: any;
219
222
  public $set_ExtensionObject?: (newValue: ExtensionObject, sourceTimestamp: PreciseClock, cache: Set<UAVariableImpl>) => void;
220
223
 
@@ -235,10 +238,10 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
235
238
 
236
239
  public _timestamped_get_func?: TimestampGetFunc | null;
237
240
  public _timestamped_set_func?: VariableDataValueSetterWithCallback | null;
238
- public _get_func: any;
239
- public _set_func: any;
241
+ public _get_func?: GetFunc | null;
242
+ public _set_func?: ((value: Variant, callback: (err: Error | null, statusCode?: StatusCode) => void) => void) | null;
240
243
  public refreshFunc?: (callback: CallbackT<DataValue>) => void;
241
- public __waiting_callbacks?: any[];
244
+ public __waiting_callbacks?: CallbackT<DataValue>[];
242
245
 
243
246
  get typeDefinitionObj(): UAVariableType {
244
247
  // c8 ignore next
@@ -417,7 +420,6 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
417
420
  if (dataValueOrPromise !== this.$dataValue) {
418
421
  // we may have a problem here if we use a getter that returns a dataValue that is a ExtensionObject
419
422
  if (dataValueOrPromise.value?.dataType === DataType.ExtensionObject) {
420
- // eslint-disable-next-line max-depth
421
423
  if (this.$extensionObject || this.$$extensionObjectArray) {
422
424
  // we have an extension object already bound to this node
423
425
  // the client is asking us to replace the object entirely by a new one
@@ -453,13 +455,15 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
453
455
  dataValue.statusCode.equals(StatusCodes.BadWaitingForInitialData) ||
454
456
  dataValue.statusCode.equals(StatusCodes.UncertainInitialValue)
455
457
  ) {
456
- debugLog(
457
- chalk.red(" Warning: UAVariable#readValue ") +
458
- chalk.cyan(this.browseName.toString()) +
459
- " (" +
460
- chalk.yellow(this.nodeId.toString()) +
461
- ") exists but dataValue has not been defined"
462
- );
458
+ // c8 ignore next
459
+ doDebug &&
460
+ debugLog(
461
+ chalk.red(" Warning: UAVariable#readValue ") +
462
+ chalk.cyan(this.browseName.toString()) +
463
+ " (" +
464
+ chalk.yellow(this.nodeId.toString()) +
465
+ ") exists but dataValue has not been defined"
466
+ );
463
467
  }
464
468
  return dataValue;
465
469
  }
@@ -495,14 +499,15 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
495
499
 
496
500
  public asyncRefresh(oldestDate: PreciseClock, callback: CallbackT<DataValue>): void;
497
501
  public asyncRefresh(oldestDate: PreciseClock): Promise<DataValue>;
498
- public asyncRefresh(...args: any[]): any {
502
+ public asyncRefresh(oldestDate: PreciseClock, callback?: CallbackT<DataValue>): Promise<DataValue> | undefined {
503
+ // asyncRefresh is always invoked with a callback at runtime: the public overload without
504
+ // a callback is only reachable through the withCallback() wrapper installed below, which
505
+ // synthesizes one before calling into this implementation.
506
+ const cb = callback as CallbackT<DataValue>;
499
507
  if (this.$dataValue.statusCode.isGoodish()) {
500
508
  this.verifyVariantCompatibility(this.$dataValue.value);
501
509
  }
502
510
 
503
- const oldestDate = args[0] as PreciseClock;
504
- const callback = args[1] as CallbackT<DataValue>;
505
-
506
511
  const lessOrEqual = (a: PreciseClock, b: PreciseClock) => {
507
512
  return (
508
513
  a.timestamp.getTime() < b.timestamp.getTime() ||
@@ -517,10 +522,12 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
517
522
  dataValue.serverPicoseconds = oldestDate.picoseconds;
518
523
  const serverClock = coerceClock(dataValue.serverTimestamp, dataValue.serverPicoseconds);
519
524
  if (lessOrEqual(oldestDate, serverClock)) {
520
- return callback(null, dataValue);
525
+ cb(null, dataValue);
526
+ return;
521
527
  } else {
522
528
  // fake
523
- return callback(null, dataValue);
529
+ cb(null, dataValue);
530
+ return;
524
531
  }
525
532
  }
526
533
 
@@ -528,11 +535,12 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
528
535
  ? coerceClock(this.$dataValue.serverTimestamp, this.$dataValue.serverPicoseconds)
529
536
  : null;
530
537
 
531
- if (this.$dataValue.serverTimestamp && lessOrEqual(oldestDate, c1!)) {
538
+ if (c1 && lessOrEqual(oldestDate, c1)) {
532
539
  const dataValue = this.readValue().clone();
533
540
  dataValue.serverTimestamp = oldestDate.timestamp;
534
541
  dataValue.serverPicoseconds = oldestDate.picoseconds;
535
- return callback(null, dataValue);
542
+ cb(null, dataValue);
543
+ return;
536
544
  }
537
545
  try {
538
546
  this.refreshFunc.call(this, (err: Error | null, dataValue?: DataValueLike) => {
@@ -549,15 +557,16 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
549
557
  if (dataValue && dataValue !== this.$dataValue) {
550
558
  this._internal_set_dataValue(coerceDataValue(dataValue), null);
551
559
  }
552
- callback(err, this.$dataValue);
560
+ cb(err, this.$dataValue);
553
561
  });
554
562
  } catch (err) {
555
563
  errorLog("-------------- refresh call failed 2", this.browseName.toString(), this.nodeId.toString());
556
564
  errorLog(err);
557
565
  const dataValue = new DataValue({ statusCode: StatusCodes.BadInternalError });
558
566
  this._internal_set_dataValue(dataValue, null);
559
- callback(err as Error, this.$dataValue);
567
+ cb(err as Error, this.$dataValue);
560
568
  }
569
+ return undefined;
561
570
  }
562
571
 
563
572
  public readEnumValue(): IEnumItem {
@@ -784,7 +793,11 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
784
793
  }
785
794
 
786
795
  private adjustDataValueStatusCode(dataValue: DataValue): StatusCode {
787
- const statusCode = adjustDataValueStatusCode(this, dataValue, (this as any).acceptValueOutOfRange || false);
796
+ const statusCode = adjustDataValueStatusCode(
797
+ this,
798
+ dataValue,
799
+ (this as unknown as { acceptValueOutOfRange?: boolean }).acceptValueOutOfRange || false
800
+ );
788
801
  return statusCode;
789
802
  }
790
803
 
@@ -800,7 +813,7 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
800
813
  dataValue: DataValue,
801
814
  indexRange?: string | NumericRange | null
802
815
  ): Promise<StatusCode>;
803
- public writeValue(context: ISessionContext, dataValue: DataValue, ...args: any[]): any {
816
+ public writeValue(context: ISessionContext, dataValue: DataValue, ...args: unknown[]): Promise<StatusCode> | undefined {
804
817
  context = context || SessionContext.defaultContext;
805
818
  assert(context instanceof SessionContext);
806
819
 
@@ -827,10 +840,10 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
827
840
  let callback: StatusCodeCallback;
828
841
  if (args.length === 1) {
829
842
  indexRange = new NumericRange();
830
- callback = args[0];
843
+ callback = args[0] as StatusCodeCallback;
831
844
  } else if (args.length === 2) {
832
- indexRange = args[0];
833
- callback = args[1];
845
+ indexRange = args[0] as NumericRange;
846
+ callback = args[1] as StatusCodeCallback;
834
847
  } else {
835
848
  throw new Error("Invalid Number of args");
836
849
  }
@@ -842,14 +855,17 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
842
855
 
843
856
  // test write permission
844
857
  if (!this.isWritable(context)) {
845
- return callback?.(null, StatusCodes.BadNotWritable);
858
+ callback?.(null, StatusCodes.BadNotWritable);
859
+ return;
846
860
  }
847
861
  if (!this.checkPermissionPrivate(context, PermissionType.Write)) {
848
- return new DataValue({ statusCode: StatusCodes.BadUserAccessDenied });
862
+ callback?.(null, StatusCodes.BadUserAccessDenied);
863
+ return;
849
864
  }
850
865
 
851
866
  if (!this.isUserWritable(context)) {
852
- return callback?.(null, StatusCodes.BadWriteNotSupported);
867
+ callback?.(null, StatusCodes.BadWriteNotSupported);
868
+ return;
853
869
  }
854
870
 
855
871
  // adjust special case
@@ -857,13 +873,15 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
857
873
 
858
874
  const statusCode = this.checkVariantCompatibility(variant);
859
875
  if (statusCode.isNot(StatusCodes.Good)) {
860
- return callback?.(null, statusCode);
876
+ callback?.(null, statusCode);
877
+ return;
861
878
  }
862
879
 
863
880
  // adjust dataValue.statusCode based on InstrumentRange and EngineeringUnits
864
881
  const statusCode2 = this.adjustDataValueStatusCode(dataValue);
865
882
  if (statusCode2.isNotGood()) {
866
- return callback?.(null, statusCode2);
883
+ callback?.(null, statusCode2);
884
+ return;
867
885
  }
868
886
 
869
887
  const write_func = this._timestamped_set_func || default_func;
@@ -871,7 +889,8 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
871
889
  if (!write_func) {
872
890
  warningLog(` warning ${this.nodeId.toString()} ${this.browseName.toString()} has no setter. \n`);
873
891
  warningLog("Please make sure to bind the variable or to pass a valid value: new Variant({}) during construction time");
874
- return callback?.(null, StatusCodes.BadNotWritable);
892
+ callback?.(null, StatusCodes.BadNotWritable);
893
+ return;
875
894
  }
876
895
  assert(write_func);
877
896
 
@@ -881,14 +900,16 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
881
900
 
882
901
  if (indexRange && !indexRange.isEmpty()) {
883
902
  if (!indexRange.isValid()) {
884
- return callback?.(null, StatusCodes.BadIndexRangeInvalid);
903
+ callback?.(null, StatusCodes.BadIndexRangeInvalid);
904
+ return;
885
905
  }
886
906
 
887
907
  const newArrayOrMatrix = dataValue.value.value;
888
908
 
889
909
  if (dataValue.value.arrayType === VariantArrayType.Array) {
890
910
  if (this.$dataValue.value.arrayType !== VariantArrayType.Array) {
891
- return callback(null, StatusCodes.BadTypeMismatch);
911
+ callback(null, StatusCodes.BadTypeMismatch);
912
+ return;
892
913
  }
893
914
  // check that destination data is also an array
894
915
  assert(check_valid_array(this.$dataValue.value.dataType, this.$dataValue.value.value));
@@ -896,7 +917,8 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
896
917
  const result = indexRange.set_values(destArr, newArrayOrMatrix);
897
918
 
898
919
  if (result.statusCode.isNot(StatusCodes.Good)) {
899
- return callback?.(null, result.statusCode);
920
+ callback?.(null, result.statusCode);
921
+ return;
900
922
  }
901
923
  dataValue.value.value = result.array;
902
924
 
@@ -906,7 +928,8 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
906
928
  const dimensions = this.$dataValue.value.dimensions;
907
929
  if (this.$dataValue.value.arrayType !== VariantArrayType.Matrix || !dimensions) {
908
930
  // not a matrix !
909
- return callback?.(null, StatusCodes.BadTypeMismatch);
931
+ callback?.(null, StatusCodes.BadTypeMismatch);
932
+ return;
910
933
  }
911
934
  const matrix = this.$dataValue.value.value;
912
935
  const result = indexRange.set_values_matrix(
@@ -917,7 +940,8 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
917
940
  newArrayOrMatrix
918
941
  );
919
942
  if (result.statusCode.isNot(StatusCodes.Good)) {
920
- return callback?.(null, result.statusCode);
943
+ callback?.(null, result.statusCode);
944
+ return;
921
945
  }
922
946
  dataValue.value.dimensions = this.$dataValue.value.dimensions;
923
947
  dataValue.value.value = result.matrix;
@@ -925,7 +949,8 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
925
949
  // scrap original array so we detect range
926
950
  this.$dataValue.value.value = null;
927
951
  } else {
928
- return callback?.(null, StatusCodes.BadTypeMismatch);
952
+ callback?.(null, StatusCodes.BadTypeMismatch);
953
+ return;
929
954
  }
930
955
  }
931
956
  try {
@@ -934,11 +959,13 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
934
959
  if (types.isNativeError(err)) {
935
960
  warningLog(err.message);
936
961
  }
937
- return callback?.(null, StatusCodes.BadInternalError);
962
+ callback?.(null, StatusCodes.BadInternalError);
963
+ return;
938
964
  }
939
965
  }
940
966
  callback?.(err || null, statusCode1);
941
967
  });
968
+ return undefined;
942
969
  }
943
970
 
944
971
  public writeAttribute(context: ISessionContext | null, writeValue: WriteValueOptions, callback: StatusCodeCallback): void;
@@ -947,14 +974,15 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
947
974
  context: ISessionContext | null,
948
975
  writeValueOptions: WriteValueOptions,
949
976
  callback?: (err: Error | null, statusCode?: StatusCode) => void
950
- ): any {
977
+ ): Promise<StatusCode> | undefined {
951
978
  // c8 ignore next
952
979
  if (!callback) {
953
980
  throw new Error("Internal error");
954
981
  }
955
982
 
956
- if (!this.canUserWriteAttribute(context, writeValueOptions.attributeId!)) {
957
- return callback(null, StatusCodes.BadUserAccessDenied);
983
+ if (!this.canUserWriteAttribute(context, writeValueOptions.attributeId as AttributeIds)) {
984
+ callback(null, StatusCodes.BadUserAccessDenied);
985
+ return;
958
986
  }
959
987
  const writeValue: WriteValue =
960
988
  writeValueOptions instanceof WriteValue ? (writeValueOptions as WriteValue) : new WriteValue(writeValueOptions);
@@ -975,33 +1003,39 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
975
1003
 
976
1004
  switch (writeValue.attributeId) {
977
1005
  case AttributeIds.Value:
978
- this.writeValue(context, writeValue.value!, writeValue.indexRange!, callback);
1006
+ this.writeValue(context, writeValue.value as DataValue, writeValue.indexRange, callback);
979
1007
  break;
980
1008
  case AttributeIds.Historizing:
981
1009
  if (writeValue.value?.value.dataType !== DataType.Boolean) {
982
- return callback(null, StatusCodes.BadTypeMismatch);
1010
+ callback(null, StatusCodes.BadTypeMismatch);
1011
+ break;
983
1012
  }
984
1013
  if (!this.checkPermissionPrivate(context, PermissionType.WriteHistorizing)) {
985
- return callback(null, StatusCodes.BadUserAccessDenied);
1014
+ callback(null, StatusCodes.BadUserAccessDenied);
1015
+ break;
986
1016
  }
987
1017
 
988
1018
  if (!this.canUserWriteHistorizingAttribute(context)) {
989
- return callback(null, StatusCodes.BadHistoryOperationUnsupported);
1019
+ callback(null, StatusCodes.BadHistoryOperationUnsupported);
1020
+ break;
990
1021
  }
991
1022
 
992
1023
  // if the variable has no historizing in place reject
993
1024
  if (!this.getChildByName("HA Configuration")) {
994
- return callback(null, StatusCodes.BadNotSupported);
1025
+ callback(null, StatusCodes.BadNotSupported);
1026
+ break;
995
1027
  }
996
1028
  // check if user is allowed to do that !
997
1029
  // TODO
998
1030
  this.historizing = !!writeValue.value?.value.value; // yes ! indeed !
999
- return callback(null, StatusCodes.Good);
1031
+ callback(null, StatusCodes.Good);
1032
+ break;
1000
1033
 
1001
1034
  default:
1002
1035
  super.writeAttribute(context, writeValue, callback);
1003
1036
  break;
1004
1037
  }
1038
+ return undefined;
1005
1039
  }
1006
1040
 
1007
1041
  /**
@@ -1189,13 +1223,13 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
1189
1223
  */
1190
1224
  public readValueAsync(context: ISessionContext | null, callback: CallbackT<DataValue>): void;
1191
1225
  public readValueAsync(context: ISessionContext | null): Promise<DataValue>;
1192
- public readValueAsync(context: ISessionContext | null, callback?: CallbackT<DataValue>): any {
1226
+ public readValueAsync(context: ISessionContext | null, callback?: CallbackT<DataValue>): Promise<DataValue> | undefined {
1193
1227
  assert(typeof callback === "function");
1194
1228
 
1195
1229
  context = context || SessionContext.defaultContext;
1196
1230
 
1197
1231
  this.__waiting_callbacks = this.__waiting_callbacks || [];
1198
- this.__waiting_callbacks.push(callback);
1232
+ this.__waiting_callbacks.push(callback as CallbackT<DataValue>);
1199
1233
 
1200
1234
  const _readValueAsync_in_progress = this.__waiting_callbacks.length >= 2;
1201
1235
  if (_readValueAsync_in_progress) {
@@ -1203,7 +1237,8 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
1203
1237
  }
1204
1238
 
1205
1239
  if (this.isDisposed()) {
1206
- return callback?.(null, new DataValue({ statusCode: StatusCodes.BadNodeIdUnknown }));
1240
+ callback?.(null, new DataValue({ statusCode: StatusCodes.BadNodeIdUnknown }));
1241
+ return;
1207
1242
  }
1208
1243
 
1209
1244
  const readImmediate = (innerCallback: (err: Error | null, dataValue: DataValue) => void) => {
@@ -1214,21 +1249,23 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
1214
1249
 
1215
1250
  let func: (innerCallback: (err: Error | null, dataValue: DataValue) => void) => void;
1216
1251
 
1217
- if (!this.isReadable(context)) {
1218
- func = (innerCallback: (err: Error | null, dataValue: DataValue) => void) => {
1219
- const dataValue = new DataValue({ statusCode: StatusCodes.BadNotReadable });
1220
- innerCallback(null, dataValue);
1221
- };
1252
+ const answerStatusOnly = (statusCode: StatusCode) => (innerCallback: (err: Error | null, dataValue: DataValue) => void) =>
1253
+ innerCallback(null, new DataValue({ statusCode }));
1254
+
1255
+ if (context.isAccessRestricted(this)) {
1256
+ // same gate as readValue(): a variable bound with a simple get()
1257
+ // also gets a refreshFunc, sending every read down the asyncRefresh
1258
+ // branch below - which calls the getter directly and never passes
1259
+ // through readValue(). Without this check here, a node hardened
1260
+ // with AccessRestrictions(EncryptionRequired) answered its value
1261
+ // over an unencrypted channel.
1262
+ func = answerStatusOnly(StatusCodes.BadSecurityModeInsufficient);
1263
+ } else if (!this.isReadable(context)) {
1264
+ func = answerStatusOnly(StatusCodes.BadNotReadable);
1222
1265
  } else if (!this.checkPermissionPrivate(context, PermissionType.Read)) {
1223
- func = (innerCallback: (err: Error | null, dataValue: DataValue) => void) => {
1224
- const dataValue = new DataValue({ statusCode: StatusCodes.BadUserAccessDenied });
1225
- innerCallback(null, dataValue);
1226
- };
1266
+ func = answerStatusOnly(StatusCodes.BadUserAccessDenied);
1227
1267
  } else if (!this.isUserReadable(context)) {
1228
- func = (innerCallback: (err: Error | null, dataValue: DataValue) => void) => {
1229
- const dataValue = new DataValue({ statusCode: StatusCodes.BadNotReadable });
1230
- innerCallback(null, dataValue);
1231
- };
1268
+ func = answerStatusOnly(StatusCodes.BadNotReadable);
1232
1269
  } else {
1233
1270
  const clock = getCurrentClock();
1234
1271
  func = typeof this.refreshFunc === "function" ? this.asyncRefresh.bind(this, clock) : readImmediate;
@@ -1256,6 +1293,7 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
1256
1293
  }
1257
1294
  satisfy_callbacks(err as Error);
1258
1295
  }
1296
+ return undefined;
1259
1297
  }
1260
1298
 
1261
1299
  public getWriteMask(): number {
@@ -1421,7 +1459,8 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
1421
1459
  continue;
1422
1460
  }
1423
1461
  if (e.constructor.name !== Constructor.name) {
1424
- debugLog("extObj.constructor.name ", e.constructor.name, "expected", Constructor.name);
1462
+ // c8 ignore next
1463
+ doDebug && debugLog("extObj.constructor.name ", e.constructor.name, "expected", Constructor.name);
1425
1464
  return false;
1426
1465
  }
1427
1466
  }
@@ -1506,9 +1545,9 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
1506
1545
  return null;
1507
1546
  }
1508
1547
 
1509
- public updateExtensionObjectPartial(partialExtensionObject?: { [key: string]: any }): ExtensionObject {
1548
+ public updateExtensionObjectPartial(partialExtensionObject?: Record<string, unknown>): ExtensionObject {
1510
1549
  setExtensionObjectPartialValue(this, partialExtensionObject);
1511
- return this.$extensionObject;
1550
+ return this.$extensionObject as ExtensionObject;
1512
1551
  }
1513
1552
 
1514
1553
  public incrementExtensionObjectPartial(path: string | string[]): void {
@@ -1643,14 +1682,23 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
1643
1682
  dataEncoding: QualifiedNameLike | null,
1644
1683
  continuationData: ContinuationData,
1645
1684
  callback?: CallbackT<HistoryReadResult>
1646
- ): any {
1685
+ ): Promise<HistoryReadResult> | undefined {
1647
1686
  assert(context instanceof SessionContext);
1648
1687
  assert(typeof callback === "function");
1649
1688
  if (typeof this._historyRead !== "function") {
1650
- return callback?.(null, new HistoryReadResult({ statusCode: StatusCodes.BadNotReadable }));
1689
+ callback?.(null, new HistoryReadResult({ statusCode: StatusCodes.BadNotReadable }));
1690
+ return;
1651
1691
  }
1652
1692
 
1653
- this._historyRead(context, historyReadDetails, indexRange, dataEncoding, continuationData, callback!);
1693
+ this._historyRead(
1694
+ context,
1695
+ historyReadDetails,
1696
+ indexRange,
1697
+ dataEncoding,
1698
+ continuationData,
1699
+ callback as CallbackT<HistoryReadResult>
1700
+ );
1701
+ return undefined;
1654
1702
  }
1655
1703
 
1656
1704
  public _historyReadRaw(
@@ -1671,7 +1719,7 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
1671
1719
  _dataEncoding: QualifiedNameLike | null,
1672
1720
  _continuationData: ContinuationData,
1673
1721
  _callback?: CallbackT<HistoryReadResult>
1674
- ): any {
1722
+ ): void {
1675
1723
  throw new Error("");
1676
1724
  }
1677
1725
 
@@ -1706,7 +1754,7 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
1706
1754
  callback(null, result);
1707
1755
  }
1708
1756
 
1709
- public _historyPush(_newDataValue: DataValue): any {
1757
+ public _historyPush(_newDataValue: DataValue): void {
1710
1758
  throw new Error("");
1711
1759
  }
1712
1760
 
@@ -1716,7 +1764,7 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
1716
1764
  _isReversed: boolean,
1717
1765
  _reverseDataValue: boolean,
1718
1766
  _callback: CallbackT<DataValue[]>
1719
- ): any {
1767
+ ): void {
1720
1768
  throw new Error("");
1721
1769
  }
1722
1770
 
@@ -1727,7 +1775,7 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
1727
1775
  _dataEncoding: QualifiedNameLike | null,
1728
1776
  _continuationData: ContinuationData,
1729
1777
  _callback: CallbackT<HistoryReadResult>
1730
- ): any {
1778
+ ): void {
1731
1779
  throw new Error("");
1732
1780
  }
1733
1781
 
@@ -1952,9 +2000,7 @@ export class UAVariableImpl<T extends UAVariableEvents & ListenerSignature<T>
1952
2000
  }
1953
2001
  }
1954
2002
 
1955
-
1956
2003
  import type { IStructuredTypeSchema } from "node-opcua-factory";
1957
- // tslint:disable:no-var-requires
1958
2004
  import { withCallback } from "thenify-ex";
1959
2005
 
1960
2006
  UAVariableImpl.prototype.asyncRefresh = withCallback(UAVariableImpl.prototype.asyncRefresh);
@@ -1971,9 +2017,7 @@ export interface UAVariableImplExtArray {
1971
2017
  $$indexPropertyName?: string;
1972
2018
  }
1973
2019
 
1974
-
1975
-
1976
- function check_valid_array(dataType: DataType, array: any): boolean {
2020
+ function check_valid_array(dataType: DataType, array: unknown): boolean {
1977
2021
  if (Array.isArray(array)) {
1978
2022
  return true;
1979
2023
  }
@@ -2134,13 +2178,14 @@ function _Variable_bind_with_async_refresh(
2134
2178
  assert(!this.refreshFunc);
2135
2179
 
2136
2180
  this.refreshFunc = options.refreshFunc;
2137
- /*
2181
+ /*
2138
2182
  // TO DO : REVISIT THIS ASSUMPTION
2139
2183
  if (false && this.minimumSamplingInterval === 0) {
2140
2184
  // when a getter /timestamped_getter or async_getter is provided
2141
2185
  // samplingInterval cannot be 0, as the item value must be scanned to be updated.
2142
2186
  this.minimumSamplingInterval = _default_minimumSamplingInterval; // MonitoredItem.minimumSamplingInterval;
2143
- debugLog(`adapting minimumSamplingInterval on ${this.browseName.toString()} to ${this.minimumSamplingInterval}`);
2187
+ // c8 ignore next
2188
+ doDebug && debugLog(`adapting minimumSamplingInterval on ${this.browseName.toString()} to ${this.minimumSamplingInterval}`);
2144
2189
  }
2145
2190
  */
2146
2191
  }
@@ -2207,7 +2252,7 @@ function _Variable_bind_with_simple_get(this: UAVariableImpl, options: GetterOpt
2207
2252
  this._get_func = options.get;
2208
2253
 
2209
2254
  const timestamped_get_func_from__Variable_bind_with_simple_get = () => {
2210
- const value: Variant | StatusCode = this._get_func();
2255
+ const value: Variant | StatusCode = (this._get_func as GetFunc)();
2211
2256
 
2212
2257
  /* c8 ignore next */
2213
2258
  if (!is_Variant_or_StatusCode(value)) {
@@ -2253,16 +2298,17 @@ function _Variable_bind_with_simple_set(this: UAVariableImpl, options: SimpleSet
2253
2298
  assert(!this._set_func);
2254
2299
 
2255
2300
  //
2256
- this._set_func = turn_sync_to_async(options.set!, 1);
2301
+ const set_func = turn_sync_to_async<UAVariable, Variant, StatusCode>(options.set as VariableSetter, 1);
2302
+ this._set_func = set_func;
2257
2303
 
2258
- assert(this._set_func.length === 2, " set function must have 2 arguments ( variant, callback)");
2304
+ assert(set_func.length === 2, " set function must have 2 arguments ( variant, callback)");
2259
2305
 
2260
2306
  this._timestamped_set_func = (
2261
2307
  timestamped_value: DataValue,
2262
2308
  callback: (err: Error | null, statusCode: StatusCode, dataValue: DataValue) => void
2263
2309
  ) => {
2264
2310
  assert(timestamped_value instanceof DataValue);
2265
- this._set_func(timestamped_value.value, (err: Error | null, statusCode: StatusCode) => {
2311
+ set_func.call(this, timestamped_value.value, (err: Error | null, statusCode?: StatusCode) => {
2266
2312
  // c8 ignore next
2267
2313
  if (!err && !statusCode) {
2268
2314
  errorLog(
@@ -2275,7 +2321,7 @@ function _Variable_bind_with_simple_set(this: UAVariableImpl, options: SimpleSet
2275
2321
  // record the value but still record the statusCode !
2276
2322
  timestamped_value.statusCode = statusCode;
2277
2323
  }
2278
- callback(err, statusCode, timestamped_value);
2324
+ callback(err, statusCode ?? StatusCodes.BadInternalError, timestamped_value);
2279
2325
  });
2280
2326
  };
2281
2327
  }
@@ -2336,7 +2382,7 @@ interface GetterOptions {
2336
2382
  timestamped_get?: TimestampGetFunc;
2337
2383
  refreshFunc?: RefreshFunc;
2338
2384
  dataType?: DataType | string;
2339
- value?: any;
2385
+ value?: unknown;
2340
2386
  }
2341
2387
  function bind_getter(this: UAVariableImpl, options: GetterOptions) {
2342
2388
  if (typeof options.get === "function") {
@@ -2353,7 +2399,7 @@ function bind_getter(this: UAVariableImpl, options: GetterOptions) {
2353
2399
  if (options.get !== undefined || options.timestamped_get !== undefined) {
2354
2400
  throw new Error("bind_getter : options should not specify both get and timestamped_get ");
2355
2401
  }
2356
- _Variable_bind_with_async_refresh.call(this, { refreshFunc: options.refreshFunc! });
2402
+ _Variable_bind_with_async_refresh.call(this, { refreshFunc: options.refreshFunc });
2357
2403
  } else {
2358
2404
  assert(!Object.hasOwn(options, "set"), "getter is missing : a getter must be provided if a setter is provided");
2359
2405
  // xx bind_variant.call(this,options);
@@ -2435,9 +2481,9 @@ function changeUAVariableDataType(uaVariable: UAVariableImpl, newDataType: NodeI
2435
2481
 
2436
2482
  // change uaVariable.dataType
2437
2483
  uaVariable.dataType = newDataTypeNode.nodeId;
2438
- (uaVariable as any)._basicDataType = null;
2439
- (uaVariable as any).$dataValue.value.dataType = newDataType;
2440
- (uaVariable as any).$dataValue.value = value;
2484
+ (uaVariable as unknown as { _basicDataType?: DataType | null })._basicDataType = null;
2485
+ uaVariable.$dataValue.value.dataType = newBaseDataType;
2486
+ uaVariable.$dataValue.value = value;
2441
2487
  // also change the value to ensure that we have a default value with the correct dataType
2442
2488
  uaVariable._internal_set_value(value);
2443
2489
  }