node-opcua-address-space 2.71.0 → 2.72.2

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 (408) hide show
  1. package/dist/source/address_space_ts.d.ts +118 -118
  2. package/dist/source/address_space_ts.js +17 -17
  3. package/dist/source/continuation_points/continuation_point_manager.d.ts +32 -32
  4. package/dist/source/continuation_points/continuation_point_manager.js +195 -195
  5. package/dist/source/helpers/adjust_browse_direction.d.ts +5 -5
  6. package/dist/source/helpers/adjust_browse_direction.js +11 -11
  7. package/dist/source/helpers/argument_list.d.ts +34 -34
  8. package/dist/source/helpers/argument_list.js +285 -285
  9. package/dist/source/helpers/call_helpers.d.ts +6 -6
  10. package/dist/source/helpers/call_helpers.js +70 -70
  11. package/dist/source/helpers/check_event_clause.d.ts +17 -17
  12. package/dist/source/helpers/check_event_clause.js +52 -52
  13. package/dist/source/helpers/coerce_enum_value.d.ts +6 -6
  14. package/dist/source/helpers/coerce_enum_value.js +33 -33
  15. package/dist/source/helpers/dump_tools.d.ts +14 -14
  16. package/dist/source/helpers/dump_tools.js +78 -78
  17. package/dist/source/helpers/ensure_secure_access.d.ts +9 -9
  18. package/dist/source/helpers/ensure_secure_access.js +76 -76
  19. package/dist/source/helpers/make_optionals_map.d.ts +21 -21
  20. package/dist/source/helpers/make_optionals_map.js +29 -29
  21. package/dist/source/helpers/multiform_func.d.ts +11 -11
  22. package/dist/source/helpers/multiform_func.js +73 -73
  23. package/dist/source/helpers/resolve_opaque_on_address_space.d.ts +3 -3
  24. package/dist/source/helpers/resolve_opaque_on_address_space.js +36 -36
  25. package/dist/source/index.d.ts +40 -40
  26. package/dist/source/index.js +66 -66
  27. package/dist/source/interfaces/alarms_and_conditions/condition_info_i.d.ts +12 -12
  28. package/dist/source/interfaces/alarms_and_conditions/condition_info_i.js +2 -2
  29. package/dist/source/interfaces/data_access/ua_multistate_discrete_ex.d.ts +21 -21
  30. package/dist/source/interfaces/data_access/ua_multistate_discrete_ex.js +2 -2
  31. package/dist/source/interfaces/data_access/ua_multistate_value_discrete_ex.d.ts +24 -24
  32. package/dist/source/interfaces/data_access/ua_multistate_value_discrete_ex.js +2 -2
  33. package/dist/source/interfaces/data_access/ua_two_state_discrete_ex.d.ts +12 -12
  34. package/dist/source/interfaces/data_access/ua_two_state_discrete_ex.js +2 -2
  35. package/dist/source/interfaces/data_access/ua_y_array_item_ex.d.ts +8 -8
  36. package/dist/source/interfaces/data_access/ua_y_array_item_ex.js +2 -2
  37. package/dist/source/interfaces/state_machine/ua_exclusive_limit_state_machine_type_ex.d.ts +12 -12
  38. package/dist/source/interfaces/state_machine/ua_exclusive_limit_state_machine_type_ex.js +2 -2
  39. package/dist/source/interfaces/state_machine/ua_finite_state_machine_type.d.ts +49 -49
  40. package/dist/source/interfaces/state_machine/ua_finite_state_machine_type.js +2 -2
  41. package/dist/source/interfaces/state_machine/ua_program_state_machine_type.d.ts +11 -11
  42. package/dist/source/interfaces/state_machine/ua_program_state_machine_type.js +2 -2
  43. package/dist/source/interfaces/state_machine/ua_state_machine_type.d.ts +222 -222
  44. package/dist/source/interfaces/state_machine/ua_state_machine_type.js +2 -2
  45. package/dist/source/interfaces/state_machine/ua_transition_ex.d.ts +6 -6
  46. package/dist/source/interfaces/state_machine/ua_transition_ex.js +2 -2
  47. package/dist/source/interfaces/ua_subscription_diagnostics_variable_ex.d.ts +8 -8
  48. package/dist/source/interfaces/ua_subscription_diagnostics_variable_ex.js +2 -2
  49. package/dist/source/loader/decode_xml_extension_object.d.ts +6 -6
  50. package/dist/source/loader/decode_xml_extension_object.js +71 -71
  51. package/dist/source/loader/ensure_datatype_extracted.d.ts +5 -5
  52. package/dist/source/loader/ensure_datatype_extracted.js +45 -45
  53. package/dist/source/loader/generateAddressSpaceRaw.d.ts +10 -10
  54. package/dist/source/loader/generateAddressSpaceRaw.js +45 -45
  55. package/dist/source/loader/load_nodeset2.d.ts +16 -16
  56. package/dist/source/loader/load_nodeset2.js +1468 -1464
  57. package/dist/source/loader/load_nodeset2.js.map +1 -1
  58. package/dist/source/loader/make_semver_compatible.d.ts +6 -0
  59. package/dist/source/loader/make_semver_compatible.js +26 -0
  60. package/dist/source/loader/make_semver_compatible.js.map +1 -0
  61. package/dist/source/loader/make_xml_extension_object_parser.d.ts +28 -28
  62. package/dist/source/loader/make_xml_extension_object_parser.js +325 -315
  63. package/dist/source/loader/make_xml_extension_object_parser.js.map +1 -1
  64. package/dist/source/loader/namespace_post_step.d.ts +6 -6
  65. package/dist/source/loader/namespace_post_step.js +47 -47
  66. package/dist/source/loader/register_node_promoter.d.ts +3 -3
  67. package/dist/source/loader/register_node_promoter.js +9 -9
  68. package/dist/source/namespace.d.ts +6 -6
  69. package/dist/source/namespace.js +2 -2
  70. package/dist/source/namespace_alarm_and_condition.d.ts +24 -24
  71. package/dist/source/namespace_alarm_and_condition.js +2 -2
  72. package/dist/source/namespace_data_access.d.ts +42 -42
  73. package/dist/source/namespace_data_access.js +2 -2
  74. package/dist/source/namespace_machine_state.d.ts +7 -7
  75. package/dist/source/namespace_machine_state.js +2 -2
  76. package/dist/source/pseudo_session.d.ts +55 -55
  77. package/dist/source/pseudo_session.js +203 -203
  78. package/dist/source/session_context.d.ts +111 -111
  79. package/dist/source/session_context.js +265 -265
  80. package/dist/source/set_namespace_meta_data.d.ts +2 -2
  81. package/dist/source/set_namespace_meta_data.js +59 -59
  82. package/dist/source/ua_root_folder.d.ts +9 -9
  83. package/dist/source/ua_root_folder.js +2 -2
  84. package/dist/source/ua_two_state_variable_ex.d.ts +23 -23
  85. package/dist/source/ua_two_state_variable_ex.js +2 -2
  86. package/dist/source/xml_writer.d.ts +9 -9
  87. package/dist/source/xml_writer.js +2 -2
  88. package/dist/src/address_space.d.ts +392 -392
  89. package/dist/src/address_space.js +1387 -1387
  90. package/dist/src/address_space_change_event_tools.d.ts +6 -6
  91. package/dist/src/address_space_change_event_tools.js +149 -149
  92. package/dist/src/address_space_private.d.ts +43 -43
  93. package/dist/src/address_space_private.js +2 -2
  94. package/dist/src/alarms_and_conditions/check_where_clause.d.ts +4 -4
  95. package/dist/src/alarms_and_conditions/check_where_clause.js +109 -109
  96. package/dist/src/alarms_and_conditions/condition.d.ts +5 -5
  97. package/dist/src/alarms_and_conditions/condition.js +80 -80
  98. package/dist/src/alarms_and_conditions/condition_info.d.ts +27 -27
  99. package/dist/src/alarms_and_conditions/condition_info.js +54 -54
  100. package/dist/src/alarms_and_conditions/condition_snapshot.d.ts +233 -233
  101. package/dist/src/alarms_and_conditions/condition_snapshot.js +666 -666
  102. package/dist/src/alarms_and_conditions/deviation_alarm_helper.d.ts +21 -21
  103. package/dist/src/alarms_and_conditions/deviation_alarm_helper.js +46 -46
  104. package/dist/src/alarms_and_conditions/extract_event_fields.d.ts +10 -10
  105. package/dist/src/alarms_and_conditions/extract_event_fields.js +89 -89
  106. package/dist/src/alarms_and_conditions/index.d.ts +18 -18
  107. package/dist/src/alarms_and_conditions/index.js +34 -34
  108. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.d.ts +64 -62
  109. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js +244 -244
  110. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js.map +1 -1
  111. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.d.ts +124 -118
  112. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js +416 -416
  113. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js.map +1 -1
  114. package/dist/src/alarms_and_conditions/ua_base_event_impl.d.ts +29 -29
  115. package/dist/src/alarms_and_conditions/ua_base_event_impl.js +38 -38
  116. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.d.ts +36 -21
  117. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.js +115 -25
  118. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.js.map +1 -1
  119. package/dist/src/alarms_and_conditions/ua_condition_impl.d.ts +187 -182
  120. package/dist/src/alarms_and_conditions/ua_condition_impl.js +1024 -1022
  121. package/dist/src/alarms_and_conditions/ua_condition_impl.js.map +1 -1
  122. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.d.ts +18 -17
  123. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.js +57 -57
  124. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.js.map +1 -1
  125. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.d.ts +30 -27
  126. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.js +56 -56
  127. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.js.map +1 -1
  128. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.d.ts +11 -9
  129. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.js +11 -11
  130. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.js.map +1 -1
  131. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.d.ts +40 -38
  132. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.js +86 -86
  133. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.js.map +1 -1
  134. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm_impl.d.ts +10 -10
  135. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm_impl.js +7 -7
  136. package/dist/src/alarms_and_conditions/ua_limit_alarm_impl.d.ts +105 -97
  137. package/dist/src/alarms_and_conditions/ua_limit_alarm_impl.js +250 -250
  138. package/dist/src/alarms_and_conditions/ua_limit_alarm_impl.js.map +1 -1
  139. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.d.ts +29 -28
  140. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.js +50 -50
  141. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.js.map +1 -1
  142. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.d.ts +26 -25
  143. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.js +162 -162
  144. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.js.map +1 -1
  145. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.d.ts +48 -39
  146. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js +161 -135
  147. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js.map +1 -1
  148. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.d.ts +17 -16
  149. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.js +17 -17
  150. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.js.map +1 -1
  151. package/dist/src/apply_condition_refresh.d.ts +6 -6
  152. package/dist/src/apply_condition_refresh.js +27 -27
  153. package/dist/src/base_node_impl.d.ts +281 -281
  154. package/dist/src/base_node_impl.js +1395 -1395
  155. package/dist/src/base_node_private.d.ts +61 -61
  156. package/dist/src/base_node_private.js +705 -705
  157. package/dist/src/data_access/add_dataItem_stuff.d.ts +11 -11
  158. package/dist/src/data_access/add_dataItem_stuff.js +61 -61
  159. package/dist/src/data_access/check_variant_compatibility_ua_analog_item.d.ts +1 -1
  160. package/dist/src/data_access/check_variant_compatibility_ua_analog_item.js +34 -34
  161. package/dist/src/data_access/ua_multistate_discrete_impl.d.ts +32 -32
  162. package/dist/src/data_access/ua_multistate_discrete_impl.js +130 -130
  163. package/dist/src/data_access/ua_multistate_value_discrete.d.ts +51 -51
  164. package/dist/src/data_access/ua_multistate_value_discrete.js +249 -249
  165. package/dist/src/data_access/ua_two_state_discrete.d.ts +25 -25
  166. package/dist/src/data_access/ua_two_state_discrete.js +153 -153
  167. package/dist/src/event_data.d.ts +29 -29
  168. package/dist/src/event_data.js +95 -95
  169. package/dist/src/extension_object_array_node.d.ts +61 -61
  170. package/dist/src/extension_object_array_node.js +276 -276
  171. package/dist/src/historical_access/address_space_historical_data_node.d.ts +26 -26
  172. package/dist/src/historical_access/address_space_historical_data_node.js +630 -630
  173. package/dist/src/index_current.d.ts +45 -45
  174. package/dist/src/index_current.js +77 -77
  175. package/dist/src/namespace_impl.d.ts +457 -457
  176. package/dist/src/namespace_impl.js +1733 -1733
  177. package/dist/src/namespace_private.d.ts +21 -21
  178. package/dist/src/namespace_private.js +32 -32
  179. package/dist/src/nodeid_manager.d.ts +36 -36
  180. package/dist/src/nodeid_manager.js +197 -197
  181. package/dist/src/nodeset_tools/adjust_namespace_array.d.ts +2 -2
  182. package/dist/src/nodeset_tools/adjust_namespace_array.js +13 -13
  183. package/dist/src/nodeset_tools/construct_namespace_dependency.d.ts +2 -2
  184. package/dist/src/nodeset_tools/construct_namespace_dependency.js +83 -83
  185. package/dist/src/nodeset_tools/nodeset_to_xml.d.ts +2 -2
  186. package/dist/src/nodeset_tools/nodeset_to_xml.js +1143 -1143
  187. package/dist/src/nodeset_tools/typedictionary_to_xml.d.ts +2 -2
  188. package/dist/src/nodeset_tools/typedictionary_to_xml.js +154 -154
  189. package/dist/src/reference_impl.d.ts +43 -43
  190. package/dist/src/reference_impl.js +139 -139
  191. package/dist/src/role_permissions.d.ts +2 -2
  192. package/dist/src/role_permissions.js +10 -10
  193. package/dist/src/state_machine/finite_state_machine.d.ts +67 -67
  194. package/dist/src/state_machine/finite_state_machine.js +353 -353
  195. package/dist/src/state_machine/ua_shelving_state_machine_ex.d.ts +34 -34
  196. package/dist/src/state_machine/ua_shelving_state_machine_ex.js +250 -250
  197. package/dist/src/state_machine/ua_two_state_variable.d.ts +61 -61
  198. package/dist/src/state_machine/ua_two_state_variable.js +331 -331
  199. package/dist/src/tool_isSupertypeOf.d.ts +17 -17
  200. package/dist/src/tool_isSupertypeOf.js +108 -108
  201. package/dist/src/ua_condition_type.d.ts +8 -8
  202. package/dist/src/ua_condition_type.js +2 -2
  203. package/dist/src/ua_data_type_impl.d.ts +93 -93
  204. package/dist/src/ua_data_type_impl.js +368 -368
  205. package/dist/src/ua_method_impl.d.ts +41 -41
  206. package/dist/src/ua_method_impl.js +208 -208
  207. package/dist/src/ua_object_impl.d.ts +35 -33
  208. package/dist/src/ua_object_impl.js +162 -156
  209. package/dist/src/ua_object_impl.js.map +1 -1
  210. package/dist/src/ua_object_type_impl.d.ts +48 -48
  211. package/dist/src/ua_object_type_impl.js +124 -124
  212. package/dist/src/ua_reference_type_impl.d.ts +43 -43
  213. package/dist/src/ua_reference_type_impl.js +139 -139
  214. package/dist/src/ua_variable_impl.d.ts +351 -351
  215. package/dist/src/ua_variable_impl.js +1604 -1604
  216. package/dist/src/ua_variable_impl_ext_obj.d.ts +17 -17
  217. package/dist/src/ua_variable_impl_ext_obj.js +437 -437
  218. package/dist/src/ua_variable_type_impl.d.ts +62 -62
  219. package/dist/src/ua_variable_type_impl.js +570 -570
  220. package/dist/src/ua_view_impl.d.ts +19 -15
  221. package/dist/src/ua_view_impl.js +43 -36
  222. package/dist/src/ua_view_impl.js.map +1 -1
  223. package/distHelpers/add_event_generator_object.d.ts +3 -3
  224. package/distHelpers/add_event_generator_object.js +65 -65
  225. package/distHelpers/alarms_and_conditions_demo.d.ts +10 -10
  226. package/distHelpers/alarms_and_conditions_demo.js +114 -114
  227. package/distHelpers/assertHasMatchingReference.d.ts +19 -19
  228. package/distHelpers/assertHasMatchingReference.js +40 -40
  229. package/distHelpers/boiler_system.d.ts +113 -113
  230. package/distHelpers/boiler_system.js +395 -395
  231. package/distHelpers/create_minimalist_address_space_nodeset.d.ts +5 -5
  232. package/distHelpers/create_minimalist_address_space_nodeset.js +171 -171
  233. package/distHelpers/date_utils.d.ts +3 -3
  234. package/distHelpers/date_utils.js +9 -9
  235. package/distHelpers/dump_statemachine.js +127 -127
  236. package/distHelpers/get_address_space_fixture.d.ts +1 -1
  237. package/distHelpers/get_address_space_fixture.js +30 -30
  238. package/distHelpers/get_mini_address_space.d.ts +7 -7
  239. package/distHelpers/get_mini_address_space.js +36 -36
  240. package/distHelpers/index.d.ts +12 -12
  241. package/distHelpers/index.js +28 -28
  242. package/distHelpers/mock_session.d.ts +14 -14
  243. package/distHelpers/mock_session.js +25 -25
  244. package/distNodeJS/generate_address_space.d.ts +4 -4
  245. package/distNodeJS/generate_address_space.js +41 -41
  246. package/distNodeJS/index.d.ts +1 -1
  247. package/distNodeJS/index.js +17 -17
  248. package/package.json +23 -23
  249. package/source/loader/load_nodeset2.ts +21 -17
  250. package/source/loader/make_semver_compatible.ts +23 -0
  251. package/source/loader/make_xml_extension_object_parser.ts +16 -6
  252. package/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.ts +13 -6
  253. package/src/alarms_and_conditions/ua_alarm_condition_impl.ts +15 -10
  254. package/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.ts +126 -10
  255. package/src/alarms_and_conditions/ua_condition_impl.ts +26 -13
  256. package/src/alarms_and_conditions/ua_discrete_alarm_impl.ts +10 -4
  257. package/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.ts +7 -6
  258. package/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.ts +5 -3
  259. package/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.ts +7 -6
  260. package/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm_impl.ts +1 -1
  261. package/src/alarms_and_conditions/ua_limit_alarm_impl.ts +23 -13
  262. package/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.ts +6 -7
  263. package/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.ts +6 -7
  264. package/src/alarms_and_conditions/ua_off_normal_alarm_impl.ts +62 -30
  265. package/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.ts +5 -5
  266. package/src/ua_object_impl.ts +11 -3
  267. package/src/ua_view_impl.ts +6 -4
  268. package/test_helpers/test_fixtures/dataType_issue.xml +9 -9
  269. package/test_helpers/test_fixtures/nodeset_with_guid.xml +1442 -0
  270. package/test_helpers/test_fixtures/nodeset_with_int64_values.xml +31 -0
  271. package/dist/source/interfaces/alarms_and_conditions/ua_condition_base_i.d.ts +0 -23
  272. package/dist/source/interfaces/alarms_and_conditions/ua_condition_base_i.js +0 -3
  273. package/dist/source/interfaces/alarms_and_conditions/ua_condition_base_i.js.map +0 -1
  274. package/dist/source/interfaces/data_access/ua_discrete_item.d.ts +0 -6
  275. package/dist/source/interfaces/data_access/ua_discrete_item.js +0 -3
  276. package/dist/source/interfaces/data_access/ua_discrete_item.js.map +0 -1
  277. package/dist/source/interfaces/data_access/ua_multistate_discrete.d.ts +0 -25
  278. package/dist/source/interfaces/data_access/ua_multistate_discrete.js +0 -3
  279. package/dist/source/interfaces/data_access/ua_multistate_discrete.js.map +0 -1
  280. package/dist/source/interfaces/data_access/ua_multistate_value_discrete.d.ts +0 -27
  281. package/dist/source/interfaces/data_access/ua_multistate_value_discrete.js +0 -3
  282. package/dist/source/interfaces/data_access/ua_multistate_value_discrete.js.map +0 -1
  283. package/dist/source/interfaces/data_access/ua_two_state_discrete.d.ts +0 -17
  284. package/dist/source/interfaces/data_access/ua_two_state_discrete.js +0 -3
  285. package/dist/source/interfaces/data_access/ua_two_state_discrete.js.map +0 -1
  286. package/dist/source/interfaces/data_access/ua_y_array_item.d.ts +0 -19
  287. package/dist/source/interfaces/data_access/ua_y_array_item.js +0 -3
  288. package/dist/source/interfaces/data_access/ua_y_array_item.js.map +0 -1
  289. package/dist/source/interfaces/state_machine/exclusive_limit_state_machine.d.ts +0 -11
  290. package/dist/source/interfaces/state_machine/exclusive_limit_state_machine.js +0 -3
  291. package/dist/source/interfaces/state_machine/exclusive_limit_state_machine.js.map +0 -1
  292. package/dist/source/interfaces/state_machine/finite_state_machine.d.ts +0 -70
  293. package/dist/source/interfaces/state_machine/finite_state_machine.js +0 -3
  294. package/dist/source/interfaces/state_machine/finite_state_machine.js.map +0 -1
  295. package/dist/source/interfaces/state_machine/program_finite_state_machine.d.ts +0 -74
  296. package/dist/source/interfaces/state_machine/program_finite_state_machine.js +0 -3
  297. package/dist/source/interfaces/state_machine/program_finite_state_machine.js.map +0 -1
  298. package/dist/source/interfaces/state_machine/state_machine.d.ts +0 -342
  299. package/dist/source/interfaces/state_machine/state_machine.js +0 -3
  300. package/dist/source/interfaces/state_machine/state_machine.js.map +0 -1
  301. package/dist/source/interfaces/state_machine/ua_finite_state_variable.d.ts +0 -18
  302. package/dist/source/interfaces/state_machine/ua_finite_state_variable.js +0 -3
  303. package/dist/source/interfaces/state_machine/ua_finite_state_variable.js.map +0 -1
  304. package/dist/source/interfaces/state_machine/ua_state_variable.d.ts +0 -29
  305. package/dist/source/interfaces/state_machine/ua_state_variable.js +0 -3
  306. package/dist/source/interfaces/state_machine/ua_state_variable.js.map +0 -1
  307. package/dist/source/interfaces/state_machine/ua_two_state_variable.d.ts +0 -26
  308. package/dist/source/interfaces/state_machine/ua_two_state_variable.js +0 -3
  309. package/dist/source/interfaces/state_machine/ua_two_state_variable.js.map +0 -1
  310. package/dist/source/interfaces/subscription_diagnostics_variable.d.ts +0 -41
  311. package/dist/source/interfaces/subscription_diagnostics_variable.js +0 -3
  312. package/dist/source/interfaces/subscription_diagnostics_variable.js.map +0 -1
  313. package/dist/src/alarms_and_conditions/base_event_type.d.ts +0 -26
  314. package/dist/src/alarms_and_conditions/base_event_type.js +0 -41
  315. package/dist/src/alarms_and_conditions/base_event_type.js.map +0 -1
  316. package/dist/src/alarms_and_conditions/shelving_state_machine.d.ts +0 -22
  317. package/dist/src/alarms_and_conditions/shelving_state_machine.js +0 -241
  318. package/dist/src/alarms_and_conditions/shelving_state_machine.js.map +0 -1
  319. package/dist/src/alarms_and_conditions/trip_alarm.d.ts +0 -16
  320. package/dist/src/alarms_and_conditions/trip_alarm.js +0 -21
  321. package/dist/src/alarms_and_conditions/trip_alarm.js.map +0 -1
  322. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_base.d.ts +0 -54
  323. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_base.js +0 -255
  324. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_base.js.map +0 -1
  325. package/dist/src/alarms_and_conditions/ua_alarm_condition_base.d.ts +0 -138
  326. package/dist/src/alarms_and_conditions/ua_alarm_condition_base.js +0 -460
  327. package/dist/src/alarms_and_conditions/ua_alarm_condition_base.js.map +0 -1
  328. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm.d.ts +0 -35
  329. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm.js +0 -32
  330. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm.js.map +0 -1
  331. package/dist/src/alarms_and_conditions/ua_condition_base.d.ts +0 -191
  332. package/dist/src/alarms_and_conditions/ua_condition_base.js +0 -1029
  333. package/dist/src/alarms_and_conditions/ua_condition_base.js.map +0 -1
  334. package/dist/src/alarms_and_conditions/ua_discrete_alarm.d.ts +0 -11
  335. package/dist/src/alarms_and_conditions/ua_discrete_alarm.js +0 -58
  336. package/dist/src/alarms_and_conditions/ua_discrete_alarm.js.map +0 -1
  337. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm.d.ts +0 -24
  338. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm.js +0 -59
  339. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm.js.map +0 -1
  340. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm.d.ts +0 -14
  341. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm.js +0 -17
  342. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm.js.map +0 -1
  343. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm.d.ts +0 -22
  344. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm.js +0 -87
  345. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm.js.map +0 -1
  346. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm.d.ts +0 -6
  347. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm.js +0 -11
  348. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm.js.map +0 -1
  349. package/dist/src/alarms_and_conditions/ua_limit_alarm.d.ts +0 -76
  350. package/dist/src/alarms_and_conditions/ua_limit_alarm.js +0 -237
  351. package/dist/src/alarms_and_conditions/ua_limit_alarm.js.map +0 -1
  352. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm.d.ts +0 -27
  353. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm.js +0 -62
  354. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm.js.map +0 -1
  355. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm.d.ts +0 -49
  356. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm.js +0 -176
  357. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm.js.map +0 -1
  358. package/dist/src/alarms_and_conditions/ua_off_normal_alarm.d.ts +0 -47
  359. package/dist/src/alarms_and_conditions/ua_off_normal_alarm.js +0 -151
  360. package/dist/src/alarms_and_conditions/ua_off_normal_alarm.js.map +0 -1
  361. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm.d.ts +0 -16
  362. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm.js +0 -18
  363. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm.js.map +0 -1
  364. package/dist/src/base_node.d.ts +0 -270
  365. package/dist/src/base_node.js +0 -1299
  366. package/dist/src/base_node.js.map +0 -1
  367. package/dist/src/data_access/ua_analog_item.d.ts +0 -13
  368. package/dist/src/data_access/ua_analog_item.js +0 -37
  369. package/dist/src/data_access/ua_analog_item.js.map +0 -1
  370. package/dist/src/data_access/ua_data_item.d.ts +0 -16
  371. package/dist/src/data_access/ua_data_item.js +0 -66
  372. package/dist/src/data_access/ua_data_item.js.map +0 -1
  373. package/dist/src/data_access/ua_multistate_discrete.d.ts +0 -24
  374. package/dist/src/data_access/ua_multistate_discrete.js +0 -132
  375. package/dist/src/data_access/ua_multistate_discrete.js.map +0 -1
  376. package/dist/src/namespace.d.ts +0 -472
  377. package/dist/src/namespace.js +0 -1759
  378. package/dist/src/namespace.js.map +0 -1
  379. package/dist/src/reference.d.ts +0 -43
  380. package/dist/src/reference.js +0 -138
  381. package/dist/src/reference.js.map +0 -1
  382. package/dist/src/session_context.d.ts +0 -4
  383. package/dist/src/session_context.js +0 -9
  384. package/dist/src/session_context.js.map +0 -1
  385. package/dist/src/ua_data_type.d.ts +0 -81
  386. package/dist/src/ua_data_type.js +0 -259
  387. package/dist/src/ua_data_type.js.map +0 -1
  388. package/dist/src/ua_method.d.ts +0 -33
  389. package/dist/src/ua_method.js +0 -194
  390. package/dist/src/ua_method.js.map +0 -1
  391. package/dist/src/ua_object.d.ts +0 -27
  392. package/dist/src/ua_object.js +0 -153
  393. package/dist/src/ua_object.js.map +0 -1
  394. package/dist/src/ua_object_type.d.ts +0 -49
  395. package/dist/src/ua_object_type.js +0 -123
  396. package/dist/src/ua_object_type.js.map +0 -1
  397. package/dist/src/ua_reference_type.d.ts +0 -31
  398. package/dist/src/ua_reference_type.js +0 -108
  399. package/dist/src/ua_reference_type.js.map +0 -1
  400. package/dist/src/ua_variable.d.ts +0 -346
  401. package/dist/src/ua_variable.js +0 -1651
  402. package/dist/src/ua_variable.js.map +0 -1
  403. package/dist/src/ua_variable_type.d.ts +0 -57
  404. package/dist/src/ua_variable_type.js +0 -530
  405. package/dist/src/ua_variable_type.js.map +0 -1
  406. package/dist/src/ua_view.d.ts +0 -16
  407. package/dist/src/ua_view.js +0 -41
  408. package/dist/src/ua_view.js.map +0 -1
