node-opcua-address-space 2.76.0 → 2.77.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 (291) hide show
  1. package/dist/source/address_space_ts.d.ts +118 -118
  2. package/dist/source/address_space_ts.js +17 -17
  3. package/dist/source/continuation_points/continuation_point_manager.d.ts +32 -32
  4. package/dist/source/continuation_points/continuation_point_manager.js +195 -195
  5. package/dist/source/helpers/adjust_browse_direction.d.ts +5 -5
  6. package/dist/source/helpers/adjust_browse_direction.js +11 -11
  7. package/dist/source/helpers/argument_list.d.ts +33 -33
  8. package/dist/source/helpers/argument_list.js +258 -258
  9. package/dist/source/helpers/call_helpers.d.ts +6 -6
  10. package/dist/source/helpers/call_helpers.js +70 -70
  11. package/dist/source/helpers/check_event_clause.d.ts +17 -0
  12. package/dist/source/helpers/check_event_clause.js +53 -0
  13. package/dist/source/helpers/check_event_clause.js.map +1 -0
  14. package/dist/source/helpers/coerce_enum_value.d.ts +6 -6
  15. package/dist/source/helpers/coerce_enum_value.js +33 -33
  16. package/dist/source/helpers/dump_tools.d.ts +14 -14
  17. package/dist/source/helpers/dump_tools.js +78 -78
  18. package/dist/source/helpers/ensure_secure_access.d.ts +9 -9
  19. package/dist/source/helpers/ensure_secure_access.js +76 -76
  20. package/dist/source/helpers/make_optionals_map.d.ts +21 -21
  21. package/dist/source/helpers/make_optionals_map.js +29 -29
  22. package/dist/source/helpers/multiform_func.d.ts +11 -11
  23. package/dist/source/helpers/multiform_func.js +75 -75
  24. package/dist/source/helpers/resolve_opaque_on_address_space.d.ts +3 -3
  25. package/dist/source/helpers/resolve_opaque_on_address_space.js +36 -36
  26. package/dist/source/index.d.ts +56 -56
  27. package/dist/source/index.js +83 -83
  28. package/dist/source/interfaces/alarms_and_conditions/condition_info_i.d.ts +19 -19
  29. package/dist/source/interfaces/alarms_and_conditions/condition_info_i.js +2 -2
  30. package/dist/source/interfaces/alarms_and_conditions/condition_snapshot.d.ts +193 -193
  31. package/dist/source/interfaces/alarms_and_conditions/condition_snapshot.js +2 -2
  32. package/dist/source/interfaces/alarms_and_conditions/deviation_stuff.d.ts +12 -12
  33. package/dist/source/interfaces/alarms_and_conditions/deviation_stuff.js +2 -2
  34. package/dist/source/interfaces/alarms_and_conditions/install_setpoint_options.d.ts +10 -10
  35. package/dist/source/interfaces/alarms_and_conditions/install_setpoint_options.js +2 -2
  36. package/dist/source/interfaces/alarms_and_conditions/instantiate_alarm_condition_options.d.ts +7 -7
  37. package/dist/source/interfaces/alarms_and_conditions/instantiate_alarm_condition_options.js +2 -2
  38. package/dist/source/interfaces/alarms_and_conditions/instantiate_condition_options.d.ts +7 -7
  39. package/dist/source/interfaces/alarms_and_conditions/instantiate_condition_options.js +2 -2
  40. package/dist/source/interfaces/alarms_and_conditions/instantiate_exclusive_deviation_alarm_options.d.ts +4 -4
  41. package/dist/source/interfaces/alarms_and_conditions/instantiate_exclusive_deviation_alarm_options.js +2 -2
  42. package/dist/source/interfaces/alarms_and_conditions/instantiate_exclusive_limit_alarm_options.d.ts +4 -4
  43. package/dist/source/interfaces/alarms_and_conditions/instantiate_exclusive_limit_alarm_options.js +2 -2
  44. package/dist/source/interfaces/alarms_and_conditions/instantiate_limit_alarm_options.d.ts +9 -9
  45. package/dist/source/interfaces/alarms_and_conditions/instantiate_limit_alarm_options.js +2 -2
  46. package/dist/source/interfaces/alarms_and_conditions/instantiate_non_exclusive_deviation_alarm_options.d.ts +4 -4
  47. package/dist/source/interfaces/alarms_and_conditions/instantiate_non_exclusive_deviation_alarm_options.js +2 -2
  48. package/dist/source/interfaces/alarms_and_conditions/instantiate_non_exclusive_limit_alarm_options.d.ts +4 -4
  49. package/dist/source/interfaces/alarms_and_conditions/instantiate_non_exclusive_limit_alarm_options.js +2 -2
  50. package/dist/source/interfaces/alarms_and_conditions/instantiate_off_normal_alarm_options.d.ts +20 -20
  51. package/dist/source/interfaces/alarms_and_conditions/instantiate_off_normal_alarm_options.js +2 -2
  52. package/dist/source/interfaces/alarms_and_conditions/ua_acknowledgeable_condition_ex.d.ts +23 -23
  53. package/dist/source/interfaces/alarms_and_conditions/ua_acknowledgeable_condition_ex.js +2 -2
  54. package/dist/source/interfaces/alarms_and_conditions/ua_alarm_condition_ex.d.ts +32 -32
  55. package/dist/source/interfaces/alarms_and_conditions/ua_alarm_condition_ex.js +2 -2
  56. package/dist/source/interfaces/alarms_and_conditions/ua_certificate_expiration_alarm_ex.d.ts +19 -19
  57. package/dist/source/interfaces/alarms_and_conditions/ua_certificate_expiration_alarm_ex.js +2 -2
  58. package/dist/source/interfaces/alarms_and_conditions/ua_condition_ex.d.ts +42 -42
  59. package/dist/source/interfaces/alarms_and_conditions/ua_condition_ex.js +2 -2
  60. package/dist/source/interfaces/alarms_and_conditions/ua_discrete_alarm_ex.d.ts +7 -7
  61. package/dist/source/interfaces/alarms_and_conditions/ua_discrete_alarm_ex.js +25 -25
  62. package/dist/source/interfaces/alarms_and_conditions/ua_exclusive_deviation_alarm_ex.d.ts +5 -5
  63. package/dist/source/interfaces/alarms_and_conditions/ua_exclusive_deviation_alarm_ex.js +2 -2
  64. package/dist/source/interfaces/alarms_and_conditions/ua_exclusive_limit_alarm_ex.d.ts +20 -20
  65. package/dist/source/interfaces/alarms_and_conditions/ua_exclusive_limit_alarm_ex.js +2 -2
  66. package/dist/source/interfaces/alarms_and_conditions/ua_limit_alarm_ex.d.ts +26 -26
  67. package/dist/source/interfaces/alarms_and_conditions/ua_limit_alarm_ex.js +2 -2
  68. package/dist/source/interfaces/alarms_and_conditions/ua_non_exclusive_deviation_alarm_ex.d.ts +8 -8
  69. package/dist/source/interfaces/alarms_and_conditions/ua_non_exclusive_deviation_alarm_ex.js +2 -2
  70. package/dist/source/interfaces/alarms_and_conditions/ua_non_exclusive_limit_alarm_ex.d.ts +10 -10
  71. package/dist/source/interfaces/alarms_and_conditions/ua_non_exclusive_limit_alarm_ex.js +2 -2
  72. package/dist/source/interfaces/data_access/ua_multistate_discrete_ex.d.ts +21 -21
  73. package/dist/source/interfaces/data_access/ua_multistate_discrete_ex.js +2 -2
  74. package/dist/source/interfaces/data_access/ua_multistate_value_discrete_ex.d.ts +24 -24
  75. package/dist/source/interfaces/data_access/ua_multistate_value_discrete_ex.js +2 -2
  76. package/dist/source/interfaces/data_access/ua_two_state_discrete_ex.d.ts +12 -12
  77. package/dist/source/interfaces/data_access/ua_two_state_discrete_ex.js +2 -2
  78. package/dist/source/interfaces/data_access/ua_y_array_item_ex.d.ts +8 -8
  79. package/dist/source/interfaces/data_access/ua_y_array_item_ex.js +2 -2
  80. package/dist/source/interfaces/state_machine/ua_exclusive_limit_state_machine_type_ex.d.ts +12 -12
  81. package/dist/source/interfaces/state_machine/ua_exclusive_limit_state_machine_type_ex.js +2 -2
  82. package/dist/source/interfaces/state_machine/ua_finite_state_machine_type.d.ts +49 -49
  83. package/dist/source/interfaces/state_machine/ua_finite_state_machine_type.js +2 -2
  84. package/dist/source/interfaces/state_machine/ua_program_state_machine_type.d.ts +11 -11
  85. package/dist/source/interfaces/state_machine/ua_program_state_machine_type.js +2 -2
  86. package/dist/source/interfaces/state_machine/ua_shelved_state_machine_ex.d.ts +30 -30
  87. package/dist/source/interfaces/state_machine/ua_shelved_state_machine_ex.js +2 -2
  88. package/dist/source/interfaces/state_machine/ua_state_machine_type.d.ts +222 -222
  89. package/dist/source/interfaces/state_machine/ua_state_machine_type.js +2 -2
  90. package/dist/source/interfaces/state_machine/ua_transition_ex.d.ts +6 -6
  91. package/dist/source/interfaces/state_machine/ua_transition_ex.js +2 -2
  92. package/dist/source/interfaces/ua_subscription_diagnostics_variable_ex.d.ts +8 -8
  93. package/dist/source/interfaces/ua_subscription_diagnostics_variable_ex.js +2 -2
  94. package/dist/source/loader/decode_xml_extension_object.d.ts +6 -6
  95. package/dist/source/loader/decode_xml_extension_object.js +71 -71
  96. package/dist/source/loader/ensure_datatype_extracted.d.ts +5 -5
  97. package/dist/source/loader/ensure_datatype_extracted.js +45 -45
  98. package/dist/source/loader/generateAddressSpaceRaw.d.ts +10 -10
  99. package/dist/source/loader/generateAddressSpaceRaw.js +45 -45
  100. package/dist/source/loader/load_nodeset2.d.ts +16 -16
  101. package/dist/source/loader/load_nodeset2.js +1461 -1461
  102. package/dist/source/loader/make_semver_compatible.d.ts +6 -6
  103. package/dist/source/loader/make_semver_compatible.js +25 -25
  104. package/dist/source/loader/make_xml_extension_object_parser.d.ts +28 -28
  105. package/dist/source/loader/make_xml_extension_object_parser.js +325 -325
  106. package/dist/source/loader/namespace_post_step.d.ts +10 -10
  107. package/dist/source/loader/namespace_post_step.js +61 -61
  108. package/dist/source/loader/register_node_promoter.d.ts +2 -2
  109. package/dist/source/loader/register_node_promoter.js +9 -9
  110. package/dist/source/namespace.d.ts +6 -6
  111. package/dist/source/namespace.js +2 -2
  112. package/dist/source/namespace_alarm_and_condition.d.ts +32 -32
  113. package/dist/source/namespace_alarm_and_condition.js +2 -2
  114. package/dist/source/namespace_data_access.d.ts +42 -42
  115. package/dist/source/namespace_data_access.js +2 -2
  116. package/dist/source/namespace_machine_state.d.ts +7 -7
  117. package/dist/source/namespace_machine_state.js +2 -2
  118. package/dist/source/pseudo_session.d.ts +55 -55
  119. package/dist/source/pseudo_session.js +203 -203
  120. package/dist/source/session_context.d.ts +111 -111
  121. package/dist/source/session_context.js +265 -265
  122. package/dist/source/set_namespace_meta_data.d.ts +2 -2
  123. package/dist/source/set_namespace_meta_data.js +59 -59
  124. package/dist/source/ua_root_folder.d.ts +9 -9
  125. package/dist/source/ua_root_folder.js +2 -2
  126. package/dist/source/ua_two_state_variable_ex.d.ts +23 -23
  127. package/dist/source/ua_two_state_variable_ex.js +2 -2
  128. package/dist/source/xml_writer.d.ts +9 -9
  129. package/dist/source/xml_writer.js +2 -2
  130. package/dist/src/address_space.d.ts +392 -392
  131. package/dist/src/address_space.js +1392 -1392
  132. package/dist/src/address_space_change_event_tools.d.ts +6 -6
  133. package/dist/src/address_space_change_event_tools.js +149 -149
  134. package/dist/src/address_space_private.d.ts +43 -43
  135. package/dist/src/address_space_private.js +2 -2
  136. package/dist/src/alarms_and_conditions/check_where_clause.d.ts +4 -0
  137. package/dist/src/alarms_and_conditions/check_where_clause.js +110 -0
  138. package/dist/src/alarms_and_conditions/check_where_clause.js.map +1 -0
  139. package/dist/src/alarms_and_conditions/condition.d.ts +5 -5
  140. package/dist/src/alarms_and_conditions/condition.js +78 -78
  141. package/dist/src/alarms_and_conditions/condition_info.d.ts +27 -0
  142. package/dist/src/alarms_and_conditions/condition_info.js +55 -0
  143. package/dist/src/alarms_and_conditions/condition_info.js.map +1 -0
  144. package/dist/src/alarms_and_conditions/condition_info_impl.d.ts +26 -26
  145. package/dist/src/alarms_and_conditions/condition_info_impl.js +54 -54
  146. package/dist/src/alarms_and_conditions/condition_snapshot.d.ts +233 -0
  147. package/dist/src/alarms_and_conditions/condition_snapshot.js +667 -0
  148. package/dist/src/alarms_and_conditions/condition_snapshot.js.map +1 -0
  149. package/dist/src/alarms_and_conditions/condition_snapshot_impl.d.ts +222 -222
  150. package/dist/src/alarms_and_conditions/condition_snapshot_impl.js +657 -657
  151. package/dist/src/alarms_and_conditions/deviation_alarm_helper.d.ts +9 -9
  152. package/dist/src/alarms_and_conditions/deviation_alarm_helper.js +61 -61
  153. package/dist/src/alarms_and_conditions/extract_event_fields.d.ts +10 -0
  154. package/dist/src/alarms_and_conditions/extract_event_fields.js +90 -0
  155. package/dist/src/alarms_and_conditions/extract_event_fields.js.map +1 -0
  156. package/dist/src/alarms_and_conditions/index.d.ts +16 -16
  157. package/dist/src/alarms_and_conditions/index.js +32 -32
  158. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.d.ts +44 -44
  159. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js +244 -244
  160. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.d.ts +93 -93
  161. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js +419 -419
  162. package/dist/src/alarms_and_conditions/ua_base_event_impl.d.ts +26 -26
  163. package/dist/src/alarms_and_conditions/ua_base_event_impl.js +38 -38
  164. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.d.ts +44 -44
  165. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.js +183 -183
  166. package/dist/src/alarms_and_conditions/ua_condition_impl.d.ts +153 -153
  167. package/dist/src/alarms_and_conditions/ua_condition_impl.js +1028 -1028
  168. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.d.ts +14 -14
  169. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.js +34 -34
  170. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.d.ts +24 -24
  171. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.js +56 -56
  172. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.d.ts +11 -11
  173. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.js +11 -11
  174. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.d.ts +23 -23
  175. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.js +86 -86
  176. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm_impl.d.ts +11 -11
  177. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm_impl.js +7 -7
  178. package/dist/src/alarms_and_conditions/ua_limit_alarm_impl.d.ts +79 -79
  179. package/dist/src/alarms_and_conditions/ua_limit_alarm_impl.js +250 -250
  180. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.d.ts +24 -24
  181. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.js +50 -50
  182. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.d.ts +19 -19
  183. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.js +162 -162
  184. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.d.ts +46 -46
  185. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js +166 -166
  186. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.d.ts +18 -18
  187. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.js +17 -17
  188. package/dist/src/apply_condition_refresh.d.ts +6 -6
  189. package/dist/src/apply_condition_refresh.js +27 -27
  190. package/dist/src/base_node_impl.d.ts +281 -281
  191. package/dist/src/base_node_impl.js +1395 -1395
  192. package/dist/src/base_node_private.d.ts +61 -61
  193. package/dist/src/base_node_private.js +705 -705
  194. package/dist/src/data_access/add_dataItem_stuff.d.ts +11 -11
  195. package/dist/src/data_access/add_dataItem_stuff.js +61 -61
  196. package/dist/src/data_access/check_variant_compatibility_ua_analog_item.d.ts +1 -1
  197. package/dist/src/data_access/check_variant_compatibility_ua_analog_item.js +34 -34
  198. package/dist/src/data_access/ua_multistate_discrete_impl.d.ts +32 -32
  199. package/dist/src/data_access/ua_multistate_discrete_impl.js +130 -130
  200. package/dist/src/data_access/ua_multistate_value_discrete.d.ts +51 -0
  201. package/dist/src/data_access/ua_multistate_value_discrete.js +250 -0
  202. package/dist/src/data_access/ua_multistate_value_discrete.js.map +1 -0
  203. package/dist/src/data_access/ua_multistate_value_discrete_impl.d.ts +51 -51
  204. package/dist/src/data_access/ua_multistate_value_discrete_impl.js +249 -249
  205. package/dist/src/data_access/ua_two_state_discrete.d.ts +25 -0
  206. package/dist/src/data_access/ua_two_state_discrete.js +154 -0
  207. package/dist/src/data_access/ua_two_state_discrete.js.map +1 -0
  208. package/dist/src/data_access/ua_two_state_discrete_impl.d.ts +25 -25
  209. package/dist/src/data_access/ua_two_state_discrete_impl.js +153 -153
  210. package/dist/src/event_data.d.ts +34 -34
  211. package/dist/src/event_data.js +64 -64
  212. package/dist/src/extension_object_array_node.d.ts +61 -61
  213. package/dist/src/extension_object_array_node.js +276 -276
  214. package/dist/src/historical_access/address_space_historical_data_node.d.ts +26 -26
  215. package/dist/src/historical_access/address_space_historical_data_node.js +630 -630
  216. package/dist/src/index_current.d.ts +43 -43
  217. package/dist/src/index_current.js +74 -74
  218. package/dist/src/namespace_impl.d.ts +461 -461
  219. package/dist/src/namespace_impl.js +1732 -1732
  220. package/dist/src/namespace_private.d.ts +21 -21
  221. package/dist/src/namespace_private.js +32 -32
  222. package/dist/src/nodeid_manager.d.ts +36 -36
  223. package/dist/src/nodeid_manager.js +197 -197
  224. package/dist/src/nodeset_tools/adjust_namespace_array.d.ts +2 -2
  225. package/dist/src/nodeset_tools/adjust_namespace_array.js +13 -13
  226. package/dist/src/nodeset_tools/construct_namespace_dependency.d.ts +2 -2
  227. package/dist/src/nodeset_tools/construct_namespace_dependency.js +83 -83
  228. package/dist/src/nodeset_tools/nodeset_to_xml.d.ts +2 -2
  229. package/dist/src/nodeset_tools/nodeset_to_xml.js +1155 -1155
  230. package/dist/src/nodeset_tools/typedictionary_to_xml.d.ts +2 -2
  231. package/dist/src/nodeset_tools/typedictionary_to_xml.js +154 -154
  232. package/dist/src/reference_impl.d.ts +43 -43
  233. package/dist/src/reference_impl.js +139 -139
  234. package/dist/src/role_permissions.d.ts +2 -2
  235. package/dist/src/role_permissions.js +10 -10
  236. package/dist/src/state_machine/finite_state_machine.d.ts +67 -67
  237. package/dist/src/state_machine/finite_state_machine.js +353 -353
  238. package/dist/src/state_machine/ua_shelving_state_machine_ex.d.ts +38 -38
  239. package/dist/src/state_machine/ua_shelving_state_machine_ex.js +250 -250
  240. package/dist/src/state_machine/ua_two_state_variable.d.ts +61 -61
  241. package/dist/src/state_machine/ua_two_state_variable.js +331 -331
  242. package/dist/src/tool_isSupertypeOf.d.ts +17 -17
  243. package/dist/src/tool_isSupertypeOf.js +108 -108
  244. package/dist/src/ua_condition_type.d.ts +8 -8
  245. package/dist/src/ua_condition_type.js +2 -2
  246. package/dist/src/ua_data_type_impl.d.ts +93 -93
  247. package/dist/src/ua_data_type_impl.js +371 -371
  248. package/dist/src/ua_method_impl.d.ts +41 -41
  249. package/dist/src/ua_method_impl.js +208 -208
  250. package/dist/src/ua_object_impl.d.ts +35 -35
  251. package/dist/src/ua_object_impl.js +161 -161
  252. package/dist/src/ua_object_type_impl.d.ts +48 -48
  253. package/dist/src/ua_object_type_impl.js +124 -124
  254. package/dist/src/ua_reference_type_impl.d.ts +43 -43
  255. package/dist/src/ua_reference_type_impl.js +139 -139
  256. package/dist/src/ua_variable_impl.d.ts +351 -351
  257. package/dist/src/ua_variable_impl.js +1604 -1604
  258. package/dist/src/ua_variable_impl.js.map +1 -1
  259. package/dist/src/ua_variable_impl_ext_obj.d.ts +17 -17
  260. package/dist/src/ua_variable_impl_ext_obj.js +437 -437
  261. package/dist/src/ua_variable_type_impl.d.ts +62 -62
  262. package/dist/src/ua_variable_type_impl.js +570 -570
  263. package/dist/src/ua_view_impl.d.ts +19 -19
  264. package/dist/src/ua_view_impl.js +43 -43
  265. package/distHelpers/add_event_generator_object.d.ts +3 -3
  266. package/distHelpers/add_event_generator_object.js +64 -64
  267. package/distHelpers/alarms_and_conditions_demo.d.ts +9 -9
  268. package/distHelpers/alarms_and_conditions_demo.js +115 -115
  269. package/distHelpers/assertHasMatchingReference.d.ts +19 -19
  270. package/distHelpers/assertHasMatchingReference.js +40 -40
  271. package/distHelpers/boiler_system.d.ts +113 -113
  272. package/distHelpers/boiler_system.js +395 -395
  273. package/distHelpers/create_minimalist_address_space_nodeset.d.ts +5 -5
  274. package/distHelpers/create_minimalist_address_space_nodeset.js +171 -171
  275. package/distHelpers/date_utils.d.ts +3 -3
  276. package/distHelpers/date_utils.js +9 -9
  277. package/distHelpers/dump_statemachine.js +127 -127
  278. package/distHelpers/get_address_space_fixture.d.ts +1 -1
  279. package/distHelpers/get_address_space_fixture.js +30 -30
  280. package/distHelpers/get_mini_address_space.d.ts +7 -7
  281. package/distHelpers/get_mini_address_space.js +36 -36
  282. package/distHelpers/index.d.ts +12 -12
  283. package/distHelpers/index.js +28 -28
  284. package/distHelpers/mock_session.d.ts +14 -14
  285. package/distHelpers/mock_session.js +25 -25
  286. package/distNodeJS/generate_address_space.d.ts +4 -4
  287. package/distNodeJS/generate_address_space.js +41 -41
  288. package/distNodeJS/index.d.ts +1 -1
  289. package/distNodeJS/index.js +17 -17
  290. package/package.json +42 -40
  291. package/src/ua_variable_impl.ts +3 -2
