node-opcua-address-space 2.71.0 → 2.72.2

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