node-opcua-address-space 2.51.0

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