@@ -1,571 +1,571 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initialize_properties_and_components = exports.assertUnusedChildBrowseName = exports.UAVariableTypeImpl = exports.topMostParentIsObjectTypeOrVariableType = void 0;
4
- /**
5
- * @module node-opcua-address-space
6
- */
7
- // tslint:disable:max-classes-per-file
8
- // tslint:disable:no-console
9
- const chalk = require("chalk");
10
- const node_opcua_assert_1 = require("node-opcua-assert");
11
- const node_opcua_constants_1 = require("node-opcua-constants");
12
- const node_opcua_data_model_1 = require("node-opcua-data-model");
13
- const node_opcua_data_value_1 = require("node-opcua-data-value");
14
- const node_opcua_debug_1 = require("node-opcua-debug");
15
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
16
- const node_opcua_status_code_1 = require("node-opcua-status-code");
17
- const node_opcua_utils_1 = require("node-opcua-utils");
18
- const node_opcua_variant_1 = require("node-opcua-variant");
19
- const session_context_1 = require("../source/session_context");
20
- const make_optionals_map_1 = require("../source/helpers/make_optionals_map");
21
- const base_node_impl_1 = require("./base_node_impl");
22
- const base_node_private_1 = require("./base_node_private");
23
- const tools = require("./tool_isSupertypeOf");
24
- const tool_isSupertypeOf_1 = require("./tool_isSupertypeOf");
25
- const tool_isSupertypeOf_2 = require("./tool_isSupertypeOf");
26
- const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
27
- const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
28
- const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
29
- const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
30
- // eslint-disable-next-line prefer-const
31
- let doTrace = (0, node_opcua_debug_1.checkDebugFlag)("INSTANTIATE");
32
- const traceLog = errorLog;
33
- function topMostParentIsObjectTypeOrVariableType(addressSpace, options) {
34
- var _a;
35
- if (options.modellingRule) {
36
- return true;
37
- }
38
- const parent = options.propertyOf || options.componentOf;
39
- if (!parent) {
40
- return false;
41
- }
42
- const parentNode = addressSpace._coerceNode(parent);
43
- if (!parentNode) {
44
- return false;
45
- }
46
- let currentNode = parentNode;
47
- while (currentNode) {
48
- const nodeClass = parentNode.nodeClass;
49
- if (nodeClass === node_opcua_data_model_1.NodeClass.ObjectType || nodeClass === node_opcua_data_model_1.NodeClass.VariableType) {
50
- return true;
51
- }
52
- if (nodeClass === node_opcua_data_model_1.NodeClass.Object || nodeClass === node_opcua_data_model_1.NodeClass.Variable || nodeClass === node_opcua_data_model_1.NodeClass.Method) {
53
- /** */
54
- }
55
- currentNode = (_a = currentNode.findReferencesEx("HasChild", node_opcua_data_model_1.BrowseDirection.Inverse)[0]) === null || _a === void 0 ? void 0 : _a.node;
56
- }
57
- return false;
58
- }
59
- exports.topMostParentIsObjectTypeOrVariableType = topMostParentIsObjectTypeOrVariableType;
60
- class UAVariableTypeImpl extends base_node_impl_1.BaseNodeImpl {
61
- constructor(options) {
62
- super(options);
63
- this.nodeClass = node_opcua_data_model_1.NodeClass.VariableType;
64
- this.isSupertypeOf = tools.construct_isSupertypeOf(UAVariableTypeImpl);
65
- (0, node_opcua_variant_1.verifyRankAndDimensions)(options);
66
- this.valueRank = options.valueRank || -1;
67
- this.arrayDimensions = options.arrayDimensions || null;
68
- this.minimumSamplingInterval = 0;
69
- this.historizing = (0, node_opcua_utils_1.isNullOrUndefined)(options.historizing) ? false : options.historizing;
70
- this.isAbstract = (0, node_opcua_utils_1.isNullOrUndefined)(options.isAbstract) ? false : options.isAbstract;
71
- this.value = options.value; // optional default value for instances of this UAVariableType
72
- this.dataType = (0, node_opcua_nodeid_1.coerceNodeId)(options.dataType); // DataType (NodeId)
73
- if (options.value) {
74
- this.value = new node_opcua_variant_1.Variant(options.value);
75
- }
76
- }
77
- get subtypeOf() {
78
- return tool_isSupertypeOf_2.get_subtypeOf.call(this);
79
- }
80
- get subtypeOfObj() {
81
- return tool_isSupertypeOf_1.get_subtypeOfObj.call(this);
82
- }
83
- readAttribute(context, attributeId) {
84
- (0, node_opcua_assert_1.assert)(!context || context instanceof session_context_1.SessionContext);
85
- const options = {};
86
- switch (attributeId) {
87
- case node_opcua_data_model_1.AttributeIds.IsAbstract:
88
- options.value = { dataType: node_opcua_variant_1.DataType.Boolean, value: this.isAbstract ? true : false };
89
- options.statusCode = node_opcua_status_code_1.StatusCodes.Good;
90
- break;
91
- case node_opcua_data_model_1.AttributeIds.Value:
92
- if (Object.prototype.hasOwnProperty.call(this, "value") && this.value !== undefined) {
93
- (0, node_opcua_assert_1.assert)(this.value.schema.name === "Variant");
94
- options.value = this.value;
95
- options.statusCode = node_opcua_status_code_1.StatusCodes.Good;
96
- }
97
- else {
98
- debugLog(" warning Value not implemented");
99
- options.value = { dataType: node_opcua_variant_1.DataType.Null };
100
- options.statusCode = node_opcua_status_code_1.StatusCodes.BadAttributeIdInvalid;
101
- }
102
- break;
103
- case node_opcua_data_model_1.AttributeIds.DataType:
104
- (0, node_opcua_assert_1.assert)(this.dataType instanceof node_opcua_nodeid_1.NodeId);
105
- options.value = { dataType: node_opcua_variant_1.DataType.NodeId, value: this.dataType };
106
- options.statusCode = node_opcua_status_code_1.StatusCodes.Good;
107
- break;
108
- case node_opcua_data_model_1.AttributeIds.ValueRank:
109
- options.value = { dataType: node_opcua_variant_1.DataType.Int32, value: this.valueRank };
110
- options.statusCode = node_opcua_status_code_1.StatusCodes.Good;
111
- break;
112
- case node_opcua_data_model_1.AttributeIds.ArrayDimensions:
113
- (0, node_opcua_assert_1.assert)(Array.isArray(this.arrayDimensions) || this.arrayDimensions === null);
114
- options.value = {
115
- arrayType: node_opcua_variant_1.VariantArrayType.Array,
116
- dataType: node_opcua_variant_1.DataType.UInt32,
117
- value: this.arrayDimensions
118
- };
119
- options.statusCode = node_opcua_status_code_1.StatusCodes.Good;
120
- break;
121
- default:
122
- return super.readAttribute(context, attributeId);
123
- }
124
- return new node_opcua_data_value_1.DataValue(options);
125
- }
126
- toString() {
127
- const options = new base_node_private_1.ToStringBuilder();
128
- base_node_private_1.UAVariableType_toString.call(this, options);
129
- return options.toString();
130
- }
131
- /**
132
- * instantiate an object of this UAVariableType
133
- * The instantiation takes care of object type inheritance when constructing inner properties
134
-
135
- * Note : HasComponent usage scope
136
- *
137
- * ```text
138
- * Source | Destination
139
- * -------------------+---------------------------
140
- * Object | Object, Variable,Method
141
- * ObjectType |
142
- * -------------------+---------------------------
143
- * DataVariable | Variable
144
- * DataVariableType |
145
- * ```
146
- *
147
- * see : OPCUA 1.03 page 44 $6.4 Instances of ObjectTypes and VariableTypes
148
- */
149
- instantiate(options) {
150
- const addressSpace = this.addressSpace;
151
- // xx assert(!this.isAbstract, "cannot instantiate abstract UAVariableType");
152
- (0, node_opcua_assert_1.assert)(options, "missing option object");
153
- (0, node_opcua_assert_1.assert)(typeof options.browseName === "string" || (options.browseName !== null && typeof options.browseName === "object"), "expecting a browse name");
154
- (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(options, "propertyOf"), "Use addressSpace#addVariable({ propertyOf: xxx}); to add a property");
155
- assertUnusedChildBrowseName(addressSpace, options);
156
- const baseVariableType = addressSpace.findVariableType("BaseVariableType");
157
- (0, node_opcua_assert_1.assert)(baseVariableType, "BaseVariableType must be defined in the address space");
158
- let dataType = options.dataType !== undefined ? options.dataType : this.dataType;
159
- // may be required (i.e YArrayItemType )
160
- dataType = this.resolveNodeId(dataType); // DataType (NodeId)
161
- (0, node_opcua_assert_1.assert)(dataType instanceof node_opcua_nodeid_1.NodeId);
162
- const valueRank = options.valueRank !== undefined ? options.valueRank : this.valueRank;
163
- const arrayDimensions = options.arrayDimensions !== undefined ? options.arrayDimensions : this.arrayDimensions;
164
- // istanbul ignore next
165
- if (!dataType || dataType.isEmpty()) {
166
- warningLog(" options.dataType", options.dataType ? options.dataType.toString() : "<null>");
167
- warningLog(" this.dataType", this.dataType ? this.dataType.toString() : "<null>");
168
- throw new Error(" A valid dataType must be specified");
169
- }
170
- const copyAlsoModellingRules = topMostParentIsObjectTypeOrVariableType(addressSpace, options);
171
- const defaultDataType = this.dataType;
172
- // BadAttributeIdInvalid
173
- const defaultDataValue = this.readAttribute(null, node_opcua_data_model_1.AttributeIds.Value);
174
- const defaultValue = (defaultDataType.namespace === 0 && defaultDataType.value == 0) || defaultDataValue.statusCode !== node_opcua_status_code_1.StatusCodes.Good
175
- ? undefined
176
- : defaultDataValue.value;
177
- const opts = {
178
- arrayDimensions,
179
- browseName: options.browseName,
180
- componentOf: options.componentOf,
181
- dataType,
182
- description: options.description || this.description,
183
- displayName: options.displayName || "",
184
- eventSourceOf: options.eventSourceOf,
185
- minimumSamplingInterval: options.minimumSamplingInterval,
186
- modellingRule: options.modellingRule,
187
- nodeId: options.nodeId,
188
- notifierOf: options.notifierOf,
189
- organizedBy: options.organizedBy,
190
- typeDefinition: this.nodeId,
191
- value: options.value || defaultValue,
192
- valueRank
193
- };
194
- const namespace = options.namespace || addressSpace.getOwnNamespace();
195
- const instance = namespace.addVariable(opts);
196
- // xx assert(instance.minimumSamplingInterval === options.minimumSamplingInterval);
197
- initialize_properties_and_components(instance, baseVariableType, this, copyAlsoModellingRules, options.optionals);
198
- // if VariableType is a type of Structure DataType
199
- // we need to instantiate a dataValue
200
- // and create a bidirectional binding with the individual properties of this type
201
- instance.bindExtensionObject(options.extensionObject);
202
- (0, node_opcua_assert_1.assert)(instance.typeDefinition.toString() === this.nodeId.toString());
203
- instance.install_extra_properties();
204
- if (this._postInstantiateFunc) {
205
- this._postInstantiateFunc(instance, this);
206
- }
207
- return instance;
208
- }
209
- }
210
- exports.UAVariableTypeImpl = UAVariableTypeImpl;
211
- /**
212
- * return true if node is a mandatory child or a requested optional
213
- * @method MandatoryChildOrRequestedOptionalFilter
214
- * @param instance
215
- * @param optionalsMap
216
- * @return {Boolean}
217
- */
218
- class MandatoryChildOrRequestedOptionalFilter {
219
- constructor(instance, optionalsMap) {
220
- // should we clone the node to be a component or propertyOf of a instance
221
- (0, node_opcua_assert_1.assert)(optionalsMap !== null && typeof optionalsMap === "object");
222
- (0, node_opcua_assert_1.assert)(null !== instance);
223
- this.optionalsMap = optionalsMap;
224
- this.instance = instance;
225
- this.references = instance.allReferences();
226
- }
227
- shouldKeep(node) {
228
- var _a;
229
- const addressSpace = node.addressSpace;
230
- const alreadyIn = this.references.filter((r) => {
231
- const n = addressSpace.findNode(r.nodeId);
232
- // istanbul ignore next
233
- if (!n) {
234
- warningLog(" cannot find node ", r.nodeId.toString());
235
- return false;
236
- }
237
- return n.browseName.name.toString() === node.browseName.name.toString();
238
- });
239
- if (alreadyIn.length > 0) {
240
- (0, node_opcua_assert_1.assert)(alreadyIn.length === 1, "Duplication found ?");
241
- // a child with the same browse name has already been install
242
- // probably from a SuperClass, we should ignore this.
243
- return false; // ignore
244
- }
245
- const modellingRule = node.modellingRule;
246
- switch (modellingRule) {
247
- case null:
248
- case undefined:
249
- debugLog("node ", node.browseName.toString(), node.nodeId.toString(), " has no modellingRule ", (_a = node.parentNodeId) === null || _a === void 0 ? void 0 : _a.toString());
250
- /**
251
- * in some badly generated NodeSet2.xml file, the modellingRule is not specified
252
- *
253
- * but in some other NodeSet2.xml, this means that the data are only attached to the Type node and shall not be
254
- * instantiate in the corresponding instance (example is the state variable of a finite state machine that are only
255
- * defined in the Type node)
256
- *
257
- * we should not consider it as an error, and treat it as not present
258
- */
259
- return false;
260
- case "Mandatory":
261
- return true; // keep;
262
- case "Optional":
263
- // only if in requested optionals
264
- return node.browseName.name in this.optionalsMap;
265
- case "OptionalPlaceholder":
266
- return false; // ignored
267
- default:
268
- return false; // ignored
269
- }
270
- }
271
- filterFor(childInstance) {
272
- const browseName = childInstance.browseName.name;
273
- let map = {};
274
- if (browseName in this.optionalsMap) {
275
- map = this.optionalsMap[browseName];
276
- }
277
- const newFilter = new MandatoryChildOrRequestedOptionalFilter(childInstance, map);
278
- return newFilter;
279
- }
280
- }
281
- /*
282
- * @function _get_parent_as_VariableOrObjectType
283
- * @param originalObject
284
- * @return {null|BaseNode}
285
- * @private
286
- */
287
- function _get_parent_as_VariableOrObjectType(originalObject) {
288
- if (originalObject.nodeClass === node_opcua_data_model_1.NodeClass.Method) {
289
- return null;
290
- }
291
- const addressSpace = originalObject.addressSpace;
292
- const parents = originalObject.findReferencesEx("HasChild", node_opcua_data_model_1.BrowseDirection.Inverse);
293
- // istanbul ignore next
294
- if (parents.length > 1) {
295
- warningLog(" object ", originalObject.browseName.toString(), " has more than one parent !");
296
- warningLog(originalObject.toString());
297
- warningLog(" parents : ");
298
- for (const parent of parents) {
299
- warningLog(" ", parent.toString(), addressSpace.findNode(parent.nodeId).browseName.toString());
300
- }
301
- return null;
302
- }
303
- (0, node_opcua_assert_1.assert)(parents.length === 0 || parents.length === 1);
304
- if (parents.length === 0) {
305
- return null;
306
- }
307
- const theParent = addressSpace.findNode(parents[0].nodeId);
308
- if (theParent && (theParent.nodeClass === node_opcua_data_model_1.NodeClass.VariableType || theParent.nodeClass === node_opcua_data_model_1.NodeClass.ObjectType)) {
309
- return theParent;
310
- }
311
- return null;
312
- }
313
- class CloneHelper {
314
- constructor() {
315
- this.level = 0;
316
- this.mapOrgToClone = new Map();
317
- }
318
- pad() {
319
- return " ".padEnd(this.level * 2, " ");
320
- }
321
- registerClonedObject(objInType, clonedObj) {
322
- this.mapOrgToClone.set(objInType.nodeId.toString(), {
323
- cloned: clonedObj,
324
- original: objInType
325
- });
326
- //
327
- // /-----------------------------\
328
- // | AcknowledgeableConditionType |
329
- // \-----------------------------/
330
- // ^ |
331
- // | +---------------------|- (EnabledState) (shadow element)
332
- // |
333
- // /-----------------------------\
334
- // | AlarmConditionType |
335
- // \-----------------------------/
336
- // |
337
- // +-------------------------------|- EnabledState <
338
- //
339
- // find also child object with the same browse name that are
340
- // overridden in the SuperType
341
- //
342
- const origParent = _get_parent_as_VariableOrObjectType(objInType);
343
- if (origParent) {
344
- let base = origParent.subtypeOfObj;
345
- while (base) {
346
- const shadowChild = base.getChildByName(objInType.browseName);
347
- if (shadowChild) {
348
- this.mapOrgToClone.set(shadowChild.nodeId.toString(), {
349
- cloned: clonedObj,
350
- original: shadowChild
351
- });
352
- }
353
- base = base.subtypeOfObj;
354
- }
355
- }
356
- // find subTypeOf
357
- }
358
- }
359
- // install properties and components on a instantiated Object
360
- //
361
- // based on their ModelingRule
362
- // => Mandatory => Installed
363
- // => Optional => Not Installed , unless it appear in optionals array
364
- // => OptionalPlaceHolder => Not Installed
365
- // => null (no modelling rule ) => Not Installed
366
- //
367
- function _initialize_properties_and_components(instance, topMostType, typeDefinitionNode, copyAlsoModellingRules, optionalsMap, extraInfo) {
368
- if (doDebug) {
369
- debugLog("instance browseName =", instance.browseName.toString());
370
- debugLog("typeNode =", typeDefinitionNode.browseName.toString());
371
- debugLog("optionalsMap =", Object.keys(optionalsMap).join(" "));
372
- const c = typeDefinitionNode.findReferencesEx("Aggregates");
373
- debugLog("typeDefinition aggregates =", c.map((x) => x.node.browseName.toString()).join(" "));
374
- }
375
- optionalsMap = optionalsMap || {};
376
- if ((0, node_opcua_nodeid_1.sameNodeId)(topMostType.nodeId, typeDefinitionNode.nodeId)) {
377
- return; // nothing to do
378
- }
379
- const filter = new MandatoryChildOrRequestedOptionalFilter(instance, optionalsMap);
380
- doTrace &&
381
- traceLog(chalk.cyan(extraInfo.pad(), "cloning relevant member of typeDefinition class"), typeDefinitionNode.browseName.toString());
382
- const browseNameMap = new Set();
383
- (0, base_node_private_1._clone_children_references)(typeDefinitionNode, instance, copyAlsoModellingRules, filter, extraInfo, browseNameMap);
384
- // now apply recursion on baseTypeDefinition to get properties and components from base class
385
- const baseTypeDefinitionNodeId = typeDefinitionNode.subtypeOf;
386
- const baseTypeDefinition = typeDefinitionNode.subtypeOfObj;
387
- doTrace &&
388
- traceLog(chalk.cyan(extraInfo.pad(), "now apply recursion on baseTypeDefinition to get properties and components from base class"), baseTypeDefinition.browseName.toString());
389
- // istanbul ignore next
390
- if (!baseTypeDefinition) {
391
- throw new Error(chalk.red("Cannot find object with nodeId ") + baseTypeDefinitionNodeId);
392
- }
393
- extraInfo.level++;
394
- _initialize_properties_and_components(instance, topMostType, baseTypeDefinition, copyAlsoModellingRules, optionalsMap, extraInfo);
395
- extraInfo.level--;
396
- }
397
- /**
398
- * @method hasChildWithBrowseName
399
- * returns true if the parent object has a child with the provided browseName
400
- * @param parent
401
- * @param childBrowseName
402
- */
403
- function hasChildWithBrowseName(parent, childBrowseName) {
404
- if (!parent) {
405
- throw Error("Internal error");
406
- }
407
- // extract children
408
- const children = parent.findReferencesAsObject("HasChild", true);
409
- return (children.filter((child) => {
410
- var _a, _b;
411
- return ((_a = child.browseName.name) === null || _a === void 0 ? void 0 : _a.toString()) === ((_b = childBrowseName.name) === null || _b === void 0 ? void 0 : _b.toString());
412
- }).length > 0);
413
- }
414
- function getParent(addressSpace, options) {
415
- const parent = options.componentOf || options.organizedBy;
416
- if (parent instanceof node_opcua_nodeid_1.NodeId) {
417
- return addressSpace.findNode(parent);
418
- }
419
- return parent;
420
- }
421
- function assertUnusedChildBrowseName(addressSpace, options) {
422
- const resolveOptionalObject = (node) => node ? addressSpace._coerceNode(node) || undefined : undefined;
423
- options.componentOf = resolveOptionalObject(options.componentOf);
424
- options.organizedBy = resolveOptionalObject(options.organizedBy);
425
- (0, node_opcua_assert_1.assert)(!(options.componentOf && options.organizedBy));
426
- const parent = getParent(addressSpace, options);
427
- if (!parent) {
428
- return;
429
- }
430
- (0, node_opcua_assert_1.assert)(parent !== null && typeof parent === "object");
431
- if (!(parent instanceof base_node_impl_1.BaseNodeImpl)) {
432
- throw new Error("Invalid parent parent is " + parent.constructor.name);
433
- }
434
- // istanbul ignore next
435
- // verify that no components already exists in parent
436
- if (parent && hasChildWithBrowseName(parent, (0, node_opcua_data_model_1.coerceQualifiedName)(options.browseName))) {
437
- throw new Error("object " +
438
- parent.browseName.name.toString() +
439
- " have already a child with browseName " +
440
- options.browseName.toString());
441
- }
442
- }
443
- exports.assertUnusedChildBrowseName = assertUnusedChildBrowseName;
444
- exports.assertUnusedChildBrowseName = assertUnusedChildBrowseName;
445
- exports.initialize_properties_and_components = initialize_properties_and_components;
446
- const hasTypeDefinitionNodeId = (0, node_opcua_nodeid_1.makeNodeId)(node_opcua_constants_1.ReferenceTypeIds.HasTypeDefinition);
447
- const hasModellingRuleNodeId = (0, node_opcua_nodeid_1.makeNodeId)(node_opcua_constants_1.ReferenceTypeIds.HasModellingRule);
448
- /**
449
- * remove unwanted reference such as HasTypeDefinition and HasModellingRule
450
- * from the list
451
- */
452
- function _remove_unwanted_ref(references) {
453
- // filter out HasTypeDefinition (i=40) , HasModellingRule (i=37);
454
- references = references.filter((reference) => !(0, node_opcua_nodeid_1.sameNodeId)(reference.referenceType, hasTypeDefinitionNodeId) &&
455
- !(0, node_opcua_nodeid_1.sameNodeId)(reference.referenceType, hasModellingRuleNodeId));
456
- return references;
457
- }
458
- /**
459
- *
460
- */
461
- function findNonHierarchicalReferences(originalObject) {
462
- // todo: MEMOIZE this method
463
- const addressSpace = originalObject.addressSpace;
464
- const referenceId = addressSpace.findReferenceType("NonHierarchicalReferences");
465
- if (!referenceId) {
466
- return [];
467
- }
468
- (0, node_opcua_assert_1.assert)(referenceId);
469
- // we need to explore the non hierarchical references backwards
470
- let references = originalObject.findReferencesEx("NonHierarchicalReferences", node_opcua_data_model_1.BrowseDirection.Inverse);
471
- references = [].concat(references, originalObject.findReferencesEx("HasEventSource", node_opcua_data_model_1.BrowseDirection.Inverse));
472
- const parent = _get_parent_as_VariableOrObjectType(originalObject);
473
- if (parent && parent.subtypeOfObj) {
474
- // parent is a ObjectType or VariableType and is not a root type
475
- (0, node_opcua_assert_1.assert)(parent.nodeClass === node_opcua_data_model_1.NodeClass.VariableType || parent.nodeClass === node_opcua_data_model_1.NodeClass.ObjectType);
476
- // let investigate the same child base child
477
- const child = parent.subtypeOfObj.getChildByName(originalObject.browseName);
478
- if (child) {
479
- const baseRef = findNonHierarchicalReferences(child);
480
- references = [].concat(references, baseRef);
481
- }
482
- }
483
- // perform some cleanup
484
- references = _remove_unwanted_ref(references);
485
- return references;
486
- }
487
- function reconstructNonHierarchicalReferences(extraInfo) {
488
- const findImplementedObject = (ref) => extraInfo.mapOrgToClone.get(ref.nodeId.toString()) || null;
489
- // navigate through original objects to find those that are being references by node that
490
- // have been cloned .
491
- // this could be node organized by some FunctionalGroup
492
- //
493
- for (const { original, cloned } of extraInfo.mapOrgToClone.values()) {
494
- // find NonHierarchical References on original object
495
- const originalNonHierarchical = findNonHierarchicalReferences(original);
496
- if (originalNonHierarchical.length === 0) {
497
- continue;
498
- }
499
- // istanbul ignore next
500
- if (doDebug) {
501
- debugLog(" investigation ", original.browseName.toString(), cloned.nodeClass.toString(), original.nodeClass.toString(), original.nodeId.toString(), cloned.nodeId.toString());
502
- }
503
- for (const ref of originalNonHierarchical) {
504
- const info = findImplementedObject(ref);
505
- // if the object pointed by this reference is also cloned ...
506
- if (info) {
507
- const originalDest = info.original;
508
- const cloneDest = info.cloned;
509
- // istanbul ignore next
510
- if (doDebug) {
511
- debugLog(chalk.cyan(" adding reference "), ref.referenceType, " from cloned ", cloned.nodeId.toString(), cloned.browseName.toString(), " to cloned ", cloneDest.nodeId.toString(), cloneDest.browseName.toString());
512
- }
513
- // restore reference
514
- cloned.addReference({
515
- isForward: false,
516
- nodeId: cloneDest.nodeId,
517
- referenceType: ref.referenceType
518
- });
519
- }
520
- }
521
- }
522
- }
523
- /**
524
- * recreate functional group types according to type definition
525
- *
526
- * @method reconstructFunctionalGroupType
527
- * @param baseType
528
- */
529
- /* @example:
530
- *
531
- * MyDeviceType
532
- * |
533
- * +----------|- ParameterSet(BaseObjectType)
534
- * | |
535
- * | +-----------------|- Parameter1
536
- * | ^
537
- * +----------|- Config(FunctionalGroupType) |
538
- * | |
539
- * +-------- Organizes---+
540
- */
541
- function reconstructFunctionalGroupType(extraInfo) {
542
- // navigate through original objects to find those that are being organized by some FunctionalGroup
543
- for (const { original, cloned } of extraInfo.mapOrgToClone.values()) {
544
- const organizedByArray = original.findReferencesEx("Organizes", node_opcua_data_model_1.BrowseDirection.Inverse);
545
- for (const ref of organizedByArray) {
546
- const info = extraInfo.mapOrgToClone.get(ref.nodeId.toString());
547
- if (!info)
548
- continue;
549
- const folder = info.original;
550
- (0, node_opcua_assert_1.assert)(folder.typeDefinitionObj.browseName.name.toString() === "FunctionalGroupType");
551
- // now create the same reference with the instantiated function group
552
- const destFolder = info.cloned;
553
- (0, node_opcua_assert_1.assert)(ref.referenceType);
554
- destFolder.addReference({
555
- isForward: !ref.isForward,
556
- nodeId: cloned.nodeId,
557
- referenceType: ref.referenceType
558
- });
559
- }
560
- }
561
- }
562
- function initialize_properties_and_components(instance, topMostType, nodeType, copyAlsoModellingRules, optionals) {
563
- const extraInfo = new CloneHelper();
564
- extraInfo.registerClonedObject(nodeType, instance);
565
- const optionalsMap = (0, make_optionals_map_1.makeOptionalsMap)(optionals);
566
- _initialize_properties_and_components(instance, topMostType, nodeType, copyAlsoModellingRules, optionalsMap, extraInfo);
567
- reconstructFunctionalGroupType(extraInfo);
568
- reconstructNonHierarchicalReferences(extraInfo);
569
- }
570
- exports.initialize_properties_and_components = initialize_properties_and_components;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initialize_properties_and_components = exports.assertUnusedChildBrowseName = exports.UAVariableTypeImpl = exports.topMostParentIsObjectTypeOrVariableType = void 0;
4
+ /**
5
+ * @module node-opcua-address-space
6
+ */
7
+ // tslint:disable:max-classes-per-file
8
+ // tslint:disable:no-console
9
+ const chalk = require("chalk");
10
+ const node_opcua_assert_1 = require("node-opcua-assert");
11
+ const node_opcua_constants_1 = require("node-opcua-constants");
12
+ const node_opcua_data_model_1 = require("node-opcua-data-model");
13
+ const node_opcua_data_value_1 = require("node-opcua-data-value");
14
+ const node_opcua_debug_1 = require("node-opcua-debug");
15
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
16
+ const node_opcua_status_code_1 = require("node-opcua-status-code");
17
+ const node_opcua_utils_1 = require("node-opcua-utils");
18
+ const node_opcua_variant_1 = require("node-opcua-variant");
19
+ const session_context_1 = require("../source/session_context");
20
+ const make_optionals_map_1 = require("../source/helpers/make_optionals_map");
21
+ const base_node_impl_1 = require("./base_node_impl");
22
+ const base_node_private_1 = require("./base_node_private");
23
+ const tools = require("./tool_isSupertypeOf");
24
+ const tool_isSupertypeOf_1 = require("./tool_isSupertypeOf");
25
+ const tool_isSupertypeOf_2 = require("./tool_isSupertypeOf");
26
+ const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
27
+ const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
28
+ const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
29
+ const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
30
+ // eslint-disable-next-line prefer-const
31
+ let doTrace = (0, node_opcua_debug_1.checkDebugFlag)("INSTANTIATE");
32
+ const traceLog = errorLog;
33
+ function topMostParentIsObjectTypeOrVariableType(addressSpace, options) {
34
+ var _a;
35
+ if (options.modellingRule) {
36
+ return true;
37
+ }
38
+ const parent = options.propertyOf || options.componentOf;
39
+ if (!parent) {
40
+ return false;
41
+ }
42
+ const parentNode = addressSpace._coerceNode(parent);
43
+ if (!parentNode) {
44
+ return false;
45
+ }
46
+ let currentNode = parentNode;
47
+ while (currentNode) {
48
+ const nodeClass = parentNode.nodeClass;
49
+ if (nodeClass === node_opcua_data_model_1.NodeClass.ObjectType || nodeClass === node_opcua_data_model_1.NodeClass.VariableType) {
50
+ return true;
51
+ }
52
+ if (nodeClass === node_opcua_data_model_1.NodeClass.Object || nodeClass === node_opcua_data_model_1.NodeClass.Variable || nodeClass === node_opcua_data_model_1.NodeClass.Method) {
53
+ /** */
54
+ }
55
+ currentNode = (_a = currentNode.findReferencesEx("HasChild", node_opcua_data_model_1.BrowseDirection.Inverse)[0]) === null || _a === void 0 ? void 0 : _a.node;
56
+ }
57
+ return false;
58
+ }
59
+ exports.topMostParentIsObjectTypeOrVariableType = topMostParentIsObjectTypeOrVariableType;
60
+ class UAVariableTypeImpl extends base_node_impl_1.BaseNodeImpl {
61
+ constructor(options) {
62
+ super(options);
63
+ this.nodeClass = node_opcua_data_model_1.NodeClass.VariableType;
64
+ this.isSupertypeOf = tools.construct_isSupertypeOf(UAVariableTypeImpl);
65
+ (0, node_opcua_variant_1.verifyRankAndDimensions)(options);
66
+ this.valueRank = options.valueRank || -1;
67
+ this.arrayDimensions = options.arrayDimensions || null;
68
+ this.minimumSamplingInterval = 0;
69
+ this.historizing = (0, node_opcua_utils_1.isNullOrUndefined)(options.historizing) ? false : options.historizing;
70
+ this.isAbstract = (0, node_opcua_utils_1.isNullOrUndefined)(options.isAbstract) ? false : options.isAbstract;
71
+ this.value = options.value; // optional default value for instances of this UAVariableType
72
+ this.dataType = (0, node_opcua_nodeid_1.coerceNodeId)(options.dataType); // DataType (NodeId)
73
+ if (options.value) {
74
+ this.value = new node_opcua_variant_1.Variant(options.value);
75
+ }
76
+ }
77
+ get subtypeOf() {
78
+ return tool_isSupertypeOf_2.get_subtypeOf.call(this);
79
+ }
80
+ get subtypeOfObj() {
81
+ return tool_isSupertypeOf_1.get_subtypeOfObj.call(this);
82
+ }
83
+ readAttribute(context, attributeId) {
84
+ (0, node_opcua_assert_1.assert)(!context || context instanceof session_context_1.SessionContext);
85
+ const options = {};
86
+ switch (attributeId) {
87
+ case node_opcua_data_model_1.AttributeIds.IsAbstract:
88
+ options.value = { dataType: node_opcua_variant_1.DataType.Boolean, value: this.isAbstract ? true : false };
89
+ options.statusCode = node_opcua_status_code_1.StatusCodes.Good;
90
+ break;
91
+ case node_opcua_data_model_1.AttributeIds.Value:
92
+ if (Object.prototype.hasOwnProperty.call(this, "value") && this.value !== undefined) {
93
+ (0, node_opcua_assert_1.assert)(this.value.schema.name === "Variant");
94
+ options.value = this.value;
95
+ options.statusCode = node_opcua_status_code_1.StatusCodes.Good;
96
+ }
97
+ else {
98
+ debugLog(" warning Value not implemented");
99
+ options.value = { dataType: node_opcua_variant_1.DataType.Null };
100
+ options.statusCode = node_opcua_status_code_1.StatusCodes.BadAttributeIdInvalid;
101
+ }
102
+ break;
103
+ case node_opcua_data_model_1.AttributeIds.DataType:
104
+ (0, node_opcua_assert_1.assert)(this.dataType instanceof node_opcua_nodeid_1.NodeId);
105
+ options.value = { dataType: node_opcua_variant_1.DataType.NodeId, value: this.dataType };
106
+ options.statusCode = node_opcua_status_code_1.StatusCodes.Good;
107
+ break;
108
+ case node_opcua_data_model_1.AttributeIds.ValueRank:
109
+ options.value = { dataType: node_opcua_variant_1.DataType.Int32, value: this.valueRank };
110
+ options.statusCode = node_opcua_status_code_1.StatusCodes.Good;
111
+ break;
112
+ case node_opcua_data_model_1.AttributeIds.ArrayDimensions:
113
+ (0, node_opcua_assert_1.assert)(Array.isArray(this.arrayDimensions) || this.arrayDimensions === null);
114
+ options.value = {
115
+ arrayType: node_opcua_variant_1.VariantArrayType.Array,
116
+ dataType: node_opcua_variant_1.DataType.UInt32,
117
+ value: this.arrayDimensions
118
+ };
119
+ options.statusCode = node_opcua_status_code_1.StatusCodes.Good;
120
+ break;
121
+ default:
122
+ return super.readAttribute(context, attributeId);
123
+ }
124
+ return new node_opcua_data_value_1.DataValue(options);
125
+ }
126
+ toString() {
127
+ const options = new base_node_private_1.ToStringBuilder();
128
+ base_node_private_1.UAVariableType_toString.call(this, options);
129
+ return options.toString();
130
+ }
131
+ /**
132
+ * instantiate an object of this UAVariableType
133
+ * The instantiation takes care of object type inheritance when constructing inner properties
134
+
135
+ * Note : HasComponent usage scope
136
+ *
137
+ * ```text
138
+ * Source | Destination
139
+ * -------------------+---------------------------
140
+ * Object | Object, Variable,Method
141
+ * ObjectType |
142
+ * -------------------+---------------------------
143
+ * DataVariable | Variable
144
+ * DataVariableType |
145
+ * ```
146
+ *
147
+ * see : OPCUA 1.03 page 44 $6.4 Instances of ObjectTypes and VariableTypes
148
+ */
149
+ instantiate(options) {
150
+ const addressSpace = this.addressSpace;
151
+ // xx assert(!this.isAbstract, "cannot instantiate abstract UAVariableType");
152
+ (0, node_opcua_assert_1.assert)(options, "missing option object");
153
+ (0, node_opcua_assert_1.assert)(typeof options.browseName === "string" || (options.browseName !== null && typeof options.browseName === "object"), "expecting a browse name");
154
+ (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(options, "propertyOf"), "Use addressSpace#addVariable({ propertyOf: xxx}); to add a property");
155
+ assertUnusedChildBrowseName(addressSpace, options);
156
+ const baseVariableType = addressSpace.findVariableType("BaseVariableType");
157
+ (0, node_opcua_assert_1.assert)(baseVariableType, "BaseVariableType must be defined in the address space");
158
+ let dataType = options.dataType !== undefined ? options.dataType : this.dataType;
159
+ // may be required (i.e YArrayItemType )
160
+ dataType = this.resolveNodeId(dataType); // DataType (NodeId)
161
+ (0, node_opcua_assert_1.assert)(dataType instanceof node_opcua_nodeid_1.NodeId);
162
+ const valueRank = options.valueRank !== undefined ? options.valueRank : this.valueRank;
163
+ const arrayDimensions = options.arrayDimensions !== undefined ? options.arrayDimensions : this.arrayDimensions;
164
+ // istanbul ignore next
165
+ if (!dataType || dataType.isEmpty()) {
166
+ warningLog(" options.dataType", options.dataType ? options.dataType.toString() : "<null>");
167
+ warningLog(" this.dataType", this.dataType ? this.dataType.toString() : "<null>");
168
+ throw new Error(" A valid dataType must be specified");
169
+ }
170
+ const copyAlsoModellingRules = topMostParentIsObjectTypeOrVariableType(addressSpace, options);
171
+ const defaultDataType = this.dataType;
172
+ // BadAttributeIdInvalid
173
+ const defaultDataValue = this.readAttribute(null, node_opcua_data_model_1.AttributeIds.Value);
174
+ const defaultValue = (defaultDataType.namespace === 0 && defaultDataType.value == 0) || defaultDataValue.statusCode !== node_opcua_status_code_1.StatusCodes.Good
175
+ ? undefined
176
+ : defaultDataValue.value;
177
+ const opts = {
178
+ arrayDimensions,
179
+ browseName: options.browseName,
180
+ componentOf: options.componentOf,
181
+ dataType,
182
+ description: options.description || this.description,
183
+ displayName: options.displayName || "",
184
+ eventSourceOf: options.eventSourceOf,
185
+ minimumSamplingInterval: options.minimumSamplingInterval,
186
+ modellingRule: options.modellingRule,
187
+ nodeId: options.nodeId,
188
+ notifierOf: options.notifierOf,
189
+ organizedBy: options.organizedBy,
190
+ typeDefinition: this.nodeId,
191
+ value: options.value || defaultValue,
192
+ valueRank
193
+ };
194
+ const namespace = options.namespace || addressSpace.getOwnNamespace();
195
+ const instance = namespace.addVariable(opts);
196
+ // xx assert(instance.minimumSamplingInterval === options.minimumSamplingInterval);
197
+ initialize_properties_and_components(instance, baseVariableType, this, copyAlsoModellingRules, options.optionals);
198
+ // if VariableType is a type of Structure DataType
199
+ // we need to instantiate a dataValue
200
+ // and create a bidirectional binding with the individual properties of this type
201
+ instance.bindExtensionObject(options.extensionObject);
202
+ (0, node_opcua_assert_1.assert)(instance.typeDefinition.toString() === this.nodeId.toString());
203
+ instance.install_extra_properties();
204
+ if (this._postInstantiateFunc) {
205
+ this._postInstantiateFunc(instance, this);
206
+ }
207
+ return instance;
208
+ }
209
+ }
210
+ exports.UAVariableTypeImpl = UAVariableTypeImpl;
211
+ /**
212
+ * return true if node is a mandatory child or a requested optional
213
+ * @method MandatoryChildOrRequestedOptionalFilter
214
+ * @param instance
215
+ * @param optionalsMap
216
+ * @return {Boolean}
217
+ */
218
+ class MandatoryChildOrRequestedOptionalFilter {
219
+ constructor(instance, optionalsMap) {
220
+ // should we clone the node to be a component or propertyOf of a instance
221
+ (0, node_opcua_assert_1.assert)(optionalsMap !== null && typeof optionalsMap === "object");
222
+ (0, node_opcua_assert_1.assert)(null !== instance);
223
+ this.optionalsMap = optionalsMap;
224
+ this.instance = instance;
225
+ this.references = instance.allReferences();
226
+ }
227
+ shouldKeep(node) {
228
+ var _a;
229
+ const addressSpace = node.addressSpace;
230
+ const alreadyIn = this.references.filter((r) => {
231
+ const n = addressSpace.findNode(r.nodeId);
232
+ // istanbul ignore next
233
+ if (!n) {
234
+ warningLog(" cannot find node ", r.nodeId.toString());
235
+ return false;
236
+ }
237
+ return n.browseName.name.toString() === node.browseName.name.toString();
238
+ });
239
+ if (alreadyIn.length > 0) {
240
+ (0, node_opcua_assert_1.assert)(alreadyIn.length === 1, "Duplication found ?");
241
+ // a child with the same browse name has already been install
242
+ // probably from a SuperClass, we should ignore this.
243
+ return false; // ignore
244
+ }
245
+ const modellingRule = node.modellingRule;
246
+ switch (modellingRule) {
247
+ case null:
248
+ case undefined:
249
+ debugLog("node ", node.browseName.toString(), node.nodeId.toString(), " has no modellingRule ", (_a = node.parentNodeId) === null || _a === void 0 ? void 0 : _a.toString());
250
+ /**
251
+ * in some badly generated NodeSet2.xml file, the modellingRule is not specified
252
+ *
253
+ * but in some other NodeSet2.xml, this means that the data are only attached to the Type node and shall not be
254
+ * instantiate in the corresponding instance (example is the state variable of a finite state machine that are only
255
+ * defined in the Type node)
256
+ *
257
+ * we should not consider it as an error, and treat it as not present
258
+ */
259
+ return false;
260
+ case "Mandatory":
261
+ return true; // keep;
262
+ case "Optional":
263
+ // only if in requested optionals
264
+ return node.browseName.name in this.optionalsMap;
265
+ case "OptionalPlaceholder":
266
+ return false; // ignored
267
+ default:
268
+ return false; // ignored
269
+ }
270
+ }
271
+ filterFor(childInstance) {
272
+ const browseName = childInstance.browseName.name;
273
+ let map = {};
274
+ if (browseName in this.optionalsMap) {
275
+ map = this.optionalsMap[browseName];
276
+ }
277
+ const newFilter = new MandatoryChildOrRequestedOptionalFilter(childInstance, map);
278
+ return newFilter;
279
+ }
280
+ }
281
+ /*
282
+ * @function _get_parent_as_VariableOrObjectType
283
+ * @param originalObject
284
+ * @return {null|BaseNode}
285
+ * @private
286
+ */
287
+ function _get_parent_as_VariableOrObjectType(originalObject) {
288
+ if (originalObject.nodeClass === node_opcua_data_model_1.NodeClass.Method) {
289
+ return null;
290
+ }
291
+ const addressSpace = originalObject.addressSpace;
292
+ const parents = originalObject.findReferencesEx("HasChild", node_opcua_data_model_1.BrowseDirection.Inverse);
293
+ // istanbul ignore next
294
+ if (parents.length > 1) {
295
+ warningLog(" object ", originalObject.browseName.toString(), " has more than one parent !");
296
+ warningLog(originalObject.toString());
297
+ warningLog(" parents : ");
298
+ for (const parent of parents) {
299
+ warningLog(" ", parent.toString(), addressSpace.findNode(parent.nodeId).browseName.toString());
300
+ }
301
+ return null;
302
+ }
303
+ (0, node_opcua_assert_1.assert)(parents.length === 0 || parents.length === 1);
304
+ if (parents.length === 0) {
305
+ return null;
306
+ }
307
+ const theParent = addressSpace.findNode(parents[0].nodeId);
308
+ if (theParent && (theParent.nodeClass === node_opcua_data_model_1.NodeClass.VariableType || theParent.nodeClass === node_opcua_data_model_1.NodeClass.ObjectType)) {
309
+ return theParent;
310
+ }
311
+ return null;
312
+ }
313
+ class CloneHelper {
314
+ constructor() {
315
+ this.level = 0;
316
+ this.mapOrgToClone = new Map();
317
+ }
318
+ pad() {
319
+ return " ".padEnd(this.level * 2, " ");
320
+ }
321
+ registerClonedObject(objInType, clonedObj) {
322
+ this.mapOrgToClone.set(objInType.nodeId.toString(), {
323
+ cloned: clonedObj,
324
+ original: objInType
325
+ });
326
+ //
327
+ // /-----------------------------\
328
+ // | AcknowledgeableConditionType |
329
+ // \-----------------------------/
330
+ // ^ |
331
+ // | +---------------------|- (EnabledState) (shadow element)
332
+ // |
333
+ // /-----------------------------\
334
+ // | AlarmConditionType |
335
+ // \-----------------------------/
336
+ // |
337
+ // +-------------------------------|- EnabledState <
338
+ //
339
+ // find also child object with the same browse name that are
340
+ // overridden in the SuperType
341
+ //
342
+ const origParent = _get_parent_as_VariableOrObjectType(objInType);
343
+ if (origParent) {
344
+ let base = origParent.subtypeOfObj;
345
+ while (base) {
346
+ const shadowChild = base.getChildByName(objInType.browseName);
347
+ if (shadowChild) {
348
+ this.mapOrgToClone.set(shadowChild.nodeId.toString(), {
349
+ cloned: clonedObj,
350
+ original: shadowChild
351
+ });
352
+ }
353
+ base = base.subtypeOfObj;
354
+ }
355
+ }
356
+ // find subTypeOf
357
+ }
358
+ }
359
+ // install properties and components on a instantiated Object
360
+ //
361
+ // based on their ModelingRule
362
+ // => Mandatory => Installed
363
+ // => Optional => Not Installed , unless it appear in optionals array
364
+ // => OptionalPlaceHolder => Not Installed
365
+ // => null (no modelling rule ) => Not Installed
366
+ //
367
+ function _initialize_properties_and_components(instance, topMostType, typeDefinitionNode, copyAlsoModellingRules, optionalsMap, extraInfo) {
368
+ if (doDebug) {
369
+ debugLog("instance browseName =", instance.browseName.toString());
370
+ debugLog("typeNode =", typeDefinitionNode.browseName.toString());
371
+ debugLog("optionalsMap =", Object.keys(optionalsMap).join(" "));
372
+ const c = typeDefinitionNode.findReferencesEx("Aggregates");
373
+ debugLog("typeDefinition aggregates =", c.map((x) => x.node.browseName.toString()).join(" "));
374
+ }
375
+ optionalsMap = optionalsMap || {};
376
+ if ((0, node_opcua_nodeid_1.sameNodeId)(topMostType.nodeId, typeDefinitionNode.nodeId)) {
377
+ return; // nothing to do
378
+ }
379
+ const filter = new MandatoryChildOrRequestedOptionalFilter(instance, optionalsMap);
380
+ doTrace &&
381
+ traceLog(chalk.cyan(extraInfo.pad(), "cloning relevant member of typeDefinition class"), typeDefinitionNode.browseName.toString());
382
+ const browseNameMap = new Set();
383
+ (0, base_node_private_1._clone_children_references)(typeDefinitionNode, instance, copyAlsoModellingRules, filter, extraInfo, browseNameMap);
384
+ // now apply recursion on baseTypeDefinition to get properties and components from base class
385
+ const baseTypeDefinitionNodeId = typeDefinitionNode.subtypeOf;
386
+ const baseTypeDefinition = typeDefinitionNode.subtypeOfObj;
387
+ doTrace &&
388
+ traceLog(chalk.cyan(extraInfo.pad(), "now apply recursion on baseTypeDefinition to get properties and components from base class"), baseTypeDefinition.browseName.toString());
389
+ // istanbul ignore next
390
+ if (!baseTypeDefinition) {
391
+ throw new Error(chalk.red("Cannot find object with nodeId ") + baseTypeDefinitionNodeId);
392
+ }
393
+ extraInfo.level++;
394
+ _initialize_properties_and_components(instance, topMostType, baseTypeDefinition, copyAlsoModellingRules, optionalsMap, extraInfo);
395
+ extraInfo.level--;
396
+ }
397
+ /**
398
+ * @method hasChildWithBrowseName
399
+ * returns true if the parent object has a child with the provided browseName
400
+ * @param parent
401
+ * @param childBrowseName
402
+ */
403
+ function hasChildWithBrowseName(parent, childBrowseName) {
404
+ if (!parent) {
405
+ throw Error("Internal error");
406
+ }
407
+ // extract children
408
+ const children = parent.findReferencesAsObject("HasChild", true);
409
+ return (children.filter((child) => {
410
+ var _a, _b;
411
+ return ((_a = child.browseName.name) === null || _a === void 0 ? void 0 : _a.toString()) === ((_b = childBrowseName.name) === null || _b === void 0 ? void 0 : _b.toString());
412
+ }).length > 0);
413
+ }
414
+ function getParent(addressSpace, options) {
415
+ const parent = options.componentOf || options.organizedBy;
416
+ if (parent instanceof node_opcua_nodeid_1.NodeId) {
417
+ return addressSpace.findNode(parent);
418
+ }
419
+ return parent;
420
+ }
421
+ function assertUnusedChildBrowseName(addressSpace, options) {
422
+ const resolveOptionalObject = (node) => node ? addressSpace._coerceNode(node) || undefined : undefined;
423
+ options.componentOf = resolveOptionalObject(options.componentOf);
424
+ options.organizedBy = resolveOptionalObject(options.organizedBy);
425
+ (0, node_opcua_assert_1.assert)(!(options.componentOf && options.organizedBy));
426
+ const parent = getParent(addressSpace, options);
427
+ if (!parent) {
428
+ return;
429
+ }
430
+ (0, node_opcua_assert_1.assert)(parent !== null && typeof parent === "object");
431
+ if (!(parent instanceof base_node_impl_1.BaseNodeImpl)) {
432
+ throw new Error("Invalid parent parent is " + parent.constructor.name);
433
+ }
434
+ // istanbul ignore next
435
+ // verify that no components already exists in parent
436
+ if (parent && hasChildWithBrowseName(parent, (0, node_opcua_data_model_1.coerceQualifiedName)(options.browseName))) {
437
+ throw new Error("object " +
438
+ parent.browseName.name.toString() +
439
+ " have already a child with browseName " +
440
+ options.browseName.toString());
441
+ }
442
+ }
443
+ exports.assertUnusedChildBrowseName = assertUnusedChildBrowseName;
444
+ exports.assertUnusedChildBrowseName = assertUnusedChildBrowseName;
445
+ exports.initialize_properties_and_components = initialize_properties_and_components;
446
+ const hasTypeDefinitionNodeId = (0, node_opcua_nodeid_1.makeNodeId)(node_opcua_constants_1.ReferenceTypeIds.HasTypeDefinition);
447
+ const hasModellingRuleNodeId = (0, node_opcua_nodeid_1.makeNodeId)(node_opcua_constants_1.ReferenceTypeIds.HasModellingRule);
448
+ /**
449
+ * remove unwanted reference such as HasTypeDefinition and HasModellingRule
450
+ * from the list
451
+ */
452
+ function _remove_unwanted_ref(references) {
453
+ // filter out HasTypeDefinition (i=40) , HasModellingRule (i=37);
454
+ references = references.filter((reference) => !(0, node_opcua_nodeid_1.sameNodeId)(reference.referenceType, hasTypeDefinitionNodeId) &&
455
+ !(0, node_opcua_nodeid_1.sameNodeId)(reference.referenceType, hasModellingRuleNodeId));
456
+ return references;
457
+ }
458
+ /**
459
+ *
460
+ */
461
+ function findNonHierarchicalReferences(originalObject) {
462
+ // todo: MEMOIZE this method
463
+ const addressSpace = originalObject.addressSpace;
464
+ const referenceId = addressSpace.findReferenceType("NonHierarchicalReferences");
465
+ if (!referenceId) {
466
+ return [];
467
+ }
468
+ (0, node_opcua_assert_1.assert)(referenceId);
469
+ // we need to explore the non hierarchical references backwards
470
+ let references = originalObject.findReferencesEx("NonHierarchicalReferences", node_opcua_data_model_1.BrowseDirection.Inverse);
471
+ references = [].concat(references, originalObject.findReferencesEx("HasEventSource", node_opcua_data_model_1.BrowseDirection.Inverse));
472
+ const parent = _get_parent_as_VariableOrObjectType(originalObject);
473
+ if (parent && parent.subtypeOfObj) {
474
+ // parent is a ObjectType or VariableType and is not a root type
475
+ (0, node_opcua_assert_1.assert)(parent.nodeClass === node_opcua_data_model_1.NodeClass.VariableType || parent.nodeClass === node_opcua_data_model_1.NodeClass.ObjectType);
476
+ // let investigate the same child base child
477
+ const child = parent.subtypeOfObj.getChildByName(originalObject.browseName);
478
+ if (child) {
479
+ const baseRef = findNonHierarchicalReferences(child);
480
+ references = [].concat(references, baseRef);
481
+ }
482
+ }
483
+ // perform some cleanup
484
+ references = _remove_unwanted_ref(references);
485
+ return references;
486
+ }
487
+ function reconstructNonHierarchicalReferences(extraInfo) {
488
+ const findImplementedObject = (ref) => extraInfo.mapOrgToClone.get(ref.nodeId.toString()) || null;
489
+ // navigate through original objects to find those that are being references by node that
490
+ // have been cloned .
491
+ // this could be node organized by some FunctionalGroup
492
+ //
493
+ for (const { original, cloned } of extraInfo.mapOrgToClone.values()) {
494
+ // find NonHierarchical References on original object
495
+ const originalNonHierarchical = findNonHierarchicalReferences(original);
496
+ if (originalNonHierarchical.length === 0) {
497
+ continue;
498
+ }
499
+ // istanbul ignore next
500
+ if (doDebug) {
501
+ debugLog(" investigation ", original.browseName.toString(), cloned.nodeClass.toString(), original.nodeClass.toString(), original.nodeId.toString(), cloned.nodeId.toString());
502
+ }
503
+ for (const ref of originalNonHierarchical) {
504
+ const info = findImplementedObject(ref);
505
+ // if the object pointed by this reference is also cloned ...
506
+ if (info) {
507
+ const originalDest = info.original;
508
+ const cloneDest = info.cloned;
509
+ // istanbul ignore next
510
+ if (doDebug) {
511
+ debugLog(chalk.cyan(" adding reference "), ref.referenceType, " from cloned ", cloned.nodeId.toString(), cloned.browseName.toString(), " to cloned ", cloneDest.nodeId.toString(), cloneDest.browseName.toString());
512
+ }
513
+ // restore reference
514
+ cloned.addReference({
515
+ isForward: false,
516
+ nodeId: cloneDest.nodeId,
517
+ referenceType: ref.referenceType
518
+ });
519
+ }
520
+ }
521
+ }
522
+ }
523
+ /**
524
+ * recreate functional group types according to type definition
525
+ *
526
+ * @method reconstructFunctionalGroupType
527
+ * @param baseType
528
+ */
529
+ /* @example:
530
+ *
531
+ * MyDeviceType
532
+ * |
533
+ * +----------|- ParameterSet(BaseObjectType)
534
+ * | |
535
+ * | +-----------------|- Parameter1
536
+ * | ^
537
+ * +----------|- Config(FunctionalGroupType) |
538
+ * | |
539
+ * +-------- Organizes---+
540
+ */
541
+ function reconstructFunctionalGroupType(extraInfo) {
542
+ // navigate through original objects to find those that are being organized by some FunctionalGroup
543
+ for (const { original, cloned } of extraInfo.mapOrgToClone.values()) {
544
+ const organizedByArray = original.findReferencesEx("Organizes", node_opcua_data_model_1.BrowseDirection.Inverse);
545
+ for (const ref of organizedByArray) {
546
+ const info = extraInfo.mapOrgToClone.get(ref.nodeId.toString());
547
+ if (!info)
548
+ continue;
549
+ const folder = info.original;
550
+ (0, node_opcua_assert_1.assert)(folder.typeDefinitionObj.browseName.name.toString() === "FunctionalGroupType");
551
+ // now create the same reference with the instantiated function group
552
+ const destFolder = info.cloned;
553
+ (0, node_opcua_assert_1.assert)(ref.referenceType);
554
+ destFolder.addReference({
555
+ isForward: !ref.isForward,
556
+ nodeId: cloned.nodeId,
557
+ referenceType: ref.referenceType
558
+ });
559
+ }
560
+ }
561
+ }
562
+ function initialize_properties_and_components(instance, topMostType, nodeType, copyAlsoModellingRules, optionals) {
563
+ const extraInfo = new CloneHelper();
564
+ extraInfo.registerClonedObject(nodeType, instance);
565
+ const optionalsMap = (0, make_optionals_map_1.makeOptionalsMap)(optionals);
566
+ _initialize_properties_and_components(instance, topMostType, nodeType, copyAlsoModellingRules, optionalsMap, extraInfo);
567
+ reconstructFunctionalGroupType(extraInfo);
568
+ reconstructNonHierarchicalReferences(extraInfo);
569
+ }
570
+ exports.initialize_properties_and_components = initialize_properties_and_components;
571
571
  //# sourceMappingURL=ua_variable_type_impl.js.map