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,1388 +1,1388 @@
1
- "use strict";
2
- /**
3
- * @module node-opcua-address-space
4
- */
5
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
- });
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.AddressSpace = void 0;
16
- const crypto_1 = require("crypto");
17
- const chalk = require("chalk");
18
- const node_opcua_assert_1 = require("node-opcua-assert");
19
- const node_opcua_constants_1 = require("node-opcua-constants");
20
- const node_opcua_data_model_1 = require("node-opcua-data-model");
21
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
22
- const node_opcua_object_registry_1 = require("node-opcua-object-registry");
23
- const node_opcua_service_browse_1 = require("node-opcua-service-browse");
24
- const node_opcua_status_code_1 = require("node-opcua-status-code");
25
- const node_opcua_types_1 = require("node-opcua-types");
26
- const utils = require("node-opcua-utils");
27
- const node_opcua_utils_1 = require("node-opcua-utils");
28
- const node_opcua_variant_1 = require("node-opcua-variant");
29
- const node_opcua_debug_1 = require("node-opcua-debug");
30
- const adjust_browse_direction_1 = require("../source/helpers/adjust_browse_direction");
31
- const alarms_and_conditions_1 = require("./alarms_and_conditions");
32
- const event_data_1 = require("./event_data");
33
- const address_space_historical_data_node_1 = require("./historical_access/address_space_historical_data_node");
34
- const namespace_impl_1 = require("./namespace_impl");
35
- const namespace_impl_2 = require("./namespace_impl");
36
- const ua_data_type_impl_1 = require("./ua_data_type_impl");
37
- const ua_object_type_impl_1 = require("./ua_object_type_impl");
38
- const ua_object_impl_1 = require("./ua_object_impl");
39
- const reference_impl_1 = require("./reference_impl");
40
- const ua_reference_type_impl_1 = require("./ua_reference_type_impl");
41
- const base_node_impl_1 = require("./base_node_impl");
42
- const doDebug = false;
43
- const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
44
- // tslint:disable-next-line:no-var-requires
45
- const Dequeue = require("dequeue");
46
- const regexNumberColumnString = /^([0-9]+):(.*)/;
47
- const enumerationTypeNodeId = (0, node_opcua_nodeid_1.coerceNodeId)(node_opcua_constants_1.DataTypeIds.Enumeration);
48
- function _extract_namespace_and_browse_name_as_string(addressSpace, browseName, namespaceIndex) {
49
- (0, node_opcua_assert_1.assert)(!namespaceIndex || namespaceIndex >= 0);
50
- let result;
51
- if (namespaceIndex !== undefined && namespaceIndex > 0) {
52
- (0, node_opcua_assert_1.assert)(typeof browseName === "string", "expecting a string when namespaceIndex is specified");
53
- result = [addressSpace.getNamespace(namespaceIndex), browseName];
54
- }
55
- else if (typeof browseName === "string") {
56
- // split
57
- if (browseName.indexOf(":") >= 0) {
58
- const a = browseName.split(":");
59
- namespaceIndex = a.length === 2 ? parseInt(a[0], 10) : namespaceIndex;
60
- browseName = a.length === 2 ? a[1] : browseName;
61
- }
62
- result = [addressSpace.getNamespace(namespaceIndex || 0), browseName];
63
- }
64
- else if (browseName instanceof node_opcua_data_model_1.QualifiedName) {
65
- namespaceIndex = browseName.namespaceIndex;
66
- result = [addressSpace.getNamespace(namespaceIndex), browseName.name];
67
- }
68
- else if (typeof browseName === "number") {
69
- result = [addressSpace.getDefaultNamespace(), node_opcua_variant_1.DataType[browseName]];
70
- }
71
- /* istanbul ignore next */
72
- if (!result || !result[0]) {
73
- throw new Error(` Cannot find namespace associated with ${browseName} ${namespaceIndex}`);
74
- }
75
- return result;
76
- }
77
- /**
78
- * returns true if str matches a nodeID, e.g i=123 or ns=...
79
- * @method isNodeIdString
80
- * @param str
81
- * @type {boolean}
82
- */
83
- function isNodeIdString(str) {
84
- if (typeof str !== "string") {
85
- return false;
86
- }
87
- return str.substring(0, 2) === "i=" || str.substring(0, 3) === "ns=";
88
- }
89
- /**
90
- * `AddressSpace` is a collection of UA nodes.
91
- *
92
- * const addressSpace = AddressSpace.create();
93
- */
94
- class AddressSpace {
95
- constructor() {
96
- /***
97
- * @internal
98
- * @private
99
- */
100
- this.suspendBackReference = false;
101
- this.isFrugal = false;
102
- this.historizingNodes = {};
103
- this._condition_refresh_in_progress = false;
104
- this.isNodeIdString = isNodeIdString;
105
- this._shutdownTask = [];
106
- this._modelChangeTransactionCounter = 0;
107
- this._modelChanges = [];
108
- this._private_namespaceIndex = 1;
109
- this._namespaceArray = [];
110
- // special namespace 0 is reserved for the UA namespace
111
- this.registerNamespace("http://opcfoundation.org/UA/");
112
- AddressSpace.registry.register(this);
113
- }
114
- get rootFolder() {
115
- const rootFolder = this.findNode(this.resolveNodeId("RootFolder"));
116
- if (!rootFolder) {
117
- // throw new Error("AddressSpace doesn't contain rootFolder object");
118
- return null;
119
- }
120
- return rootFolder;
121
- }
122
- static create() {
123
- return new AddressSpace();
124
- }
125
- /**
126
- * @internal
127
- */
128
- getDataTypeManager() {
129
- const addressSpacePriv = this;
130
- (0, node_opcua_assert_1.assert)(addressSpacePriv.$$extraDataTypeManager, "expecting a $$extraDataTypeManager please make sure ensureDatatypeExtracted is called");
131
- return addressSpacePriv.$$extraDataTypeManager;
132
- }
133
- getNamespaceUri(namespaceIndex) {
134
- (0, node_opcua_assert_1.assert)(namespaceIndex >= 0 && namespaceIndex < this._namespaceArray.length);
135
- return this._namespaceArray[namespaceIndex].namespaceUri;
136
- }
137
- /***
138
- * @method getNamespace
139
- * @param {string|number} namespace index or namespace uri.
140
- * @return {NameSpace} the namespace
141
- */
142
- getNamespace(namespaceIndexOrName) {
143
- if (typeof namespaceIndexOrName === "number") {
144
- const namespaceIndex = namespaceIndexOrName;
145
- (0, node_opcua_assert_1.assert)(namespaceIndex >= 0 && namespaceIndex < this._namespaceArray.length, "invalid namespace index ( out of bound)");
146
- return this._namespaceArray[namespaceIndex];
147
- }
148
- else {
149
- const namespaceUri = namespaceIndexOrName;
150
- (0, node_opcua_assert_1.assert)(typeof namespaceUri === "string");
151
- const index = this.getNamespaceIndex(namespaceUri);
152
- return this._namespaceArray[index];
153
- }
154
- }
155
- /***
156
- * @method getDefaultNamespace
157
- * @return the default namespace (standard OPCUA namespace)
158
- */
159
- getDefaultNamespace() {
160
- return this.getNamespace(0);
161
- }
162
- /***
163
- * @method getOwnNamespace
164
- *
165
- * objects instances managed by the server will be created in this namespace.
166
- *
167
- * @return address space own namespace
168
- */
169
- getOwnNamespace() {
170
- /* istanbul ignore next */
171
- if (this._private_namespaceIndex >= this._namespaceArray.length) {
172
- throw new Error("please create the private namespace");
173
- }
174
- return this.getNamespace(this._private_namespaceIndex);
175
- }
176
- /**
177
- * @method getNamespaceIndex
178
- * @param namespaceUri
179
- * @return the namespace index of a namespace given by its namespace uri
180
- *
181
- */
182
- getNamespaceIndex(namespaceUri) {
183
- (0, node_opcua_assert_1.assert)(typeof namespaceUri === "string");
184
- return this._namespaceArray.findIndex((ns) => ns.namespaceUri === namespaceUri);
185
- }
186
- /**
187
- * @method registerNamespace
188
- *
189
- * register a new namespace
190
- *
191
- * @param namespaceUri {string}
192
- * @returns {Namespace}
193
- */
194
- registerNamespace(namespaceUri) {
195
- let index = this._namespaceArray.findIndex((ns) => ns.namespaceUri === namespaceUri);
196
- if (index !== -1) {
197
- (0, node_opcua_assert_1.assert)(this._namespaceArray[index].addressSpace === this);
198
- return this._namespaceArray[index];
199
- }
200
- index = this._namespaceArray.length;
201
- this._namespaceArray.push(new namespace_impl_1.NamespaceImpl({
202
- addressSpace: this,
203
- index,
204
- namespaceUri,
205
- publicationDate: new Date(),
206
- version: "undefined"
207
- }));
208
- return this._namespaceArray[index];
209
- }
210
- /***
211
- * @method getNamespaceArray
212
- * @return {Namespace[]} the namespace array
213
- */
214
- getNamespaceArray() {
215
- return this._namespaceArray;
216
- }
217
- /**
218
- *
219
- * @method addAlias
220
- * @param alias {String} the alias name
221
- * @param nodeId {NodeId}
222
- * @internal
223
- */
224
- addAlias(alias, nodeId) {
225
- (0, node_opcua_assert_1.assert)(typeof alias === "string");
226
- (0, node_opcua_assert_1.assert)(nodeId instanceof node_opcua_nodeid_1.NodeId);
227
- this.getNamespace(nodeId.namespace).addAlias(alias, nodeId);
228
- }
229
- /**
230
- * find an node by node Id
231
- * @method findNode
232
- * @param nodeId a nodeId or a string coerce-able to nodeID, representing the object to find.
233
- * @return {BaseNode|null}
234
- */
235
- findNode(nodeId) {
236
- if (!(nodeId instanceof node_opcua_nodeid_1.NodeId)) {
237
- nodeId = this.resolveNodeId(nodeId);
238
- }
239
- if (nodeId.namespace < 0 || nodeId.namespace >= this._namespaceArray.length) {
240
- // namespace index is out of bound
241
- return null;
242
- }
243
- const namespace = this._namespaceArray[nodeId.namespace];
244
- return namespace.findNode2(nodeId);
245
- }
246
- findMethod(nodeId) {
247
- const node = this.findNode(nodeId);
248
- if (!node || node.nodeClass !== node_opcua_data_model_1.NodeClass.Method) {
249
- return null;
250
- }
251
- return node;
252
- }
253
- /**
254
- * resolved a string or a nodeId to a nodeID
255
- */
256
- resolveNodeId(nodeId) {
257
- if (typeof nodeId === "string") {
258
- const m = nodeId.match(regexNumberColumnString);
259
- if (m && m.length === 3) {
260
- const namespaceIndex = parseInt(m[1], 10);
261
- const aliasName = m[2];
262
- const namespace = this.getNamespace(namespaceIndex);
263
- // check if the string is a known alias
264
- const aliasNodeId = namespace.resolveAlias(aliasName);
265
- if (aliasNodeId !== null) {
266
- return aliasNodeId;
267
- }
268
- }
269
- }
270
- return (0, node_opcua_nodeid_1.resolveNodeId)(nodeId);
271
- }
272
- /**
273
- *
274
- * @method findObjectType
275
- * @param objectType {String|NodeId|QualifiedName}
276
- * @param [namespaceIndex=0 {Number}] an optional namespace index
277
- * @return {UAObjectType|null}
278
- *
279
- * @example
280
- *
281
- * ```javascript
282
- * const objectType = addressSpace.findObjectType("ns=0;i=58");
283
- * objectType.browseName.toString().should.eql("BaseObjectType");
284
- *
285
- * const objectType = addressSpace.findObjectType("BaseObjectType");
286
- * objectType.browseName.toString().should.eql("BaseObjectType");
287
- *
288
- * const objectType = addressSpace.findObjectType(resolveNodeId("ns=0;i=58"));
289
- * objectType.browseName.toString().should.eql("BaseObjectType");
290
- *
291
- * const objectType = addressSpace.findObjectType("CustomObjectType",36);
292
- * objectType.nodeId.namespace.should.eql(36);
293
- * objectType.browseName.toString().should.eql("BaseObjectType");
294
- *
295
- * const objectType = addressSpace.findObjectType("36:CustomObjectType");
296
- * objectType.nodeId.namespace.should.eql(36);
297
- * objectType.browseName.toString().should.eql("BaseObjectType");
298
- * ```
299
- */
300
- findObjectType(objectType, namespaceIndex) {
301
- if (objectType instanceof node_opcua_nodeid_1.NodeId) {
302
- return _find_by_node_id(this, objectType, namespaceIndex);
303
- }
304
- const [namespace, browseName] = _extract_namespace_and_browse_name_as_string(this, objectType, namespaceIndex);
305
- return namespace.findObjectType(browseName);
306
- }
307
- /**
308
- * @method findVariableType
309
- * @param variableType {String|NodeId}
310
- * @param [namespaceIndex=0 {Number}] an optional namespace index
311
- * @return {UAObjectType|null}
312
- *
313
- * @example
314
- *
315
- * ```javascript
316
- * const objectType = addressSpace.findVariableType("ns=0;i=62");
317
- * objectType.browseName.toString().should.eql("BaseVariableType");
318
- *
319
- * const objectType = addressSpace.findVariableType("BaseVariableType");
320
- * objectType.browseName.toString().should.eql("BaseVariableType");
321
- *
322
- * const objectType = addressSpace.findVariableType(resolveNodeId("ns=0;i=62"));
323
- * objectType.browseName.toString().should.eql("BaseVariableType");
324
- * ```
325
- */
326
- findVariableType(variableType, namespaceIndex) {
327
- if (variableType instanceof node_opcua_nodeid_1.NodeId) {
328
- return _find_by_node_id(this, variableType, namespaceIndex);
329
- }
330
- const [namespace, browseName] = _extract_namespace_and_browse_name_as_string(this, variableType, namespaceIndex);
331
- return namespace.findVariableType(browseName);
332
- }
333
- /**
334
- * Find the DataType node from a NodeId or a browseName
335
- * @method findDataType
336
- * @param dataType {String|NodeId}
337
- * @param [namespaceIndex=0 {Number}] an optional namespace index
338
- * @return {DataType|null}
339
- *
340
- *
341
- * @example
342
- *
343
- * ```javascript
344
- * const dataDouble = addressSpace.findDataType("Double");
345
- * const dataDouble = addressSpace.findDataType(resolveNodeId("ns=0;i=3"));
346
- * ```
347
- */
348
- findDataType(dataType, namespaceIndex) {
349
- // startingNode i=24 :
350
- // BaseDataType
351
- // +-> Boolean (i=1) {BooleanDataType (ns=2:9898)
352
- // +-> String (i=12)
353
- // +->NumericRange
354
- // +->Time
355
- // +-> DateTime
356
- // +-> Structure
357
- // +-> Node
358
- // +-> ObjectNode
359
- if (dataType instanceof node_opcua_nodeid_1.NodeId) {
360
- return _find_by_node_id(this, dataType, namespaceIndex);
361
- }
362
- if (typeof dataType === "number") {
363
- if (node_opcua_variant_1.DataType[dataType] !== undefined) {
364
- dataType = node_opcua_variant_1.DataType[dataType];
365
- }
366
- else {
367
- return this.findDataType((0, node_opcua_nodeid_1.resolveNodeId)(dataType));
368
- }
369
- }
370
- const res = _extract_namespace_and_browse_name_as_string(this, dataType, namespaceIndex);
371
- const namespace = res[0];
372
- const browseName = res[1];
373
- return namespace.findDataType(browseName);
374
- }
375
- /**
376
- * @method findCorrespondingBasicDataType
377
- *
378
- * @example
379
- *
380
- * const dataType = addressSpace.findDataType("ns=0;i=12");
381
- * addressSpace.findCorrespondingBasicDataType(dataType).should.eql(DataType.String);
382
- *
383
- * const dataType = addressSpace.findDataType("ServerStatusDataType"); // ServerStatus
384
- * addressSpace.findCorrespondingBasicDataType(dataType).should.eql(DataType.ExtensionObject);
385
- *
386
- */
387
- findCorrespondingBasicDataType(dataTypeNode) {
388
- const _orig_dataTypeNode = dataTypeNode;
389
- if (typeof dataTypeNode === "string") {
390
- const resolvedDataType = this.resolveNodeId(dataTypeNode);
391
- /* istanbul ignore next */
392
- if (!resolvedDataType) {
393
- throw new Error("Cannot resolve " + _orig_dataTypeNode.toString());
394
- }
395
- dataTypeNode = resolvedDataType;
396
- }
397
- if (dataTypeNode instanceof node_opcua_nodeid_1.NodeId) {
398
- dataTypeNode = this.findDataType(dataTypeNode);
399
- /* istanbul ignore next */
400
- if (!dataTypeNode) {
401
- throw Error("cannot find dataTypeNode " + _orig_dataTypeNode.toString());
402
- }
403
- }
404
- /* istanbul ignore next */
405
- if (!(dataTypeNode instanceof ua_data_type_impl_1.UADataTypeImpl)) {
406
- throw new Error("we are expecting an UADataType here : " +
407
- _orig_dataTypeNode.toString() +
408
- " should not refer to a " +
409
- dataTypeNode.constructor.name);
410
- }
411
- if ((0, node_opcua_nodeid_1.sameNodeId)(enumerationTypeNodeId, dataTypeNode.nodeId)) {
412
- return node_opcua_variant_1.DataType.Int32;
413
- }
414
- if (dataTypeNode.nodeId.namespace === 0 && dataTypeNode.nodeId.value === 29) {
415
- // Number
416
- return node_opcua_variant_1.DataType.Null; //which one ?
417
- }
418
- if (dataTypeNode.nodeId.namespace === 0 && dataTypeNode.nodeId.value === 0) {
419
- return node_opcua_variant_1.DataType.Null;
420
- }
421
- if (dataTypeNode.nodeId.namespace === 0 && dataTypeNode.nodeId.value <= 25) {
422
- return dataTypeNode.nodeId.value;
423
- }
424
- const result = this.findCorrespondingBasicDataType(dataTypeNode.subtypeOfObj);
425
- return result;
426
- }
427
- /**
428
- * find a ReferenceType by its inverse name.
429
- * @method findReferenceTypeFromInverseName
430
- * @param inverseName the inverse name of the ReferenceType to find
431
- * @deprecated
432
- */
433
- findReferenceTypeFromInverseName(inverseName) {
434
- return this.getDefaultNamespace().findReferenceTypeFromInverseName(inverseName);
435
- }
436
- /**
437
- * @method findReferenceType
438
- * @param refType {String|NodeId}
439
- * @param [namespaceIndex=0 {Number}] an optional namespace index
440
- * @return {ReferenceType|null}
441
- *
442
- * refType could be
443
- * - a string representing a nodeid : e.g. `i=9004` or ns=1;i=6030
444
- * - a string representing a browse name : e.g `"HasTypeDefinition"`.
445
- * In this case it should be in the alias list.
446
- *
447
- */
448
- findReferenceType(refType, namespaceIndex) {
449
- // startingNode ns=0;i=31 : References
450
- // +-> References i=31
451
- // +->(hasSubtype) NonHierarchicalReferences
452
- // +->(hasSubtype) HasTypeDefinition
453
- // +->(hasSubtype) HierarchicalReferences
454
- // +->(hasSubtype) HasChild/ChildOf
455
- // +->(hasSubtype) Aggregates/AggregatedBy
456
- // +-> HasProperty/PropertyOf
457
- // +-> HasComponent/ComponentOf
458
- // +-> HasHistoricalConfiguration/HistoricalConfigurationOf
459
- // +->(hasSubtype) HasSubtype/HasSupertype
460
- // +->(hasSubtype) Organizes/OrganizedBy
461
- // +->(hasSubtype) HasEventSource/EventSourceOf
462
- let node;
463
- if (isNodeIdString(refType) || typeof refType === "number") {
464
- refType = (0, node_opcua_nodeid_1.resolveNodeId)(refType);
465
- }
466
- if (refType instanceof node_opcua_nodeid_1.NodeId) {
467
- node = this.findNode(refType);
468
- /* istanbul ignore next */
469
- if (!(node && node.nodeClass === node_opcua_data_model_1.NodeClass.ReferenceType)) {
470
- // throw new Error("cannot resolve referenceId "+ refType.toString());
471
- return null;
472
- }
473
- }
474
- else {
475
- (0, node_opcua_assert_1.assert)(typeof refType === "string");
476
- node = this._findReferenceType(refType, namespaceIndex);
477
- }
478
- return node;
479
- }
480
- /**
481
- * returns the inverse name of the referenceType.
482
- *
483
- * @method inverseReferenceType
484
- * @param referenceType {String} : the reference type name
485
- * @return {String} the name of the inverse reference type.
486
- *
487
- * @example
488
- *
489
- * ```javascript
490
- * addressSpace.inverseReferenceType("OrganizedBy").should.eql("Organizes");
491
- * addressSpace.inverseReferenceType("Organizes").should.eql("OrganizedBy");
492
- * ```
493
- *
494
- */
495
- inverseReferenceType(referenceType) {
496
- (0, node_opcua_assert_1.assert)(typeof referenceType === "string");
497
- const n1 = this.findReferenceType(referenceType);
498
- const n2 = this.findReferenceTypeFromInverseName(referenceType);
499
- if (n1) {
500
- (0, node_opcua_assert_1.assert)(!n2);
501
- return n1.inverseName.text;
502
- }
503
- else {
504
- (0, node_opcua_assert_1.assert)(n2);
505
- return n2.browseName.toString();
506
- }
507
- }
508
- /**
509
- * find an EventType node in the address space
510
- * @method findEventType
511
- * @param eventTypeId {String|NodeId|UAObjectType} the eventType to find
512
- * @param namespaceIndex the namespace index of the event to find
513
- * @return {UAObjectType|null} the EventType found or null.
514
- *
515
- * note:
516
- * - the method with throw an exception if a node is found
517
- * that is not a BaseEventType or a subtype of it.
518
- *
519
- * @example
520
- *
521
- * var evtType = addressSpace.findEventType("AuditEventType");
522
- *
523
- */
524
- findEventType(eventTypeId, namespaceIndex) {
525
- let eventType;
526
- if (eventTypeId instanceof base_node_impl_1.BaseNodeImpl) {
527
- eventType = eventTypeId;
528
- }
529
- else {
530
- eventType = this.findObjectType(eventTypeId, namespaceIndex);
531
- }
532
- if (!eventType) {
533
- return null;
534
- }
535
- const baseEventType = this.findObjectType("BaseEventType");
536
- /* istanbul ignore next */
537
- if (!baseEventType) {
538
- throw new Error("expecting BaseEventType - please check you nodeset xml file!");
539
- }
540
- if ((0, node_opcua_nodeid_1.sameNodeId)(eventType.nodeId, baseEventType.nodeId)) {
541
- return eventType;
542
- }
543
- /* eventTypeNode should be isSupertypeOf("BaseEventType"); */
544
- /* istanbul ignore next */
545
- if (!eventType.isSupertypeOf(baseEventType)) {
546
- throw new Error("findEventType: event found is not subType of BaseEventType");
547
- }
548
- return eventType;
549
- }
550
- /**
551
- * EventId is generated by the Server to uniquely identify a particular Event Notification.
552
- * @method generateEventId
553
- * @return {Variant} dataType: "ByteString"
554
- */
555
- generateEventId() {
556
- /*
557
- * OpcUA 1.02 part 5 : 6.4.2 BaseEventType
558
- * The Server is responsible to ensure that each Event has its unique EventId.
559
- * It may do this, for example, by putting GUIDs into the ByteString.
560
- * Clients can use the EventId to assist in minimizing or eliminating gaps and overlaps that may occur during
561
- * a redundancy fail-over. The EventId shall always be returned as value and the Server is not allowed to
562
- * return a StatusCode for the EventId indicating an error.
563
- *
564
- */
565
- const offset = 16;
566
- const self = this;
567
- if (!self._eventIdCounter) {
568
- self._eventIdCounter = (0, crypto_1.randomBytes)(20);
569
- self._eventIdCounter.writeInt32BE(0, offset);
570
- }
571
- self._eventIdCounter.writeInt32BE(self._eventIdCounter.readInt32BE(offset) + 1, offset);
572
- return new node_opcua_variant_1.Variant({
573
- dataType: node_opcua_variant_1.DataType.ByteString,
574
- value: Buffer.from(self._eventIdCounter)
575
- });
576
- }
577
- /*=
578
- * construct a simple javascript object with all the default properties of the event
579
- * @method constructEventData
580
- *
581
- * @return result.$eventDataSource {BaseNode} the event type node
582
- * @return result.eventId {NodeId} the
583
- * ...
584
- *
585
- *
586
- * eventTypeId can be a UAEventType
587
- *
588
- * @private
589
- */
590
- constructEventData(eventTypeId, data) {
591
- data = data || {};
592
- // construct the reference dataStructure to store event Data
593
- let eventTypeNode = eventTypeId;
594
- // make sure that eventType is really a object that derived from EventType
595
- if (eventTypeId instanceof ua_object_type_impl_1.UAObjectTypeImpl) {
596
- eventTypeNode = this.findEventType(eventTypeId);
597
- }
598
- /* istanbul ignore next */
599
- if (!eventTypeNode) {
600
- throw new Error(" cannot find EvenType for " + eventTypeId);
601
- }
602
- (0, node_opcua_assert_1.assert)(eventTypeNode instanceof ua_object_type_impl_1.UAObjectTypeImpl, "eventTypeId must represent a UAObjectType");
603
- // eventId
604
- (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(data, "eventId"), "eventId constructEventData : options object should not have eventId property");
605
- data.eventId = data.eventId || this.generateEventId();
606
- // eventType
607
- data.eventType = { dataType: node_opcua_variant_1.DataType.NodeId, value: eventTypeNode.nodeId };
608
- // sourceNode
609
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(data, "sourceNode"), "expecting a source node to be defined");
610
- data.sourceNode = new node_opcua_variant_1.Variant(data.sourceNode);
611
- (0, node_opcua_assert_1.assert)(data.sourceNode.dataType === node_opcua_variant_1.DataType.NodeId);
612
- // sourceName
613
- const sourceNode = this.findNode(data.sourceNode.value);
614
- data.sourceName = data.sourceName || {
615
- dataType: node_opcua_variant_1.DataType.String,
616
- value: sourceNode.getDisplayName("en")
617
- };
618
- const nowUTC = new Date();
619
- // time (UtcTime)
620
- // TODO
621
- data.time = data.time || { dataType: node_opcua_variant_1.DataType.DateTime, value: nowUTC };
622
- // receivedTime (UtcTime)
623
- // TODO
624
- data.receiveTime = data.receiveTime || { dataType: node_opcua_variant_1.DataType.DateTime, value: nowUTC };
625
- // localTime (UtcTime)
626
- // TODO
627
- data.localTime = data.localTime || { dataType: node_opcua_variant_1.DataType.DateTime, value: nowUTC };
628
- // message (LocalizedText)
629
- data.message = data.message || { dataType: node_opcua_variant_1.DataType.LocalizedText, value: { text: "" } };
630
- // severity (UInt16)
631
- data.severity = data.severity || { dataType: node_opcua_variant_1.DataType.UInt16, value: 0 };
632
- // xx // reminder : event type cannot be instantiated directly !
633
- // xx assert(eventTypeNode.isAbstract);
634
- const baseObjectType = this.findObjectType("BaseObjectType"); // i=58
635
- /* istanbul ignore next */
636
- if (!baseObjectType) {
637
- throw new Error("BaseObjectType must be defined in the address space");
638
- }
639
- const visitedProperties = {};
640
- function _process_var(self, prefix, node) {
641
- const lowerName = prefix + (0, node_opcua_utils_1.lowerFirstLetter)(node.browseName.name);
642
- // istanbul ignore next
643
- // xx if (doDebug) { debugLog(" " + lowerName.toString()); }
644
- visitedProperties[lowerName] = node;
645
- if (Object.prototype.hasOwnProperty.call(data, lowerName)) {
646
- eventData.setValue(lowerName, node, data[lowerName]);
647
- // xx eventData[lowerName] = _coerceVariant(data[lowerName]);
648
- }
649
- else {
650
- // add a property , but with a null variant
651
- eventData.setValue(lowerName, node, { dataType: node_opcua_variant_1.DataType.Null });
652
- if (doDebug) {
653
- if (node.modellingRule === "Mandatory") {
654
- // tslint:disable:no-console
655
- console.log(chalk.red("ERROR : AddressSpace#constructEventData(eventType,options) " + "cannot find property ") +
656
- self.browseName.toString() +
657
- " => " +
658
- chalk.cyan(lowerName));
659
- }
660
- else {
661
- console.log(chalk.yellow("Warning : AddressSpace#constructEventData(eventType,options)" + " cannot find property ") +
662
- self.browseName.toString() +
663
- " => " +
664
- chalk.cyan(lowerName));
665
- }
666
- }
667
- }
668
- }
669
- // verify that all elements of data are valid
670
- function verify_data_is_valid(data1) {
671
- Object.keys(data1).map((k) => {
672
- if (k === "$eventDataSource") {
673
- return;
674
- }
675
- /* istanbul ignore next */
676
- if (!Object.prototype.hasOwnProperty.call(visitedProperties, k)) {
677
- throw new Error(" cannot find property '" +
678
- k +
679
- "' in [ " +
680
- Object.keys(visitedProperties).join(", ") +
681
- "] when filling " +
682
- eventTypeNode.browseName.toString());
683
- }
684
- });
685
- }
686
- const populate_data = (self, eventData1) => {
687
- if ((0, node_opcua_nodeid_1.sameNodeId)(baseObjectType.nodeId, self.nodeId)) {
688
- return; // nothing to do
689
- }
690
- const baseTypeNodeId = self.subtypeOf;
691
- /* istanbul ignore next */
692
- if (!baseTypeNodeId) {
693
- throw new Error("Object " + self.browseName.toString() + " with nodeId " + self.nodeId + " has no Type");
694
- }
695
- const baseType = this.findNode(baseTypeNodeId);
696
- /* istanbul ignore next */
697
- if (!baseType) {
698
- throw new Error(chalk.red("Cannot find object with nodeId ") + baseTypeNodeId);
699
- }
700
- populate_data(baseType, eventData1);
701
- // get properties and components from base class
702
- const properties = self.getProperties();
703
- const components = self.getComponents();
704
- const children = [].concat(properties, components);
705
- // istanbul ignore next
706
- if (doDebug) {
707
- console.log(" " + chalk.bgWhite.cyan(self.browseName.toString()));
708
- }
709
- for (const node of children) {
710
- // only keep those that have a "HasModellingRule"
711
- if (!node.modellingRule) {
712
- // xx console.log(" skipping node without modelling rule", node.browseName.toString());
713
- continue;
714
- }
715
- // ignore also methods
716
- if (node.nodeClass === node_opcua_data_model_1.NodeClass.Method) {
717
- // xx console.log(" skipping method ", node.browseName.toString());
718
- continue;
719
- }
720
- _process_var(self, "", node);
721
- // also store value in index
722
- // xx eventData.__nodes[node.nodeId.toString()] = eventData[lowerName];
723
- const children2 = node.getAggregates();
724
- if (children2.length > 0) {
725
- const lowerName = (0, node_opcua_utils_1.lowerFirstLetter)(node.browseName.name);
726
- // console.log(" Children to visit = ",lowerName,
727
- // children.map(function(a){ return a.browseName.toString();}).join(" "));
728
- for (const child2 of children2) {
729
- _process_var(self, lowerName + ".", child2);
730
- }
731
- }
732
- }
733
- };
734
- const eventData = new event_data_1.EventData(eventTypeNode);
735
- // verify standard properties...
736
- populate_data(eventTypeNode, eventData);
737
- verify_data_is_valid(data);
738
- return eventData;
739
- }
740
- // - Browse --------------------------------------------------------------------------------------------------------
741
- /**
742
- * browse some path.
743
- *
744
- * @method browsePath
745
- * @param {BrowsePath} browsePath
746
- * @return {BrowsePathResult}
747
- *
748
- * This service can be used translates one or more browse paths into NodeIds.
749
- * A browse path is constructed of a starting Node and a RelativePath. The specified starting Node
750
- * identifies the Node from which the RelativePath is based. The RelativePath contains a sequence of
751
- * ReferenceTypes and BrowseNames.
752
- *
753
- * |StatusCode | |
754
- * |------------------------------|:-----------------------------------------------------------|
755
- * |BadNodeIdUnknown | |
756
- * |BadNodeIdInvalid | |
757
- * |BadNothingToDo | - the relative path contains an empty list ) |
758
- * |BadBrowseNameInvalid | - target name is missing in relative path |
759
- * |UncertainReferenceOutOfServer | - The path element has targets which are in another server.|
760
- * |BadTooManyMatches | |
761
- * |BadQueryTooComplex | |
762
- * |BadNoMatch | |
763
- *
764
- *
765
- *
766
- */
767
- browsePath(browsePath) {
768
- (0, node_opcua_assert_1.assert)(browsePath instanceof node_opcua_types_1.BrowsePath);
769
- const startingNode = this.findNode(browsePath.startingNode);
770
- if (!startingNode) {
771
- return new node_opcua_types_1.BrowsePathResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadNodeIdUnknown });
772
- }
773
- if (!browsePath.relativePath.elements || browsePath.relativePath.elements.length === 0) {
774
- return new node_opcua_types_1.BrowsePathResult({
775
- statusCode: node_opcua_status_code_1.StatusCodes.BadNothingToDo,
776
- targets: []
777
- });
778
- }
779
- const elements_length = browsePath.relativePath.elements.length;
780
- // -------------------------------------------------------------------------------------------------------
781
- // verify standard RelativePath construction
782
- // from OPCUA 1.03 - PArt 3 - 7.6 RelativePath:
783
- // TargetName The BrowseName of the target node.
784
- // The final element may have an empty targetName. In this situation all targets of the
785
- // references identified by the referenceTypeId are the targets of the RelativePath.
786
- // The targetName shall be specified for all other elements.
787
- // The current path cannot be followed any further if no targets with the specified
788
- // BrowseName exist.
789
- // Let's detect null targetName which are not in last position and return BadBrowseNameInvalid if not
790
- //
791
- const empty_targetName_not_in_lastPos = browsePath.relativePath.elements.reduce((prev, e, index) => {
792
- const is_last = index + 1 === elements_length;
793
- const isBad = !is_last && (!e.targetName || e.targetName.isEmpty());
794
- return prev + (!is_last && (!e.targetName || e.targetName.isEmpty()) ? 1 : 0);
795
- }, 0);
796
- if (empty_targetName_not_in_lastPos) {
797
- return new node_opcua_types_1.BrowsePathResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadBrowseNameInvalid });
798
- }
799
- // from OPCUA 1.03 - PArt 3 - 5.8.4 TranslateBrowsePathToNodeIds
800
- // TranslateBrowsePathToNodeIds further restrict RelativePath targetName rules:
801
- // The last element in the relativePath shall always have a targetName specified.
802
- const last_el = browsePath.relativePath.elements[elements_length - 1];
803
- if (!last_el.targetName || !last_el.targetName.name || last_el.targetName.name.length === 0) {
804
- return new node_opcua_types_1.BrowsePathResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadBrowseNameInvalid });
805
- }
806
- const res = [];
807
- const explore_element = (curNodeObject, elements, index) => {
808
- const element = elements[index];
809
- (0, node_opcua_assert_1.assert)(element instanceof node_opcua_types_1.RelativePathElement);
810
- const is_last = index + 1 === elements.length;
811
- const nodeIds = curNodeObject.browseNodeByTargetName(element, is_last);
812
- const targets = nodeIds.map((nodeId) => {
813
- return {
814
- remainingPathIndex: elements.length - index,
815
- targetId: nodeId
816
- };
817
- });
818
- if (!is_last) {
819
- // explorer
820
- for (const target of targets) {
821
- const node = this.findNode(target.targetId);
822
- if (!node) {
823
- continue;
824
- }
825
- explore_element(node, elements, index + 1);
826
- }
827
- }
828
- else {
829
- for (const target of targets) {
830
- res.push({
831
- remainingPathIndex: 0xffffffff,
832
- targetId: (0, node_opcua_nodeid_1.coerceExpandedNodeId)(target.targetId)
833
- });
834
- }
835
- }
836
- };
837
- explore_element(startingNode, browsePath.relativePath.elements, 0);
838
- if (res.length === 0) {
839
- return new node_opcua_types_1.BrowsePathResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadNoMatch });
840
- }
841
- return new node_opcua_types_1.BrowsePathResult({
842
- statusCode: node_opcua_status_code_1.StatusCodes.Good,
843
- targets: res
844
- });
845
- }
846
- // - Extension Object ----------------------------------------------------------------------------------------------
847
- getExtensionObjectConstructor(dataType) {
848
- (0, node_opcua_assert_1.assert)(dataType, "expecting a dataType");
849
- if (dataType instanceof node_opcua_nodeid_1.NodeId) {
850
- const tmp = this.findNode(dataType);
851
- /* istanbul ignore next */
852
- if (!tmp) {
853
- throw new Error("getExtensionObjectConstructor: cannot resolve dataType " + dataType);
854
- }
855
- dataType = tmp;
856
- }
857
- /* istanbul ignore next */
858
- if (!(dataType instanceof ua_data_type_impl_1.UADataTypeImpl)) {
859
- // may be dataType was the NodeId of the "Binary Encoding" node
860
- throw new Error("getExtensionObjectConstructor: dataType has unexpected type" + dataType);
861
- }
862
- const _dataType = dataType;
863
- // to do verify that dataType is of type "Structure"
864
- /* istanbul ignore next */
865
- if (!_dataType.isSupertypeOf(this.findDataType("Structure"))) {
866
- console.log(_dataType.toString());
867
- }
868
- (0, node_opcua_assert_1.assert)(_dataType.isSupertypeOf(this.findDataType("Structure")));
869
- if (!_dataType._extensionObjectConstructor) {
870
- const dataTypeManager = this.$$extraDataTypeManager;
871
- _dataType._extensionObjectConstructor = dataTypeManager.getExtensionObjectConstructorFromDataType(_dataType.nodeId);
872
- }
873
- (0, node_opcua_assert_1.assert)(_dataType._extensionObjectConstructor, "dataType must have a constructor");
874
- const Constructor = _dataType._extensionObjectConstructor;
875
- return Constructor;
876
- }
877
- /**
878
- * @param dataType
879
- * @param [options]
880
- * @return the constructed extension object
881
- *
882
- *
883
- * @example
884
- *
885
- * // example 1
886
- * var extObj = addressSpace.constructExtensionObject("BuildInfo",{ productName: "PRODUCT_NAME"});
887
- *
888
- * // example 2
889
- * serverStatusDataType.nodeClass.should.eql(NodeClass.DataType);
890
- * serverStatusDataType.browseName.toString().should.eql("ServerStatusDataType");
891
- * var serverStatus = addressSpace.constructExtensionObject(serverStatusDataType);
892
- * serverStatus.constructor.name.should.eql("ServerStatusDataType");
893
- */
894
- constructExtensionObject(dataType, options) {
895
- const Constructor = this.getExtensionObjectConstructor(dataType);
896
- return new Constructor(options);
897
- }
898
- /**
899
- * cleanup all resources maintained by this addressSpace.
900
- * @method dispose
901
- */
902
- dispose() {
903
- this._namespaceArray.map((namespace) => namespace.dispose());
904
- AddressSpace.registry.unregister(this);
905
- /* istanbul ignore next */
906
- if (this._shutdownTask && this._shutdownTask.length > 0) {
907
- throw new Error("AddressSpace#dispose : shutdown has not been called");
908
- }
909
- }
910
- /**
911
- * register a function that will be called when the server will perform its shut down.
912
- * @method registerShutdownTask
913
- */
914
- registerShutdownTask(task) {
915
- this._shutdownTask = this._shutdownTask || [];
916
- (0, node_opcua_assert_1.assert)(typeof task === "function");
917
- this._shutdownTask.push(task);
918
- }
919
- shutdown() {
920
- return __awaiter(this, void 0, void 0, function* () {
921
- if (!this._shutdownTask) {
922
- return;
923
- }
924
- const tasks = this._shutdownTask;
925
- this._shutdownTask = [];
926
- // perform registerShutdownTask
927
- for (const task of tasks) {
928
- yield task.call(this);
929
- }
930
- });
931
- }
932
- /**
933
- *
934
- * @method browseSingleNode
935
- * @param nodeId {NodeId|String} : the nodeid of the element to browse
936
- * @param browseDescription
937
- * @param browseDescription.browseDirection {BrowseDirection} :
938
- * @param browseDescription.referenceTypeId {String|NodeId}
939
- * @param [session]
940
- * @return {BrowseResult}
941
- */
942
- browseSingleNode(nodeId, browseDescription, context) {
943
- const browseResult = {
944
- continuationPoint: undefined,
945
- references: null,
946
- statusCode: node_opcua_status_code_1.StatusCodes.Good
947
- };
948
- if (!browseDescription || browseDescription.browseDirection === node_opcua_data_model_1.BrowseDirection.Invalid) {
949
- browseResult.statusCode = node_opcua_status_code_1.StatusCodes.BadBrowseDirectionInvalid;
950
- return new node_opcua_service_browse_1.BrowseResult(browseResult);
951
- }
952
- browseDescription.browseDirection = (0, adjust_browse_direction_1.adjustBrowseDirection)(browseDescription.browseDirection, node_opcua_data_model_1.BrowseDirection.Forward);
953
- /* istanbul ignore next */
954
- if (typeof nodeId === "number") {
955
- throw new Error("Not Implemented");
956
- }
957
- if (typeof nodeId === "string") {
958
- const node = this.findNode(this.resolveNodeId(nodeId));
959
- if (node) {
960
- nodeId = node.nodeId;
961
- }
962
- }
963
- // check if referenceTypeId is correct
964
- if (browseDescription.referenceTypeId instanceof node_opcua_nodeid_1.NodeId) {
965
- if (browseDescription.referenceTypeId.value === 0) {
966
- browseDescription.referenceTypeId = null;
967
- }
968
- else {
969
- const rf = this.findNode(browseDescription.referenceTypeId);
970
- if (!rf || !(rf instanceof ua_reference_type_impl_1.UAReferenceTypeImpl)) {
971
- browseResult.statusCode = node_opcua_status_code_1.StatusCodes.BadReferenceTypeIdInvalid;
972
- return new node_opcua_service_browse_1.BrowseResult(browseResult);
973
- }
974
- }
975
- }
976
- const obj = this.findNode(nodeId);
977
- if (!obj) {
978
- // Object Not Found
979
- browseResult.statusCode = node_opcua_status_code_1.StatusCodes.BadNodeIdUnknown;
980
- // xx console.log("xxxxxx browsing ",nodeId.toString() , " not found" );
981
- }
982
- else {
983
- browseResult.statusCode = node_opcua_status_code_1.StatusCodes.Good;
984
- browseResult.references = obj.browseNode(browseDescription, context);
985
- }
986
- return new node_opcua_service_browse_1.BrowseResult(browseResult);
987
- }
988
- /**
989
- * @param folder
990
- * @private
991
- */
992
- _coerceFolder(folder) {
993
- folder = this._coerceNode(folder);
994
- /* istanbul ignore next */
995
- if (folder && !_isFolder(this, folder)) {
996
- throw new Error("Parent folder must be of FolderType " + folder.typeDefinition.toString());
997
- }
998
- return folder;
999
- }
1000
- /**
1001
- *
1002
- * @param view
1003
- * @param modelChange
1004
- * @private
1005
- */
1006
- _collectModelChange(view, modelChange) {
1007
- // xx console.log("in _collectModelChange", modelChange.verb, verbFlags.get(modelChange.verb).toString());
1008
- this._modelChanges.push(modelChange);
1009
- }
1010
- /**
1011
- *
1012
- * walk up the hierarchy of objects until a view is found
1013
- * objects may belong to multiples views.
1014
- * Note: this method doesn't return the main view => Server object.
1015
- * @method extractRootViews
1016
- * @param node {BaseNode}
1017
- * @return {BaseNode[]}
1018
- */
1019
- /**
1020
- *
1021
- * @param node
1022
- * @private
1023
- */
1024
- extractRootViews(node) {
1025
- (0, node_opcua_assert_1.assert)(node.nodeClass === node_opcua_data_model_1.NodeClass.Object || node.nodeClass === node_opcua_data_model_1.NodeClass.Variable);
1026
- const visitedMap = {};
1027
- const q = new Dequeue();
1028
- q.push(node);
1029
- const objectsFolder = this.rootFolder.objects;
1030
- (0, node_opcua_assert_1.assert)(objectsFolder instanceof ua_object_impl_1.UAObjectImpl);
1031
- const results = [];
1032
- while (q.length) {
1033
- node = q.shift();
1034
- const references = node.findReferencesEx("HierarchicalReferences", node_opcua_data_model_1.BrowseDirection.Inverse);
1035
- const parentNodes = references.map((r) => reference_impl_1.ReferenceImpl.resolveReferenceNode(this, r));
1036
- for (const parent of parentNodes) {
1037
- if ((0, node_opcua_nodeid_1.sameNodeId)(parent.nodeId, objectsFolder.nodeId)) {
1038
- continue; // nothing to do
1039
- }
1040
- if (parent.nodeClass === node_opcua_data_model_1.NodeClass.View) {
1041
- results.push(parent);
1042
- }
1043
- else {
1044
- const key = parent.nodeId.toString();
1045
- if (Object.prototype.hasOwnProperty.call(visitedMap, key)) {
1046
- continue;
1047
- }
1048
- visitedMap[key] = parent;
1049
- q.push(parent);
1050
- }
1051
- }
1052
- }
1053
- return results;
1054
- }
1055
- /**
1056
- *
1057
- * @param func
1058
- * @private
1059
- */
1060
- modelChangeTransaction(func) {
1061
- this._modelChangeTransactionCounter = this._modelChangeTransactionCounter || 0;
1062
- function beginModelChange() {
1063
- /* jshint validthis:true */
1064
- (0, node_opcua_assert_1.assert)(this);
1065
- this._modelChanges = this._modelChanges || [];
1066
- (0, node_opcua_assert_1.assert)(this._modelChangeTransactionCounter >= 0);
1067
- this._modelChangeTransactionCounter += 1;
1068
- }
1069
- function endModelChange() {
1070
- /* jshint validthis:true */
1071
- this._modelChangeTransactionCounter -= 1;
1072
- if (this._modelChangeTransactionCounter === 0) {
1073
- if (this._modelChanges.length === 0) {
1074
- return; // nothing to do
1075
- }
1076
- // xx console.log( "xx dealing with ",this._modelChanges.length);
1077
- // increase version number of participating nodes
1078
- // https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore
1079
- // const nodeIds = _.uniq(this._modelChanges.map((c: any) => c.affected));
1080
- const nodeIds = [...new Set(this._modelChanges.map((c) => c.affected))];
1081
- const nodes = nodeIds.map((nodeId) => this.findNode(nodeId));
1082
- nodes.forEach(_increase_version_number);
1083
- // raise events
1084
- if (this.rootFolder.objects.server) {
1085
- const eventTypeNode = this.findEventType("GeneralModelChangeEventType");
1086
- if (eventTypeNode) {
1087
- // xx console.log("xx raising event on server object");
1088
- this.rootFolder.objects.server.raiseEvent(eventTypeNode, {
1089
- // Part 5 - 6.4.32 GeneralModelChangeEventType
1090
- changes: {
1091
- dataType: node_opcua_variant_1.DataType.ExtensionObject,
1092
- arrayType: node_opcua_variant_1.VariantArrayType.Array,
1093
- value: this._modelChanges
1094
- }
1095
- });
1096
- }
1097
- }
1098
- this._modelChanges = [];
1099
- // _notifyModelChange(this);
1100
- }
1101
- }
1102
- beginModelChange.call(this);
1103
- try {
1104
- func();
1105
- }
1106
- catch (err) {
1107
- errorLog("modelChangeTransaction", err === null || err === void 0 ? void 0 : err.message);
1108
- throw err;
1109
- }
1110
- finally {
1111
- endModelChange.call(this);
1112
- }
1113
- }
1114
- /**
1115
- * normalize the ReferenceType field of the Reference Object
1116
- * @param params.referenceType {String|nodeId}
1117
- * @param params.isForward {Boolean} default value: true;
1118
- * @return {Object} a new reference object with the normalized name { referenceType: <value>, isForward: <flag>}
1119
- */
1120
- normalizeReferenceType(params) {
1121
- if (params instanceof reference_impl_1.ReferenceImpl) {
1122
- // a reference has already been normalized
1123
- return params;
1124
- }
1125
- // ----------------------------------------------- handle is forward
1126
- (0, node_opcua_assert_1.assert)(params.isForward === undefined || typeof params.isForward === "boolean");
1127
- params.isForward = utils.isNullOrUndefined(params.isForward) ? true : !!params.isForward;
1128
- // referenceType = Organizes , isForward = true => referenceType = Organizes , isForward = true
1129
- // referenceType = Organizes , isForward = false => referenceType = Organizes , isForward = false
1130
- // referenceType = OrganizedBy , isForward = true => referenceType = Organizes , isForward = **false**
1131
- // referenceType = OrganizedBy , isForward = false => referenceType = Organizes , isForward = **true**
1132
- // ----------------------------------------------- handle referenceType
1133
- if (params.referenceType instanceof ua_reference_type_impl_1.UAReferenceTypeImpl) {
1134
- params.referenceType = params.referenceType;
1135
- params.referenceType = params.referenceType.nodeId;
1136
- }
1137
- else if (typeof params.referenceType === "string") {
1138
- const inv = this.findReferenceTypeFromInverseName(params.referenceType);
1139
- if (inv) {
1140
- params.referenceType = inv.nodeId;
1141
- params._referenceType = inv;
1142
- params.isForward = !params.isForward;
1143
- }
1144
- else {
1145
- params.referenceType = (0, node_opcua_nodeid_1.resolveNodeId)(params.referenceType);
1146
- const refType = this.findReferenceType(params.referenceType);
1147
- if (refType) {
1148
- params._referenceType = refType;
1149
- }
1150
- }
1151
- }
1152
- (0, node_opcua_assert_1.assert)(params.referenceType instanceof node_opcua_nodeid_1.NodeId);
1153
- // ----------- now resolve target NodeId;
1154
- if (params.nodeId instanceof base_node_impl_1.BaseNodeImpl) {
1155
- (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(params, "node"));
1156
- params.node = params.nodeId;
1157
- params.nodeId = params.node.nodeId;
1158
- }
1159
- else {
1160
- let _nodeId = params.nodeId;
1161
- (0, node_opcua_assert_1.assert)(!!_nodeId, "missing 'nodeId' in reference");
1162
- if (_nodeId && _nodeId.nodeId) {
1163
- _nodeId = _nodeId.nodeId;
1164
- }
1165
- _nodeId = (0, node_opcua_nodeid_1.resolveNodeId)(_nodeId);
1166
- /* istanbul ignore next */
1167
- if (!(_nodeId instanceof node_opcua_nodeid_1.NodeId) || _nodeId.isEmpty()) {
1168
- // tslint:disable:no-console
1169
- console.log("xx =>", JSON.stringify(params, null, " "));
1170
- throw new Error(" Invalid reference nodeId " + _nodeId.toString());
1171
- }
1172
- params.nodeId = _nodeId;
1173
- }
1174
- return new reference_impl_1.ReferenceImpl(params);
1175
- }
1176
- /**
1177
- *
1178
- * @param references
1179
- */
1180
- normalizeReferenceTypes(references) {
1181
- if (!references || references.length === 0) {
1182
- return [];
1183
- }
1184
- references = references;
1185
- (0, node_opcua_assert_1.assert)(Array.isArray(references));
1186
- return references.map((el) => this.normalizeReferenceType(el));
1187
- }
1188
- // -- Historical Node -----------------------------------------------------------------------------------------
1189
- /**
1190
- *
1191
- * @param node
1192
- * @param options
1193
- */
1194
- installHistoricalDataNode(node, options) {
1195
- address_space_historical_data_node_1.AddressSpace_installHistoricalDataNode.call(this, node, options);
1196
- }
1197
- // -- Alarms & Conditions -----------------------------------------------------------------------------------------
1198
- /**
1199
- *
1200
- */
1201
- installAlarmsAndConditionsService() {
1202
- alarms_and_conditions_1.UAConditionImpl.install_condition_refresh_handle(this);
1203
- alarms_and_conditions_1.UAAcknowledgeableConditionImpl.install_method_handle_on_type(this);
1204
- }
1205
- // -- internal stuff -----------------------------------------------------------------------------------------------
1206
- _coerceNode(node) {
1207
- function hasTypeDefinition(node1) {
1208
- return (node1.nodeClass === node_opcua_data_model_1.NodeClass.Variable ||
1209
- node1.nodeClass === node_opcua_data_model_1.NodeClass.Object ||
1210
- node1.nodeClass === node_opcua_data_model_1.NodeClass.Method);
1211
- }
1212
- // coerce to BaseNode object
1213
- if (node instanceof base_node_impl_1.BaseNodeImpl) {
1214
- return node;
1215
- }
1216
- // it's a node id like
1217
- // coerce parent folder to an object
1218
- const returnValue = this.findNode((0, node_opcua_nodeid_1.resolveNodeId)(node));
1219
- /*
1220
- if (!hasTypeDefinition(node as BaseNode)) {
1221
- node = this.findNode(node.nodeId) || node;
1222
- if (!node || !hasTypeDefinition(node)) {
1223
- return null;
1224
- }
1225
- }
1226
- */
1227
- return returnValue;
1228
- }
1229
- _coerce_DataType(dataType) {
1230
- if (dataType instanceof node_opcua_nodeid_1.NodeId) {
1231
- // xx assert(self.findDataType(dataType));
1232
- return dataType;
1233
- }
1234
- return this._coerce_Type(dataType, node_opcua_constants_1.DataTypeIds, "DataTypeIds", AddressSpace.prototype.findDataType);
1235
- }
1236
- _coerceTypeDefinition(typeDefinition) {
1237
- if (typeof typeDefinition === "string") {
1238
- // coerce parent folder to an node
1239
- const typeDefinitionNode = this.findNode(typeDefinition);
1240
- typeDefinition = typeDefinitionNode.nodeId;
1241
- }
1242
- // xx console.log("typeDefinition = ",typeDefinition);
1243
- (0, node_opcua_assert_1.assert)(typeDefinition instanceof node_opcua_nodeid_1.NodeId);
1244
- return typeDefinition;
1245
- }
1246
- _coerceType(baseType, topMostBaseType, nodeClass) {
1247
- (0, node_opcua_assert_1.assert)(typeof topMostBaseType === "string");
1248
- const topMostBaseTypeNode = this.findNode(topMostBaseType);
1249
- /* istanbul ignore next */
1250
- if (!topMostBaseTypeNode) {
1251
- throw new Error("Cannot find topMostBaseTypeNode " + topMostBaseType.toString());
1252
- }
1253
- (0, node_opcua_assert_1.assert)(topMostBaseTypeNode instanceof base_node_impl_1.BaseNodeImpl);
1254
- (0, node_opcua_assert_1.assert)(topMostBaseTypeNode.nodeClass === nodeClass);
1255
- if (!baseType) {
1256
- return topMostBaseTypeNode;
1257
- }
1258
- (0, node_opcua_assert_1.assert)(typeof baseType === "string" || baseType instanceof base_node_impl_1.BaseNodeImpl);
1259
- let baseTypeNode;
1260
- if (baseType instanceof base_node_impl_1.BaseNodeImpl) {
1261
- baseTypeNode = baseType;
1262
- }
1263
- else {
1264
- baseTypeNode = this.findNode(baseType);
1265
- }
1266
- /* istanbul ignore next*/
1267
- if (!baseTypeNode) {
1268
- throw new Error("Cannot find ObjectType or VariableType for " + baseType.toString());
1269
- }
1270
- /* istanbul ignore next */
1271
- if (!baseTypeNode.isSupertypeOf) {
1272
- throw new Error("Cannot find ObjectType or VariableType for " + baseType.toString());
1273
- }
1274
- /* istanbul ignore next */
1275
- if (!baseTypeNode.isSupertypeOf(topMostBaseTypeNode)) {
1276
- throw new Error("wrong type ");
1277
- }
1278
- return baseTypeNode;
1279
- }
1280
- _coerce_VariableTypeIds(dataType) {
1281
- return this._coerce_Type(dataType, node_opcua_constants_1.VariableTypeIds, "VariableTypeIds", AddressSpace.prototype.findVariableType);
1282
- }
1283
- _register(node) {
1284
- (0, node_opcua_assert_1.assert)(node.nodeId instanceof node_opcua_nodeid_1.NodeId);
1285
- const namespace = this.getNamespace(node.nodeId.namespace);
1286
- namespace._register(node);
1287
- }
1288
- deleteNode(nodeOrNodeId) {
1289
- _getNamespace(this, nodeOrNodeId).deleteNode(nodeOrNodeId);
1290
- }
1291
- isEnumeration(dataType) {
1292
- // DataType must be one of Enumeration
1293
- const dataTypeNode = this.findDataType(dataType);
1294
- if (!dataTypeNode) {
1295
- throw new Error(" Cannot find DataType " + dataType.toString() + " in standard address Space");
1296
- }
1297
- const enumerationNode = this.findDataType("Enumeration");
1298
- if (!enumerationNode) {
1299
- throw new Error(" Cannot find 'Enumeration' DataType in standard address Space");
1300
- }
1301
- return dataTypeNode.isSupertypeOf(enumerationNode);
1302
- }
1303
- _coerce_Type(dataType, typeMap, typeMapName, finderMethod) {
1304
- if (dataType instanceof base_node_impl_1.BaseNodeImpl) {
1305
- dataType = dataType.nodeId;
1306
- }
1307
- (0, node_opcua_assert_1.assert)(typeMap !== null && typeof typeMap === "object");
1308
- let nodeId;
1309
- if (typeof dataType === "string") {
1310
- const namespace0 = this.getDefaultNamespace();
1311
- // resolve dataType
1312
- nodeId = namespace0.resolveAlias(dataType);
1313
- if (!nodeId) {
1314
- // dataType was not found in the aliases database
1315
- if (typeMap[dataType]) {
1316
- nodeId = (0, node_opcua_nodeid_1.makeNodeId)(typeMap[dataType], 0);
1317
- return nodeId;
1318
- }
1319
- else {
1320
- nodeId = (0, node_opcua_nodeid_1.resolveNodeId)(dataType);
1321
- }
1322
- }
1323
- }
1324
- else if (typeof dataType === "number") {
1325
- nodeId = (0, node_opcua_nodeid_1.makeNodeId)(dataType, 0);
1326
- }
1327
- else {
1328
- nodeId = (0, node_opcua_nodeid_1.resolveNodeId)(dataType);
1329
- }
1330
- /* istanbul ignore next */
1331
- if (nodeId == null || !(nodeId instanceof node_opcua_nodeid_1.NodeId)) {
1332
- throw new Error("Expecting valid nodeId ");
1333
- }
1334
- const el = finderMethod.call(this, nodeId);
1335
- if (!el) {
1336
- // verify that node Id exists in standard type map typeMap
1337
- const find = Object.values(typeMap).filter((a) => a === nodeId.value);
1338
- /* istanbul ignore next */
1339
- if (find.length !== 1) {
1340
- throw new Error(" cannot find " + dataType.toString() + " in typeMap " + typeMapName + " L = " + find.length);
1341
- }
1342
- }
1343
- return nodeId;
1344
- }
1345
- _findReferenceType(refType, namespaceIndex) {
1346
- if (refType instanceof node_opcua_nodeid_1.NodeId) {
1347
- return _find_by_node_id(this, refType, namespaceIndex);
1348
- }
1349
- const [namespace, browseName] = _extract_namespace_and_browse_name_as_string(this, refType, namespaceIndex);
1350
- return namespace.findReferenceType(browseName);
1351
- }
1352
- }
1353
- exports.AddressSpace = AddressSpace;
1354
- AddressSpace.isNonEmptyQualifiedName = namespace_impl_2.isNonEmptyQualifiedName;
1355
- AddressSpace.registry = new node_opcua_object_registry_1.ObjectRegistry();
1356
- function _getNamespace(addressSpace, nodeOrNodId) {
1357
- const nodeId = nodeOrNodId instanceof base_node_impl_1.BaseNodeImpl ? nodeOrNodId.nodeId : nodeOrNodId;
1358
- return addressSpace.getNamespace(nodeId.namespace);
1359
- }
1360
- function _find_by_node_id(addressSpace, nodeId, namespaceIndex) {
1361
- const obj = addressSpace.findNode(nodeId);
1362
- return obj;
1363
- }
1364
- /**
1365
- * return true if nodeId is a UAFolder
1366
- * @method _isFolder
1367
- * @param addressSpace
1368
- * @param folder
1369
- * @return {Boolean}
1370
- * @private
1371
- */
1372
- function _isFolder(addressSpace, folder) {
1373
- const folderType = addressSpace.findObjectType("FolderType");
1374
- (0, node_opcua_assert_1.assert)(folder instanceof base_node_impl_1.BaseNodeImpl);
1375
- (0, node_opcua_assert_1.assert)(folder.typeDefinitionObj);
1376
- return folder.typeDefinitionObj.isSupertypeOf(folderType);
1377
- }
1378
- function _increase_version_number(node) {
1379
- if (node && node.nodeVersion) {
1380
- const previousValue = parseInt(node.nodeVersion.readValue().value.value, 10);
1381
- node.nodeVersion.setValueFromSource({
1382
- dataType: node_opcua_variant_1.DataType.String,
1383
- value: (previousValue + 1).toString()
1384
- });
1385
- // xx console.log("xxx increasing version number of node ", node.browseName.toString(),previousValue);
1386
- }
1387
- }
1
+ "use strict";
2
+ /**
3
+ * @module node-opcua-address-space
4
+ */
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.AddressSpace = void 0;
16
+ const crypto_1 = require("crypto");
17
+ const chalk = require("chalk");
18
+ const node_opcua_assert_1 = require("node-opcua-assert");
19
+ const node_opcua_constants_1 = require("node-opcua-constants");
20
+ const node_opcua_data_model_1 = require("node-opcua-data-model");
21
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
22
+ const node_opcua_object_registry_1 = require("node-opcua-object-registry");
23
+ const node_opcua_service_browse_1 = require("node-opcua-service-browse");
24
+ const node_opcua_status_code_1 = require("node-opcua-status-code");
25
+ const node_opcua_types_1 = require("node-opcua-types");
26
+ const utils = require("node-opcua-utils");
27
+ const node_opcua_utils_1 = require("node-opcua-utils");
28
+ const node_opcua_variant_1 = require("node-opcua-variant");
29
+ const node_opcua_debug_1 = require("node-opcua-debug");
30
+ const adjust_browse_direction_1 = require("../source/helpers/adjust_browse_direction");
31
+ const alarms_and_conditions_1 = require("./alarms_and_conditions");
32
+ const event_data_1 = require("./event_data");
33
+ const address_space_historical_data_node_1 = require("./historical_access/address_space_historical_data_node");
34
+ const namespace_impl_1 = require("./namespace_impl");
35
+ const namespace_impl_2 = require("./namespace_impl");
36
+ const ua_data_type_impl_1 = require("./ua_data_type_impl");
37
+ const ua_object_type_impl_1 = require("./ua_object_type_impl");
38
+ const ua_object_impl_1 = require("./ua_object_impl");
39
+ const reference_impl_1 = require("./reference_impl");
40
+ const ua_reference_type_impl_1 = require("./ua_reference_type_impl");
41
+ const base_node_impl_1 = require("./base_node_impl");
42
+ const doDebug = false;
43
+ const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
44
+ // tslint:disable-next-line:no-var-requires
45
+ const Dequeue = require("dequeue");
46
+ const regexNumberColumnString = /^([0-9]+):(.*)/;
47
+ const enumerationTypeNodeId = (0, node_opcua_nodeid_1.coerceNodeId)(node_opcua_constants_1.DataTypeIds.Enumeration);
48
+ function _extract_namespace_and_browse_name_as_string(addressSpace, browseName, namespaceIndex) {
49
+ (0, node_opcua_assert_1.assert)(!namespaceIndex || namespaceIndex >= 0);
50
+ let result;
51
+ if (namespaceIndex !== undefined && namespaceIndex > 0) {
52
+ (0, node_opcua_assert_1.assert)(typeof browseName === "string", "expecting a string when namespaceIndex is specified");
53
+ result = [addressSpace.getNamespace(namespaceIndex), browseName];
54
+ }
55
+ else if (typeof browseName === "string") {
56
+ // split
57
+ if (browseName.indexOf(":") >= 0) {
58
+ const a = browseName.split(":");
59
+ namespaceIndex = a.length === 2 ? parseInt(a[0], 10) : namespaceIndex;
60
+ browseName = a.length === 2 ? a[1] : browseName;
61
+ }
62
+ result = [addressSpace.getNamespace(namespaceIndex || 0), browseName];
63
+ }
64
+ else if (browseName instanceof node_opcua_data_model_1.QualifiedName) {
65
+ namespaceIndex = browseName.namespaceIndex;
66
+ result = [addressSpace.getNamespace(namespaceIndex), browseName.name];
67
+ }
68
+ else if (typeof browseName === "number") {
69
+ result = [addressSpace.getDefaultNamespace(), node_opcua_variant_1.DataType[browseName]];
70
+ }
71
+ /* istanbul ignore next */
72
+ if (!result || !result[0]) {
73
+ throw new Error(` Cannot find namespace associated with ${browseName} ${namespaceIndex}`);
74
+ }
75
+ return result;
76
+ }
77
+ /**
78
+ * returns true if str matches a nodeID, e.g i=123 or ns=...
79
+ * @method isNodeIdString
80
+ * @param str
81
+ * @type {boolean}
82
+ */
83
+ function isNodeIdString(str) {
84
+ if (typeof str !== "string") {
85
+ return false;
86
+ }
87
+ return str.substring(0, 2) === "i=" || str.substring(0, 3) === "ns=";
88
+ }
89
+ /**
90
+ * `AddressSpace` is a collection of UA nodes.
91
+ *
92
+ * const addressSpace = AddressSpace.create();
93
+ */
94
+ class AddressSpace {
95
+ constructor() {
96
+ /***
97
+ * @internal
98
+ * @private
99
+ */
100
+ this.suspendBackReference = false;
101
+ this.isFrugal = false;
102
+ this.historizingNodes = {};
103
+ this._condition_refresh_in_progress = false;
104
+ this.isNodeIdString = isNodeIdString;
105
+ this._shutdownTask = [];
106
+ this._modelChangeTransactionCounter = 0;
107
+ this._modelChanges = [];
108
+ this._private_namespaceIndex = 1;
109
+ this._namespaceArray = [];
110
+ // special namespace 0 is reserved for the UA namespace
111
+ this.registerNamespace("http://opcfoundation.org/UA/");
112
+ AddressSpace.registry.register(this);
113
+ }
114
+ get rootFolder() {
115
+ const rootFolder = this.findNode(this.resolveNodeId("RootFolder"));
116
+ if (!rootFolder) {
117
+ // throw new Error("AddressSpace doesn't contain rootFolder object");
118
+ return null;
119
+ }
120
+ return rootFolder;
121
+ }
122
+ static create() {
123
+ return new AddressSpace();
124
+ }
125
+ /**
126
+ * @internal
127
+ */
128
+ getDataTypeManager() {
129
+ const addressSpacePriv = this;
130
+ (0, node_opcua_assert_1.assert)(addressSpacePriv.$$extraDataTypeManager, "expecting a $$extraDataTypeManager please make sure ensureDatatypeExtracted is called");
131
+ return addressSpacePriv.$$extraDataTypeManager;
132
+ }
133
+ getNamespaceUri(namespaceIndex) {
134
+ (0, node_opcua_assert_1.assert)(namespaceIndex >= 0 && namespaceIndex < this._namespaceArray.length);
135
+ return this._namespaceArray[namespaceIndex].namespaceUri;
136
+ }
137
+ /***
138
+ * @method getNamespace
139
+ * @param {string|number} namespace index or namespace uri.
140
+ * @return {NameSpace} the namespace
141
+ */
142
+ getNamespace(namespaceIndexOrName) {
143
+ if (typeof namespaceIndexOrName === "number") {
144
+ const namespaceIndex = namespaceIndexOrName;
145
+ (0, node_opcua_assert_1.assert)(namespaceIndex >= 0 && namespaceIndex < this._namespaceArray.length, "invalid namespace index ( out of bound)");
146
+ return this._namespaceArray[namespaceIndex];
147
+ }
148
+ else {
149
+ const namespaceUri = namespaceIndexOrName;
150
+ (0, node_opcua_assert_1.assert)(typeof namespaceUri === "string");
151
+ const index = this.getNamespaceIndex(namespaceUri);
152
+ return this._namespaceArray[index];
153
+ }
154
+ }
155
+ /***
156
+ * @method getDefaultNamespace
157
+ * @return the default namespace (standard OPCUA namespace)
158
+ */
159
+ getDefaultNamespace() {
160
+ return this.getNamespace(0);
161
+ }
162
+ /***
163
+ * @method getOwnNamespace
164
+ *
165
+ * objects instances managed by the server will be created in this namespace.
166
+ *
167
+ * @return address space own namespace
168
+ */
169
+ getOwnNamespace() {
170
+ /* istanbul ignore next */
171
+ if (this._private_namespaceIndex >= this._namespaceArray.length) {
172
+ throw new Error("please create the private namespace");
173
+ }
174
+ return this.getNamespace(this._private_namespaceIndex);
175
+ }
176
+ /**
177
+ * @method getNamespaceIndex
178
+ * @param namespaceUri
179
+ * @return the namespace index of a namespace given by its namespace uri
180
+ *
181
+ */
182
+ getNamespaceIndex(namespaceUri) {
183
+ (0, node_opcua_assert_1.assert)(typeof namespaceUri === "string");
184
+ return this._namespaceArray.findIndex((ns) => ns.namespaceUri === namespaceUri);
185
+ }
186
+ /**
187
+ * @method registerNamespace
188
+ *
189
+ * register a new namespace
190
+ *
191
+ * @param namespaceUri {string}
192
+ * @returns {Namespace}
193
+ */
194
+ registerNamespace(namespaceUri) {
195
+ let index = this._namespaceArray.findIndex((ns) => ns.namespaceUri === namespaceUri);
196
+ if (index !== -1) {
197
+ (0, node_opcua_assert_1.assert)(this._namespaceArray[index].addressSpace === this);
198
+ return this._namespaceArray[index];
199
+ }
200
+ index = this._namespaceArray.length;
201
+ this._namespaceArray.push(new namespace_impl_1.NamespaceImpl({
202
+ addressSpace: this,
203
+ index,
204
+ namespaceUri,
205
+ publicationDate: new Date(),
206
+ version: "undefined"
207
+ }));
208
+ return this._namespaceArray[index];
209
+ }
210
+ /***
211
+ * @method getNamespaceArray
212
+ * @return {Namespace[]} the namespace array
213
+ */
214
+ getNamespaceArray() {
215
+ return this._namespaceArray;
216
+ }
217
+ /**
218
+ *
219
+ * @method addAlias
220
+ * @param alias {String} the alias name
221
+ * @param nodeId {NodeId}
222
+ * @internal
223
+ */
224
+ addAlias(alias, nodeId) {
225
+ (0, node_opcua_assert_1.assert)(typeof alias === "string");
226
+ (0, node_opcua_assert_1.assert)(nodeId instanceof node_opcua_nodeid_1.NodeId);
227
+ this.getNamespace(nodeId.namespace).addAlias(alias, nodeId);
228
+ }
229
+ /**
230
+ * find an node by node Id
231
+ * @method findNode
232
+ * @param nodeId a nodeId or a string coerce-able to nodeID, representing the object to find.
233
+ * @return {BaseNode|null}
234
+ */
235
+ findNode(nodeId) {
236
+ if (!(nodeId instanceof node_opcua_nodeid_1.NodeId)) {
237
+ nodeId = this.resolveNodeId(nodeId);
238
+ }
239
+ if (nodeId.namespace < 0 || nodeId.namespace >= this._namespaceArray.length) {
240
+ // namespace index is out of bound
241
+ return null;
242
+ }
243
+ const namespace = this._namespaceArray[nodeId.namespace];
244
+ return namespace.findNode2(nodeId);
245
+ }
246
+ findMethod(nodeId) {
247
+ const node = this.findNode(nodeId);
248
+ if (!node || node.nodeClass !== node_opcua_data_model_1.NodeClass.Method) {
249
+ return null;
250
+ }
251
+ return node;
252
+ }
253
+ /**
254
+ * resolved a string or a nodeId to a nodeID
255
+ */
256
+ resolveNodeId(nodeId) {
257
+ if (typeof nodeId === "string") {
258
+ const m = nodeId.match(regexNumberColumnString);
259
+ if (m && m.length === 3) {
260
+ const namespaceIndex = parseInt(m[1], 10);
261
+ const aliasName = m[2];
262
+ const namespace = this.getNamespace(namespaceIndex);
263
+ // check if the string is a known alias
264
+ const aliasNodeId = namespace.resolveAlias(aliasName);
265
+ if (aliasNodeId !== null) {
266
+ return aliasNodeId;
267
+ }
268
+ }
269
+ }
270
+ return (0, node_opcua_nodeid_1.resolveNodeId)(nodeId);
271
+ }
272
+ /**
273
+ *
274
+ * @method findObjectType
275
+ * @param objectType {String|NodeId|QualifiedName}
276
+ * @param [namespaceIndex=0 {Number}] an optional namespace index
277
+ * @return {UAObjectType|null}
278
+ *
279
+ * @example
280
+ *
281
+ * ```javascript
282
+ * const objectType = addressSpace.findObjectType("ns=0;i=58");
283
+ * objectType.browseName.toString().should.eql("BaseObjectType");
284
+ *
285
+ * const objectType = addressSpace.findObjectType("BaseObjectType");
286
+ * objectType.browseName.toString().should.eql("BaseObjectType");
287
+ *
288
+ * const objectType = addressSpace.findObjectType(resolveNodeId("ns=0;i=58"));
289
+ * objectType.browseName.toString().should.eql("BaseObjectType");
290
+ *
291
+ * const objectType = addressSpace.findObjectType("CustomObjectType",36);
292
+ * objectType.nodeId.namespace.should.eql(36);
293
+ * objectType.browseName.toString().should.eql("BaseObjectType");
294
+ *
295
+ * const objectType = addressSpace.findObjectType("36:CustomObjectType");
296
+ * objectType.nodeId.namespace.should.eql(36);
297
+ * objectType.browseName.toString().should.eql("BaseObjectType");
298
+ * ```
299
+ */
300
+ findObjectType(objectType, namespaceIndex) {
301
+ if (objectType instanceof node_opcua_nodeid_1.NodeId) {
302
+ return _find_by_node_id(this, objectType, namespaceIndex);
303
+ }
304
+ const [namespace, browseName] = _extract_namespace_and_browse_name_as_string(this, objectType, namespaceIndex);
305
+ return namespace.findObjectType(browseName);
306
+ }
307
+ /**
308
+ * @method findVariableType
309
+ * @param variableType {String|NodeId}
310
+ * @param [namespaceIndex=0 {Number}] an optional namespace index
311
+ * @return {UAObjectType|null}
312
+ *
313
+ * @example
314
+ *
315
+ * ```javascript
316
+ * const objectType = addressSpace.findVariableType("ns=0;i=62");
317
+ * objectType.browseName.toString().should.eql("BaseVariableType");
318
+ *
319
+ * const objectType = addressSpace.findVariableType("BaseVariableType");
320
+ * objectType.browseName.toString().should.eql("BaseVariableType");
321
+ *
322
+ * const objectType = addressSpace.findVariableType(resolveNodeId("ns=0;i=62"));
323
+ * objectType.browseName.toString().should.eql("BaseVariableType");
324
+ * ```
325
+ */
326
+ findVariableType(variableType, namespaceIndex) {
327
+ if (variableType instanceof node_opcua_nodeid_1.NodeId) {
328
+ return _find_by_node_id(this, variableType, namespaceIndex);
329
+ }
330
+ const [namespace, browseName] = _extract_namespace_and_browse_name_as_string(this, variableType, namespaceIndex);
331
+ return namespace.findVariableType(browseName);
332
+ }
333
+ /**
334
+ * Find the DataType node from a NodeId or a browseName
335
+ * @method findDataType
336
+ * @param dataType {String|NodeId}
337
+ * @param [namespaceIndex=0 {Number}] an optional namespace index
338
+ * @return {DataType|null}
339
+ *
340
+ *
341
+ * @example
342
+ *
343
+ * ```javascript
344
+ * const dataDouble = addressSpace.findDataType("Double");
345
+ * const dataDouble = addressSpace.findDataType(resolveNodeId("ns=0;i=3"));
346
+ * ```
347
+ */
348
+ findDataType(dataType, namespaceIndex) {
349
+ // startingNode i=24 :
350
+ // BaseDataType
351
+ // +-> Boolean (i=1) {BooleanDataType (ns=2:9898)
352
+ // +-> String (i=12)
353
+ // +->NumericRange
354
+ // +->Time
355
+ // +-> DateTime
356
+ // +-> Structure
357
+ // +-> Node
358
+ // +-> ObjectNode
359
+ if (dataType instanceof node_opcua_nodeid_1.NodeId) {
360
+ return _find_by_node_id(this, dataType, namespaceIndex);
361
+ }
362
+ if (typeof dataType === "number") {
363
+ if (node_opcua_variant_1.DataType[dataType] !== undefined) {
364
+ dataType = node_opcua_variant_1.DataType[dataType];
365
+ }
366
+ else {
367
+ return this.findDataType((0, node_opcua_nodeid_1.resolveNodeId)(dataType));
368
+ }
369
+ }
370
+ const res = _extract_namespace_and_browse_name_as_string(this, dataType, namespaceIndex);
371
+ const namespace = res[0];
372
+ const browseName = res[1];
373
+ return namespace.findDataType(browseName);
374
+ }
375
+ /**
376
+ * @method findCorrespondingBasicDataType
377
+ *
378
+ * @example
379
+ *
380
+ * const dataType = addressSpace.findDataType("ns=0;i=12");
381
+ * addressSpace.findCorrespondingBasicDataType(dataType).should.eql(DataType.String);
382
+ *
383
+ * const dataType = addressSpace.findDataType("ServerStatusDataType"); // ServerStatus
384
+ * addressSpace.findCorrespondingBasicDataType(dataType).should.eql(DataType.ExtensionObject);
385
+ *
386
+ */
387
+ findCorrespondingBasicDataType(dataTypeNode) {
388
+ const _orig_dataTypeNode = dataTypeNode;
389
+ if (typeof dataTypeNode === "string") {
390
+ const resolvedDataType = this.resolveNodeId(dataTypeNode);
391
+ /* istanbul ignore next */
392
+ if (!resolvedDataType) {
393
+ throw new Error("Cannot resolve " + _orig_dataTypeNode.toString());
394
+ }
395
+ dataTypeNode = resolvedDataType;
396
+ }
397
+ if (dataTypeNode instanceof node_opcua_nodeid_1.NodeId) {
398
+ dataTypeNode = this.findDataType(dataTypeNode);
399
+ /* istanbul ignore next */
400
+ if (!dataTypeNode) {
401
+ throw Error("cannot find dataTypeNode " + _orig_dataTypeNode.toString());
402
+ }
403
+ }
404
+ /* istanbul ignore next */
405
+ if (!(dataTypeNode instanceof ua_data_type_impl_1.UADataTypeImpl)) {
406
+ throw new Error("we are expecting an UADataType here : " +
407
+ _orig_dataTypeNode.toString() +
408
+ " should not refer to a " +
409
+ dataTypeNode.constructor.name);
410
+ }
411
+ if ((0, node_opcua_nodeid_1.sameNodeId)(enumerationTypeNodeId, dataTypeNode.nodeId)) {
412
+ return node_opcua_variant_1.DataType.Int32;
413
+ }
414
+ if (dataTypeNode.nodeId.namespace === 0 && dataTypeNode.nodeId.value === 29) {
415
+ // Number
416
+ return node_opcua_variant_1.DataType.Null; //which one ?
417
+ }
418
+ if (dataTypeNode.nodeId.namespace === 0 && dataTypeNode.nodeId.value === 0) {
419
+ return node_opcua_variant_1.DataType.Null;
420
+ }
421
+ if (dataTypeNode.nodeId.namespace === 0 && dataTypeNode.nodeId.value <= 25) {
422
+ return dataTypeNode.nodeId.value;
423
+ }
424
+ const result = this.findCorrespondingBasicDataType(dataTypeNode.subtypeOfObj);
425
+ return result;
426
+ }
427
+ /**
428
+ * find a ReferenceType by its inverse name.
429
+ * @method findReferenceTypeFromInverseName
430
+ * @param inverseName the inverse name of the ReferenceType to find
431
+ * @deprecated
432
+ */
433
+ findReferenceTypeFromInverseName(inverseName) {
434
+ return this.getDefaultNamespace().findReferenceTypeFromInverseName(inverseName);
435
+ }
436
+ /**
437
+ * @method findReferenceType
438
+ * @param refType {String|NodeId}
439
+ * @param [namespaceIndex=0 {Number}] an optional namespace index
440
+ * @return {ReferenceType|null}
441
+ *
442
+ * refType could be
443
+ * - a string representing a nodeid : e.g. `i=9004` or ns=1;i=6030
444
+ * - a string representing a browse name : e.g `"HasTypeDefinition"`.
445
+ * In this case it should be in the alias list.
446
+ *
447
+ */
448
+ findReferenceType(refType, namespaceIndex) {
449
+ // startingNode ns=0;i=31 : References
450
+ // +-> References i=31
451
+ // +->(hasSubtype) NonHierarchicalReferences
452
+ // +->(hasSubtype) HasTypeDefinition
453
+ // +->(hasSubtype) HierarchicalReferences
454
+ // +->(hasSubtype) HasChild/ChildOf
455
+ // +->(hasSubtype) Aggregates/AggregatedBy
456
+ // +-> HasProperty/PropertyOf
457
+ // +-> HasComponent/ComponentOf
458
+ // +-> HasHistoricalConfiguration/HistoricalConfigurationOf
459
+ // +->(hasSubtype) HasSubtype/HasSupertype
460
+ // +->(hasSubtype) Organizes/OrganizedBy
461
+ // +->(hasSubtype) HasEventSource/EventSourceOf
462
+ let node;
463
+ if (isNodeIdString(refType) || typeof refType === "number") {
464
+ refType = (0, node_opcua_nodeid_1.resolveNodeId)(refType);
465
+ }
466
+ if (refType instanceof node_opcua_nodeid_1.NodeId) {
467
+ node = this.findNode(refType);
468
+ /* istanbul ignore next */
469
+ if (!(node && node.nodeClass === node_opcua_data_model_1.NodeClass.ReferenceType)) {
470
+ // throw new Error("cannot resolve referenceId "+ refType.toString());
471
+ return null;
472
+ }
473
+ }
474
+ else {
475
+ (0, node_opcua_assert_1.assert)(typeof refType === "string");
476
+ node = this._findReferenceType(refType, namespaceIndex);
477
+ }
478
+ return node;
479
+ }
480
+ /**
481
+ * returns the inverse name of the referenceType.
482
+ *
483
+ * @method inverseReferenceType
484
+ * @param referenceType {String} : the reference type name
485
+ * @return {String} the name of the inverse reference type.
486
+ *
487
+ * @example
488
+ *
489
+ * ```javascript
490
+ * addressSpace.inverseReferenceType("OrganizedBy").should.eql("Organizes");
491
+ * addressSpace.inverseReferenceType("Organizes").should.eql("OrganizedBy");
492
+ * ```
493
+ *
494
+ */
495
+ inverseReferenceType(referenceType) {
496
+ (0, node_opcua_assert_1.assert)(typeof referenceType === "string");
497
+ const n1 = this.findReferenceType(referenceType);
498
+ const n2 = this.findReferenceTypeFromInverseName(referenceType);
499
+ if (n1) {
500
+ (0, node_opcua_assert_1.assert)(!n2);
501
+ return n1.inverseName.text;
502
+ }
503
+ else {
504
+ (0, node_opcua_assert_1.assert)(n2);
505
+ return n2.browseName.toString();
506
+ }
507
+ }
508
+ /**
509
+ * find an EventType node in the address space
510
+ * @method findEventType
511
+ * @param eventTypeId {String|NodeId|UAObjectType} the eventType to find
512
+ * @param namespaceIndex the namespace index of the event to find
513
+ * @return {UAObjectType|null} the EventType found or null.
514
+ *
515
+ * note:
516
+ * - the method with throw an exception if a node is found
517
+ * that is not a BaseEventType or a subtype of it.
518
+ *
519
+ * @example
520
+ *
521
+ * var evtType = addressSpace.findEventType("AuditEventType");
522
+ *
523
+ */
524
+ findEventType(eventTypeId, namespaceIndex) {
525
+ let eventType;
526
+ if (eventTypeId instanceof base_node_impl_1.BaseNodeImpl) {
527
+ eventType = eventTypeId;
528
+ }
529
+ else {
530
+ eventType = this.findObjectType(eventTypeId, namespaceIndex);
531
+ }
532
+ if (!eventType) {
533
+ return null;
534
+ }
535
+ const baseEventType = this.findObjectType("BaseEventType");
536
+ /* istanbul ignore next */
537
+ if (!baseEventType) {
538
+ throw new Error("expecting BaseEventType - please check you nodeset xml file!");
539
+ }
540
+ if ((0, node_opcua_nodeid_1.sameNodeId)(eventType.nodeId, baseEventType.nodeId)) {
541
+ return eventType;
542
+ }
543
+ /* eventTypeNode should be isSupertypeOf("BaseEventType"); */
544
+ /* istanbul ignore next */
545
+ if (!eventType.isSupertypeOf(baseEventType)) {
546
+ throw new Error("findEventType: event found is not subType of BaseEventType");
547
+ }
548
+ return eventType;
549
+ }
550
+ /**
551
+ * EventId is generated by the Server to uniquely identify a particular Event Notification.
552
+ * @method generateEventId
553
+ * @return {Variant} dataType: "ByteString"
554
+ */
555
+ generateEventId() {
556
+ /*
557
+ * OpcUA 1.02 part 5 : 6.4.2 BaseEventType
558
+ * The Server is responsible to ensure that each Event has its unique EventId.
559
+ * It may do this, for example, by putting GUIDs into the ByteString.
560
+ * Clients can use the EventId to assist in minimizing or eliminating gaps and overlaps that may occur during
561
+ * a redundancy fail-over. The EventId shall always be returned as value and the Server is not allowed to
562
+ * return a StatusCode for the EventId indicating an error.
563
+ *
564
+ */
565
+ const offset = 16;
566
+ const self = this;
567
+ if (!self._eventIdCounter) {
568
+ self._eventIdCounter = (0, crypto_1.randomBytes)(20);
569
+ self._eventIdCounter.writeInt32BE(0, offset);
570
+ }
571
+ self._eventIdCounter.writeInt32BE(self._eventIdCounter.readInt32BE(offset) + 1, offset);
572
+ return new node_opcua_variant_1.Variant({
573
+ dataType: node_opcua_variant_1.DataType.ByteString,
574
+ value: Buffer.from(self._eventIdCounter)
575
+ });
576
+ }
577
+ /*=
578
+ * construct a simple javascript object with all the default properties of the event
579
+ * @method constructEventData
580
+ *
581
+ * @return result.$eventDataSource {BaseNode} the event type node
582
+ * @return result.eventId {NodeId} the
583
+ * ...
584
+ *
585
+ *
586
+ * eventTypeId can be a UAEventType
587
+ *
588
+ * @private
589
+ */
590
+ constructEventData(eventTypeId, data) {
591
+ data = data || {};
592
+ // construct the reference dataStructure to store event Data
593
+ let eventTypeNode = eventTypeId;
594
+ // make sure that eventType is really a object that derived from EventType
595
+ if (eventTypeId instanceof ua_object_type_impl_1.UAObjectTypeImpl) {
596
+ eventTypeNode = this.findEventType(eventTypeId);
597
+ }
598
+ /* istanbul ignore next */
599
+ if (!eventTypeNode) {
600
+ throw new Error(" cannot find EvenType for " + eventTypeId);
601
+ }
602
+ (0, node_opcua_assert_1.assert)(eventTypeNode instanceof ua_object_type_impl_1.UAObjectTypeImpl, "eventTypeId must represent a UAObjectType");
603
+ // eventId
604
+ (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(data, "eventId"), "eventId constructEventData : options object should not have eventId property");
605
+ data.eventId = data.eventId || this.generateEventId();
606
+ // eventType
607
+ data.eventType = { dataType: node_opcua_variant_1.DataType.NodeId, value: eventTypeNode.nodeId };
608
+ // sourceNode
609
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(data, "sourceNode"), "expecting a source node to be defined");
610
+ data.sourceNode = new node_opcua_variant_1.Variant(data.sourceNode);
611
+ (0, node_opcua_assert_1.assert)(data.sourceNode.dataType === node_opcua_variant_1.DataType.NodeId);
612
+ // sourceName
613
+ const sourceNode = this.findNode(data.sourceNode.value);
614
+ data.sourceName = data.sourceName || {
615
+ dataType: node_opcua_variant_1.DataType.String,
616
+ value: sourceNode.getDisplayName("en")
617
+ };
618
+ const nowUTC = new Date();
619
+ // time (UtcTime)
620
+ // TODO
621
+ data.time = data.time || { dataType: node_opcua_variant_1.DataType.DateTime, value: nowUTC };
622
+ // receivedTime (UtcTime)
623
+ // TODO
624
+ data.receiveTime = data.receiveTime || { dataType: node_opcua_variant_1.DataType.DateTime, value: nowUTC };
625
+ // localTime (UtcTime)
626
+ // TODO
627
+ data.localTime = data.localTime || { dataType: node_opcua_variant_1.DataType.DateTime, value: nowUTC };
628
+ // message (LocalizedText)
629
+ data.message = data.message || { dataType: node_opcua_variant_1.DataType.LocalizedText, value: { text: "" } };
630
+ // severity (UInt16)
631
+ data.severity = data.severity || { dataType: node_opcua_variant_1.DataType.UInt16, value: 0 };
632
+ // xx // reminder : event type cannot be instantiated directly !
633
+ // xx assert(eventTypeNode.isAbstract);
634
+ const baseObjectType = this.findObjectType("BaseObjectType"); // i=58
635
+ /* istanbul ignore next */
636
+ if (!baseObjectType) {
637
+ throw new Error("BaseObjectType must be defined in the address space");
638
+ }
639
+ const visitedProperties = {};
640
+ function _process_var(self, prefix, node) {
641
+ const lowerName = prefix + (0, node_opcua_utils_1.lowerFirstLetter)(node.browseName.name);
642
+ // istanbul ignore next
643
+ // xx if (doDebug) { debugLog(" " + lowerName.toString()); }
644
+ visitedProperties[lowerName] = node;
645
+ if (Object.prototype.hasOwnProperty.call(data, lowerName)) {
646
+ eventData.setValue(lowerName, node, data[lowerName]);
647
+ // xx eventData[lowerName] = _coerceVariant(data[lowerName]);
648
+ }
649
+ else {
650
+ // add a property , but with a null variant
651
+ eventData.setValue(lowerName, node, { dataType: node_opcua_variant_1.DataType.Null });
652
+ if (doDebug) {
653
+ if (node.modellingRule === "Mandatory") {
654
+ // tslint:disable:no-console
655
+ console.log(chalk.red("ERROR : AddressSpace#constructEventData(eventType,options) " + "cannot find property ") +
656
+ self.browseName.toString() +
657
+ " => " +
658
+ chalk.cyan(lowerName));
659
+ }
660
+ else {
661
+ console.log(chalk.yellow("Warning : AddressSpace#constructEventData(eventType,options)" + " cannot find property ") +
662
+ self.browseName.toString() +
663
+ " => " +
664
+ chalk.cyan(lowerName));
665
+ }
666
+ }
667
+ }
668
+ }
669
+ // verify that all elements of data are valid
670
+ function verify_data_is_valid(data1) {
671
+ Object.keys(data1).map((k) => {
672
+ if (k === "$eventDataSource") {
673
+ return;
674
+ }
675
+ /* istanbul ignore next */
676
+ if (!Object.prototype.hasOwnProperty.call(visitedProperties, k)) {
677
+ throw new Error(" cannot find property '" +
678
+ k +
679
+ "' in [ " +
680
+ Object.keys(visitedProperties).join(", ") +
681
+ "] when filling " +
682
+ eventTypeNode.browseName.toString());
683
+ }
684
+ });
685
+ }
686
+ const populate_data = (self, eventData1) => {
687
+ if ((0, node_opcua_nodeid_1.sameNodeId)(baseObjectType.nodeId, self.nodeId)) {
688
+ return; // nothing to do
689
+ }
690
+ const baseTypeNodeId = self.subtypeOf;
691
+ /* istanbul ignore next */
692
+ if (!baseTypeNodeId) {
693
+ throw new Error("Object " + self.browseName.toString() + " with nodeId " + self.nodeId + " has no Type");
694
+ }
695
+ const baseType = this.findNode(baseTypeNodeId);
696
+ /* istanbul ignore next */
697
+ if (!baseType) {
698
+ throw new Error(chalk.red("Cannot find object with nodeId ") + baseTypeNodeId);
699
+ }
700
+ populate_data(baseType, eventData1);
701
+ // get properties and components from base class
702
+ const properties = self.getProperties();
703
+ const components = self.getComponents();
704
+ const children = [].concat(properties, components);
705
+ // istanbul ignore next
706
+ if (doDebug) {
707
+ console.log(" " + chalk.bgWhite.cyan(self.browseName.toString()));
708
+ }
709
+ for (const node of children) {
710
+ // only keep those that have a "HasModellingRule"
711
+ if (!node.modellingRule) {
712
+ // xx console.log(" skipping node without modelling rule", node.browseName.toString());
713
+ continue;
714
+ }
715
+ // ignore also methods
716
+ if (node.nodeClass === node_opcua_data_model_1.NodeClass.Method) {
717
+ // xx console.log(" skipping method ", node.browseName.toString());
718
+ continue;
719
+ }
720
+ _process_var(self, "", node);
721
+ // also store value in index
722
+ // xx eventData.__nodes[node.nodeId.toString()] = eventData[lowerName];
723
+ const children2 = node.getAggregates();
724
+ if (children2.length > 0) {
725
+ const lowerName = (0, node_opcua_utils_1.lowerFirstLetter)(node.browseName.name);
726
+ // console.log(" Children to visit = ",lowerName,
727
+ // children.map(function(a){ return a.browseName.toString();}).join(" "));
728
+ for (const child2 of children2) {
729
+ _process_var(self, lowerName + ".", child2);
730
+ }
731
+ }
732
+ }
733
+ };
734
+ const eventData = new event_data_1.EventData(eventTypeNode);
735
+ // verify standard properties...
736
+ populate_data(eventTypeNode, eventData);
737
+ verify_data_is_valid(data);
738
+ return eventData;
739
+ }
740
+ // - Browse --------------------------------------------------------------------------------------------------------
741
+ /**
742
+ * browse some path.
743
+ *
744
+ * @method browsePath
745
+ * @param {BrowsePath} browsePath
746
+ * @return {BrowsePathResult}
747
+ *
748
+ * This service can be used translates one or more browse paths into NodeIds.
749
+ * A browse path is constructed of a starting Node and a RelativePath. The specified starting Node
750
+ * identifies the Node from which the RelativePath is based. The RelativePath contains a sequence of
751
+ * ReferenceTypes and BrowseNames.
752
+ *
753
+ * |StatusCode | |
754
+ * |------------------------------|:-----------------------------------------------------------|
755
+ * |BadNodeIdUnknown | |
756
+ * |BadNodeIdInvalid | |
757
+ * |BadNothingToDo | - the relative path contains an empty list ) |
758
+ * |BadBrowseNameInvalid | - target name is missing in relative path |
759
+ * |UncertainReferenceOutOfServer | - The path element has targets which are in another server.|
760
+ * |BadTooManyMatches | |
761
+ * |BadQueryTooComplex | |
762
+ * |BadNoMatch | |
763
+ *
764
+ *
765
+ *
766
+ */
767
+ browsePath(browsePath) {
768
+ (0, node_opcua_assert_1.assert)(browsePath instanceof node_opcua_types_1.BrowsePath);
769
+ const startingNode = this.findNode(browsePath.startingNode);
770
+ if (!startingNode) {
771
+ return new node_opcua_types_1.BrowsePathResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadNodeIdUnknown });
772
+ }
773
+ if (!browsePath.relativePath.elements || browsePath.relativePath.elements.length === 0) {
774
+ return new node_opcua_types_1.BrowsePathResult({
775
+ statusCode: node_opcua_status_code_1.StatusCodes.BadNothingToDo,
776
+ targets: []
777
+ });
778
+ }
779
+ const elements_length = browsePath.relativePath.elements.length;
780
+ // -------------------------------------------------------------------------------------------------------
781
+ // verify standard RelativePath construction
782
+ // from OPCUA 1.03 - PArt 3 - 7.6 RelativePath:
783
+ // TargetName The BrowseName of the target node.
784
+ // The final element may have an empty targetName. In this situation all targets of the
785
+ // references identified by the referenceTypeId are the targets of the RelativePath.
786
+ // The targetName shall be specified for all other elements.
787
+ // The current path cannot be followed any further if no targets with the specified
788
+ // BrowseName exist.
789
+ // Let's detect null targetName which are not in last position and return BadBrowseNameInvalid if not
790
+ //
791
+ const empty_targetName_not_in_lastPos = browsePath.relativePath.elements.reduce((prev, e, index) => {
792
+ const is_last = index + 1 === elements_length;
793
+ const isBad = !is_last && (!e.targetName || e.targetName.isEmpty());
794
+ return prev + (!is_last && (!e.targetName || e.targetName.isEmpty()) ? 1 : 0);
795
+ }, 0);
796
+ if (empty_targetName_not_in_lastPos) {
797
+ return new node_opcua_types_1.BrowsePathResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadBrowseNameInvalid });
798
+ }
799
+ // from OPCUA 1.03 - PArt 3 - 5.8.4 TranslateBrowsePathToNodeIds
800
+ // TranslateBrowsePathToNodeIds further restrict RelativePath targetName rules:
801
+ // The last element in the relativePath shall always have a targetName specified.
802
+ const last_el = browsePath.relativePath.elements[elements_length - 1];
803
+ if (!last_el.targetName || !last_el.targetName.name || last_el.targetName.name.length === 0) {
804
+ return new node_opcua_types_1.BrowsePathResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadBrowseNameInvalid });
805
+ }
806
+ const res = [];
807
+ const explore_element = (curNodeObject, elements, index) => {
808
+ const element = elements[index];
809
+ (0, node_opcua_assert_1.assert)(element instanceof node_opcua_types_1.RelativePathElement);
810
+ const is_last = index + 1 === elements.length;
811
+ const nodeIds = curNodeObject.browseNodeByTargetName(element, is_last);
812
+ const targets = nodeIds.map((nodeId) => {
813
+ return {
814
+ remainingPathIndex: elements.length - index,
815
+ targetId: nodeId
816
+ };
817
+ });
818
+ if (!is_last) {
819
+ // explorer
820
+ for (const target of targets) {
821
+ const node = this.findNode(target.targetId);
822
+ if (!node) {
823
+ continue;
824
+ }
825
+ explore_element(node, elements, index + 1);
826
+ }
827
+ }
828
+ else {
829
+ for (const target of targets) {
830
+ res.push({
831
+ remainingPathIndex: 0xffffffff,
832
+ targetId: (0, node_opcua_nodeid_1.coerceExpandedNodeId)(target.targetId)
833
+ });
834
+ }
835
+ }
836
+ };
837
+ explore_element(startingNode, browsePath.relativePath.elements, 0);
838
+ if (res.length === 0) {
839
+ return new node_opcua_types_1.BrowsePathResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadNoMatch });
840
+ }
841
+ return new node_opcua_types_1.BrowsePathResult({
842
+ statusCode: node_opcua_status_code_1.StatusCodes.Good,
843
+ targets: res
844
+ });
845
+ }
846
+ // - Extension Object ----------------------------------------------------------------------------------------------
847
+ getExtensionObjectConstructor(dataType) {
848
+ (0, node_opcua_assert_1.assert)(dataType, "expecting a dataType");
849
+ if (dataType instanceof node_opcua_nodeid_1.NodeId) {
850
+ const tmp = this.findNode(dataType);
851
+ /* istanbul ignore next */
852
+ if (!tmp) {
853
+ throw new Error("getExtensionObjectConstructor: cannot resolve dataType " + dataType);
854
+ }
855
+ dataType = tmp;
856
+ }
857
+ /* istanbul ignore next */
858
+ if (!(dataType instanceof ua_data_type_impl_1.UADataTypeImpl)) {
859
+ // may be dataType was the NodeId of the "Binary Encoding" node
860
+ throw new Error("getExtensionObjectConstructor: dataType has unexpected type" + dataType);
861
+ }
862
+ const _dataType = dataType;
863
+ // to do verify that dataType is of type "Structure"
864
+ /* istanbul ignore next */
865
+ if (!_dataType.isSupertypeOf(this.findDataType("Structure"))) {
866
+ console.log(_dataType.toString());
867
+ }
868
+ (0, node_opcua_assert_1.assert)(_dataType.isSupertypeOf(this.findDataType("Structure")));
869
+ if (!_dataType._extensionObjectConstructor) {
870
+ const dataTypeManager = this.$$extraDataTypeManager;
871
+ _dataType._extensionObjectConstructor = dataTypeManager.getExtensionObjectConstructorFromDataType(_dataType.nodeId);
872
+ }
873
+ (0, node_opcua_assert_1.assert)(_dataType._extensionObjectConstructor, "dataType must have a constructor");
874
+ const Constructor = _dataType._extensionObjectConstructor;
875
+ return Constructor;
876
+ }
877
+ /**
878
+ * @param dataType
879
+ * @param [options]
880
+ * @return the constructed extension object
881
+ *
882
+ *
883
+ * @example
884
+ *
885
+ * // example 1
886
+ * var extObj = addressSpace.constructExtensionObject("BuildInfo",{ productName: "PRODUCT_NAME"});
887
+ *
888
+ * // example 2
889
+ * serverStatusDataType.nodeClass.should.eql(NodeClass.DataType);
890
+ * serverStatusDataType.browseName.toString().should.eql("ServerStatusDataType");
891
+ * var serverStatus = addressSpace.constructExtensionObject(serverStatusDataType);
892
+ * serverStatus.constructor.name.should.eql("ServerStatusDataType");
893
+ */
894
+ constructExtensionObject(dataType, options) {
895
+ const Constructor = this.getExtensionObjectConstructor(dataType);
896
+ return new Constructor(options);
897
+ }
898
+ /**
899
+ * cleanup all resources maintained by this addressSpace.
900
+ * @method dispose
901
+ */
902
+ dispose() {
903
+ this._namespaceArray.map((namespace) => namespace.dispose());
904
+ AddressSpace.registry.unregister(this);
905
+ /* istanbul ignore next */
906
+ if (this._shutdownTask && this._shutdownTask.length > 0) {
907
+ throw new Error("AddressSpace#dispose : shutdown has not been called");
908
+ }
909
+ }
910
+ /**
911
+ * register a function that will be called when the server will perform its shut down.
912
+ * @method registerShutdownTask
913
+ */
914
+ registerShutdownTask(task) {
915
+ this._shutdownTask = this._shutdownTask || [];
916
+ (0, node_opcua_assert_1.assert)(typeof task === "function");
917
+ this._shutdownTask.push(task);
918
+ }
919
+ shutdown() {
920
+ return __awaiter(this, void 0, void 0, function* () {
921
+ if (!this._shutdownTask) {
922
+ return;
923
+ }
924
+ const tasks = this._shutdownTask;
925
+ this._shutdownTask = [];
926
+ // perform registerShutdownTask
927
+ for (const task of tasks) {
928
+ yield task.call(this);
929
+ }
930
+ });
931
+ }
932
+ /**
933
+ *
934
+ * @method browseSingleNode
935
+ * @param nodeId {NodeId|String} : the nodeid of the element to browse
936
+ * @param browseDescription
937
+ * @param browseDescription.browseDirection {BrowseDirection} :
938
+ * @param browseDescription.referenceTypeId {String|NodeId}
939
+ * @param [session]
940
+ * @return {BrowseResult}
941
+ */
942
+ browseSingleNode(nodeId, browseDescription, context) {
943
+ const browseResult = {
944
+ continuationPoint: undefined,
945
+ references: null,
946
+ statusCode: node_opcua_status_code_1.StatusCodes.Good
947
+ };
948
+ if (!browseDescription || browseDescription.browseDirection === node_opcua_data_model_1.BrowseDirection.Invalid) {
949
+ browseResult.statusCode = node_opcua_status_code_1.StatusCodes.BadBrowseDirectionInvalid;
950
+ return new node_opcua_service_browse_1.BrowseResult(browseResult);
951
+ }
952
+ browseDescription.browseDirection = (0, adjust_browse_direction_1.adjustBrowseDirection)(browseDescription.browseDirection, node_opcua_data_model_1.BrowseDirection.Forward);
953
+ /* istanbul ignore next */
954
+ if (typeof nodeId === "number") {
955
+ throw new Error("Not Implemented");
956
+ }
957
+ if (typeof nodeId === "string") {
958
+ const node = this.findNode(this.resolveNodeId(nodeId));
959
+ if (node) {
960
+ nodeId = node.nodeId;
961
+ }
962
+ }
963
+ // check if referenceTypeId is correct
964
+ if (browseDescription.referenceTypeId instanceof node_opcua_nodeid_1.NodeId) {
965
+ if (browseDescription.referenceTypeId.value === 0) {
966
+ browseDescription.referenceTypeId = null;
967
+ }
968
+ else {
969
+ const rf = this.findNode(browseDescription.referenceTypeId);
970
+ if (!rf || !(rf instanceof ua_reference_type_impl_1.UAReferenceTypeImpl)) {
971
+ browseResult.statusCode = node_opcua_status_code_1.StatusCodes.BadReferenceTypeIdInvalid;
972
+ return new node_opcua_service_browse_1.BrowseResult(browseResult);
973
+ }
974
+ }
975
+ }
976
+ const obj = this.findNode(nodeId);
977
+ if (!obj) {
978
+ // Object Not Found
979
+ browseResult.statusCode = node_opcua_status_code_1.StatusCodes.BadNodeIdUnknown;
980
+ // xx console.log("xxxxxx browsing ",nodeId.toString() , " not found" );
981
+ }
982
+ else {
983
+ browseResult.statusCode = node_opcua_status_code_1.StatusCodes.Good;
984
+ browseResult.references = obj.browseNode(browseDescription, context);
985
+ }
986
+ return new node_opcua_service_browse_1.BrowseResult(browseResult);
987
+ }
988
+ /**
989
+ * @param folder
990
+ * @private
991
+ */
992
+ _coerceFolder(folder) {
993
+ folder = this._coerceNode(folder);
994
+ /* istanbul ignore next */
995
+ if (folder && !_isFolder(this, folder)) {
996
+ throw new Error("Parent folder must be of FolderType " + folder.typeDefinition.toString());
997
+ }
998
+ return folder;
999
+ }
1000
+ /**
1001
+ *
1002
+ * @param view
1003
+ * @param modelChange
1004
+ * @private
1005
+ */
1006
+ _collectModelChange(view, modelChange) {
1007
+ // xx console.log("in _collectModelChange", modelChange.verb, verbFlags.get(modelChange.verb).toString());
1008
+ this._modelChanges.push(modelChange);
1009
+ }
1010
+ /**
1011
+ *
1012
+ * walk up the hierarchy of objects until a view is found
1013
+ * objects may belong to multiples views.
1014
+ * Note: this method doesn't return the main view => Server object.
1015
+ * @method extractRootViews
1016
+ * @param node {BaseNode}
1017
+ * @return {BaseNode[]}
1018
+ */
1019
+ /**
1020
+ *
1021
+ * @param node
1022
+ * @private
1023
+ */
1024
+ extractRootViews(node) {
1025
+ (0, node_opcua_assert_1.assert)(node.nodeClass === node_opcua_data_model_1.NodeClass.Object || node.nodeClass === node_opcua_data_model_1.NodeClass.Variable);
1026
+ const visitedMap = {};
1027
+ const q = new Dequeue();
1028
+ q.push(node);
1029
+ const objectsFolder = this.rootFolder.objects;
1030
+ (0, node_opcua_assert_1.assert)(objectsFolder instanceof ua_object_impl_1.UAObjectImpl);
1031
+ const results = [];
1032
+ while (q.length) {
1033
+ node = q.shift();
1034
+ const references = node.findReferencesEx("HierarchicalReferences", node_opcua_data_model_1.BrowseDirection.Inverse);
1035
+ const parentNodes = references.map((r) => reference_impl_1.ReferenceImpl.resolveReferenceNode(this, r));
1036
+ for (const parent of parentNodes) {
1037
+ if ((0, node_opcua_nodeid_1.sameNodeId)(parent.nodeId, objectsFolder.nodeId)) {
1038
+ continue; // nothing to do
1039
+ }
1040
+ if (parent.nodeClass === node_opcua_data_model_1.NodeClass.View) {
1041
+ results.push(parent);
1042
+ }
1043
+ else {
1044
+ const key = parent.nodeId.toString();
1045
+ if (Object.prototype.hasOwnProperty.call(visitedMap, key)) {
1046
+ continue;
1047
+ }
1048
+ visitedMap[key] = parent;
1049
+ q.push(parent);
1050
+ }
1051
+ }
1052
+ }
1053
+ return results;
1054
+ }
1055
+ /**
1056
+ *
1057
+ * @param func
1058
+ * @private
1059
+ */
1060
+ modelChangeTransaction(func) {
1061
+ this._modelChangeTransactionCounter = this._modelChangeTransactionCounter || 0;
1062
+ function beginModelChange() {
1063
+ /* jshint validthis:true */
1064
+ (0, node_opcua_assert_1.assert)(this);
1065
+ this._modelChanges = this._modelChanges || [];
1066
+ (0, node_opcua_assert_1.assert)(this._modelChangeTransactionCounter >= 0);
1067
+ this._modelChangeTransactionCounter += 1;
1068
+ }
1069
+ function endModelChange() {
1070
+ /* jshint validthis:true */
1071
+ this._modelChangeTransactionCounter -= 1;
1072
+ if (this._modelChangeTransactionCounter === 0) {
1073
+ if (this._modelChanges.length === 0) {
1074
+ return; // nothing to do
1075
+ }
1076
+ // xx console.log( "xx dealing with ",this._modelChanges.length);
1077
+ // increase version number of participating nodes
1078
+ // https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore
1079
+ // const nodeIds = _.uniq(this._modelChanges.map((c: any) => c.affected));
1080
+ const nodeIds = [...new Set(this._modelChanges.map((c) => c.affected))];
1081
+ const nodes = nodeIds.map((nodeId) => this.findNode(nodeId));
1082
+ nodes.forEach(_increase_version_number);
1083
+ // raise events
1084
+ if (this.rootFolder.objects.server) {
1085
+ const eventTypeNode = this.findEventType("GeneralModelChangeEventType");
1086
+ if (eventTypeNode) {
1087
+ // xx console.log("xx raising event on server object");
1088
+ this.rootFolder.objects.server.raiseEvent(eventTypeNode, {
1089
+ // Part 5 - 6.4.32 GeneralModelChangeEventType
1090
+ changes: {
1091
+ dataType: node_opcua_variant_1.DataType.ExtensionObject,
1092
+ arrayType: node_opcua_variant_1.VariantArrayType.Array,
1093
+ value: this._modelChanges
1094
+ }
1095
+ });
1096
+ }
1097
+ }
1098
+ this._modelChanges = [];
1099
+ // _notifyModelChange(this);
1100
+ }
1101
+ }
1102
+ beginModelChange.call(this);
1103
+ try {
1104
+ func();
1105
+ }
1106
+ catch (err) {
1107
+ errorLog("modelChangeTransaction", err === null || err === void 0 ? void 0 : err.message);
1108
+ throw err;
1109
+ }
1110
+ finally {
1111
+ endModelChange.call(this);
1112
+ }
1113
+ }
1114
+ /**
1115
+ * normalize the ReferenceType field of the Reference Object
1116
+ * @param params.referenceType {String|nodeId}
1117
+ * @param params.isForward {Boolean} default value: true;
1118
+ * @return {Object} a new reference object with the normalized name { referenceType: <value>, isForward: <flag>}
1119
+ */
1120
+ normalizeReferenceType(params) {
1121
+ if (params instanceof reference_impl_1.ReferenceImpl) {
1122
+ // a reference has already been normalized
1123
+ return params;
1124
+ }
1125
+ // ----------------------------------------------- handle is forward
1126
+ (0, node_opcua_assert_1.assert)(params.isForward === undefined || typeof params.isForward === "boolean");
1127
+ params.isForward = utils.isNullOrUndefined(params.isForward) ? true : !!params.isForward;
1128
+ // referenceType = Organizes , isForward = true => referenceType = Organizes , isForward = true
1129
+ // referenceType = Organizes , isForward = false => referenceType = Organizes , isForward = false
1130
+ // referenceType = OrganizedBy , isForward = true => referenceType = Organizes , isForward = **false**
1131
+ // referenceType = OrganizedBy , isForward = false => referenceType = Organizes , isForward = **true**
1132
+ // ----------------------------------------------- handle referenceType
1133
+ if (params.referenceType instanceof ua_reference_type_impl_1.UAReferenceTypeImpl) {
1134
+ params.referenceType = params.referenceType;
1135
+ params.referenceType = params.referenceType.nodeId;
1136
+ }
1137
+ else if (typeof params.referenceType === "string") {
1138
+ const inv = this.findReferenceTypeFromInverseName(params.referenceType);
1139
+ if (inv) {
1140
+ params.referenceType = inv.nodeId;
1141
+ params._referenceType = inv;
1142
+ params.isForward = !params.isForward;
1143
+ }
1144
+ else {
1145
+ params.referenceType = (0, node_opcua_nodeid_1.resolveNodeId)(params.referenceType);
1146
+ const refType = this.findReferenceType(params.referenceType);
1147
+ if (refType) {
1148
+ params._referenceType = refType;
1149
+ }
1150
+ }
1151
+ }
1152
+ (0, node_opcua_assert_1.assert)(params.referenceType instanceof node_opcua_nodeid_1.NodeId);
1153
+ // ----------- now resolve target NodeId;
1154
+ if (params.nodeId instanceof base_node_impl_1.BaseNodeImpl) {
1155
+ (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(params, "node"));
1156
+ params.node = params.nodeId;
1157
+ params.nodeId = params.node.nodeId;
1158
+ }
1159
+ else {
1160
+ let _nodeId = params.nodeId;
1161
+ (0, node_opcua_assert_1.assert)(!!_nodeId, "missing 'nodeId' in reference");
1162
+ if (_nodeId && _nodeId.nodeId) {
1163
+ _nodeId = _nodeId.nodeId;
1164
+ }
1165
+ _nodeId = (0, node_opcua_nodeid_1.resolveNodeId)(_nodeId);
1166
+ /* istanbul ignore next */
1167
+ if (!(_nodeId instanceof node_opcua_nodeid_1.NodeId) || _nodeId.isEmpty()) {
1168
+ // tslint:disable:no-console
1169
+ console.log("xx =>", JSON.stringify(params, null, " "));
1170
+ throw new Error(" Invalid reference nodeId " + _nodeId.toString());
1171
+ }
1172
+ params.nodeId = _nodeId;
1173
+ }
1174
+ return new reference_impl_1.ReferenceImpl(params);
1175
+ }
1176
+ /**
1177
+ *
1178
+ * @param references
1179
+ */
1180
+ normalizeReferenceTypes(references) {
1181
+ if (!references || references.length === 0) {
1182
+ return [];
1183
+ }
1184
+ references = references;
1185
+ (0, node_opcua_assert_1.assert)(Array.isArray(references));
1186
+ return references.map((el) => this.normalizeReferenceType(el));
1187
+ }
1188
+ // -- Historical Node -----------------------------------------------------------------------------------------
1189
+ /**
1190
+ *
1191
+ * @param node
1192
+ * @param options
1193
+ */
1194
+ installHistoricalDataNode(node, options) {
1195
+ address_space_historical_data_node_1.AddressSpace_installHistoricalDataNode.call(this, node, options);
1196
+ }
1197
+ // -- Alarms & Conditions -----------------------------------------------------------------------------------------
1198
+ /**
1199
+ *
1200
+ */
1201
+ installAlarmsAndConditionsService() {
1202
+ alarms_and_conditions_1.UAConditionImpl.install_condition_refresh_handle(this);
1203
+ alarms_and_conditions_1.UAAcknowledgeableConditionImpl.install_method_handle_on_type(this);
1204
+ }
1205
+ // -- internal stuff -----------------------------------------------------------------------------------------------
1206
+ _coerceNode(node) {
1207
+ function hasTypeDefinition(node1) {
1208
+ return (node1.nodeClass === node_opcua_data_model_1.NodeClass.Variable ||
1209
+ node1.nodeClass === node_opcua_data_model_1.NodeClass.Object ||
1210
+ node1.nodeClass === node_opcua_data_model_1.NodeClass.Method);
1211
+ }
1212
+ // coerce to BaseNode object
1213
+ if (node instanceof base_node_impl_1.BaseNodeImpl) {
1214
+ return node;
1215
+ }
1216
+ // it's a node id like
1217
+ // coerce parent folder to an object
1218
+ const returnValue = this.findNode((0, node_opcua_nodeid_1.resolveNodeId)(node));
1219
+ /*
1220
+ if (!hasTypeDefinition(node as BaseNode)) {
1221
+ node = this.findNode(node.nodeId) || node;
1222
+ if (!node || !hasTypeDefinition(node)) {
1223
+ return null;
1224
+ }
1225
+ }
1226
+ */
1227
+ return returnValue;
1228
+ }
1229
+ _coerce_DataType(dataType) {
1230
+ if (dataType instanceof node_opcua_nodeid_1.NodeId) {
1231
+ // xx assert(self.findDataType(dataType));
1232
+ return dataType;
1233
+ }
1234
+ return this._coerce_Type(dataType, node_opcua_constants_1.DataTypeIds, "DataTypeIds", AddressSpace.prototype.findDataType);
1235
+ }
1236
+ _coerceTypeDefinition(typeDefinition) {
1237
+ if (typeof typeDefinition === "string") {
1238
+ // coerce parent folder to an node
1239
+ const typeDefinitionNode = this.findNode(typeDefinition);
1240
+ typeDefinition = typeDefinitionNode.nodeId;
1241
+ }
1242
+ // xx console.log("typeDefinition = ",typeDefinition);
1243
+ (0, node_opcua_assert_1.assert)(typeDefinition instanceof node_opcua_nodeid_1.NodeId);
1244
+ return typeDefinition;
1245
+ }
1246
+ _coerceType(baseType, topMostBaseType, nodeClass) {
1247
+ (0, node_opcua_assert_1.assert)(typeof topMostBaseType === "string");
1248
+ const topMostBaseTypeNode = this.findNode(topMostBaseType);
1249
+ /* istanbul ignore next */
1250
+ if (!topMostBaseTypeNode) {
1251
+ throw new Error("Cannot find topMostBaseTypeNode " + topMostBaseType.toString());
1252
+ }
1253
+ (0, node_opcua_assert_1.assert)(topMostBaseTypeNode instanceof base_node_impl_1.BaseNodeImpl);
1254
+ (0, node_opcua_assert_1.assert)(topMostBaseTypeNode.nodeClass === nodeClass);
1255
+ if (!baseType) {
1256
+ return topMostBaseTypeNode;
1257
+ }
1258
+ (0, node_opcua_assert_1.assert)(typeof baseType === "string" || baseType instanceof base_node_impl_1.BaseNodeImpl);
1259
+ let baseTypeNode;
1260
+ if (baseType instanceof base_node_impl_1.BaseNodeImpl) {
1261
+ baseTypeNode = baseType;
1262
+ }
1263
+ else {
1264
+ baseTypeNode = this.findNode(baseType);
1265
+ }
1266
+ /* istanbul ignore next*/
1267
+ if (!baseTypeNode) {
1268
+ throw new Error("Cannot find ObjectType or VariableType for " + baseType.toString());
1269
+ }
1270
+ /* istanbul ignore next */
1271
+ if (!baseTypeNode.isSupertypeOf) {
1272
+ throw new Error("Cannot find ObjectType or VariableType for " + baseType.toString());
1273
+ }
1274
+ /* istanbul ignore next */
1275
+ if (!baseTypeNode.isSupertypeOf(topMostBaseTypeNode)) {
1276
+ throw new Error("wrong type ");
1277
+ }
1278
+ return baseTypeNode;
1279
+ }
1280
+ _coerce_VariableTypeIds(dataType) {
1281
+ return this._coerce_Type(dataType, node_opcua_constants_1.VariableTypeIds, "VariableTypeIds", AddressSpace.prototype.findVariableType);
1282
+ }
1283
+ _register(node) {
1284
+ (0, node_opcua_assert_1.assert)(node.nodeId instanceof node_opcua_nodeid_1.NodeId);
1285
+ const namespace = this.getNamespace(node.nodeId.namespace);
1286
+ namespace._register(node);
1287
+ }
1288
+ deleteNode(nodeOrNodeId) {
1289
+ _getNamespace(this, nodeOrNodeId).deleteNode(nodeOrNodeId);
1290
+ }
1291
+ isEnumeration(dataType) {
1292
+ // DataType must be one of Enumeration
1293
+ const dataTypeNode = this.findDataType(dataType);
1294
+ if (!dataTypeNode) {
1295
+ throw new Error(" Cannot find DataType " + dataType.toString() + " in standard address Space");
1296
+ }
1297
+ const enumerationNode = this.findDataType("Enumeration");
1298
+ if (!enumerationNode) {
1299
+ throw new Error(" Cannot find 'Enumeration' DataType in standard address Space");
1300
+ }
1301
+ return dataTypeNode.isSupertypeOf(enumerationNode);
1302
+ }
1303
+ _coerce_Type(dataType, typeMap, typeMapName, finderMethod) {
1304
+ if (dataType instanceof base_node_impl_1.BaseNodeImpl) {
1305
+ dataType = dataType.nodeId;
1306
+ }
1307
+ (0, node_opcua_assert_1.assert)(typeMap !== null && typeof typeMap === "object");
1308
+ let nodeId;
1309
+ if (typeof dataType === "string") {
1310
+ const namespace0 = this.getDefaultNamespace();
1311
+ // resolve dataType
1312
+ nodeId = namespace0.resolveAlias(dataType);
1313
+ if (!nodeId) {
1314
+ // dataType was not found in the aliases database
1315
+ if (typeMap[dataType]) {
1316
+ nodeId = (0, node_opcua_nodeid_1.makeNodeId)(typeMap[dataType], 0);
1317
+ return nodeId;
1318
+ }
1319
+ else {
1320
+ nodeId = (0, node_opcua_nodeid_1.resolveNodeId)(dataType);
1321
+ }
1322
+ }
1323
+ }
1324
+ else if (typeof dataType === "number") {
1325
+ nodeId = (0, node_opcua_nodeid_1.makeNodeId)(dataType, 0);
1326
+ }
1327
+ else {
1328
+ nodeId = (0, node_opcua_nodeid_1.resolveNodeId)(dataType);
1329
+ }
1330
+ /* istanbul ignore next */
1331
+ if (nodeId == null || !(nodeId instanceof node_opcua_nodeid_1.NodeId)) {
1332
+ throw new Error("Expecting valid nodeId ");
1333
+ }
1334
+ const el = finderMethod.call(this, nodeId);
1335
+ if (!el) {
1336
+ // verify that node Id exists in standard type map typeMap
1337
+ const find = Object.values(typeMap).filter((a) => a === nodeId.value);
1338
+ /* istanbul ignore next */
1339
+ if (find.length !== 1) {
1340
+ throw new Error(" cannot find " + dataType.toString() + " in typeMap " + typeMapName + " L = " + find.length);
1341
+ }
1342
+ }
1343
+ return nodeId;
1344
+ }
1345
+ _findReferenceType(refType, namespaceIndex) {
1346
+ if (refType instanceof node_opcua_nodeid_1.NodeId) {
1347
+ return _find_by_node_id(this, refType, namespaceIndex);
1348
+ }
1349
+ const [namespace, browseName] = _extract_namespace_and_browse_name_as_string(this, refType, namespaceIndex);
1350
+ return namespace.findReferenceType(browseName);
1351
+ }
1352
+ }
1353
+ exports.AddressSpace = AddressSpace;
1354
+ AddressSpace.isNonEmptyQualifiedName = namespace_impl_2.isNonEmptyQualifiedName;
1355
+ AddressSpace.registry = new node_opcua_object_registry_1.ObjectRegistry();
1356
+ function _getNamespace(addressSpace, nodeOrNodId) {
1357
+ const nodeId = nodeOrNodId instanceof base_node_impl_1.BaseNodeImpl ? nodeOrNodId.nodeId : nodeOrNodId;
1358
+ return addressSpace.getNamespace(nodeId.namespace);
1359
+ }
1360
+ function _find_by_node_id(addressSpace, nodeId, namespaceIndex) {
1361
+ const obj = addressSpace.findNode(nodeId);
1362
+ return obj;
1363
+ }
1364
+ /**
1365
+ * return true if nodeId is a UAFolder
1366
+ * @method _isFolder
1367
+ * @param addressSpace
1368
+ * @param folder
1369
+ * @return {Boolean}
1370
+ * @private
1371
+ */
1372
+ function _isFolder(addressSpace, folder) {
1373
+ const folderType = addressSpace.findObjectType("FolderType");
1374
+ (0, node_opcua_assert_1.assert)(folder instanceof base_node_impl_1.BaseNodeImpl);
1375
+ (0, node_opcua_assert_1.assert)(folder.typeDefinitionObj);
1376
+ return folder.typeDefinitionObj.isSupertypeOf(folderType);
1377
+ }
1378
+ function _increase_version_number(node) {
1379
+ if (node && node.nodeVersion) {
1380
+ const previousValue = parseInt(node.nodeVersion.readValue().value.value, 10);
1381
+ node.nodeVersion.setValueFromSource({
1382
+ dataType: node_opcua_variant_1.DataType.String,
1383
+ value: (previousValue + 1).toString()
1384
+ });
1385
+ // xx console.log("xxx increasing version number of node ", node.browseName.toString(),previousValue);
1386
+ }
1387
+ }
1388
1388
  //# sourceMappingURL=address_space.js.map