node-opcua-address-space 2.55.0 → 2.58.0

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