node-opcua-address-space 2.97.0 → 2.98.1

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