node-opcua-address-space 2.55.0 → 2.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (329) hide show
  1. package/LICENSE +20 -20
  2. package/dist/source/address_space_ts.js.map +1 -1
  3. package/dist/source/continuation_points/continuation_point_manager.d.ts +27 -16
  4. package/dist/source/continuation_points/continuation_point_manager.js +141 -48
  5. package/dist/source/continuation_points/continuation_point_manager.js.map +1 -1
  6. package/dist/source/helpers/adjust_browse_direction.js.map +1 -1
  7. package/dist/source/helpers/call_helpers.js.map +1 -1
  8. package/dist/source/helpers/check_event_clause.js.map +1 -1
  9. package/dist/source/helpers/coerce_enum_value.js.map +1 -1
  10. package/dist/source/helpers/ensure_secure_access.js +0 -13
  11. package/dist/source/helpers/ensure_secure_access.js.map +1 -1
  12. package/dist/source/helpers/resolve_opaque_on_address_space.js.map +1 -1
  13. package/dist/source/loader/load_nodeset2.js +29 -3
  14. package/dist/source/loader/load_nodeset2.js.map +1 -1
  15. package/dist/source/loader/namespace_post_step.js.map +1 -1
  16. package/dist/source/loader/register_node_promoter.js.map +1 -1
  17. package/dist/source/namespace_machine_state.d.ts +1 -1
  18. package/dist/source/pseudo_session.js +23 -24
  19. package/dist/source/pseudo_session.js.map +1 -1
  20. package/dist/source/session_context.js +2 -2
  21. package/dist/source/session_context.js.map +1 -1
  22. package/dist/source/set_namespace_meta_data.js.map +1 -1
  23. package/dist/src/address_space.d.ts +7 -8
  24. package/dist/src/address_space.js +2 -2
  25. package/dist/src/address_space.js.map +1 -1
  26. package/dist/src/address_space_private.d.ts +4 -5
  27. package/dist/src/alarms_and_conditions/check_where_clause.js +1 -1
  28. package/dist/src/alarms_and_conditions/check_where_clause.js.map +1 -1
  29. package/dist/src/alarms_and_conditions/condition.js.map +1 -1
  30. package/dist/src/alarms_and_conditions/extract_event_fields.js.map +1 -1
  31. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js +2 -1
  32. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js.map +1 -1
  33. package/dist/src/alarms_and_conditions/ua_base_event_impl.js.map +1 -1
  34. package/dist/src/alarms_and_conditions/ua_condition_impl.js.map +1 -1
  35. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.js.map +1 -1
  36. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.js.map +1 -1
  37. package/dist/src/alarms_and_conditions/ua_limit_alarm_impl.js.map +1 -1
  38. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.js.map +1 -1
  39. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js.map +1 -1
  40. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.js.map +1 -1
  41. package/dist/src/base_node_impl.js.map +1 -1
  42. package/dist/src/data_access/add_dataItem_stuff.js.map +1 -1
  43. package/dist/src/data_access/check_variant_compatibility_ua_analog_item.js.map +1 -1
  44. package/dist/src/data_access/ua_multistate_discrete_impl.js.map +1 -1
  45. package/dist/src/event_data.js.map +1 -1
  46. package/dist/src/extension_object_array_node.js.map +1 -1
  47. package/dist/src/historical_access/address_space_historical_data_node.js +28 -59
  48. package/dist/src/historical_access/address_space_historical_data_node.js.map +1 -1
  49. package/dist/src/namespace_impl.d.ts +2 -2
  50. package/dist/src/namespace_impl.js +6 -6
  51. package/dist/src/namespace_impl.js.map +1 -1
  52. package/dist/src/nodeid_manager.js +1 -4
  53. package/dist/src/nodeid_manager.js.map +1 -1
  54. package/dist/src/nodeset_tools/nodeset_to_xml.js +1 -1
  55. package/dist/src/nodeset_tools/nodeset_to_xml.js.map +1 -1
  56. package/dist/src/nodeset_tools/typedictionary_to_xml.d.ts +1 -1
  57. package/dist/src/nodeset_tools/typedictionary_to_xml.js +3 -2
  58. package/dist/src/nodeset_tools/typedictionary_to_xml.js.map +1 -1
  59. package/dist/src/reference_impl.js +3 -1
  60. package/dist/src/reference_impl.js.map +1 -1
  61. package/dist/src/state_machine/finite_state_machine.js.map +1 -1
  62. package/dist/src/state_machine/ua_shelving_state_machine_ex.js.map +1 -1
  63. package/dist/src/state_machine/ua_two_state_variable.js.map +1 -1
  64. package/dist/src/tool_isSupertypeOf.js.map +1 -1
  65. package/dist/src/ua_method_impl.d.ts +3 -2
  66. package/dist/src/ua_method_impl.js +5 -0
  67. package/dist/src/ua_method_impl.js.map +1 -1
  68. package/dist/src/ua_object_impl.d.ts +10 -6
  69. package/dist/src/ua_object_impl.js +1 -1
  70. package/dist/src/ua_object_impl.js.map +1 -1
  71. package/dist/src/ua_object_type_impl.js.map +1 -1
  72. package/dist/src/ua_reference_type_impl.js +3 -1
  73. package/dist/src/ua_reference_type_impl.js.map +1 -1
  74. package/dist/src/ua_variable_impl.d.ts +8 -7
  75. package/dist/src/ua_variable_impl.js +6 -10
  76. package/dist/src/ua_variable_impl.js.map +1 -1
  77. package/dist/src/ua_variable_type_impl.js.map +1 -1
  78. package/dist/src/ua_view_impl.js.map +1 -1
  79. package/distHelpers/add_event_generator_object.js.map +1 -1
  80. package/distHelpers/alarms_and_conditions_demo.js.map +1 -1
  81. package/distHelpers/boiler_system.d.ts +1 -1
  82. package/distHelpers/boiler_system.js +1 -2
  83. package/distHelpers/boiler_system.js.map +1 -1
  84. package/distHelpers/create_minimalist_address_space_nodeset.js +1 -0
  85. package/distHelpers/create_minimalist_address_space_nodeset.js.map +1 -1
  86. package/distHelpers/date_utils.d.ts +3 -0
  87. package/distHelpers/date_utils.js +10 -0
  88. package/distHelpers/date_utils.js.map +1 -0
  89. package/distHelpers/get_mini_address_space.js.map +1 -1
  90. package/distHelpers/index.d.ts +2 -0
  91. package/distHelpers/index.js +2 -0
  92. package/distHelpers/index.js.map +1 -1
  93. package/distHelpers/mock_session.d.ts +14 -0
  94. package/distHelpers/mock_session.js +26 -0
  95. package/distHelpers/mock_session.js.map +1 -0
  96. package/generate.js +1 -1
  97. package/nodeJS.d.ts +1 -1
  98. package/package.json +32 -32
  99. package/source/address_space_ts.ts +0 -3
  100. package/source/continuation_points/continuation_point_manager.ts +178 -64
  101. package/source/helpers/adjust_browse_direction.ts +3 -3
  102. package/source/helpers/argument_list.ts +1 -1
  103. package/source/helpers/call_helpers.ts +0 -1
  104. package/source/helpers/check_event_clause.ts +2 -9
  105. package/source/helpers/coerce_enum_value.ts +3 -3
  106. package/source/helpers/ensure_secure_access.ts +1 -13
  107. package/source/helpers/resolve_opaque_on_address_space.ts +4 -1
  108. package/source/interfaces/alarms_and_conditions/condition_info_i.ts +13 -13
  109. package/source/interfaces/data_access/ua_multistate_value_discrete_ex.ts +0 -1
  110. package/source/interfaces/data_access/ua_y_array_item_ex.ts +4 -2
  111. package/source/interfaces/state_machine/ua_exclusive_limit_state_machine_type_ex.ts +5 -1
  112. package/source/interfaces/state_machine/ua_state_machine_type.ts +2 -2
  113. package/source/loader/load_nodeset2.ts +39 -3
  114. package/source/loader/namespace_post_step.ts +1 -2
  115. package/source/loader/register_node_promoter.ts +4 -1
  116. package/source/namespace.ts +4 -6
  117. package/source/namespace_machine_state.ts +1 -2
  118. package/source/pseudo_session.ts +37 -29
  119. package/source/session_context.ts +2 -9
  120. package/source/set_namespace_meta_data.ts +21 -15
  121. package/source/xml_writer.ts +0 -1
  122. package/source_nodejs/index.ts +1 -1
  123. package/src/address_space.ts +17 -16
  124. package/src/address_space_private.ts +7 -12
  125. package/src/alarms_and_conditions/check_where_clause.ts +21 -22
  126. package/src/alarms_and_conditions/condition.ts +0 -1
  127. package/src/alarms_and_conditions/extract_event_fields.ts +0 -1
  128. package/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.ts +14 -10
  129. package/src/alarms_and_conditions/ua_base_event_impl.ts +11 -15
  130. package/src/alarms_and_conditions/ua_condition_impl.ts +35 -40
  131. package/src/alarms_and_conditions/ua_discrete_alarm_impl.ts +39 -33
  132. package/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.ts +2 -2
  133. package/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.ts +4 -5
  134. package/src/alarms_and_conditions/ua_limit_alarm_impl.ts +16 -16
  135. package/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.ts +8 -8
  136. package/src/alarms_and_conditions/ua_off_normal_alarm_impl.ts +9 -10
  137. package/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.ts +2 -4
  138. package/src/apply_condition_refresh.ts +2 -2
  139. package/src/base_node_impl.ts +2 -2
  140. package/src/data_access/add_dataItem_stuff.ts +4 -4
  141. package/src/data_access/check_variant_compatibility_ua_analog_item.ts +12 -15
  142. package/src/data_access/ua_multistate_discrete_impl.ts +6 -3
  143. package/src/data_access/ua_multistate_value_discrete.ts +1 -1
  144. package/src/event_data.ts +1 -7
  145. package/src/extension_object_array_node.ts +4 -10
  146. package/src/historical_access/address_space_historical_data_node.ts +39 -63
  147. package/src/namespace_impl.ts +5 -5
  148. package/src/namespace_private.ts +1 -1
  149. package/src/nodeid_manager.ts +2 -5
  150. package/src/nodeset_tools/nodeset_to_xml.ts +5 -5
  151. package/src/nodeset_tools/typedictionary_to_xml.ts +7 -5
  152. package/src/reference_impl.ts +4 -2
  153. package/src/state_machine/finite_state_machine.ts +426 -428
  154. package/src/state_machine/ua_shelving_state_machine_ex.ts +19 -9
  155. package/src/state_machine/ua_two_state_variable.ts +5 -7
  156. package/src/tool_isSupertypeOf.ts +2 -6
  157. package/src/ua_condition_type.ts +0 -1
  158. package/src/ua_method_impl.ts +25 -9
  159. package/src/ua_object_impl.ts +13 -8
  160. package/src/ua_object_type_impl.ts +7 -4
  161. package/src/ua_reference_type_impl.ts +6 -12
  162. package/src/ua_variable_impl.ts +11 -15
  163. package/src/ua_variable_type_impl.ts +2 -2
  164. package/src/ua_view_impl.ts +3 -6
  165. package/testHelpers.d.ts +1 -1
  166. package/test_helpers/add_event_generator_object.ts +6 -5
  167. package/test_helpers/alarms_and_conditions_demo.ts +9 -8
  168. package/test_helpers/assertHasMatchingReference.ts +43 -43
  169. package/test_helpers/boiler_system.ts +610 -618
  170. package/test_helpers/create_minimalist_address_space_nodeset.ts +13 -13
  171. package/test_helpers/date_utils.ts +5 -0
  172. package/test_helpers/dump_statemachine.ts +2 -2
  173. package/test_helpers/get_address_space_fixture.ts +30 -30
  174. package/test_helpers/get_mini_address_space.ts +42 -42
  175. package/test_helpers/index.ts +13 -11
  176. package/test_helpers/mock_session.ts +34 -0
  177. package/test_helpers/test_fixtures/dataType_in_separateNamespace.xml +150 -150
  178. package/test_helpers/test_fixtures/dataType_in_separateNamespace_basic.xml +57 -57
  179. package/test_helpers/test_fixtures/dataType_in_separateNamespace_mix.xml +135 -135
  180. package/test_helpers/test_fixtures/dataType_withEnumeration.xml +82 -82
  181. package/test_helpers/test_fixtures/dataType_with_isOptionSet.xml +194 -194
  182. package/test_helpers/test_fixtures/dataType_with_union.xml +1 -1
  183. package/test_helpers/test_fixtures/fixture_empty_nodeset2.xml +106 -106
  184. package/test_helpers/test_fixtures/fixture_simple_statemachine_nodeset2.xml +1303 -1303
  185. package/test_helpers/test_fixtures/fixuture_nodeset_objects_with_some_methods.xml +362 -362
  186. package/test_helpers/test_fixtures/issue_846.xml +3172 -3172
  187. package/test_helpers/test_fixtures/issue_899_variable_with_nodeid_value.xml +32 -32
  188. package/test_helpers/test_fixtures/mini.nodeset.withVariousVariables.xml +194 -194
  189. package/test_helpers/test_fixtures/minimalist_nodeset_with_models.xml +8 -8
  190. package/test_helpers/test_fixtures/minimalist_nodeset_with_models_more_complex.xml +16 -16
  191. package/test_helpers/test_fixtures/nodeset_with_analog_items.xml +45 -45
  192. package/dist/source/interfaces/alarms_and_conditions/ua_condition_base_i.d.ts +0 -23
  193. package/dist/source/interfaces/alarms_and_conditions/ua_condition_base_i.js +0 -3
  194. package/dist/source/interfaces/alarms_and_conditions/ua_condition_base_i.js.map +0 -1
  195. package/dist/source/interfaces/data_access/ua_discrete_item.d.ts +0 -6
  196. package/dist/source/interfaces/data_access/ua_discrete_item.js +0 -3
  197. package/dist/source/interfaces/data_access/ua_discrete_item.js.map +0 -1
  198. package/dist/source/interfaces/data_access/ua_multistate_discrete.d.ts +0 -25
  199. package/dist/source/interfaces/data_access/ua_multistate_discrete.js +0 -3
  200. package/dist/source/interfaces/data_access/ua_multistate_discrete.js.map +0 -1
  201. package/dist/source/interfaces/data_access/ua_multistate_value_discrete.d.ts +0 -27
  202. package/dist/source/interfaces/data_access/ua_multistate_value_discrete.js +0 -3
  203. package/dist/source/interfaces/data_access/ua_multistate_value_discrete.js.map +0 -1
  204. package/dist/source/interfaces/data_access/ua_two_state_discrete.d.ts +0 -17
  205. package/dist/source/interfaces/data_access/ua_two_state_discrete.js +0 -3
  206. package/dist/source/interfaces/data_access/ua_two_state_discrete.js.map +0 -1
  207. package/dist/source/interfaces/data_access/ua_y_array_item.d.ts +0 -19
  208. package/dist/source/interfaces/data_access/ua_y_array_item.js +0 -3
  209. package/dist/source/interfaces/data_access/ua_y_array_item.js.map +0 -1
  210. package/dist/source/interfaces/state_machine/exclusive_limit_state_machine.d.ts +0 -11
  211. package/dist/source/interfaces/state_machine/exclusive_limit_state_machine.js +0 -3
  212. package/dist/source/interfaces/state_machine/exclusive_limit_state_machine.js.map +0 -1
  213. package/dist/source/interfaces/state_machine/finite_state_machine.d.ts +0 -70
  214. package/dist/source/interfaces/state_machine/finite_state_machine.js +0 -3
  215. package/dist/source/interfaces/state_machine/finite_state_machine.js.map +0 -1
  216. package/dist/source/interfaces/state_machine/program_finite_state_machine.d.ts +0 -74
  217. package/dist/source/interfaces/state_machine/program_finite_state_machine.js +0 -3
  218. package/dist/source/interfaces/state_machine/program_finite_state_machine.js.map +0 -1
  219. package/dist/source/interfaces/state_machine/state_machine.d.ts +0 -342
  220. package/dist/source/interfaces/state_machine/state_machine.js +0 -3
  221. package/dist/source/interfaces/state_machine/state_machine.js.map +0 -1
  222. package/dist/source/interfaces/state_machine/ua_finite_state_variable.d.ts +0 -18
  223. package/dist/source/interfaces/state_machine/ua_finite_state_variable.js +0 -3
  224. package/dist/source/interfaces/state_machine/ua_finite_state_variable.js.map +0 -1
  225. package/dist/source/interfaces/state_machine/ua_state_variable.d.ts +0 -29
  226. package/dist/source/interfaces/state_machine/ua_state_variable.js +0 -3
  227. package/dist/source/interfaces/state_machine/ua_state_variable.js.map +0 -1
  228. package/dist/source/interfaces/state_machine/ua_two_state_variable.d.ts +0 -26
  229. package/dist/source/interfaces/state_machine/ua_two_state_variable.js +0 -3
  230. package/dist/source/interfaces/state_machine/ua_two_state_variable.js.map +0 -1
  231. package/dist/source/interfaces/subscription_diagnostics_variable.d.ts +0 -41
  232. package/dist/source/interfaces/subscription_diagnostics_variable.js +0 -3
  233. package/dist/source/interfaces/subscription_diagnostics_variable.js.map +0 -1
  234. package/dist/src/alarms_and_conditions/base_event_type.d.ts +0 -26
  235. package/dist/src/alarms_and_conditions/base_event_type.js +0 -41
  236. package/dist/src/alarms_and_conditions/base_event_type.js.map +0 -1
  237. package/dist/src/alarms_and_conditions/shelving_state_machine.d.ts +0 -22
  238. package/dist/src/alarms_and_conditions/shelving_state_machine.js +0 -241
  239. package/dist/src/alarms_and_conditions/shelving_state_machine.js.map +0 -1
  240. package/dist/src/alarms_and_conditions/trip_alarm.d.ts +0 -16
  241. package/dist/src/alarms_and_conditions/trip_alarm.js +0 -21
  242. package/dist/src/alarms_and_conditions/trip_alarm.js.map +0 -1
  243. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_base.d.ts +0 -54
  244. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_base.js +0 -255
  245. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_base.js.map +0 -1
  246. package/dist/src/alarms_and_conditions/ua_alarm_condition_base.d.ts +0 -138
  247. package/dist/src/alarms_and_conditions/ua_alarm_condition_base.js +0 -460
  248. package/dist/src/alarms_and_conditions/ua_alarm_condition_base.js.map +0 -1
  249. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm.d.ts +0 -35
  250. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm.js +0 -32
  251. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm.js.map +0 -1
  252. package/dist/src/alarms_and_conditions/ua_condition_base.d.ts +0 -191
  253. package/dist/src/alarms_and_conditions/ua_condition_base.js +0 -1029
  254. package/dist/src/alarms_and_conditions/ua_condition_base.js.map +0 -1
  255. package/dist/src/alarms_and_conditions/ua_discrete_alarm.d.ts +0 -11
  256. package/dist/src/alarms_and_conditions/ua_discrete_alarm.js +0 -58
  257. package/dist/src/alarms_and_conditions/ua_discrete_alarm.js.map +0 -1
  258. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm.d.ts +0 -24
  259. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm.js +0 -59
  260. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm.js.map +0 -1
  261. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm.d.ts +0 -14
  262. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm.js +0 -17
  263. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm.js.map +0 -1
  264. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm.d.ts +0 -22
  265. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm.js +0 -87
  266. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm.js.map +0 -1
  267. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm.d.ts +0 -6
  268. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm.js +0 -11
  269. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm.js.map +0 -1
  270. package/dist/src/alarms_and_conditions/ua_limit_alarm.d.ts +0 -76
  271. package/dist/src/alarms_and_conditions/ua_limit_alarm.js +0 -237
  272. package/dist/src/alarms_and_conditions/ua_limit_alarm.js.map +0 -1
  273. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm.d.ts +0 -27
  274. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm.js +0 -62
  275. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm.js.map +0 -1
  276. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm.d.ts +0 -49
  277. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm.js +0 -176
  278. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm.js.map +0 -1
  279. package/dist/src/alarms_and_conditions/ua_off_normal_alarm.d.ts +0 -47
  280. package/dist/src/alarms_and_conditions/ua_off_normal_alarm.js +0 -151
  281. package/dist/src/alarms_and_conditions/ua_off_normal_alarm.js.map +0 -1
  282. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm.d.ts +0 -16
  283. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm.js +0 -18
  284. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm.js.map +0 -1
  285. package/dist/src/base_node.d.ts +0 -289
  286. package/dist/src/base_node.js +0 -1345
  287. package/dist/src/base_node.js.map +0 -1
  288. package/dist/src/data_access/ua_analog_item.d.ts +0 -13
  289. package/dist/src/data_access/ua_analog_item.js +0 -37
  290. package/dist/src/data_access/ua_analog_item.js.map +0 -1
  291. package/dist/src/data_access/ua_data_item.d.ts +0 -16
  292. package/dist/src/data_access/ua_data_item.js +0 -66
  293. package/dist/src/data_access/ua_data_item.js.map +0 -1
  294. package/dist/src/data_access/ua_multistate_discrete.d.ts +0 -24
  295. package/dist/src/data_access/ua_multistate_discrete.js +0 -132
  296. package/dist/src/data_access/ua_multistate_discrete.js.map +0 -1
  297. package/dist/src/namespace.d.ts +0 -472
  298. package/dist/src/namespace.js +0 -1751
  299. package/dist/src/namespace.js.map +0 -1
  300. package/dist/src/reference.d.ts +0 -43
  301. package/dist/src/reference.js +0 -138
  302. package/dist/src/reference.js.map +0 -1
  303. package/dist/src/session_context.d.ts +0 -4
  304. package/dist/src/session_context.js +0 -9
  305. package/dist/src/session_context.js.map +0 -1
  306. package/dist/src/ua_data_type.d.ts +0 -83
  307. package/dist/src/ua_data_type.js +0 -289
  308. package/dist/src/ua_data_type.js.map +0 -1
  309. package/dist/src/ua_method.d.ts +0 -41
  310. package/dist/src/ua_method.js +0 -202
  311. package/dist/src/ua_method.js.map +0 -1
  312. package/dist/src/ua_object.d.ts +0 -28
  313. package/dist/src/ua_object.js +0 -153
  314. package/dist/src/ua_object.js.map +0 -1
  315. package/dist/src/ua_object_type.d.ts +0 -49
  316. package/dist/src/ua_object_type.js +0 -123
  317. package/dist/src/ua_object_type.js.map +0 -1
  318. package/dist/src/ua_reference_type.d.ts +0 -42
  319. package/dist/src/ua_reference_type.js +0 -138
  320. package/dist/src/ua_reference_type.js.map +0 -1
  321. package/dist/src/ua_variable.d.ts +0 -339
  322. package/dist/src/ua_variable.js +0 -1706
  323. package/dist/src/ua_variable.js.map +0 -1
  324. package/dist/src/ua_variable_type.d.ts +0 -57
  325. package/dist/src/ua_variable_type.js +0 -530
  326. package/dist/src/ua_variable_type.js.map +0 -1
  327. package/dist/src/ua_view.d.ts +0 -16
  328. package/dist/src/ua_view.js +0 -42
  329. package/dist/src/ua_view.js.map +0 -1
