node-opcua-address-space 2.76.1 → 2.76.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 (289) 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 +33 -33
  8. package/dist/source/helpers/argument_list.js +258 -258
  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 -0
  12. package/dist/source/helpers/check_event_clause.js +53 -0
  13. package/dist/source/helpers/check_event_clause.js.map +1 -0
  14. package/dist/source/helpers/coerce_enum_value.d.ts +6 -6
  15. package/dist/source/helpers/coerce_enum_value.js +33 -33
  16. package/dist/source/helpers/dump_tools.d.ts +14 -14
  17. package/dist/source/helpers/dump_tools.js +78 -78
  18. package/dist/source/helpers/ensure_secure_access.d.ts +9 -9
  19. package/dist/source/helpers/ensure_secure_access.js +76 -76
  20. package/dist/source/helpers/make_optionals_map.d.ts +21 -21
  21. package/dist/source/helpers/make_optionals_map.js +29 -29
  22. package/dist/source/helpers/multiform_func.d.ts +11 -11
  23. package/dist/source/helpers/multiform_func.js +75 -75
  24. package/dist/source/helpers/resolve_opaque_on_address_space.d.ts +3 -3
  25. package/dist/source/helpers/resolve_opaque_on_address_space.js +36 -36
  26. package/dist/source/index.d.ts +56 -56
  27. package/dist/source/index.js +83 -83
  28. package/dist/source/interfaces/alarms_and_conditions/condition_info_i.d.ts +19 -19
  29. package/dist/source/interfaces/alarms_and_conditions/condition_info_i.js +2 -2
  30. package/dist/source/interfaces/alarms_and_conditions/condition_snapshot.d.ts +193 -193
  31. package/dist/source/interfaces/alarms_and_conditions/condition_snapshot.js +2 -2
  32. package/dist/source/interfaces/alarms_and_conditions/deviation_stuff.d.ts +12 -12
  33. package/dist/source/interfaces/alarms_and_conditions/deviation_stuff.js +2 -2
  34. package/dist/source/interfaces/alarms_and_conditions/install_setpoint_options.d.ts +10 -10
  35. package/dist/source/interfaces/alarms_and_conditions/install_setpoint_options.js +2 -2
  36. package/dist/source/interfaces/alarms_and_conditions/instantiate_alarm_condition_options.d.ts +7 -7
  37. package/dist/source/interfaces/alarms_and_conditions/instantiate_alarm_condition_options.js +2 -2
  38. package/dist/source/interfaces/alarms_and_conditions/instantiate_condition_options.d.ts +7 -7
  39. package/dist/source/interfaces/alarms_and_conditions/instantiate_condition_options.js +2 -2
  40. package/dist/source/interfaces/alarms_and_conditions/instantiate_exclusive_deviation_alarm_options.d.ts +4 -4
  41. package/dist/source/interfaces/alarms_and_conditions/instantiate_exclusive_deviation_alarm_options.js +2 -2
  42. package/dist/source/interfaces/alarms_and_conditions/instantiate_exclusive_limit_alarm_options.d.ts +4 -4
  43. package/dist/source/interfaces/alarms_and_conditions/instantiate_exclusive_limit_alarm_options.js +2 -2
  44. package/dist/source/interfaces/alarms_and_conditions/instantiate_limit_alarm_options.d.ts +9 -9
  45. package/dist/source/interfaces/alarms_and_conditions/instantiate_limit_alarm_options.js +2 -2
  46. package/dist/source/interfaces/alarms_and_conditions/instantiate_non_exclusive_deviation_alarm_options.d.ts +4 -4
  47. package/dist/source/interfaces/alarms_and_conditions/instantiate_non_exclusive_deviation_alarm_options.js +2 -2
  48. package/dist/source/interfaces/alarms_and_conditions/instantiate_non_exclusive_limit_alarm_options.d.ts +4 -4
  49. package/dist/source/interfaces/alarms_and_conditions/instantiate_non_exclusive_limit_alarm_options.js +2 -2
  50. package/dist/source/interfaces/alarms_and_conditions/instantiate_off_normal_alarm_options.d.ts +20 -20
  51. package/dist/source/interfaces/alarms_and_conditions/instantiate_off_normal_alarm_options.js +2 -2
  52. package/dist/source/interfaces/alarms_and_conditions/ua_acknowledgeable_condition_ex.d.ts +23 -23
  53. package/dist/source/interfaces/alarms_and_conditions/ua_acknowledgeable_condition_ex.js +2 -2
  54. package/dist/source/interfaces/alarms_and_conditions/ua_alarm_condition_ex.d.ts +32 -32
  55. package/dist/source/interfaces/alarms_and_conditions/ua_alarm_condition_ex.js +2 -2
  56. package/dist/source/interfaces/alarms_and_conditions/ua_certificate_expiration_alarm_ex.d.ts +19 -19
  57. package/dist/source/interfaces/alarms_and_conditions/ua_certificate_expiration_alarm_ex.js +2 -2
  58. package/dist/source/interfaces/alarms_and_conditions/ua_condition_ex.d.ts +42 -42
  59. package/dist/source/interfaces/alarms_and_conditions/ua_condition_ex.js +2 -2
  60. package/dist/source/interfaces/alarms_and_conditions/ua_discrete_alarm_ex.d.ts +7 -7
  61. package/dist/source/interfaces/alarms_and_conditions/ua_discrete_alarm_ex.js +25 -25
  62. package/dist/source/interfaces/alarms_and_conditions/ua_exclusive_deviation_alarm_ex.d.ts +5 -5
  63. package/dist/source/interfaces/alarms_and_conditions/ua_exclusive_deviation_alarm_ex.js +2 -2
  64. package/dist/source/interfaces/alarms_and_conditions/ua_exclusive_limit_alarm_ex.d.ts +20 -20
  65. package/dist/source/interfaces/alarms_and_conditions/ua_exclusive_limit_alarm_ex.js +2 -2
  66. package/dist/source/interfaces/alarms_and_conditions/ua_limit_alarm_ex.d.ts +26 -26
  67. package/dist/source/interfaces/alarms_and_conditions/ua_limit_alarm_ex.js +2 -2
  68. package/dist/source/interfaces/alarms_and_conditions/ua_non_exclusive_deviation_alarm_ex.d.ts +8 -8
  69. package/dist/source/interfaces/alarms_and_conditions/ua_non_exclusive_deviation_alarm_ex.js +2 -2
  70. package/dist/source/interfaces/alarms_and_conditions/ua_non_exclusive_limit_alarm_ex.d.ts +10 -10
  71. package/dist/source/interfaces/alarms_and_conditions/ua_non_exclusive_limit_alarm_ex.js +2 -2
  72. package/dist/source/interfaces/data_access/ua_multistate_discrete_ex.d.ts +21 -21
  73. package/dist/source/interfaces/data_access/ua_multistate_discrete_ex.js +2 -2
  74. package/dist/source/interfaces/data_access/ua_multistate_value_discrete_ex.d.ts +24 -24
  75. package/dist/source/interfaces/data_access/ua_multistate_value_discrete_ex.js +2 -2
  76. package/dist/source/interfaces/data_access/ua_two_state_discrete_ex.d.ts +12 -12
  77. package/dist/source/interfaces/data_access/ua_two_state_discrete_ex.js +2 -2
  78. package/dist/source/interfaces/data_access/ua_y_array_item_ex.d.ts +8 -8
  79. package/dist/source/interfaces/data_access/ua_y_array_item_ex.js +2 -2
  80. package/dist/source/interfaces/state_machine/ua_exclusive_limit_state_machine_type_ex.d.ts +12 -12
  81. package/dist/source/interfaces/state_machine/ua_exclusive_limit_state_machine_type_ex.js +2 -2
  82. package/dist/source/interfaces/state_machine/ua_finite_state_machine_type.d.ts +49 -49
  83. package/dist/source/interfaces/state_machine/ua_finite_state_machine_type.js +2 -2
  84. package/dist/source/interfaces/state_machine/ua_program_state_machine_type.d.ts +11 -11
  85. package/dist/source/interfaces/state_machine/ua_program_state_machine_type.js +2 -2
  86. package/dist/source/interfaces/state_machine/ua_shelved_state_machine_ex.d.ts +30 -30
  87. package/dist/source/interfaces/state_machine/ua_shelved_state_machine_ex.js +2 -2
  88. package/dist/source/interfaces/state_machine/ua_state_machine_type.d.ts +222 -222
  89. package/dist/source/interfaces/state_machine/ua_state_machine_type.js +2 -2
  90. package/dist/source/interfaces/state_machine/ua_transition_ex.d.ts +6 -6
  91. package/dist/source/interfaces/state_machine/ua_transition_ex.js +2 -2
  92. package/dist/source/interfaces/ua_subscription_diagnostics_variable_ex.d.ts +8 -8
  93. package/dist/source/interfaces/ua_subscription_diagnostics_variable_ex.js +2 -2
  94. package/dist/source/loader/decode_xml_extension_object.d.ts +6 -6
  95. package/dist/source/loader/decode_xml_extension_object.js +71 -71
  96. package/dist/source/loader/ensure_datatype_extracted.d.ts +5 -5
  97. package/dist/source/loader/ensure_datatype_extracted.js +45 -45
  98. package/dist/source/loader/generateAddressSpaceRaw.d.ts +10 -10
  99. package/dist/source/loader/generateAddressSpaceRaw.js +45 -45
  100. package/dist/source/loader/load_nodeset2.d.ts +16 -16
  101. package/dist/source/loader/load_nodeset2.js +1461 -1461
  102. package/dist/source/loader/make_semver_compatible.d.ts +6 -6
  103. package/dist/source/loader/make_semver_compatible.js +25 -25
  104. package/dist/source/loader/make_xml_extension_object_parser.d.ts +28 -28
  105. package/dist/source/loader/make_xml_extension_object_parser.js +325 -325
  106. package/dist/source/loader/namespace_post_step.d.ts +10 -10
  107. package/dist/source/loader/namespace_post_step.js +61 -61
  108. package/dist/source/loader/register_node_promoter.d.ts +2 -2
  109. package/dist/source/loader/register_node_promoter.js +9 -9
  110. package/dist/source/namespace.d.ts +6 -6
  111. package/dist/source/namespace.js +2 -2
  112. package/dist/source/namespace_alarm_and_condition.d.ts +32 -32
  113. package/dist/source/namespace_alarm_and_condition.js +2 -2
  114. package/dist/source/namespace_data_access.d.ts +42 -42
  115. package/dist/source/namespace_data_access.js +2 -2
  116. package/dist/source/namespace_machine_state.d.ts +7 -7
  117. package/dist/source/namespace_machine_state.js +2 -2
  118. package/dist/source/pseudo_session.d.ts +55 -55
  119. package/dist/source/pseudo_session.js +203 -203
  120. package/dist/source/session_context.d.ts +111 -111
  121. package/dist/source/session_context.js +265 -265
  122. package/dist/source/set_namespace_meta_data.d.ts +2 -2
  123. package/dist/source/set_namespace_meta_data.js +59 -59
  124. package/dist/source/ua_root_folder.d.ts +9 -9
  125. package/dist/source/ua_root_folder.js +2 -2
  126. package/dist/source/ua_two_state_variable_ex.d.ts +23 -23
  127. package/dist/source/ua_two_state_variable_ex.js +2 -2
  128. package/dist/source/xml_writer.d.ts +9 -9
  129. package/dist/source/xml_writer.js +2 -2
  130. package/dist/src/address_space.d.ts +392 -392
  131. package/dist/src/address_space.js +1392 -1392
  132. package/dist/src/address_space_change_event_tools.d.ts +6 -6
  133. package/dist/src/address_space_change_event_tools.js +149 -149
  134. package/dist/src/address_space_private.d.ts +43 -43
  135. package/dist/src/address_space_private.js +2 -2
  136. package/dist/src/alarms_and_conditions/check_where_clause.d.ts +4 -0
  137. package/dist/src/alarms_and_conditions/check_where_clause.js +110 -0
  138. package/dist/src/alarms_and_conditions/check_where_clause.js.map +1 -0
  139. package/dist/src/alarms_and_conditions/condition.d.ts +5 -5
  140. package/dist/src/alarms_and_conditions/condition.js +78 -78
  141. package/dist/src/alarms_and_conditions/condition_info.d.ts +27 -0
  142. package/dist/src/alarms_and_conditions/condition_info.js +55 -0
  143. package/dist/src/alarms_and_conditions/condition_info.js.map +1 -0
  144. package/dist/src/alarms_and_conditions/condition_info_impl.d.ts +26 -26
  145. package/dist/src/alarms_and_conditions/condition_info_impl.js +54 -54
  146. package/dist/src/alarms_and_conditions/condition_snapshot.d.ts +233 -0
  147. package/dist/src/alarms_and_conditions/condition_snapshot.js +667 -0
  148. package/dist/src/alarms_and_conditions/condition_snapshot.js.map +1 -0
  149. package/dist/src/alarms_and_conditions/condition_snapshot_impl.d.ts +222 -222
  150. package/dist/src/alarms_and_conditions/condition_snapshot_impl.js +657 -657
  151. package/dist/src/alarms_and_conditions/deviation_alarm_helper.d.ts +9 -9
  152. package/dist/src/alarms_and_conditions/deviation_alarm_helper.js +61 -61
  153. package/dist/src/alarms_and_conditions/extract_event_fields.d.ts +10 -0
  154. package/dist/src/alarms_and_conditions/extract_event_fields.js +90 -0
  155. package/dist/src/alarms_and_conditions/extract_event_fields.js.map +1 -0
  156. package/dist/src/alarms_and_conditions/index.d.ts +16 -16
  157. package/dist/src/alarms_and_conditions/index.js +32 -32
  158. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.d.ts +44 -44
  159. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js +244 -244
  160. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.d.ts +93 -93
  161. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js +419 -419
  162. package/dist/src/alarms_and_conditions/ua_base_event_impl.d.ts +26 -26
  163. package/dist/src/alarms_and_conditions/ua_base_event_impl.js +38 -38
  164. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.d.ts +44 -44
  165. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.js +183 -183
  166. package/dist/src/alarms_and_conditions/ua_condition_impl.d.ts +153 -153
  167. package/dist/src/alarms_and_conditions/ua_condition_impl.js +1028 -1028
  168. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.d.ts +14 -14
  169. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.js +34 -34
  170. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.d.ts +24 -24
  171. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.js +56 -56
  172. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.d.ts +11 -11
  173. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.js +11 -11
  174. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.d.ts +23 -23
  175. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.js +86 -86
  176. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm_impl.d.ts +11 -11
  177. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm_impl.js +7 -7
  178. package/dist/src/alarms_and_conditions/ua_limit_alarm_impl.d.ts +79 -79
  179. package/dist/src/alarms_and_conditions/ua_limit_alarm_impl.js +250 -250
  180. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.d.ts +24 -24
  181. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.js +50 -50
  182. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.d.ts +19 -19
  183. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.js +162 -162
  184. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.d.ts +46 -46
  185. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js +166 -166
  186. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.d.ts +18 -18
  187. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.js +17 -17
  188. package/dist/src/apply_condition_refresh.d.ts +6 -6
  189. package/dist/src/apply_condition_refresh.js +27 -27
  190. package/dist/src/base_node_impl.d.ts +281 -281
  191. package/dist/src/base_node_impl.js +1395 -1395
  192. package/dist/src/base_node_private.d.ts +61 -61
  193. package/dist/src/base_node_private.js +705 -705
  194. package/dist/src/data_access/add_dataItem_stuff.d.ts +11 -11
  195. package/dist/src/data_access/add_dataItem_stuff.js +61 -61
  196. package/dist/src/data_access/check_variant_compatibility_ua_analog_item.d.ts +1 -1
  197. package/dist/src/data_access/check_variant_compatibility_ua_analog_item.js +34 -34
  198. package/dist/src/data_access/ua_multistate_discrete_impl.d.ts +32 -32
  199. package/dist/src/data_access/ua_multistate_discrete_impl.js +130 -130
  200. package/dist/src/data_access/ua_multistate_value_discrete.d.ts +51 -0
  201. package/dist/src/data_access/ua_multistate_value_discrete.js +250 -0
  202. package/dist/src/data_access/ua_multistate_value_discrete.js.map +1 -0
  203. package/dist/src/data_access/ua_multistate_value_discrete_impl.d.ts +51 -51
  204. package/dist/src/data_access/ua_multistate_value_discrete_impl.js +249 -249
  205. package/dist/src/data_access/ua_two_state_discrete.d.ts +25 -0
  206. package/dist/src/data_access/ua_two_state_discrete.js +154 -0
  207. package/dist/src/data_access/ua_two_state_discrete.js.map +1 -0
  208. package/dist/src/data_access/ua_two_state_discrete_impl.d.ts +25 -25
  209. package/dist/src/data_access/ua_two_state_discrete_impl.js +153 -153
  210. package/dist/src/event_data.d.ts +34 -34
  211. package/dist/src/event_data.js +64 -64
  212. package/dist/src/extension_object_array_node.d.ts +61 -61
  213. package/dist/src/extension_object_array_node.js +276 -276
  214. package/dist/src/historical_access/address_space_historical_data_node.d.ts +26 -26
  215. package/dist/src/historical_access/address_space_historical_data_node.js +630 -630
  216. package/dist/src/index_current.d.ts +43 -43
  217. package/dist/src/index_current.js +74 -74
  218. package/dist/src/namespace_impl.d.ts +461 -461
  219. package/dist/src/namespace_impl.js +1732 -1732
  220. package/dist/src/namespace_private.d.ts +21 -21
  221. package/dist/src/namespace_private.js +32 -32
  222. package/dist/src/nodeid_manager.d.ts +36 -36
  223. package/dist/src/nodeid_manager.js +197 -197
  224. package/dist/src/nodeset_tools/adjust_namespace_array.d.ts +2 -2
  225. package/dist/src/nodeset_tools/adjust_namespace_array.js +13 -13
  226. package/dist/src/nodeset_tools/construct_namespace_dependency.d.ts +2 -2
  227. package/dist/src/nodeset_tools/construct_namespace_dependency.js +83 -83
  228. package/dist/src/nodeset_tools/nodeset_to_xml.d.ts +2 -2
  229. package/dist/src/nodeset_tools/nodeset_to_xml.js +1155 -1155
  230. package/dist/src/nodeset_tools/typedictionary_to_xml.d.ts +2 -2
  231. package/dist/src/nodeset_tools/typedictionary_to_xml.js +154 -154
  232. package/dist/src/reference_impl.d.ts +43 -43
  233. package/dist/src/reference_impl.js +139 -139
  234. package/dist/src/role_permissions.d.ts +2 -2
  235. package/dist/src/role_permissions.js +10 -10
  236. package/dist/src/state_machine/finite_state_machine.d.ts +67 -67
  237. package/dist/src/state_machine/finite_state_machine.js +353 -353
  238. package/dist/src/state_machine/ua_shelving_state_machine_ex.d.ts +38 -38
  239. package/dist/src/state_machine/ua_shelving_state_machine_ex.js +250 -250
  240. package/dist/src/state_machine/ua_two_state_variable.d.ts +61 -61
  241. package/dist/src/state_machine/ua_two_state_variable.js +331 -331
  242. package/dist/src/tool_isSupertypeOf.d.ts +17 -17
  243. package/dist/src/tool_isSupertypeOf.js +108 -108
  244. package/dist/src/ua_condition_type.d.ts +8 -8
  245. package/dist/src/ua_condition_type.js +2 -2
  246. package/dist/src/ua_data_type_impl.d.ts +93 -93
  247. package/dist/src/ua_data_type_impl.js +371 -371
  248. package/dist/src/ua_method_impl.d.ts +41 -41
  249. package/dist/src/ua_method_impl.js +208 -208
  250. package/dist/src/ua_object_impl.d.ts +35 -35
  251. package/dist/src/ua_object_impl.js +161 -161
  252. package/dist/src/ua_object_type_impl.d.ts +48 -48
  253. package/dist/src/ua_object_type_impl.js +124 -124
  254. package/dist/src/ua_reference_type_impl.d.ts +43 -43
  255. package/dist/src/ua_reference_type_impl.js +139 -139
  256. package/dist/src/ua_variable_impl.d.ts +351 -351
  257. package/dist/src/ua_variable_impl.js +1604 -1604
  258. package/dist/src/ua_variable_impl_ext_obj.d.ts +17 -17
  259. package/dist/src/ua_variable_impl_ext_obj.js +437 -437
  260. package/dist/src/ua_variable_type_impl.d.ts +62 -62
  261. package/dist/src/ua_variable_type_impl.js +570 -570
  262. package/dist/src/ua_view_impl.d.ts +19 -19
  263. package/dist/src/ua_view_impl.js +43 -43
  264. package/distHelpers/add_event_generator_object.d.ts +3 -3
  265. package/distHelpers/add_event_generator_object.js +64 -64
  266. package/distHelpers/alarms_and_conditions_demo.d.ts +9 -9
  267. package/distHelpers/alarms_and_conditions_demo.js +115 -115
  268. package/distHelpers/assertHasMatchingReference.d.ts +19 -19
  269. package/distHelpers/assertHasMatchingReference.js +40 -40
  270. package/distHelpers/boiler_system.d.ts +113 -113
  271. package/distHelpers/boiler_system.js +395 -395
  272. package/distHelpers/create_minimalist_address_space_nodeset.d.ts +5 -5
  273. package/distHelpers/create_minimalist_address_space_nodeset.js +171 -171
  274. package/distHelpers/date_utils.d.ts +3 -3
  275. package/distHelpers/date_utils.js +9 -9
  276. package/distHelpers/dump_statemachine.js +127 -127
  277. package/distHelpers/get_address_space_fixture.d.ts +1 -1
  278. package/distHelpers/get_address_space_fixture.js +30 -30
  279. package/distHelpers/get_mini_address_space.d.ts +7 -7
  280. package/distHelpers/get_mini_address_space.js +36 -36
  281. package/distHelpers/index.d.ts +12 -12
  282. package/distHelpers/index.js +28 -28
  283. package/distHelpers/mock_session.d.ts +14 -14
  284. package/distHelpers/mock_session.js +25 -25
  285. package/distNodeJS/generate_address_space.d.ts +4 -4
  286. package/distNodeJS/generate_address_space.js +41 -41
  287. package/distNodeJS/index.d.ts +1 -1
  288. package/distNodeJS/index.js +17 -17
  289. package/package.json +36 -35
