node-opcua-address-space 2.71.0 → 2.72.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (408) hide show
  1. package/dist/source/address_space_ts.d.ts +118 -118
  2. package/dist/source/address_space_ts.js +17 -17
  3. package/dist/source/continuation_points/continuation_point_manager.d.ts +32 -32
  4. package/dist/source/continuation_points/continuation_point_manager.js +195 -195
  5. package/dist/source/helpers/adjust_browse_direction.d.ts +5 -5
  6. package/dist/source/helpers/adjust_browse_direction.js +11 -11
  7. package/dist/source/helpers/argument_list.d.ts +34 -34
  8. package/dist/source/helpers/argument_list.js +285 -285
  9. package/dist/source/helpers/call_helpers.d.ts +6 -6
  10. package/dist/source/helpers/call_helpers.js +70 -70
  11. package/dist/source/helpers/check_event_clause.d.ts +17 -17
  12. package/dist/source/helpers/check_event_clause.js +52 -52
  13. package/dist/source/helpers/coerce_enum_value.d.ts +6 -6
  14. package/dist/source/helpers/coerce_enum_value.js +33 -33
  15. package/dist/source/helpers/dump_tools.d.ts +14 -14
  16. package/dist/source/helpers/dump_tools.js +78 -78
  17. package/dist/source/helpers/ensure_secure_access.d.ts +9 -9
  18. package/dist/source/helpers/ensure_secure_access.js +76 -76
  19. package/dist/source/helpers/make_optionals_map.d.ts +21 -21
  20. package/dist/source/helpers/make_optionals_map.js +29 -29
  21. package/dist/source/helpers/multiform_func.d.ts +11 -11
  22. package/dist/source/helpers/multiform_func.js +73 -73
  23. package/dist/source/helpers/resolve_opaque_on_address_space.d.ts +3 -3
  24. package/dist/source/helpers/resolve_opaque_on_address_space.js +36 -36
  25. package/dist/source/index.d.ts +40 -40
  26. package/dist/source/index.js +66 -66
  27. package/dist/source/interfaces/alarms_and_conditions/condition_info_i.d.ts +12 -12
  28. package/dist/source/interfaces/alarms_and_conditions/condition_info_i.js +2 -2
  29. package/dist/source/interfaces/data_access/ua_multistate_discrete_ex.d.ts +21 -21
  30. package/dist/source/interfaces/data_access/ua_multistate_discrete_ex.js +2 -2
  31. package/dist/source/interfaces/data_access/ua_multistate_value_discrete_ex.d.ts +24 -24
  32. package/dist/source/interfaces/data_access/ua_multistate_value_discrete_ex.js +2 -2
  33. package/dist/source/interfaces/data_access/ua_two_state_discrete_ex.d.ts +12 -12
  34. package/dist/source/interfaces/data_access/ua_two_state_discrete_ex.js +2 -2
  35. package/dist/source/interfaces/data_access/ua_y_array_item_ex.d.ts +8 -8
  36. package/dist/source/interfaces/data_access/ua_y_array_item_ex.js +2 -2
  37. package/dist/source/interfaces/state_machine/ua_exclusive_limit_state_machine_type_ex.d.ts +12 -12
  38. package/dist/source/interfaces/state_machine/ua_exclusive_limit_state_machine_type_ex.js +2 -2
  39. package/dist/source/interfaces/state_machine/ua_finite_state_machine_type.d.ts +49 -49
  40. package/dist/source/interfaces/state_machine/ua_finite_state_machine_type.js +2 -2
  41. package/dist/source/interfaces/state_machine/ua_program_state_machine_type.d.ts +11 -11
  42. package/dist/source/interfaces/state_machine/ua_program_state_machine_type.js +2 -2
  43. package/dist/source/interfaces/state_machine/ua_state_machine_type.d.ts +222 -222
  44. package/dist/source/interfaces/state_machine/ua_state_machine_type.js +2 -2
  45. package/dist/source/interfaces/state_machine/ua_transition_ex.d.ts +6 -6
  46. package/dist/source/interfaces/state_machine/ua_transition_ex.js +2 -2
  47. package/dist/source/interfaces/ua_subscription_diagnostics_variable_ex.d.ts +8 -8
  48. package/dist/source/interfaces/ua_subscription_diagnostics_variable_ex.js +2 -2
  49. package/dist/source/loader/decode_xml_extension_object.d.ts +6 -6
  50. package/dist/source/loader/decode_xml_extension_object.js +71 -71
  51. package/dist/source/loader/ensure_datatype_extracted.d.ts +5 -5
  52. package/dist/source/loader/ensure_datatype_extracted.js +45 -45
  53. package/dist/source/loader/generateAddressSpaceRaw.d.ts +10 -10
  54. package/dist/source/loader/generateAddressSpaceRaw.js +45 -45
  55. package/dist/source/loader/load_nodeset2.d.ts +16 -16
  56. package/dist/source/loader/load_nodeset2.js +1468 -1464
  57. package/dist/source/loader/load_nodeset2.js.map +1 -1
  58. package/dist/source/loader/make_semver_compatible.d.ts +6 -0
  59. package/dist/source/loader/make_semver_compatible.js +26 -0
  60. package/dist/source/loader/make_semver_compatible.js.map +1 -0
  61. package/dist/source/loader/make_xml_extension_object_parser.d.ts +28 -28
  62. package/dist/source/loader/make_xml_extension_object_parser.js +325 -315
  63. package/dist/source/loader/make_xml_extension_object_parser.js.map +1 -1
  64. package/dist/source/loader/namespace_post_step.d.ts +6 -6
  65. package/dist/source/loader/namespace_post_step.js +47 -47
  66. package/dist/source/loader/register_node_promoter.d.ts +3 -3
  67. package/dist/source/loader/register_node_promoter.js +9 -9
  68. package/dist/source/namespace.d.ts +6 -6
  69. package/dist/source/namespace.js +2 -2
  70. package/dist/source/namespace_alarm_and_condition.d.ts +24 -24
  71. package/dist/source/namespace_alarm_and_condition.js +2 -2
  72. package/dist/source/namespace_data_access.d.ts +42 -42
  73. package/dist/source/namespace_data_access.js +2 -2
  74. package/dist/source/namespace_machine_state.d.ts +7 -7
  75. package/dist/source/namespace_machine_state.js +2 -2
  76. package/dist/source/pseudo_session.d.ts +55 -55
  77. package/dist/source/pseudo_session.js +203 -203
  78. package/dist/source/session_context.d.ts +111 -111
  79. package/dist/source/session_context.js +265 -265
  80. package/dist/source/set_namespace_meta_data.d.ts +2 -2
  81. package/dist/source/set_namespace_meta_data.js +59 -59
  82. package/dist/source/ua_root_folder.d.ts +9 -9
  83. package/dist/source/ua_root_folder.js +2 -2
  84. package/dist/source/ua_two_state_variable_ex.d.ts +23 -23
  85. package/dist/source/ua_two_state_variable_ex.js +2 -2
  86. package/dist/source/xml_writer.d.ts +9 -9
  87. package/dist/source/xml_writer.js +2 -2
  88. package/dist/src/address_space.d.ts +392 -392
  89. package/dist/src/address_space.js +1387 -1387
  90. package/dist/src/address_space_change_event_tools.d.ts +6 -6
  91. package/dist/src/address_space_change_event_tools.js +149 -149
  92. package/dist/src/address_space_private.d.ts +43 -43
  93. package/dist/src/address_space_private.js +2 -2
  94. package/dist/src/alarms_and_conditions/check_where_clause.d.ts +4 -4
  95. package/dist/src/alarms_and_conditions/check_where_clause.js +109 -109
  96. package/dist/src/alarms_and_conditions/condition.d.ts +5 -5
  97. package/dist/src/alarms_and_conditions/condition.js +80 -80
  98. package/dist/src/alarms_and_conditions/condition_info.d.ts +27 -27
  99. package/dist/src/alarms_and_conditions/condition_info.js +54 -54
  100. package/dist/src/alarms_and_conditions/condition_snapshot.d.ts +233 -233
  101. package/dist/src/alarms_and_conditions/condition_snapshot.js +666 -666
  102. package/dist/src/alarms_and_conditions/deviation_alarm_helper.d.ts +21 -21
  103. package/dist/src/alarms_and_conditions/deviation_alarm_helper.js +46 -46
  104. package/dist/src/alarms_and_conditions/extract_event_fields.d.ts +10 -10
  105. package/dist/src/alarms_and_conditions/extract_event_fields.js +89 -89
  106. package/dist/src/alarms_and_conditions/index.d.ts +18 -18
  107. package/dist/src/alarms_and_conditions/index.js +34 -34
  108. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.d.ts +64 -62
  109. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js +244 -244
  110. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js.map +1 -1
  111. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.d.ts +124 -118
  112. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js +416 -416
  113. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js.map +1 -1
  114. package/dist/src/alarms_and_conditions/ua_base_event_impl.d.ts +29 -29
  115. package/dist/src/alarms_and_conditions/ua_base_event_impl.js +38 -38
  116. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.d.ts +36 -21
  117. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.js +115 -25
  118. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.js.map +1 -1
  119. package/dist/src/alarms_and_conditions/ua_condition_impl.d.ts +187 -182
  120. package/dist/src/alarms_and_conditions/ua_condition_impl.js +1024 -1022
  121. package/dist/src/alarms_and_conditions/ua_condition_impl.js.map +1 -1
  122. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.d.ts +18 -17
  123. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.js +57 -57
  124. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.js.map +1 -1
  125. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.d.ts +30 -27
  126. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.js +56 -56
  127. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.js.map +1 -1
  128. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.d.ts +11 -9
  129. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.js +11 -11
  130. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.js.map +1 -1
  131. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.d.ts +40 -38
  132. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.js +86 -86
  133. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.js.map +1 -1
  134. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm_impl.d.ts +10 -10
  135. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm_impl.js +7 -7
  136. package/dist/src/alarms_and_conditions/ua_limit_alarm_impl.d.ts +105 -97
  137. package/dist/src/alarms_and_conditions/ua_limit_alarm_impl.js +250 -250
  138. package/dist/src/alarms_and_conditions/ua_limit_alarm_impl.js.map +1 -1
  139. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.d.ts +29 -28
  140. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.js +50 -50
  141. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.js.map +1 -1
  142. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.d.ts +26 -25
  143. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.js +162 -162
  144. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.js.map +1 -1
  145. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.d.ts +48 -39
  146. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js +161 -135
  147. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js.map +1 -1
  148. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.d.ts +17 -16
  149. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.js +17 -17
  150. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.js.map +1 -1
  151. package/dist/src/apply_condition_refresh.d.ts +6 -6
  152. package/dist/src/apply_condition_refresh.js +27 -27
  153. package/dist/src/base_node_impl.d.ts +281 -281
  154. package/dist/src/base_node_impl.js +1395 -1395
  155. package/dist/src/base_node_private.d.ts +61 -61
  156. package/dist/src/base_node_private.js +705 -705
  157. package/dist/src/data_access/add_dataItem_stuff.d.ts +11 -11
  158. package/dist/src/data_access/add_dataItem_stuff.js +61 -61
  159. package/dist/src/data_access/check_variant_compatibility_ua_analog_item.d.ts +1 -1
  160. package/dist/src/data_access/check_variant_compatibility_ua_analog_item.js +34 -34
  161. package/dist/src/data_access/ua_multistate_discrete_impl.d.ts +32 -32
  162. package/dist/src/data_access/ua_multistate_discrete_impl.js +130 -130
  163. package/dist/src/data_access/ua_multistate_value_discrete.d.ts +51 -51
  164. package/dist/src/data_access/ua_multistate_value_discrete.js +249 -249
  165. package/dist/src/data_access/ua_two_state_discrete.d.ts +25 -25
  166. package/dist/src/data_access/ua_two_state_discrete.js +153 -153
  167. package/dist/src/event_data.d.ts +29 -29
  168. package/dist/src/event_data.js +95 -95
  169. package/dist/src/extension_object_array_node.d.ts +61 -61
  170. package/dist/src/extension_object_array_node.js +276 -276
  171. package/dist/src/historical_access/address_space_historical_data_node.d.ts +26 -26
  172. package/dist/src/historical_access/address_space_historical_data_node.js +630 -630
  173. package/dist/src/index_current.d.ts +45 -45
  174. package/dist/src/index_current.js +77 -77
  175. package/dist/src/namespace_impl.d.ts +457 -457
  176. package/dist/src/namespace_impl.js +1733 -1733
  177. package/dist/src/namespace_private.d.ts +21 -21
  178. package/dist/src/namespace_private.js +32 -32
  179. package/dist/src/nodeid_manager.d.ts +36 -36
  180. package/dist/src/nodeid_manager.js +197 -197
  181. package/dist/src/nodeset_tools/adjust_namespace_array.d.ts +2 -2
  182. package/dist/src/nodeset_tools/adjust_namespace_array.js +13 -13
  183. package/dist/src/nodeset_tools/construct_namespace_dependency.d.ts +2 -2
  184. package/dist/src/nodeset_tools/construct_namespace_dependency.js +83 -83
  185. package/dist/src/nodeset_tools/nodeset_to_xml.d.ts +2 -2
  186. package/dist/src/nodeset_tools/nodeset_to_xml.js +1143 -1143
  187. package/dist/src/nodeset_tools/typedictionary_to_xml.d.ts +2 -2
  188. package/dist/src/nodeset_tools/typedictionary_to_xml.js +154 -154
  189. package/dist/src/reference_impl.d.ts +43 -43
  190. package/dist/src/reference_impl.js +139 -139
  191. package/dist/src/role_permissions.d.ts +2 -2
  192. package/dist/src/role_permissions.js +10 -10
  193. package/dist/src/state_machine/finite_state_machine.d.ts +67 -67
  194. package/dist/src/state_machine/finite_state_machine.js +353 -353
  195. package/dist/src/state_machine/ua_shelving_state_machine_ex.d.ts +34 -34
  196. package/dist/src/state_machine/ua_shelving_state_machine_ex.js +250 -250
  197. package/dist/src/state_machine/ua_two_state_variable.d.ts +61 -61
  198. package/dist/src/state_machine/ua_two_state_variable.js +331 -331
  199. package/dist/src/tool_isSupertypeOf.d.ts +17 -17
  200. package/dist/src/tool_isSupertypeOf.js +108 -108
  201. package/dist/src/ua_condition_type.d.ts +8 -8
  202. package/dist/src/ua_condition_type.js +2 -2
  203. package/dist/src/ua_data_type_impl.d.ts +93 -93
  204. package/dist/src/ua_data_type_impl.js +368 -368
  205. package/dist/src/ua_method_impl.d.ts +41 -41
  206. package/dist/src/ua_method_impl.js +208 -208
  207. package/dist/src/ua_object_impl.d.ts +35 -33
  208. package/dist/src/ua_object_impl.js +162 -156
  209. package/dist/src/ua_object_impl.js.map +1 -1
  210. package/dist/src/ua_object_type_impl.d.ts +48 -48
  211. package/dist/src/ua_object_type_impl.js +124 -124
  212. package/dist/src/ua_reference_type_impl.d.ts +43 -43
  213. package/dist/src/ua_reference_type_impl.js +139 -139
  214. package/dist/src/ua_variable_impl.d.ts +351 -351
  215. package/dist/src/ua_variable_impl.js +1604 -1604
  216. package/dist/src/ua_variable_impl_ext_obj.d.ts +17 -17
  217. package/dist/src/ua_variable_impl_ext_obj.js +437 -437
  218. package/dist/src/ua_variable_type_impl.d.ts +62 -62
  219. package/dist/src/ua_variable_type_impl.js +570 -570
  220. package/dist/src/ua_view_impl.d.ts +19 -15
  221. package/dist/src/ua_view_impl.js +43 -36
  222. package/dist/src/ua_view_impl.js.map +1 -1
  223. package/distHelpers/add_event_generator_object.d.ts +3 -3
  224. package/distHelpers/add_event_generator_object.js +65 -65
  225. package/distHelpers/alarms_and_conditions_demo.d.ts +10 -10
  226. package/distHelpers/alarms_and_conditions_demo.js +114 -114
  227. package/distHelpers/assertHasMatchingReference.d.ts +19 -19
  228. package/distHelpers/assertHasMatchingReference.js +40 -40
  229. package/distHelpers/boiler_system.d.ts +113 -113
  230. package/distHelpers/boiler_system.js +395 -395
  231. package/distHelpers/create_minimalist_address_space_nodeset.d.ts +5 -5
  232. package/distHelpers/create_minimalist_address_space_nodeset.js +171 -171
  233. package/distHelpers/date_utils.d.ts +3 -3
  234. package/distHelpers/date_utils.js +9 -9
  235. package/distHelpers/dump_statemachine.js +127 -127
  236. package/distHelpers/get_address_space_fixture.d.ts +1 -1
  237. package/distHelpers/get_address_space_fixture.js +30 -30
  238. package/distHelpers/get_mini_address_space.d.ts +7 -7
  239. package/distHelpers/get_mini_address_space.js +36 -36
  240. package/distHelpers/index.d.ts +12 -12
  241. package/distHelpers/index.js +28 -28
  242. package/distHelpers/mock_session.d.ts +14 -14
  243. package/distHelpers/mock_session.js +25 -25
  244. package/distNodeJS/generate_address_space.d.ts +4 -4
  245. package/distNodeJS/generate_address_space.js +41 -41
  246. package/distNodeJS/index.d.ts +1 -1
  247. package/distNodeJS/index.js +17 -17
  248. package/package.json +23 -23
  249. package/source/loader/load_nodeset2.ts +21 -17
  250. package/source/loader/make_semver_compatible.ts +23 -0
  251. package/source/loader/make_xml_extension_object_parser.ts +16 -6
  252. package/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.ts +13 -6
  253. package/src/alarms_and_conditions/ua_alarm_condition_impl.ts +15 -10
  254. package/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.ts +126 -10
  255. package/src/alarms_and_conditions/ua_condition_impl.ts +26 -13
  256. package/src/alarms_and_conditions/ua_discrete_alarm_impl.ts +10 -4
  257. package/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.ts +7 -6
  258. package/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.ts +5 -3
  259. package/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.ts +7 -6
  260. package/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm_impl.ts +1 -1
  261. package/src/alarms_and_conditions/ua_limit_alarm_impl.ts +23 -13
  262. package/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.ts +6 -7
  263. package/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.ts +6 -7
  264. package/src/alarms_and_conditions/ua_off_normal_alarm_impl.ts +62 -30
  265. package/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.ts +5 -5
  266. package/src/ua_object_impl.ts +11 -3
  267. package/src/ua_view_impl.ts +6 -4
  268. package/test_helpers/test_fixtures/dataType_issue.xml +9 -9
  269. package/test_helpers/test_fixtures/nodeset_with_guid.xml +1442 -0
  270. package/test_helpers/test_fixtures/nodeset_with_int64_values.xml +31 -0
  271. package/dist/source/interfaces/alarms_and_conditions/ua_condition_base_i.d.ts +0 -23
  272. package/dist/source/interfaces/alarms_and_conditions/ua_condition_base_i.js +0 -3
  273. package/dist/source/interfaces/alarms_and_conditions/ua_condition_base_i.js.map +0 -1
  274. package/dist/source/interfaces/data_access/ua_discrete_item.d.ts +0 -6
  275. package/dist/source/interfaces/data_access/ua_discrete_item.js +0 -3
  276. package/dist/source/interfaces/data_access/ua_discrete_item.js.map +0 -1
  277. package/dist/source/interfaces/data_access/ua_multistate_discrete.d.ts +0 -25
  278. package/dist/source/interfaces/data_access/ua_multistate_discrete.js +0 -3
  279. package/dist/source/interfaces/data_access/ua_multistate_discrete.js.map +0 -1
  280. package/dist/source/interfaces/data_access/ua_multistate_value_discrete.d.ts +0 -27
  281. package/dist/source/interfaces/data_access/ua_multistate_value_discrete.js +0 -3
  282. package/dist/source/interfaces/data_access/ua_multistate_value_discrete.js.map +0 -1
  283. package/dist/source/interfaces/data_access/ua_two_state_discrete.d.ts +0 -17
  284. package/dist/source/interfaces/data_access/ua_two_state_discrete.js +0 -3
  285. package/dist/source/interfaces/data_access/ua_two_state_discrete.js.map +0 -1
  286. package/dist/source/interfaces/data_access/ua_y_array_item.d.ts +0 -19
  287. package/dist/source/interfaces/data_access/ua_y_array_item.js +0 -3
  288. package/dist/source/interfaces/data_access/ua_y_array_item.js.map +0 -1
  289. package/dist/source/interfaces/state_machine/exclusive_limit_state_machine.d.ts +0 -11
  290. package/dist/source/interfaces/state_machine/exclusive_limit_state_machine.js +0 -3
  291. package/dist/source/interfaces/state_machine/exclusive_limit_state_machine.js.map +0 -1
  292. package/dist/source/interfaces/state_machine/finite_state_machine.d.ts +0 -70
  293. package/dist/source/interfaces/state_machine/finite_state_machine.js +0 -3
  294. package/dist/source/interfaces/state_machine/finite_state_machine.js.map +0 -1
  295. package/dist/source/interfaces/state_machine/program_finite_state_machine.d.ts +0 -74
  296. package/dist/source/interfaces/state_machine/program_finite_state_machine.js +0 -3
  297. package/dist/source/interfaces/state_machine/program_finite_state_machine.js.map +0 -1
  298. package/dist/source/interfaces/state_machine/state_machine.d.ts +0 -342
  299. package/dist/source/interfaces/state_machine/state_machine.js +0 -3
  300. package/dist/source/interfaces/state_machine/state_machine.js.map +0 -1
  301. package/dist/source/interfaces/state_machine/ua_finite_state_variable.d.ts +0 -18
  302. package/dist/source/interfaces/state_machine/ua_finite_state_variable.js +0 -3
  303. package/dist/source/interfaces/state_machine/ua_finite_state_variable.js.map +0 -1
  304. package/dist/source/interfaces/state_machine/ua_state_variable.d.ts +0 -29
  305. package/dist/source/interfaces/state_machine/ua_state_variable.js +0 -3
  306. package/dist/source/interfaces/state_machine/ua_state_variable.js.map +0 -1
  307. package/dist/source/interfaces/state_machine/ua_two_state_variable.d.ts +0 -26
  308. package/dist/source/interfaces/state_machine/ua_two_state_variable.js +0 -3
  309. package/dist/source/interfaces/state_machine/ua_two_state_variable.js.map +0 -1
  310. package/dist/source/interfaces/subscription_diagnostics_variable.d.ts +0 -41
  311. package/dist/source/interfaces/subscription_diagnostics_variable.js +0 -3
  312. package/dist/source/interfaces/subscription_diagnostics_variable.js.map +0 -1
  313. package/dist/src/alarms_and_conditions/base_event_type.d.ts +0 -26
  314. package/dist/src/alarms_and_conditions/base_event_type.js +0 -41
  315. package/dist/src/alarms_and_conditions/base_event_type.js.map +0 -1
  316. package/dist/src/alarms_and_conditions/shelving_state_machine.d.ts +0 -22
  317. package/dist/src/alarms_and_conditions/shelving_state_machine.js +0 -241
  318. package/dist/src/alarms_and_conditions/shelving_state_machine.js.map +0 -1
  319. package/dist/src/alarms_and_conditions/trip_alarm.d.ts +0 -16
  320. package/dist/src/alarms_and_conditions/trip_alarm.js +0 -21
  321. package/dist/src/alarms_and_conditions/trip_alarm.js.map +0 -1
  322. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_base.d.ts +0 -54
  323. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_base.js +0 -255
  324. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_base.js.map +0 -1
  325. package/dist/src/alarms_and_conditions/ua_alarm_condition_base.d.ts +0 -138
  326. package/dist/src/alarms_and_conditions/ua_alarm_condition_base.js +0 -460
  327. package/dist/src/alarms_and_conditions/ua_alarm_condition_base.js.map +0 -1
  328. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm.d.ts +0 -35
  329. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm.js +0 -32
  330. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm.js.map +0 -1
  331. package/dist/src/alarms_and_conditions/ua_condition_base.d.ts +0 -191
  332. package/dist/src/alarms_and_conditions/ua_condition_base.js +0 -1029
  333. package/dist/src/alarms_and_conditions/ua_condition_base.js.map +0 -1
  334. package/dist/src/alarms_and_conditions/ua_discrete_alarm.d.ts +0 -11
  335. package/dist/src/alarms_and_conditions/ua_discrete_alarm.js +0 -58
  336. package/dist/src/alarms_and_conditions/ua_discrete_alarm.js.map +0 -1
  337. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm.d.ts +0 -24
  338. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm.js +0 -59
  339. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm.js.map +0 -1
  340. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm.d.ts +0 -14
  341. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm.js +0 -17
  342. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm.js.map +0 -1
  343. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm.d.ts +0 -22
  344. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm.js +0 -87
  345. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm.js.map +0 -1
  346. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm.d.ts +0 -6
  347. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm.js +0 -11
  348. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm.js.map +0 -1
  349. package/dist/src/alarms_and_conditions/ua_limit_alarm.d.ts +0 -76
  350. package/dist/src/alarms_and_conditions/ua_limit_alarm.js +0 -237
  351. package/dist/src/alarms_and_conditions/ua_limit_alarm.js.map +0 -1
  352. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm.d.ts +0 -27
  353. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm.js +0 -62
  354. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm.js.map +0 -1
  355. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm.d.ts +0 -49
  356. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm.js +0 -176
  357. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm.js.map +0 -1
  358. package/dist/src/alarms_and_conditions/ua_off_normal_alarm.d.ts +0 -47
  359. package/dist/src/alarms_and_conditions/ua_off_normal_alarm.js +0 -151
  360. package/dist/src/alarms_and_conditions/ua_off_normal_alarm.js.map +0 -1
  361. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm.d.ts +0 -16
  362. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm.js +0 -18
  363. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm.js.map +0 -1
  364. package/dist/src/base_node.d.ts +0 -270
  365. package/dist/src/base_node.js +0 -1299
  366. package/dist/src/base_node.js.map +0 -1
  367. package/dist/src/data_access/ua_analog_item.d.ts +0 -13
  368. package/dist/src/data_access/ua_analog_item.js +0 -37
  369. package/dist/src/data_access/ua_analog_item.js.map +0 -1
  370. package/dist/src/data_access/ua_data_item.d.ts +0 -16
  371. package/dist/src/data_access/ua_data_item.js +0 -66
  372. package/dist/src/data_access/ua_data_item.js.map +0 -1
  373. package/dist/src/data_access/ua_multistate_discrete.d.ts +0 -24
  374. package/dist/src/data_access/ua_multistate_discrete.js +0 -132
  375. package/dist/src/data_access/ua_multistate_discrete.js.map +0 -1
  376. package/dist/src/namespace.d.ts +0 -472
  377. package/dist/src/namespace.js +0 -1759
  378. package/dist/src/namespace.js.map +0 -1
  379. package/dist/src/reference.d.ts +0 -43
  380. package/dist/src/reference.js +0 -138
  381. package/dist/src/reference.js.map +0 -1
  382. package/dist/src/session_context.d.ts +0 -4
  383. package/dist/src/session_context.js +0 -9
  384. package/dist/src/session_context.js.map +0 -1
  385. package/dist/src/ua_data_type.d.ts +0 -81
  386. package/dist/src/ua_data_type.js +0 -259
  387. package/dist/src/ua_data_type.js.map +0 -1
  388. package/dist/src/ua_method.d.ts +0 -33
  389. package/dist/src/ua_method.js +0 -194
  390. package/dist/src/ua_method.js.map +0 -1
  391. package/dist/src/ua_object.d.ts +0 -27
  392. package/dist/src/ua_object.js +0 -153
  393. package/dist/src/ua_object.js.map +0 -1
  394. package/dist/src/ua_object_type.d.ts +0 -49
  395. package/dist/src/ua_object_type.js +0 -123
  396. package/dist/src/ua_object_type.js.map +0 -1
  397. package/dist/src/ua_reference_type.d.ts +0 -31
  398. package/dist/src/ua_reference_type.js +0 -108
  399. package/dist/src/ua_reference_type.js.map +0 -1
  400. package/dist/src/ua_variable.d.ts +0 -346
  401. package/dist/src/ua_variable.js +0 -1651
  402. package/dist/src/ua_variable.js.map +0 -1
  403. package/dist/src/ua_variable_type.d.ts +0 -57
  404. package/dist/src/ua_variable_type.js +0 -530
  405. package/dist/src/ua_variable_type.js.map +0 -1
  406. package/dist/src/ua_view.d.ts +0 -16
  407. package/dist/src/ua_view.js +0 -41
  408. package/dist/src/ua_view.js.map +0 -1