@@ -1,428 +1,426 @@
1
- /**
2
- * @module node-opcua-address-space
3
- */
4
- import * as chalk from "chalk";
5
- import { UAState, UAStateVariable, UATransition, UATransition_Base, UATransitionVariable } from "node-opcua-nodeset-ua";
6
- import { assert } from "node-opcua-assert";
7
- import { ObjectTypeIds } from "node-opcua-constants";
8
- import { coerceLocalizedText, LocalizedText, NodeClass } from "node-opcua-data-model";
9
- import { AttributeIds } from "node-opcua-data-model";
10
- import { NodeId } from "node-opcua-nodeid";
11
- import { StatusCodes } from "node-opcua-status-code";
12
- import { DataType } from "node-opcua-variant";
13
- import { BaseNode, UAMethod, UAObject, UAObjectType, UAVariable } from "node-opcua-address-space-base";
14
- import { registerNodePromoter } from "../../source/loader/register_node_promoter";
15
-
16
- import { UAStateMachineEx, TransitionSelector } from "../../source/interfaces/state_machine/ua_state_machine_type";
17
- import { UAObjectImpl } from "../ua_object_impl";
18
- import { UATransitionEx } from "../../source/interfaces/state_machine/ua_transition_ex";
19
- import { BaseNodeImpl } from "../base_node_impl";
20
-
21
- const doDebug = false;
22
-
23
- export declare interface UATransitionImpl extends UATransition, UATransitionEx {
24
- }
25
- export class UATransitionImpl implements UATransition, UATransitionEx {}
26
-
27
-
28
- function getComponentFromTypeAndSubtype(typeDef: UAObjectType): UAObject[] {
29
- const components_parts: BaseNode[][] = [];
30
- components_parts.push(typeDef.getComponents());
31
- while (typeDef.subtypeOfObj) {
32
- typeDef = typeDef.subtypeOfObj;
33
- components_parts.push(typeDef.getComponents());
34
- }
35
- return Array.prototype.concat.apply([], components_parts).filter((x: BaseNode) => x.nodeClass === NodeClass.Object);
36
- }
37
-
38
- export interface UAStateMachineImpl {
39
- currentState: UAStateVariable<LocalizedText>;
40
- lastTransition?: UATransitionVariable<LocalizedText>;
41
-
42
- // Extra
43
- _currentStateNode: UAState | null;
44
- }
45
-
46
- const defaultPredicate = (transitions: UATransition[], fromState: UAState, toState: UAState) => {
47
- if (transitions.length === 0) {
48
- return null;
49
- }
50
- if (transitions.length === 1) {
51
- return transitions[0];
52
- }
53
- // tslint:disable-next-line: no-console
54
- console.log(" FromState = ", fromState.browseName.toString());
55
- // tslint:disable-next-line: no-console
56
- console.log(" ToState = ", toState.browseName.toString());
57
- for (const transition of transitions) {
58
- // tslint:disable-next-line: no-console
59
- console.log(" possible transition : ", transition.browseName.toString(), " ", transition.nodeId.toString());
60
- }
61
- // tslint:disable-next-line: no-console
62
- console.log(
63
- "warning: a duplicated FromState Reference to the same target has been found.\nPlease check your model or provide a predicate method to select which one to use"
64
- );
65
- // tslint:disable-next-line: no-console
66
- console.log("fromStateNode: ", fromState.toString());
67
- return transitions[0];
68
- };
69
-
70
- /*
71
- *
72
- * @class StateMachine
73
- * @constructor
74
- * @extends UAObject
75
- *
76
- *
77
- */
78
- export class UAStateMachineImpl extends UAObjectImpl implements UAStateMachineEx {
79
- public getStates(): UAState[] {
80
- const addressSpace = this.addressSpace;
81
-
82
- const initialStateType = addressSpace.findObjectType("InitialStateType");
83
- // istanbul ignore next
84
- if (!initialStateType) {
85
- throw new Error("cannot find InitialStateType");
86
- }
87
-
88
- const stateType = addressSpace.findObjectType("StateType");
89
- // istanbul ignore next
90
- if (!stateType) {
91
- throw new Error("cannot find StateType");
92
- }
93
-
94
- assert(initialStateType.isSupertypeOf(stateType));
95
-
96
- const typeDef = this.typeDefinitionObj;
97
-
98
- let comp = getComponentFromTypeAndSubtype(typeDef);
99
-
100
- comp = comp.filter((c) => {
101
- if (!c.typeDefinitionObj || c.typeDefinitionObj.nodeClass !== NodeClass.ObjectType) {
102
- return false;
103
- }
104
- return c.typeDefinitionObj.isSupertypeOf(stateType);
105
- });
106
-
107
- return comp as UAState[];
108
- }
109
-
110
- public get states(): UAState[] {
111
- return this.getStates();
112
- }
113
-
114
- /**
115
- * @method getStateByName
116
- * @param name the name of the state to get
117
- * @return the state with the given name
118
- */
119
- public getStateByName(name: string): UAState | null {
120
- let states = this.getStates();
121
- states = states.filter((s: any) => {
122
- return s.browseName.name === name;
123
- });
124
- assert(states.length <= 1);
125
- return states.length === 1 ? (states[0] as any as UAState) : null;
126
- }
127
-
128
- public getTransitions(): UATransitionEx[] {
129
- const addressSpace = this.addressSpace;
130
-
131
- const transitionType = addressSpace.findObjectType("TransitionType");
132
- // istanbul ignore next
133
- if (!transitionType) {
134
- throw new Error("cannot find TransitionType");
135
- }
136
- const typeDef = this.typeDefinitionObj;
137
-
138
- let comp = getComponentFromTypeAndSubtype(typeDef);
139
-
140
- comp = comp.filter((c) => {
141
- if (!c.typeDefinitionObj || c.typeDefinitionObj.nodeClass !== NodeClass.ObjectType) {
142
- return false;
143
- }
144
- return c.typeDefinitionObj.isSupertypeOf(transitionType);
145
- });
146
-
147
- return comp as UATransitionEx[];
148
- }
149
-
150
- public get transitions(): UATransitionEx[] {
151
- return this.getTransitions();
152
- }
153
-
154
- /**
155
- * return the node InitialStateType
156
- * @property initialState
157
- */
158
- get initialState(): UAState | null {
159
- const addressSpace = this.addressSpace;
160
-
161
- const initialStateType = addressSpace.findObjectType("InitialStateType");
162
- const typeDef = this.typeDefinitionObj;
163
-
164
- let comp = getComponentFromTypeAndSubtype(typeDef);
165
-
166
- comp = comp.filter((c: any) => c.typeDefinitionObj === initialStateType);
167
-
168
- // istanbul ignore next
169
- if (comp.length > 1) {
170
- throw new Error(" More than 1 initial state in stateMachine");
171
- }
172
- return comp.length === 0 ? null : comp[0] as UAState;
173
- }
174
-
175
- /**
176
- *
177
- * @param node
178
- * @private
179
- */
180
- public _coerceNode(node: UAState | BaseNode | null | string | NodeId): BaseNode | null {
181
- if (node === null) {
182
- return null;
183
- }
184
- const addressSpace = this.addressSpace;
185
- if (node instanceof BaseNodeImpl) {
186
- return node;
187
- } else if (node instanceof NodeId) {
188
- return addressSpace.findNode(node) as BaseNode;
189
- } else if (typeof node === "string") {
190
- return this.getStateByName(node) as any as BaseNode;
191
- }
192
- return null;
193
- }
194
-
195
- /**
196
- * @method isValidTransition
197
- * @param toStateNode
198
- * @return {boolean}
199
- */
200
- public isValidTransition(toStateNode: UAState | string, predicate?: TransitionSelector): boolean {
201
- // is it legal to go from state currentState to toStateNode;
202
- if (!this.currentStateNode) {
203
- return true;
204
- }
205
- const n = this.currentState.readValue();
206
-
207
- // to be executed there must be a transition from currentState to toState
208
- const transition = this.findTransitionNode(this.currentStateNode, toStateNode, predicate);
209
- if (!transition) {
210
- // istanbul ignore next
211
- if (doDebug) {
212
- // tslint:disable-next-line: no-console
213
- console.log(" No transition from ", this.currentStateNode.browseName.toString(), " to ", toStateNode.toString());
214
- }
215
- return false;
216
- }
217
- return true;
218
- }
219
-
220
- /**
221
- */
222
- public findTransitionNode(
223
- fromStateNode: NodeId | UAState | string | null,
224
- toStateNode: NodeId | UAState | string | null,
225
- predicate?: TransitionSelector
226
- ): UATransitionEx | null {
227
- const addressSpace = this.addressSpace;
228
-
229
- const _fromStateNode = this._coerceNode(fromStateNode) as UAObject;
230
- if (!_fromStateNode) {
231
- return null;
232
- }
233
-
234
- const _toStateNode = this._coerceNode(toStateNode) as UAObject;
235
- if (!_toStateNode) {
236
- return null;
237
- }
238
-
239
- if (_fromStateNode.nodeClass !== NodeClass.Object) {
240
- throw new Error("Internal Error");
241
- }
242
- if (_toStateNode && _toStateNode.nodeClass !== NodeClass.Object) {
243
- throw new Error("Internal Error");
244
- }
245
-
246
- const stateType = addressSpace.findObjectType("StateType");
247
- if (!stateType) {
248
- throw new Error("Cannot find StateType");
249
- }
250
- assert((_fromStateNode.typeDefinitionObj as any).isSupertypeOf(stateType));
251
- assert((_toStateNode.typeDefinitionObj as any).isSupertypeOf(stateType));
252
-
253
- let transitions = _fromStateNode.findReferencesAsObject("FromState", false) as UATransitionImpl[];
254
-
255
- transitions = transitions.filter((transition: any) => {
256
- assert(transition.toStateNode.nodeClass === NodeClass.Object);
257
- return transition.toStateNode === _toStateNode;
258
- });
259
- if (transitions.length === 0) {
260
- // cannot find a transition from fromState to toState
261
- return null;
262
- }
263
- // istanbul ignore next
264
- if (transitions.length > 1) {
265
- const selectedTransition = (predicate || defaultPredicate)(
266
- transitions,
267
- _fromStateNode as unknown as UAState,
268
- _toStateNode as unknown as UAState
269
- );
270
- return selectedTransition as UATransitionEx;
271
- }
272
- return transitions[0];
273
- }
274
-
275
- public get currentStateNode(): UAState | null {
276
- return this._currentStateNode;
277
- }
278
-
279
- /**
280
- * @property currentStateNode
281
- * @type BaseNode
282
- */
283
- public set currentStateNode(value: UAState | null) {
284
- this._currentStateNode = value;
285
- }
286
-
287
- /**
288
- */
289
- public getCurrentState(): string | null {
290
- // xx this.currentState.readValue().value.value.text
291
- // xx this.shelvingState.currentStateNode.browseName.toString()
292
- if (!this.currentStateNode) {
293
- return null;
294
- }
295
- return this.currentStateNode.browseName.toString();
296
- }
297
-
298
- /**
299
- * @method setState
300
- */
301
- public setState(toStateNode: string | UAState | null, predicate?: TransitionSelector): void {
302
- if (!toStateNode) {
303
- this.currentStateNode = null;
304
- this.currentState.setValueFromSource({ dataType: DataType.LocalizedText, value: null }, StatusCodes.BadStateNotActive);
305
- return;
306
- }
307
-
308
- if (typeof toStateNode === "string") {
309
- const state = this.getStateByName(toStateNode);
310
- // istanbul ignore next
311
- if (!state) {
312
- throw new Error("Cannot find state with name " + toStateNode);
313
- }
314
- assert(state.browseName.name!.toString() === toStateNode);
315
- toStateNode = state;
316
- }
317
- const fromStateNode = this.currentStateNode;
318
-
319
- toStateNode = this._coerceNode(toStateNode) as any as UAState;
320
- assert(toStateNode.nodeClass === NodeClass.Object);
321
-
322
- this.currentState.setValueFromSource(
323
- {
324
- dataType: DataType.LocalizedText,
325
- value: coerceLocalizedText(toStateNode.browseName.toString())
326
- },
327
- StatusCodes.Good
328
- );
329
-
330
- this.currentStateNode = toStateNode;
331
-
332
- const transitionNode = this.findTransitionNode(fromStateNode, toStateNode, predicate) as UATransitionImpl;
333
-
334
- if (transitionNode) {
335
- // xx console.log("transitionNode ",transitionNode.toString());
336
- // The inherited Property SourceNode shall be filled with the NodeId of the StateMachine instance where the
337
- // Transition occurs. If the Transition occurs in a SubStateMachine, then the NodeId of the SubStateMachine
338
- // has to be used. If the Transition occurs between a StateMachine and a SubStateMachine, then the NodeId of
339
- // the StateMachine has to be used, independent of the direction of the Transition.
340
- // Transition identifies the Transition that triggered the Event.
341
- // FromState identifies the State before the Transition.
342
- // ToState identifies the State after the Transition.
343
- this.raiseEvent("TransitionEventType", {
344
- // Base EventType
345
- // xx nodeId: this.nodeId,
346
- // TransitionEventType
347
- // TransitionVariableType
348
- transition: {
349
- dataType: "LocalizedText",
350
- value: (transitionNode as BaseNode).displayName[0]
351
- },
352
-
353
- "transition.id": transitionNode.transitionNumber.readValue().value,
354
-
355
- fromState: {
356
- dataType: "LocalizedText",
357
- value: fromStateNode ? fromStateNode.displayName[0] : ""
358
- }, // StateVariableType
359
-
360
- "fromState.id": fromStateNode
361
- ? fromStateNode.stateNumber.readValue().value
362
- : {
363
- dataType: "Null"
364
- },
365
-
366
- toState: {
367
- dataType: "LocalizedText",
368
- value: toStateNode.displayName[0]
369
- }, // StateVariableType
370
-
371
- "toState.id": toStateNode.stateNumber.readValue().value
372
- });
373
- } else {
374
- if (fromStateNode && fromStateNode !== toStateNode) {
375
- // istanbul ignore next
376
- if (doDebug) {
377
- const f = fromStateNode.browseName.toString();
378
- const t = toStateNode.browseName.toString();
379
- // tslint:disable-next-line:no-console
380
- console.log(chalk.red("Warning"), " cannot raise event : transition " + f + " to " + t + " is missing");
381
- }
382
- }
383
- }
384
-
385
- // also update executable flags on methods
386
- for (const method of this.getMethods()) {
387
- (method as any)._notifyAttributeChange(AttributeIds.Executable);
388
- }
389
- }
390
-
391
- /**
392
- * @internal
393
- * @private
394
- */
395
- public _post_initialize(): void {
396
- const addressSpace = this.addressSpace;
397
- const finiteStateMachineType = addressSpace.findObjectType("FiniteStateMachineType");
398
- if (!finiteStateMachineType) {
399
- throw new Error("cannot find FiniteStateMachineType");
400
- }
401
-
402
- // xx assert(this.typeDefinitionObj && !this.subtypeOfObj);
403
- // xx assert(!this.typeDefinitionObj || this.typeDefinitionObj.isSupertypeOf(finiteStateMachineType));
404
- // get current Status
405
-
406
- const d = this.currentState.readValue();
407
-
408
- if (d.statusCode !== StatusCodes.Good) {
409
- this.setState(null);
410
- } else {
411
- const txt =
412
- d.value && d.value.value ? (d.value.value.text ? d.value.value.text.toString() : d.value.value.toString()) : "";
413
- this.currentStateNode = this.getStateByName(txt);
414
- }
415
- }
416
- }
417
-
418
- export function promoteToStateMachine(node: UAObject): UAStateMachineEx {
419
- if (node instanceof UAStateMachineImpl) {
420
- return node; // already promoted
421
- }
422
- Object.setPrototypeOf(node, UAStateMachineImpl.prototype);
423
- assert(node instanceof UAStateMachineImpl, "should now be a State Machine");
424
- const _node = node as unknown as UAStateMachineImpl;
425
- _node._post_initialize();
426
- return _node;
427
- }
428
- registerNodePromoter(ObjectTypeIds.FiniteStateMachineType, promoteToStateMachine);
1
+ /**
2
+ * @module node-opcua-address-space
3
+ */
4
+ import * as chalk from "chalk";
5
+ import { UAState, UAStateVariable, UATransition, UATransition_Base, UATransitionVariable } from "node-opcua-nodeset-ua";
6
+ import { assert } from "node-opcua-assert";
7
+ import { ObjectTypeIds } from "node-opcua-constants";
8
+ import { coerceLocalizedText, LocalizedText, NodeClass } from "node-opcua-data-model";
9
+ import { AttributeIds } from "node-opcua-data-model";
10
+ import { NodeId } from "node-opcua-nodeid";
11
+ import { StatusCodes } from "node-opcua-status-code";
12
+ import { DataType } from "node-opcua-variant";
13
+ import { BaseNode, UAMethod, UAObject, UAObjectType, UAVariable } from "node-opcua-address-space-base";
14
+ import { registerNodePromoter } from "../../source/loader/register_node_promoter";
15
+
16
+ import { UAStateMachineEx, TransitionSelector } from "../../source/interfaces/state_machine/ua_state_machine_type";
17
+ import { UAObjectImpl } from "../ua_object_impl";
18
+ import { UATransitionEx } from "../../source/interfaces/state_machine/ua_transition_ex";
19
+ import { BaseNodeImpl } from "../base_node_impl";
20
+
21
+ const doDebug = false;
22
+
23
+ export declare interface UATransitionImpl extends UATransition, UATransitionEx {}
24
+ export class UATransitionImpl implements UATransition, UATransitionEx {}
25
+
26
+ function getComponentFromTypeAndSubtype(typeDef: UAObjectType): UAObject[] {
27
+ const components_parts: BaseNode[][] = [];
28
+ components_parts.push(typeDef.getComponents());
29
+ while (typeDef.subtypeOfObj) {
30
+ typeDef = typeDef.subtypeOfObj;
31
+ components_parts.push(typeDef.getComponents());
32
+ }
33
+ return Array.prototype.concat.apply([], components_parts).filter((x: BaseNode) => x.nodeClass === NodeClass.Object);
34
+ }
35
+
36
+ export interface UAStateMachineImpl {
37
+ currentState: UAStateVariable<LocalizedText>;
38
+ lastTransition?: UATransitionVariable<LocalizedText>;
39
+
40
+ // Extra
41
+ _currentStateNode: UAState | null;
42
+ }
43
+
44
+ const defaultPredicate = (transitions: UATransition[], fromState: UAState, toState: UAState) => {
45
+ if (transitions.length === 0) {
46
+ return null;
47
+ }
48
+ if (transitions.length === 1) {
49
+ return transitions[0];
50
+ }
51
+ // tslint:disable-next-line: no-console
52
+ console.log(" FromState = ", fromState.browseName.toString());
53
+ // tslint:disable-next-line: no-console
54
+ console.log(" ToState = ", toState.browseName.toString());
55
+ for (const transition of transitions) {
56
+ // tslint:disable-next-line: no-console
57
+ console.log(" possible transition : ", transition.browseName.toString(), " ", transition.nodeId.toString());
58
+ }
59
+ // tslint:disable-next-line: no-console
60
+ console.log(
61
+ "warning: a duplicated FromState Reference to the same target has been found.\nPlease check your model or provide a predicate method to select which one to use"
62
+ );
63
+ // tslint:disable-next-line: no-console
64
+ console.log("fromStateNode: ", fromState.toString());
65
+ return transitions[0];
66
+ };
67
+
68
+ /*
69
+ *
70
+ * @class StateMachine
71
+ * @constructor
72
+ * @extends UAObject
73
+ *
74
+ *
75
+ */
76
+ export class UAStateMachineImpl extends UAObjectImpl implements UAStateMachineEx {
77
+ public getStates(): UAState[] {
78
+ const addressSpace = this.addressSpace;
79
+
80
+ const initialStateType = addressSpace.findObjectType("InitialStateType");
81
+ // istanbul ignore next
82
+ if (!initialStateType) {
83
+ throw new Error("cannot find InitialStateType");
84
+ }
85
+
86
+ const stateType = addressSpace.findObjectType("StateType");
87
+ // istanbul ignore next
88
+ if (!stateType) {
89
+ throw new Error("cannot find StateType");
90
+ }
91
+
92
+ assert(initialStateType.isSupertypeOf(stateType));
93
+
94
+ const typeDef = this.typeDefinitionObj;
95
+
96
+ let comp = getComponentFromTypeAndSubtype(typeDef);
97
+
98
+ comp = comp.filter((c) => {
99
+ if (!c.typeDefinitionObj || c.typeDefinitionObj.nodeClass !== NodeClass.ObjectType) {
100
+ return false;
101
+ }
102
+ return c.typeDefinitionObj.isSupertypeOf(stateType);
103
+ });
104
+
105
+ return comp as UAState[];
106
+ }
107
+
108
+ public get states(): UAState[] {
109
+ return this.getStates();
110
+ }
111
+
112
+ /**
113
+ * @method getStateByName
114
+ * @param name the name of the state to get
115
+ * @return the state with the given name
116
+ */
117
+ public getStateByName(name: string): UAState | null {
118
+ let states = this.getStates();
119
+ states = states.filter((s: any) => {
120
+ return s.browseName.name === name;
121
+ });
122
+ assert(states.length <= 1);
123
+ return states.length === 1 ? (states[0] as any as UAState) : null;
124
+ }
125
+
126
+ public getTransitions(): UATransitionEx[] {
127
+ const addressSpace = this.addressSpace;
128
+
129
+ const transitionType = addressSpace.findObjectType("TransitionType");
130
+ // istanbul ignore next
131
+ if (!transitionType) {
132
+ throw new Error("cannot find TransitionType");
133
+ }
134
+ const typeDef = this.typeDefinitionObj;
135
+
136
+ let comp = getComponentFromTypeAndSubtype(typeDef);
137
+
138
+ comp = comp.filter((c) => {
139
+ if (!c.typeDefinitionObj || c.typeDefinitionObj.nodeClass !== NodeClass.ObjectType) {
140
+ return false;
141
+ }
142
+ return c.typeDefinitionObj.isSupertypeOf(transitionType);
143
+ });
144
+
145
+ return comp as UATransitionEx[];
146
+ }
147
+
148
+ public get transitions(): UATransitionEx[] {
149
+ return this.getTransitions();
150
+ }
151
+
152
+ /**
153
+ * return the node InitialStateType
154
+ * @property initialState
155
+ */
156
+ get initialState(): UAState | null {
157
+ const addressSpace = this.addressSpace;
158
+
159
+ const initialStateType = addressSpace.findObjectType("InitialStateType");
160
+ const typeDef = this.typeDefinitionObj;
161
+
162
+ let comp = getComponentFromTypeAndSubtype(typeDef);
163
+
164
+ comp = comp.filter((c: any) => c.typeDefinitionObj === initialStateType);
165
+
166
+ // istanbul ignore next
167
+ if (comp.length > 1) {
168
+ throw new Error(" More than 1 initial state in stateMachine");
169
+ }
170
+ return comp.length === 0 ? null : (comp[0] as UAState);
171
+ }
172
+
173
+ /**
174
+ *
175
+ * @param node
176
+ * @private
177
+ */
178
+ public _coerceNode(node: UAState | BaseNode | null | string | NodeId): BaseNode | null {
179
+ if (node === null) {
180
+ return null;
181
+ }
182
+ const addressSpace = this.addressSpace;
183
+ if (node instanceof BaseNodeImpl) {
184
+ return node;
185
+ } else if (node instanceof NodeId) {
186
+ return addressSpace.findNode(node) as BaseNode;
187
+ } else if (typeof node === "string") {
188
+ return this.getStateByName(node) as any as BaseNode;
189
+ }
190
+ return null;
191
+ }
192
+
193
+ /**
194
+ * @method isValidTransition
195
+ * @param toStateNode
196
+ * @return {boolean}
197
+ */
198
+ public isValidTransition(toStateNode: UAState | string, predicate?: TransitionSelector): boolean {
199
+ // is it legal to go from state currentState to toStateNode;
200
+ if (!this.currentStateNode) {
201
+ return true;
202
+ }
203
+ const n = this.currentState.readValue();
204
+
205
+ // to be executed there must be a transition from currentState to toState
206
+ const transition = this.findTransitionNode(this.currentStateNode, toStateNode, predicate);
207
+ if (!transition) {
208
+ // istanbul ignore next
209
+ if (doDebug) {
210
+ // tslint:disable-next-line: no-console
211
+ console.log(" No transition from ", this.currentStateNode.browseName.toString(), " to ", toStateNode.toString());
212
+ }
213
+ return false;
214
+ }
215
+ return true;
216
+ }
217
+
218
+ /**
219
+ */
220
+ public findTransitionNode(
221
+ fromStateNode: NodeId | UAState | string | null,
222
+ toStateNode: NodeId | UAState | string | null,
223
+ predicate?: TransitionSelector
224
+ ): UATransitionEx | null {
225
+ const addressSpace = this.addressSpace;
226
+
227
+ const _fromStateNode = this._coerceNode(fromStateNode) as UAObject;
228
+ if (!_fromStateNode) {
229
+ return null;
230
+ }
231
+
232
+ const _toStateNode = this._coerceNode(toStateNode) as UAObject;
233
+ if (!_toStateNode) {
234
+ return null;
235
+ }
236
+
237
+ if (_fromStateNode.nodeClass !== NodeClass.Object) {
238
+ throw new Error("Internal Error");
239
+ }
240
+ if (_toStateNode && _toStateNode.nodeClass !== NodeClass.Object) {
241
+ throw new Error("Internal Error");
242
+ }
243
+
244
+ const stateType = addressSpace.findObjectType("StateType");
245
+ if (!stateType) {
246
+ throw new Error("Cannot find StateType");
247
+ }
248
+ assert((_fromStateNode.typeDefinitionObj as any).isSupertypeOf(stateType));
249
+ assert((_toStateNode.typeDefinitionObj as any).isSupertypeOf(stateType));
250
+
251
+ let transitions = _fromStateNode.findReferencesAsObject("FromState", false) as UATransitionImpl[];
252
+
253
+ transitions = transitions.filter((transition: any) => {
254
+ assert(transition.toStateNode.nodeClass === NodeClass.Object);
255
+ return transition.toStateNode === _toStateNode;
256
+ });
257
+ if (transitions.length === 0) {
258
+ // cannot find a transition from fromState to toState
259
+ return null;
260
+ }
261
+ // istanbul ignore next
262
+ if (transitions.length > 1) {
263
+ const selectedTransition = (predicate || defaultPredicate)(
264
+ transitions,
265
+ _fromStateNode as unknown as UAState,
266
+ _toStateNode as unknown as UAState
267
+ );
268
+ return selectedTransition as UATransitionEx;
269
+ }
270
+ return transitions[0];
271
+ }
272
+
273
+ public get currentStateNode(): UAState | null {
274
+ return this._currentStateNode;
275
+ }
276
+
277
+ /**
278
+ * @property currentStateNode
279
+ * @type BaseNode
280
+ */
281
+ public set currentStateNode(value: UAState | null) {
282
+ this._currentStateNode = value;
283
+ }
284
+
285
+ /**
286
+ */
287
+ public getCurrentState(): string | null {
288
+ // xx this.currentState.readValue().value.value.text
289
+ // xx this.shelvingState.currentStateNode.browseName.toString()
290
+ if (!this.currentStateNode) {
291
+ return null;
292
+ }
293
+ return this.currentStateNode.browseName.toString();
294
+ }
295
+
296
+ /**
297
+ * @method setState
298
+ */
299
+ public setState(toStateNode: string | UAState | null, predicate?: TransitionSelector): void {
300
+ if (!toStateNode) {
301
+ this.currentStateNode = null;
302
+ this.currentState.setValueFromSource({ dataType: DataType.LocalizedText, value: null }, StatusCodes.BadStateNotActive);
303
+ return;
304
+ }
305
+
306
+ if (typeof toStateNode === "string") {
307
+ const state = this.getStateByName(toStateNode);
308
+ // istanbul ignore next
309
+ if (!state) {
310
+ throw new Error("Cannot find state with name " + toStateNode);
311
+ }
312
+ assert(state.browseName.name!.toString() === toStateNode);
313
+ toStateNode = state;
314
+ }
315
+ const fromStateNode = this.currentStateNode;
316
+
317
+ toStateNode = this._coerceNode(toStateNode) as any as UAState;
318
+ assert(toStateNode.nodeClass === NodeClass.Object);
319
+
320
+ this.currentState.setValueFromSource(
321
+ {
322
+ dataType: DataType.LocalizedText,
323
+ value: coerceLocalizedText(toStateNode.browseName.toString())
324
+ },
325
+ StatusCodes.Good
326
+ );
327
+
328
+ this.currentStateNode = toStateNode;
329
+
330
+ const transitionNode = this.findTransitionNode(fromStateNode, toStateNode, predicate) as UATransitionImpl;
331
+
332
+ if (transitionNode) {
333
+ // xx console.log("transitionNode ",transitionNode.toString());
334
+ // The inherited Property SourceNode shall be filled with the NodeId of the StateMachine instance where the
335
+ // Transition occurs. If the Transition occurs in a SubStateMachine, then the NodeId of the SubStateMachine
336
+ // has to be used. If the Transition occurs between a StateMachine and a SubStateMachine, then the NodeId of
337
+ // the StateMachine has to be used, independent of the direction of the Transition.
338
+ // Transition identifies the Transition that triggered the Event.
339
+ // FromState identifies the State before the Transition.
340
+ // ToState identifies the State after the Transition.
341
+ this.raiseEvent("TransitionEventType", {
342
+ // Base EventType
343
+ // xx nodeId: this.nodeId,
344
+ // TransitionEventType
345
+ // TransitionVariableType
346
+ transition: {
347
+ dataType: "LocalizedText",
348
+ value: (transitionNode as BaseNode).displayName[0]
349
+ },
350
+
351
+ "transition.id": transitionNode.transitionNumber.readValue().value,
352
+
353
+ fromState: {
354
+ dataType: "LocalizedText",
355
+ value: fromStateNode ? fromStateNode.displayName[0] : ""
356
+ }, // StateVariableType
357
+
358
+ "fromState.id": fromStateNode
359
+ ? fromStateNode.stateNumber.readValue().value
360
+ : {
361
+ dataType: "Null"
362
+ },
363
+
364
+ toState: {
365
+ dataType: "LocalizedText",
366
+ value: toStateNode.displayName[0]
367
+ }, // StateVariableType
368
+
369
+ "toState.id": toStateNode.stateNumber.readValue().value
370
+ });
371
+ } else {
372
+ if (fromStateNode && fromStateNode !== toStateNode) {
373
+ // istanbul ignore next
374
+ if (doDebug) {
375
+ const f = fromStateNode.browseName.toString();
376
+ const t = toStateNode.browseName.toString();
377
+ // tslint:disable-next-line:no-console
378
+ console.log(chalk.red("Warning"), " cannot raise event : transition " + f + " to " + t + " is missing");
379
+ }
380
+ }
381
+ }
382
+
383
+ // also update executable flags on methods
384
+ for (const method of this.getMethods()) {
385
+ (method as any)._notifyAttributeChange(AttributeIds.Executable);
386
+ }
387
+ }
388
+
389
+ /**
390
+ * @internal
391
+ * @private
392
+ */
393
+ public _post_initialize(): void {
394
+ const addressSpace = this.addressSpace;
395
+ const finiteStateMachineType = addressSpace.findObjectType("FiniteStateMachineType");
396
+ if (!finiteStateMachineType) {
397
+ throw new Error("cannot find FiniteStateMachineType");
398
+ }
399
+
400
+ // xx assert(this.typeDefinitionObj && !this.subtypeOfObj);
401
+ // xx assert(!this.typeDefinitionObj || this.typeDefinitionObj.isSupertypeOf(finiteStateMachineType));
402
+ // get current Status
403
+
404
+ const d = this.currentState.readValue();
405
+
406
+ if (d.statusCode !== StatusCodes.Good) {
407
+ this.setState(null);
408
+ } else {
409
+ const txt =
410
+ d.value && d.value.value ? (d.value.value.text ? d.value.value.text.toString() : d.value.value.toString()) : "";
411
+ this.currentStateNode = this.getStateByName(txt);
412
+ }
413
+ }
414
+ }
415
+
416
+ export function promoteToStateMachine(node: UAObject): UAStateMachineEx {
417
+ if (node instanceof UAStateMachineImpl) {
418
+ return node; // already promoted
419
+ }
420
+ Object.setPrototypeOf(node, UAStateMachineImpl.prototype);
421
+ assert(node instanceof UAStateMachineImpl, "should now be a State Machine");
422
+ const _node = node as unknown as UAStateMachineImpl;
423
+ _node._post_initialize();
424
+ return _node;
425
+ }
426
+ registerNodePromoter(ObjectTypeIds.FiniteStateMachineType, promoteToStateMachine);