@@ -1,1393 +1,1393 @@
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 hasProperty = (data, propertyName) => Object.prototype.hasOwnProperty.call(data, propertyName);
640
- const visitedProperties = {};
641
- const alreadyVisited = (key) => Object.prototype.hasOwnProperty.call(visitedProperties, key);
642
- const markAsVisited = (key) => visitedProperties[key] = 1;
643
- function _process_var(self, prefixLower, prefixStandard, node) {
644
- const lowerName = prefixLower + (0, node_opcua_utils_1.lowerFirstLetter)(node.browseName.name);
645
- const fullBrowsePath = prefixStandard + node.browseName.toString();
646
- if (alreadyVisited(lowerName)) {
647
- return;
648
- }
649
- markAsVisited(lowerName);
650
- if (hasProperty(data, lowerName)) {
651
- eventData._createValue(fullBrowsePath, node, data[lowerName]);
652
- }
653
- else {
654
- // add a property , but with a null variant
655
- eventData._createValue(fullBrowsePath, node, { dataType: node_opcua_variant_1.DataType.Null });
656
- if (doDebug) {
657
- if (node.modellingRule === "Mandatory") {
658
- // tslint:disable:no-console
659
- console.log(chalk.red("ERROR : AddressSpace#constructEventData(eventType,options) " + "cannot find property ") +
660
- self.browseName.toString() +
661
- " => " +
662
- chalk.cyan(lowerName));
663
- }
664
- else {
665
- console.log(chalk.yellow("Warning : AddressSpace#constructEventData(eventType,options)" + " cannot find property ") +
666
- self.browseName.toString() +
667
- " => " +
668
- chalk.cyan(lowerName));
669
- }
670
- }
671
- }
672
- }
673
- // verify that all elements of data are valid
674
- function verify_data_is_valid(data1) {
675
- Object.keys(data1).map((k) => {
676
- if (k === "$eventDataSource") {
677
- return;
678
- }
679
- /* istanbul ignore next */
680
- if (!alreadyVisited(k)) {
681
- throw new Error(" cannot find property '" +
682
- k +
683
- "' in [ " +
684
- Object.keys(visitedProperties).join(", ") +
685
- "] when filling " +
686
- eventTypeNode.browseName.toString());
687
- }
688
- });
689
- }
690
- const populate_data = (self, eventData1) => {
691
- if ((0, node_opcua_nodeid_1.sameNodeId)(baseObjectType.nodeId, self.nodeId)) {
692
- return; // nothing to do
693
- }
694
- const baseTypeNodeId = self.subtypeOf;
695
- /* istanbul ignore next */
696
- if (!baseTypeNodeId) {
697
- throw new Error("Object " + self.browseName.toString() + " with nodeId " + self.nodeId + " has no Type");
698
- }
699
- const baseType = this.findNode(baseTypeNodeId);
700
- /* istanbul ignore next */
701
- if (!baseType) {
702
- throw new Error(chalk.red("Cannot find object with nodeId ") + baseTypeNodeId);
703
- }
704
- populate_data(baseType, eventData1);
705
- // get properties and components from base class
706
- const properties = self.getProperties();
707
- const components = self.getComponents();
708
- const children = [].concat(properties, components);
709
- // istanbul ignore next
710
- if (doDebug) {
711
- console.log(" " + chalk.bgWhite.cyan(self.browseName.toString()));
712
- }
713
- for (const node of children) {
714
- // only keep those that have a "HasModellingRule"
715
- if (!node.modellingRule) {
716
- // xx console.log(" skipping node without modelling rule", node.browseName.toString());
717
- continue;
718
- }
719
- // ignore also methods
720
- if (node.nodeClass === node_opcua_data_model_1.NodeClass.Method) {
721
- // xx console.log(" skipping method ", node.browseName.toString());
722
- continue;
723
- }
724
- _process_var(self, "", "", node);
725
- // also store value in index
726
- // xx eventData.__nodes[node.nodeId.toString()] = eventData[lowerName];
727
- const children2 = node.getAggregates();
728
- if (children2.length > 0) {
729
- const lowerName = (0, node_opcua_utils_1.lowerFirstLetter)(node.browseName.name);
730
- const standardName = node.browseName.toString();
731
- // console.log(" Children to visit = ",lowerName,
732
- // children.map(function(a){ return a.browseName.toString();}).join(" "));
733
- for (const child2 of children2) {
734
- _process_var(self, lowerName + ".", standardName + ".", child2);
735
- }
736
- }
737
- }
738
- };
739
- const eventData = new event_data_1.EventData(eventTypeNode);
740
- // verify standard properties...
741
- populate_data(eventTypeNode, eventData);
742
- verify_data_is_valid(data);
743
- return eventData;
744
- }
745
- // - Browse --------------------------------------------------------------------------------------------------------
746
- /**
747
- * browse some path.
748
- *
749
- * @method browsePath
750
- * @param {BrowsePath} browsePath
751
- * @return {BrowsePathResult}
752
- *
753
- * This service can be used translates one or more browse paths into NodeIds.
754
- * A browse path is constructed of a starting Node and a RelativePath. The specified starting Node
755
- * identifies the Node from which the RelativePath is based. The RelativePath contains a sequence of
756
- * ReferenceTypes and BrowseNames.
757
- *
758
- * |StatusCode | |
759
- * |------------------------------|:-----------------------------------------------------------|
760
- * |BadNodeIdUnknown | |
761
- * |BadNodeIdInvalid | |
762
- * |BadNothingToDo | - the relative path contains an empty list ) |
763
- * |BadBrowseNameInvalid | - target name is missing in relative path |
764
- * |UncertainReferenceOutOfServer | - The path element has targets which are in another server.|
765
- * |BadTooManyMatches | |
766
- * |BadQueryTooComplex | |
767
- * |BadNoMatch | |
768
- *
769
- *
770
- *
771
- */
772
- browsePath(browsePath) {
773
- (0, node_opcua_assert_1.assert)(browsePath instanceof node_opcua_types_1.BrowsePath);
774
- const startingNode = this.findNode(browsePath.startingNode);
775
- if (!startingNode) {
776
- return new node_opcua_types_1.BrowsePathResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadNodeIdUnknown });
777
- }
778
- if (!browsePath.relativePath.elements || browsePath.relativePath.elements.length === 0) {
779
- return new node_opcua_types_1.BrowsePathResult({
780
- statusCode: node_opcua_status_code_1.StatusCodes.BadNothingToDo,
781
- targets: []
782
- });
783
- }
784
- const elements_length = browsePath.relativePath.elements.length;
785
- // -------------------------------------------------------------------------------------------------------
786
- // verify standard RelativePath construction
787
- // from OPCUA 1.03 - PArt 3 - 7.6 RelativePath:
788
- // TargetName The BrowseName of the target node.
789
- // The final element may have an empty targetName. In this situation all targets of the
790
- // references identified by the referenceTypeId are the targets of the RelativePath.
791
- // The targetName shall be specified for all other elements.
792
- // The current path cannot be followed any further if no targets with the specified
793
- // BrowseName exist.
794
- // Let's detect null targetName which are not in last position and return BadBrowseNameInvalid if not
795
- //
796
- const empty_targetName_not_in_lastPos = browsePath.relativePath.elements.reduce((prev, e, index) => {
797
- const is_last = index + 1 === elements_length;
798
- const isBad = !is_last && (!e.targetName || e.targetName.isEmpty());
799
- return prev + (!is_last && (!e.targetName || e.targetName.isEmpty()) ? 1 : 0);
800
- }, 0);
801
- if (empty_targetName_not_in_lastPos) {
802
- return new node_opcua_types_1.BrowsePathResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadBrowseNameInvalid });
803
- }
804
- // from OPCUA 1.03 - PArt 3 - 5.8.4 TranslateBrowsePathToNodeIds
805
- // TranslateBrowsePathToNodeIds further restrict RelativePath targetName rules:
806
- // The last element in the relativePath shall always have a targetName specified.
807
- const last_el = browsePath.relativePath.elements[elements_length - 1];
808
- if (!last_el.targetName || !last_el.targetName.name || last_el.targetName.name.length === 0) {
809
- return new node_opcua_types_1.BrowsePathResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadBrowseNameInvalid });
810
- }
811
- const res = [];
812
- const explore_element = (curNodeObject, elements, index) => {
813
- const element = elements[index];
814
- (0, node_opcua_assert_1.assert)(element instanceof node_opcua_types_1.RelativePathElement);
815
- const is_last = index + 1 === elements.length;
816
- const nodeIds = curNodeObject.browseNodeByTargetName(element, is_last);
817
- const targets = nodeIds.map((nodeId) => {
818
- return {
819
- remainingPathIndex: elements.length - index,
820
- targetId: nodeId
821
- };
822
- });
823
- if (!is_last) {
824
- // explorer
825
- for (const target of targets) {
826
- const node = this.findNode(target.targetId);
827
- if (!node) {
828
- continue;
829
- }
830
- explore_element(node, elements, index + 1);
831
- }
832
- }
833
- else {
834
- for (const target of targets) {
835
- res.push({
836
- remainingPathIndex: 0xffffffff,
837
- targetId: (0, node_opcua_nodeid_1.coerceExpandedNodeId)(target.targetId)
838
- });
839
- }
840
- }
841
- };
842
- explore_element(startingNode, browsePath.relativePath.elements, 0);
843
- if (res.length === 0) {
844
- return new node_opcua_types_1.BrowsePathResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadNoMatch });
845
- }
846
- return new node_opcua_types_1.BrowsePathResult({
847
- statusCode: node_opcua_status_code_1.StatusCodes.Good,
848
- targets: res
849
- });
850
- }
851
- // - Extension Object ----------------------------------------------------------------------------------------------
852
- getExtensionObjectConstructor(dataType) {
853
- (0, node_opcua_assert_1.assert)(dataType, "expecting a dataType");
854
- if (dataType instanceof node_opcua_nodeid_1.NodeId) {
855
- const tmp = this.findNode(dataType);
856
- /* istanbul ignore next */
857
- if (!tmp) {
858
- throw new Error("getExtensionObjectConstructor: cannot resolve dataType " + dataType);
859
- }
860
- dataType = tmp;
861
- }
862
- /* istanbul ignore next */
863
- if (!(dataType instanceof ua_data_type_impl_1.UADataTypeImpl)) {
864
- // may be dataType was the NodeId of the "Binary Encoding" node
865
- throw new Error("getExtensionObjectConstructor: dataType has unexpected type" + dataType);
866
- }
867
- const _dataType = dataType;
868
- // to do verify that dataType is of type "Structure"
869
- /* istanbul ignore next */
870
- if (!_dataType.isSupertypeOf(this.findDataType("Structure"))) {
871
- console.log(_dataType.toString());
872
- }
873
- (0, node_opcua_assert_1.assert)(_dataType.isSupertypeOf(this.findDataType("Structure")));
874
- if (!_dataType._extensionObjectConstructor) {
875
- const dataTypeManager = this.$$extraDataTypeManager;
876
- _dataType._extensionObjectConstructor = dataTypeManager.getExtensionObjectConstructorFromDataType(_dataType.nodeId);
877
- }
878
- (0, node_opcua_assert_1.assert)(_dataType._extensionObjectConstructor, "dataType must have a constructor");
879
- const Constructor = _dataType._extensionObjectConstructor;
880
- return Constructor;
881
- }
882
- /**
883
- * @param dataType
884
- * @param [options]
885
- * @return the constructed extension object
886
- *
887
- *
888
- * @example
889
- *
890
- * // example 1
891
- * var extObj = addressSpace.constructExtensionObject("BuildInfo",{ productName: "PRODUCT_NAME"});
892
- *
893
- * // example 2
894
- * serverStatusDataType.nodeClass.should.eql(NodeClass.DataType);
895
- * serverStatusDataType.browseName.toString().should.eql("ServerStatusDataType");
896
- * var serverStatus = addressSpace.constructExtensionObject(serverStatusDataType);
897
- * serverStatus.constructor.name.should.eql("ServerStatusDataType");
898
- */
899
- constructExtensionObject(dataType, options) {
900
- const Constructor = this.getExtensionObjectConstructor(dataType);
901
- return new Constructor(options);
902
- }
903
- /**
904
- * cleanup all resources maintained by this addressSpace.
905
- * @method dispose
906
- */
907
- dispose() {
908
- this._namespaceArray.map((namespace) => namespace.dispose());
909
- AddressSpace.registry.unregister(this);
910
- /* istanbul ignore next */
911
- if (this._shutdownTask && this._shutdownTask.length > 0) {
912
- throw new Error("AddressSpace#dispose : shutdown has not been called");
913
- }
914
- }
915
- /**
916
- * register a function that will be called when the server will perform its shut down.
917
- * @method registerShutdownTask
918
- */
919
- registerShutdownTask(task) {
920
- this._shutdownTask = this._shutdownTask || [];
921
- (0, node_opcua_assert_1.assert)(typeof task === "function");
922
- this._shutdownTask.push(task);
923
- }
924
- shutdown() {
925
- return __awaiter(this, void 0, void 0, function* () {
926
- if (!this._shutdownTask) {
927
- return;
928
- }
929
- const tasks = this._shutdownTask;
930
- this._shutdownTask = [];
931
- // perform registerShutdownTask
932
- for (const task of tasks) {
933
- yield task.call(this);
934
- }
935
- });
936
- }
937
- /**
938
- *
939
- * @method browseSingleNode
940
- * @param nodeId {NodeId|String} : the nodeid of the element to browse
941
- * @param browseDescription
942
- * @param browseDescription.browseDirection {BrowseDirection} :
943
- * @param browseDescription.referenceTypeId {String|NodeId}
944
- * @param [session]
945
- * @return {BrowseResult}
946
- */
947
- browseSingleNode(nodeId, browseDescription, context) {
948
- const browseResult = {
949
- continuationPoint: undefined,
950
- references: null,
951
- statusCode: node_opcua_status_code_1.StatusCodes.Good
952
- };
953
- if (!browseDescription || browseDescription.browseDirection === node_opcua_data_model_1.BrowseDirection.Invalid) {
954
- browseResult.statusCode = node_opcua_status_code_1.StatusCodes.BadBrowseDirectionInvalid;
955
- return new node_opcua_service_browse_1.BrowseResult(browseResult);
956
- }
957
- browseDescription.browseDirection = (0, adjust_browse_direction_1.adjustBrowseDirection)(browseDescription.browseDirection, node_opcua_data_model_1.BrowseDirection.Forward);
958
- /* istanbul ignore next */
959
- if (typeof nodeId === "number") {
960
- throw new Error("Not Implemented");
961
- }
962
- if (typeof nodeId === "string") {
963
- const node = this.findNode(this.resolveNodeId(nodeId));
964
- if (node) {
965
- nodeId = node.nodeId;
966
- }
967
- }
968
- // check if referenceTypeId is correct
969
- if (browseDescription.referenceTypeId instanceof node_opcua_nodeid_1.NodeId) {
970
- if (browseDescription.referenceTypeId.value === 0) {
971
- browseDescription.referenceTypeId = null;
972
- }
973
- else {
974
- const rf = this.findNode(browseDescription.referenceTypeId);
975
- if (!rf || !(rf instanceof ua_reference_type_impl_1.UAReferenceTypeImpl)) {
976
- browseResult.statusCode = node_opcua_status_code_1.StatusCodes.BadReferenceTypeIdInvalid;
977
- return new node_opcua_service_browse_1.BrowseResult(browseResult);
978
- }
979
- }
980
- }
981
- const obj = this.findNode(nodeId);
982
- if (!obj) {
983
- // Object Not Found
984
- browseResult.statusCode = node_opcua_status_code_1.StatusCodes.BadNodeIdUnknown;
985
- // xx console.log("xxxxxx browsing ",nodeId.toString() , " not found" );
986
- }
987
- else {
988
- browseResult.statusCode = node_opcua_status_code_1.StatusCodes.Good;
989
- browseResult.references = obj.browseNode(browseDescription, context);
990
- }
991
- return new node_opcua_service_browse_1.BrowseResult(browseResult);
992
- }
993
- /**
994
- * @param folder
995
- * @private
996
- */
997
- _coerceFolder(folder) {
998
- folder = this._coerceNode(folder);
999
- /* istanbul ignore next */
1000
- if (folder && !_isFolder(this, folder)) {
1001
- throw new Error("Parent folder must be of FolderType " + folder.typeDefinition.toString());
1002
- }
1003
- return folder;
1004
- }
1005
- /**
1006
- *
1007
- * @param view
1008
- * @param modelChange
1009
- * @private
1010
- */
1011
- _collectModelChange(view, modelChange) {
1012
- // xx console.log("in _collectModelChange", modelChange.verb, verbFlags.get(modelChange.verb).toString());
1013
- this._modelChanges.push(modelChange);
1014
- }
1015
- /**
1016
- *
1017
- * walk up the hierarchy of objects until a view is found
1018
- * objects may belong to multiples views.
1019
- * Note: this method doesn't return the main view => Server object.
1020
- * @method extractRootViews
1021
- * @param node {BaseNode}
1022
- * @return {BaseNode[]}
1023
- */
1024
- /**
1025
- *
1026
- * @param node
1027
- * @private
1028
- */
1029
- extractRootViews(node) {
1030
- (0, node_opcua_assert_1.assert)(node.nodeClass === node_opcua_data_model_1.NodeClass.Object || node.nodeClass === node_opcua_data_model_1.NodeClass.Variable);
1031
- const visitedMap = {};
1032
- const q = new Dequeue();
1033
- q.push(node);
1034
- const objectsFolder = this.rootFolder.objects;
1035
- (0, node_opcua_assert_1.assert)(objectsFolder instanceof ua_object_impl_1.UAObjectImpl);
1036
- const results = [];
1037
- while (q.length) {
1038
- node = q.shift();
1039
- const references = node.findReferencesEx("HierarchicalReferences", node_opcua_data_model_1.BrowseDirection.Inverse);
1040
- const parentNodes = references.map((r) => reference_impl_1.ReferenceImpl.resolveReferenceNode(this, r));
1041
- for (const parent of parentNodes) {
1042
- if ((0, node_opcua_nodeid_1.sameNodeId)(parent.nodeId, objectsFolder.nodeId)) {
1043
- continue; // nothing to do
1044
- }
1045
- if (parent.nodeClass === node_opcua_data_model_1.NodeClass.View) {
1046
- results.push(parent);
1047
- }
1048
- else {
1049
- const key = parent.nodeId.toString();
1050
- if (Object.prototype.hasOwnProperty.call(visitedMap, key)) {
1051
- continue;
1052
- }
1053
- visitedMap[key] = parent;
1054
- q.push(parent);
1055
- }
1056
- }
1057
- }
1058
- return results;
1059
- }
1060
- /**
1061
- *
1062
- * @param func
1063
- * @private
1064
- */
1065
- modelChangeTransaction(func) {
1066
- this._modelChangeTransactionCounter = this._modelChangeTransactionCounter || 0;
1067
- function beginModelChange() {
1068
- /* jshint validthis:true */
1069
- (0, node_opcua_assert_1.assert)(this);
1070
- this._modelChanges = this._modelChanges || [];
1071
- (0, node_opcua_assert_1.assert)(this._modelChangeTransactionCounter >= 0);
1072
- this._modelChangeTransactionCounter += 1;
1073
- }
1074
- function endModelChange() {
1075
- /* jshint validthis:true */
1076
- this._modelChangeTransactionCounter -= 1;
1077
- if (this._modelChangeTransactionCounter === 0) {
1078
- if (this._modelChanges.length === 0) {
1079
- return; // nothing to do
1080
- }
1081
- // xx console.log( "xx dealing with ",this._modelChanges.length);
1082
- // increase version number of participating nodes
1083
- // https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore
1084
- // const nodeIds = _.uniq(this._modelChanges.map((c: any) => c.affected));
1085
- const nodeIds = [...new Set(this._modelChanges.map((c) => c.affected))];
1086
- const nodes = nodeIds.map((nodeId) => this.findNode(nodeId));
1087
- nodes.forEach(_increase_version_number);
1088
- // raise events
1089
- if (this.rootFolder.objects.server) {
1090
- const eventTypeNode = this.findEventType("GeneralModelChangeEventType");
1091
- if (eventTypeNode) {
1092
- // xx console.log("xx raising event on server object");
1093
- this.rootFolder.objects.server.raiseEvent(eventTypeNode, {
1094
- // Part 5 - 6.4.32 GeneralModelChangeEventType
1095
- changes: {
1096
- dataType: node_opcua_variant_1.DataType.ExtensionObject,
1097
- arrayType: node_opcua_variant_1.VariantArrayType.Array,
1098
- value: this._modelChanges
1099
- }
1100
- });
1101
- }
1102
- }
1103
- this._modelChanges = [];
1104
- // _notifyModelChange(this);
1105
- }
1106
- }
1107
- beginModelChange.call(this);
1108
- try {
1109
- func();
1110
- }
1111
- catch (err) {
1112
- errorLog("modelChangeTransaction", err === null || err === void 0 ? void 0 : err.message);
1113
- throw err;
1114
- }
1115
- finally {
1116
- endModelChange.call(this);
1117
- }
1118
- }
1119
- /**
1120
- * normalize the ReferenceType field of the Reference Object
1121
- * @param params.referenceType {String|nodeId}
1122
- * @param params.isForward {Boolean} default value: true;
1123
- * @return {Object} a new reference object with the normalized name { referenceType: <value>, isForward: <flag>}
1124
- */
1125
- normalizeReferenceType(params) {
1126
- if (params instanceof reference_impl_1.ReferenceImpl) {
1127
- // a reference has already been normalized
1128
- return params;
1129
- }
1130
- // ----------------------------------------------- handle is forward
1131
- (0, node_opcua_assert_1.assert)(params.isForward === undefined || typeof params.isForward === "boolean");
1132
- params.isForward = utils.isNullOrUndefined(params.isForward) ? true : !!params.isForward;
1133
- // referenceType = Organizes , isForward = true => referenceType = Organizes , isForward = true
1134
- // referenceType = Organizes , isForward = false => referenceType = Organizes , isForward = false
1135
- // referenceType = OrganizedBy , isForward = true => referenceType = Organizes , isForward = **false**
1136
- // referenceType = OrganizedBy , isForward = false => referenceType = Organizes , isForward = **true**
1137
- // ----------------------------------------------- handle referenceType
1138
- if (params.referenceType instanceof ua_reference_type_impl_1.UAReferenceTypeImpl) {
1139
- params.referenceType = params.referenceType;
1140
- params.referenceType = params.referenceType.nodeId;
1141
- }
1142
- else if (typeof params.referenceType === "string") {
1143
- const inv = this.findReferenceTypeFromInverseName(params.referenceType);
1144
- if (inv) {
1145
- params.referenceType = inv.nodeId;
1146
- params._referenceType = inv;
1147
- params.isForward = !params.isForward;
1148
- }
1149
- else {
1150
- params.referenceType = (0, node_opcua_nodeid_1.resolveNodeId)(params.referenceType);
1151
- const refType = this.findReferenceType(params.referenceType);
1152
- if (refType) {
1153
- params._referenceType = refType;
1154
- }
1155
- }
1156
- }
1157
- (0, node_opcua_assert_1.assert)(params.referenceType instanceof node_opcua_nodeid_1.NodeId);
1158
- // ----------- now resolve target NodeId;
1159
- if (params.nodeId instanceof base_node_impl_1.BaseNodeImpl) {
1160
- (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(params, "node"));
1161
- params.node = params.nodeId;
1162
- params.nodeId = params.node.nodeId;
1163
- }
1164
- else {
1165
- let _nodeId = params.nodeId;
1166
- (0, node_opcua_assert_1.assert)(!!_nodeId, "missing 'nodeId' in reference");
1167
- if (_nodeId && _nodeId.nodeId) {
1168
- _nodeId = _nodeId.nodeId;
1169
- }
1170
- _nodeId = (0, node_opcua_nodeid_1.resolveNodeId)(_nodeId);
1171
- /* istanbul ignore next */
1172
- if (!(_nodeId instanceof node_opcua_nodeid_1.NodeId) || _nodeId.isEmpty()) {
1173
- // tslint:disable:no-console
1174
- console.log("xx =>", JSON.stringify(params, null, " "));
1175
- throw new Error(" Invalid reference nodeId " + _nodeId.toString());
1176
- }
1177
- params.nodeId = _nodeId;
1178
- }
1179
- return new reference_impl_1.ReferenceImpl(params);
1180
- }
1181
- /**
1182
- *
1183
- * @param references
1184
- */
1185
- normalizeReferenceTypes(references) {
1186
- if (!references || references.length === 0) {
1187
- return [];
1188
- }
1189
- references = references;
1190
- (0, node_opcua_assert_1.assert)(Array.isArray(references));
1191
- return references.map((el) => this.normalizeReferenceType(el));
1192
- }
1193
- // -- Historical Node -----------------------------------------------------------------------------------------
1194
- /**
1195
- *
1196
- * @param node
1197
- * @param options
1198
- */
1199
- installHistoricalDataNode(node, options) {
1200
- address_space_historical_data_node_1.AddressSpace_installHistoricalDataNode.call(this, node, options);
1201
- }
1202
- // -- Alarms & Conditions -----------------------------------------------------------------------------------------
1203
- /**
1204
- *
1205
- */
1206
- installAlarmsAndConditionsService() {
1207
- alarms_and_conditions_1.UAConditionImpl.install_condition_refresh_handle(this);
1208
- alarms_and_conditions_1.UAAcknowledgeableConditionImpl.install_method_handle_on_type(this);
1209
- }
1210
- // -- internal stuff -----------------------------------------------------------------------------------------------
1211
- _coerceNode(node) {
1212
- function hasTypeDefinition(node1) {
1213
- return (node1.nodeClass === node_opcua_data_model_1.NodeClass.Variable ||
1214
- node1.nodeClass === node_opcua_data_model_1.NodeClass.Object ||
1215
- node1.nodeClass === node_opcua_data_model_1.NodeClass.Method);
1216
- }
1217
- // coerce to BaseNode object
1218
- if (node instanceof base_node_impl_1.BaseNodeImpl) {
1219
- return node;
1220
- }
1221
- // it's a node id like
1222
- // coerce parent folder to an object
1223
- const returnValue = this.findNode((0, node_opcua_nodeid_1.resolveNodeId)(node));
1224
- /*
1225
- if (!hasTypeDefinition(node as BaseNode)) {
1226
- node = this.findNode(node.nodeId) || node;
1227
- if (!node || !hasTypeDefinition(node)) {
1228
- return null;
1229
- }
1230
- }
1231
- */
1232
- return returnValue;
1233
- }
1234
- _coerce_DataType(dataType) {
1235
- if (dataType instanceof node_opcua_nodeid_1.NodeId) {
1236
- // xx assert(self.findDataType(dataType));
1237
- return dataType;
1238
- }
1239
- return this._coerce_Type(dataType, node_opcua_constants_1.DataTypeIds, "DataTypeIds", AddressSpace.prototype.findDataType);
1240
- }
1241
- _coerceTypeDefinition(typeDefinition) {
1242
- if (typeof typeDefinition === "string") {
1243
- // coerce parent folder to an node
1244
- const typeDefinitionNode = this.findNode(typeDefinition);
1245
- typeDefinition = typeDefinitionNode.nodeId;
1246
- }
1247
- // xx console.log("typeDefinition = ",typeDefinition);
1248
- (0, node_opcua_assert_1.assert)(typeDefinition instanceof node_opcua_nodeid_1.NodeId);
1249
- return typeDefinition;
1250
- }
1251
- _coerceType(baseType, topMostBaseType, nodeClass) {
1252
- (0, node_opcua_assert_1.assert)(typeof topMostBaseType === "string");
1253
- const topMostBaseTypeNode = this.findNode(topMostBaseType);
1254
- /* istanbul ignore next */
1255
- if (!topMostBaseTypeNode) {
1256
- throw new Error("Cannot find topMostBaseTypeNode " + topMostBaseType.toString());
1257
- }
1258
- (0, node_opcua_assert_1.assert)(topMostBaseTypeNode instanceof base_node_impl_1.BaseNodeImpl);
1259
- (0, node_opcua_assert_1.assert)(topMostBaseTypeNode.nodeClass === nodeClass);
1260
- if (!baseType) {
1261
- return topMostBaseTypeNode;
1262
- }
1263
- (0, node_opcua_assert_1.assert)(typeof baseType === "string" || baseType instanceof base_node_impl_1.BaseNodeImpl);
1264
- let baseTypeNode;
1265
- if (baseType instanceof base_node_impl_1.BaseNodeImpl) {
1266
- baseTypeNode = baseType;
1267
- }
1268
- else {
1269
- baseTypeNode = this.findNode(baseType);
1270
- }
1271
- /* istanbul ignore next*/
1272
- if (!baseTypeNode) {
1273
- throw new Error("Cannot find ObjectType or VariableType for " + baseType.toString());
1274
- }
1275
- /* istanbul ignore next */
1276
- if (!baseTypeNode.isSupertypeOf) {
1277
- throw new Error("Cannot find ObjectType or VariableType for " + baseType.toString());
1278
- }
1279
- /* istanbul ignore next */
1280
- if (!baseTypeNode.isSupertypeOf(topMostBaseTypeNode)) {
1281
- throw new Error("wrong type ");
1282
- }
1283
- return baseTypeNode;
1284
- }
1285
- _coerce_VariableTypeIds(dataType) {
1286
- return this._coerce_Type(dataType, node_opcua_constants_1.VariableTypeIds, "VariableTypeIds", AddressSpace.prototype.findVariableType);
1287
- }
1288
- _register(node) {
1289
- (0, node_opcua_assert_1.assert)(node.nodeId instanceof node_opcua_nodeid_1.NodeId);
1290
- const namespace = this.getNamespace(node.nodeId.namespace);
1291
- namespace._register(node);
1292
- }
1293
- deleteNode(nodeOrNodeId) {
1294
- _getNamespace(this, nodeOrNodeId).deleteNode(nodeOrNodeId);
1295
- }
1296
- isEnumeration(dataType) {
1297
- // DataType must be one of Enumeration
1298
- const dataTypeNode = this.findDataType(dataType);
1299
- if (!dataTypeNode) {
1300
- throw new Error(" Cannot find DataType " + dataType.toString() + " in standard address Space");
1301
- }
1302
- const enumerationNode = this.findDataType("Enumeration");
1303
- if (!enumerationNode) {
1304
- throw new Error(" Cannot find 'Enumeration' DataType in standard address Space");
1305
- }
1306
- return dataTypeNode.isSupertypeOf(enumerationNode);
1307
- }
1308
- _coerce_Type(dataType, typeMap, typeMapName, finderMethod) {
1309
- if (dataType instanceof base_node_impl_1.BaseNodeImpl) {
1310
- dataType = dataType.nodeId;
1311
- }
1312
- (0, node_opcua_assert_1.assert)(typeMap !== null && typeof typeMap === "object");
1313
- let nodeId;
1314
- if (typeof dataType === "string") {
1315
- const namespace0 = this.getDefaultNamespace();
1316
- // resolve dataType
1317
- nodeId = namespace0.resolveAlias(dataType);
1318
- if (!nodeId) {
1319
- // dataType was not found in the aliases database
1320
- if (typeMap[dataType]) {
1321
- nodeId = (0, node_opcua_nodeid_1.makeNodeId)(typeMap[dataType], 0);
1322
- return nodeId;
1323
- }
1324
- else {
1325
- nodeId = (0, node_opcua_nodeid_1.resolveNodeId)(dataType);
1326
- }
1327
- }
1328
- }
1329
- else if (typeof dataType === "number") {
1330
- nodeId = (0, node_opcua_nodeid_1.makeNodeId)(dataType, 0);
1331
- }
1332
- else {
1333
- nodeId = (0, node_opcua_nodeid_1.resolveNodeId)(dataType);
1334
- }
1335
- /* istanbul ignore next */
1336
- if (nodeId == null || !(nodeId instanceof node_opcua_nodeid_1.NodeId)) {
1337
- throw new Error("Expecting valid nodeId ");
1338
- }
1339
- const el = finderMethod.call(this, nodeId);
1340
- if (!el) {
1341
- // verify that node Id exists in standard type map typeMap
1342
- const find = Object.values(typeMap).filter((a) => a === nodeId.value);
1343
- /* istanbul ignore next */
1344
- if (find.length !== 1) {
1345
- throw new Error(" cannot find " + dataType.toString() + " in typeMap " + typeMapName + " L = " + find.length);
1346
- }
1347
- }
1348
- return nodeId;
1349
- }
1350
- _findReferenceType(refType, namespaceIndex) {
1351
- if (refType instanceof node_opcua_nodeid_1.NodeId) {
1352
- return _find_by_node_id(this, refType, namespaceIndex);
1353
- }
1354
- const [namespace, browseName] = _extract_namespace_and_browse_name_as_string(this, refType, namespaceIndex);
1355
- return namespace.findReferenceType(browseName);
1356
- }
1357
- }
1358
- exports.AddressSpace = AddressSpace;
1359
- AddressSpace.isNonEmptyQualifiedName = namespace_impl_2.isNonEmptyQualifiedName;
1360
- AddressSpace.registry = new node_opcua_object_registry_1.ObjectRegistry();
1361
- function _getNamespace(addressSpace, nodeOrNodId) {
1362
- const nodeId = nodeOrNodId instanceof base_node_impl_1.BaseNodeImpl ? nodeOrNodId.nodeId : nodeOrNodId;
1363
- return addressSpace.getNamespace(nodeId.namespace);
1364
- }
1365
- function _find_by_node_id(addressSpace, nodeId, namespaceIndex) {
1366
- const obj = addressSpace.findNode(nodeId);
1367
- return obj;
1368
- }
1369
- /**
1370
- * return true if nodeId is a UAFolder
1371
- * @method _isFolder
1372
- * @param addressSpace
1373
- * @param folder
1374
- * @return {Boolean}
1375
- * @private
1376
- */
1377
- function _isFolder(addressSpace, folder) {
1378
- const folderType = addressSpace.findObjectType("FolderType");
1379
- (0, node_opcua_assert_1.assert)(folder instanceof base_node_impl_1.BaseNodeImpl);
1380
- (0, node_opcua_assert_1.assert)(folder.typeDefinitionObj);
1381
- return folder.typeDefinitionObj.isSupertypeOf(folderType);
1382
- }
1383
- function _increase_version_number(node) {
1384
- if (node && node.nodeVersion) {
1385
- const previousValue = parseInt(node.nodeVersion.readValue().value.value, 10);
1386
- node.nodeVersion.setValueFromSource({
1387
- dataType: node_opcua_variant_1.DataType.String,
1388
- value: (previousValue + 1).toString()
1389
- });
1390
- // xx console.log("xxx increasing version number of node ", node.browseName.toString(),previousValue);
1391
- }
1392
- }
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 hasProperty = (data, propertyName) => Object.prototype.hasOwnProperty.call(data, propertyName);
640
+ const visitedProperties = {};
641
+ const alreadyVisited = (key) => Object.prototype.hasOwnProperty.call(visitedProperties, key);
642
+ const markAsVisited = (key) => visitedProperties[key] = 1;
643
+ function _process_var(self, prefixLower, prefixStandard, node) {
644
+ const lowerName = prefixLower + (0, node_opcua_utils_1.lowerFirstLetter)(node.browseName.name);
645
+ const fullBrowsePath = prefixStandard + node.browseName.toString();
646
+ if (alreadyVisited(lowerName)) {
647
+ return;
648
+ }
649
+ markAsVisited(lowerName);
650
+ if (hasProperty(data, lowerName)) {
651
+ eventData._createValue(fullBrowsePath, node, data[lowerName]);
652
+ }
653
+ else {
654
+ // add a property , but with a null variant
655
+ eventData._createValue(fullBrowsePath, node, { dataType: node_opcua_variant_1.DataType.Null });
656
+ if (doDebug) {
657
+ if (node.modellingRule === "Mandatory") {
658
+ // tslint:disable:no-console
659
+ console.log(chalk.red("ERROR : AddressSpace#constructEventData(eventType,options) " + "cannot find property ") +
660
+ self.browseName.toString() +
661
+ " => " +
662
+ chalk.cyan(lowerName));
663
+ }
664
+ else {
665
+ console.log(chalk.yellow("Warning : AddressSpace#constructEventData(eventType,options)" + " cannot find property ") +
666
+ self.browseName.toString() +
667
+ " => " +
668
+ chalk.cyan(lowerName));
669
+ }
670
+ }
671
+ }
672
+ }
673
+ // verify that all elements of data are valid
674
+ function verify_data_is_valid(data1) {
675
+ Object.keys(data1).map((k) => {
676
+ if (k === "$eventDataSource") {
677
+ return;
678
+ }
679
+ /* istanbul ignore next */
680
+ if (!alreadyVisited(k)) {
681
+ throw new Error(" cannot find property '" +
682
+ k +
683
+ "' in [ " +
684
+ Object.keys(visitedProperties).join(", ") +
685
+ "] when filling " +
686
+ eventTypeNode.browseName.toString());
687
+ }
688
+ });
689
+ }
690
+ const populate_data = (self, eventData1) => {
691
+ if ((0, node_opcua_nodeid_1.sameNodeId)(baseObjectType.nodeId, self.nodeId)) {
692
+ return; // nothing to do
693
+ }
694
+ const baseTypeNodeId = self.subtypeOf;
695
+ /* istanbul ignore next */
696
+ if (!baseTypeNodeId) {
697
+ throw new Error("Object " + self.browseName.toString() + " with nodeId " + self.nodeId + " has no Type");
698
+ }
699
+ const baseType = this.findNode(baseTypeNodeId);
700
+ /* istanbul ignore next */
701
+ if (!baseType) {
702
+ throw new Error(chalk.red("Cannot find object with nodeId ") + baseTypeNodeId);
703
+ }
704
+ populate_data(baseType, eventData1);
705
+ // get properties and components from base class
706
+ const properties = self.getProperties();
707
+ const components = self.getComponents();
708
+ const children = [].concat(properties, components);
709
+ // istanbul ignore next
710
+ if (doDebug) {
711
+ console.log(" " + chalk.bgWhite.cyan(self.browseName.toString()));
712
+ }
713
+ for (const node of children) {
714
+ // only keep those that have a "HasModellingRule"
715
+ if (!node.modellingRule) {
716
+ // xx console.log(" skipping node without modelling rule", node.browseName.toString());
717
+ continue;
718
+ }
719
+ // ignore also methods
720
+ if (node.nodeClass === node_opcua_data_model_1.NodeClass.Method) {
721
+ // xx console.log(" skipping method ", node.browseName.toString());
722
+ continue;
723
+ }
724
+ _process_var(self, "", "", node);
725
+ // also store value in index
726
+ // xx eventData.__nodes[node.nodeId.toString()] = eventData[lowerName];
727
+ const children2 = node.getAggregates();
728
+ if (children2.length > 0) {
729
+ const lowerName = (0, node_opcua_utils_1.lowerFirstLetter)(node.browseName.name);
730
+ const standardName = node.browseName.toString();
731
+ // console.log(" Children to visit = ",lowerName,
732
+ // children.map(function(a){ return a.browseName.toString();}).join(" "));
733
+ for (const child2 of children2) {
734
+ _process_var(self, lowerName + ".", standardName + ".", child2);
735
+ }
736
+ }
737
+ }
738
+ };
739
+ const eventData = new event_data_1.EventData(eventTypeNode);
740
+ // verify standard properties...
741
+ populate_data(eventTypeNode, eventData);
742
+ verify_data_is_valid(data);
743
+ return eventData;
744
+ }
745
+ // - Browse --------------------------------------------------------------------------------------------------------
746
+ /**
747
+ * browse some path.
748
+ *
749
+ * @method browsePath
750
+ * @param {BrowsePath} browsePath
751
+ * @return {BrowsePathResult}
752
+ *
753
+ * This service can be used translates one or more browse paths into NodeIds.
754
+ * A browse path is constructed of a starting Node and a RelativePath. The specified starting Node
755
+ * identifies the Node from which the RelativePath is based. The RelativePath contains a sequence of
756
+ * ReferenceTypes and BrowseNames.
757
+ *
758
+ * |StatusCode | |
759
+ * |------------------------------|:-----------------------------------------------------------|
760
+ * |BadNodeIdUnknown | |
761
+ * |BadNodeIdInvalid | |
762
+ * |BadNothingToDo | - the relative path contains an empty list ) |
763
+ * |BadBrowseNameInvalid | - target name is missing in relative path |
764
+ * |UncertainReferenceOutOfServer | - The path element has targets which are in another server.|
765
+ * |BadTooManyMatches | |
766
+ * |BadQueryTooComplex | |
767
+ * |BadNoMatch | |
768
+ *
769
+ *
770
+ *
771
+ */
772
+ browsePath(browsePath) {
773
+ (0, node_opcua_assert_1.assert)(browsePath instanceof node_opcua_types_1.BrowsePath);
774
+ const startingNode = this.findNode(browsePath.startingNode);
775
+ if (!startingNode) {
776
+ return new node_opcua_types_1.BrowsePathResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadNodeIdUnknown });
777
+ }
778
+ if (!browsePath.relativePath.elements || browsePath.relativePath.elements.length === 0) {
779
+ return new node_opcua_types_1.BrowsePathResult({
780
+ statusCode: node_opcua_status_code_1.StatusCodes.BadNothingToDo,
781
+ targets: []
782
+ });
783
+ }
784
+ const elements_length = browsePath.relativePath.elements.length;
785
+ // -------------------------------------------------------------------------------------------------------
786
+ // verify standard RelativePath construction
787
+ // from OPCUA 1.03 - PArt 3 - 7.6 RelativePath:
788
+ // TargetName The BrowseName of the target node.
789
+ // The final element may have an empty targetName. In this situation all targets of the
790
+ // references identified by the referenceTypeId are the targets of the RelativePath.
791
+ // The targetName shall be specified for all other elements.
792
+ // The current path cannot be followed any further if no targets with the specified
793
+ // BrowseName exist.
794
+ // Let's detect null targetName which are not in last position and return BadBrowseNameInvalid if not
795
+ //
796
+ const empty_targetName_not_in_lastPos = browsePath.relativePath.elements.reduce((prev, e, index) => {
797
+ const is_last = index + 1 === elements_length;
798
+ const isBad = !is_last && (!e.targetName || e.targetName.isEmpty());
799
+ return prev + (!is_last && (!e.targetName || e.targetName.isEmpty()) ? 1 : 0);
800
+ }, 0);
801
+ if (empty_targetName_not_in_lastPos) {
802
+ return new node_opcua_types_1.BrowsePathResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadBrowseNameInvalid });
803
+ }
804
+ // from OPCUA 1.03 - PArt 3 - 5.8.4 TranslateBrowsePathToNodeIds
805
+ // TranslateBrowsePathToNodeIds further restrict RelativePath targetName rules:
806
+ // The last element in the relativePath shall always have a targetName specified.
807
+ const last_el = browsePath.relativePath.elements[elements_length - 1];
808
+ if (!last_el.targetName || !last_el.targetName.name || last_el.targetName.name.length === 0) {
809
+ return new node_opcua_types_1.BrowsePathResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadBrowseNameInvalid });
810
+ }
811
+ const res = [];
812
+ const explore_element = (curNodeObject, elements, index) => {
813
+ const element = elements[index];
814
+ (0, node_opcua_assert_1.assert)(element instanceof node_opcua_types_1.RelativePathElement);
815
+ const is_last = index + 1 === elements.length;
816
+ const nodeIds = curNodeObject.browseNodeByTargetName(element, is_last);
817
+ const targets = nodeIds.map((nodeId) => {
818
+ return {
819
+ remainingPathIndex: elements.length - index,
820
+ targetId: nodeId
821
+ };
822
+ });
823
+ if (!is_last) {
824
+ // explorer
825
+ for (const target of targets) {
826
+ const node = this.findNode(target.targetId);
827
+ if (!node) {
828
+ continue;
829
+ }
830
+ explore_element(node, elements, index + 1);
831
+ }
832
+ }
833
+ else {
834
+ for (const target of targets) {
835
+ res.push({
836
+ remainingPathIndex: 0xffffffff,
837
+ targetId: (0, node_opcua_nodeid_1.coerceExpandedNodeId)(target.targetId)
838
+ });
839
+ }
840
+ }
841
+ };
842
+ explore_element(startingNode, browsePath.relativePath.elements, 0);
843
+ if (res.length === 0) {
844
+ return new node_opcua_types_1.BrowsePathResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadNoMatch });
845
+ }
846
+ return new node_opcua_types_1.BrowsePathResult({
847
+ statusCode: node_opcua_status_code_1.StatusCodes.Good,
848
+ targets: res
849
+ });
850
+ }
851
+ // - Extension Object ----------------------------------------------------------------------------------------------
852
+ getExtensionObjectConstructor(dataType) {
853
+ (0, node_opcua_assert_1.assert)(dataType, "expecting a dataType");
854
+ if (dataType instanceof node_opcua_nodeid_1.NodeId) {
855
+ const tmp = this.findNode(dataType);
856
+ /* istanbul ignore next */
857
+ if (!tmp) {
858
+ throw new Error("getExtensionObjectConstructor: cannot resolve dataType " + dataType);
859
+ }
860
+ dataType = tmp;
861
+ }
862
+ /* istanbul ignore next */
863
+ if (!(dataType instanceof ua_data_type_impl_1.UADataTypeImpl)) {
864
+ // may be dataType was the NodeId of the "Binary Encoding" node
865
+ throw new Error("getExtensionObjectConstructor: dataType has unexpected type" + dataType);
866
+ }
867
+ const _dataType = dataType;
868
+ // to do verify that dataType is of type "Structure"
869
+ /* istanbul ignore next */
870
+ if (!_dataType.isSupertypeOf(this.findDataType("Structure"))) {
871
+ console.log(_dataType.toString());
872
+ }
873
+ (0, node_opcua_assert_1.assert)(_dataType.isSupertypeOf(this.findDataType("Structure")));
874
+ if (!_dataType._extensionObjectConstructor) {
875
+ const dataTypeManager = this.$$extraDataTypeManager;
876
+ _dataType._extensionObjectConstructor = dataTypeManager.getExtensionObjectConstructorFromDataType(_dataType.nodeId);
877
+ }
878
+ (0, node_opcua_assert_1.assert)(_dataType._extensionObjectConstructor, "dataType must have a constructor");
879
+ const Constructor = _dataType._extensionObjectConstructor;
880
+ return Constructor;
881
+ }
882
+ /**
883
+ * @param dataType
884
+ * @param [options]
885
+ * @return the constructed extension object
886
+ *
887
+ *
888
+ * @example
889
+ *
890
+ * // example 1
891
+ * var extObj = addressSpace.constructExtensionObject("BuildInfo",{ productName: "PRODUCT_NAME"});
892
+ *
893
+ * // example 2
894
+ * serverStatusDataType.nodeClass.should.eql(NodeClass.DataType);
895
+ * serverStatusDataType.browseName.toString().should.eql("ServerStatusDataType");
896
+ * var serverStatus = addressSpace.constructExtensionObject(serverStatusDataType);
897
+ * serverStatus.constructor.name.should.eql("ServerStatusDataType");
898
+ */
899
+ constructExtensionObject(dataType, options) {
900
+ const Constructor = this.getExtensionObjectConstructor(dataType);
901
+ return new Constructor(options);
902
+ }
903
+ /**
904
+ * cleanup all resources maintained by this addressSpace.
905
+ * @method dispose
906
+ */
907
+ dispose() {
908
+ this._namespaceArray.map((namespace) => namespace.dispose());
909
+ AddressSpace.registry.unregister(this);
910
+ /* istanbul ignore next */
911
+ if (this._shutdownTask && this._shutdownTask.length > 0) {
912
+ throw new Error("AddressSpace#dispose : shutdown has not been called");
913
+ }
914
+ }
915
+ /**
916
+ * register a function that will be called when the server will perform its shut down.
917
+ * @method registerShutdownTask
918
+ */
919
+ registerShutdownTask(task) {
920
+ this._shutdownTask = this._shutdownTask || [];
921
+ (0, node_opcua_assert_1.assert)(typeof task === "function");
922
+ this._shutdownTask.push(task);
923
+ }
924
+ shutdown() {
925
+ return __awaiter(this, void 0, void 0, function* () {
926
+ if (!this._shutdownTask) {
927
+ return;
928
+ }
929
+ const tasks = this._shutdownTask;
930
+ this._shutdownTask = [];
931
+ // perform registerShutdownTask
932
+ for (const task of tasks) {
933
+ yield task.call(this);
934
+ }
935
+ });
936
+ }
937
+ /**
938
+ *
939
+ * @method browseSingleNode
940
+ * @param nodeId {NodeId|String} : the nodeid of the element to browse
941
+ * @param browseDescription
942
+ * @param browseDescription.browseDirection {BrowseDirection} :
943
+ * @param browseDescription.referenceTypeId {String|NodeId}
944
+ * @param [session]
945
+ * @return {BrowseResult}
946
+ */
947
+ browseSingleNode(nodeId, browseDescription, context) {
948
+ const browseResult = {
949
+ continuationPoint: undefined,
950
+ references: null,
951
+ statusCode: node_opcua_status_code_1.StatusCodes.Good
952
+ };
953
+ if (!browseDescription || browseDescription.browseDirection === node_opcua_data_model_1.BrowseDirection.Invalid) {
954
+ browseResult.statusCode = node_opcua_status_code_1.StatusCodes.BadBrowseDirectionInvalid;
955
+ return new node_opcua_service_browse_1.BrowseResult(browseResult);
956
+ }
957
+ browseDescription.browseDirection = (0, adjust_browse_direction_1.adjustBrowseDirection)(browseDescription.browseDirection, node_opcua_data_model_1.BrowseDirection.Forward);
958
+ /* istanbul ignore next */
959
+ if (typeof nodeId === "number") {
960
+ throw new Error("Not Implemented");
961
+ }
962
+ if (typeof nodeId === "string") {
963
+ const node = this.findNode(this.resolveNodeId(nodeId));
964
+ if (node) {
965
+ nodeId = node.nodeId;
966
+ }
967
+ }
968
+ // check if referenceTypeId is correct
969
+ if (browseDescription.referenceTypeId instanceof node_opcua_nodeid_1.NodeId) {
970
+ if (browseDescription.referenceTypeId.value === 0) {
971
+ browseDescription.referenceTypeId = null;
972
+ }
973
+ else {
974
+ const rf = this.findNode(browseDescription.referenceTypeId);
975
+ if (!rf || !(rf instanceof ua_reference_type_impl_1.UAReferenceTypeImpl)) {
976
+ browseResult.statusCode = node_opcua_status_code_1.StatusCodes.BadReferenceTypeIdInvalid;
977
+ return new node_opcua_service_browse_1.BrowseResult(browseResult);
978
+ }
979
+ }
980
+ }
981
+ const obj = this.findNode(nodeId);
982
+ if (!obj) {
983
+ // Object Not Found
984
+ browseResult.statusCode = node_opcua_status_code_1.StatusCodes.BadNodeIdUnknown;
985
+ // xx console.log("xxxxxx browsing ",nodeId.toString() , " not found" );
986
+ }
987
+ else {
988
+ browseResult.statusCode = node_opcua_status_code_1.StatusCodes.Good;
989
+ browseResult.references = obj.browseNode(browseDescription, context);
990
+ }
991
+ return new node_opcua_service_browse_1.BrowseResult(browseResult);
992
+ }
993
+ /**
994
+ * @param folder
995
+ * @private
996
+ */
997
+ _coerceFolder(folder) {
998
+ folder = this._coerceNode(folder);
999
+ /* istanbul ignore next */
1000
+ if (folder && !_isFolder(this, folder)) {
1001
+ throw new Error("Parent folder must be of FolderType " + folder.typeDefinition.toString());
1002
+ }
1003
+ return folder;
1004
+ }
1005
+ /**
1006
+ *
1007
+ * @param view
1008
+ * @param modelChange
1009
+ * @private
1010
+ */
1011
+ _collectModelChange(view, modelChange) {
1012
+ // xx console.log("in _collectModelChange", modelChange.verb, verbFlags.get(modelChange.verb).toString());
1013
+ this._modelChanges.push(modelChange);
1014
+ }
1015
+ /**
1016
+ *
1017
+ * walk up the hierarchy of objects until a view is found
1018
+ * objects may belong to multiples views.
1019
+ * Note: this method doesn't return the main view => Server object.
1020
+ * @method extractRootViews
1021
+ * @param node {BaseNode}
1022
+ * @return {BaseNode[]}
1023
+ */
1024
+ /**
1025
+ *
1026
+ * @param node
1027
+ * @private
1028
+ */
1029
+ extractRootViews(node) {
1030
+ (0, node_opcua_assert_1.assert)(node.nodeClass === node_opcua_data_model_1.NodeClass.Object || node.nodeClass === node_opcua_data_model_1.NodeClass.Variable);
1031
+ const visitedMap = {};
1032
+ const q = new Dequeue();
1033
+ q.push(node);
1034
+ const objectsFolder = this.rootFolder.objects;
1035
+ (0, node_opcua_assert_1.assert)(objectsFolder instanceof ua_object_impl_1.UAObjectImpl);
1036
+ const results = [];
1037
+ while (q.length) {
1038
+ node = q.shift();
1039
+ const references = node.findReferencesEx("HierarchicalReferences", node_opcua_data_model_1.BrowseDirection.Inverse);
1040
+ const parentNodes = references.map((r) => reference_impl_1.ReferenceImpl.resolveReferenceNode(this, r));
1041
+ for (const parent of parentNodes) {
1042
+ if ((0, node_opcua_nodeid_1.sameNodeId)(parent.nodeId, objectsFolder.nodeId)) {
1043
+ continue; // nothing to do
1044
+ }
1045
+ if (parent.nodeClass === node_opcua_data_model_1.NodeClass.View) {
1046
+ results.push(parent);
1047
+ }
1048
+ else {
1049
+ const key = parent.nodeId.toString();
1050
+ if (Object.prototype.hasOwnProperty.call(visitedMap, key)) {
1051
+ continue;
1052
+ }
1053
+ visitedMap[key] = parent;
1054
+ q.push(parent);
1055
+ }
1056
+ }
1057
+ }
1058
+ return results;
1059
+ }
1060
+ /**
1061
+ *
1062
+ * @param func
1063
+ * @private
1064
+ */
1065
+ modelChangeTransaction(func) {
1066
+ this._modelChangeTransactionCounter = this._modelChangeTransactionCounter || 0;
1067
+ function beginModelChange() {
1068
+ /* jshint validthis:true */
1069
+ (0, node_opcua_assert_1.assert)(this);
1070
+ this._modelChanges = this._modelChanges || [];
1071
+ (0, node_opcua_assert_1.assert)(this._modelChangeTransactionCounter >= 0);
1072
+ this._modelChangeTransactionCounter += 1;
1073
+ }
1074
+ function endModelChange() {
1075
+ /* jshint validthis:true */
1076
+ this._modelChangeTransactionCounter -= 1;
1077
+ if (this._modelChangeTransactionCounter === 0) {
1078
+ if (this._modelChanges.length === 0) {
1079
+ return; // nothing to do
1080
+ }
1081
+ // xx console.log( "xx dealing with ",this._modelChanges.length);
1082
+ // increase version number of participating nodes
1083
+ // https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore
1084
+ // const nodeIds = _.uniq(this._modelChanges.map((c: any) => c.affected));
1085
+ const nodeIds = [...new Set(this._modelChanges.map((c) => c.affected))];
1086
+ const nodes = nodeIds.map((nodeId) => this.findNode(nodeId));
1087
+ nodes.forEach(_increase_version_number);
1088
+ // raise events
1089
+ if (this.rootFolder.objects.server) {
1090
+ const eventTypeNode = this.findEventType("GeneralModelChangeEventType");
1091
+ if (eventTypeNode) {
1092
+ // xx console.log("xx raising event on server object");
1093
+ this.rootFolder.objects.server.raiseEvent(eventTypeNode, {
1094
+ // Part 5 - 6.4.32 GeneralModelChangeEventType
1095
+ changes: {
1096
+ dataType: node_opcua_variant_1.DataType.ExtensionObject,
1097
+ arrayType: node_opcua_variant_1.VariantArrayType.Array,
1098
+ value: this._modelChanges
1099
+ }
1100
+ });
1101
+ }
1102
+ }
1103
+ this._modelChanges = [];
1104
+ // _notifyModelChange(this);
1105
+ }
1106
+ }
1107
+ beginModelChange.call(this);
1108
+ try {
1109
+ func();
1110
+ }
1111
+ catch (err) {
1112
+ errorLog("modelChangeTransaction", err === null || err === void 0 ? void 0 : err.message);
1113
+ throw err;
1114
+ }
1115
+ finally {
1116
+ endModelChange.call(this);
1117
+ }
1118
+ }
1119
+ /**
1120
+ * normalize the ReferenceType field of the Reference Object
1121
+ * @param params.referenceType {String|nodeId}
1122
+ * @param params.isForward {Boolean} default value: true;
1123
+ * @return {Object} a new reference object with the normalized name { referenceType: <value>, isForward: <flag>}
1124
+ */
1125
+ normalizeReferenceType(params) {
1126
+ if (params instanceof reference_impl_1.ReferenceImpl) {
1127
+ // a reference has already been normalized
1128
+ return params;
1129
+ }
1130
+ // ----------------------------------------------- handle is forward
1131
+ (0, node_opcua_assert_1.assert)(params.isForward === undefined || typeof params.isForward === "boolean");
1132
+ params.isForward = utils.isNullOrUndefined(params.isForward) ? true : !!params.isForward;
1133
+ // referenceType = Organizes , isForward = true => referenceType = Organizes , isForward = true
1134
+ // referenceType = Organizes , isForward = false => referenceType = Organizes , isForward = false
1135
+ // referenceType = OrganizedBy , isForward = true => referenceType = Organizes , isForward = **false**
1136
+ // referenceType = OrganizedBy , isForward = false => referenceType = Organizes , isForward = **true**
1137
+ // ----------------------------------------------- handle referenceType
1138
+ if (params.referenceType instanceof ua_reference_type_impl_1.UAReferenceTypeImpl) {
1139
+ params.referenceType = params.referenceType;
1140
+ params.referenceType = params.referenceType.nodeId;
1141
+ }
1142
+ else if (typeof params.referenceType === "string") {
1143
+ const inv = this.findReferenceTypeFromInverseName(params.referenceType);
1144
+ if (inv) {
1145
+ params.referenceType = inv.nodeId;
1146
+ params._referenceType = inv;
1147
+ params.isForward = !params.isForward;
1148
+ }
1149
+ else {
1150
+ params.referenceType = (0, node_opcua_nodeid_1.resolveNodeId)(params.referenceType);
1151
+ const refType = this.findReferenceType(params.referenceType);
1152
+ if (refType) {
1153
+ params._referenceType = refType;
1154
+ }
1155
+ }
1156
+ }
1157
+ (0, node_opcua_assert_1.assert)(params.referenceType instanceof node_opcua_nodeid_1.NodeId);
1158
+ // ----------- now resolve target NodeId;
1159
+ if (params.nodeId instanceof base_node_impl_1.BaseNodeImpl) {
1160
+ (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(params, "node"));
1161
+ params.node = params.nodeId;
1162
+ params.nodeId = params.node.nodeId;
1163
+ }
1164
+ else {
1165
+ let _nodeId = params.nodeId;
1166
+ (0, node_opcua_assert_1.assert)(!!_nodeId, "missing 'nodeId' in reference");
1167
+ if (_nodeId && _nodeId.nodeId) {
1168
+ _nodeId = _nodeId.nodeId;
1169
+ }
1170
+ _nodeId = (0, node_opcua_nodeid_1.resolveNodeId)(_nodeId);
1171
+ /* istanbul ignore next */
1172
+ if (!(_nodeId instanceof node_opcua_nodeid_1.NodeId) || _nodeId.isEmpty()) {
1173
+ // tslint:disable:no-console
1174
+ console.log("xx =>", JSON.stringify(params, null, " "));
1175
+ throw new Error(" Invalid reference nodeId " + _nodeId.toString());
1176
+ }
1177
+ params.nodeId = _nodeId;
1178
+ }
1179
+ return new reference_impl_1.ReferenceImpl(params);
1180
+ }
1181
+ /**
1182
+ *
1183
+ * @param references
1184
+ */
1185
+ normalizeReferenceTypes(references) {
1186
+ if (!references || references.length === 0) {
1187
+ return [];
1188
+ }
1189
+ references = references;
1190
+ (0, node_opcua_assert_1.assert)(Array.isArray(references));
1191
+ return references.map((el) => this.normalizeReferenceType(el));
1192
+ }
1193
+ // -- Historical Node -----------------------------------------------------------------------------------------
1194
+ /**
1195
+ *
1196
+ * @param node
1197
+ * @param options
1198
+ */
1199
+ installHistoricalDataNode(node, options) {
1200
+ address_space_historical_data_node_1.AddressSpace_installHistoricalDataNode.call(this, node, options);
1201
+ }
1202
+ // -- Alarms & Conditions -----------------------------------------------------------------------------------------
1203
+ /**
1204
+ *
1205
+ */
1206
+ installAlarmsAndConditionsService() {
1207
+ alarms_and_conditions_1.UAConditionImpl.install_condition_refresh_handle(this);
1208
+ alarms_and_conditions_1.UAAcknowledgeableConditionImpl.install_method_handle_on_type(this);
1209
+ }
1210
+ // -- internal stuff -----------------------------------------------------------------------------------------------
1211
+ _coerceNode(node) {
1212
+ function hasTypeDefinition(node1) {
1213
+ return (node1.nodeClass === node_opcua_data_model_1.NodeClass.Variable ||
1214
+ node1.nodeClass === node_opcua_data_model_1.NodeClass.Object ||
1215
+ node1.nodeClass === node_opcua_data_model_1.NodeClass.Method);
1216
+ }
1217
+ // coerce to BaseNode object
1218
+ if (node instanceof base_node_impl_1.BaseNodeImpl) {
1219
+ return node;
1220
+ }
1221
+ // it's a node id like
1222
+ // coerce parent folder to an object
1223
+ const returnValue = this.findNode((0, node_opcua_nodeid_1.resolveNodeId)(node));
1224
+ /*
1225
+ if (!hasTypeDefinition(node as BaseNode)) {
1226
+ node = this.findNode(node.nodeId) || node;
1227
+ if (!node || !hasTypeDefinition(node)) {
1228
+ return null;
1229
+ }
1230
+ }
1231
+ */
1232
+ return returnValue;
1233
+ }
1234
+ _coerce_DataType(dataType) {
1235
+ if (dataType instanceof node_opcua_nodeid_1.NodeId) {
1236
+ // xx assert(self.findDataType(dataType));
1237
+ return dataType;
1238
+ }
1239
+ return this._coerce_Type(dataType, node_opcua_constants_1.DataTypeIds, "DataTypeIds", AddressSpace.prototype.findDataType);
1240
+ }
1241
+ _coerceTypeDefinition(typeDefinition) {
1242
+ if (typeof typeDefinition === "string") {
1243
+ // coerce parent folder to an node
1244
+ const typeDefinitionNode = this.findNode(typeDefinition);
1245
+ typeDefinition = typeDefinitionNode.nodeId;
1246
+ }
1247
+ // xx console.log("typeDefinition = ",typeDefinition);
1248
+ (0, node_opcua_assert_1.assert)(typeDefinition instanceof node_opcua_nodeid_1.NodeId);
1249
+ return typeDefinition;
1250
+ }
1251
+ _coerceType(baseType, topMostBaseType, nodeClass) {
1252
+ (0, node_opcua_assert_1.assert)(typeof topMostBaseType === "string");
1253
+ const topMostBaseTypeNode = this.findNode(topMostBaseType);
1254
+ /* istanbul ignore next */
1255
+ if (!topMostBaseTypeNode) {
1256
+ throw new Error("Cannot find topMostBaseTypeNode " + topMostBaseType.toString());
1257
+ }
1258
+ (0, node_opcua_assert_1.assert)(topMostBaseTypeNode instanceof base_node_impl_1.BaseNodeImpl);
1259
+ (0, node_opcua_assert_1.assert)(topMostBaseTypeNode.nodeClass === nodeClass);
1260
+ if (!baseType) {
1261
+ return topMostBaseTypeNode;
1262
+ }
1263
+ (0, node_opcua_assert_1.assert)(typeof baseType === "string" || baseType instanceof base_node_impl_1.BaseNodeImpl);
1264
+ let baseTypeNode;
1265
+ if (baseType instanceof base_node_impl_1.BaseNodeImpl) {
1266
+ baseTypeNode = baseType;
1267
+ }
1268
+ else {
1269
+ baseTypeNode = this.findNode(baseType);
1270
+ }
1271
+ /* istanbul ignore next*/
1272
+ if (!baseTypeNode) {
1273
+ throw new Error("Cannot find ObjectType or VariableType for " + baseType.toString());
1274
+ }
1275
+ /* istanbul ignore next */
1276
+ if (!baseTypeNode.isSupertypeOf) {
1277
+ throw new Error("Cannot find ObjectType or VariableType for " + baseType.toString());
1278
+ }
1279
+ /* istanbul ignore next */
1280
+ if (!baseTypeNode.isSupertypeOf(topMostBaseTypeNode)) {
1281
+ throw new Error("wrong type ");
1282
+ }
1283
+ return baseTypeNode;
1284
+ }
1285
+ _coerce_VariableTypeIds(dataType) {
1286
+ return this._coerce_Type(dataType, node_opcua_constants_1.VariableTypeIds, "VariableTypeIds", AddressSpace.prototype.findVariableType);
1287
+ }
1288
+ _register(node) {
1289
+ (0, node_opcua_assert_1.assert)(node.nodeId instanceof node_opcua_nodeid_1.NodeId);
1290
+ const namespace = this.getNamespace(node.nodeId.namespace);
1291
+ namespace._register(node);
1292
+ }
1293
+ deleteNode(nodeOrNodeId) {
1294
+ _getNamespace(this, nodeOrNodeId).deleteNode(nodeOrNodeId);
1295
+ }
1296
+ isEnumeration(dataType) {
1297
+ // DataType must be one of Enumeration
1298
+ const dataTypeNode = this.findDataType(dataType);
1299
+ if (!dataTypeNode) {
1300
+ throw new Error(" Cannot find DataType " + dataType.toString() + " in standard address Space");
1301
+ }
1302
+ const enumerationNode = this.findDataType("Enumeration");
1303
+ if (!enumerationNode) {
1304
+ throw new Error(" Cannot find 'Enumeration' DataType in standard address Space");
1305
+ }
1306
+ return dataTypeNode.isSupertypeOf(enumerationNode);
1307
+ }
1308
+ _coerce_Type(dataType, typeMap, typeMapName, finderMethod) {
1309
+ if (dataType instanceof base_node_impl_1.BaseNodeImpl) {
1310
+ dataType = dataType.nodeId;
1311
+ }
1312
+ (0, node_opcua_assert_1.assert)(typeMap !== null && typeof typeMap === "object");
1313
+ let nodeId;
1314
+ if (typeof dataType === "string") {
1315
+ const namespace0 = this.getDefaultNamespace();
1316
+ // resolve dataType
1317
+ nodeId = namespace0.resolveAlias(dataType);
1318
+ if (!nodeId) {
1319
+ // dataType was not found in the aliases database
1320
+ if (typeMap[dataType]) {
1321
+ nodeId = (0, node_opcua_nodeid_1.makeNodeId)(typeMap[dataType], 0);
1322
+ return nodeId;
1323
+ }
1324
+ else {
1325
+ nodeId = (0, node_opcua_nodeid_1.resolveNodeId)(dataType);
1326
+ }
1327
+ }
1328
+ }
1329
+ else if (typeof dataType === "number") {
1330
+ nodeId = (0, node_opcua_nodeid_1.makeNodeId)(dataType, 0);
1331
+ }
1332
+ else {
1333
+ nodeId = (0, node_opcua_nodeid_1.resolveNodeId)(dataType);
1334
+ }
1335
+ /* istanbul ignore next */
1336
+ if (nodeId == null || !(nodeId instanceof node_opcua_nodeid_1.NodeId)) {
1337
+ throw new Error("Expecting valid nodeId ");
1338
+ }
1339
+ const el = finderMethod.call(this, nodeId);
1340
+ if (!el) {
1341
+ // verify that node Id exists in standard type map typeMap
1342
+ const find = Object.values(typeMap).filter((a) => a === nodeId.value);
1343
+ /* istanbul ignore next */
1344
+ if (find.length !== 1) {
1345
+ throw new Error(" cannot find " + dataType.toString() + " in typeMap " + typeMapName + " L = " + find.length);
1346
+ }
1347
+ }
1348
+ return nodeId;
1349
+ }
1350
+ _findReferenceType(refType, namespaceIndex) {
1351
+ if (refType instanceof node_opcua_nodeid_1.NodeId) {
1352
+ return _find_by_node_id(this, refType, namespaceIndex);
1353
+ }
1354
+ const [namespace, browseName] = _extract_namespace_and_browse_name_as_string(this, refType, namespaceIndex);
1355
+ return namespace.findReferenceType(browseName);
1356
+ }
1357
+ }
1358
+ exports.AddressSpace = AddressSpace;
1359
+ AddressSpace.isNonEmptyQualifiedName = namespace_impl_2.isNonEmptyQualifiedName;
1360
+ AddressSpace.registry = new node_opcua_object_registry_1.ObjectRegistry();
1361
+ function _getNamespace(addressSpace, nodeOrNodId) {
1362
+ const nodeId = nodeOrNodId instanceof base_node_impl_1.BaseNodeImpl ? nodeOrNodId.nodeId : nodeOrNodId;
1363
+ return addressSpace.getNamespace(nodeId.namespace);
1364
+ }
1365
+ function _find_by_node_id(addressSpace, nodeId, namespaceIndex) {
1366
+ const obj = addressSpace.findNode(nodeId);
1367
+ return obj;
1368
+ }
1369
+ /**
1370
+ * return true if nodeId is a UAFolder
1371
+ * @method _isFolder
1372
+ * @param addressSpace
1373
+ * @param folder
1374
+ * @return {Boolean}
1375
+ * @private
1376
+ */
1377
+ function _isFolder(addressSpace, folder) {
1378
+ const folderType = addressSpace.findObjectType("FolderType");
1379
+ (0, node_opcua_assert_1.assert)(folder instanceof base_node_impl_1.BaseNodeImpl);
1380
+ (0, node_opcua_assert_1.assert)(folder.typeDefinitionObj);
1381
+ return folder.typeDefinitionObj.isSupertypeOf(folderType);
1382
+ }
1383
+ function _increase_version_number(node) {
1384
+ if (node && node.nodeVersion) {
1385
+ const previousValue = parseInt(node.nodeVersion.readValue().value.value, 10);
1386
+ node.nodeVersion.setValueFromSource({
1387
+ dataType: node_opcua_variant_1.DataType.String,
1388
+ value: (previousValue + 1).toString()
1389
+ });
1390
+ // xx console.log("xxx increasing version number of node ", node.browseName.toString(),previousValue);
1391
+ }
1392
+ }
1393
1393
  //# sourceMappingURL=address_space.js.map