@@ -1,1396 +1,1396 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getReferenceType = exports.BaseNodeImpl = exports.makeAttributeEventName = void 0;
4
- /**
5
- * @module node-opcua-address-space
6
- */
7
- const events_1 = require("events");
8
- const chalk = require("chalk");
9
- const lodash_1 = require("lodash");
10
- const node_opcua_assert_1 = require("node-opcua-assert");
11
- const node_opcua_data_model_1 = require("node-opcua-data-model");
12
- const node_opcua_data_value_1 = require("node-opcua-data-value");
13
- const node_opcua_debug_1 = require("node-opcua-debug");
14
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
15
- const node_opcua_status_code_1 = require("node-opcua-status-code");
16
- const node_opcua_types_1 = require("node-opcua-types");
17
- const node_opcua_utils_1 = require("node-opcua-utils");
18
- const node_opcua_variant_1 = require("node-opcua-variant");
19
- const dump_tools_1 = require("../source/helpers/dump_tools");
20
- const session_context_1 = require("../source/session_context");
21
- const cetools = require("./address_space_change_event_tools");
22
- const base_node_private_1 = require("./base_node_private");
23
- const reference_impl_1 = require("./reference_impl");
24
- const role_permissions_1 = require("./role_permissions");
25
- // tslint:disable:no-var-requires
26
- // tslint:disable:no-bitwise
27
- // tslint:disable:no-console
28
- const doDebug = false;
29
- const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
30
- const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
31
- function defaultBrowseFilterFunc(context) {
32
- return true;
33
- }
34
- function _get_QualifiedBrowseName(browseName) {
35
- return (0, node_opcua_data_model_1.coerceQualifiedName)(browseName);
36
- }
37
- function _is_valid_BrowseDirection(browseDirection) {
38
- return (browseDirection === node_opcua_data_model_1.BrowseDirection.Forward ||
39
- browseDirection === node_opcua_data_model_1.BrowseDirection.Inverse ||
40
- browseDirection === node_opcua_data_model_1.BrowseDirection.Both);
41
- }
42
- function makeAttributeEventName(attributeId) {
43
- const attributeName = node_opcua_data_model_1.attributeNameById[attributeId];
44
- return attributeName + "_changed";
45
- }
46
- exports.makeAttributeEventName = makeAttributeEventName;
47
- /**
48
- * Base class for all Node classes
49
- *
50
- * BaseNode is the base class for all the OPCUA objects in the address space
51
- * It provides attributes and a set of references to other nodes.
52
- * see:
53
- * {{#crossLink "UAObject"}}{{/crossLink}},
54
- * {{#crossLink "UAVariable"}}{{/crossLink}},
55
- * {{#crossLink "Reference"}}{{/crossLink}},
56
- * {{#crossLink "UAMethod"}}{{/crossLink}},
57
- * {{#crossLink "UAView"}}{{/crossLink}},
58
- * {{#crossLink "UAObjectType"}}{{/crossLink}},
59
- * {{#crossLink "UADataType"}}{{/crossLink}},
60
- * {{#crossLink "UAVariableType"}}{{/crossLink}},
61
- *
62
- *
63
- */
64
- class BaseNodeImpl extends events_1.EventEmitter {
65
- /**
66
- * @internal
67
- * @param options
68
- */
69
- constructor(options) {
70
- super();
71
- this.nodeClass = node_opcua_data_model_1.NodeClass.Unspecified;
72
- (0, node_opcua_assert_1.assert)(this.nodeClass === node_opcua_data_model_1.NodeClass.Unspecified, "must not be specify a nodeClass");
73
- (0, node_opcua_assert_1.assert)(options.addressSpace); // expecting an address space
74
- (0, node_opcua_assert_1.assert)(options.browseName instanceof node_opcua_data_model_1.QualifiedName, "Expecting a valid QualifiedName");
75
- (0, node_opcua_assert_1.assert)(options.nodeId instanceof node_opcua_nodeid_1.NodeId, "Expecting a valid NodeId");
76
- options.references = options.references || [];
77
- const _private = (0, base_node_private_1.BaseNode_initPrivate)(this);
78
- _private.__address_space = options.addressSpace;
79
- this.nodeId = (0, node_opcua_nodeid_1.resolveNodeId)(options.nodeId);
80
- // QualifiedName
81
- /**
82
- * the node browseName
83
- * @property browseName
84
- * @type QualifiedName
85
- * @static
86
- */
87
- this.browseName = _get_QualifiedBrowseName(options.browseName);
88
- // re-use browseName as displayName if displayName is missing
89
- options.displayName = options.displayName || this.browseName.name.toString();
90
- if (options.description === undefined) {
91
- options.description = null;
92
- }
93
- this._setDisplayName(options.displayName);
94
- this._setDescription(options.description);
95
- // user defined filter function for browsing
96
- const _browseFilter = options.browseFilter || defaultBrowseFilterFunc;
97
- (0, node_opcua_assert_1.assert)(typeof _browseFilter === "function");
98
- _private._browseFilter = _browseFilter;
99
- // normalize reference type
100
- // this will convert any referenceType expressed with its inverseName into
101
- // its normal name and fix the isForward flag accordingly.
102
- // ( e.g "ComponentOf" isForward:true => "HasComponent", isForward:false)
103
- for (const reference of options.references) {
104
- this.__addReference(reference);
105
- }
106
- this._accessRestrictions = options.accessRestrictions;
107
- this._rolePermissions = (0, role_permissions_1.coerceRolePermissions)(options.rolePermissions);
108
- }
109
- static makeAttributeEventName(attributeId) {
110
- return makeAttributeEventName(attributeId);
111
- }
112
- get addressSpace() {
113
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
114
- // istanbul ignore next
115
- if (!_private) {
116
- throw new Error("Internal error , cannot extract private data from " + this.browseName.toString());
117
- }
118
- return _private.__address_space;
119
- }
120
- get addressSpacePrivate() {
121
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
122
- // istanbul ignore next
123
- if (!_private) {
124
- throw new Error("Internal error , cannot extract private data from " + this.browseName.toString());
125
- }
126
- return _private.__address_space;
127
- }
128
- get displayName() {
129
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
130
- return _private._displayName;
131
- }
132
- setDisplayName(value) {
133
- this._setDisplayName(value);
134
- /**
135
- * fires when the displayName is changed.
136
- * @event DisplayName_changed
137
- * @param dataValue {DataValue}
138
- */
139
- this._notifyAttributeChange(node_opcua_data_model_1.AttributeIds.DisplayName);
140
- }
141
- get description() {
142
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
143
- return _private._description;
144
- }
145
- setDescription(value) {
146
- this._setDescription(value);
147
- /**
148
- * fires when the description attribute is changed.
149
- * @event Description_changed
150
- * @param dataValue {DataValue}
151
- */
152
- this._notifyAttributeChange(node_opcua_data_model_1.AttributeIds.Description);
153
- }
154
- /**
155
- * returns the nodeId of this node's Type Definition
156
- */
157
- get typeDefinition() {
158
- const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
159
- if (!_cache.typeDefinition) {
160
- const has_type_definition_ref = this.findReference("HasTypeDefinition", true);
161
- _cache.typeDefinition = has_type_definition_ref ? has_type_definition_ref.nodeId : null;
162
- }
163
- return _cache.typeDefinition;
164
- }
165
- /**
166
- * returns the nodeId of this node's Type Definition
167
- */
168
- get typeDefinitionObj() {
169
- const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
170
- if (undefined === _cache.typeDefinitionObj) {
171
- const nodeId = this.typeDefinition;
172
- _cache.typeDefinitionObj = nodeId ? this.addressSpace.findNode(nodeId) : null;
173
- }
174
- return _cache.typeDefinitionObj;
175
- }
176
- get parentNodeId() {
177
- const parent = this.parent;
178
- return parent ? parent.nodeId : undefined;
179
- }
180
- /**
181
- * namespace index
182
- */
183
- get namespaceIndex() {
184
- return this.nodeId.namespace;
185
- }
186
- /**
187
- * namespace uri
188
- */
189
- get namespaceUri() {
190
- return this.addressSpace.getNamespaceUri(this.namespaceIndex);
191
- }
192
- /**
193
- * the parent node
194
- */
195
- get parent() {
196
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
197
- if (_private._parent === undefined) {
198
- // never been set before
199
- _private._parent = _setup_parent_item.call(this, _private._referenceIdx);
200
- }
201
- return _private._parent || null;
202
- }
203
- /**
204
- * @property modellingRule
205
- * @type {String|undefined}
206
- */
207
- get modellingRule() {
208
- const r = this.findReferencesAsObject("HasModellingRule");
209
- if (!r || r.length === 0) {
210
- return null; /// "? modellingRule missing ?"; // consider "Mandatory"
211
- }
212
- const r0 = r[0];
213
- return r0.browseName.toString();
214
- }
215
- getDisplayName(locale) {
216
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
217
- return _private._displayName[0].text;
218
- }
219
- get namespace() {
220
- return this.addressSpacePrivate.getNamespace(this.nodeId.namespace);
221
- }
222
- // ---------------------------------------------------------------------------------------------------
223
- // Finders
224
- // ---------------------------------------------------------------------------------------------------
225
- findReferencesEx(referenceType, browseDirection) {
226
- browseDirection = browseDirection !== undefined ? browseDirection : node_opcua_data_model_1.BrowseDirection.Forward;
227
- (0, node_opcua_assert_1.assert)(_is_valid_BrowseDirection(browseDirection));
228
- (0, node_opcua_assert_1.assert)(browseDirection !== node_opcua_data_model_1.BrowseDirection.Both);
229
- const referenceTypeNode = this._coerceReferenceType(referenceType);
230
- if (!referenceTypeNode) {
231
- // note: when loading nodeset2.xml files, reference type may not exit yet
232
- // throw new Error("expecting valid reference name " + strReference);
233
- return [];
234
- }
235
- const isForward = browseDirection === node_opcua_data_model_1.BrowseDirection.Forward;
236
- const results = [];
237
- const process = (referenceIdx) => {
238
- const references = Object.values(referenceIdx);
239
- for (const ref of references) {
240
- if (ref.isForward === isForward && referenceTypeNode && referenceTypeNode.checkHasSubtype(ref.referenceType)) {
241
- results.push(ref);
242
- }
243
- }
244
- };
245
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
246
- process(_private._referenceIdx);
247
- process(_private._back_referenceIdx);
248
- return results;
249
- }
250
- findReferences(referenceType, isForward = true) {
251
- const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
252
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
253
- const referenceTypeNode = this._coerceReferenceType(referenceType);
254
- if (!referenceTypeNode) {
255
- // note: when loading nodeset2.xml files, reference type may not exit yet
256
- // throw new Error("expecting valid reference name " + strReference);
257
- return [];
258
- }
259
- const hash = "_ref_" + referenceTypeNode.nodeId.toString() + isForward.toString();
260
- if (_cache[hash]) {
261
- return _cache[hash];
262
- }
263
- // istanbul ignore next
264
- if (doDebug && !this.addressSpace.findReferenceType(referenceTypeNode.nodeId)) {
265
- throw new Error("expecting valid reference name " + referenceType);
266
- }
267
- const result = [];
268
- for (const ref of Object.values(_private._referenceIdx)) {
269
- if (ref.isForward === isForward) {
270
- if ((0, node_opcua_nodeid_1.sameNodeId)(ref.referenceType, referenceTypeNode.nodeId)) {
271
- result.push(ref);
272
- }
273
- }
274
- }
275
- for (const ref of Object.values(_private._back_referenceIdx)) {
276
- if (ref.isForward === isForward) {
277
- if ((0, node_opcua_nodeid_1.sameNodeId)(ref.referenceType, referenceTypeNode.nodeId)) {
278
- result.push(ref);
279
- }
280
- }
281
- }
282
- _cache[hash] = result;
283
- return result;
284
- }
285
- findReference(strReference, isForward) {
286
- const refs = this.findReferences(strReference, isForward);
287
- if (refs.length !== 1 && refs.length !== 0) {
288
- throw new Error("findReference: expecting only one or zero element here");
289
- }
290
- return refs[0] || null;
291
- }
292
- findReferencesExAsObject(referenceType, browseDirection) {
293
- const references = this.findReferencesEx(referenceType, browseDirection);
294
- return _asObject(references, this.addressSpace);
295
- }
296
- findReferencesAsObject(referenceType, isForward) {
297
- const references = this.findReferences(referenceType, isForward);
298
- return _asObject(references, this.addressSpace);
299
- }
300
- /**
301
- * return an array with the Aggregates of this object.
302
- */
303
- getAggregates() {
304
- const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
305
- if (!_cache._aggregates) {
306
- _cache._aggregates = this.findReferencesExAsObject("Aggregates", node_opcua_data_model_1.BrowseDirection.Forward);
307
- }
308
- return _cache._aggregates;
309
- }
310
- /**
311
- * return an array with the components of this object.
312
- */
313
- getComponents() {
314
- const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
315
- if (!_cache._components) {
316
- _cache._components = this.findReferencesExAsObject("HasComponent", node_opcua_data_model_1.BrowseDirection.Forward);
317
- }
318
- return _cache._components;
319
- }
320
- /**
321
- * return a array with the properties of this object.
322
- */
323
- getProperties() {
324
- const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
325
- if (!_cache._properties) {
326
- _cache._properties = this.findReferencesExAsObject("HasProperty", node_opcua_data_model_1.BrowseDirection.Forward);
327
- }
328
- return _cache._properties;
329
- }
330
- /**
331
- * return a array with the notifiers of this object.
332
- */
333
- getNotifiers() {
334
- const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
335
- if (!_cache._notifiers) {
336
- _cache._notifiers = this.findReferencesAsObject("HasNotifier", true);
337
- }
338
- return _cache._notifiers;
339
- }
340
- /**
341
- * return a array with the event source of this object.
342
- */
343
- getEventSources() {
344
- const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
345
- if (!_cache._eventSources) {
346
- _cache._eventSources = this.findReferencesAsObject("HasEventSource", true);
347
- }
348
- return _cache._eventSources;
349
- }
350
- /**
351
- * return a array of the objects for which this node is an EventSource
352
- */
353
- getEventSourceOfs() {
354
- const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
355
- if (!_cache._eventSources) {
356
- _cache._eventSources = this.findReferencesAsObject("HasEventSource", false);
357
- }
358
- return _cache._eventSources;
359
- }
360
- getComponentByName(browseName, namespaceIndex) {
361
- const components = this.getComponents();
362
- const select = _filter_by_browse_name(components, browseName, namespaceIndex);
363
- (0, node_opcua_assert_1.assert)(select.length <= 1, "BaseNode#getComponentByName found duplicated reference");
364
- if (select.length === 1) {
365
- const component = select[0];
366
- if (component.nodeClass === node_opcua_data_model_1.NodeClass.Method) {
367
- warningLog("please use getMethodByName to retrieve a method");
368
- return null;
369
- }
370
- (0, node_opcua_assert_1.assert)(component.nodeClass === node_opcua_data_model_1.NodeClass.Variable || component.nodeClass === node_opcua_data_model_1.NodeClass.Object);
371
- return component;
372
- }
373
- else {
374
- return null;
375
- }
376
- }
377
- getPropertyByName(browseName, namespaceIndex) {
378
- const properties = this.getProperties();
379
- const select = _filter_by_browse_name(properties, browseName, namespaceIndex);
380
- (0, node_opcua_assert_1.assert)(select.length <= 1, "BaseNode#getPropertyByName found duplicated reference");
381
- if (select.length === 1 && select[0].nodeClass !== node_opcua_data_model_1.NodeClass.Variable) {
382
- throw new Error("Expecting a property to be of nodeClass==NodeClass.Variable");
383
- }
384
- return select.length === 1 ? select[0] : null;
385
- }
386
- getFolderElementByName(browseName, namespaceIndex) {
387
- const elements = this.getFolderElements();
388
- const select = _filter_by_browse_name(elements, browseName, namespaceIndex);
389
- return select.length === 1 ? select[0] : null;
390
- }
391
- /**
392
- * returns the list of nodes that this folder object organizes
393
- */
394
- getFolderElements() {
395
- return this.findReferencesExAsObject("Organizes", node_opcua_data_model_1.BrowseDirection.Forward);
396
- }
397
- /**
398
- * returns the list of methods that this object provides
399
- * @method getMethods
400
- * @return an array with Method objects.
401
- *
402
- *
403
- * Note: internally, methods are special types of components
404
- */
405
- getMethods() {
406
- const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
407
- if (!_cache._methods) {
408
- const components = this.getComponents();
409
- _cache._methods = components.filter((obj) => obj.nodeClass === node_opcua_data_model_1.NodeClass.Method);
410
- }
411
- return _cache._methods;
412
- }
413
- /**
414
- * returns the method exposed by this object and with the given nodeId
415
- */
416
- getMethodById(nodeId) {
417
- const methods = this.getMethods();
418
- const found = methods.find((m) => m.nodeId.toString() === nodeId.toString());
419
- return found || null;
420
- }
421
- getMethodByName(methodName, namespaceIndex) {
422
- const methods = this.getMethods();
423
- const select = _filter_by_browse_name(methods, methodName, namespaceIndex);
424
- (0, node_opcua_assert_1.assert)(select.length <= 1, "BaseNode#getMethodByName found duplicated reference");
425
- return select.length === 1 ? select[0] : null;
426
- }
427
- getWriteMask() {
428
- return 0;
429
- }
430
- getUserWriteMask() {
431
- return 0;
432
- }
433
- readAttribute(context, attributeId, indexRange, dataEncoding) {
434
- indexRange;
435
- dataEncoding;
436
- (0, node_opcua_assert_1.assert)(!context || context instanceof session_context_1.SessionContext);
437
- const options = {};
438
- options.statusCode = node_opcua_status_code_1.StatusCodes.Good;
439
- switch (attributeId) {
440
- case node_opcua_data_model_1.AttributeIds.NodeId: // NodeId
441
- options.value = { dataType: node_opcua_variant_1.DataType.NodeId, value: this.nodeId };
442
- break;
443
- case node_opcua_data_model_1.AttributeIds.NodeClass: // NodeClass
444
- (0, node_opcua_assert_1.assert)(isFinite(this.nodeClass));
445
- options.value = { dataType: node_opcua_variant_1.DataType.Int32, value: this.nodeClass };
446
- break;
447
- case node_opcua_data_model_1.AttributeIds.BrowseName: // QualifiedName
448
- (0, node_opcua_assert_1.assert)(this.browseName instanceof node_opcua_data_model_1.QualifiedName);
449
- options.value = { dataType: node_opcua_variant_1.DataType.QualifiedName, value: this.browseName };
450
- break;
451
- case node_opcua_data_model_1.AttributeIds.DisplayName: // LocalizedText
452
- options.value = { dataType: node_opcua_variant_1.DataType.LocalizedText, value: this.displayName[0] };
453
- break;
454
- case node_opcua_data_model_1.AttributeIds.Description: // LocalizedText
455
- options.value = { dataType: node_opcua_variant_1.DataType.LocalizedText, value: this.description };
456
- break;
457
- case node_opcua_data_model_1.AttributeIds.WriteMask:
458
- options.value = { dataType: node_opcua_variant_1.DataType.UInt32, value: this.getWriteMask() };
459
- break;
460
- case node_opcua_data_model_1.AttributeIds.UserWriteMask:
461
- options.value = { dataType: node_opcua_variant_1.DataType.UInt32, value: this.getUserWriteMask() };
462
- break;
463
- case node_opcua_data_model_1.AttributeIds.AccessRestrictions:
464
- return this._readAccessRestrictions(context);
465
- case node_opcua_data_model_1.AttributeIds.RolePermissions:
466
- return this._readRolePermissions(context);
467
- case node_opcua_data_model_1.AttributeIds.UserRolePermissions:
468
- return this._readUserRolePermissions(context);
469
- default:
470
- options.value = null;
471
- options.statusCode = node_opcua_status_code_1.StatusCodes.BadAttributeIdInvalid;
472
- break;
473
- }
474
- // xx options.serverTimestamp = new Date();
475
- return new node_opcua_data_value_1.DataValue(options);
476
- }
477
- writeAttribute(context, writeValue, callback) {
478
- context = context || session_context_1.SessionContext.defaultContext;
479
- (0, node_opcua_assert_1.assert)(context instanceof session_context_1.SessionContext);
480
- (0, node_opcua_assert_1.assert)(typeof callback === "function");
481
- if (writeValue.attributeId === undefined ||
482
- writeValue.attributeId <= 0 ||
483
- writeValue.attributeId > node_opcua_data_model_1.AttributeIds.AccessLevelEx) {
484
- return callback(null, node_opcua_status_code_1.StatusCodes.BadAttributeIdInvalid);
485
- }
486
- // by default Node is read-only,
487
- // this method needs to be overridden to change the behavior
488
- callback(null, node_opcua_status_code_1.StatusCodes.BadNotWritable);
489
- }
490
- fullName() {
491
- if (this.parentNodeId) {
492
- const parent = this.addressSpace.findNode(this.parentNodeId);
493
- // istanbul ignore else
494
- if (parent) {
495
- return parent.fullName() + "." + this.browseName.toString() + "";
496
- }
497
- else {
498
- return "NOT YET REGISTERED" + this.parentNodeId.toString() + "." + this.browseName.toString() + "";
499
- }
500
- }
501
- return this.browseName.toString();
502
- }
503
- ownReferences() {
504
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
505
- return Object.values(_private._referenceIdx);
506
- }
507
- /**
508
- * @method browseNodeByTargetName
509
- *
510
- * @param relativePathElement
511
- * @param isLast
512
- * @return {NodeId[]}
513
- */
514
- browseNodeByTargetName(relativePathElement, isLast) {
515
- relativePathElement.targetName = relativePathElement.targetName || new node_opcua_data_model_1.QualifiedName({});
516
- // part 4.0 v1.03 $7.26 RelativePath
517
- // The BrowseName of the target node.
518
- // The final element may have an empty targetName. In this situation all targets of the references identified by
519
- // the referenceTypeId are the targets of the RelativePath.
520
- // The targetName shall be specified for all other elements.
521
- // The current path cannot be followed any further if no targets with the specified BrowseName exist.
522
- (0, node_opcua_assert_1.assert)(relativePathElement.targetName instanceof node_opcua_data_model_1.QualifiedName);
523
- (0, node_opcua_assert_1.assert)(relativePathElement.targetName.namespaceIndex >= 0);
524
- (0, node_opcua_assert_1.assert)(relativePathElement.targetName.name.length > 0);
525
- // The type of reference to follow from the current node.
526
- // The current path cannot be followed any further if the referenceTypeId is not available on the Node instance.
527
- // If not specified then all References are included and the parameter includeSubtypes is ignored.
528
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(relativePathElement, "referenceTypeId"));
529
- // Indicates whether the inverse Reference should be followed.
530
- // The inverse reference is followed if this value is TRUE.
531
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(relativePathElement, "isInverse"));
532
- // Indicates whether subtypes of the ReferenceType should be followed.
533
- // Subtypes are included if this value is TRUE.
534
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(relativePathElement, "includeSubtypes"));
535
- const references = this.allReferences();
536
- const _check_reference = (reference) => {
537
- if (relativePathElement.referenceTypeId.isEmpty()) {
538
- return true;
539
- }
540
- (0, node_opcua_assert_1.assert)(relativePathElement.referenceTypeId instanceof node_opcua_nodeid_1.NodeId);
541
- if ((relativePathElement.isInverse && reference.isForward) ||
542
- (!relativePathElement.isInverse && !reference.isForward)) {
543
- return false;
544
- }
545
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(reference, "isForward"));
546
- const referenceType = resolveReferenceType(this.addressSpace, reference);
547
- const referenceTypeId = referenceType.nodeId;
548
- if ((0, node_opcua_nodeid_1.sameNodeId)(relativePathElement.referenceTypeId, referenceTypeId)) {
549
- return true;
550
- }
551
- if (relativePathElement.includeSubtypes) {
552
- const baseType = this.addressSpace.findReferenceType(relativePathElement.referenceTypeId);
553
- if (baseType && referenceType.isSupertypeOf(baseType)) {
554
- return true;
555
- }
556
- }
557
- return false;
558
- };
559
- const nodeIdsMap = {};
560
- let nodeIds = [];
561
- for (const reference of references) {
562
- if (!_check_reference(reference)) {
563
- continue;
564
- }
565
- const obj = resolveReferenceNode(this.addressSpace, reference);
566
- // istanbul ignore next
567
- if (!obj) {
568
- throw new Error(" cannot find node with id " + reference.nodeId.toString());
569
- }
570
- if ((0, lodash_1.isEqual)(obj.browseName, relativePathElement.targetName)) {
571
- // compare QualifiedName
572
- const key = obj.nodeId.toString();
573
- if (!Object.prototype.hasOwnProperty.call(nodeIdsMap, key)) {
574
- nodeIds.push(obj.nodeId);
575
- nodeIdsMap[key] = obj;
576
- }
577
- }
578
- }
579
- if (nodeIds.length === 0 && (this.nodeClass === node_opcua_data_model_1.NodeClass.ObjectType || this.nodeClass === node_opcua_data_model_1.NodeClass.VariableType)) {
580
- const nodeType = this;
581
- if (nodeType.subtypeOf) {
582
- // browsing also InstanceDeclarations included in base type
583
- const baseType = this.addressSpace.findNode(nodeType.subtypeOf);
584
- const n = baseType.browseNodeByTargetName(relativePathElement, isLast);
585
- nodeIds = [].concat(nodeIds, n);
586
- }
587
- }
588
- return nodeIds;
589
- }
590
- /**
591
- * browse the node to extract information requested in browseDescription
592
- * and returns an array with reference descriptions
593
- *
594
- *
595
- *
596
- */
597
- browseNode(browseDescription, context) {
598
- (0, node_opcua_assert_1.assert)(isFinite(browseDescription.nodeClassMask));
599
- const do_debug = false;
600
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
601
- const addressSpace = this.addressSpace;
602
- const referenceTypeId = normalize_referenceTypeId(addressSpace, browseDescription.referenceTypeId);
603
- (0, node_opcua_assert_1.assert)(referenceTypeId instanceof node_opcua_nodeid_1.NodeId);
604
- const browseDirection = browseDescription.browseDirection !== undefined ? browseDescription.browseDirection : node_opcua_data_model_1.BrowseDirection.Both;
605
- // get all possible references
606
- let references = this.allReferences();
607
- /* istanbul ignore next */
608
- if (do_debug) {
609
- console.log("all references :", this.nodeId.toString(), this.browseName.toString());
610
- (0, dump_tools_1.dumpReferences)(addressSpace, Object.values(_private._referenceIdx));
611
- }
612
- // filter out references not matching referenceType
613
- references = _filter_by_referenceType.call(this, browseDescription, references, referenceTypeId);
614
- references = _filter_by_direction(references, browseDirection);
615
- references = _filter_by_nodeClass.call(this, references, browseDescription.nodeClassMask);
616
- references = _filter_by_userFilter.call(this, references, context);
617
- if (context) {
618
- references = _filter_by_context(this, references, context);
619
- }
620
- const referenceDescriptions = (0, base_node_private_1._constructReferenceDescription)(addressSpace, references, browseDescription.resultMask);
621
- /* istanbul ignore next */
622
- if (do_debug) {
623
- (0, dump_tools_1.dumpReferenceDescriptions)(this.addressSpace, referenceDescriptions);
624
- }
625
- return referenceDescriptions;
626
- }
627
- allReferences() {
628
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
629
- return Object.values(_private._referenceIdx).concat(Object.values(_private._back_referenceIdx));
630
- }
631
- /**
632
- * @method addReference
633
- * @param reference
634
- * @param reference.referenceType {String}
635
- * @param [reference.isForward = true] {Boolean}
636
- * @param reference.nodeId {Node|NodeId|String}
637
- *
638
- * @example
639
- *
640
- * view.addReference({ referenceType: "Organizes", nodeId: myDevice });
641
- *
642
- * or
643
- *
644
- * myDevice1.addReference({ referenceType: "OrganizedBy", nodeId: view });
645
- */
646
- addReference(reference) {
647
- const referenceNode = this.__addReference(reference);
648
- const addressSpace = this.addressSpace;
649
- if (!resolveReferenceType(addressSpace, referenceNode)) {
650
- throw new Error("BaseNode#addReference : invalid reference " + reference.toString());
651
- }
652
- this._clear_caches();
653
- _propagate_ref.call(this, addressSpace, referenceNode);
654
- this.install_extra_properties();
655
- cetools._handle_add_reference_change_event(this, referenceNode.nodeId);
656
- }
657
- removeReference(referenceOpts) {
658
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
659
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(referenceOpts, "referenceType"));
660
- // xx isForward is optional : assert(Object.prototype.hasOwnProperty.call(reference,"isForward"));
661
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(referenceOpts, "nodeId"));
662
- const addressSpace = this.addressSpace;
663
- // istanbul ignore next
664
- if (!addressSpace) {
665
- console.log(" Where is addressSpace ?");
666
- }
667
- const reference = addressSpace.normalizeReferenceTypes([referenceOpts])[0];
668
- const h = reference.hash;
669
- const relatedNode = addressSpace.findNode(reference.nodeId);
670
- const invReference = new reference_impl_1.ReferenceImpl({
671
- isForward: !reference.isForward,
672
- nodeId: this.nodeId,
673
- referenceType: reference.referenceType
674
- });
675
- if (_private._referenceIdx[h]) {
676
- delete _private._referenceIdx[h];
677
- base_node_private_1.BaseNode_remove_backward_reference.call(relatedNode, invReference);
678
- }
679
- else if (_private._back_referenceIdx[h]) {
680
- relatedNode.removeReference(invReference);
681
- }
682
- else {
683
- // throw new Error("Cannot find reference " + reference);
684
- }
685
- (0, base_node_private_1._handle_HierarchicalReference)(this, reference);
686
- this.uninstall_extra_properties(reference);
687
- this._clear_caches();
688
- }
689
- /**
690
- *
691
- */
692
- resolveNodeId(nodeId) {
693
- return this.addressSpace.resolveNodeId(nodeId);
694
- }
695
- install_extra_properties() {
696
- const addressSpace = this.addressSpace;
697
- if (addressSpace.isFrugal) {
698
- // skipping
699
- return;
700
- }
701
- install_components_as_object_properties(this);
702
- function install_extra_properties_on_parent(ref) {
703
- const node = reference_impl_1.ReferenceImpl.resolveReferenceNode(addressSpace, ref);
704
- install_components_as_object_properties(node);
705
- }
706
- // make sure parent have extra properties updated
707
- const parentComponents = this.findReferencesEx("HasComponent", node_opcua_data_model_1.BrowseDirection.Inverse);
708
- const parentSubfolders = this.findReferencesEx("Organizes", node_opcua_data_model_1.BrowseDirection.Inverse);
709
- const parentProperties = this.findReferencesEx("HasProperty", node_opcua_data_model_1.BrowseDirection.Inverse);
710
- for (const p of parentComponents) {
711
- install_extra_properties_on_parent(p);
712
- }
713
- for (const p of parentSubfolders) {
714
- install_extra_properties_on_parent(p);
715
- }
716
- for (const p of parentProperties) {
717
- install_extra_properties_on_parent(p);
718
- }
719
- }
720
- uninstall_extra_properties(reference) {
721
- const addressSpace = this.addressSpace;
722
- if (addressSpace.isFrugal) {
723
- // skipping
724
- return;
725
- }
726
- const childNode = resolveReferenceNode(addressSpace, reference);
727
- const name = (0, node_opcua_utils_1.lowerFirstLetter)(childNode.browseName.name.toString());
728
- if (Object.prototype.hasOwnProperty.call(reservedNames, name)) {
729
- // istanbul ignore next
730
- if (doDebug) {
731
- // tslint:disable-next-line:no-console
732
- console.log(chalk.bgWhite.red("Ignoring reserved keyword " + name));
733
- }
734
- return;
735
- }
736
- /* istanbul ignore next */
737
- if (!Object.prototype.hasOwnProperty.call(this, name)) {
738
- return;
739
- }
740
- Object.defineProperty(this, name, {
741
- value: undefined
742
- });
743
- }
744
- toString() {
745
- const options = new base_node_private_1.ToStringBuilder();
746
- base_node_private_1.BaseNode_toString.call(this, options);
747
- return options.toString();
748
- }
749
- /**
750
- * @property isFalseSubStateOf
751
- * @type {BaseNode|null}
752
- */
753
- get isFalseSubStateOf() {
754
- const r = this.findReferencesAsObject("HasFalseSubState", false);
755
- if (!r || r.length === 0) {
756
- return null;
757
- }
758
- (0, node_opcua_assert_1.assert)(r.length === 1);
759
- return r[0];
760
- }
761
- /**
762
- * @property isTrueSubStateOf
763
- * @type {BaseNode|null}
764
- */
765
- get isTrueSubStateOf() {
766
- const r = this.findReferencesAsObject("HasTrueSubState", false);
767
- if (!r || r.length === 0) {
768
- return null;
769
- }
770
- (0, node_opcua_assert_1.assert)(r.length === 1);
771
- return r[0];
772
- }
773
- /**
774
- * @method getFalseSubStates
775
- * @return {UAStateVariable[]} return an array with the SubStates of this object.
776
- */
777
- getFalseSubStates() {
778
- return this.findReferencesAsObject("HasFalseSubState");
779
- }
780
- /**
781
- * @method getTrueSubStates
782
- * @return {UAStateVariable[]} return an array with the SubStates of this object.
783
- */
784
- getTrueSubStates() {
785
- return this.findReferencesAsObject("HasTrueSubState");
786
- }
787
- findHierarchicalReferences() {
788
- return this.findReferencesEx("HierarchicalReferences", node_opcua_data_model_1.BrowseDirection.Forward);
789
- }
790
- getChildByName(browseName, namespaceIndex) {
791
- // Attention: getChild doesn't care about namespace on browseName
792
- // !!!!
793
- if (browseName instanceof node_opcua_data_model_1.QualifiedName) {
794
- browseName = browseName.name.toString();
795
- }
796
- (0, node_opcua_assert_1.assert)(typeof browseName === "string");
797
- const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
798
- const addressSpace = this.addressSpace;
799
- if (!_cache._childByNameMap) {
800
- _cache._childByNameMap = {};
801
- const childReferenceTypes = this.findReferencesEx("HasChild");
802
- for (const r of childReferenceTypes) {
803
- const child = resolveReferenceNode(addressSpace, r);
804
- _cache._childByNameMap[child.browseName.name.toString()] = child;
805
- }
806
- }
807
- const ret = _cache._childByNameMap[browseName.toString()] || null;
808
- return ret;
809
- }
810
- get toStateNode() {
811
- const nodes = this.findReferencesAsObject("ToState", true);
812
- (0, node_opcua_assert_1.assert)(nodes.length <= 1);
813
- return nodes.length === 1 ? nodes[0] : null;
814
- }
815
- get fromStateNode() {
816
- const nodes = this.findReferencesAsObject("FromState", true);
817
- (0, node_opcua_assert_1.assert)(nodes.length <= 1);
818
- return nodes.length === 1 ? nodes[0] : null;
819
- }
820
- /**
821
- * this methods propagates the forward references to the pointed node
822
- * by inserting backward references to the counter part node
823
- */
824
- propagate_back_references() {
825
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
826
- if (this.addressSpace.suspendBackReference) {
827
- // this indicates that the base node is constructed from an xml definition
828
- // propagate_back_references will be called later once the file has been completely processed.
829
- return;
830
- }
831
- const addressSpace = this.addressSpace;
832
- for (const reference of Object.values(_private._referenceIdx)) {
833
- _propagate_ref.call(this, addressSpace, reference);
834
- }
835
- }
836
- /**
837
- * the dispose method should be called when the node is no longer used, to release
838
- * back pointer to the address space and clear caches.
839
- *
840
- * @method dispose
841
- *
842
- */
843
- dispose() {
844
- this.emit("dispose");
845
- this.removeAllListeners();
846
- this._clear_caches();
847
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
848
- Object.values(_private._back_referenceIdx).forEach((ref) => ref.dispose());
849
- Object.values(_private._referenceIdx).forEach((ref) => ref.dispose());
850
- (0, base_node_private_1.BaseNode_removePrivate)(this);
851
- }
852
- // istanbul ignore next
853
- dumpXML(xmlWriter) {
854
- console.error(" This ", node_opcua_data_model_1.NodeClass[this.nodeClass]);
855
- (0, node_opcua_assert_1.assert)(false, "BaseNode#dumpXML NOT IMPLEMENTED !");
856
- (0, node_opcua_assert_1.assert)(xmlWriter);
857
- }
858
- /**
859
- * Undo the effect of propagate_back_references
860
- */
861
- unpropagate_back_references() {
862
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
863
- const addressSpace = this.addressSpace;
864
- for (const reference of Object.values(_private._referenceIdx)) {
865
- // filter out non Hierarchical References
866
- const referenceType = resolveReferenceType(addressSpace, reference);
867
- // istanbul ignore next
868
- if (!referenceType) {
869
- console.error(chalk.red(" ERROR"), " cannot find reference ", reference.referenceType, reference.toString());
870
- }
871
- const related_node = resolveReferenceNode(addressSpace, reference);
872
- if (related_node) {
873
- (0, node_opcua_assert_1.assert)(reference.nodeId.toString() !== this.nodeId.toString());
874
- base_node_private_1.BaseNode_remove_backward_reference.call(related_node, new reference_impl_1.ReferenceImpl({
875
- isForward: !reference.isForward,
876
- nodeId: this.nodeId,
877
- referenceType: reference.referenceType
878
- }));
879
- } // else addressSpace may be incomplete
880
- }
881
- }
882
- installPostInstallFunc(f) {
883
- if (!f) {
884
- // nothing to do
885
- return;
886
- }
887
- function chain(f1, f2) {
888
- return function chaiFunc(...args) {
889
- if (f1) {
890
- f1.apply(this, args);
891
- }
892
- if (f2) {
893
- f2.apply(this, args);
894
- }
895
- };
896
- }
897
- this._postInstantiateFunc = chain.call(this, this._postInstantiateFunc, f);
898
- }
899
- _on_child_added() {
900
- this._clear_caches();
901
- }
902
- _on_child_removed(obj) {
903
- // obj; // unused;
904
- this._clear_caches();
905
- }
906
- /**
907
- * @private
908
- * @param reference
909
- */
910
- _add_backward_reference(reference) {
911
- base_node_private_1.BaseNode_add_backward_reference.call(this, reference);
912
- }
913
- _coerceReferenceType(referenceType) {
914
- let result;
915
- if (typeof referenceType === "string") {
916
- result = this.addressSpace.findReferenceType(referenceType);
917
- /* istanbul ignore next */
918
- if (!result) {
919
- errorLog("referenceType ", referenceType, " cannot be found");
920
- throw new Error("Cannot coerce reference with name " + referenceType);
921
- }
922
- }
923
- else if (referenceType instanceof node_opcua_nodeid_1.NodeId) {
924
- result = this.addressSpace.findNode(referenceType);
925
- if (!result) {
926
- return null;
927
- }
928
- }
929
- else {
930
- result = referenceType;
931
- }
932
- (0, node_opcua_assert_1.assert)(result, "reference must exists");
933
- (0, node_opcua_assert_1.assert)(result.nodeClass === node_opcua_data_model_1.NodeClass.ReferenceType);
934
- return result;
935
- }
936
- __addReference(referenceOpts) {
937
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
938
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(referenceOpts, "referenceType"));
939
- // xx isForward is optional : assert(Object.prototype.hasOwnProperty.call(reference,"isForward"));
940
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(referenceOpts, "nodeId"));
941
- const addressSpace = this.addressSpace;
942
- const reference = addressSpace.normalizeReferenceTypes([referenceOpts])[0];
943
- (0, node_opcua_assert_1.assert)(reference instanceof reference_impl_1.ReferenceImpl);
944
- const h = reference.hash;
945
- (0, node_opcua_assert_1.assert)(!_private._back_referenceIdx[h], "reference exists already in _back_references");
946
- (0, node_opcua_assert_1.assert)(!_private._referenceIdx[h], "reference exists already in _references");
947
- _private._referenceIdx[h] = reference;
948
- (0, base_node_private_1._handle_HierarchicalReference)(this, reference);
949
- return reference;
950
- }
951
- _setDisplayName(displayName) {
952
- const displayNames = Array.isArray(displayName) ? displayName : [displayName];
953
- const _displayNames = displayNames.map(node_opcua_data_model_1.coerceLocalizedText);
954
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
955
- _private._displayName = _displayNames;
956
- }
957
- _setDescription(description) {
958
- const __description = (0, node_opcua_data_model_1.coerceLocalizedText)(description);
959
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
960
- _private._description = __description;
961
- }
962
- _notifyAttributeChange(attributeId) {
963
- const event_name = BaseNodeImpl.makeAttributeEventName(attributeId);
964
- this.emit(event_name, this.readAttribute(session_context_1.SessionContext.defaultContext, attributeId));
965
- }
966
- _clear_caches() {
967
- (0, base_node_private_1.BaseNode_clearCache)(this);
968
- }
969
- _readAccessRestrictions(context) {
970
- // https://reference.opcfoundation.org/v104/Core/docs/Part3/8.56/
971
- if (this.accessRestrictions === undefined) {
972
- return new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadAttributeIdInvalid });
973
- }
974
- return new node_opcua_data_value_1.DataValue({
975
- statusCode: node_opcua_status_code_1.StatusCodes.Good,
976
- value: {
977
- dataType: node_opcua_variant_1.DataType.UInt16,
978
- value: this.accessRestrictions
979
- }
980
- });
981
- }
982
- _readRolePermissions(context) {
983
- // https://reference.opcfoundation.org/v104/Core/docs/Part3/4.8.3/
984
- // to do check that current user can read permission
985
- if (context && !(context === null || context === void 0 ? void 0 : context.checkPermission(this, node_opcua_types_1.PermissionType.ReadRolePermissions))) {
986
- return new node_opcua_data_value_1.DataValue({
987
- statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient
988
- });
989
- }
990
- if (this.rolePermissions === undefined) {
991
- // to do : If not specified, the value of DefaultUserRolePermissions Property from
992
- // the Namespace Metadata Object associated with the Node is used instead.
993
- return new node_opcua_data_value_1.DataValue({
994
- statusCode: node_opcua_status_code_1.StatusCodes.BadAttributeIdInvalid
995
- });
996
- }
997
- const rolePermissions = this.rolePermissions.map(({ roleId, permissions }) => {
998
- return new node_opcua_types_1.RolePermissionType({
999
- roleId: toRoleNodeId(roleId),
1000
- permissions
1001
- });
1002
- });
1003
- return new node_opcua_data_value_1.DataValue({
1004
- statusCode: node_opcua_status_code_1.StatusCodes.Good,
1005
- value: {
1006
- dataType: node_opcua_variant_1.DataType.ExtensionObject,
1007
- arrayType: node_opcua_variant_1.VariantArrayType.Array,
1008
- value: rolePermissions
1009
- }
1010
- });
1011
- }
1012
- _readUserRolePermissions(context) {
1013
- if (this.rolePermissions === undefined) {
1014
- // to do : If not specified, the value of DefaultUserRolePermissions Property from
1015
- // the Namespace Metadata Object associated with the Node is used instead.
1016
- return new node_opcua_data_value_1.DataValue({
1017
- statusCode: node_opcua_status_code_1.StatusCodes.BadAttributeIdInvalid
1018
- });
1019
- }
1020
- const context1 = context === null ? session_context_1.SessionContext.defaultContext : context;
1021
- // for the time being ...
1022
- // get user Permission
1023
- const rolePermissions = this.rolePermissions
1024
- .map(({ roleId, permissions }) => {
1025
- return new node_opcua_types_1.RolePermissionType({
1026
- roleId: toRoleNodeId(roleId),
1027
- permissions
1028
- });
1029
- })
1030
- .filter(({ roleId }) => context1.currentUserHasRole(roleId));
1031
- return new node_opcua_data_value_1.DataValue({
1032
- statusCode: node_opcua_status_code_1.StatusCodes.Good,
1033
- value: {
1034
- dataType: node_opcua_variant_1.DataType.ExtensionObject,
1035
- arrayType: node_opcua_variant_1.VariantArrayType.Array,
1036
- value: rolePermissions
1037
- }
1038
- });
1039
- }
1040
- /**
1041
- *
1042
- * @param rolePermissions
1043
- */
1044
- setRolePermissions(rolePermissions) {
1045
- this._rolePermissions = (0, role_permissions_1.coerceRolePermissions)(rolePermissions);
1046
- }
1047
- getRolePermissions(inherited) {
1048
- if (this.rolePermissions === undefined && inherited) {
1049
- return this.namespace.getDefaultRolePermissions();
1050
- }
1051
- return this._rolePermissions || null;
1052
- }
1053
- get rolePermissions() {
1054
- return this._rolePermissions || undefined;
1055
- }
1056
- setAccessRestrictions(accessRestrictions) {
1057
- this._accessRestrictions = accessRestrictions;
1058
- }
1059
- get accessRestrictions() {
1060
- return this._accessRestrictions;
1061
- }
1062
- getAccessRestrictions(inherited) {
1063
- if (this._accessRestrictions === undefined && inherited) {
1064
- return this.namespace.getDefaultAccessRestrictions();
1065
- }
1066
- return this._accessRestrictions || node_opcua_data_model_1.AccessRestrictionsFlag.None;
1067
- }
1068
- }
1069
- exports.BaseNodeImpl = BaseNodeImpl;
1070
- function toRoleNodeId(s) {
1071
- if (typeof s === "string") {
1072
- return (0, node_opcua_nodeid_1.resolveNodeId)(session_context_1.WellKnownRolesNodeId[s]);
1073
- }
1074
- return (0, node_opcua_nodeid_1.coerceNodeId)(s);
1075
- }
1076
- let displayWarning = true;
1077
- function toString_ReferenceDescription(ref, options) {
1078
- const addressSpace = options.addressSpace;
1079
- // xx assert(ref instanceof ReferenceDescription);
1080
- const refNode = addressSpace.findNode(ref.referenceType);
1081
- if (!refNode) {
1082
- return "Unknown Ref : " + ref;
1083
- }
1084
- const r = new reference_impl_1.ReferenceImpl({
1085
- isForward: ref.isForward,
1086
- nodeId: ref.nodeId,
1087
- referenceType: refNode.browseName.toString()
1088
- });
1089
- const str = r.toString(options);
1090
- r.dispose();
1091
- return str;
1092
- }
1093
- function _setup_parent_item(references) {
1094
- references = Object.values(references);
1095
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
1096
- (0, node_opcua_assert_1.assert)(!_private._parent, "_setup_parent_item has been already called");
1097
- const addressSpace = this.addressSpace;
1098
- if (references.length > 0) {
1099
- references = this.findReferencesEx("Aggregates", node_opcua_data_model_1.BrowseDirection.Inverse);
1100
- if (references.length >= 1) {
1101
- // istanbul ignore next
1102
- if (references.length > 1) {
1103
- if (displayWarning) {
1104
- const options = { addressSpace };
1105
- // tslint:disable-next-line:no-console
1106
- console.warn(" More than one Aggregates reference have been found for parent of object");
1107
- // tslint:disable-next-line:no-console
1108
- console.warn(" object node id:", this.nodeId.toString(), chalk.cyan(this.browseName.toString()));
1109
- // tslint:disable-next-line:no-console
1110
- console.warn(" browseResults:");
1111
- // tslint:disable-next-line:no-console
1112
- console.warn(references.map((f) => toString_ReferenceDescription(f, options)).join("\n"));
1113
- // tslint:disable-next-line:no-console
1114
- console.warn(" first one will be used as parent");
1115
- // xx assert(browseResults.length === 1);
1116
- displayWarning = false;
1117
- }
1118
- }
1119
- return reference_impl_1.ReferenceImpl.resolveReferenceNode(addressSpace, references[0]);
1120
- }
1121
- }
1122
- return null;
1123
- }
1124
- function _asObject(references, addressSpace) {
1125
- function toObject(reference) {
1126
- const obj = resolveReferenceNode(addressSpace, reference);
1127
- // istanbul ignore next
1128
- if (false && !obj) {
1129
- // tslint:disable-next-line:no-console
1130
- console.log(chalk.red(" Warning : object with nodeId ") +
1131
- chalk.cyan(reference.nodeId.toString()) +
1132
- chalk.red(" cannot be found in the address space !"));
1133
- }
1134
- return obj;
1135
- }
1136
- function remove_null(o) {
1137
- return !!o;
1138
- }
1139
- return references.map(toObject).filter(remove_null);
1140
- }
1141
- function _filter_by_browse_name(components, browseName, namespaceIndex) {
1142
- let select = [];
1143
- if ((namespaceIndex === null || namespaceIndex === undefined) && typeof browseName === "string") {
1144
- select = components.filter((c) => c.browseName.name.toString() === browseName);
1145
- if (select && select.length > 1) {
1146
- warningLog("Multiple children exist with name ", browseName, " please specify a namespace index");
1147
- }
1148
- }
1149
- else {
1150
- const _browseName = (0, node_opcua_data_model_1.coerceQualifiedName)(typeof browseName === "string" ? { name: browseName, namespaceIndex } : browseName);
1151
- select = components.filter((c) => c.browseName.name === _browseName.name && c.browseName.namespaceIndex === _browseName.namespaceIndex);
1152
- }
1153
- return select;
1154
- }
1155
- let displayWarningReferencePointingToItSelf = true;
1156
- function _is_massively_used_reference(referenceType) {
1157
- const name = referenceType.browseName.toString();
1158
- return name === "HasTypeDefinition" || name === "HasModellingRule";
1159
- }
1160
- function _propagate_ref(addressSpace, reference) {
1161
- // filter out non Hierarchical References
1162
- const referenceType = reference_impl_1.ReferenceImpl.resolveReferenceType(addressSpace, reference);
1163
- // istanbul ignore next
1164
- if (!referenceType) {
1165
- // tslint:disable-next-line:no-console
1166
- console.error(chalk.red(" ERROR"), " cannot find reference ", reference.referenceType, reference.toString());
1167
- }
1168
- // ------------------------------- Filter out back reference when reference type
1169
- // is HasTypeDefinition, HasModellingRule, etc ...
1170
- //
1171
- // var referenceNode = Reference.resolveReferenceNode(addressSpace,reference);
1172
- // ignore propagation on back reference to UAVariableType or UAObject Type reference
1173
- // because there are too many !
1174
- if (!referenceType || _is_massively_used_reference(referenceType)) {
1175
- return;
1176
- }
1177
- // ------------------------------- EXPERIMENT
1178
- // xx if (!referenceType.isSupertypeOf(hierarchicalReferencesId)) { return; }
1179
- const related_node = resolveReferenceNode(addressSpace, reference);
1180
- if (related_node) {
1181
- // verify that reference doesn't point to object it this (see mantis 3099)
1182
- if ((0, node_opcua_nodeid_1.sameNodeId)(reference.nodeId, this.nodeId)) {
1183
- // istanbul ignore next
1184
- if (displayWarningReferencePointingToItSelf) {
1185
- // this could happen with method
1186
- console.warn(" Warning: a Reference is pointing to this ", this.nodeId.toString(), this.browseName.toString());
1187
- displayWarningReferencePointingToItSelf = false;
1188
- }
1189
- }
1190
- // xx ignore this assert(reference.nodeId.toString() !== this.nodeId.toString());
1191
- // function w(s,l) { return (s+" ").substring(0,l);}
1192
- // if (reference.isForward) {
1193
- // console.log(" CHILD => ",w(related_node.browseName + " " + related_node.nodeId.toString(),30),
1194
- // " PARENT ",w(this.browseName + " " + this.nodeId.toString(),30) , reference.toString());
1195
- // } else {
1196
- // console.log(" CHILD => ",w(this.browseName + " " + this.nodeId.toString(),30),
1197
- // " PARENT ",w(related_node.browseName + " " + related_node.nodeId.toString(),30) , reference.toString());
1198
- //
1199
- // }
1200
- related_node._add_backward_reference(new reference_impl_1.ReferenceImpl({
1201
- _referenceType: getReferenceType(reference),
1202
- isForward: !reference.isForward,
1203
- node: this,
1204
- nodeId: this.nodeId,
1205
- referenceType: reference.referenceType
1206
- }));
1207
- } // else addressSpace may be incomplete and under construction (while loading a nodeset.xml file for instance)
1208
- }
1209
- function nodeid_is_nothing(nodeid) {
1210
- return nodeid.value === 0 && nodeid.namespace === 0;
1211
- }
1212
- /**
1213
- * @method normalize_referenceTypeId
1214
- * @param addressSpace {IAddressSpace}
1215
- * @param referenceTypeId {String|NodeId|null} : the referenceType either as a string or a nodeId
1216
- * @return {NodeId}
1217
- */
1218
- function normalize_referenceTypeId(addressSpace, referenceTypeId) {
1219
- if (!referenceTypeId) {
1220
- return (0, node_opcua_nodeid_1.makeNodeId)(0);
1221
- }
1222
- if (typeof referenceTypeId === "string") {
1223
- const ref = addressSpace.findReferenceType(referenceTypeId);
1224
- if (ref) {
1225
- return ref.nodeId;
1226
- }
1227
- }
1228
- let nodeId;
1229
- try {
1230
- nodeId = addressSpace.resolveNodeId(referenceTypeId);
1231
- }
1232
- catch (err) {
1233
- console.log("cannot normalize_referenceTypeId", referenceTypeId);
1234
- throw err;
1235
- }
1236
- (0, node_opcua_assert_1.assert)(nodeId);
1237
- return nodeId;
1238
- }
1239
- const resolveReferenceNode = reference_impl_1.ReferenceImpl.resolveReferenceNode;
1240
- const resolveReferenceType = reference_impl_1.ReferenceImpl.resolveReferenceType;
1241
- function _filter_by_referenceType(browseDescription, references, referenceTypeId) {
1242
- // make sure we have a valid referenceTypeId if not null
1243
- if (!nodeid_is_nothing(referenceTypeId)) {
1244
- (0, node_opcua_assert_1.assert)(referenceTypeId instanceof node_opcua_nodeid_1.NodeId);
1245
- const referenceType = this.addressSpace.findNode(referenceTypeId);
1246
- (0, node_opcua_debug_1.dumpIf)(!referenceType, referenceTypeId);
1247
- // istanbul ignore next
1248
- if (!referenceType || referenceType.nodeClass !== node_opcua_data_model_1.NodeClass.ReferenceType) {
1249
- throw new Error("Cannot find reference type");
1250
- }
1251
- if (!browseDescription.includeSubtypes && referenceType.isAbstract) {
1252
- warningLog("filter by reference will skip all reference as referenceType is abstract and includeSubtypes is false");
1253
- }
1254
- references = references.filter((reference) => {
1255
- const ref = resolveReferenceType(this.addressSpace, reference);
1256
- // istanbul ignore next
1257
- if (!ref) {
1258
- throw new Error("Cannot find reference type " + reference.toString());
1259
- }
1260
- // unknown type ... this may happen when the address space is not fully build
1261
- (0, node_opcua_assert_1.assert)(ref.nodeClass === node_opcua_data_model_1.NodeClass.ReferenceType);
1262
- const isSameType = (0, node_opcua_nodeid_1.sameNodeId)(ref.nodeId, referenceType.nodeId);
1263
- if (isSameType) {
1264
- return true;
1265
- }
1266
- if (browseDescription.includeSubtypes) {
1267
- return ref.isSupertypeOf(referenceType);
1268
- }
1269
- else {
1270
- return false;
1271
- }
1272
- });
1273
- }
1274
- return references;
1275
- }
1276
- function forwardOnly(reference) {
1277
- return reference.isForward;
1278
- }
1279
- function reverseOnly(reference) {
1280
- return !reference.isForward;
1281
- }
1282
- function _filter_by_direction(references, browseDirection) {
1283
- if (browseDirection === node_opcua_data_model_1.BrowseDirection.Both) {
1284
- return references;
1285
- }
1286
- if (browseDirection === node_opcua_data_model_1.BrowseDirection.Forward) {
1287
- return references.filter(forwardOnly);
1288
- }
1289
- else {
1290
- return references.filter(reverseOnly);
1291
- }
1292
- }
1293
- /*
1294
- function _filter_by_context(node: BaseNode, references: Reference[], context: SessionContext): Reference[] {
1295
- if (!context.isBrowseAccessRestricted(node)) {
1296
- return references;
1297
- }
1298
- // browse access is restricted for forward
1299
- return [];
1300
- }
1301
- */
1302
- function _filter_by_context(node, references, context) {
1303
- const addressSpace = node.addressSpace;
1304
- return references.filter((reference) => !context.isBrowseAccessRestricted(resolveReferenceNode(addressSpace, reference)));
1305
- }
1306
- function _filter_by_nodeClass(references, nodeClassMask) {
1307
- (0, node_opcua_assert_1.assert)(isFinite(nodeClassMask));
1308
- if (nodeClassMask === 0) {
1309
- return references;
1310
- }
1311
- const addressSpace = this.addressSpace;
1312
- return references.filter((reference) => {
1313
- const obj = resolveReferenceNode(addressSpace, reference);
1314
- if (!obj) {
1315
- return false;
1316
- }
1317
- const nodeClassName = node_opcua_data_model_1.NodeClass[obj.nodeClass];
1318
- const value = (0, node_opcua_data_model_1.makeNodeClassMask)(nodeClassName);
1319
- return (value & nodeClassMask) === value;
1320
- });
1321
- }
1322
- function _filter_by_userFilter(references, context) {
1323
- const addressSpace = this.addressSpace;
1324
- return references.filter((reference) => {
1325
- const obj = resolveReferenceNode(addressSpace, reference);
1326
- // istanbul ignore next
1327
- if (!obj) {
1328
- return false;
1329
- }
1330
- const _private = (0, base_node_private_1.BaseNode_getPrivate)(obj);
1331
- // istanbul ignore next
1332
- if (!_private._browseFilter) {
1333
- throw Error("Internal error : cannot find browseFilter");
1334
- }
1335
- const filter1 = _private._browseFilter.call(obj, context);
1336
- return filter1;
1337
- });
1338
- }
1339
- const reservedNames = {
1340
- __description: 0,
1341
- __displayName: 0,
1342
- browseName: 0,
1343
- description: 0,
1344
- displayName: 0,
1345
- nodeClass: 0,
1346
- nodeId: 0,
1347
- typeDefinition: 0
1348
- };
1349
- /*
1350
- * install hierarchical references as javascript properties
1351
- * Components/Properties/Organizes
1352
- */
1353
- function install_components_as_object_properties(parentObj) {
1354
- if (!parentObj) {
1355
- return;
1356
- }
1357
- const addressSpace = parentObj.addressSpace;
1358
- const hierarchicalRefs = parentObj.findHierarchicalReferences();
1359
- const children = hierarchicalRefs.map((r) => reference_impl_1.ReferenceImpl.resolveReferenceNode(addressSpace, r));
1360
- for (const child of children) {
1361
- if (!child) {
1362
- continue;
1363
- }
1364
- // assumption: we ignore namespace here .
1365
- const name = (0, node_opcua_utils_1.lowerFirstLetter)(child.browseName.name.toString());
1366
- if (Object.prototype.hasOwnProperty.call(reservedNames, name)) {
1367
- // ignore reserved names
1368
- if (doDebug) {
1369
- console.log(chalk.bgWhite.red("Ignoring reserved keyword " + name));
1370
- }
1371
- continue;
1372
- }
1373
- // ignore reserved names
1374
- if (doDebug) {
1375
- console.log("Installing property " + name, " on ", parentObj.browseName.toString());
1376
- }
1377
- /* istanbul ignore next */
1378
- if (Object.prototype.hasOwnProperty.call(parentObj, name)) {
1379
- continue;
1380
- }
1381
- Object.defineProperty(parentObj, name, {
1382
- configurable: true,
1383
- enumerable: true,
1384
- // xx writable: false,
1385
- get() {
1386
- return child;
1387
- }
1388
- // value: child
1389
- });
1390
- }
1391
- }
1392
- function getReferenceType(reference) {
1393
- return reference._referenceType;
1394
- }
1395
- exports.getReferenceType = getReferenceType;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getReferenceType = exports.BaseNodeImpl = exports.makeAttributeEventName = void 0;
4
+ /**
5
+ * @module node-opcua-address-space
6
+ */
7
+ const events_1 = require("events");
8
+ const chalk = require("chalk");
9
+ const lodash_1 = require("lodash");
10
+ const node_opcua_assert_1 = require("node-opcua-assert");
11
+ const node_opcua_data_model_1 = require("node-opcua-data-model");
12
+ const node_opcua_data_value_1 = require("node-opcua-data-value");
13
+ const node_opcua_debug_1 = require("node-opcua-debug");
14
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
15
+ const node_opcua_status_code_1 = require("node-opcua-status-code");
16
+ const node_opcua_types_1 = require("node-opcua-types");
17
+ const node_opcua_utils_1 = require("node-opcua-utils");
18
+ const node_opcua_variant_1 = require("node-opcua-variant");
19
+ const dump_tools_1 = require("../source/helpers/dump_tools");
20
+ const session_context_1 = require("../source/session_context");
21
+ const cetools = require("./address_space_change_event_tools");
22
+ const base_node_private_1 = require("./base_node_private");
23
+ const reference_impl_1 = require("./reference_impl");
24
+ const role_permissions_1 = require("./role_permissions");
25
+ // tslint:disable:no-var-requires
26
+ // tslint:disable:no-bitwise
27
+ // tslint:disable:no-console
28
+ const doDebug = false;
29
+ const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
30
+ const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
31
+ function defaultBrowseFilterFunc(context) {
32
+ return true;
33
+ }
34
+ function _get_QualifiedBrowseName(browseName) {
35
+ return (0, node_opcua_data_model_1.coerceQualifiedName)(browseName);
36
+ }
37
+ function _is_valid_BrowseDirection(browseDirection) {
38
+ return (browseDirection === node_opcua_data_model_1.BrowseDirection.Forward ||
39
+ browseDirection === node_opcua_data_model_1.BrowseDirection.Inverse ||
40
+ browseDirection === node_opcua_data_model_1.BrowseDirection.Both);
41
+ }
42
+ function makeAttributeEventName(attributeId) {
43
+ const attributeName = node_opcua_data_model_1.attributeNameById[attributeId];
44
+ return attributeName + "_changed";
45
+ }
46
+ exports.makeAttributeEventName = makeAttributeEventName;
47
+ /**
48
+ * Base class for all Node classes
49
+ *
50
+ * BaseNode is the base class for all the OPCUA objects in the address space
51
+ * It provides attributes and a set of references to other nodes.
52
+ * see:
53
+ * {{#crossLink "UAObject"}}{{/crossLink}},
54
+ * {{#crossLink "UAVariable"}}{{/crossLink}},
55
+ * {{#crossLink "Reference"}}{{/crossLink}},
56
+ * {{#crossLink "UAMethod"}}{{/crossLink}},
57
+ * {{#crossLink "UAView"}}{{/crossLink}},
58
+ * {{#crossLink "UAObjectType"}}{{/crossLink}},
59
+ * {{#crossLink "UADataType"}}{{/crossLink}},
60
+ * {{#crossLink "UAVariableType"}}{{/crossLink}},
61
+ *
62
+ *
63
+ */
64
+ class BaseNodeImpl extends events_1.EventEmitter {
65
+ /**
66
+ * @internal
67
+ * @param options
68
+ */
69
+ constructor(options) {
70
+ super();
71
+ this.nodeClass = node_opcua_data_model_1.NodeClass.Unspecified;
72
+ (0, node_opcua_assert_1.assert)(this.nodeClass === node_opcua_data_model_1.NodeClass.Unspecified, "must not be specify a nodeClass");
73
+ (0, node_opcua_assert_1.assert)(options.addressSpace); // expecting an address space
74
+ (0, node_opcua_assert_1.assert)(options.browseName instanceof node_opcua_data_model_1.QualifiedName, "Expecting a valid QualifiedName");
75
+ (0, node_opcua_assert_1.assert)(options.nodeId instanceof node_opcua_nodeid_1.NodeId, "Expecting a valid NodeId");
76
+ options.references = options.references || [];
77
+ const _private = (0, base_node_private_1.BaseNode_initPrivate)(this);
78
+ _private.__address_space = options.addressSpace;
79
+ this.nodeId = (0, node_opcua_nodeid_1.resolveNodeId)(options.nodeId);
80
+ // QualifiedName
81
+ /**
82
+ * the node browseName
83
+ * @property browseName
84
+ * @type QualifiedName
85
+ * @static
86
+ */
87
+ this.browseName = _get_QualifiedBrowseName(options.browseName);
88
+ // re-use browseName as displayName if displayName is missing
89
+ options.displayName = options.displayName || this.browseName.name.toString();
90
+ if (options.description === undefined) {
91
+ options.description = null;
92
+ }
93
+ this._setDisplayName(options.displayName);
94
+ this._setDescription(options.description);
95
+ // user defined filter function for browsing
96
+ const _browseFilter = options.browseFilter || defaultBrowseFilterFunc;
97
+ (0, node_opcua_assert_1.assert)(typeof _browseFilter === "function");
98
+ _private._browseFilter = _browseFilter;
99
+ // normalize reference type
100
+ // this will convert any referenceType expressed with its inverseName into
101
+ // its normal name and fix the isForward flag accordingly.
102
+ // ( e.g "ComponentOf" isForward:true => "HasComponent", isForward:false)
103
+ for (const reference of options.references) {
104
+ this.__addReference(reference);
105
+ }
106
+ this._accessRestrictions = options.accessRestrictions;
107
+ this._rolePermissions = (0, role_permissions_1.coerceRolePermissions)(options.rolePermissions);
108
+ }
109
+ static makeAttributeEventName(attributeId) {
110
+ return makeAttributeEventName(attributeId);
111
+ }
112
+ get addressSpace() {
113
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
114
+ // istanbul ignore next
115
+ if (!_private) {
116
+ throw new Error("Internal error , cannot extract private data from " + this.browseName.toString());
117
+ }
118
+ return _private.__address_space;
119
+ }
120
+ get addressSpacePrivate() {
121
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
122
+ // istanbul ignore next
123
+ if (!_private) {
124
+ throw new Error("Internal error , cannot extract private data from " + this.browseName.toString());
125
+ }
126
+ return _private.__address_space;
127
+ }
128
+ get displayName() {
129
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
130
+ return _private._displayName;
131
+ }
132
+ setDisplayName(value) {
133
+ this._setDisplayName(value);
134
+ /**
135
+ * fires when the displayName is changed.
136
+ * @event DisplayName_changed
137
+ * @param dataValue {DataValue}
138
+ */
139
+ this._notifyAttributeChange(node_opcua_data_model_1.AttributeIds.DisplayName);
140
+ }
141
+ get description() {
142
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
143
+ return _private._description;
144
+ }
145
+ setDescription(value) {
146
+ this._setDescription(value);
147
+ /**
148
+ * fires when the description attribute is changed.
149
+ * @event Description_changed
150
+ * @param dataValue {DataValue}
151
+ */
152
+ this._notifyAttributeChange(node_opcua_data_model_1.AttributeIds.Description);
153
+ }
154
+ /**
155
+ * returns the nodeId of this node's Type Definition
156
+ */
157
+ get typeDefinition() {
158
+ const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
159
+ if (!_cache.typeDefinition) {
160
+ const has_type_definition_ref = this.findReference("HasTypeDefinition", true);
161
+ _cache.typeDefinition = has_type_definition_ref ? has_type_definition_ref.nodeId : null;
162
+ }
163
+ return _cache.typeDefinition;
164
+ }
165
+ /**
166
+ * returns the nodeId of this node's Type Definition
167
+ */
168
+ get typeDefinitionObj() {
169
+ const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
170
+ if (undefined === _cache.typeDefinitionObj) {
171
+ const nodeId = this.typeDefinition;
172
+ _cache.typeDefinitionObj = nodeId ? this.addressSpace.findNode(nodeId) : null;
173
+ }
174
+ return _cache.typeDefinitionObj;
175
+ }
176
+ get parentNodeId() {
177
+ const parent = this.parent;
178
+ return parent ? parent.nodeId : undefined;
179
+ }
180
+ /**
181
+ * namespace index
182
+ */
183
+ get namespaceIndex() {
184
+ return this.nodeId.namespace;
185
+ }
186
+ /**
187
+ * namespace uri
188
+ */
189
+ get namespaceUri() {
190
+ return this.addressSpace.getNamespaceUri(this.namespaceIndex);
191
+ }
192
+ /**
193
+ * the parent node
194
+ */
195
+ get parent() {
196
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
197
+ if (_private._parent === undefined) {
198
+ // never been set before
199
+ _private._parent = _setup_parent_item.call(this, _private._referenceIdx);
200
+ }
201
+ return _private._parent || null;
202
+ }
203
+ /**
204
+ * @property modellingRule
205
+ * @type {String|undefined}
206
+ */
207
+ get modellingRule() {
208
+ const r = this.findReferencesAsObject("HasModellingRule");
209
+ if (!r || r.length === 0) {
210
+ return null; /// "? modellingRule missing ?"; // consider "Mandatory"
211
+ }
212
+ const r0 = r[0];
213
+ return r0.browseName.toString();
214
+ }
215
+ getDisplayName(locale) {
216
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
217
+ return _private._displayName[0].text;
218
+ }
219
+ get namespace() {
220
+ return this.addressSpacePrivate.getNamespace(this.nodeId.namespace);
221
+ }
222
+ // ---------------------------------------------------------------------------------------------------
223
+ // Finders
224
+ // ---------------------------------------------------------------------------------------------------
225
+ findReferencesEx(referenceType, browseDirection) {
226
+ browseDirection = browseDirection !== undefined ? browseDirection : node_opcua_data_model_1.BrowseDirection.Forward;
227
+ (0, node_opcua_assert_1.assert)(_is_valid_BrowseDirection(browseDirection));
228
+ (0, node_opcua_assert_1.assert)(browseDirection !== node_opcua_data_model_1.BrowseDirection.Both);
229
+ const referenceTypeNode = this._coerceReferenceType(referenceType);
230
+ if (!referenceTypeNode) {
231
+ // note: when loading nodeset2.xml files, reference type may not exit yet
232
+ // throw new Error("expecting valid reference name " + strReference);
233
+ return [];
234
+ }
235
+ const isForward = browseDirection === node_opcua_data_model_1.BrowseDirection.Forward;
236
+ const results = [];
237
+ const process = (referenceIdx) => {
238
+ const references = Object.values(referenceIdx);
239
+ for (const ref of references) {
240
+ if (ref.isForward === isForward && referenceTypeNode && referenceTypeNode.checkHasSubtype(ref.referenceType)) {
241
+ results.push(ref);
242
+ }
243
+ }
244
+ };
245
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
246
+ process(_private._referenceIdx);
247
+ process(_private._back_referenceIdx);
248
+ return results;
249
+ }
250
+ findReferences(referenceType, isForward = true) {
251
+ const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
252
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
253
+ const referenceTypeNode = this._coerceReferenceType(referenceType);
254
+ if (!referenceTypeNode) {
255
+ // note: when loading nodeset2.xml files, reference type may not exit yet
256
+ // throw new Error("expecting valid reference name " + strReference);
257
+ return [];
258
+ }
259
+ const hash = "_ref_" + referenceTypeNode.nodeId.toString() + isForward.toString();
260
+ if (_cache[hash]) {
261
+ return _cache[hash];
262
+ }
263
+ // istanbul ignore next
264
+ if (doDebug && !this.addressSpace.findReferenceType(referenceTypeNode.nodeId)) {
265
+ throw new Error("expecting valid reference name " + referenceType);
266
+ }
267
+ const result = [];
268
+ for (const ref of Object.values(_private._referenceIdx)) {
269
+ if (ref.isForward === isForward) {
270
+ if ((0, node_opcua_nodeid_1.sameNodeId)(ref.referenceType, referenceTypeNode.nodeId)) {
271
+ result.push(ref);
272
+ }
273
+ }
274
+ }
275
+ for (const ref of Object.values(_private._back_referenceIdx)) {
276
+ if (ref.isForward === isForward) {
277
+ if ((0, node_opcua_nodeid_1.sameNodeId)(ref.referenceType, referenceTypeNode.nodeId)) {
278
+ result.push(ref);
279
+ }
280
+ }
281
+ }
282
+ _cache[hash] = result;
283
+ return result;
284
+ }
285
+ findReference(strReference, isForward) {
286
+ const refs = this.findReferences(strReference, isForward);
287
+ if (refs.length !== 1 && refs.length !== 0) {
288
+ throw new Error("findReference: expecting only one or zero element here");
289
+ }
290
+ return refs[0] || null;
291
+ }
292
+ findReferencesExAsObject(referenceType, browseDirection) {
293
+ const references = this.findReferencesEx(referenceType, browseDirection);
294
+ return _asObject(references, this.addressSpace);
295
+ }
296
+ findReferencesAsObject(referenceType, isForward) {
297
+ const references = this.findReferences(referenceType, isForward);
298
+ return _asObject(references, this.addressSpace);
299
+ }
300
+ /**
301
+ * return an array with the Aggregates of this object.
302
+ */
303
+ getAggregates() {
304
+ const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
305
+ if (!_cache._aggregates) {
306
+ _cache._aggregates = this.findReferencesExAsObject("Aggregates", node_opcua_data_model_1.BrowseDirection.Forward);
307
+ }
308
+ return _cache._aggregates;
309
+ }
310
+ /**
311
+ * return an array with the components of this object.
312
+ */
313
+ getComponents() {
314
+ const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
315
+ if (!_cache._components) {
316
+ _cache._components = this.findReferencesExAsObject("HasComponent", node_opcua_data_model_1.BrowseDirection.Forward);
317
+ }
318
+ return _cache._components;
319
+ }
320
+ /**
321
+ * return a array with the properties of this object.
322
+ */
323
+ getProperties() {
324
+ const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
325
+ if (!_cache._properties) {
326
+ _cache._properties = this.findReferencesExAsObject("HasProperty", node_opcua_data_model_1.BrowseDirection.Forward);
327
+ }
328
+ return _cache._properties;
329
+ }
330
+ /**
331
+ * return a array with the notifiers of this object.
332
+ */
333
+ getNotifiers() {
334
+ const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
335
+ if (!_cache._notifiers) {
336
+ _cache._notifiers = this.findReferencesAsObject("HasNotifier", true);
337
+ }
338
+ return _cache._notifiers;
339
+ }
340
+ /**
341
+ * return a array with the event source of this object.
342
+ */
343
+ getEventSources() {
344
+ const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
345
+ if (!_cache._eventSources) {
346
+ _cache._eventSources = this.findReferencesAsObject("HasEventSource", true);
347
+ }
348
+ return _cache._eventSources;
349
+ }
350
+ /**
351
+ * return a array of the objects for which this node is an EventSource
352
+ */
353
+ getEventSourceOfs() {
354
+ const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
355
+ if (!_cache._eventSources) {
356
+ _cache._eventSources = this.findReferencesAsObject("HasEventSource", false);
357
+ }
358
+ return _cache._eventSources;
359
+ }
360
+ getComponentByName(browseName, namespaceIndex) {
361
+ const components = this.getComponents();
362
+ const select = _filter_by_browse_name(components, browseName, namespaceIndex);
363
+ (0, node_opcua_assert_1.assert)(select.length <= 1, "BaseNode#getComponentByName found duplicated reference");
364
+ if (select.length === 1) {
365
+ const component = select[0];
366
+ if (component.nodeClass === node_opcua_data_model_1.NodeClass.Method) {
367
+ warningLog("please use getMethodByName to retrieve a method");
368
+ return null;
369
+ }
370
+ (0, node_opcua_assert_1.assert)(component.nodeClass === node_opcua_data_model_1.NodeClass.Variable || component.nodeClass === node_opcua_data_model_1.NodeClass.Object);
371
+ return component;
372
+ }
373
+ else {
374
+ return null;
375
+ }
376
+ }
377
+ getPropertyByName(browseName, namespaceIndex) {
378
+ const properties = this.getProperties();
379
+ const select = _filter_by_browse_name(properties, browseName, namespaceIndex);
380
+ (0, node_opcua_assert_1.assert)(select.length <= 1, "BaseNode#getPropertyByName found duplicated reference");
381
+ if (select.length === 1 && select[0].nodeClass !== node_opcua_data_model_1.NodeClass.Variable) {
382
+ throw new Error("Expecting a property to be of nodeClass==NodeClass.Variable");
383
+ }
384
+ return select.length === 1 ? select[0] : null;
385
+ }
386
+ getFolderElementByName(browseName, namespaceIndex) {
387
+ const elements = this.getFolderElements();
388
+ const select = _filter_by_browse_name(elements, browseName, namespaceIndex);
389
+ return select.length === 1 ? select[0] : null;
390
+ }
391
+ /**
392
+ * returns the list of nodes that this folder object organizes
393
+ */
394
+ getFolderElements() {
395
+ return this.findReferencesExAsObject("Organizes", node_opcua_data_model_1.BrowseDirection.Forward);
396
+ }
397
+ /**
398
+ * returns the list of methods that this object provides
399
+ * @method getMethods
400
+ * @return an array with Method objects.
401
+ *
402
+ *
403
+ * Note: internally, methods are special types of components
404
+ */
405
+ getMethods() {
406
+ const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
407
+ if (!_cache._methods) {
408
+ const components = this.getComponents();
409
+ _cache._methods = components.filter((obj) => obj.nodeClass === node_opcua_data_model_1.NodeClass.Method);
410
+ }
411
+ return _cache._methods;
412
+ }
413
+ /**
414
+ * returns the method exposed by this object and with the given nodeId
415
+ */
416
+ getMethodById(nodeId) {
417
+ const methods = this.getMethods();
418
+ const found = methods.find((m) => m.nodeId.toString() === nodeId.toString());
419
+ return found || null;
420
+ }
421
+ getMethodByName(methodName, namespaceIndex) {
422
+ const methods = this.getMethods();
423
+ const select = _filter_by_browse_name(methods, methodName, namespaceIndex);
424
+ (0, node_opcua_assert_1.assert)(select.length <= 1, "BaseNode#getMethodByName found duplicated reference");
425
+ return select.length === 1 ? select[0] : null;
426
+ }
427
+ getWriteMask() {
428
+ return 0;
429
+ }
430
+ getUserWriteMask() {
431
+ return 0;
432
+ }
433
+ readAttribute(context, attributeId, indexRange, dataEncoding) {
434
+ indexRange;
435
+ dataEncoding;
436
+ (0, node_opcua_assert_1.assert)(!context || context instanceof session_context_1.SessionContext);
437
+ const options = {};
438
+ options.statusCode = node_opcua_status_code_1.StatusCodes.Good;
439
+ switch (attributeId) {
440
+ case node_opcua_data_model_1.AttributeIds.NodeId: // NodeId
441
+ options.value = { dataType: node_opcua_variant_1.DataType.NodeId, value: this.nodeId };
442
+ break;
443
+ case node_opcua_data_model_1.AttributeIds.NodeClass: // NodeClass
444
+ (0, node_opcua_assert_1.assert)(isFinite(this.nodeClass));
445
+ options.value = { dataType: node_opcua_variant_1.DataType.Int32, value: this.nodeClass };
446
+ break;
447
+ case node_opcua_data_model_1.AttributeIds.BrowseName: // QualifiedName
448
+ (0, node_opcua_assert_1.assert)(this.browseName instanceof node_opcua_data_model_1.QualifiedName);
449
+ options.value = { dataType: node_opcua_variant_1.DataType.QualifiedName, value: this.browseName };
450
+ break;
451
+ case node_opcua_data_model_1.AttributeIds.DisplayName: // LocalizedText
452
+ options.value = { dataType: node_opcua_variant_1.DataType.LocalizedText, value: this.displayName[0] };
453
+ break;
454
+ case node_opcua_data_model_1.AttributeIds.Description: // LocalizedText
455
+ options.value = { dataType: node_opcua_variant_1.DataType.LocalizedText, value: this.description };
456
+ break;
457
+ case node_opcua_data_model_1.AttributeIds.WriteMask:
458
+ options.value = { dataType: node_opcua_variant_1.DataType.UInt32, value: this.getWriteMask() };
459
+ break;
460
+ case node_opcua_data_model_1.AttributeIds.UserWriteMask:
461
+ options.value = { dataType: node_opcua_variant_1.DataType.UInt32, value: this.getUserWriteMask() };
462
+ break;
463
+ case node_opcua_data_model_1.AttributeIds.AccessRestrictions:
464
+ return this._readAccessRestrictions(context);
465
+ case node_opcua_data_model_1.AttributeIds.RolePermissions:
466
+ return this._readRolePermissions(context);
467
+ case node_opcua_data_model_1.AttributeIds.UserRolePermissions:
468
+ return this._readUserRolePermissions(context);
469
+ default:
470
+ options.value = null;
471
+ options.statusCode = node_opcua_status_code_1.StatusCodes.BadAttributeIdInvalid;
472
+ break;
473
+ }
474
+ // xx options.serverTimestamp = new Date();
475
+ return new node_opcua_data_value_1.DataValue(options);
476
+ }
477
+ writeAttribute(context, writeValue, callback) {
478
+ context = context || session_context_1.SessionContext.defaultContext;
479
+ (0, node_opcua_assert_1.assert)(context instanceof session_context_1.SessionContext);
480
+ (0, node_opcua_assert_1.assert)(typeof callback === "function");
481
+ if (writeValue.attributeId === undefined ||
482
+ writeValue.attributeId <= 0 ||
483
+ writeValue.attributeId > node_opcua_data_model_1.AttributeIds.AccessLevelEx) {
484
+ return callback(null, node_opcua_status_code_1.StatusCodes.BadAttributeIdInvalid);
485
+ }
486
+ // by default Node is read-only,
487
+ // this method needs to be overridden to change the behavior
488
+ callback(null, node_opcua_status_code_1.StatusCodes.BadNotWritable);
489
+ }
490
+ fullName() {
491
+ if (this.parentNodeId) {
492
+ const parent = this.addressSpace.findNode(this.parentNodeId);
493
+ // istanbul ignore else
494
+ if (parent) {
495
+ return parent.fullName() + "." + this.browseName.toString() + "";
496
+ }
497
+ else {
498
+ return "NOT YET REGISTERED" + this.parentNodeId.toString() + "." + this.browseName.toString() + "";
499
+ }
500
+ }
501
+ return this.browseName.toString();
502
+ }
503
+ ownReferences() {
504
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
505
+ return Object.values(_private._referenceIdx);
506
+ }
507
+ /**
508
+ * @method browseNodeByTargetName
509
+ *
510
+ * @param relativePathElement
511
+ * @param isLast
512
+ * @return {NodeId[]}
513
+ */
514
+ browseNodeByTargetName(relativePathElement, isLast) {
515
+ relativePathElement.targetName = relativePathElement.targetName || new node_opcua_data_model_1.QualifiedName({});
516
+ // part 4.0 v1.03 $7.26 RelativePath
517
+ // The BrowseName of the target node.
518
+ // The final element may have an empty targetName. In this situation all targets of the references identified by
519
+ // the referenceTypeId are the targets of the RelativePath.
520
+ // The targetName shall be specified for all other elements.
521
+ // The current path cannot be followed any further if no targets with the specified BrowseName exist.
522
+ (0, node_opcua_assert_1.assert)(relativePathElement.targetName instanceof node_opcua_data_model_1.QualifiedName);
523
+ (0, node_opcua_assert_1.assert)(relativePathElement.targetName.namespaceIndex >= 0);
524
+ (0, node_opcua_assert_1.assert)(relativePathElement.targetName.name.length > 0);
525
+ // The type of reference to follow from the current node.
526
+ // The current path cannot be followed any further if the referenceTypeId is not available on the Node instance.
527
+ // If not specified then all References are included and the parameter includeSubtypes is ignored.
528
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(relativePathElement, "referenceTypeId"));
529
+ // Indicates whether the inverse Reference should be followed.
530
+ // The inverse reference is followed if this value is TRUE.
531
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(relativePathElement, "isInverse"));
532
+ // Indicates whether subtypes of the ReferenceType should be followed.
533
+ // Subtypes are included if this value is TRUE.
534
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(relativePathElement, "includeSubtypes"));
535
+ const references = this.allReferences();
536
+ const _check_reference = (reference) => {
537
+ if (relativePathElement.referenceTypeId.isEmpty()) {
538
+ return true;
539
+ }
540
+ (0, node_opcua_assert_1.assert)(relativePathElement.referenceTypeId instanceof node_opcua_nodeid_1.NodeId);
541
+ if ((relativePathElement.isInverse && reference.isForward) ||
542
+ (!relativePathElement.isInverse && !reference.isForward)) {
543
+ return false;
544
+ }
545
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(reference, "isForward"));
546
+ const referenceType = resolveReferenceType(this.addressSpace, reference);
547
+ const referenceTypeId = referenceType.nodeId;
548
+ if ((0, node_opcua_nodeid_1.sameNodeId)(relativePathElement.referenceTypeId, referenceTypeId)) {
549
+ return true;
550
+ }
551
+ if (relativePathElement.includeSubtypes) {
552
+ const baseType = this.addressSpace.findReferenceType(relativePathElement.referenceTypeId);
553
+ if (baseType && referenceType.isSupertypeOf(baseType)) {
554
+ return true;
555
+ }
556
+ }
557
+ return false;
558
+ };
559
+ const nodeIdsMap = {};
560
+ let nodeIds = [];
561
+ for (const reference of references) {
562
+ if (!_check_reference(reference)) {
563
+ continue;
564
+ }
565
+ const obj = resolveReferenceNode(this.addressSpace, reference);
566
+ // istanbul ignore next
567
+ if (!obj) {
568
+ throw new Error(" cannot find node with id " + reference.nodeId.toString());
569
+ }
570
+ if ((0, lodash_1.isEqual)(obj.browseName, relativePathElement.targetName)) {
571
+ // compare QualifiedName
572
+ const key = obj.nodeId.toString();
573
+ if (!Object.prototype.hasOwnProperty.call(nodeIdsMap, key)) {
574
+ nodeIds.push(obj.nodeId);
575
+ nodeIdsMap[key] = obj;
576
+ }
577
+ }
578
+ }
579
+ if (nodeIds.length === 0 && (this.nodeClass === node_opcua_data_model_1.NodeClass.ObjectType || this.nodeClass === node_opcua_data_model_1.NodeClass.VariableType)) {
580
+ const nodeType = this;
581
+ if (nodeType.subtypeOf) {
582
+ // browsing also InstanceDeclarations included in base type
583
+ const baseType = this.addressSpace.findNode(nodeType.subtypeOf);
584
+ const n = baseType.browseNodeByTargetName(relativePathElement, isLast);
585
+ nodeIds = [].concat(nodeIds, n);
586
+ }
587
+ }
588
+ return nodeIds;
589
+ }
590
+ /**
591
+ * browse the node to extract information requested in browseDescription
592
+ * and returns an array with reference descriptions
593
+ *
594
+ *
595
+ *
596
+ */
597
+ browseNode(browseDescription, context) {
598
+ (0, node_opcua_assert_1.assert)(isFinite(browseDescription.nodeClassMask));
599
+ const do_debug = false;
600
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
601
+ const addressSpace = this.addressSpace;
602
+ const referenceTypeId = normalize_referenceTypeId(addressSpace, browseDescription.referenceTypeId);
603
+ (0, node_opcua_assert_1.assert)(referenceTypeId instanceof node_opcua_nodeid_1.NodeId);
604
+ const browseDirection = browseDescription.browseDirection !== undefined ? browseDescription.browseDirection : node_opcua_data_model_1.BrowseDirection.Both;
605
+ // get all possible references
606
+ let references = this.allReferences();
607
+ /* istanbul ignore next */
608
+ if (do_debug) {
609
+ console.log("all references :", this.nodeId.toString(), this.browseName.toString());
610
+ (0, dump_tools_1.dumpReferences)(addressSpace, Object.values(_private._referenceIdx));
611
+ }
612
+ // filter out references not matching referenceType
613
+ references = _filter_by_referenceType.call(this, browseDescription, references, referenceTypeId);
614
+ references = _filter_by_direction(references, browseDirection);
615
+ references = _filter_by_nodeClass.call(this, references, browseDescription.nodeClassMask);
616
+ references = _filter_by_userFilter.call(this, references, context);
617
+ if (context) {
618
+ references = _filter_by_context(this, references, context);
619
+ }
620
+ const referenceDescriptions = (0, base_node_private_1._constructReferenceDescription)(addressSpace, references, browseDescription.resultMask);
621
+ /* istanbul ignore next */
622
+ if (do_debug) {
623
+ (0, dump_tools_1.dumpReferenceDescriptions)(this.addressSpace, referenceDescriptions);
624
+ }
625
+ return referenceDescriptions;
626
+ }
627
+ allReferences() {
628
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
629
+ return Object.values(_private._referenceIdx).concat(Object.values(_private._back_referenceIdx));
630
+ }
631
+ /**
632
+ * @method addReference
633
+ * @param reference
634
+ * @param reference.referenceType {String}
635
+ * @param [reference.isForward = true] {Boolean}
636
+ * @param reference.nodeId {Node|NodeId|String}
637
+ *
638
+ * @example
639
+ *
640
+ * view.addReference({ referenceType: "Organizes", nodeId: myDevice });
641
+ *
642
+ * or
643
+ *
644
+ * myDevice1.addReference({ referenceType: "OrganizedBy", nodeId: view });
645
+ */
646
+ addReference(reference) {
647
+ const referenceNode = this.__addReference(reference);
648
+ const addressSpace = this.addressSpace;
649
+ if (!resolveReferenceType(addressSpace, referenceNode)) {
650
+ throw new Error("BaseNode#addReference : invalid reference " + reference.toString());
651
+ }
652
+ this._clear_caches();
653
+ _propagate_ref.call(this, addressSpace, referenceNode);
654
+ this.install_extra_properties();
655
+ cetools._handle_add_reference_change_event(this, referenceNode.nodeId);
656
+ }
657
+ removeReference(referenceOpts) {
658
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
659
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(referenceOpts, "referenceType"));
660
+ // xx isForward is optional : assert(Object.prototype.hasOwnProperty.call(reference,"isForward"));
661
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(referenceOpts, "nodeId"));
662
+ const addressSpace = this.addressSpace;
663
+ // istanbul ignore next
664
+ if (!addressSpace) {
665
+ console.log(" Where is addressSpace ?");
666
+ }
667
+ const reference = addressSpace.normalizeReferenceTypes([referenceOpts])[0];
668
+ const h = reference.hash;
669
+ const relatedNode = addressSpace.findNode(reference.nodeId);
670
+ const invReference = new reference_impl_1.ReferenceImpl({
671
+ isForward: !reference.isForward,
672
+ nodeId: this.nodeId,
673
+ referenceType: reference.referenceType
674
+ });
675
+ if (_private._referenceIdx[h]) {
676
+ delete _private._referenceIdx[h];
677
+ base_node_private_1.BaseNode_remove_backward_reference.call(relatedNode, invReference);
678
+ }
679
+ else if (_private._back_referenceIdx[h]) {
680
+ relatedNode.removeReference(invReference);
681
+ }
682
+ else {
683
+ // throw new Error("Cannot find reference " + reference);
684
+ }
685
+ (0, base_node_private_1._handle_HierarchicalReference)(this, reference);
686
+ this.uninstall_extra_properties(reference);
687
+ this._clear_caches();
688
+ }
689
+ /**
690
+ *
691
+ */
692
+ resolveNodeId(nodeId) {
693
+ return this.addressSpace.resolveNodeId(nodeId);
694
+ }
695
+ install_extra_properties() {
696
+ const addressSpace = this.addressSpace;
697
+ if (addressSpace.isFrugal) {
698
+ // skipping
699
+ return;
700
+ }
701
+ install_components_as_object_properties(this);
702
+ function install_extra_properties_on_parent(ref) {
703
+ const node = reference_impl_1.ReferenceImpl.resolveReferenceNode(addressSpace, ref);
704
+ install_components_as_object_properties(node);
705
+ }
706
+ // make sure parent have extra properties updated
707
+ const parentComponents = this.findReferencesEx("HasComponent", node_opcua_data_model_1.BrowseDirection.Inverse);
708
+ const parentSubfolders = this.findReferencesEx("Organizes", node_opcua_data_model_1.BrowseDirection.Inverse);
709
+ const parentProperties = this.findReferencesEx("HasProperty", node_opcua_data_model_1.BrowseDirection.Inverse);
710
+ for (const p of parentComponents) {
711
+ install_extra_properties_on_parent(p);
712
+ }
713
+ for (const p of parentSubfolders) {
714
+ install_extra_properties_on_parent(p);
715
+ }
716
+ for (const p of parentProperties) {
717
+ install_extra_properties_on_parent(p);
718
+ }
719
+ }
720
+ uninstall_extra_properties(reference) {
721
+ const addressSpace = this.addressSpace;
722
+ if (addressSpace.isFrugal) {
723
+ // skipping
724
+ return;
725
+ }
726
+ const childNode = resolveReferenceNode(addressSpace, reference);
727
+ const name = (0, node_opcua_utils_1.lowerFirstLetter)(childNode.browseName.name.toString());
728
+ if (Object.prototype.hasOwnProperty.call(reservedNames, name)) {
729
+ // istanbul ignore next
730
+ if (doDebug) {
731
+ // tslint:disable-next-line:no-console
732
+ console.log(chalk.bgWhite.red("Ignoring reserved keyword " + name));
733
+ }
734
+ return;
735
+ }
736
+ /* istanbul ignore next */
737
+ if (!Object.prototype.hasOwnProperty.call(this, name)) {
738
+ return;
739
+ }
740
+ Object.defineProperty(this, name, {
741
+ value: undefined
742
+ });
743
+ }
744
+ toString() {
745
+ const options = new base_node_private_1.ToStringBuilder();
746
+ base_node_private_1.BaseNode_toString.call(this, options);
747
+ return options.toString();
748
+ }
749
+ /**
750
+ * @property isFalseSubStateOf
751
+ * @type {BaseNode|null}
752
+ */
753
+ get isFalseSubStateOf() {
754
+ const r = this.findReferencesAsObject("HasFalseSubState", false);
755
+ if (!r || r.length === 0) {
756
+ return null;
757
+ }
758
+ (0, node_opcua_assert_1.assert)(r.length === 1);
759
+ return r[0];
760
+ }
761
+ /**
762
+ * @property isTrueSubStateOf
763
+ * @type {BaseNode|null}
764
+ */
765
+ get isTrueSubStateOf() {
766
+ const r = this.findReferencesAsObject("HasTrueSubState", false);
767
+ if (!r || r.length === 0) {
768
+ return null;
769
+ }
770
+ (0, node_opcua_assert_1.assert)(r.length === 1);
771
+ return r[0];
772
+ }
773
+ /**
774
+ * @method getFalseSubStates
775
+ * @return {UAStateVariable[]} return an array with the SubStates of this object.
776
+ */
777
+ getFalseSubStates() {
778
+ return this.findReferencesAsObject("HasFalseSubState");
779
+ }
780
+ /**
781
+ * @method getTrueSubStates
782
+ * @return {UAStateVariable[]} return an array with the SubStates of this object.
783
+ */
784
+ getTrueSubStates() {
785
+ return this.findReferencesAsObject("HasTrueSubState");
786
+ }
787
+ findHierarchicalReferences() {
788
+ return this.findReferencesEx("HierarchicalReferences", node_opcua_data_model_1.BrowseDirection.Forward);
789
+ }
790
+ getChildByName(browseName, namespaceIndex) {
791
+ // Attention: getChild doesn't care about namespace on browseName
792
+ // !!!!
793
+ if (browseName instanceof node_opcua_data_model_1.QualifiedName) {
794
+ browseName = browseName.name.toString();
795
+ }
796
+ (0, node_opcua_assert_1.assert)(typeof browseName === "string");
797
+ const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
798
+ const addressSpace = this.addressSpace;
799
+ if (!_cache._childByNameMap) {
800
+ _cache._childByNameMap = {};
801
+ const childReferenceTypes = this.findReferencesEx("HasChild");
802
+ for (const r of childReferenceTypes) {
803
+ const child = resolveReferenceNode(addressSpace, r);
804
+ _cache._childByNameMap[child.browseName.name.toString()] = child;
805
+ }
806
+ }
807
+ const ret = _cache._childByNameMap[browseName.toString()] || null;
808
+ return ret;
809
+ }
810
+ get toStateNode() {
811
+ const nodes = this.findReferencesAsObject("ToState", true);
812
+ (0, node_opcua_assert_1.assert)(nodes.length <= 1);
813
+ return nodes.length === 1 ? nodes[0] : null;
814
+ }
815
+ get fromStateNode() {
816
+ const nodes = this.findReferencesAsObject("FromState", true);
817
+ (0, node_opcua_assert_1.assert)(nodes.length <= 1);
818
+ return nodes.length === 1 ? nodes[0] : null;
819
+ }
820
+ /**
821
+ * this methods propagates the forward references to the pointed node
822
+ * by inserting backward references to the counter part node
823
+ */
824
+ propagate_back_references() {
825
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
826
+ if (this.addressSpace.suspendBackReference) {
827
+ // this indicates that the base node is constructed from an xml definition
828
+ // propagate_back_references will be called later once the file has been completely processed.
829
+ return;
830
+ }
831
+ const addressSpace = this.addressSpace;
832
+ for (const reference of Object.values(_private._referenceIdx)) {
833
+ _propagate_ref.call(this, addressSpace, reference);
834
+ }
835
+ }
836
+ /**
837
+ * the dispose method should be called when the node is no longer used, to release
838
+ * back pointer to the address space and clear caches.
839
+ *
840
+ * @method dispose
841
+ *
842
+ */
843
+ dispose() {
844
+ this.emit("dispose");
845
+ this.removeAllListeners();
846
+ this._clear_caches();
847
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
848
+ Object.values(_private._back_referenceIdx).forEach((ref) => ref.dispose());
849
+ Object.values(_private._referenceIdx).forEach((ref) => ref.dispose());
850
+ (0, base_node_private_1.BaseNode_removePrivate)(this);
851
+ }
852
+ // istanbul ignore next
853
+ dumpXML(xmlWriter) {
854
+ console.error(" This ", node_opcua_data_model_1.NodeClass[this.nodeClass]);
855
+ (0, node_opcua_assert_1.assert)(false, "BaseNode#dumpXML NOT IMPLEMENTED !");
856
+ (0, node_opcua_assert_1.assert)(xmlWriter);
857
+ }
858
+ /**
859
+ * Undo the effect of propagate_back_references
860
+ */
861
+ unpropagate_back_references() {
862
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
863
+ const addressSpace = this.addressSpace;
864
+ for (const reference of Object.values(_private._referenceIdx)) {
865
+ // filter out non Hierarchical References
866
+ const referenceType = resolveReferenceType(addressSpace, reference);
867
+ // istanbul ignore next
868
+ if (!referenceType) {
869
+ console.error(chalk.red(" ERROR"), " cannot find reference ", reference.referenceType, reference.toString());
870
+ }
871
+ const related_node = resolveReferenceNode(addressSpace, reference);
872
+ if (related_node) {
873
+ (0, node_opcua_assert_1.assert)(reference.nodeId.toString() !== this.nodeId.toString());
874
+ base_node_private_1.BaseNode_remove_backward_reference.call(related_node, new reference_impl_1.ReferenceImpl({
875
+ isForward: !reference.isForward,
876
+ nodeId: this.nodeId,
877
+ referenceType: reference.referenceType
878
+ }));
879
+ } // else addressSpace may be incomplete
880
+ }
881
+ }
882
+ installPostInstallFunc(f) {
883
+ if (!f) {
884
+ // nothing to do
885
+ return;
886
+ }
887
+ function chain(f1, f2) {
888
+ return function chaiFunc(...args) {
889
+ if (f1) {
890
+ f1.apply(this, args);
891
+ }
892
+ if (f2) {
893
+ f2.apply(this, args);
894
+ }
895
+ };
896
+ }
897
+ this._postInstantiateFunc = chain.call(this, this._postInstantiateFunc, f);
898
+ }
899
+ _on_child_added() {
900
+ this._clear_caches();
901
+ }
902
+ _on_child_removed(obj) {
903
+ // obj; // unused;
904
+ this._clear_caches();
905
+ }
906
+ /**
907
+ * @private
908
+ * @param reference
909
+ */
910
+ _add_backward_reference(reference) {
911
+ base_node_private_1.BaseNode_add_backward_reference.call(this, reference);
912
+ }
913
+ _coerceReferenceType(referenceType) {
914
+ let result;
915
+ if (typeof referenceType === "string") {
916
+ result = this.addressSpace.findReferenceType(referenceType);
917
+ /* istanbul ignore next */
918
+ if (!result) {
919
+ errorLog("referenceType ", referenceType, " cannot be found");
920
+ throw new Error("Cannot coerce reference with name " + referenceType);
921
+ }
922
+ }
923
+ else if (referenceType instanceof node_opcua_nodeid_1.NodeId) {
924
+ result = this.addressSpace.findNode(referenceType);
925
+ if (!result) {
926
+ return null;
927
+ }
928
+ }
929
+ else {
930
+ result = referenceType;
931
+ }
932
+ (0, node_opcua_assert_1.assert)(result, "reference must exists");
933
+ (0, node_opcua_assert_1.assert)(result.nodeClass === node_opcua_data_model_1.NodeClass.ReferenceType);
934
+ return result;
935
+ }
936
+ __addReference(referenceOpts) {
937
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
938
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(referenceOpts, "referenceType"));
939
+ // xx isForward is optional : assert(Object.prototype.hasOwnProperty.call(reference,"isForward"));
940
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(referenceOpts, "nodeId"));
941
+ const addressSpace = this.addressSpace;
942
+ const reference = addressSpace.normalizeReferenceTypes([referenceOpts])[0];
943
+ (0, node_opcua_assert_1.assert)(reference instanceof reference_impl_1.ReferenceImpl);
944
+ const h = reference.hash;
945
+ (0, node_opcua_assert_1.assert)(!_private._back_referenceIdx[h], "reference exists already in _back_references");
946
+ (0, node_opcua_assert_1.assert)(!_private._referenceIdx[h], "reference exists already in _references");
947
+ _private._referenceIdx[h] = reference;
948
+ (0, base_node_private_1._handle_HierarchicalReference)(this, reference);
949
+ return reference;
950
+ }
951
+ _setDisplayName(displayName) {
952
+ const displayNames = Array.isArray(displayName) ? displayName : [displayName];
953
+ const _displayNames = displayNames.map(node_opcua_data_model_1.coerceLocalizedText);
954
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
955
+ _private._displayName = _displayNames;
956
+ }
957
+ _setDescription(description) {
958
+ const __description = (0, node_opcua_data_model_1.coerceLocalizedText)(description);
959
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
960
+ _private._description = __description;
961
+ }
962
+ _notifyAttributeChange(attributeId) {
963
+ const event_name = BaseNodeImpl.makeAttributeEventName(attributeId);
964
+ this.emit(event_name, this.readAttribute(session_context_1.SessionContext.defaultContext, attributeId));
965
+ }
966
+ _clear_caches() {
967
+ (0, base_node_private_1.BaseNode_clearCache)(this);
968
+ }
969
+ _readAccessRestrictions(context) {
970
+ // https://reference.opcfoundation.org/v104/Core/docs/Part3/8.56/
971
+ if (this.accessRestrictions === undefined) {
972
+ return new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadAttributeIdInvalid });
973
+ }
974
+ return new node_opcua_data_value_1.DataValue({
975
+ statusCode: node_opcua_status_code_1.StatusCodes.Good,
976
+ value: {
977
+ dataType: node_opcua_variant_1.DataType.UInt16,
978
+ value: this.accessRestrictions
979
+ }
980
+ });
981
+ }
982
+ _readRolePermissions(context) {
983
+ // https://reference.opcfoundation.org/v104/Core/docs/Part3/4.8.3/
984
+ // to do check that current user can read permission
985
+ if (context && !(context === null || context === void 0 ? void 0 : context.checkPermission(this, node_opcua_types_1.PermissionType.ReadRolePermissions))) {
986
+ return new node_opcua_data_value_1.DataValue({
987
+ statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient
988
+ });
989
+ }
990
+ if (this.rolePermissions === undefined) {
991
+ // to do : If not specified, the value of DefaultUserRolePermissions Property from
992
+ // the Namespace Metadata Object associated with the Node is used instead.
993
+ return new node_opcua_data_value_1.DataValue({
994
+ statusCode: node_opcua_status_code_1.StatusCodes.BadAttributeIdInvalid
995
+ });
996
+ }
997
+ const rolePermissions = this.rolePermissions.map(({ roleId, permissions }) => {
998
+ return new node_opcua_types_1.RolePermissionType({
999
+ roleId: toRoleNodeId(roleId),
1000
+ permissions
1001
+ });
1002
+ });
1003
+ return new node_opcua_data_value_1.DataValue({
1004
+ statusCode: node_opcua_status_code_1.StatusCodes.Good,
1005
+ value: {
1006
+ dataType: node_opcua_variant_1.DataType.ExtensionObject,
1007
+ arrayType: node_opcua_variant_1.VariantArrayType.Array,
1008
+ value: rolePermissions
1009
+ }
1010
+ });
1011
+ }
1012
+ _readUserRolePermissions(context) {
1013
+ if (this.rolePermissions === undefined) {
1014
+ // to do : If not specified, the value of DefaultUserRolePermissions Property from
1015
+ // the Namespace Metadata Object associated with the Node is used instead.
1016
+ return new node_opcua_data_value_1.DataValue({
1017
+ statusCode: node_opcua_status_code_1.StatusCodes.BadAttributeIdInvalid
1018
+ });
1019
+ }
1020
+ const context1 = context === null ? session_context_1.SessionContext.defaultContext : context;
1021
+ // for the time being ...
1022
+ // get user Permission
1023
+ const rolePermissions = this.rolePermissions
1024
+ .map(({ roleId, permissions }) => {
1025
+ return new node_opcua_types_1.RolePermissionType({
1026
+ roleId: toRoleNodeId(roleId),
1027
+ permissions
1028
+ });
1029
+ })
1030
+ .filter(({ roleId }) => context1.currentUserHasRole(roleId));
1031
+ return new node_opcua_data_value_1.DataValue({
1032
+ statusCode: node_opcua_status_code_1.StatusCodes.Good,
1033
+ value: {
1034
+ dataType: node_opcua_variant_1.DataType.ExtensionObject,
1035
+ arrayType: node_opcua_variant_1.VariantArrayType.Array,
1036
+ value: rolePermissions
1037
+ }
1038
+ });
1039
+ }
1040
+ /**
1041
+ *
1042
+ * @param rolePermissions
1043
+ */
1044
+ setRolePermissions(rolePermissions) {
1045
+ this._rolePermissions = (0, role_permissions_1.coerceRolePermissions)(rolePermissions);
1046
+ }
1047
+ getRolePermissions(inherited) {
1048
+ if (this.rolePermissions === undefined && inherited) {
1049
+ return this.namespace.getDefaultRolePermissions();
1050
+ }
1051
+ return this._rolePermissions || null;
1052
+ }
1053
+ get rolePermissions() {
1054
+ return this._rolePermissions || undefined;
1055
+ }
1056
+ setAccessRestrictions(accessRestrictions) {
1057
+ this._accessRestrictions = accessRestrictions;
1058
+ }
1059
+ get accessRestrictions() {
1060
+ return this._accessRestrictions;
1061
+ }
1062
+ getAccessRestrictions(inherited) {
1063
+ if (this._accessRestrictions === undefined && inherited) {
1064
+ return this.namespace.getDefaultAccessRestrictions();
1065
+ }
1066
+ return this._accessRestrictions || node_opcua_data_model_1.AccessRestrictionsFlag.None;
1067
+ }
1068
+ }
1069
+ exports.BaseNodeImpl = BaseNodeImpl;
1070
+ function toRoleNodeId(s) {
1071
+ if (typeof s === "string") {
1072
+ return (0, node_opcua_nodeid_1.resolveNodeId)(session_context_1.WellKnownRolesNodeId[s]);
1073
+ }
1074
+ return (0, node_opcua_nodeid_1.coerceNodeId)(s);
1075
+ }
1076
+ let displayWarning = true;
1077
+ function toString_ReferenceDescription(ref, options) {
1078
+ const addressSpace = options.addressSpace;
1079
+ // xx assert(ref instanceof ReferenceDescription);
1080
+ const refNode = addressSpace.findNode(ref.referenceType);
1081
+ if (!refNode) {
1082
+ return "Unknown Ref : " + ref;
1083
+ }
1084
+ const r = new reference_impl_1.ReferenceImpl({
1085
+ isForward: ref.isForward,
1086
+ nodeId: ref.nodeId,
1087
+ referenceType: refNode.browseName.toString()
1088
+ });
1089
+ const str = r.toString(options);
1090
+ r.dispose();
1091
+ return str;
1092
+ }
1093
+ function _setup_parent_item(references) {
1094
+ references = Object.values(references);
1095
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
1096
+ (0, node_opcua_assert_1.assert)(!_private._parent, "_setup_parent_item has been already called");
1097
+ const addressSpace = this.addressSpace;
1098
+ if (references.length > 0) {
1099
+ references = this.findReferencesEx("Aggregates", node_opcua_data_model_1.BrowseDirection.Inverse);
1100
+ if (references.length >= 1) {
1101
+ // istanbul ignore next
1102
+ if (references.length > 1) {
1103
+ if (displayWarning) {
1104
+ const options = { addressSpace };
1105
+ // tslint:disable-next-line:no-console
1106
+ console.warn(" More than one Aggregates reference have been found for parent of object");
1107
+ // tslint:disable-next-line:no-console
1108
+ console.warn(" object node id:", this.nodeId.toString(), chalk.cyan(this.browseName.toString()));
1109
+ // tslint:disable-next-line:no-console
1110
+ console.warn(" browseResults:");
1111
+ // tslint:disable-next-line:no-console
1112
+ console.warn(references.map((f) => toString_ReferenceDescription(f, options)).join("\n"));
1113
+ // tslint:disable-next-line:no-console
1114
+ console.warn(" first one will be used as parent");
1115
+ // xx assert(browseResults.length === 1);
1116
+ displayWarning = false;
1117
+ }
1118
+ }
1119
+ return reference_impl_1.ReferenceImpl.resolveReferenceNode(addressSpace, references[0]);
1120
+ }
1121
+ }
1122
+ return null;
1123
+ }
1124
+ function _asObject(references, addressSpace) {
1125
+ function toObject(reference) {
1126
+ const obj = resolveReferenceNode(addressSpace, reference);
1127
+ // istanbul ignore next
1128
+ if (false && !obj) {
1129
+ // tslint:disable-next-line:no-console
1130
+ console.log(chalk.red(" Warning : object with nodeId ") +
1131
+ chalk.cyan(reference.nodeId.toString()) +
1132
+ chalk.red(" cannot be found in the address space !"));
1133
+ }
1134
+ return obj;
1135
+ }
1136
+ function remove_null(o) {
1137
+ return !!o;
1138
+ }
1139
+ return references.map(toObject).filter(remove_null);
1140
+ }
1141
+ function _filter_by_browse_name(components, browseName, namespaceIndex) {
1142
+ let select = [];
1143
+ if ((namespaceIndex === null || namespaceIndex === undefined) && typeof browseName === "string") {
1144
+ select = components.filter((c) => c.browseName.name.toString() === browseName);
1145
+ if (select && select.length > 1) {
1146
+ warningLog("Multiple children exist with name ", browseName, " please specify a namespace index");
1147
+ }
1148
+ }
1149
+ else {
1150
+ const _browseName = (0, node_opcua_data_model_1.coerceQualifiedName)(typeof browseName === "string" ? { name: browseName, namespaceIndex } : browseName);
1151
+ select = components.filter((c) => c.browseName.name === _browseName.name && c.browseName.namespaceIndex === _browseName.namespaceIndex);
1152
+ }
1153
+ return select;
1154
+ }
1155
+ let displayWarningReferencePointingToItSelf = true;
1156
+ function _is_massively_used_reference(referenceType) {
1157
+ const name = referenceType.browseName.toString();
1158
+ return name === "HasTypeDefinition" || name === "HasModellingRule";
1159
+ }
1160
+ function _propagate_ref(addressSpace, reference) {
1161
+ // filter out non Hierarchical References
1162
+ const referenceType = reference_impl_1.ReferenceImpl.resolveReferenceType(addressSpace, reference);
1163
+ // istanbul ignore next
1164
+ if (!referenceType) {
1165
+ // tslint:disable-next-line:no-console
1166
+ console.error(chalk.red(" ERROR"), " cannot find reference ", reference.referenceType, reference.toString());
1167
+ }
1168
+ // ------------------------------- Filter out back reference when reference type
1169
+ // is HasTypeDefinition, HasModellingRule, etc ...
1170
+ //
1171
+ // var referenceNode = Reference.resolveReferenceNode(addressSpace,reference);
1172
+ // ignore propagation on back reference to UAVariableType or UAObject Type reference
1173
+ // because there are too many !
1174
+ if (!referenceType || _is_massively_used_reference(referenceType)) {
1175
+ return;
1176
+ }
1177
+ // ------------------------------- EXPERIMENT
1178
+ // xx if (!referenceType.isSupertypeOf(hierarchicalReferencesId)) { return; }
1179
+ const related_node = resolveReferenceNode(addressSpace, reference);
1180
+ if (related_node) {
1181
+ // verify that reference doesn't point to object it this (see mantis 3099)
1182
+ if ((0, node_opcua_nodeid_1.sameNodeId)(reference.nodeId, this.nodeId)) {
1183
+ // istanbul ignore next
1184
+ if (displayWarningReferencePointingToItSelf) {
1185
+ // this could happen with method
1186
+ console.warn(" Warning: a Reference is pointing to this ", this.nodeId.toString(), this.browseName.toString());
1187
+ displayWarningReferencePointingToItSelf = false;
1188
+ }
1189
+ }
1190
+ // xx ignore this assert(reference.nodeId.toString() !== this.nodeId.toString());
1191
+ // function w(s,l) { return (s+" ").substring(0,l);}
1192
+ // if (reference.isForward) {
1193
+ // console.log(" CHILD => ",w(related_node.browseName + " " + related_node.nodeId.toString(),30),
1194
+ // " PARENT ",w(this.browseName + " " + this.nodeId.toString(),30) , reference.toString());
1195
+ // } else {
1196
+ // console.log(" CHILD => ",w(this.browseName + " " + this.nodeId.toString(),30),
1197
+ // " PARENT ",w(related_node.browseName + " " + related_node.nodeId.toString(),30) , reference.toString());
1198
+ //
1199
+ // }
1200
+ related_node._add_backward_reference(new reference_impl_1.ReferenceImpl({
1201
+ _referenceType: getReferenceType(reference),
1202
+ isForward: !reference.isForward,
1203
+ node: this,
1204
+ nodeId: this.nodeId,
1205
+ referenceType: reference.referenceType
1206
+ }));
1207
+ } // else addressSpace may be incomplete and under construction (while loading a nodeset.xml file for instance)
1208
+ }
1209
+ function nodeid_is_nothing(nodeid) {
1210
+ return nodeid.value === 0 && nodeid.namespace === 0;
1211
+ }
1212
+ /**
1213
+ * @method normalize_referenceTypeId
1214
+ * @param addressSpace {IAddressSpace}
1215
+ * @param referenceTypeId {String|NodeId|null} : the referenceType either as a string or a nodeId
1216
+ * @return {NodeId}
1217
+ */
1218
+ function normalize_referenceTypeId(addressSpace, referenceTypeId) {
1219
+ if (!referenceTypeId) {
1220
+ return (0, node_opcua_nodeid_1.makeNodeId)(0);
1221
+ }
1222
+ if (typeof referenceTypeId === "string") {
1223
+ const ref = addressSpace.findReferenceType(referenceTypeId);
1224
+ if (ref) {
1225
+ return ref.nodeId;
1226
+ }
1227
+ }
1228
+ let nodeId;
1229
+ try {
1230
+ nodeId = addressSpace.resolveNodeId(referenceTypeId);
1231
+ }
1232
+ catch (err) {
1233
+ console.log("cannot normalize_referenceTypeId", referenceTypeId);
1234
+ throw err;
1235
+ }
1236
+ (0, node_opcua_assert_1.assert)(nodeId);
1237
+ return nodeId;
1238
+ }
1239
+ const resolveReferenceNode = reference_impl_1.ReferenceImpl.resolveReferenceNode;
1240
+ const resolveReferenceType = reference_impl_1.ReferenceImpl.resolveReferenceType;
1241
+ function _filter_by_referenceType(browseDescription, references, referenceTypeId) {
1242
+ // make sure we have a valid referenceTypeId if not null
1243
+ if (!nodeid_is_nothing(referenceTypeId)) {
1244
+ (0, node_opcua_assert_1.assert)(referenceTypeId instanceof node_opcua_nodeid_1.NodeId);
1245
+ const referenceType = this.addressSpace.findNode(referenceTypeId);
1246
+ (0, node_opcua_debug_1.dumpIf)(!referenceType, referenceTypeId);
1247
+ // istanbul ignore next
1248
+ if (!referenceType || referenceType.nodeClass !== node_opcua_data_model_1.NodeClass.ReferenceType) {
1249
+ throw new Error("Cannot find reference type");
1250
+ }
1251
+ if (!browseDescription.includeSubtypes && referenceType.isAbstract) {
1252
+ warningLog("filter by reference will skip all reference as referenceType is abstract and includeSubtypes is false");
1253
+ }
1254
+ references = references.filter((reference) => {
1255
+ const ref = resolveReferenceType(this.addressSpace, reference);
1256
+ // istanbul ignore next
1257
+ if (!ref) {
1258
+ throw new Error("Cannot find reference type " + reference.toString());
1259
+ }
1260
+ // unknown type ... this may happen when the address space is not fully build
1261
+ (0, node_opcua_assert_1.assert)(ref.nodeClass === node_opcua_data_model_1.NodeClass.ReferenceType);
1262
+ const isSameType = (0, node_opcua_nodeid_1.sameNodeId)(ref.nodeId, referenceType.nodeId);
1263
+ if (isSameType) {
1264
+ return true;
1265
+ }
1266
+ if (browseDescription.includeSubtypes) {
1267
+ return ref.isSupertypeOf(referenceType);
1268
+ }
1269
+ else {
1270
+ return false;
1271
+ }
1272
+ });
1273
+ }
1274
+ return references;
1275
+ }
1276
+ function forwardOnly(reference) {
1277
+ return reference.isForward;
1278
+ }
1279
+ function reverseOnly(reference) {
1280
+ return !reference.isForward;
1281
+ }
1282
+ function _filter_by_direction(references, browseDirection) {
1283
+ if (browseDirection === node_opcua_data_model_1.BrowseDirection.Both) {
1284
+ return references;
1285
+ }
1286
+ if (browseDirection === node_opcua_data_model_1.BrowseDirection.Forward) {
1287
+ return references.filter(forwardOnly);
1288
+ }
1289
+ else {
1290
+ return references.filter(reverseOnly);
1291
+ }
1292
+ }
1293
+ /*
1294
+ function _filter_by_context(node: BaseNode, references: Reference[], context: SessionContext): Reference[] {
1295
+ if (!context.isBrowseAccessRestricted(node)) {
1296
+ return references;
1297
+ }
1298
+ // browse access is restricted for forward
1299
+ return [];
1300
+ }
1301
+ */
1302
+ function _filter_by_context(node, references, context) {
1303
+ const addressSpace = node.addressSpace;
1304
+ return references.filter((reference) => !context.isBrowseAccessRestricted(resolveReferenceNode(addressSpace, reference)));
1305
+ }
1306
+ function _filter_by_nodeClass(references, nodeClassMask) {
1307
+ (0, node_opcua_assert_1.assert)(isFinite(nodeClassMask));
1308
+ if (nodeClassMask === 0) {
1309
+ return references;
1310
+ }
1311
+ const addressSpace = this.addressSpace;
1312
+ return references.filter((reference) => {
1313
+ const obj = resolveReferenceNode(addressSpace, reference);
1314
+ if (!obj) {
1315
+ return false;
1316
+ }
1317
+ const nodeClassName = node_opcua_data_model_1.NodeClass[obj.nodeClass];
1318
+ const value = (0, node_opcua_data_model_1.makeNodeClassMask)(nodeClassName);
1319
+ return (value & nodeClassMask) === value;
1320
+ });
1321
+ }
1322
+ function _filter_by_userFilter(references, context) {
1323
+ const addressSpace = this.addressSpace;
1324
+ return references.filter((reference) => {
1325
+ const obj = resolveReferenceNode(addressSpace, reference);
1326
+ // istanbul ignore next
1327
+ if (!obj) {
1328
+ return false;
1329
+ }
1330
+ const _private = (0, base_node_private_1.BaseNode_getPrivate)(obj);
1331
+ // istanbul ignore next
1332
+ if (!_private._browseFilter) {
1333
+ throw Error("Internal error : cannot find browseFilter");
1334
+ }
1335
+ const filter1 = _private._browseFilter.call(obj, context);
1336
+ return filter1;
1337
+ });
1338
+ }
1339
+ const reservedNames = {
1340
+ __description: 0,
1341
+ __displayName: 0,
1342
+ browseName: 0,
1343
+ description: 0,
1344
+ displayName: 0,
1345
+ nodeClass: 0,
1346
+ nodeId: 0,
1347
+ typeDefinition: 0
1348
+ };
1349
+ /*
1350
+ * install hierarchical references as javascript properties
1351
+ * Components/Properties/Organizes
1352
+ */
1353
+ function install_components_as_object_properties(parentObj) {
1354
+ if (!parentObj) {
1355
+ return;
1356
+ }
1357
+ const addressSpace = parentObj.addressSpace;
1358
+ const hierarchicalRefs = parentObj.findHierarchicalReferences();
1359
+ const children = hierarchicalRefs.map((r) => reference_impl_1.ReferenceImpl.resolveReferenceNode(addressSpace, r));
1360
+ for (const child of children) {
1361
+ if (!child) {
1362
+ continue;
1363
+ }
1364
+ // assumption: we ignore namespace here .
1365
+ const name = (0, node_opcua_utils_1.lowerFirstLetter)(child.browseName.name.toString());
1366
+ if (Object.prototype.hasOwnProperty.call(reservedNames, name)) {
1367
+ // ignore reserved names
1368
+ if (doDebug) {
1369
+ console.log(chalk.bgWhite.red("Ignoring reserved keyword " + name));
1370
+ }
1371
+ continue;
1372
+ }
1373
+ // ignore reserved names
1374
+ if (doDebug) {
1375
+ console.log("Installing property " + name, " on ", parentObj.browseName.toString());
1376
+ }
1377
+ /* istanbul ignore next */
1378
+ if (Object.prototype.hasOwnProperty.call(parentObj, name)) {
1379
+ continue;
1380
+ }
1381
+ Object.defineProperty(parentObj, name, {
1382
+ configurable: true,
1383
+ enumerable: true,
1384
+ // xx writable: false,
1385
+ get() {
1386
+ return child;
1387
+ }
1388
+ // value: child
1389
+ });
1390
+ }
1391
+ }
1392
+ function getReferenceType(reference) {
1393
+ return reference._referenceType;
1394
+ }
1395
+ exports.getReferenceType = getReferenceType;
1396
1396
  //# sourceMappingURL=base_node_impl.js.map