@@ -1,1605 +1,1605 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UAVariableImplT = exports.UAVariableImpl = exports.adjust_userAccessLevel = exports.adjust_accessLevel = void 0;
4
- /* eslint-disable max-statements */
5
- /* eslint-disable complexity */
6
- /**
7
- * @module node-opcua-address-space
8
- */
9
- // tslint:disable:no-bitwise
10
- // tslint:disable:no-console
11
- // tslint:disable:max-line-length
12
- const chalk = require("chalk");
13
- const node_opcua_address_space_base_1 = require("node-opcua-address-space-base");
14
- const node_opcua_assert_1 = require("node-opcua-assert");
15
- const node_opcua_data_model_1 = require("node-opcua-data-model");
16
- const node_opcua_data_value_1 = require("node-opcua-data-value");
17
- const node_opcua_date_time_1 = require("node-opcua-date-time");
18
- const node_opcua_debug_1 = require("node-opcua-debug");
19
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
20
- const node_opcua_numeric_range_1 = require("node-opcua-numeric-range");
21
- const node_opcua_service_write_1 = require("node-opcua-service-write");
22
- const node_opcua_status_code_1 = require("node-opcua-status-code");
23
- const node_opcua_types_1 = require("node-opcua-types");
24
- const utils = require("node-opcua-utils");
25
- const node_opcua_variant_1 = require("node-opcua-variant");
26
- const session_context_1 = require("../source/session_context");
27
- const multiform_func_1 = require("../source/helpers/multiform_func");
28
- const base_node_impl_1 = require("./base_node_impl");
29
- const base_node_private_1 = require("./base_node_private");
30
- const ua_data_type_impl_1 = require("./ua_data_type_impl");
31
- const apply_condition_refresh_1 = require("./apply_condition_refresh");
32
- const ua_variable_impl_ext_obj_1 = require("./ua_variable_impl_ext_obj");
33
- const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
34
- const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
35
- const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
36
- const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
37
- function isGoodish(statusCode) {
38
- return statusCode.value < 0x10000000;
39
- }
40
- function adjust_accessLevel(accessLevel) {
41
- accessLevel = utils.isNullOrUndefined(accessLevel) ? "CurrentRead | CurrentWrite" : accessLevel;
42
- accessLevel = (0, node_opcua_data_model_1.makeAccessLevelFlag)(accessLevel);
43
- (0, node_opcua_assert_1.assert)(isFinite(accessLevel));
44
- return accessLevel;
45
- }
46
- exports.adjust_accessLevel = adjust_accessLevel;
47
- function adjust_userAccessLevel(userAccessLevel, accessLevel) {
48
- if (userAccessLevel === undefined) {
49
- return undefined;
50
- }
51
- userAccessLevel = adjust_accessLevel(userAccessLevel);
52
- accessLevel = adjust_accessLevel(accessLevel);
53
- return (0, node_opcua_data_model_1.makeAccessLevelFlag)(accessLevel & userAccessLevel);
54
- }
55
- exports.adjust_userAccessLevel = adjust_userAccessLevel;
56
- function adjust_samplingInterval(minimumSamplingInterval) {
57
- (0, node_opcua_assert_1.assert)(isFinite(minimumSamplingInterval));
58
- if (minimumSamplingInterval < 0) {
59
- return -1; // only -1 is a valid negative value for samplingInterval and means "unspecified"
60
- }
61
- return minimumSamplingInterval;
62
- }
63
- function is_Variant(v) {
64
- return v instanceof node_opcua_variant_1.Variant;
65
- }
66
- function is_StatusCode(v) {
67
- return (v &&
68
- v.constructor &&
69
- (v.constructor.name === "ConstantStatusCode" ||
70
- v.constructor.name === "StatusCode" ||
71
- v.constructor.name === "ModifiableStatusCode"));
72
- }
73
- function is_Variant_or_StatusCode(v) {
74
- if (is_Variant(v)) {
75
- // /@@assert(v.isValid());
76
- }
77
- return is_Variant(v) || is_StatusCode(v);
78
- }
79
- function _dataType_toUADataType(addressSpace, dataType) {
80
- (0, node_opcua_assert_1.assert)(addressSpace);
81
- (0, node_opcua_assert_1.assert)(dataType !== node_opcua_variant_1.DataType.Null);
82
- const dataTypeNode = addressSpace.findDataType(node_opcua_variant_1.DataType[dataType]);
83
- /* istanbul ignore next */
84
- if (!dataTypeNode) {
85
- throw new Error(" Cannot find DataType " + node_opcua_variant_1.DataType[dataType] + " in address Space");
86
- }
87
- return dataTypeNode;
88
- }
89
- /*=
90
- *
91
- * @param addressSpace
92
- * @param dataTypeNodeId : the nodeId matching the dataType of the destination variable.
93
- * @param variantDataType: the dataType of the variant to write to the destination variable
94
- * @param nodeId
95
- * @return {boolean} true if the variant dataType is compatible with the Variable DataType
96
- */
97
- function validateDataType(addressSpace, dataTypeNodeId, variantDataType, nodeId, allowNulls) {
98
- if (variantDataType === node_opcua_variant_1.DataType.ExtensionObject) {
99
- return true;
100
- }
101
- if (variantDataType === node_opcua_variant_1.DataType.Null && allowNulls) {
102
- return true;
103
- }
104
- if (variantDataType === node_opcua_variant_1.DataType.Null && !allowNulls) {
105
- return false;
106
- }
107
- let builtInType;
108
- let builtInUADataType;
109
- const destUADataType = addressSpace.findDataType(dataTypeNodeId);
110
- (0, node_opcua_assert_1.assert)(destUADataType instanceof ua_data_type_impl_1.UADataTypeImpl);
111
- if (destUADataType.isAbstract || destUADataType.nodeId.namespace !== 0) {
112
- builtInUADataType = destUADataType;
113
- }
114
- else {
115
- builtInType = addressSpace.findCorrespondingBasicDataType(destUADataType);
116
- builtInUADataType = addressSpace.findDataType(builtInType);
117
- }
118
- (0, node_opcua_assert_1.assert)(builtInUADataType instanceof ua_data_type_impl_1.UADataTypeImpl);
119
- const enumerationUADataType = addressSpace.findDataType("Enumeration");
120
- if (!enumerationUADataType) {
121
- throw new Error("cannot find Enumeration DataType node in standard address space");
122
- }
123
- if (destUADataType.isSupertypeOf(enumerationUADataType)) {
124
- // istanbul ignore next
125
- if (doDebug) {
126
- debugLog("destUADataType.", destUADataType.browseName.toString(), destUADataType.nodeId.toString());
127
- debugLog("enumerationUADataType.", enumerationUADataType.browseName.toString(), enumerationUADataType.nodeId.toString());
128
- }
129
- return true;
130
- }
131
- // The value supplied for the attribute is not of the same type as the value.
132
- const variantUADataType = _dataType_toUADataType(addressSpace, variantDataType);
133
- (0, node_opcua_assert_1.assert)(variantUADataType instanceof ua_data_type_impl_1.UADataTypeImpl);
134
- const dest_isSuperTypeOf_variant = variantUADataType.isSupertypeOf(builtInUADataType);
135
- /* istanbul ignore next */
136
- if (doDebug) {
137
- if (dest_isSuperTypeOf_variant) {
138
- /* istanbul ignore next*/
139
- debugLog(chalk.green(" ---------- Type match !!! "), " on ", nodeId.toString());
140
- }
141
- else {
142
- /* istanbul ignore next*/
143
- debugLog(chalk.red(" ---------- Type mismatch "), " on ", nodeId.toString());
144
- }
145
- debugLog(chalk.cyan(" Variable data Type is = "), destUADataType.browseName.toString());
146
- debugLog(chalk.cyan(" which matches basic Type = "), builtInUADataType.browseName.toString());
147
- debugLog(chalk.yellow(" Actual dataType = "), variantUADataType.browseName.toString());
148
- }
149
- return dest_isSuperTypeOf_variant;
150
- }
151
- function default_func(dataValue1, callback1) {
152
- return _default_writable_timestamped_set_func.call(this, dataValue1, callback1);
153
- }
154
- /**
155
- * A OPCUA Variable Node
156
- *
157
- * @class UAVariable
158
- * @constructor
159
- * @extends BaseNode
160
- * The AccessLevel Attribute is used to indicate how the Value of a Variable can be accessed (read/write) and if it
161
- * contains current and/or historic data. The AccessLevel does not take any user access rights into account,
162
- * i.e. although the Variable is writable this may be restricted to a certain user / user group.
163
- * The AccessLevel is an 8-bit unsigned integer with the structure defined in the following table:
164
- *
165
- * Field Bit Description
166
- * CurrentRead 0 Indicates if the current value is readable
167
- * (0 means not readable, 1 means readable).
168
- * CurrentWrite 1 Indicates if the current value is writable
169
- * (0 means not writable, 1 means writable).
170
- * HistoryRead 2 Indicates if the history of the value is readable
171
- * (0 means not readable, 1 means readable).
172
- * HistoryWrite 3 Indicates if the history of the value is writable (0 means not writable, 1 means writable).
173
- * SemanticChange 4 Indicates if the Variable used as Property generates SemanticChangeEvents (see 9.31).
174
- * Reserved 5:7 Reserved for future use. Shall always be zero.
175
- *
176
- * The first two bits also indicate if a current value of this Variable is available and the second two bits
177
- * indicates if the history of the Variable is available via the OPC UA server.
178
- *
179
- */
180
- class UAVariableImpl extends base_node_impl_1.BaseNodeImpl {
181
- constructor(options) {
182
- super(options);
183
- this.nodeClass = node_opcua_data_model_1.NodeClass.Variable;
184
- (0, node_opcua_variant_1.verifyRankAndDimensions)(options);
185
- this.valueRank = options.valueRank;
186
- this.arrayDimensions = options.arrayDimensions;
187
- this.dataType = this.resolveNodeId(options.dataType); // DataType (NodeId)
188
- this.accessLevel = adjust_accessLevel(options.accessLevel);
189
- this.userAccessLevel = adjust_userAccessLevel(options.userAccessLevel, this.accessLevel);
190
- this.minimumSamplingInterval = adjust_samplingInterval(options.minimumSamplingInterval || 0);
191
- this.historizing = !!options.historizing; // coerced to boolean"
192
- this.$dataValue = new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.UncertainInitialValue, value: { dataType: node_opcua_variant_1.DataType.Null } });
193
- if (options.value) {
194
- this.bindVariable(options.value);
195
- }
196
- this.setMaxListeners(5000);
197
- this.semantic_version = 0;
198
- }
199
- get typeDefinitionObj() {
200
- return super.typeDefinitionObj;
201
- }
202
- get typeDefinition() {
203
- return super.typeDefinition;
204
- }
205
- checkPermissionAndAccessLevelPrivate(context, permission, accessLevel) {
206
- (0, node_opcua_assert_1.assert)(context instanceof session_context_1.SessionContext);
207
- if (context.checkPermission) {
208
- (0, node_opcua_assert_1.assert)(context.checkPermission instanceof Function);
209
- if (!context.checkPermission(this, permission)) {
210
- return false;
211
- }
212
- }
213
- if (this.userAccessLevel === undefined) {
214
- return true;
215
- }
216
- return (this.userAccessLevel & accessLevel) === accessLevel;
217
- }
218
- isReadable(context) {
219
- return (this.accessLevel & node_opcua_data_model_1.AccessLevelFlag.CurrentRead) === node_opcua_data_model_1.AccessLevelFlag.CurrentRead;
220
- }
221
- isUserReadable(context) {
222
- if (!this.isReadable(context)) {
223
- return false;
224
- }
225
- return this.checkPermissionAndAccessLevelPrivate(context, node_opcua_types_1.PermissionType.Read, node_opcua_data_model_1.AccessLevelFlag.CurrentRead);
226
- }
227
- isWritable(context) {
228
- return (this.accessLevel & node_opcua_data_model_1.AccessLevelFlag.CurrentWrite) === node_opcua_data_model_1.AccessLevelFlag.CurrentWrite;
229
- }
230
- isUserWritable(context) {
231
- if (!this.isWritable(context)) {
232
- return false;
233
- }
234
- return this.checkPermissionAndAccessLevelPrivate(context, node_opcua_types_1.PermissionType.Write, node_opcua_data_model_1.AccessLevelFlag.CurrentWrite);
235
- }
236
- /**
237
- *
238
- *
239
- * from OPC.UA.Spec 1.02 part 4
240
- * 5.10.2.4 StatusCodes
241
- * Table 51 defines values for the operation level statusCode contained in the DataValue structure of
242
- * each values element. Common StatusCodes are defined in Table 166.
243
- *
244
- * Table 51 Read Operation Level Result Codes
245
- *
246
- * Symbolic Id Description
247
- *
248
- * BadNodeIdInvalid The syntax of the node id is not valid.
249
- * BadNodeIdUnknown The node id refers to a node that does not exist in the server address space.
250
- * BadAttributeIdInvalid BadAttributeIdInvalid The attribute is not supported for the specified node.
251
- * BadIndexRangeInvalid The syntax of the index range parameter is invalid.
252
- * BadIndexRangeNoData No data exists within the range of indexes specified.
253
- * BadDataEncodingInvalid The data encoding is invalid.
254
- * This result is used if no dataEncoding can be applied because an Attribute other
255
- * than Value was requested or the DataType of the Value Attribute is not a subtype
256
- * of the Structure DataType.
257
- * BadDataEncodingUnsupported The server does not support the requested data encoding for the node.
258
- * This result is used if a dataEncoding can be applied but the passed data encoding
259
- * is not known to the Server.
260
- * BadNotReadable The access level does not allow reading or subscribing to the Node.
261
- * BadUserAccessDenied User does not have permission to perform the requested operation. (table 165)
262
- */
263
- readValue(context, indexRange, dataEncoding) {
264
- if (!context) {
265
- context = session_context_1.SessionContext.defaultContext;
266
- }
267
- if (context.isAccessRestricted(this)) {
268
- return new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient });
269
- }
270
- if (!this.isReadable(context)) {
271
- return new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadNotReadable });
272
- }
273
- if (!this.isUserReadable(context)) {
274
- return new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied });
275
- }
276
- if (!(0, node_opcua_data_model_1.isValidDataEncoding)(dataEncoding)) {
277
- return new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadDataEncodingInvalid });
278
- }
279
- if (this._timestamped_get_func) {
280
- if (this._timestamped_get_func.length === 0) {
281
- const dataValueOrPromise = this._timestamped_get_func();
282
- if (!Object.prototype.hasOwnProperty.call(dataValueOrPromise, "then")) {
283
- this.$dataValue = dataValueOrPromise;
284
- this.verifyVariantCompatibility(this.$dataValue.value);
285
- }
286
- else {
287
- errorLog("Unsupported: _timestamped_get_func returns a Promise !");
288
- }
289
- }
290
- }
291
- let dataValue = this.$dataValue;
292
- if (isGoodish(dataValue.statusCode)) {
293
- // note : extractRange will clone the dataValue
294
- dataValue = (0, node_opcua_data_value_1.extractRange)(dataValue, indexRange);
295
- }
296
- /* istanbul ignore next */
297
- if (dataValue.statusCode.equals(node_opcua_status_code_1.StatusCodes.BadWaitingForInitialData) ||
298
- dataValue.statusCode.equals(node_opcua_status_code_1.StatusCodes.UncertainInitialValue)) {
299
- debugLog(chalk.red(" Warning: UAVariable#readValue ") +
300
- chalk.cyan(this.browseName.toString()) +
301
- " (" +
302
- chalk.yellow(this.nodeId.toString()) +
303
- ") exists but dataValue has not been defined");
304
- }
305
- return dataValue;
306
- }
307
- isEnumeration() {
308
- return this.addressSpacePrivate.isEnumeration(this.dataType);
309
- }
310
- isExtensionObject() {
311
- // DataType must be one of Structure
312
- const dataTypeNode = this.addressSpace.findDataType(this.dataType);
313
- if (!dataTypeNode) {
314
- throw new Error(" Cannot find DataType " + this.dataType.toString() + " in standard address Space");
315
- }
316
- const structureNode = this.addressSpace.findDataType("Structure");
317
- if (!structureNode) {
318
- throw new Error(" Cannot find 'Structure' DataType in standard address Space");
319
- }
320
- return dataTypeNode.isSupertypeOf(structureNode);
321
- }
322
- _getEnumerationInfo() {
323
- // DataType must be one of Enumeration
324
- (0, node_opcua_assert_1.assert)(this.isEnumeration(), "Variable is not an enumeration");
325
- const dataTypeNode = this.addressSpace.findDataType(this.dataType);
326
- return dataTypeNode._getEnumerationInfo();
327
- }
328
- asyncRefresh(...args) {
329
- if (isGoodish(this.$dataValue.statusCode)) {
330
- this.verifyVariantCompatibility(this.$dataValue.value);
331
- }
332
- const oldestDate = args[0];
333
- (0, node_opcua_assert_1.assert)(oldestDate instanceof Date);
334
- const callback = args[1];
335
- if (!this.refreshFunc) {
336
- // no refresh func
337
- const dataValue = this.readValue();
338
- dataValue.serverTimestamp = oldestDate;
339
- dataValue.serverPicoseconds = 0;
340
- if (oldestDate.getTime() <= dataValue.serverTimestamp.getTime()) {
341
- return callback(null, dataValue);
342
- }
343
- else {
344
- // fake
345
- return callback(null, dataValue);
346
- }
347
- }
348
- if (this.$dataValue.serverTimestamp && oldestDate.getTime() <= this.$dataValue.serverTimestamp.getTime()) {
349
- const dataValue = this.readValue();
350
- dataValue.serverTimestamp = oldestDate;
351
- dataValue.serverPicoseconds = 0;
352
- return callback(null, dataValue);
353
- }
354
- try {
355
- this.refreshFunc.call(this, (err, dataValue) => {
356
- if (err || !dataValue) {
357
- errorLog("-------------- refresh call failed", this.browseName.toString(), this.nodeId.toString(), err === null || err === void 0 ? void 0 : err.message);
358
- dataValue = { statusCode: node_opcua_status_code_1.StatusCodes.BadNoDataAvailable };
359
- }
360
- if (dataValue !== this.$dataValue) {
361
- this._internal_set_dataValue(coerceDataValue(dataValue), null);
362
- }
363
- callback(err, this.$dataValue);
364
- });
365
- }
366
- catch (err) {
367
- errorLog("-------------- refresh call failed 2", this.browseName.toString(), this.nodeId.toString());
368
- errorLog(err);
369
- const dataValue = new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadInternalError });
370
- this._internal_set_dataValue(dataValue, null);
371
- callback(err, this.$dataValue);
372
- }
373
- }
374
- readEnumValue() {
375
- const value = this.readValue().value.value;
376
- const enumInfo = this._getEnumerationInfo();
377
- const enumV = enumInfo.valueIndex[value];
378
- return { value, name: enumV ? enumV.name : "?????" };
379
- }
380
- writeEnumValue(value) {
381
- const enumInfo = this._getEnumerationInfo();
382
- if (typeof value === "string") {
383
- if (!Object.prototype.hasOwnProperty.call(enumInfo.nameIndex, value)) {
384
- const possibleValues = Object.keys(enumInfo.nameIndex).join(",");
385
- throw new Error("UAVariable#writeEnumValue: cannot find value " + value + " in [" + possibleValues + "]");
386
- }
387
- const valueIndex = enumInfo.nameIndex[value].value;
388
- value = valueIndex;
389
- }
390
- if (isFinite(value)) {
391
- const possibleValues = Object.keys(enumInfo.nameIndex).join(",");
392
- if (!enumInfo.valueIndex[value]) {
393
- throw new Error("UAVariable#writeEnumValue : value out of range " + value + " in [" + possibleValues + "]");
394
- }
395
- this.setValueFromSource({
396
- dataType: node_opcua_variant_1.DataType.Int32,
397
- value
398
- });
399
- }
400
- else {
401
- throw new Error("UAVariable#writeEnumValue: value type mismatch");
402
- }
403
- }
404
- readAttribute(context, attributeId, indexRange, dataEncoding) {
405
- context = context || session_context_1.SessionContext.defaultContext;
406
- (0, node_opcua_assert_1.assert)(context instanceof session_context_1.SessionContext);
407
- const options = {};
408
- if (attributeId !== node_opcua_data_model_1.AttributeIds.Value) {
409
- if (indexRange && indexRange.isDefined()) {
410
- options.statusCode = node_opcua_status_code_1.StatusCodes.BadIndexRangeNoData;
411
- return new node_opcua_data_value_1.DataValue(options);
412
- }
413
- if ((0, node_opcua_data_model_1.isDataEncoding)(dataEncoding)) {
414
- options.statusCode = node_opcua_status_code_1.StatusCodes.BadDataEncodingInvalid;
415
- return new node_opcua_data_value_1.DataValue(options);
416
- }
417
- }
418
- switch (attributeId) {
419
- case node_opcua_data_model_1.AttributeIds.Value:
420
- return this.readValue(context, indexRange, dataEncoding);
421
- case node_opcua_data_model_1.AttributeIds.DataType:
422
- return this._readDataType();
423
- case node_opcua_data_model_1.AttributeIds.ValueRank:
424
- return this._readValueRank();
425
- case node_opcua_data_model_1.AttributeIds.ArrayDimensions:
426
- return this._readArrayDimensions();
427
- case node_opcua_data_model_1.AttributeIds.AccessLevel:
428
- return this._readAccessLevel(context);
429
- case node_opcua_data_model_1.AttributeIds.UserAccessLevel:
430
- return this._readUserAccessLevel(context);
431
- case node_opcua_data_model_1.AttributeIds.MinimumSamplingInterval:
432
- return this._readMinimumSamplingInterval();
433
- case node_opcua_data_model_1.AttributeIds.Historizing:
434
- return this._readHistorizing();
435
- case node_opcua_data_model_1.AttributeIds.AccessLevelEx:
436
- return this._readAccessLevelEx(context);
437
- default:
438
- return base_node_impl_1.BaseNodeImpl.prototype.readAttribute.call(this, context, attributeId);
439
- }
440
- }
441
- getBasicDataType() {
442
- if (this._basicDataType) {
443
- return this._basicDataType;
444
- }
445
- if (this.dataType.namespace === 0 && this.dataType.value === 0) {
446
- return node_opcua_variant_1.DataType.Null;
447
- }
448
- const addressSpace = this.addressSpace;
449
- if (!addressSpace) {
450
- // may be node has been deleted already
451
- return node_opcua_variant_1.DataType.Null;
452
- }
453
- const dataTypeNode = addressSpace.findDataType(this.dataType);
454
- const basicDataType = dataTypeNode && dataTypeNode.nodeClass === node_opcua_data_model_1.NodeClass.DataType ? dataTypeNode.getBasicDataType() : node_opcua_variant_1.DataType.Null;
455
- // const basicDataType = addressSpace.findCorrespondingBasicDataType(this.dataType);
456
- this._basicDataType = basicDataType;
457
- return basicDataType;
458
- }
459
- adjustVariant(variant) {
460
- return (0, node_opcua_variant_1.adjustVariant)(variant, this.valueRank, this.getBasicDataType());
461
- }
462
- verifyVariantCompatibility(variant) {
463
- try {
464
- // istanbul ignore next
465
- if (Object.prototype.hasOwnProperty.call(variant, "value")) {
466
- if (variant.dataType === null || variant.dataType === undefined) {
467
- throw new Error("Variant must provide a valid dataType : variant = " +
468
- variant.toString() +
469
- " this.dataType= " +
470
- this.dataType.toString());
471
- }
472
- if (variant.dataType === node_opcua_variant_1.DataType.Boolean &&
473
- (this.dataType.namespace !== 0 || this.dataType.value !== node_opcua_variant_1.DataType.Boolean)) {
474
- throw new Error("Variant must provide a valid Boolean : variant = " +
475
- variant.toString() +
476
- " this.dataType= " +
477
- this.dataType.toString());
478
- }
479
- if (this.dataType.namespace === 0 &&
480
- this.dataType.value === node_opcua_variant_1.DataType.LocalizedText &&
481
- variant.dataType !== node_opcua_variant_1.DataType.LocalizedText &&
482
- variant.dataType !== node_opcua_variant_1.DataType.Null) {
483
- throw new Error("Variant must provide a valid LocalizedText : variant = " +
484
- variant.toString() +
485
- " this.dataType= " +
486
- this.dataType.toString());
487
- }
488
- }
489
- const basicType = this.getBasicDataType();
490
- if (basicType === node_opcua_variant_1.DataType.String && variant.dataType === node_opcua_variant_1.DataType.ByteString) {
491
- return; // this is allowed
492
- }
493
- if (basicType === node_opcua_variant_1.DataType.ByteString && variant.dataType === node_opcua_variant_1.DataType.String) {
494
- return; // this is allowed
495
- }
496
- if (basicType !== node_opcua_variant_1.DataType.Null &&
497
- basicType !== node_opcua_variant_1.DataType.Variant &&
498
- variant.dataType !== node_opcua_variant_1.DataType.Null &&
499
- variant.dataType !== basicType) {
500
- const message = "UAVariable.setValueFromSource " +
501
- this.browseName.toString() +
502
- " nodeId:" +
503
- this.nodeId.toString() +
504
- " dataType:" +
505
- this.dataType.toString() +
506
- ":\n" +
507
- "the provided variant must have the expected dataType!\n" +
508
- " - the expected dataType is " +
509
- chalk.cyan(node_opcua_variant_1.DataType[basicType]) +
510
- "\n" +
511
- " - the actual dataType is " +
512
- chalk.magenta(node_opcua_variant_1.DataType[variant.dataType]) +
513
- "\n" +
514
- " - " +
515
- variant.toString();
516
- throw new Error(message);
517
- }
518
- }
519
- catch (err) {
520
- errorLog("UAVariable ", err === null || err === void 0 ? void 0 : err.message, this.browseName.toString(), " nodeId=", this.nodeId.toString());
521
- errorLog(err.message);
522
- errorLog(err.stack);
523
- throw err;
524
- }
525
- }
526
- /**
527
- * setValueFromSource is used to let the device sets the variable values
528
- * this method also records the current time as sourceTimestamp and serverTimestamp.
529
- . *
530
- * The method will raise an exception if the value is not compatible with the dataType and expected dimension
531
- *
532
- * @method setValueFromSource
533
- * @param variant {Variant}
534
- * @param [statusCode {StatusCode} = StatusCodes.Good]
535
- * @param [sourceTimestamp= Now]
536
- */
537
- setValueFromSource(variant, statusCode, sourceTimestamp) {
538
- var _a;
539
- try {
540
- statusCode = statusCode || node_opcua_status_code_1.StatusCodes.Good;
541
- const variant1 = node_opcua_variant_1.Variant.coerce(variant);
542
- this.verifyVariantCompatibility(variant1);
543
- const now = (0, node_opcua_date_time_1.coerceClock)(sourceTimestamp, 0);
544
- const dataValue = new node_opcua_data_value_1.DataValue(null);
545
- dataValue.serverPicoseconds = now.picoseconds;
546
- dataValue.serverTimestamp = now.timestamp;
547
- dataValue.sourcePicoseconds = now.picoseconds;
548
- dataValue.sourceTimestamp = now.timestamp;
549
- dataValue.statusCode = statusCode;
550
- dataValue.value = variant1;
551
- if (dataValue.value.dataType === node_opcua_variant_1.DataType.ExtensionObject) {
552
- const valueIsCorrect = this.checkExtensionObjectIsCorrect(dataValue.value.value);
553
- if (!valueIsCorrect) {
554
- errorLog("Invalid value !");
555
- errorLog(this.toString());
556
- errorLog(dataValue.toString());
557
- this.checkExtensionObjectIsCorrect(dataValue.value.value);
558
- }
559
- this.$dataValue = dataValue;
560
- // ----------------------------------
561
- if (this.$extensionObject) {
562
- // we have an extension object already bound to this node
563
- // the client is asking us to replace the object entierly by a new one
564
- const ext = dataValue.value.value;
565
- (0, ua_variable_impl_ext_obj_1._setExtensionObject)(this, ext);
566
- return;
567
- }
568
- }
569
- else {
570
- this._internal_set_dataValue(dataValue);
571
- }
572
- }
573
- catch (err) {
574
- errorLog("UAVariable#setValueFromString Error : ", this.browseName.toString(), this.nodeId.toString());
575
- errorLog(err.message);
576
- errorLog((_a = this.parent) === null || _a === void 0 ? void 0 : _a.toString());
577
- throw err;
578
- }
579
- }
580
- writeValue(context, dataValue, ...args) {
581
- context = context || session_context_1.SessionContext.defaultContext;
582
- (0, node_opcua_assert_1.assert)(context instanceof session_context_1.SessionContext);
583
- if (!dataValue.sourceTimestamp) {
584
- // source timestamp was not specified by the caller
585
- // we will set the timestamp ourself with the current clock
586
- if (context.currentTime) {
587
- dataValue.sourceTimestamp = context.currentTime.timestamp;
588
- dataValue.sourcePicoseconds = context.currentTime.picoseconds;
589
- }
590
- else {
591
- const { timestamp, picoseconds } = (0, node_opcua_date_time_1.getCurrentClock)();
592
- dataValue.sourceTimestamp = timestamp;
593
- dataValue.sourcePicoseconds = picoseconds;
594
- }
595
- }
596
- if (context.currentTime && !dataValue.serverTimestamp) {
597
- dataValue.serverTimestamp = context.currentTime.timestamp;
598
- dataValue.serverPicoseconds = context.currentTime.picoseconds;
599
- }
600
- // adjust arguments if optional indexRange Parameter is not given
601
- let indexRange = null;
602
- let callback;
603
- if (args.length === 1) {
604
- indexRange = new node_opcua_numeric_range_1.NumericRange();
605
- callback = args[0];
606
- }
607
- else if (args.length === 2) {
608
- indexRange = args[0];
609
- callback = args[1];
610
- }
611
- else {
612
- throw new Error("Invalid Number of args");
613
- }
614
- (0, node_opcua_assert_1.assert)(typeof callback === "function");
615
- (0, node_opcua_assert_1.assert)(dataValue instanceof node_opcua_data_value_1.DataValue);
616
- // index range could be string
617
- indexRange = node_opcua_numeric_range_1.NumericRange.coerce(indexRange);
618
- // test write permission
619
- if (!this.isWritable(context)) {
620
- return callback(null, node_opcua_status_code_1.StatusCodes.BadNotWritable);
621
- }
622
- if (!this.isUserWritable(context)) {
623
- return callback(null, node_opcua_status_code_1.StatusCodes.BadUserAccessDenied);
624
- }
625
- // adjust special case
626
- const variant = adjustVariant2.call(this, dataValue.value);
627
- const statusCode = this.checkVariantCompatibility(variant);
628
- if (statusCode.isNot(node_opcua_status_code_1.StatusCodes.Good)) {
629
- return callback(null, statusCode);
630
- }
631
- const write_func = this._timestamped_set_func || default_func;
632
- if (!write_func) {
633
- warningLog(" warning " + this.nodeId.toString() + " " + this.browseName.toString() + " has no setter. \n");
634
- warningLog("Please make sure to bind the variable or to pass a valid value: new Variant({}) during construction time");
635
- return callback(null, node_opcua_status_code_1.StatusCodes.BadNotWritable);
636
- }
637
- (0, node_opcua_assert_1.assert)(write_func);
638
- write_func.call(this, dataValue, (err, statusCode1) => {
639
- if (!err) {
640
- dataValue && this.verifyVariantCompatibility(dataValue.value);
641
- if (indexRange && !indexRange.isEmpty()) {
642
- if (!indexRange.isValid()) {
643
- return callback(null, node_opcua_status_code_1.StatusCodes.BadIndexRangeInvalid);
644
- }
645
- const newArrayOrMatrix = dataValue.value.value;
646
- if (dataValue.value.arrayType === node_opcua_variant_1.VariantArrayType.Array) {
647
- if (this.$dataValue.value.arrayType !== node_opcua_variant_1.VariantArrayType.Array) {
648
- return callback(null, node_opcua_status_code_1.StatusCodes.BadTypeMismatch);
649
- }
650
- // check that destination data is also an array
651
- (0, node_opcua_assert_1.assert)(check_valid_array(this.$dataValue.value.dataType, this.$dataValue.value.value));
652
- const destArr = this.$dataValue.value.value;
653
- const result = indexRange.set_values(destArr, newArrayOrMatrix);
654
- if (result.statusCode.isNot(node_opcua_status_code_1.StatusCodes.Good)) {
655
- return callback(null, result.statusCode);
656
- }
657
- dataValue.value.value = result.array;
658
- // scrap original array so we detect range
659
- this.$dataValue.value.value = null;
660
- }
661
- else if (dataValue.value.arrayType === node_opcua_variant_1.VariantArrayType.Matrix) {
662
- const dimensions = this.$dataValue.value.dimensions;
663
- if (this.$dataValue.value.arrayType !== node_opcua_variant_1.VariantArrayType.Matrix || !dimensions) {
664
- // not a matrix !
665
- return callback(null, node_opcua_status_code_1.StatusCodes.BadTypeMismatch);
666
- }
667
- const matrix = this.$dataValue.value.value;
668
- const result = indexRange.set_values_matrix({
669
- matrix,
670
- dimensions
671
- }, newArrayOrMatrix);
672
- if (result.statusCode.isNot(node_opcua_status_code_1.StatusCodes.Good)) {
673
- return callback(null, result.statusCode);
674
- }
675
- dataValue.value.dimensions = this.$dataValue.value.dimensions;
676
- dataValue.value.value = result.matrix;
677
- // scrap original array so we detect range
678
- this.$dataValue.value.value = null;
679
- }
680
- else {
681
- return callback(null, node_opcua_status_code_1.StatusCodes.BadTypeMismatch);
682
- }
683
- }
684
- try {
685
- this._internal_set_dataValue(dataValue, indexRange);
686
- }
687
- catch (err) {
688
- if (err instanceof Error) {
689
- warningLog(err.message);
690
- }
691
- return callback(null, node_opcua_status_code_1.StatusCodes.BadInternalError);
692
- }
693
- }
694
- callback(err || null, statusCode1);
695
- });
696
- }
697
- writeAttribute(context, writeValueOptions, callback) {
698
- // istanbul ignore next
699
- if (!callback) {
700
- throw new Error("Internal error");
701
- }
702
- const writeValue = writeValueOptions instanceof node_opcua_service_write_1.WriteValue ? writeValueOptions : new node_opcua_service_write_1.WriteValue(writeValueOptions);
703
- context = context || session_context_1.SessionContext.defaultContext;
704
- (0, node_opcua_assert_1.assert)(context instanceof session_context_1.SessionContext);
705
- (0, node_opcua_assert_1.assert)(writeValue instanceof node_opcua_service_write_1.WriteValue);
706
- (0, node_opcua_assert_1.assert)(writeValue.value instanceof node_opcua_data_value_1.DataValue);
707
- (0, node_opcua_assert_1.assert)(writeValue.value.value instanceof node_opcua_variant_1.Variant);
708
- (0, node_opcua_assert_1.assert)(typeof callback === "function");
709
- // Spec 1.0.2 Part 4 page 58
710
- // If the SourceTimestamp or the ServerTimestamp is specified, the Server shall
711
- // use these values.
712
- // xx _apply_default_timestamps(writeValue.value);
713
- switch (writeValue.attributeId) {
714
- case node_opcua_data_model_1.AttributeIds.Value:
715
- this.writeValue(context, writeValue.value, writeValue.indexRange, callback);
716
- break;
717
- case node_opcua_data_model_1.AttributeIds.Historizing:
718
- if (writeValue.value.value.dataType !== node_opcua_variant_1.DataType.Boolean) {
719
- return callback(null, node_opcua_status_code_1.StatusCodes.BadNotSupported);
720
- }
721
- // if the variable has no historizing in place reject
722
- if (!this["hA Configuration"]) {
723
- return callback(null, node_opcua_status_code_1.StatusCodes.BadNotSupported);
724
- }
725
- // check if user is allowed to do that !
726
- // TODO
727
- this.historizing = !!writeValue.value.value.value; // yes ! indeed !
728
- return callback(null, node_opcua_status_code_1.StatusCodes.Good);
729
- default:
730
- super.writeAttribute(context, writeValue, callback);
731
- break;
732
- }
733
- }
734
- /**
735
- * @method checkVariantCompatibility
736
- * note:
737
- * this method is overridden in address-space-data-access
738
- * @return {StatusCode}
739
- */
740
- checkVariantCompatibility(value) {
741
- // test dataType
742
- if (!this._validate_DataType(value.dataType)) {
743
- return node_opcua_status_code_1.StatusCodes.BadTypeMismatch;
744
- }
745
- try {
746
- this.verifyVariantCompatibility(value);
747
- }
748
- catch (err) {
749
- return node_opcua_status_code_1.StatusCodes.BadTypeMismatch;
750
- }
751
- return node_opcua_status_code_1.StatusCodes.Good;
752
- }
753
- /**
754
- * touch the source timestamp of a Variable and cascade up the change
755
- * to the parent variable if any.
756
- */
757
- touchValue(optionalNow) {
758
- const now = optionalNow || (0, node_opcua_date_time_1.getCurrentClock)();
759
- (0, ua_variable_impl_ext_obj_1.propagateTouchValueUpward)(this, now);
760
- }
761
- /**
762
- * bind a variable with a get and set functions.
763
- *
764
- * properties:
765
- * - value: a Variant or a status code
766
- * - sourceTimestamp
767
- * - sourcePicoseconds
768
- * @param [options.timestamped_set]
769
- * @param [options.refreshFunc] the variable asynchronous getter function.
770
- * @param [overwrite {Boolean} = false] set overwrite to true to overwrite existing binding
771
- * @return void
772
- *
773
- *
774
- * ### Providing read access to the underlying value
775
- *
776
- * #### Variation 1
777
- *
778
- * In this variation, the user provides a function that returns a Variant with the current value.
779
- *
780
- * The sourceTimestamp will be set automatically.
781
- *
782
- * The get function is called synchronously.
783
- *
784
- * @example
785
- *
786
- *
787
- * ```javascript
788
- * ...
789
- * var options = {
790
- * get : () => {
791
- * return new Variant({...});
792
- * },
793
- * set : function(variant) {
794
- * // store the variant somewhere
795
- * return StatusCodes.Good;
796
- * }
797
- * };
798
- * ...
799
- * engine.bindVariable(nodeId,options):
800
- * ...
801
- * ```
802
- *
803
- *
804
- * #### Variation 2:
805
- *
806
- * This variation can be used when the user wants to specify a specific '''sourceTimestamp''' associated
807
- * with the current value of the UAVariable.
808
- *
809
- * The provided ```timestamped_get``` function should return an object with three properties:
810
- * * value: containing the variant value or a error StatusCode,
811
- * * sourceTimestamp
812
- * * sourcePicoseconds
813
- *
814
- * ```javascript
815
- * ...
816
- * var myDataValue = new DataValue({
817
- * value: {dataType: DataType.Double , value: 10.0},
818
- * sourceTimestamp : new Date(),
819
- * sourcePicoseconds: 0
820
- * });
821
- * ...
822
- * var options = {
823
- * timestamped_get : () => { return myDataValue; }
824
- * };
825
- * ...
826
- * engine.bindVariable(nodeId,options):
827
- * ...
828
- * // record a new value
829
- * myDataValue.value.value = 5.0;
830
- * myDataValue.sourceTimestamp = new Date();
831
- * ...
832
- * ```
833
- *
834
- *
835
- * #### Variation 3:
836
- *
837
- * This variation can be used when the value associated with the variables requires a asynchronous function call to be
838
- * extracted. In this case, the user should provide an async method ```refreshFunc```.
839
- *
840
- *
841
- * The ```refreshFunc``` shall do whatever is necessary to fetch the most up to date version of the variable value, and
842
- * call the ```callback``` function when the data is ready.
843
- *
844
- *
845
- * The ```callback``` function follow the standard callback function signature:
846
- * * the first argument shall be **null** or **Error**, depending of the outcome of the fetch operation,
847
- * * the second argument shall be a DataValue with the new UAVariable Value, a StatusCode, and time stamps.
848
- *
849
- *
850
- * Optionally, it is possible to pass a sourceTimestamp and a sourcePicoseconds value as a third and fourth arguments
851
- * of the callback. When sourceTimestamp and sourcePicoseconds are missing, the system will set their default value
852
- * to the current time..
853
- *
854
- *
855
- * ```javascript
856
- * ...
857
- * var options = {
858
- * refreshFunc : function(callback) {
859
- * ... do_some_async_stuff_to_get_the_new_variable_value
860
- * var dataValue = new DataValue({
861
- * value: new Variant({...}),
862
- * statusCode: StatusCodes.Good,
863
- * sourceTimestamp: new Date()
864
- * });
865
- * callback(null,dataValue);
866
- * }
867
- * };
868
- * ...
869
- * variable.bindVariable(nodeId,options):
870
- * ...
871
- * ```
872
- *
873
- * ### Providing write access to the underlying value
874
- *
875
- * #### Variation1 - provide a simple synchronous set function
876
- *
877
- *
878
- * #### Notes
879
- * to do : explain return StatusCodes.GoodCompletesAsynchronously;
880
- *
881
- */
882
- bindVariable(options, overwrite) {
883
- if (overwrite) {
884
- this._timestamped_set_func = null;
885
- this._timestamped_get_func = null;
886
- this._get_func = null;
887
- this._set_func = null;
888
- this.refreshFunc = undefined;
889
- this._historyRead = UAVariableImpl.prototype._historyRead;
890
- }
891
- options = options || {};
892
- (0, node_opcua_assert_1.assert)(typeof this._timestamped_set_func !== "function", "UAVariable already bound");
893
- (0, node_opcua_assert_1.assert)(typeof this._timestamped_get_func !== "function", "UAVariable already bound");
894
- bind_getter.call(this, options);
895
- bind_setter.call(this, options);
896
- const _historyRead = options.historyRead;
897
- if (_historyRead) {
898
- (0, node_opcua_assert_1.assert)(typeof this._historyRead !== "function" || this._historyRead === UAVariableImpl.prototype._historyRead);
899
- (0, node_opcua_assert_1.assert)(typeof _historyRead === "function");
900
- this._historyRead = _historyRead;
901
- (0, node_opcua_assert_1.assert)(this._historyRead.length === 6);
902
- }
903
- // post conditions
904
- (0, node_opcua_assert_1.assert)(typeof this._timestamped_set_func === "function");
905
- (0, node_opcua_assert_1.assert)(this._timestamped_set_func.length === 2, "expecting 2 parameters");
906
- }
907
- readValueAsync(context, callback) {
908
- if (!context) {
909
- context = session_context_1.SessionContext.defaultContext;
910
- }
911
- (0, node_opcua_assert_1.assert)(typeof callback === "function");
912
- this.__waiting_callbacks = this.__waiting_callbacks || [];
913
- this.__waiting_callbacks.push(callback);
914
- const _readValueAsync_in_progress = this.__waiting_callbacks.length >= 2;
915
- if (_readValueAsync_in_progress) {
916
- return;
917
- }
918
- const readImmediate = (innerCallback) => {
919
- (0, node_opcua_assert_1.assert)(this.$dataValue instanceof node_opcua_data_value_1.DataValue);
920
- const dataValue = this.readValue();
921
- innerCallback(null, dataValue);
922
- };
923
- let func;
924
- if (!this.isReadable(context)) {
925
- func = (innerCallback) => {
926
- const dataValue = new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadNotReadable });
927
- innerCallback(null, dataValue);
928
- };
929
- }
930
- else if (!this.isUserReadable(context)) {
931
- func = (innerCallback) => {
932
- const dataValue = new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied });
933
- innerCallback(null, dataValue);
934
- };
935
- }
936
- else {
937
- func = typeof this.refreshFunc === "function" ? this.asyncRefresh.bind(this, new Date()) : readImmediate;
938
- }
939
- const satisfy_callbacks = (err, dataValue) => {
940
- // now call all pending callbacks
941
- const callbacks = this.__waiting_callbacks || [];
942
- this.__waiting_callbacks = [];
943
- const n = callbacks.length;
944
- for (const callback1 of callbacks) {
945
- callback1.call(this, err, dataValue);
946
- }
947
- };
948
- try {
949
- func.call(this, satisfy_callbacks);
950
- }
951
- catch (err) {
952
- // istanbul ignore next
953
- if (doDebug) {
954
- debugLog(chalk.red("func readValueAsync has failed "));
955
- if (err instanceof Error) {
956
- debugLog(" stack", err.stack);
957
- }
958
- }
959
- satisfy_callbacks(err);
960
- }
961
- }
962
- getWriteMask() {
963
- return super.getWriteMask();
964
- }
965
- getUserWriteMask() {
966
- return super.getUserWriteMask();
967
- }
968
- clone(options, optionalFilter, extraInfo) {
969
- options = Object.assign(Object.assign({}, options), {
970
- // check this eventNotifier: this.eventNotifier,
971
- // check this symbolicName: this.symbolicName,
972
- accessLevel: this.accessLevel, arrayDimensions: this.arrayDimensions, dataType: this.dataType, historizing: this.historizing, minimumSamplingInterval: this.minimumSamplingInterval, userAccessLevel: this.userAccessLevel, valueRank: this.valueRank });
973
- const newVariable = base_node_private_1._clone.call(this, UAVariableImpl, options, optionalFilter || node_opcua_address_space_base_1.defaultCloneFilter, extraInfo || node_opcua_address_space_base_1.defaultCloneExtraInfo);
974
- newVariable.bindVariable();
975
- (0, node_opcua_assert_1.assert)(typeof newVariable._timestamped_set_func === "function");
976
- (0, node_opcua_assert_1.assert)(newVariable.dataType === this.dataType);
977
- newVariable.$dataValue = this.$dataValue.clone();
978
- // also bind extension object
979
- const v = newVariable.$dataValue.value;
980
- if (v.dataType === node_opcua_variant_1.DataType.ExtensionObject && v.value && v.arrayType === node_opcua_variant_1.VariantArrayType.Scalar) {
981
- try {
982
- newVariable.bindExtensionObject(newVariable.$dataValue.value.value);
983
- }
984
- catch (err) {
985
- errorLog("Errro binding extension objects");
986
- errorLog(err.message);
987
- errorLog(this.toString());
988
- errorLog("---------------------------------------");
989
- errorLog(this.$dataValue.toString());
990
- errorLog("---------------------------------------");
991
- errorLog(newVariable.$dataValue.toString());
992
- throw err;
993
- }
994
- }
995
- return newVariable;
996
- }
997
- getDataTypeNode() {
998
- const addressSpace = this.addressSpace;
999
- const dt = addressSpace.findNode(this.dataType);
1000
- // istanbul ignore next
1001
- if (!dt) {
1002
- throw new Error("getDataTypeNode: cannot find dataType " + this.dataType.toString());
1003
- }
1004
- return dt;
1005
- }
1006
- get dataTypeObj() {
1007
- return this.getDataTypeNode();
1008
- }
1009
- checkExtensionObjectIsCorrect(extObj) {
1010
- if (!extObj) {
1011
- return true;
1012
- }
1013
- const addressSpace = this.addressSpace;
1014
- const dataType = addressSpace.findDataType(this.dataType);
1015
- if (!dataType) {
1016
- // may be we are in the process of loading a xml file and the corresponding dataType
1017
- // has not yet been loaded !
1018
- return true;
1019
- }
1020
- const Constructor = addressSpace.getExtensionObjectConstructor(this.dataType);
1021
- if (this.valueRank === -1) {
1022
- /** Scalar */
1023
- if (extObj instanceof Array) {
1024
- return false;
1025
- }
1026
- return checkExtensionObjectIsCorrectScalar.call(this, extObj);
1027
- }
1028
- else if (this.valueRank === 1) {
1029
- /** array */
1030
- if (!(extObj instanceof Array)) {
1031
- // let's coerce this scalar into an 1-element array if it is a valid extension object
1032
- if (checkExtensionObjectIsCorrectScalar.call(this, extObj)) {
1033
- warningLog(`checkExtensionObjectIsCorrect : expecting a array but got a scalar (value rank of ${this.browseName.toString()} is 1)`);
1034
- extObj = [extObj];
1035
- }
1036
- else {
1037
- return false;
1038
- }
1039
- }
1040
- return checkExtensionObjectIsCorrectArray.call(this, extObj);
1041
- }
1042
- else if (this.valueRank === 0) {
1043
- // Scalar or Array
1044
- const isCorrectScalar = !Array.isArray(extObj) && checkExtensionObjectIsCorrectScalar.call(this, extObj);
1045
- const isCorrectArray = Array.isArray(extObj) && checkExtensionObjectIsCorrectArray.call(this, extObj);
1046
- return isCorrectArray || isCorrectScalar;
1047
- }
1048
- else {
1049
- throw new Error(`checkExtensionObjectIsCorrect: Not Implemented case, please contact sterfive : this.valueRank =${this.valueRank}`);
1050
- }
1051
- function checkExtensionObjectIsCorrectScalar(extObj) {
1052
- // istanbul ignore next
1053
- if (!(extObj && extObj.constructor)) {
1054
- errorLog(extObj);
1055
- throw new Error("expecting an valid extension object");
1056
- }
1057
- return extObj.constructor.name === Constructor.name;
1058
- }
1059
- function checkExtensionObjectIsCorrectArray(extObjArray) {
1060
- // istanbul ignore next
1061
- for (const extObj of extObjArray) {
1062
- if (!(extObj && extObj.constructor)) {
1063
- errorLog(extObj);
1064
- throw new Error("expecting an valid extension object");
1065
- }
1066
- }
1067
- try {
1068
- for (const e of extObjArray) {
1069
- if (!e) {
1070
- continue;
1071
- }
1072
- if (e.constructor.name !== Constructor.name) {
1073
- debugLog("extObj.constructor.name ", e.constructor.name, "expected", Constructor.name);
1074
- return false;
1075
- }
1076
- }
1077
- return true;
1078
- }
1079
- catch (err) {
1080
- errorLog(err);
1081
- return false;
1082
- }
1083
- }
1084
- }
1085
- /**
1086
- * @private
1087
- * install UAVariable to exposed th
1088
- *
1089
- * precondition:
1090
- */
1091
- installExtensionObjectVariables() {
1092
- (0, ua_variable_impl_ext_obj_1._installExtensionObjectBindingOnProperties)(this, { createMissingProp: true });
1093
- // now recursively install extension object on children
1094
- for (const child of this.getComponents()) {
1095
- if (child.nodeClass === node_opcua_data_model_1.NodeClass.Variable && child instanceof UAVariableImpl) {
1096
- if (child.isExtensionObject()) {
1097
- child.installExtensionObjectVariables();
1098
- }
1099
- }
1100
- }
1101
- }
1102
- /**
1103
- * @method bindExtensionObject
1104
- * @return {ExtensionObject}
1105
- */
1106
- bindExtensionObjectScalar(optionalExtensionObject, options) {
1107
- return this.bindExtensionObject(optionalExtensionObject, options);
1108
- }
1109
- bindExtensionObjectArray(optionalExtensionObject, options) {
1110
- return this.bindExtensionObject(optionalExtensionObject, options);
1111
- }
1112
- bindExtensionObject(optionalExtensionObject, options) {
1113
- return (0, ua_variable_impl_ext_obj_1._bindExtensionObject)(this, optionalExtensionObject, options);
1114
- }
1115
- updateExtensionObjectPartial(partialExtensionObject) {
1116
- (0, ua_variable_impl_ext_obj_1.setExtensionObjectValue)(this, partialExtensionObject);
1117
- return this.$extensionObject;
1118
- }
1119
- incrementExtensionObjectPartial(path) {
1120
- const extensionObject = this.readValue().value.value;
1121
- const partialData = (0, ua_variable_impl_ext_obj_1.extractPartialData)(path, extensionObject);
1122
- (0, ua_variable_impl_ext_obj_1.setExtensionObjectValue)(this, partialData);
1123
- }
1124
- toString() {
1125
- const options = new base_node_private_1.ToStringBuilder();
1126
- base_node_private_1.UAVariable_toString.call(this, options);
1127
- return options.toString();
1128
- }
1129
- historyRead(context, historyReadDetails, indexRange, dataEncoding, continuationData, callback) {
1130
- (0, node_opcua_assert_1.assert)(context instanceof session_context_1.SessionContext);
1131
- (0, node_opcua_assert_1.assert)(typeof callback === "function");
1132
- if (typeof this._historyRead !== "function") {
1133
- return callback(null, new node_opcua_types_1.HistoryReadResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadNotReadable }));
1134
- }
1135
- this._historyRead(context, historyReadDetails, indexRange, dataEncoding, continuationData, callback);
1136
- }
1137
- _historyReadRaw(context, historyReadRawModifiedDetails, indexRange, dataEncoding, continuationData, callback) {
1138
- throw new Error("");
1139
- }
1140
- _historyReadRawModify(context, historyReadRawModifiedDetails, indexRange, dataEncoding, continuationData, callback) {
1141
- throw new Error("");
1142
- }
1143
- _historyRead(context, historyReadDetails, indexRange, dataEncoding, continuationData, callback) {
1144
- const result = new node_opcua_types_1.HistoryReadResult({
1145
- statusCode: node_opcua_status_code_1.StatusCodes.BadHistoryOperationUnsupported
1146
- });
1147
- callback(null, result);
1148
- }
1149
- _historyPush(newDataValue) {
1150
- throw new Error("");
1151
- }
1152
- _historyReadRawAsync(historyReadRawModifiedDetails, maxNumberToExtract, isReversed, reverseDataValue, callback) {
1153
- throw new Error("");
1154
- }
1155
- _historyReadModify(context, historyReadRawModifiedDetails, indexRange, dataEncoding, continuationData, callback) {
1156
- throw new Error("");
1157
- }
1158
- _update_startOfOnlineArchive(newDate) {
1159
- // please install
1160
- throw new Error("");
1161
- }
1162
- _update_startOfArchive(newDate) {
1163
- throw new Error("");
1164
- }
1165
- _validate_DataType(variantDataType) {
1166
- return validateDataType(this.addressSpace, this.dataType, variantDataType, this.nodeId, /* allow Nulls */ false);
1167
- }
1168
- _internal_set_value(value) {
1169
- if (value.dataType !== node_opcua_variant_1.DataType.Null) {
1170
- this.verifyVariantCompatibility(value);
1171
- }
1172
- this.$dataValue.value = value;
1173
- }
1174
- _internal_set_dataValue(dataValue, indexRange) {
1175
- (0, node_opcua_assert_1.assert)(dataValue, "expecting a dataValue");
1176
- (0, node_opcua_assert_1.assert)(dataValue instanceof node_opcua_data_value_1.DataValue, "expecting dataValue to be a DataValue");
1177
- (0, node_opcua_assert_1.assert)(dataValue !== this.$dataValue, "expecting dataValue to be different from previous DataValue instance");
1178
- const addressSpace = this.addressSpace;
1179
- if (!addressSpace) {
1180
- warningLog("UAVariable#_internal_set_dataValue : no addressSpace ! may be node has already been deleted ?");
1181
- return;
1182
- }
1183
- if (dataValue.value.arrayType === node_opcua_variant_1.VariantArrayType.Matrix) {
1184
- if (!dataValue.value.dimensions) {
1185
- throw new Error("missing dimensions: a Matrix Variant needs a dimension");
1186
- }
1187
- const nbElements = dataValue.value.dimensions.reduce((acc, x) => acc * x, 1);
1188
- if (dataValue.value.value.length !== 0 && dataValue.value.value.length !== nbElements) {
1189
- throw new Error(`Internal Error: matrix dimension doesn't match the number of element in the array : ${dataValue.toString()} "\n expecting ${nbElements} elements but got ${dataValue.value.value.length}`);
1190
- }
1191
- }
1192
- if (dataValue.value.dataType === node_opcua_variant_1.DataType.ExtensionObject) {
1193
- if (!this.checkExtensionObjectIsCorrect(dataValue.value.value)) {
1194
- warningLog(dataValue.toString());
1195
- throw new Error("Invalid Extension Object on nodeId =" + this.nodeId.toString());
1196
- }
1197
- // ----------------------------------
1198
- // if (this.$extensionObject) {
1199
- // // we have an extension object already bound to this node
1200
- // // the client is asking us to replace the object entierly by a new one
1201
- // const ext = dataValue.value.value;
1202
- // _setExtensionObject(this, ext);
1203
- // return;
1204
- // }
1205
- }
1206
- // // istanbul ignore next
1207
- // if (this.dataType.namespace === 0) {
1208
- // if (this.dataType.value === DataType.LocalizedText && dataValue.value.dataType !== DataType.LocalizedText) {
1209
- // const message = "Invalid dataValue provided (expecting a LocalizedText) but got " + dataValue.toString();
1210
- // errorLog(message);
1211
- // // throw new Error(message);
1212
- // }
1213
- // }
1214
- this.verifyVariantCompatibility(dataValue.value);
1215
- const old_dataValue = this.$dataValue;
1216
- this.$dataValue = dataValue;
1217
- this.$dataValue.statusCode = this.$dataValue.statusCode || node_opcua_status_code_1.StatusCodes.Good;
1218
- // repair missing timestamps
1219
- if (!dataValue.serverTimestamp) {
1220
- this.$dataValue.serverTimestamp = old_dataValue.serverTimestamp;
1221
- this.$dataValue.serverPicoseconds = old_dataValue.serverPicoseconds;
1222
- }
1223
- if (!dataValue.sourceTimestamp) {
1224
- this.$dataValue.sourceTimestamp = old_dataValue.sourceTimestamp;
1225
- this.$dataValue.sourcePicoseconds = old_dataValue.sourcePicoseconds;
1226
- }
1227
- if (!(0, node_opcua_data_value_1.sameDataValue)(old_dataValue, dataValue)) {
1228
- this.emit("value_changed", this.$dataValue, indexRange);
1229
- }
1230
- }
1231
- _conditionRefresh(_cache) {
1232
- apply_condition_refresh_1.apply_condition_refresh.call(this, _cache);
1233
- }
1234
- handle_semantic_changed() {
1235
- this.semantic_version = this.semantic_version + 1;
1236
- this.emit("semantic_changed");
1237
- }
1238
- _readDataType() {
1239
- (0, node_opcua_assert_1.assert)(this.dataType instanceof node_opcua_nodeid_1.NodeId);
1240
- const options = {
1241
- statusCode: node_opcua_status_code_1.StatusCodes.Good,
1242
- value: {
1243
- dataType: node_opcua_variant_1.DataType.NodeId,
1244
- value: this.dataType
1245
- }
1246
- };
1247
- return new node_opcua_data_value_1.DataValue(options);
1248
- }
1249
- _readValueRank() {
1250
- (0, node_opcua_assert_1.assert)(typeof this.valueRank === "number");
1251
- const options = {
1252
- statusCode: node_opcua_status_code_1.StatusCodes.Good,
1253
- value: { dataType: node_opcua_variant_1.DataType.Int32, value: this.valueRank }
1254
- };
1255
- return new node_opcua_data_value_1.DataValue(options);
1256
- }
1257
- _readArrayDimensions() {
1258
- (0, node_opcua_assert_1.assert)(Array.isArray(this.arrayDimensions) || this.arrayDimensions === null);
1259
- (0, node_opcua_assert_1.assert)(!this.arrayDimensions || this.valueRank > 0, "arrayDimension must be null if valueRank <0");
1260
- const options = {
1261
- statusCode: node_opcua_status_code_1.StatusCodes.Good,
1262
- value: { dataType: node_opcua_variant_1.DataType.UInt32, arrayType: node_opcua_variant_1.VariantArrayType.Array, value: this.arrayDimensions }
1263
- };
1264
- return new node_opcua_data_value_1.DataValue(options);
1265
- }
1266
- _readAccessLevel(context) {
1267
- (0, node_opcua_assert_1.assert)(context instanceof session_context_1.SessionContext);
1268
- const options = {
1269
- statusCode: node_opcua_status_code_1.StatusCodes.Good,
1270
- value: { dataType: node_opcua_variant_1.DataType.Byte, value: (0, node_opcua_data_model_1.convertAccessLevelFlagToByte)(this.accessLevel) }
1271
- };
1272
- return new node_opcua_data_value_1.DataValue(options);
1273
- }
1274
- _readAccessLevelEx(context) {
1275
- (0, node_opcua_assert_1.assert)(context instanceof session_context_1.SessionContext);
1276
- const options = {
1277
- statusCode: node_opcua_status_code_1.StatusCodes.Good,
1278
- // Extra flags are not supported yet. to do:
1279
- value: { dataType: node_opcua_variant_1.DataType.UInt32, value: (0, node_opcua_data_model_1.convertAccessLevelFlagToByte)(this.accessLevel) }
1280
- };
1281
- return new node_opcua_data_value_1.DataValue(options);
1282
- }
1283
- _readUserAccessLevel(context) {
1284
- (0, node_opcua_assert_1.assert)(context instanceof session_context_1.SessionContext);
1285
- const effectiveUserAccessLevel = _calculateEffectiveUserAccessLevelFromPermission(this, context, this.userAccessLevel);
1286
- const options = {
1287
- value: {
1288
- dataType: node_opcua_variant_1.DataType.Byte,
1289
- statusCode: node_opcua_status_code_1.StatusCodes.Good,
1290
- value: (0, node_opcua_data_model_1.convertAccessLevelFlagToByte)(effectiveUserAccessLevel)
1291
- }
1292
- };
1293
- return new node_opcua_data_value_1.DataValue(options);
1294
- }
1295
- _readMinimumSamplingInterval() {
1296
- // expect a Duration => Double
1297
- const options = {};
1298
- if (this.minimumSamplingInterval === undefined) {
1299
- options.statusCode = node_opcua_status_code_1.StatusCodes.BadAttributeIdInvalid;
1300
- }
1301
- else {
1302
- options.value = { dataType: node_opcua_variant_1.DataType.Double, value: this.minimumSamplingInterval };
1303
- options.statusCode = node_opcua_status_code_1.StatusCodes.Good;
1304
- }
1305
- return new node_opcua_data_value_1.DataValue(options);
1306
- }
1307
- _readHistorizing() {
1308
- (0, node_opcua_assert_1.assert)(typeof this.historizing === "boolean");
1309
- const options = {
1310
- statusCode: node_opcua_status_code_1.StatusCodes.Good,
1311
- value: { dataType: node_opcua_variant_1.DataType.Boolean, value: !!this.historizing }
1312
- };
1313
- return new node_opcua_data_value_1.DataValue(options);
1314
- }
1315
- }
1316
- exports.UAVariableImpl = UAVariableImpl;
1317
- // tslint:disable:no-var-requires
1318
- const thenify = require("thenify");
1319
- UAVariableImpl.prototype.asyncRefresh = thenify.withCallback(UAVariableImpl.prototype.asyncRefresh);
1320
- UAVariableImpl.prototype.writeValue = thenify.withCallback(UAVariableImpl.prototype.writeValue);
1321
- UAVariableImpl.prototype.writeAttribute = thenify.withCallback(UAVariableImpl.prototype.writeAttribute);
1322
- UAVariableImpl.prototype.historyRead = thenify.withCallback(UAVariableImpl.prototype.historyRead);
1323
- UAVariableImpl.prototype.readValueAsync = thenify.withCallback(UAVariableImpl.prototype.readValueAsync);
1324
- function check_valid_array(dataType, array) {
1325
- if (Array.isArray(array)) {
1326
- return true;
1327
- }
1328
- switch (dataType) {
1329
- case node_opcua_variant_1.DataType.Double:
1330
- return array instanceof Float64Array;
1331
- case node_opcua_variant_1.DataType.Float:
1332
- return array instanceof Float32Array;
1333
- case node_opcua_variant_1.DataType.Int32:
1334
- return array instanceof Int32Array;
1335
- case node_opcua_variant_1.DataType.Int16:
1336
- return array instanceof Int16Array;
1337
- case node_opcua_variant_1.DataType.SByte:
1338
- return array instanceof Int8Array;
1339
- case node_opcua_variant_1.DataType.UInt32:
1340
- return array instanceof Uint32Array;
1341
- case node_opcua_variant_1.DataType.UInt16:
1342
- return array instanceof Uint16Array;
1343
- case node_opcua_variant_1.DataType.Byte:
1344
- return array instanceof Uint8Array || array instanceof Buffer;
1345
- }
1346
- return false;
1347
- }
1348
- function _apply_default_timestamps(dataValue) {
1349
- const now = (0, node_opcua_date_time_1.getCurrentClock)();
1350
- (0, node_opcua_assert_1.assert)(dataValue instanceof node_opcua_data_value_1.DataValue);
1351
- if (!dataValue.sourceTimestamp) {
1352
- dataValue.sourceTimestamp = now.timestamp;
1353
- dataValue.sourcePicoseconds = now.picoseconds;
1354
- }
1355
- if (!dataValue.serverTimestamp) {
1356
- dataValue.serverTimestamp = now.timestamp;
1357
- dataValue.serverPicoseconds = now.picoseconds;
1358
- }
1359
- }
1360
- function unsetFlag(flags, mask) {
1361
- return flags & ~mask;
1362
- }
1363
- function setFlag(flags, mask) {
1364
- return flags | mask;
1365
- }
1366
- function _calculateEffectiveUserAccessLevelFromPermission(node, context, userAccessLevel) {
1367
- function __adjustFlag(permissionType, access, userAccessLevel1) {
1368
- if ((node.accessLevel & access) === 0 || (userAccessLevel1 & access) === 0) {
1369
- userAccessLevel1 = unsetFlag(userAccessLevel1, access);
1370
- }
1371
- else {
1372
- if (!context.checkPermission(node, permissionType)) {
1373
- userAccessLevel1 = unsetFlag(userAccessLevel1, access);
1374
- }
1375
- }
1376
- return userAccessLevel1;
1377
- }
1378
- userAccessLevel = node.userAccessLevel === undefined ? node.accessLevel : node.userAccessLevel & node.accessLevel;
1379
- if (context.checkPermission) {
1380
- (0, node_opcua_assert_1.assert)(context.checkPermission instanceof Function);
1381
- userAccessLevel = __adjustFlag(node_opcua_types_1.PermissionType.Read, node_opcua_data_model_1.AccessLevelFlag.CurrentRead, userAccessLevel);
1382
- userAccessLevel = __adjustFlag(node_opcua_types_1.PermissionType.Write, node_opcua_data_model_1.AccessLevelFlag.CurrentWrite, userAccessLevel);
1383
- userAccessLevel = __adjustFlag(node_opcua_types_1.PermissionType.Write, node_opcua_data_model_1.AccessLevelFlag.StatusWrite, userAccessLevel);
1384
- userAccessLevel = __adjustFlag(node_opcua_types_1.PermissionType.Write, node_opcua_data_model_1.AccessLevelFlag.TimestampWrite, userAccessLevel);
1385
- userAccessLevel = __adjustFlag(node_opcua_types_1.PermissionType.ReadHistory, node_opcua_data_model_1.AccessLevelFlag.HistoryRead, userAccessLevel);
1386
- userAccessLevel = __adjustFlag(node_opcua_types_1.PermissionType.DeleteHistory, node_opcua_data_model_1.AccessLevelFlag.HistoryWrite, userAccessLevel);
1387
- return userAccessLevel;
1388
- }
1389
- else {
1390
- return userAccessLevel;
1391
- }
1392
- }
1393
- function adjustVariant2(variant) {
1394
- // convert Variant( Scalar|ByteString) => Variant(Array|ByteArray)
1395
- const addressSpace = this.addressSpace;
1396
- const basicType = this.getBasicDataType();
1397
- variant = (0, node_opcua_variant_1.adjustVariant)(variant, this.valueRank, basicType);
1398
- return variant;
1399
- }
1400
- function _not_writable_timestamped_set_func(dataValue, callback) {
1401
- (0, node_opcua_assert_1.assert)(dataValue instanceof node_opcua_data_value_1.DataValue);
1402
- callback(null, node_opcua_status_code_1.StatusCodes.BadNotWritable, null);
1403
- }
1404
- function _default_writable_timestamped_set_func(dataValue, callback) {
1405
- (0, node_opcua_assert_1.assert)(dataValue instanceof node_opcua_data_value_1.DataValue);
1406
- callback(null, node_opcua_status_code_1.StatusCodes.Good, dataValue);
1407
- }
1408
- function turn_sync_to_async(f, numberOfArgs) {
1409
- if (f.length <= numberOfArgs) {
1410
- return function (data, callback) {
1411
- const r = f.call(this, data);
1412
- setImmediate(() => {
1413
- return callback(null, r);
1414
- });
1415
- };
1416
- }
1417
- else {
1418
- (0, node_opcua_assert_1.assert)(f.length === numberOfArgs + 1);
1419
- return f;
1420
- }
1421
- }
1422
- const _default_minimumSamplingInterval = 1000;
1423
- function coerceDataValue(dataValue) {
1424
- if (dataValue instanceof node_opcua_data_value_1.DataValue) {
1425
- return dataValue;
1426
- }
1427
- return new node_opcua_data_value_1.DataValue(dataValue);
1428
- }
1429
- // variation #3 :
1430
- function _Variable_bind_with_async_refresh(options) {
1431
- /* jshint validthis: true */
1432
- (0, node_opcua_assert_1.assert)(this instanceof UAVariableImpl);
1433
- (0, node_opcua_assert_1.assert)(typeof options.refreshFunc === "function");
1434
- (0, node_opcua_assert_1.assert)(!options.get, "a getter shall not be specified when refreshFunc is set");
1435
- (0, node_opcua_assert_1.assert)(!options.timestamped_get, "a getter shall not be specified when refreshFunc is set");
1436
- (0, node_opcua_assert_1.assert)(!this.refreshFunc);
1437
- this.refreshFunc = options.refreshFunc;
1438
- // assert(this.readValue().statusCode === StatusCodes.BadNodeIdUnknown);
1439
- this.$dataValue.statusCode = node_opcua_status_code_1.StatusCodes.UncertainInitialValue;
1440
- // TO DO : REVISIT THIS ASSUMPTION
1441
- if (false && this.minimumSamplingInterval === 0) {
1442
- // when a getter /timestamped_getter or async_getter is provided
1443
- // samplingInterval cannot be 0, as the item value must be scanned to be updated.
1444
- this.minimumSamplingInterval = _default_minimumSamplingInterval; // MonitoredItem.minimumSamplingInterval;
1445
- debugLog("adapting minimumSamplingInterval on " + this.browseName.toString() + " to " + this.minimumSamplingInterval);
1446
- }
1447
- }
1448
- // variation 2
1449
- function _Variable_bind_with_timestamped_get(options) {
1450
- /* jshint validthis: true */
1451
- (0, node_opcua_assert_1.assert)(this instanceof UAVariableImpl);
1452
- (0, node_opcua_assert_1.assert)(typeof options.timestamped_get === "function");
1453
- (0, node_opcua_assert_1.assert)(!options.get, "should not specify 'get' when 'timestamped_get' exists ");
1454
- (0, node_opcua_assert_1.assert)(!this._timestamped_get_func);
1455
- const async_refresh_func = (callback) => {
1456
- Promise.resolve(this._timestamped_get_func.call(this))
1457
- .then((dataValue) => callback(null, dataValue))
1458
- .catch((err) => {
1459
- errorLog("asyncRefresh error: Variable is ", this.nodeId.toString(), this.browseName.toString());
1460
- callback(err);
1461
- });
1462
- };
1463
- const pThis = this;
1464
- if (options.timestamped_get.length === 0) {
1465
- const timestamped_get = options.timestamped_get;
1466
- // sync version | Promise version
1467
- this._timestamped_get_func = timestamped_get;
1468
- const dataValue_verify = timestamped_get.call(pThis);
1469
- // dataValue_verify should be a DataValue or a Promise
1470
- /* istanbul ignore next */
1471
- if (!(dataValue_verify instanceof node_opcua_data_value_1.DataValue) && typeof dataValue_verify.then !== "function") {
1472
- errorLog(chalk.red(" Bind variable error: "), " the timestamped_get function must return a DataValue or a Promise<DataValue>" +
1473
- "\n value_check.constructor.name ", dataValue_verify ? dataValue_verify.constructor.name : "null");
1474
- throw new Error(" Bind variable error: " + " the timestamped_get function must return a DataValue");
1475
- }
1476
- _Variable_bind_with_async_refresh.call(this, { refreshFunc: async_refresh_func });
1477
- }
1478
- else if (options.timestamped_get.length === 1) {
1479
- _Variable_bind_with_async_refresh.call(this, { refreshFunc: options.timestamped_get });
1480
- }
1481
- else {
1482
- errorLog("timestamped_get has a invalid number of argument , should be 0 or 1 ");
1483
- throw new Error("timestamped_get has a invalid number of argument , should be 0 or 1 ");
1484
- }
1485
- }
1486
- // variation 1
1487
- function _Variable_bind_with_simple_get(options) {
1488
- /* jshint validthis: true */
1489
- (0, node_opcua_assert_1.assert)(this instanceof UAVariableImpl);
1490
- (0, node_opcua_assert_1.assert)(typeof options.get === "function", "should specify get function");
1491
- (0, node_opcua_assert_1.assert)(options.get.length === 0, "get function should not have arguments");
1492
- (0, node_opcua_assert_1.assert)(!options.timestamped_get, "should not specify a timestamped_get function when get is specified");
1493
- (0, node_opcua_assert_1.assert)(!this._timestamped_get_func);
1494
- (0, node_opcua_assert_1.assert)(!this._get_func);
1495
- this._get_func = options.get;
1496
- const timestamped_get_func_from__Variable_bind_with_simple_get = () => {
1497
- const value = this._get_func();
1498
- /* istanbul ignore next */
1499
- if (!is_Variant_or_StatusCode(value)) {
1500
- errorLog(chalk.red(" Bind variable error: "), " : the getter must return a Variant or a StatusCode" + "\nvalue_check.constructor.name ", value ? value.constructor.name : "null");
1501
- throw new Error(" bindVariable : the value getter function returns a invalid result ( expecting a Variant or a StatusCode !!!");
1502
- }
1503
- if (is_StatusCode(value)) {
1504
- return new node_opcua_data_value_1.DataValue({ statusCode: value });
1505
- }
1506
- else {
1507
- if (!this.$dataValue || !isGoodish(this.$dataValue.statusCode) || !(0, node_opcua_variant_1.sameVariant)(this.$dataValue.value, value)) {
1508
- this.setValueFromSource(value, node_opcua_status_code_1.StatusCodes.Good);
1509
- }
1510
- return this.$dataValue;
1511
- }
1512
- };
1513
- _Variable_bind_with_timestamped_get.call(this, {
1514
- get: undefined,
1515
- timestamped_get: timestamped_get_func_from__Variable_bind_with_simple_get
1516
- });
1517
- }
1518
- function _Variable_bind_with_simple_set(options) {
1519
- (0, node_opcua_assert_1.assert)(this instanceof UAVariableImpl);
1520
- (0, node_opcua_assert_1.assert)(typeof options.set === "function", "should specify set function");
1521
- (0, node_opcua_assert_1.assert)(!options.timestamped_set, "should not specify a timestamped_set function");
1522
- (0, node_opcua_assert_1.assert)(!this._timestamped_set_func);
1523
- (0, node_opcua_assert_1.assert)(!this._set_func);
1524
- this._set_func = turn_sync_to_async(options.set, 1);
1525
- (0, node_opcua_assert_1.assert)(this._set_func.length === 2, " set function must have 2 arguments ( variant, callback)");
1526
- this._timestamped_set_func = (timestamped_value, callback) => {
1527
- (0, node_opcua_assert_1.assert)(timestamped_value instanceof node_opcua_data_value_1.DataValue);
1528
- this._set_func(timestamped_value.value, (err, statusCode) => {
1529
- // istanbul ignore next
1530
- if (!err && !statusCode) {
1531
- errorLog(chalk.red("UAVariable Binding Error _set_func must return a StatusCode, check the bindVariable parameters"));
1532
- errorLog(chalk.yellow("StatusCode.Good is assumed"));
1533
- return callback(err, node_opcua_status_code_1.StatusCodes.Good, timestamped_value);
1534
- }
1535
- callback(err, statusCode, timestamped_value);
1536
- });
1537
- };
1538
- }
1539
- function _Variable_bind_with_timestamped_set(options) {
1540
- (0, node_opcua_assert_1.assert)(typeof options.timestamped_set === "function");
1541
- (0, node_opcua_assert_1.assert)(options.timestamped_set.length === 2, "timestamped_set must have 2 parameters timestamped_set: function(dataValue,callback){}");
1542
- (0, node_opcua_assert_1.assert)(!options.set, "should not specify set when timestamped_set_func exists ");
1543
- this._timestamped_set_func = (0, multiform_func_1.convertToCallbackFunction1)(options.timestamped_set);
1544
- }
1545
- function bind_setter(options) {
1546
- if (typeof options.set === "function") {
1547
- // variation 1
1548
- _Variable_bind_with_simple_set.call(this, options);
1549
- }
1550
- else if (typeof options.timestamped_set === "function") {
1551
- // variation 2
1552
- (0, node_opcua_assert_1.assert)(typeof options.timestamped_get === "function", "timestamped_set must be used with timestamped_get ");
1553
- _Variable_bind_with_timestamped_set.call(this, {
1554
- set: undefined,
1555
- timestamped_set: options.timestamped_set
1556
- });
1557
- }
1558
- else if (typeof options.timestamped_get === "function") {
1559
- // timestamped_get is specified but timestamped_set is not
1560
- // => Value is read-only
1561
- _Variable_bind_with_timestamped_set.call(this, {
1562
- set: undefined,
1563
- timestamped_set: _not_writable_timestamped_set_func
1564
- });
1565
- }
1566
- else {
1567
- _Variable_bind_with_timestamped_set.call(this, {
1568
- set: undefined,
1569
- timestamped_set: _default_writable_timestamped_set_func
1570
- });
1571
- }
1572
- }
1573
- function bind_getter(options) {
1574
- if (typeof options.get === "function") {
1575
- // variation 1
1576
- _Variable_bind_with_simple_get.call(this, options);
1577
- }
1578
- else if (typeof options.timestamped_get === "function") {
1579
- // variation 2
1580
- _Variable_bind_with_timestamped_get.call(this, {
1581
- get: undefined,
1582
- timestamped_get: options.timestamped_get
1583
- });
1584
- }
1585
- else if (typeof options.refreshFunc === "function") {
1586
- // variation 3
1587
- _Variable_bind_with_async_refresh.call(this, options);
1588
- }
1589
- else {
1590
- (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(options, "set"), "getter is missing : a getter must be provided if a setter is provided");
1591
- // xx bind_variant.call(this,options);
1592
- if (options.dataType !== undefined) {
1593
- // if (options.dataType !== DataType.ExtensionObject) {
1594
- this.setValueFromSource(options);
1595
- // }
1596
- }
1597
- }
1598
- }
1599
- class UAVariableImplT extends UAVariableImpl {
1600
- }
1601
- exports.UAVariableImplT = UAVariableImplT;
1602
- // x TO DO
1603
- // require("./data_access/ua_variable_data_access");
1604
- // require("./historical_access/ua_variable_history");
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UAVariableImplT = exports.UAVariableImpl = exports.adjust_userAccessLevel = exports.adjust_accessLevel = void 0;
4
+ /* eslint-disable max-statements */
5
+ /* eslint-disable complexity */
6
+ /**
7
+ * @module node-opcua-address-space
8
+ */
9
+ // tslint:disable:no-bitwise
10
+ // tslint:disable:no-console
11
+ // tslint:disable:max-line-length
12
+ const chalk = require("chalk");
13
+ const node_opcua_address_space_base_1 = require("node-opcua-address-space-base");
14
+ const node_opcua_assert_1 = require("node-opcua-assert");
15
+ const node_opcua_data_model_1 = require("node-opcua-data-model");
16
+ const node_opcua_data_value_1 = require("node-opcua-data-value");
17
+ const node_opcua_date_time_1 = require("node-opcua-date-time");
18
+ const node_opcua_debug_1 = require("node-opcua-debug");
19
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
20
+ const node_opcua_numeric_range_1 = require("node-opcua-numeric-range");
21
+ const node_opcua_service_write_1 = require("node-opcua-service-write");
22
+ const node_opcua_status_code_1 = require("node-opcua-status-code");
23
+ const node_opcua_types_1 = require("node-opcua-types");
24
+ const utils = require("node-opcua-utils");
25
+ const node_opcua_variant_1 = require("node-opcua-variant");
26
+ const session_context_1 = require("../source/session_context");
27
+ const multiform_func_1 = require("../source/helpers/multiform_func");
28
+ const base_node_impl_1 = require("./base_node_impl");
29
+ const base_node_private_1 = require("./base_node_private");
30
+ const ua_data_type_impl_1 = require("./ua_data_type_impl");
31
+ const apply_condition_refresh_1 = require("./apply_condition_refresh");
32
+ const ua_variable_impl_ext_obj_1 = require("./ua_variable_impl_ext_obj");
33
+ const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
34
+ const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
35
+ const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
36
+ const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
37
+ function isGoodish(statusCode) {
38
+ return statusCode.value < 0x10000000;
39
+ }
40
+ function adjust_accessLevel(accessLevel) {
41
+ accessLevel = utils.isNullOrUndefined(accessLevel) ? "CurrentRead | CurrentWrite" : accessLevel;
42
+ accessLevel = (0, node_opcua_data_model_1.makeAccessLevelFlag)(accessLevel);
43
+ (0, node_opcua_assert_1.assert)(isFinite(accessLevel));
44
+ return accessLevel;
45
+ }
46
+ exports.adjust_accessLevel = adjust_accessLevel;
47
+ function adjust_userAccessLevel(userAccessLevel, accessLevel) {
48
+ if (userAccessLevel === undefined) {
49
+ return undefined;
50
+ }
51
+ userAccessLevel = adjust_accessLevel(userAccessLevel);
52
+ accessLevel = adjust_accessLevel(accessLevel);
53
+ return (0, node_opcua_data_model_1.makeAccessLevelFlag)(accessLevel & userAccessLevel);
54
+ }
55
+ exports.adjust_userAccessLevel = adjust_userAccessLevel;
56
+ function adjust_samplingInterval(minimumSamplingInterval) {
57
+ (0, node_opcua_assert_1.assert)(isFinite(minimumSamplingInterval));
58
+ if (minimumSamplingInterval < 0) {
59
+ return -1; // only -1 is a valid negative value for samplingInterval and means "unspecified"
60
+ }
61
+ return minimumSamplingInterval;
62
+ }
63
+ function is_Variant(v) {
64
+ return v instanceof node_opcua_variant_1.Variant;
65
+ }
66
+ function is_StatusCode(v) {
67
+ return (v &&
68
+ v.constructor &&
69
+ (v.constructor.name === "ConstantStatusCode" ||
70
+ v.constructor.name === "StatusCode" ||
71
+ v.constructor.name === "ModifiableStatusCode"));
72
+ }
73
+ function is_Variant_or_StatusCode(v) {
74
+ if (is_Variant(v)) {
75
+ // /@@assert(v.isValid());
76
+ }
77
+ return is_Variant(v) || is_StatusCode(v);
78
+ }
79
+ function _dataType_toUADataType(addressSpace, dataType) {
80
+ (0, node_opcua_assert_1.assert)(addressSpace);
81
+ (0, node_opcua_assert_1.assert)(dataType !== node_opcua_variant_1.DataType.Null);
82
+ const dataTypeNode = addressSpace.findDataType(node_opcua_variant_1.DataType[dataType]);
83
+ /* istanbul ignore next */
84
+ if (!dataTypeNode) {
85
+ throw new Error(" Cannot find DataType " + node_opcua_variant_1.DataType[dataType] + " in address Space");
86
+ }
87
+ return dataTypeNode;
88
+ }
89
+ /*=
90
+ *
91
+ * @param addressSpace
92
+ * @param dataTypeNodeId : the nodeId matching the dataType of the destination variable.
93
+ * @param variantDataType: the dataType of the variant to write to the destination variable
94
+ * @param nodeId
95
+ * @return {boolean} true if the variant dataType is compatible with the Variable DataType
96
+ */
97
+ function validateDataType(addressSpace, dataTypeNodeId, variantDataType, nodeId, allowNulls) {
98
+ if (variantDataType === node_opcua_variant_1.DataType.ExtensionObject) {
99
+ return true;
100
+ }
101
+ if (variantDataType === node_opcua_variant_1.DataType.Null && allowNulls) {
102
+ return true;
103
+ }
104
+ if (variantDataType === node_opcua_variant_1.DataType.Null && !allowNulls) {
105
+ return false;
106
+ }
107
+ let builtInType;
108
+ let builtInUADataType;
109
+ const destUADataType = addressSpace.findDataType(dataTypeNodeId);
110
+ (0, node_opcua_assert_1.assert)(destUADataType instanceof ua_data_type_impl_1.UADataTypeImpl);
111
+ if (destUADataType.isAbstract || destUADataType.nodeId.namespace !== 0) {
112
+ builtInUADataType = destUADataType;
113
+ }
114
+ else {
115
+ builtInType = addressSpace.findCorrespondingBasicDataType(destUADataType);
116
+ builtInUADataType = addressSpace.findDataType(builtInType);
117
+ }
118
+ (0, node_opcua_assert_1.assert)(builtInUADataType instanceof ua_data_type_impl_1.UADataTypeImpl);
119
+ const enumerationUADataType = addressSpace.findDataType("Enumeration");
120
+ if (!enumerationUADataType) {
121
+ throw new Error("cannot find Enumeration DataType node in standard address space");
122
+ }
123
+ if (destUADataType.isSupertypeOf(enumerationUADataType)) {
124
+ // istanbul ignore next
125
+ if (doDebug) {
126
+ debugLog("destUADataType.", destUADataType.browseName.toString(), destUADataType.nodeId.toString());
127
+ debugLog("enumerationUADataType.", enumerationUADataType.browseName.toString(), enumerationUADataType.nodeId.toString());
128
+ }
129
+ return true;
130
+ }
131
+ // The value supplied for the attribute is not of the same type as the value.
132
+ const variantUADataType = _dataType_toUADataType(addressSpace, variantDataType);
133
+ (0, node_opcua_assert_1.assert)(variantUADataType instanceof ua_data_type_impl_1.UADataTypeImpl);
134
+ const dest_isSuperTypeOf_variant = variantUADataType.isSupertypeOf(builtInUADataType);
135
+ /* istanbul ignore next */
136
+ if (doDebug) {
137
+ if (dest_isSuperTypeOf_variant) {
138
+ /* istanbul ignore next*/
139
+ debugLog(chalk.green(" ---------- Type match !!! "), " on ", nodeId.toString());
140
+ }
141
+ else {
142
+ /* istanbul ignore next*/
143
+ debugLog(chalk.red(" ---------- Type mismatch "), " on ", nodeId.toString());
144
+ }
145
+ debugLog(chalk.cyan(" Variable data Type is = "), destUADataType.browseName.toString());
146
+ debugLog(chalk.cyan(" which matches basic Type = "), builtInUADataType.browseName.toString());
147
+ debugLog(chalk.yellow(" Actual dataType = "), variantUADataType.browseName.toString());
148
+ }
149
+ return dest_isSuperTypeOf_variant;
150
+ }
151
+ function default_func(dataValue1, callback1) {
152
+ return _default_writable_timestamped_set_func.call(this, dataValue1, callback1);
153
+ }
154
+ /**
155
+ * A OPCUA Variable Node
156
+ *
157
+ * @class UAVariable
158
+ * @constructor
159
+ * @extends BaseNode
160
+ * The AccessLevel Attribute is used to indicate how the Value of a Variable can be accessed (read/write) and if it
161
+ * contains current and/or historic data. The AccessLevel does not take any user access rights into account,
162
+ * i.e. although the Variable is writable this may be restricted to a certain user / user group.
163
+ * The AccessLevel is an 8-bit unsigned integer with the structure defined in the following table:
164
+ *
165
+ * Field Bit Description
166
+ * CurrentRead 0 Indicates if the current value is readable
167
+ * (0 means not readable, 1 means readable).
168
+ * CurrentWrite 1 Indicates if the current value is writable
169
+ * (0 means not writable, 1 means writable).
170
+ * HistoryRead 2 Indicates if the history of the value is readable
171
+ * (0 means not readable, 1 means readable).
172
+ * HistoryWrite 3 Indicates if the history of the value is writable (0 means not writable, 1 means writable).
173
+ * SemanticChange 4 Indicates if the Variable used as Property generates SemanticChangeEvents (see 9.31).
174
+ * Reserved 5:7 Reserved for future use. Shall always be zero.
175
+ *
176
+ * The first two bits also indicate if a current value of this Variable is available and the second two bits
177
+ * indicates if the history of the Variable is available via the OPC UA server.
178
+ *
179
+ */
180
+ class UAVariableImpl extends base_node_impl_1.BaseNodeImpl {
181
+ constructor(options) {
182
+ super(options);
183
+ this.nodeClass = node_opcua_data_model_1.NodeClass.Variable;
184
+ (0, node_opcua_variant_1.verifyRankAndDimensions)(options);
185
+ this.valueRank = options.valueRank;
186
+ this.arrayDimensions = options.arrayDimensions;
187
+ this.dataType = this.resolveNodeId(options.dataType); // DataType (NodeId)
188
+ this.accessLevel = adjust_accessLevel(options.accessLevel);
189
+ this.userAccessLevel = adjust_userAccessLevel(options.userAccessLevel, this.accessLevel);
190
+ this.minimumSamplingInterval = adjust_samplingInterval(options.minimumSamplingInterval || 0);
191
+ this.historizing = !!options.historizing; // coerced to boolean"
192
+ this.$dataValue = new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.UncertainInitialValue, value: { dataType: node_opcua_variant_1.DataType.Null } });
193
+ if (options.value) {
194
+ this.bindVariable(options.value);
195
+ }
196
+ this.setMaxListeners(5000);
197
+ this.semantic_version = 0;
198
+ }
199
+ get typeDefinitionObj() {
200
+ return super.typeDefinitionObj;
201
+ }
202
+ get typeDefinition() {
203
+ return super.typeDefinition;
204
+ }
205
+ checkPermissionAndAccessLevelPrivate(context, permission, accessLevel) {
206
+ (0, node_opcua_assert_1.assert)(context instanceof session_context_1.SessionContext);
207
+ if (context.checkPermission) {
208
+ (0, node_opcua_assert_1.assert)(context.checkPermission instanceof Function);
209
+ if (!context.checkPermission(this, permission)) {
210
+ return false;
211
+ }
212
+ }
213
+ if (this.userAccessLevel === undefined) {
214
+ return true;
215
+ }
216
+ return (this.userAccessLevel & accessLevel) === accessLevel;
217
+ }
218
+ isReadable(context) {
219
+ return (this.accessLevel & node_opcua_data_model_1.AccessLevelFlag.CurrentRead) === node_opcua_data_model_1.AccessLevelFlag.CurrentRead;
220
+ }
221
+ isUserReadable(context) {
222
+ if (!this.isReadable(context)) {
223
+ return false;
224
+ }
225
+ return this.checkPermissionAndAccessLevelPrivate(context, node_opcua_types_1.PermissionType.Read, node_opcua_data_model_1.AccessLevelFlag.CurrentRead);
226
+ }
227
+ isWritable(context) {
228
+ return (this.accessLevel & node_opcua_data_model_1.AccessLevelFlag.CurrentWrite) === node_opcua_data_model_1.AccessLevelFlag.CurrentWrite;
229
+ }
230
+ isUserWritable(context) {
231
+ if (!this.isWritable(context)) {
232
+ return false;
233
+ }
234
+ return this.checkPermissionAndAccessLevelPrivate(context, node_opcua_types_1.PermissionType.Write, node_opcua_data_model_1.AccessLevelFlag.CurrentWrite);
235
+ }
236
+ /**
237
+ *
238
+ *
239
+ * from OPC.UA.Spec 1.02 part 4
240
+ * 5.10.2.4 StatusCodes
241
+ * Table 51 defines values for the operation level statusCode contained in the DataValue structure of
242
+ * each values element. Common StatusCodes are defined in Table 166.
243
+ *
244
+ * Table 51 Read Operation Level Result Codes
245
+ *
246
+ * Symbolic Id Description
247
+ *
248
+ * BadNodeIdInvalid The syntax of the node id is not valid.
249
+ * BadNodeIdUnknown The node id refers to a node that does not exist in the server address space.
250
+ * BadAttributeIdInvalid BadAttributeIdInvalid The attribute is not supported for the specified node.
251
+ * BadIndexRangeInvalid The syntax of the index range parameter is invalid.
252
+ * BadIndexRangeNoData No data exists within the range of indexes specified.
253
+ * BadDataEncodingInvalid The data encoding is invalid.
254
+ * This result is used if no dataEncoding can be applied because an Attribute other
255
+ * than Value was requested or the DataType of the Value Attribute is not a subtype
256
+ * of the Structure DataType.
257
+ * BadDataEncodingUnsupported The server does not support the requested data encoding for the node.
258
+ * This result is used if a dataEncoding can be applied but the passed data encoding
259
+ * is not known to the Server.
260
+ * BadNotReadable The access level does not allow reading or subscribing to the Node.
261
+ * BadUserAccessDenied User does not have permission to perform the requested operation. (table 165)
262
+ */
263
+ readValue(context, indexRange, dataEncoding) {
264
+ if (!context) {
265
+ context = session_context_1.SessionContext.defaultContext;
266
+ }
267
+ if (context.isAccessRestricted(this)) {
268
+ return new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient });
269
+ }
270
+ if (!this.isReadable(context)) {
271
+ return new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadNotReadable });
272
+ }
273
+ if (!this.isUserReadable(context)) {
274
+ return new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied });
275
+ }
276
+ if (!(0, node_opcua_data_model_1.isValidDataEncoding)(dataEncoding)) {
277
+ return new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadDataEncodingInvalid });
278
+ }
279
+ if (this._timestamped_get_func) {
280
+ if (this._timestamped_get_func.length === 0) {
281
+ const dataValueOrPromise = this._timestamped_get_func();
282
+ if (!Object.prototype.hasOwnProperty.call(dataValueOrPromise, "then")) {
283
+ this.$dataValue = dataValueOrPromise;
284
+ this.verifyVariantCompatibility(this.$dataValue.value);
285
+ }
286
+ else {
287
+ errorLog("Unsupported: _timestamped_get_func returns a Promise !");
288
+ }
289
+ }
290
+ }
291
+ let dataValue = this.$dataValue;
292
+ if (isGoodish(dataValue.statusCode)) {
293
+ // note : extractRange will clone the dataValue
294
+ dataValue = (0, node_opcua_data_value_1.extractRange)(dataValue, indexRange);
295
+ }
296
+ /* istanbul ignore next */
297
+ if (dataValue.statusCode.equals(node_opcua_status_code_1.StatusCodes.BadWaitingForInitialData) ||
298
+ dataValue.statusCode.equals(node_opcua_status_code_1.StatusCodes.UncertainInitialValue)) {
299
+ debugLog(chalk.red(" Warning: UAVariable#readValue ") +
300
+ chalk.cyan(this.browseName.toString()) +
301
+ " (" +
302
+ chalk.yellow(this.nodeId.toString()) +
303
+ ") exists but dataValue has not been defined");
304
+ }
305
+ return dataValue;
306
+ }
307
+ isEnumeration() {
308
+ return this.addressSpacePrivate.isEnumeration(this.dataType);
309
+ }
310
+ isExtensionObject() {
311
+ // DataType must be one of Structure
312
+ const dataTypeNode = this.addressSpace.findDataType(this.dataType);
313
+ if (!dataTypeNode) {
314
+ throw new Error(" Cannot find DataType " + this.dataType.toString() + " in standard address Space");
315
+ }
316
+ const structureNode = this.addressSpace.findDataType("Structure");
317
+ if (!structureNode) {
318
+ throw new Error(" Cannot find 'Structure' DataType in standard address Space");
319
+ }
320
+ return dataTypeNode.isSupertypeOf(structureNode);
321
+ }
322
+ _getEnumerationInfo() {
323
+ // DataType must be one of Enumeration
324
+ (0, node_opcua_assert_1.assert)(this.isEnumeration(), "Variable is not an enumeration");
325
+ const dataTypeNode = this.addressSpace.findDataType(this.dataType);
326
+ return dataTypeNode._getEnumerationInfo();
327
+ }
328
+ asyncRefresh(...args) {
329
+ if (isGoodish(this.$dataValue.statusCode)) {
330
+ this.verifyVariantCompatibility(this.$dataValue.value);
331
+ }
332
+ const oldestDate = args[0];
333
+ (0, node_opcua_assert_1.assert)(oldestDate instanceof Date);
334
+ const callback = args[1];
335
+ if (!this.refreshFunc) {
336
+ // no refresh func
337
+ const dataValue = this.readValue();
338
+ dataValue.serverTimestamp = oldestDate;
339
+ dataValue.serverPicoseconds = 0;
340
+ if (oldestDate.getTime() <= dataValue.serverTimestamp.getTime()) {
341
+ return callback(null, dataValue);
342
+ }
343
+ else {
344
+ // fake
345
+ return callback(null, dataValue);
346
+ }
347
+ }
348
+ if (this.$dataValue.serverTimestamp && oldestDate.getTime() <= this.$dataValue.serverTimestamp.getTime()) {
349
+ const dataValue = this.readValue();
350
+ dataValue.serverTimestamp = oldestDate;
351
+ dataValue.serverPicoseconds = 0;
352
+ return callback(null, dataValue);
353
+ }
354
+ try {
355
+ this.refreshFunc.call(this, (err, dataValue) => {
356
+ if (err || !dataValue) {
357
+ errorLog("-------------- refresh call failed", this.browseName.toString(), this.nodeId.toString(), err === null || err === void 0 ? void 0 : err.message);
358
+ dataValue = { statusCode: node_opcua_status_code_1.StatusCodes.BadNoDataAvailable };
359
+ }
360
+ if (dataValue !== this.$dataValue) {
361
+ this._internal_set_dataValue(coerceDataValue(dataValue), null);
362
+ }
363
+ callback(err, this.$dataValue);
364
+ });
365
+ }
366
+ catch (err) {
367
+ errorLog("-------------- refresh call failed 2", this.browseName.toString(), this.nodeId.toString());
368
+ errorLog(err);
369
+ const dataValue = new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadInternalError });
370
+ this._internal_set_dataValue(dataValue, null);
371
+ callback(err, this.$dataValue);
372
+ }
373
+ }
374
+ readEnumValue() {
375
+ const value = this.readValue().value.value;
376
+ const enumInfo = this._getEnumerationInfo();
377
+ const enumV = enumInfo.valueIndex[value];
378
+ return { value, name: enumV ? enumV.name : "?????" };
379
+ }
380
+ writeEnumValue(value) {
381
+ const enumInfo = this._getEnumerationInfo();
382
+ if (typeof value === "string") {
383
+ if (!Object.prototype.hasOwnProperty.call(enumInfo.nameIndex, value)) {
384
+ const possibleValues = Object.keys(enumInfo.nameIndex).join(",");
385
+ throw new Error("UAVariable#writeEnumValue: cannot find value " + value + " in [" + possibleValues + "]");
386
+ }
387
+ const valueIndex = enumInfo.nameIndex[value].value;
388
+ value = valueIndex;
389
+ }
390
+ if (isFinite(value)) {
391
+ const possibleValues = Object.keys(enumInfo.nameIndex).join(",");
392
+ if (!enumInfo.valueIndex[value]) {
393
+ throw new Error("UAVariable#writeEnumValue : value out of range " + value + " in [" + possibleValues + "]");
394
+ }
395
+ this.setValueFromSource({
396
+ dataType: node_opcua_variant_1.DataType.Int32,
397
+ value
398
+ });
399
+ }
400
+ else {
401
+ throw new Error("UAVariable#writeEnumValue: value type mismatch");
402
+ }
403
+ }
404
+ readAttribute(context, attributeId, indexRange, dataEncoding) {
405
+ context = context || session_context_1.SessionContext.defaultContext;
406
+ (0, node_opcua_assert_1.assert)(context instanceof session_context_1.SessionContext);
407
+ const options = {};
408
+ if (attributeId !== node_opcua_data_model_1.AttributeIds.Value) {
409
+ if (indexRange && indexRange.isDefined()) {
410
+ options.statusCode = node_opcua_status_code_1.StatusCodes.BadIndexRangeNoData;
411
+ return new node_opcua_data_value_1.DataValue(options);
412
+ }
413
+ if ((0, node_opcua_data_model_1.isDataEncoding)(dataEncoding)) {
414
+ options.statusCode = node_opcua_status_code_1.StatusCodes.BadDataEncodingInvalid;
415
+ return new node_opcua_data_value_1.DataValue(options);
416
+ }
417
+ }
418
+ switch (attributeId) {
419
+ case node_opcua_data_model_1.AttributeIds.Value:
420
+ return this.readValue(context, indexRange, dataEncoding);
421
+ case node_opcua_data_model_1.AttributeIds.DataType:
422
+ return this._readDataType();
423
+ case node_opcua_data_model_1.AttributeIds.ValueRank:
424
+ return this._readValueRank();
425
+ case node_opcua_data_model_1.AttributeIds.ArrayDimensions:
426
+ return this._readArrayDimensions();
427
+ case node_opcua_data_model_1.AttributeIds.AccessLevel:
428
+ return this._readAccessLevel(context);
429
+ case node_opcua_data_model_1.AttributeIds.UserAccessLevel:
430
+ return this._readUserAccessLevel(context);
431
+ case node_opcua_data_model_1.AttributeIds.MinimumSamplingInterval:
432
+ return this._readMinimumSamplingInterval();
433
+ case node_opcua_data_model_1.AttributeIds.Historizing:
434
+ return this._readHistorizing();
435
+ case node_opcua_data_model_1.AttributeIds.AccessLevelEx:
436
+ return this._readAccessLevelEx(context);
437
+ default:
438
+ return base_node_impl_1.BaseNodeImpl.prototype.readAttribute.call(this, context, attributeId);
439
+ }
440
+ }
441
+ getBasicDataType() {
442
+ if (this._basicDataType) {
443
+ return this._basicDataType;
444
+ }
445
+ if (this.dataType.namespace === 0 && this.dataType.value === 0) {
446
+ return node_opcua_variant_1.DataType.Null;
447
+ }
448
+ const addressSpace = this.addressSpace;
449
+ if (!addressSpace) {
450
+ // may be node has been deleted already
451
+ return node_opcua_variant_1.DataType.Null;
452
+ }
453
+ const dataTypeNode = addressSpace.findDataType(this.dataType);
454
+ const basicDataType = dataTypeNode && dataTypeNode.nodeClass === node_opcua_data_model_1.NodeClass.DataType ? dataTypeNode.getBasicDataType() : node_opcua_variant_1.DataType.Null;
455
+ // const basicDataType = addressSpace.findCorrespondingBasicDataType(this.dataType);
456
+ this._basicDataType = basicDataType;
457
+ return basicDataType;
458
+ }
459
+ adjustVariant(variant) {
460
+ return (0, node_opcua_variant_1.adjustVariant)(variant, this.valueRank, this.getBasicDataType());
461
+ }
462
+ verifyVariantCompatibility(variant) {
463
+ try {
464
+ // istanbul ignore next
465
+ if (Object.prototype.hasOwnProperty.call(variant, "value")) {
466
+ if (variant.dataType === null || variant.dataType === undefined) {
467
+ throw new Error("Variant must provide a valid dataType : variant = " +
468
+ variant.toString() +
469
+ " this.dataType= " +
470
+ this.dataType.toString());
471
+ }
472
+ if (variant.dataType === node_opcua_variant_1.DataType.Boolean &&
473
+ (this.dataType.namespace !== 0 || this.dataType.value !== node_opcua_variant_1.DataType.Boolean)) {
474
+ throw new Error("Variant must provide a valid Boolean : variant = " +
475
+ variant.toString() +
476
+ " this.dataType= " +
477
+ this.dataType.toString());
478
+ }
479
+ if (this.dataType.namespace === 0 &&
480
+ this.dataType.value === node_opcua_variant_1.DataType.LocalizedText &&
481
+ variant.dataType !== node_opcua_variant_1.DataType.LocalizedText &&
482
+ variant.dataType !== node_opcua_variant_1.DataType.Null) {
483
+ throw new Error("Variant must provide a valid LocalizedText : variant = " +
484
+ variant.toString() +
485
+ " this.dataType= " +
486
+ this.dataType.toString());
487
+ }
488
+ }
489
+ const basicType = this.getBasicDataType();
490
+ if (basicType === node_opcua_variant_1.DataType.String && variant.dataType === node_opcua_variant_1.DataType.ByteString) {
491
+ return; // this is allowed
492
+ }
493
+ if (basicType === node_opcua_variant_1.DataType.ByteString && variant.dataType === node_opcua_variant_1.DataType.String) {
494
+ return; // this is allowed
495
+ }
496
+ if (basicType !== node_opcua_variant_1.DataType.Null &&
497
+ basicType !== node_opcua_variant_1.DataType.Variant &&
498
+ variant.dataType !== node_opcua_variant_1.DataType.Null &&
499
+ variant.dataType !== basicType) {
500
+ const message = "UAVariable.setValueFromSource " +
501
+ this.browseName.toString() +
502
+ " nodeId:" +
503
+ this.nodeId.toString() +
504
+ " dataType:" +
505
+ this.dataType.toString() +
506
+ ":\n" +
507
+ "the provided variant must have the expected dataType!\n" +
508
+ " - the expected dataType is " +
509
+ chalk.cyan(node_opcua_variant_1.DataType[basicType]) +
510
+ "\n" +
511
+ " - the actual dataType is " +
512
+ chalk.magenta(node_opcua_variant_1.DataType[variant.dataType]) +
513
+ "\n" +
514
+ " - " +
515
+ variant.toString();
516
+ throw new Error(message);
517
+ }
518
+ }
519
+ catch (err) {
520
+ errorLog("UAVariable ", err === null || err === void 0 ? void 0 : err.message, this.browseName.toString(), " nodeId=", this.nodeId.toString());
521
+ errorLog(err.message);
522
+ errorLog(err.stack);
523
+ throw err;
524
+ }
525
+ }
526
+ /**
527
+ * setValueFromSource is used to let the device sets the variable values
528
+ * this method also records the current time as sourceTimestamp and serverTimestamp.
529
+ . *
530
+ * The method will raise an exception if the value is not compatible with the dataType and expected dimension
531
+ *
532
+ * @method setValueFromSource
533
+ * @param variant {Variant}
534
+ * @param [statusCode {StatusCode} = StatusCodes.Good]
535
+ * @param [sourceTimestamp= Now]
536
+ */
537
+ setValueFromSource(variant, statusCode, sourceTimestamp) {
538
+ var _a;
539
+ try {
540
+ statusCode = statusCode || node_opcua_status_code_1.StatusCodes.Good;
541
+ const variant1 = node_opcua_variant_1.Variant.coerce(variant);
542
+ this.verifyVariantCompatibility(variant1);
543
+ const now = (0, node_opcua_date_time_1.coerceClock)(sourceTimestamp, 0);
544
+ const dataValue = new node_opcua_data_value_1.DataValue(null);
545
+ dataValue.serverPicoseconds = now.picoseconds;
546
+ dataValue.serverTimestamp = now.timestamp;
547
+ dataValue.sourcePicoseconds = now.picoseconds;
548
+ dataValue.sourceTimestamp = now.timestamp;
549
+ dataValue.statusCode = statusCode;
550
+ dataValue.value = variant1;
551
+ if (dataValue.value.dataType === node_opcua_variant_1.DataType.ExtensionObject) {
552
+ const valueIsCorrect = this.checkExtensionObjectIsCorrect(dataValue.value.value);
553
+ if (!valueIsCorrect) {
554
+ errorLog("Invalid value !");
555
+ errorLog(this.toString());
556
+ errorLog(dataValue.toString());
557
+ this.checkExtensionObjectIsCorrect(dataValue.value.value);
558
+ }
559
+ this.$dataValue = dataValue;
560
+ // ----------------------------------
561
+ if (this.$extensionObject) {
562
+ // we have an extension object already bound to this node
563
+ // the client is asking us to replace the object entierly by a new one
564
+ const ext = dataValue.value.value;
565
+ (0, ua_variable_impl_ext_obj_1._setExtensionObject)(this, ext);
566
+ return;
567
+ }
568
+ }
569
+ else {
570
+ this._internal_set_dataValue(dataValue);
571
+ }
572
+ }
573
+ catch (err) {
574
+ errorLog("UAVariable#setValueFromString Error : ", this.browseName.toString(), this.nodeId.toString());
575
+ errorLog(err.message);
576
+ errorLog((_a = this.parent) === null || _a === void 0 ? void 0 : _a.toString());
577
+ throw err;
578
+ }
579
+ }
580
+ writeValue(context, dataValue, ...args) {
581
+ context = context || session_context_1.SessionContext.defaultContext;
582
+ (0, node_opcua_assert_1.assert)(context instanceof session_context_1.SessionContext);
583
+ if (!dataValue.sourceTimestamp) {
584
+ // source timestamp was not specified by the caller
585
+ // we will set the timestamp ourself with the current clock
586
+ if (context.currentTime) {
587
+ dataValue.sourceTimestamp = context.currentTime.timestamp;
588
+ dataValue.sourcePicoseconds = context.currentTime.picoseconds;
589
+ }
590
+ else {
591
+ const { timestamp, picoseconds } = (0, node_opcua_date_time_1.getCurrentClock)();
592
+ dataValue.sourceTimestamp = timestamp;
593
+ dataValue.sourcePicoseconds = picoseconds;
594
+ }
595
+ }
596
+ if (context.currentTime && !dataValue.serverTimestamp) {
597
+ dataValue.serverTimestamp = context.currentTime.timestamp;
598
+ dataValue.serverPicoseconds = context.currentTime.picoseconds;
599
+ }
600
+ // adjust arguments if optional indexRange Parameter is not given
601
+ let indexRange = null;
602
+ let callback;
603
+ if (args.length === 1) {
604
+ indexRange = new node_opcua_numeric_range_1.NumericRange();
605
+ callback = args[0];
606
+ }
607
+ else if (args.length === 2) {
608
+ indexRange = args[0];
609
+ callback = args[1];
610
+ }
611
+ else {
612
+ throw new Error("Invalid Number of args");
613
+ }
614
+ (0, node_opcua_assert_1.assert)(typeof callback === "function");
615
+ (0, node_opcua_assert_1.assert)(dataValue instanceof node_opcua_data_value_1.DataValue);
616
+ // index range could be string
617
+ indexRange = node_opcua_numeric_range_1.NumericRange.coerce(indexRange);
618
+ // test write permission
619
+ if (!this.isWritable(context)) {
620
+ return callback(null, node_opcua_status_code_1.StatusCodes.BadNotWritable);
621
+ }
622
+ if (!this.isUserWritable(context)) {
623
+ return callback(null, node_opcua_status_code_1.StatusCodes.BadUserAccessDenied);
624
+ }
625
+ // adjust special case
626
+ const variant = adjustVariant2.call(this, dataValue.value);
627
+ const statusCode = this.checkVariantCompatibility(variant);
628
+ if (statusCode.isNot(node_opcua_status_code_1.StatusCodes.Good)) {
629
+ return callback(null, statusCode);
630
+ }
631
+ const write_func = this._timestamped_set_func || default_func;
632
+ if (!write_func) {
633
+ warningLog(" warning " + this.nodeId.toString() + " " + this.browseName.toString() + " has no setter. \n");
634
+ warningLog("Please make sure to bind the variable or to pass a valid value: new Variant({}) during construction time");
635
+ return callback(null, node_opcua_status_code_1.StatusCodes.BadNotWritable);
636
+ }
637
+ (0, node_opcua_assert_1.assert)(write_func);
638
+ write_func.call(this, dataValue, (err, statusCode1) => {
639
+ if (!err) {
640
+ dataValue && this.verifyVariantCompatibility(dataValue.value);
641
+ if (indexRange && !indexRange.isEmpty()) {
642
+ if (!indexRange.isValid()) {
643
+ return callback(null, node_opcua_status_code_1.StatusCodes.BadIndexRangeInvalid);
644
+ }
645
+ const newArrayOrMatrix = dataValue.value.value;
646
+ if (dataValue.value.arrayType === node_opcua_variant_1.VariantArrayType.Array) {
647
+ if (this.$dataValue.value.arrayType !== node_opcua_variant_1.VariantArrayType.Array) {
648
+ return callback(null, node_opcua_status_code_1.StatusCodes.BadTypeMismatch);
649
+ }
650
+ // check that destination data is also an array
651
+ (0, node_opcua_assert_1.assert)(check_valid_array(this.$dataValue.value.dataType, this.$dataValue.value.value));
652
+ const destArr = this.$dataValue.value.value;
653
+ const result = indexRange.set_values(destArr, newArrayOrMatrix);
654
+ if (result.statusCode.isNot(node_opcua_status_code_1.StatusCodes.Good)) {
655
+ return callback(null, result.statusCode);
656
+ }
657
+ dataValue.value.value = result.array;
658
+ // scrap original array so we detect range
659
+ this.$dataValue.value.value = null;
660
+ }
661
+ else if (dataValue.value.arrayType === node_opcua_variant_1.VariantArrayType.Matrix) {
662
+ const dimensions = this.$dataValue.value.dimensions;
663
+ if (this.$dataValue.value.arrayType !== node_opcua_variant_1.VariantArrayType.Matrix || !dimensions) {
664
+ // not a matrix !
665
+ return callback(null, node_opcua_status_code_1.StatusCodes.BadTypeMismatch);
666
+ }
667
+ const matrix = this.$dataValue.value.value;
668
+ const result = indexRange.set_values_matrix({
669
+ matrix,
670
+ dimensions
671
+ }, newArrayOrMatrix);
672
+ if (result.statusCode.isNot(node_opcua_status_code_1.StatusCodes.Good)) {
673
+ return callback(null, result.statusCode);
674
+ }
675
+ dataValue.value.dimensions = this.$dataValue.value.dimensions;
676
+ dataValue.value.value = result.matrix;
677
+ // scrap original array so we detect range
678
+ this.$dataValue.value.value = null;
679
+ }
680
+ else {
681
+ return callback(null, node_opcua_status_code_1.StatusCodes.BadTypeMismatch);
682
+ }
683
+ }
684
+ try {
685
+ this._internal_set_dataValue(dataValue, indexRange);
686
+ }
687
+ catch (err) {
688
+ if (err instanceof Error) {
689
+ warningLog(err.message);
690
+ }
691
+ return callback(null, node_opcua_status_code_1.StatusCodes.BadInternalError);
692
+ }
693
+ }
694
+ callback(err || null, statusCode1);
695
+ });
696
+ }
697
+ writeAttribute(context, writeValueOptions, callback) {
698
+ // istanbul ignore next
699
+ if (!callback) {
700
+ throw new Error("Internal error");
701
+ }
702
+ const writeValue = writeValueOptions instanceof node_opcua_service_write_1.WriteValue ? writeValueOptions : new node_opcua_service_write_1.WriteValue(writeValueOptions);
703
+ context = context || session_context_1.SessionContext.defaultContext;
704
+ (0, node_opcua_assert_1.assert)(context instanceof session_context_1.SessionContext);
705
+ (0, node_opcua_assert_1.assert)(writeValue instanceof node_opcua_service_write_1.WriteValue);
706
+ (0, node_opcua_assert_1.assert)(writeValue.value instanceof node_opcua_data_value_1.DataValue);
707
+ (0, node_opcua_assert_1.assert)(writeValue.value.value instanceof node_opcua_variant_1.Variant);
708
+ (0, node_opcua_assert_1.assert)(typeof callback === "function");
709
+ // Spec 1.0.2 Part 4 page 58
710
+ // If the SourceTimestamp or the ServerTimestamp is specified, the Server shall
711
+ // use these values.
712
+ // xx _apply_default_timestamps(writeValue.value);
713
+ switch (writeValue.attributeId) {
714
+ case node_opcua_data_model_1.AttributeIds.Value:
715
+ this.writeValue(context, writeValue.value, writeValue.indexRange, callback);
716
+ break;
717
+ case node_opcua_data_model_1.AttributeIds.Historizing:
718
+ if (writeValue.value.value.dataType !== node_opcua_variant_1.DataType.Boolean) {
719
+ return callback(null, node_opcua_status_code_1.StatusCodes.BadNotSupported);
720
+ }
721
+ // if the variable has no historizing in place reject
722
+ if (!this["hA Configuration"]) {
723
+ return callback(null, node_opcua_status_code_1.StatusCodes.BadNotSupported);
724
+ }
725
+ // check if user is allowed to do that !
726
+ // TODO
727
+ this.historizing = !!writeValue.value.value.value; // yes ! indeed !
728
+ return callback(null, node_opcua_status_code_1.StatusCodes.Good);
729
+ default:
730
+ super.writeAttribute(context, writeValue, callback);
731
+ break;
732
+ }
733
+ }
734
+ /**
735
+ * @method checkVariantCompatibility
736
+ * note:
737
+ * this method is overridden in address-space-data-access
738
+ * @return {StatusCode}
739
+ */
740
+ checkVariantCompatibility(value) {
741
+ // test dataType
742
+ if (!this._validate_DataType(value.dataType)) {
743
+ return node_opcua_status_code_1.StatusCodes.BadTypeMismatch;
744
+ }
745
+ try {
746
+ this.verifyVariantCompatibility(value);
747
+ }
748
+ catch (err) {
749
+ return node_opcua_status_code_1.StatusCodes.BadTypeMismatch;
750
+ }
751
+ return node_opcua_status_code_1.StatusCodes.Good;
752
+ }
753
+ /**
754
+ * touch the source timestamp of a Variable and cascade up the change
755
+ * to the parent variable if any.
756
+ */
757
+ touchValue(optionalNow) {
758
+ const now = optionalNow || (0, node_opcua_date_time_1.getCurrentClock)();
759
+ (0, ua_variable_impl_ext_obj_1.propagateTouchValueUpward)(this, now);
760
+ }
761
+ /**
762
+ * bind a variable with a get and set functions.
763
+ *
764
+ * properties:
765
+ * - value: a Variant or a status code
766
+ * - sourceTimestamp
767
+ * - sourcePicoseconds
768
+ * @param [options.timestamped_set]
769
+ * @param [options.refreshFunc] the variable asynchronous getter function.
770
+ * @param [overwrite {Boolean} = false] set overwrite to true to overwrite existing binding
771
+ * @return void
772
+ *
773
+ *
774
+ * ### Providing read access to the underlying value
775
+ *
776
+ * #### Variation 1
777
+ *
778
+ * In this variation, the user provides a function that returns a Variant with the current value.
779
+ *
780
+ * The sourceTimestamp will be set automatically.
781
+ *
782
+ * The get function is called synchronously.
783
+ *
784
+ * @example
785
+ *
786
+ *
787
+ * ```javascript
788
+ * ...
789
+ * var options = {
790
+ * get : () => {
791
+ * return new Variant({...});
792
+ * },
793
+ * set : function(variant) {
794
+ * // store the variant somewhere
795
+ * return StatusCodes.Good;
796
+ * }
797
+ * };
798
+ * ...
799
+ * engine.bindVariable(nodeId,options):
800
+ * ...
801
+ * ```
802
+ *
803
+ *
804
+ * #### Variation 2:
805
+ *
806
+ * This variation can be used when the user wants to specify a specific '''sourceTimestamp''' associated
807
+ * with the current value of the UAVariable.
808
+ *
809
+ * The provided ```timestamped_get``` function should return an object with three properties:
810
+ * * value: containing the variant value or a error StatusCode,
811
+ * * sourceTimestamp
812
+ * * sourcePicoseconds
813
+ *
814
+ * ```javascript
815
+ * ...
816
+ * var myDataValue = new DataValue({
817
+ * value: {dataType: DataType.Double , value: 10.0},
818
+ * sourceTimestamp : new Date(),
819
+ * sourcePicoseconds: 0
820
+ * });
821
+ * ...
822
+ * var options = {
823
+ * timestamped_get : () => { return myDataValue; }
824
+ * };
825
+ * ...
826
+ * engine.bindVariable(nodeId,options):
827
+ * ...
828
+ * // record a new value
829
+ * myDataValue.value.value = 5.0;
830
+ * myDataValue.sourceTimestamp = new Date();
831
+ * ...
832
+ * ```
833
+ *
834
+ *
835
+ * #### Variation 3:
836
+ *
837
+ * This variation can be used when the value associated with the variables requires a asynchronous function call to be
838
+ * extracted. In this case, the user should provide an async method ```refreshFunc```.
839
+ *
840
+ *
841
+ * The ```refreshFunc``` shall do whatever is necessary to fetch the most up to date version of the variable value, and
842
+ * call the ```callback``` function when the data is ready.
843
+ *
844
+ *
845
+ * The ```callback``` function follow the standard callback function signature:
846
+ * * the first argument shall be **null** or **Error**, depending of the outcome of the fetch operation,
847
+ * * the second argument shall be a DataValue with the new UAVariable Value, a StatusCode, and time stamps.
848
+ *
849
+ *
850
+ * Optionally, it is possible to pass a sourceTimestamp and a sourcePicoseconds value as a third and fourth arguments
851
+ * of the callback. When sourceTimestamp and sourcePicoseconds are missing, the system will set their default value
852
+ * to the current time..
853
+ *
854
+ *
855
+ * ```javascript
856
+ * ...
857
+ * var options = {
858
+ * refreshFunc : function(callback) {
859
+ * ... do_some_async_stuff_to_get_the_new_variable_value
860
+ * var dataValue = new DataValue({
861
+ * value: new Variant({...}),
862
+ * statusCode: StatusCodes.Good,
863
+ * sourceTimestamp: new Date()
864
+ * });
865
+ * callback(null,dataValue);
866
+ * }
867
+ * };
868
+ * ...
869
+ * variable.bindVariable(nodeId,options):
870
+ * ...
871
+ * ```
872
+ *
873
+ * ### Providing write access to the underlying value
874
+ *
875
+ * #### Variation1 - provide a simple synchronous set function
876
+ *
877
+ *
878
+ * #### Notes
879
+ * to do : explain return StatusCodes.GoodCompletesAsynchronously;
880
+ *
881
+ */
882
+ bindVariable(options, overwrite) {
883
+ if (overwrite) {
884
+ this._timestamped_set_func = null;
885
+ this._timestamped_get_func = null;
886
+ this._get_func = null;
887
+ this._set_func = null;
888
+ this.refreshFunc = undefined;
889
+ this._historyRead = UAVariableImpl.prototype._historyRead;
890
+ }
891
+ options = options || {};
892
+ (0, node_opcua_assert_1.assert)(typeof this._timestamped_set_func !== "function", "UAVariable already bound");
893
+ (0, node_opcua_assert_1.assert)(typeof this._timestamped_get_func !== "function", "UAVariable already bound");
894
+ bind_getter.call(this, options);
895
+ bind_setter.call(this, options);
896
+ const _historyRead = options.historyRead;
897
+ if (_historyRead) {
898
+ (0, node_opcua_assert_1.assert)(typeof this._historyRead !== "function" || this._historyRead === UAVariableImpl.prototype._historyRead);
899
+ (0, node_opcua_assert_1.assert)(typeof _historyRead === "function");
900
+ this._historyRead = _historyRead;
901
+ (0, node_opcua_assert_1.assert)(this._historyRead.length === 6);
902
+ }
903
+ // post conditions
904
+ (0, node_opcua_assert_1.assert)(typeof this._timestamped_set_func === "function");
905
+ (0, node_opcua_assert_1.assert)(this._timestamped_set_func.length === 2, "expecting 2 parameters");
906
+ }
907
+ readValueAsync(context, callback) {
908
+ if (!context) {
909
+ context = session_context_1.SessionContext.defaultContext;
910
+ }
911
+ (0, node_opcua_assert_1.assert)(typeof callback === "function");
912
+ this.__waiting_callbacks = this.__waiting_callbacks || [];
913
+ this.__waiting_callbacks.push(callback);
914
+ const _readValueAsync_in_progress = this.__waiting_callbacks.length >= 2;
915
+ if (_readValueAsync_in_progress) {
916
+ return;
917
+ }
918
+ const readImmediate = (innerCallback) => {
919
+ (0, node_opcua_assert_1.assert)(this.$dataValue instanceof node_opcua_data_value_1.DataValue);
920
+ const dataValue = this.readValue();
921
+ innerCallback(null, dataValue);
922
+ };
923
+ let func;
924
+ if (!this.isReadable(context)) {
925
+ func = (innerCallback) => {
926
+ const dataValue = new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadNotReadable });
927
+ innerCallback(null, dataValue);
928
+ };
929
+ }
930
+ else if (!this.isUserReadable(context)) {
931
+ func = (innerCallback) => {
932
+ const dataValue = new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied });
933
+ innerCallback(null, dataValue);
934
+ };
935
+ }
936
+ else {
937
+ func = typeof this.refreshFunc === "function" ? this.asyncRefresh.bind(this, new Date()) : readImmediate;
938
+ }
939
+ const satisfy_callbacks = (err, dataValue) => {
940
+ // now call all pending callbacks
941
+ const callbacks = this.__waiting_callbacks || [];
942
+ this.__waiting_callbacks = [];
943
+ const n = callbacks.length;
944
+ for (const callback1 of callbacks) {
945
+ callback1.call(this, err, dataValue);
946
+ }
947
+ };
948
+ try {
949
+ func.call(this, satisfy_callbacks);
950
+ }
951
+ catch (err) {
952
+ // istanbul ignore next
953
+ if (doDebug) {
954
+ debugLog(chalk.red("func readValueAsync has failed "));
955
+ if (err instanceof Error) {
956
+ debugLog(" stack", err.stack);
957
+ }
958
+ }
959
+ satisfy_callbacks(err);
960
+ }
961
+ }
962
+ getWriteMask() {
963
+ return super.getWriteMask();
964
+ }
965
+ getUserWriteMask() {
966
+ return super.getUserWriteMask();
967
+ }
968
+ clone(options, optionalFilter, extraInfo) {
969
+ options = Object.assign(Object.assign({}, options), {
970
+ // check this eventNotifier: this.eventNotifier,
971
+ // check this symbolicName: this.symbolicName,
972
+ accessLevel: this.accessLevel, arrayDimensions: this.arrayDimensions, dataType: this.dataType, historizing: this.historizing, minimumSamplingInterval: this.minimumSamplingInterval, userAccessLevel: this.userAccessLevel, valueRank: this.valueRank });
973
+ const newVariable = base_node_private_1._clone.call(this, UAVariableImpl, options, optionalFilter || node_opcua_address_space_base_1.defaultCloneFilter, extraInfo || node_opcua_address_space_base_1.defaultCloneExtraInfo);
974
+ newVariable.bindVariable();
975
+ (0, node_opcua_assert_1.assert)(typeof newVariable._timestamped_set_func === "function");
976
+ (0, node_opcua_assert_1.assert)(newVariable.dataType === this.dataType);
977
+ newVariable.$dataValue = this.$dataValue.clone();
978
+ // also bind extension object
979
+ const v = newVariable.$dataValue.value;
980
+ if (v.dataType === node_opcua_variant_1.DataType.ExtensionObject && v.value && v.arrayType === node_opcua_variant_1.VariantArrayType.Scalar) {
981
+ try {
982
+ newVariable.bindExtensionObject(newVariable.$dataValue.value.value);
983
+ }
984
+ catch (err) {
985
+ errorLog("Errro binding extension objects");
986
+ errorLog(err.message);
987
+ errorLog(this.toString());
988
+ errorLog("---------------------------------------");
989
+ errorLog(this.$dataValue.toString());
990
+ errorLog("---------------------------------------");
991
+ errorLog(newVariable.$dataValue.toString());
992
+ throw err;
993
+ }
994
+ }
995
+ return newVariable;
996
+ }
997
+ getDataTypeNode() {
998
+ const addressSpace = this.addressSpace;
999
+ const dt = addressSpace.findNode(this.dataType);
1000
+ // istanbul ignore next
1001
+ if (!dt) {
1002
+ throw new Error("getDataTypeNode: cannot find dataType " + this.dataType.toString());
1003
+ }
1004
+ return dt;
1005
+ }
1006
+ get dataTypeObj() {
1007
+ return this.getDataTypeNode();
1008
+ }
1009
+ checkExtensionObjectIsCorrect(extObj) {
1010
+ if (!extObj) {
1011
+ return true;
1012
+ }
1013
+ const addressSpace = this.addressSpace;
1014
+ const dataType = addressSpace.findDataType(this.dataType);
1015
+ if (!dataType) {
1016
+ // may be we are in the process of loading a xml file and the corresponding dataType
1017
+ // has not yet been loaded !
1018
+ return true;
1019
+ }
1020
+ const Constructor = addressSpace.getExtensionObjectConstructor(this.dataType);
1021
+ if (this.valueRank === -1) {
1022
+ /** Scalar */
1023
+ if (extObj instanceof Array) {
1024
+ return false;
1025
+ }
1026
+ return checkExtensionObjectIsCorrectScalar.call(this, extObj);
1027
+ }
1028
+ else if (this.valueRank === 1) {
1029
+ /** array */
1030
+ if (!(extObj instanceof Array)) {
1031
+ // let's coerce this scalar into an 1-element array if it is a valid extension object
1032
+ if (checkExtensionObjectIsCorrectScalar.call(this, extObj)) {
1033
+ warningLog(`checkExtensionObjectIsCorrect : expecting a array but got a scalar (value rank of ${this.browseName.toString()} is 1)`);
1034
+ extObj = [extObj];
1035
+ }
1036
+ else {
1037
+ return false;
1038
+ }
1039
+ }
1040
+ return checkExtensionObjectIsCorrectArray.call(this, extObj);
1041
+ }
1042
+ else if (this.valueRank === 0) {
1043
+ // Scalar or Array
1044
+ const isCorrectScalar = !Array.isArray(extObj) && checkExtensionObjectIsCorrectScalar.call(this, extObj);
1045
+ const isCorrectArray = Array.isArray(extObj) && checkExtensionObjectIsCorrectArray.call(this, extObj);
1046
+ return isCorrectArray || isCorrectScalar;
1047
+ }
1048
+ else {
1049
+ throw new Error(`checkExtensionObjectIsCorrect: Not Implemented case, please contact sterfive : this.valueRank =${this.valueRank}`);
1050
+ }
1051
+ function checkExtensionObjectIsCorrectScalar(extObj) {
1052
+ // istanbul ignore next
1053
+ if (!(extObj && extObj.constructor)) {
1054
+ errorLog(extObj);
1055
+ throw new Error("expecting an valid extension object");
1056
+ }
1057
+ return extObj.constructor.name === Constructor.name;
1058
+ }
1059
+ function checkExtensionObjectIsCorrectArray(extObjArray) {
1060
+ // istanbul ignore next
1061
+ for (const extObj of extObjArray) {
1062
+ if (!(extObj && extObj.constructor)) {
1063
+ errorLog(extObj);
1064
+ throw new Error("expecting an valid extension object");
1065
+ }
1066
+ }
1067
+ try {
1068
+ for (const e of extObjArray) {
1069
+ if (!e) {
1070
+ continue;
1071
+ }
1072
+ if (e.constructor.name !== Constructor.name) {
1073
+ debugLog("extObj.constructor.name ", e.constructor.name, "expected", Constructor.name);
1074
+ return false;
1075
+ }
1076
+ }
1077
+ return true;
1078
+ }
1079
+ catch (err) {
1080
+ errorLog(err);
1081
+ return false;
1082
+ }
1083
+ }
1084
+ }
1085
+ /**
1086
+ * @private
1087
+ * install UAVariable to exposed th
1088
+ *
1089
+ * precondition:
1090
+ */
1091
+ installExtensionObjectVariables() {
1092
+ (0, ua_variable_impl_ext_obj_1._installExtensionObjectBindingOnProperties)(this, { createMissingProp: true });
1093
+ // now recursively install extension object on children
1094
+ for (const child of this.getComponents()) {
1095
+ if (child.nodeClass === node_opcua_data_model_1.NodeClass.Variable && child instanceof UAVariableImpl) {
1096
+ if (child.isExtensionObject()) {
1097
+ child.installExtensionObjectVariables();
1098
+ }
1099
+ }
1100
+ }
1101
+ }
1102
+ /**
1103
+ * @method bindExtensionObject
1104
+ * @return {ExtensionObject}
1105
+ */
1106
+ bindExtensionObjectScalar(optionalExtensionObject, options) {
1107
+ return this.bindExtensionObject(optionalExtensionObject, options);
1108
+ }
1109
+ bindExtensionObjectArray(optionalExtensionObject, options) {
1110
+ return this.bindExtensionObject(optionalExtensionObject, options);
1111
+ }
1112
+ bindExtensionObject(optionalExtensionObject, options) {
1113
+ return (0, ua_variable_impl_ext_obj_1._bindExtensionObject)(this, optionalExtensionObject, options);
1114
+ }
1115
+ updateExtensionObjectPartial(partialExtensionObject) {
1116
+ (0, ua_variable_impl_ext_obj_1.setExtensionObjectValue)(this, partialExtensionObject);
1117
+ return this.$extensionObject;
1118
+ }
1119
+ incrementExtensionObjectPartial(path) {
1120
+ const extensionObject = this.readValue().value.value;
1121
+ const partialData = (0, ua_variable_impl_ext_obj_1.extractPartialData)(path, extensionObject);
1122
+ (0, ua_variable_impl_ext_obj_1.setExtensionObjectValue)(this, partialData);
1123
+ }
1124
+ toString() {
1125
+ const options = new base_node_private_1.ToStringBuilder();
1126
+ base_node_private_1.UAVariable_toString.call(this, options);
1127
+ return options.toString();
1128
+ }
1129
+ historyRead(context, historyReadDetails, indexRange, dataEncoding, continuationData, callback) {
1130
+ (0, node_opcua_assert_1.assert)(context instanceof session_context_1.SessionContext);
1131
+ (0, node_opcua_assert_1.assert)(typeof callback === "function");
1132
+ if (typeof this._historyRead !== "function") {
1133
+ return callback(null, new node_opcua_types_1.HistoryReadResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadNotReadable }));
1134
+ }
1135
+ this._historyRead(context, historyReadDetails, indexRange, dataEncoding, continuationData, callback);
1136
+ }
1137
+ _historyReadRaw(context, historyReadRawModifiedDetails, indexRange, dataEncoding, continuationData, callback) {
1138
+ throw new Error("");
1139
+ }
1140
+ _historyReadRawModify(context, historyReadRawModifiedDetails, indexRange, dataEncoding, continuationData, callback) {
1141
+ throw new Error("");
1142
+ }
1143
+ _historyRead(context, historyReadDetails, indexRange, dataEncoding, continuationData, callback) {
1144
+ const result = new node_opcua_types_1.HistoryReadResult({
1145
+ statusCode: node_opcua_status_code_1.StatusCodes.BadHistoryOperationUnsupported
1146
+ });
1147
+ callback(null, result);
1148
+ }
1149
+ _historyPush(newDataValue) {
1150
+ throw new Error("");
1151
+ }
1152
+ _historyReadRawAsync(historyReadRawModifiedDetails, maxNumberToExtract, isReversed, reverseDataValue, callback) {
1153
+ throw new Error("");
1154
+ }
1155
+ _historyReadModify(context, historyReadRawModifiedDetails, indexRange, dataEncoding, continuationData, callback) {
1156
+ throw new Error("");
1157
+ }
1158
+ _update_startOfOnlineArchive(newDate) {
1159
+ // please install
1160
+ throw new Error("");
1161
+ }
1162
+ _update_startOfArchive(newDate) {
1163
+ throw new Error("");
1164
+ }
1165
+ _validate_DataType(variantDataType) {
1166
+ return validateDataType(this.addressSpace, this.dataType, variantDataType, this.nodeId, /* allow Nulls */ false);
1167
+ }
1168
+ _internal_set_value(value) {
1169
+ if (value.dataType !== node_opcua_variant_1.DataType.Null) {
1170
+ this.verifyVariantCompatibility(value);
1171
+ }
1172
+ this.$dataValue.value = value;
1173
+ }
1174
+ _internal_set_dataValue(dataValue, indexRange) {
1175
+ (0, node_opcua_assert_1.assert)(dataValue, "expecting a dataValue");
1176
+ (0, node_opcua_assert_1.assert)(dataValue instanceof node_opcua_data_value_1.DataValue, "expecting dataValue to be a DataValue");
1177
+ (0, node_opcua_assert_1.assert)(dataValue !== this.$dataValue, "expecting dataValue to be different from previous DataValue instance");
1178
+ const addressSpace = this.addressSpace;
1179
+ if (!addressSpace) {
1180
+ warningLog("UAVariable#_internal_set_dataValue : no addressSpace ! may be node has already been deleted ?");
1181
+ return;
1182
+ }
1183
+ if (dataValue.value.arrayType === node_opcua_variant_1.VariantArrayType.Matrix) {
1184
+ if (!dataValue.value.dimensions) {
1185
+ throw new Error("missing dimensions: a Matrix Variant needs a dimension");
1186
+ }
1187
+ const nbElements = dataValue.value.dimensions.reduce((acc, x) => acc * x, 1);
1188
+ if (dataValue.value.value.length !== 0 && dataValue.value.value.length !== nbElements) {
1189
+ throw new Error(`Internal Error: matrix dimension doesn't match the number of element in the array : ${dataValue.toString()} "\n expecting ${nbElements} elements but got ${dataValue.value.value.length}`);
1190
+ }
1191
+ }
1192
+ if (dataValue.value.dataType === node_opcua_variant_1.DataType.ExtensionObject) {
1193
+ if (!this.checkExtensionObjectIsCorrect(dataValue.value.value)) {
1194
+ warningLog(dataValue.toString());
1195
+ throw new Error("Invalid Extension Object on nodeId =" + this.nodeId.toString());
1196
+ }
1197
+ // ----------------------------------
1198
+ // if (this.$extensionObject) {
1199
+ // // we have an extension object already bound to this node
1200
+ // // the client is asking us to replace the object entierly by a new one
1201
+ // const ext = dataValue.value.value;
1202
+ // _setExtensionObject(this, ext);
1203
+ // return;
1204
+ // }
1205
+ }
1206
+ // // istanbul ignore next
1207
+ // if (this.dataType.namespace === 0) {
1208
+ // if (this.dataType.value === DataType.LocalizedText && dataValue.value.dataType !== DataType.LocalizedText) {
1209
+ // const message = "Invalid dataValue provided (expecting a LocalizedText) but got " + dataValue.toString();
1210
+ // errorLog(message);
1211
+ // // throw new Error(message);
1212
+ // }
1213
+ // }
1214
+ this.verifyVariantCompatibility(dataValue.value);
1215
+ const old_dataValue = this.$dataValue;
1216
+ this.$dataValue = dataValue;
1217
+ this.$dataValue.statusCode = this.$dataValue.statusCode || node_opcua_status_code_1.StatusCodes.Good;
1218
+ // repair missing timestamps
1219
+ if (!dataValue.serverTimestamp) {
1220
+ this.$dataValue.serverTimestamp = old_dataValue.serverTimestamp;
1221
+ this.$dataValue.serverPicoseconds = old_dataValue.serverPicoseconds;
1222
+ }
1223
+ if (!dataValue.sourceTimestamp) {
1224
+ this.$dataValue.sourceTimestamp = old_dataValue.sourceTimestamp;
1225
+ this.$dataValue.sourcePicoseconds = old_dataValue.sourcePicoseconds;
1226
+ }
1227
+ if (!(0, node_opcua_data_value_1.sameDataValue)(old_dataValue, dataValue)) {
1228
+ this.emit("value_changed", this.$dataValue, indexRange);
1229
+ }
1230
+ }
1231
+ _conditionRefresh(_cache) {
1232
+ apply_condition_refresh_1.apply_condition_refresh.call(this, _cache);
1233
+ }
1234
+ handle_semantic_changed() {
1235
+ this.semantic_version = this.semantic_version + 1;
1236
+ this.emit("semantic_changed");
1237
+ }
1238
+ _readDataType() {
1239
+ (0, node_opcua_assert_1.assert)(this.dataType instanceof node_opcua_nodeid_1.NodeId);
1240
+ const options = {
1241
+ statusCode: node_opcua_status_code_1.StatusCodes.Good,
1242
+ value: {
1243
+ dataType: node_opcua_variant_1.DataType.NodeId,
1244
+ value: this.dataType
1245
+ }
1246
+ };
1247
+ return new node_opcua_data_value_1.DataValue(options);
1248
+ }
1249
+ _readValueRank() {
1250
+ (0, node_opcua_assert_1.assert)(typeof this.valueRank === "number");
1251
+ const options = {
1252
+ statusCode: node_opcua_status_code_1.StatusCodes.Good,
1253
+ value: { dataType: node_opcua_variant_1.DataType.Int32, value: this.valueRank }
1254
+ };
1255
+ return new node_opcua_data_value_1.DataValue(options);
1256
+ }
1257
+ _readArrayDimensions() {
1258
+ (0, node_opcua_assert_1.assert)(Array.isArray(this.arrayDimensions) || this.arrayDimensions === null);
1259
+ (0, node_opcua_assert_1.assert)(!this.arrayDimensions || this.valueRank > 0, "arrayDimension must be null if valueRank <0");
1260
+ const options = {
1261
+ statusCode: node_opcua_status_code_1.StatusCodes.Good,
1262
+ value: { dataType: node_opcua_variant_1.DataType.UInt32, arrayType: node_opcua_variant_1.VariantArrayType.Array, value: this.arrayDimensions }
1263
+ };
1264
+ return new node_opcua_data_value_1.DataValue(options);
1265
+ }
1266
+ _readAccessLevel(context) {
1267
+ (0, node_opcua_assert_1.assert)(context instanceof session_context_1.SessionContext);
1268
+ const options = {
1269
+ statusCode: node_opcua_status_code_1.StatusCodes.Good,
1270
+ value: { dataType: node_opcua_variant_1.DataType.Byte, value: (0, node_opcua_data_model_1.convertAccessLevelFlagToByte)(this.accessLevel) }
1271
+ };
1272
+ return new node_opcua_data_value_1.DataValue(options);
1273
+ }
1274
+ _readAccessLevelEx(context) {
1275
+ (0, node_opcua_assert_1.assert)(context instanceof session_context_1.SessionContext);
1276
+ const options = {
1277
+ statusCode: node_opcua_status_code_1.StatusCodes.Good,
1278
+ // Extra flags are not supported yet. to do:
1279
+ value: { dataType: node_opcua_variant_1.DataType.UInt32, value: (0, node_opcua_data_model_1.convertAccessLevelFlagToByte)(this.accessLevel) }
1280
+ };
1281
+ return new node_opcua_data_value_1.DataValue(options);
1282
+ }
1283
+ _readUserAccessLevel(context) {
1284
+ (0, node_opcua_assert_1.assert)(context instanceof session_context_1.SessionContext);
1285
+ const effectiveUserAccessLevel = _calculateEffectiveUserAccessLevelFromPermission(this, context, this.userAccessLevel);
1286
+ const options = {
1287
+ value: {
1288
+ dataType: node_opcua_variant_1.DataType.Byte,
1289
+ statusCode: node_opcua_status_code_1.StatusCodes.Good,
1290
+ value: (0, node_opcua_data_model_1.convertAccessLevelFlagToByte)(effectiveUserAccessLevel)
1291
+ }
1292
+ };
1293
+ return new node_opcua_data_value_1.DataValue(options);
1294
+ }
1295
+ _readMinimumSamplingInterval() {
1296
+ // expect a Duration => Double
1297
+ const options = {};
1298
+ if (this.minimumSamplingInterval === undefined) {
1299
+ options.statusCode = node_opcua_status_code_1.StatusCodes.BadAttributeIdInvalid;
1300
+ }
1301
+ else {
1302
+ options.value = { dataType: node_opcua_variant_1.DataType.Double, value: this.minimumSamplingInterval };
1303
+ options.statusCode = node_opcua_status_code_1.StatusCodes.Good;
1304
+ }
1305
+ return new node_opcua_data_value_1.DataValue(options);
1306
+ }
1307
+ _readHistorizing() {
1308
+ (0, node_opcua_assert_1.assert)(typeof this.historizing === "boolean");
1309
+ const options = {
1310
+ statusCode: node_opcua_status_code_1.StatusCodes.Good,
1311
+ value: { dataType: node_opcua_variant_1.DataType.Boolean, value: !!this.historizing }
1312
+ };
1313
+ return new node_opcua_data_value_1.DataValue(options);
1314
+ }
1315
+ }
1316
+ exports.UAVariableImpl = UAVariableImpl;
1317
+ // tslint:disable:no-var-requires
1318
+ const thenify = require("thenify");
1319
+ UAVariableImpl.prototype.asyncRefresh = thenify.withCallback(UAVariableImpl.prototype.asyncRefresh);
1320
+ UAVariableImpl.prototype.writeValue = thenify.withCallback(UAVariableImpl.prototype.writeValue);
1321
+ UAVariableImpl.prototype.writeAttribute = thenify.withCallback(UAVariableImpl.prototype.writeAttribute);
1322
+ UAVariableImpl.prototype.historyRead = thenify.withCallback(UAVariableImpl.prototype.historyRead);
1323
+ UAVariableImpl.prototype.readValueAsync = thenify.withCallback(UAVariableImpl.prototype.readValueAsync);
1324
+ function check_valid_array(dataType, array) {
1325
+ if (Array.isArray(array)) {
1326
+ return true;
1327
+ }
1328
+ switch (dataType) {
1329
+ case node_opcua_variant_1.DataType.Double:
1330
+ return array instanceof Float64Array;
1331
+ case node_opcua_variant_1.DataType.Float:
1332
+ return array instanceof Float32Array;
1333
+ case node_opcua_variant_1.DataType.Int32:
1334
+ return array instanceof Int32Array;
1335
+ case node_opcua_variant_1.DataType.Int16:
1336
+ return array instanceof Int16Array;
1337
+ case node_opcua_variant_1.DataType.SByte:
1338
+ return array instanceof Int8Array;
1339
+ case node_opcua_variant_1.DataType.UInt32:
1340
+ return array instanceof Uint32Array;
1341
+ case node_opcua_variant_1.DataType.UInt16:
1342
+ return array instanceof Uint16Array;
1343
+ case node_opcua_variant_1.DataType.Byte:
1344
+ return array instanceof Uint8Array || array instanceof Buffer;
1345
+ }
1346
+ return false;
1347
+ }
1348
+ function _apply_default_timestamps(dataValue) {
1349
+ const now = (0, node_opcua_date_time_1.getCurrentClock)();
1350
+ (0, node_opcua_assert_1.assert)(dataValue instanceof node_opcua_data_value_1.DataValue);
1351
+ if (!dataValue.sourceTimestamp) {
1352
+ dataValue.sourceTimestamp = now.timestamp;
1353
+ dataValue.sourcePicoseconds = now.picoseconds;
1354
+ }
1355
+ if (!dataValue.serverTimestamp) {
1356
+ dataValue.serverTimestamp = now.timestamp;
1357
+ dataValue.serverPicoseconds = now.picoseconds;
1358
+ }
1359
+ }
1360
+ function unsetFlag(flags, mask) {
1361
+ return flags & ~mask;
1362
+ }
1363
+ function setFlag(flags, mask) {
1364
+ return flags | mask;
1365
+ }
1366
+ function _calculateEffectiveUserAccessLevelFromPermission(node, context, userAccessLevel) {
1367
+ function __adjustFlag(permissionType, access, userAccessLevel1) {
1368
+ if ((node.accessLevel & access) === 0 || (userAccessLevel1 & access) === 0) {
1369
+ userAccessLevel1 = unsetFlag(userAccessLevel1, access);
1370
+ }
1371
+ else {
1372
+ if (!context.checkPermission(node, permissionType)) {
1373
+ userAccessLevel1 = unsetFlag(userAccessLevel1, access);
1374
+ }
1375
+ }
1376
+ return userAccessLevel1;
1377
+ }
1378
+ userAccessLevel = node.userAccessLevel === undefined ? node.accessLevel : node.userAccessLevel & node.accessLevel;
1379
+ if (context.checkPermission) {
1380
+ (0, node_opcua_assert_1.assert)(context.checkPermission instanceof Function);
1381
+ userAccessLevel = __adjustFlag(node_opcua_types_1.PermissionType.Read, node_opcua_data_model_1.AccessLevelFlag.CurrentRead, userAccessLevel);
1382
+ userAccessLevel = __adjustFlag(node_opcua_types_1.PermissionType.Write, node_opcua_data_model_1.AccessLevelFlag.CurrentWrite, userAccessLevel);
1383
+ userAccessLevel = __adjustFlag(node_opcua_types_1.PermissionType.Write, node_opcua_data_model_1.AccessLevelFlag.StatusWrite, userAccessLevel);
1384
+ userAccessLevel = __adjustFlag(node_opcua_types_1.PermissionType.Write, node_opcua_data_model_1.AccessLevelFlag.TimestampWrite, userAccessLevel);
1385
+ userAccessLevel = __adjustFlag(node_opcua_types_1.PermissionType.ReadHistory, node_opcua_data_model_1.AccessLevelFlag.HistoryRead, userAccessLevel);
1386
+ userAccessLevel = __adjustFlag(node_opcua_types_1.PermissionType.DeleteHistory, node_opcua_data_model_1.AccessLevelFlag.HistoryWrite, userAccessLevel);
1387
+ return userAccessLevel;
1388
+ }
1389
+ else {
1390
+ return userAccessLevel;
1391
+ }
1392
+ }
1393
+ function adjustVariant2(variant) {
1394
+ // convert Variant( Scalar|ByteString) => Variant(Array|ByteArray)
1395
+ const addressSpace = this.addressSpace;
1396
+ const basicType = this.getBasicDataType();
1397
+ variant = (0, node_opcua_variant_1.adjustVariant)(variant, this.valueRank, basicType);
1398
+ return variant;
1399
+ }
1400
+ function _not_writable_timestamped_set_func(dataValue, callback) {
1401
+ (0, node_opcua_assert_1.assert)(dataValue instanceof node_opcua_data_value_1.DataValue);
1402
+ callback(null, node_opcua_status_code_1.StatusCodes.BadNotWritable, null);
1403
+ }
1404
+ function _default_writable_timestamped_set_func(dataValue, callback) {
1405
+ (0, node_opcua_assert_1.assert)(dataValue instanceof node_opcua_data_value_1.DataValue);
1406
+ callback(null, node_opcua_status_code_1.StatusCodes.Good, dataValue);
1407
+ }
1408
+ function turn_sync_to_async(f, numberOfArgs) {
1409
+ if (f.length <= numberOfArgs) {
1410
+ return function (data, callback) {
1411
+ const r = f.call(this, data);
1412
+ setImmediate(() => {
1413
+ return callback(null, r);
1414
+ });
1415
+ };
1416
+ }
1417
+ else {
1418
+ (0, node_opcua_assert_1.assert)(f.length === numberOfArgs + 1);
1419
+ return f;
1420
+ }
1421
+ }
1422
+ const _default_minimumSamplingInterval = 1000;
1423
+ function coerceDataValue(dataValue) {
1424
+ if (dataValue instanceof node_opcua_data_value_1.DataValue) {
1425
+ return dataValue;
1426
+ }
1427
+ return new node_opcua_data_value_1.DataValue(dataValue);
1428
+ }
1429
+ // variation #3 :
1430
+ function _Variable_bind_with_async_refresh(options) {
1431
+ /* jshint validthis: true */
1432
+ (0, node_opcua_assert_1.assert)(this instanceof UAVariableImpl);
1433
+ (0, node_opcua_assert_1.assert)(typeof options.refreshFunc === "function");
1434
+ (0, node_opcua_assert_1.assert)(!options.get, "a getter shall not be specified when refreshFunc is set");
1435
+ (0, node_opcua_assert_1.assert)(!options.timestamped_get, "a getter shall not be specified when refreshFunc is set");
1436
+ (0, node_opcua_assert_1.assert)(!this.refreshFunc);
1437
+ this.refreshFunc = options.refreshFunc;
1438
+ // assert(this.readValue().statusCode === StatusCodes.BadNodeIdUnknown);
1439
+ this.$dataValue.statusCode = node_opcua_status_code_1.StatusCodes.UncertainInitialValue;
1440
+ // TO DO : REVISIT THIS ASSUMPTION
1441
+ if (false && this.minimumSamplingInterval === 0) {
1442
+ // when a getter /timestamped_getter or async_getter is provided
1443
+ // samplingInterval cannot be 0, as the item value must be scanned to be updated.
1444
+ this.minimumSamplingInterval = _default_minimumSamplingInterval; // MonitoredItem.minimumSamplingInterval;
1445
+ debugLog("adapting minimumSamplingInterval on " + this.browseName.toString() + " to " + this.minimumSamplingInterval);
1446
+ }
1447
+ }
1448
+ // variation 2
1449
+ function _Variable_bind_with_timestamped_get(options) {
1450
+ /* jshint validthis: true */
1451
+ (0, node_opcua_assert_1.assert)(this instanceof UAVariableImpl);
1452
+ (0, node_opcua_assert_1.assert)(typeof options.timestamped_get === "function");
1453
+ (0, node_opcua_assert_1.assert)(!options.get, "should not specify 'get' when 'timestamped_get' exists ");
1454
+ (0, node_opcua_assert_1.assert)(!this._timestamped_get_func);
1455
+ const async_refresh_func = (callback) => {
1456
+ Promise.resolve(this._timestamped_get_func.call(this))
1457
+ .then((dataValue) => callback(null, dataValue))
1458
+ .catch((err) => {
1459
+ errorLog("asyncRefresh error: Variable is ", this.nodeId.toString(), this.browseName.toString());
1460
+ callback(err);
1461
+ });
1462
+ };
1463
+ const pThis = this;
1464
+ if (options.timestamped_get.length === 0) {
1465
+ const timestamped_get = options.timestamped_get;
1466
+ // sync version | Promise version
1467
+ this._timestamped_get_func = timestamped_get;
1468
+ const dataValue_verify = timestamped_get.call(pThis);
1469
+ // dataValue_verify should be a DataValue or a Promise
1470
+ /* istanbul ignore next */
1471
+ if (!(dataValue_verify instanceof node_opcua_data_value_1.DataValue) && typeof dataValue_verify.then !== "function") {
1472
+ errorLog(chalk.red(" Bind variable error: "), " the timestamped_get function must return a DataValue or a Promise<DataValue>" +
1473
+ "\n value_check.constructor.name ", dataValue_verify ? dataValue_verify.constructor.name : "null");
1474
+ throw new Error(" Bind variable error: " + " the timestamped_get function must return a DataValue");
1475
+ }
1476
+ _Variable_bind_with_async_refresh.call(this, { refreshFunc: async_refresh_func });
1477
+ }
1478
+ else if (options.timestamped_get.length === 1) {
1479
+ _Variable_bind_with_async_refresh.call(this, { refreshFunc: options.timestamped_get });
1480
+ }
1481
+ else {
1482
+ errorLog("timestamped_get has a invalid number of argument , should be 0 or 1 ");
1483
+ throw new Error("timestamped_get has a invalid number of argument , should be 0 or 1 ");
1484
+ }
1485
+ }
1486
+ // variation 1
1487
+ function _Variable_bind_with_simple_get(options) {
1488
+ /* jshint validthis: true */
1489
+ (0, node_opcua_assert_1.assert)(this instanceof UAVariableImpl);
1490
+ (0, node_opcua_assert_1.assert)(typeof options.get === "function", "should specify get function");
1491
+ (0, node_opcua_assert_1.assert)(options.get.length === 0, "get function should not have arguments");
1492
+ (0, node_opcua_assert_1.assert)(!options.timestamped_get, "should not specify a timestamped_get function when get is specified");
1493
+ (0, node_opcua_assert_1.assert)(!this._timestamped_get_func);
1494
+ (0, node_opcua_assert_1.assert)(!this._get_func);
1495
+ this._get_func = options.get;
1496
+ const timestamped_get_func_from__Variable_bind_with_simple_get = () => {
1497
+ const value = this._get_func();
1498
+ /* istanbul ignore next */
1499
+ if (!is_Variant_or_StatusCode(value)) {
1500
+ errorLog(chalk.red(" Bind variable error: "), " : the getter must return a Variant or a StatusCode" + "\nvalue_check.constructor.name ", value ? value.constructor.name : "null");
1501
+ throw new Error(" bindVariable : the value getter function returns a invalid result ( expecting a Variant or a StatusCode !!!");
1502
+ }
1503
+ if (is_StatusCode(value)) {
1504
+ return new node_opcua_data_value_1.DataValue({ statusCode: value });
1505
+ }
1506
+ else {
1507
+ if (!this.$dataValue || !isGoodish(this.$dataValue.statusCode) || !(0, node_opcua_variant_1.sameVariant)(this.$dataValue.value, value)) {
1508
+ this.setValueFromSource(value, node_opcua_status_code_1.StatusCodes.Good);
1509
+ }
1510
+ return this.$dataValue;
1511
+ }
1512
+ };
1513
+ _Variable_bind_with_timestamped_get.call(this, {
1514
+ get: undefined,
1515
+ timestamped_get: timestamped_get_func_from__Variable_bind_with_simple_get
1516
+ });
1517
+ }
1518
+ function _Variable_bind_with_simple_set(options) {
1519
+ (0, node_opcua_assert_1.assert)(this instanceof UAVariableImpl);
1520
+ (0, node_opcua_assert_1.assert)(typeof options.set === "function", "should specify set function");
1521
+ (0, node_opcua_assert_1.assert)(!options.timestamped_set, "should not specify a timestamped_set function");
1522
+ (0, node_opcua_assert_1.assert)(!this._timestamped_set_func);
1523
+ (0, node_opcua_assert_1.assert)(!this._set_func);
1524
+ this._set_func = turn_sync_to_async(options.set, 1);
1525
+ (0, node_opcua_assert_1.assert)(this._set_func.length === 2, " set function must have 2 arguments ( variant, callback)");
1526
+ this._timestamped_set_func = (timestamped_value, callback) => {
1527
+ (0, node_opcua_assert_1.assert)(timestamped_value instanceof node_opcua_data_value_1.DataValue);
1528
+ this._set_func(timestamped_value.value, (err, statusCode) => {
1529
+ // istanbul ignore next
1530
+ if (!err && !statusCode) {
1531
+ errorLog(chalk.red("UAVariable Binding Error _set_func must return a StatusCode, check the bindVariable parameters"));
1532
+ errorLog(chalk.yellow("StatusCode.Good is assumed"));
1533
+ return callback(err, node_opcua_status_code_1.StatusCodes.Good, timestamped_value);
1534
+ }
1535
+ callback(err, statusCode, timestamped_value);
1536
+ });
1537
+ };
1538
+ }
1539
+ function _Variable_bind_with_timestamped_set(options) {
1540
+ (0, node_opcua_assert_1.assert)(typeof options.timestamped_set === "function");
1541
+ (0, node_opcua_assert_1.assert)(options.timestamped_set.length === 2, "timestamped_set must have 2 parameters timestamped_set: function(dataValue,callback){}");
1542
+ (0, node_opcua_assert_1.assert)(!options.set, "should not specify set when timestamped_set_func exists ");
1543
+ this._timestamped_set_func = (0, multiform_func_1.convertToCallbackFunction1)(options.timestamped_set);
1544
+ }
1545
+ function bind_setter(options) {
1546
+ if (typeof options.set === "function") {
1547
+ // variation 1
1548
+ _Variable_bind_with_simple_set.call(this, options);
1549
+ }
1550
+ else if (typeof options.timestamped_set === "function") {
1551
+ // variation 2
1552
+ (0, node_opcua_assert_1.assert)(typeof options.timestamped_get === "function", "timestamped_set must be used with timestamped_get ");
1553
+ _Variable_bind_with_timestamped_set.call(this, {
1554
+ set: undefined,
1555
+ timestamped_set: options.timestamped_set
1556
+ });
1557
+ }
1558
+ else if (typeof options.timestamped_get === "function") {
1559
+ // timestamped_get is specified but timestamped_set is not
1560
+ // => Value is read-only
1561
+ _Variable_bind_with_timestamped_set.call(this, {
1562
+ set: undefined,
1563
+ timestamped_set: _not_writable_timestamped_set_func
1564
+ });
1565
+ }
1566
+ else {
1567
+ _Variable_bind_with_timestamped_set.call(this, {
1568
+ set: undefined,
1569
+ timestamped_set: _default_writable_timestamped_set_func
1570
+ });
1571
+ }
1572
+ }
1573
+ function bind_getter(options) {
1574
+ if (typeof options.get === "function") {
1575
+ // variation 1
1576
+ _Variable_bind_with_simple_get.call(this, options);
1577
+ }
1578
+ else if (typeof options.timestamped_get === "function") {
1579
+ // variation 2
1580
+ _Variable_bind_with_timestamped_get.call(this, {
1581
+ get: undefined,
1582
+ timestamped_get: options.timestamped_get
1583
+ });
1584
+ }
1585
+ else if (typeof options.refreshFunc === "function") {
1586
+ // variation 3
1587
+ _Variable_bind_with_async_refresh.call(this, options);
1588
+ }
1589
+ else {
1590
+ (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(options, "set"), "getter is missing : a getter must be provided if a setter is provided");
1591
+ // xx bind_variant.call(this,options);
1592
+ if (options.dataType !== undefined) {
1593
+ // if (options.dataType !== DataType.ExtensionObject) {
1594
+ this.setValueFromSource(options);
1595
+ // }
1596
+ }
1597
+ }
1598
+ }
1599
+ class UAVariableImplT extends UAVariableImpl {
1600
+ }
1601
+ exports.UAVariableImplT = UAVariableImplT;
1602
+ // x TO DO
1603
+ // require("./data_access/ua_variable_data_access");
1604
+ // require("./historical_access/ua_variable_history");
1605
1605
  //# sourceMappingURL=ua_variable_impl.js.map