node-opcua-address-space 2.75.0 → 2.76.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 (312) 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/coerce_enum_value.d.ts +6 -6
  12. package/dist/source/helpers/coerce_enum_value.js +33 -33
  13. package/dist/source/helpers/dump_tools.d.ts +14 -14
  14. package/dist/source/helpers/dump_tools.js +78 -78
  15. package/dist/source/helpers/ensure_secure_access.d.ts +9 -9
  16. package/dist/source/helpers/ensure_secure_access.js +76 -76
  17. package/dist/source/helpers/make_optionals_map.d.ts +21 -21
  18. package/dist/source/helpers/make_optionals_map.js +29 -29
  19. package/dist/source/helpers/multiform_func.d.ts +11 -11
  20. package/dist/source/helpers/multiform_func.js +75 -75
  21. package/dist/source/helpers/resolve_opaque_on_address_space.d.ts +3 -3
  22. package/dist/source/helpers/resolve_opaque_on_address_space.js +36 -36
  23. package/dist/source/index.d.ts +56 -56
  24. package/dist/source/index.js +83 -83
  25. package/dist/source/interfaces/alarms_and_conditions/condition_info_i.d.ts +19 -19
  26. package/dist/source/interfaces/alarms_and_conditions/condition_info_i.js +2 -2
  27. package/dist/source/interfaces/alarms_and_conditions/condition_snapshot.d.ts +193 -193
  28. package/dist/source/interfaces/alarms_and_conditions/condition_snapshot.js +2 -2
  29. package/dist/source/interfaces/alarms_and_conditions/deviation_stuff.d.ts +12 -12
  30. package/dist/source/interfaces/alarms_and_conditions/deviation_stuff.js +2 -2
  31. package/dist/source/interfaces/alarms_and_conditions/install_setpoint_options.d.ts +10 -10
  32. package/dist/source/interfaces/alarms_and_conditions/install_setpoint_options.js +2 -2
  33. package/dist/source/interfaces/alarms_and_conditions/instantiate_alarm_condition_options.d.ts +7 -7
  34. package/dist/source/interfaces/alarms_and_conditions/instantiate_alarm_condition_options.js +2 -2
  35. package/dist/source/interfaces/alarms_and_conditions/instantiate_condition_options.d.ts +7 -7
  36. package/dist/source/interfaces/alarms_and_conditions/instantiate_condition_options.js +2 -2
  37. package/dist/source/interfaces/alarms_and_conditions/instantiate_exclusive_deviation_alarm_options.d.ts +4 -4
  38. package/dist/source/interfaces/alarms_and_conditions/instantiate_exclusive_deviation_alarm_options.js +2 -2
  39. package/dist/source/interfaces/alarms_and_conditions/instantiate_exclusive_limit_alarm_options.d.ts +4 -4
  40. package/dist/source/interfaces/alarms_and_conditions/instantiate_exclusive_limit_alarm_options.js +2 -2
  41. package/dist/source/interfaces/alarms_and_conditions/instantiate_limit_alarm_options.d.ts +9 -9
  42. package/dist/source/interfaces/alarms_and_conditions/instantiate_limit_alarm_options.js +2 -2
  43. package/dist/source/interfaces/alarms_and_conditions/instantiate_non_exclusive_deviation_alarm_options.d.ts +4 -4
  44. package/dist/source/interfaces/alarms_and_conditions/instantiate_non_exclusive_deviation_alarm_options.js +2 -2
  45. package/dist/source/interfaces/alarms_and_conditions/instantiate_non_exclusive_limit_alarm_options.d.ts +4 -4
  46. package/dist/source/interfaces/alarms_and_conditions/instantiate_non_exclusive_limit_alarm_options.js +2 -2
  47. package/dist/source/interfaces/alarms_and_conditions/instantiate_off_normal_alarm_options.d.ts +20 -20
  48. package/dist/source/interfaces/alarms_and_conditions/instantiate_off_normal_alarm_options.js +2 -2
  49. package/dist/source/interfaces/alarms_and_conditions/ua_acknowledgeable_condition_ex.d.ts +23 -23
  50. package/dist/source/interfaces/alarms_and_conditions/ua_acknowledgeable_condition_ex.js +2 -2
  51. package/dist/source/interfaces/alarms_and_conditions/ua_alarm_condition_ex.d.ts +32 -32
  52. package/dist/source/interfaces/alarms_and_conditions/ua_alarm_condition_ex.js +2 -2
  53. package/dist/source/interfaces/alarms_and_conditions/ua_certificate_expiration_alarm_ex.d.ts +19 -15
  54. package/dist/source/interfaces/alarms_and_conditions/ua_certificate_expiration_alarm_ex.js +2 -2
  55. package/dist/source/interfaces/alarms_and_conditions/ua_condition_ex.d.ts +42 -42
  56. package/dist/source/interfaces/alarms_and_conditions/ua_condition_ex.js +2 -2
  57. package/dist/source/interfaces/alarms_and_conditions/ua_discrete_alarm_ex.d.ts +7 -7
  58. package/dist/source/interfaces/alarms_and_conditions/ua_discrete_alarm_ex.js +25 -25
  59. package/dist/source/interfaces/alarms_and_conditions/ua_exclusive_deviation_alarm_ex.d.ts +5 -5
  60. package/dist/source/interfaces/alarms_and_conditions/ua_exclusive_deviation_alarm_ex.js +2 -2
  61. package/dist/source/interfaces/alarms_and_conditions/ua_exclusive_limit_alarm_ex.d.ts +20 -20
  62. package/dist/source/interfaces/alarms_and_conditions/ua_exclusive_limit_alarm_ex.js +2 -2
  63. package/dist/source/interfaces/alarms_and_conditions/ua_limit_alarm_ex.d.ts +26 -26
  64. package/dist/source/interfaces/alarms_and_conditions/ua_limit_alarm_ex.js +2 -2
  65. package/dist/source/interfaces/alarms_and_conditions/ua_non_exclusive_deviation_alarm_ex.d.ts +8 -8
  66. package/dist/source/interfaces/alarms_and_conditions/ua_non_exclusive_deviation_alarm_ex.js +2 -2
  67. package/dist/source/interfaces/alarms_and_conditions/ua_non_exclusive_limit_alarm_ex.d.ts +10 -10
  68. package/dist/source/interfaces/alarms_and_conditions/ua_non_exclusive_limit_alarm_ex.js +2 -2
  69. package/dist/source/interfaces/data_access/ua_multistate_discrete_ex.d.ts +21 -21
  70. package/dist/source/interfaces/data_access/ua_multistate_discrete_ex.js +2 -2
  71. package/dist/source/interfaces/data_access/ua_multistate_value_discrete_ex.d.ts +24 -24
  72. package/dist/source/interfaces/data_access/ua_multistate_value_discrete_ex.js +2 -2
  73. package/dist/source/interfaces/data_access/ua_two_state_discrete_ex.d.ts +12 -12
  74. package/dist/source/interfaces/data_access/ua_two_state_discrete_ex.js +2 -2
  75. package/dist/source/interfaces/data_access/ua_y_array_item_ex.d.ts +8 -8
  76. package/dist/source/interfaces/data_access/ua_y_array_item_ex.js +2 -2
  77. package/dist/source/interfaces/state_machine/ua_exclusive_limit_state_machine_type_ex.d.ts +12 -12
  78. package/dist/source/interfaces/state_machine/ua_exclusive_limit_state_machine_type_ex.js +2 -2
  79. package/dist/source/interfaces/state_machine/ua_finite_state_machine_type.d.ts +49 -49
  80. package/dist/source/interfaces/state_machine/ua_finite_state_machine_type.js +2 -2
  81. package/dist/source/interfaces/state_machine/ua_program_state_machine_type.d.ts +11 -11
  82. package/dist/source/interfaces/state_machine/ua_program_state_machine_type.js +2 -2
  83. package/dist/source/interfaces/state_machine/ua_shelved_state_machine_ex.d.ts +30 -30
  84. package/dist/source/interfaces/state_machine/ua_shelved_state_machine_ex.js +2 -2
  85. package/dist/source/interfaces/state_machine/ua_state_machine_type.d.ts +222 -222
  86. package/dist/source/interfaces/state_machine/ua_state_machine_type.js +2 -2
  87. package/dist/source/interfaces/state_machine/ua_transition_ex.d.ts +6 -6
  88. package/dist/source/interfaces/state_machine/ua_transition_ex.js +2 -2
  89. package/dist/source/interfaces/ua_subscription_diagnostics_variable_ex.d.ts +8 -8
  90. package/dist/source/interfaces/ua_subscription_diagnostics_variable_ex.js +2 -2
  91. package/dist/source/loader/decode_xml_extension_object.d.ts +6 -6
  92. package/dist/source/loader/decode_xml_extension_object.js +71 -71
  93. package/dist/source/loader/ensure_datatype_extracted.d.ts +5 -5
  94. package/dist/source/loader/ensure_datatype_extracted.js +45 -45
  95. package/dist/source/loader/generateAddressSpaceRaw.d.ts +10 -10
  96. package/dist/source/loader/generateAddressSpaceRaw.js +45 -45
  97. package/dist/source/loader/load_nodeset2.d.ts +16 -16
  98. package/dist/source/loader/load_nodeset2.js +1461 -1461
  99. package/dist/source/loader/make_semver_compatible.d.ts +6 -6
  100. package/dist/source/loader/make_semver_compatible.js +25 -25
  101. package/dist/source/loader/make_xml_extension_object_parser.d.ts +28 -28
  102. package/dist/source/loader/make_xml_extension_object_parser.js +325 -325
  103. package/dist/source/loader/namespace_post_step.d.ts +10 -6
  104. package/dist/source/loader/namespace_post_step.js +61 -47
  105. package/dist/source/loader/namespace_post_step.js.map +1 -1
  106. package/dist/source/loader/register_node_promoter.d.ts +2 -3
  107. package/dist/source/loader/register_node_promoter.js +9 -9
  108. package/dist/source/loader/register_node_promoter.js.map +1 -1
  109. package/dist/source/namespace.d.ts +6 -6
  110. package/dist/source/namespace.js +2 -2
  111. package/dist/source/namespace_alarm_and_condition.d.ts +32 -32
  112. package/dist/source/namespace_alarm_and_condition.js +2 -2
  113. package/dist/source/namespace_data_access.d.ts +42 -42
  114. package/dist/source/namespace_data_access.js +2 -2
  115. package/dist/source/namespace_machine_state.d.ts +7 -7
  116. package/dist/source/namespace_machine_state.js +2 -2
  117. package/dist/source/pseudo_session.d.ts +55 -55
  118. package/dist/source/pseudo_session.js +203 -203
  119. package/dist/source/session_context.d.ts +111 -111
  120. package/dist/source/session_context.js +265 -265
  121. package/dist/source/set_namespace_meta_data.d.ts +2 -2
  122. package/dist/source/set_namespace_meta_data.js +59 -59
  123. package/dist/source/ua_root_folder.d.ts +9 -9
  124. package/dist/source/ua_root_folder.js +2 -2
  125. package/dist/source/ua_two_state_variable_ex.d.ts +23 -23
  126. package/dist/source/ua_two_state_variable_ex.js +2 -2
  127. package/dist/source/xml_writer.d.ts +9 -9
  128. package/dist/source/xml_writer.js +2 -2
  129. package/dist/src/address_space.d.ts +392 -392
  130. package/dist/src/address_space.js +1392 -1392
  131. package/dist/src/address_space_change_event_tools.d.ts +6 -6
  132. package/dist/src/address_space_change_event_tools.js +149 -149
  133. package/dist/src/address_space_private.d.ts +43 -43
  134. package/dist/src/address_space_private.js +2 -2
  135. package/dist/src/alarms_and_conditions/condition.d.ts +5 -5
  136. package/dist/src/alarms_and_conditions/condition.js +78 -78
  137. package/dist/src/alarms_and_conditions/condition_info_impl.d.ts +26 -26
  138. package/dist/src/alarms_and_conditions/condition_info_impl.js +54 -54
  139. package/dist/src/alarms_and_conditions/condition_snapshot_impl.d.ts +222 -222
  140. package/dist/src/alarms_and_conditions/condition_snapshot_impl.js +657 -657
  141. package/dist/src/alarms_and_conditions/deviation_alarm_helper.d.ts +9 -9
  142. package/dist/src/alarms_and_conditions/deviation_alarm_helper.js +61 -61
  143. package/dist/src/alarms_and_conditions/index.d.ts +16 -16
  144. package/dist/src/alarms_and_conditions/index.js +32 -32
  145. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.d.ts +44 -44
  146. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js +244 -244
  147. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.d.ts +93 -93
  148. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js +419 -416
  149. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js.map +1 -1
  150. package/dist/src/alarms_and_conditions/ua_base_event_impl.d.ts +26 -26
  151. package/dist/src/alarms_and_conditions/ua_base_event_impl.js +38 -38
  152. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.d.ts +44 -36
  153. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.js +183 -118
  154. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.js.map +1 -1
  155. package/dist/src/alarms_and_conditions/ua_condition_impl.d.ts +153 -153
  156. package/dist/src/alarms_and_conditions/ua_condition_impl.js +1028 -1024
  157. package/dist/src/alarms_and_conditions/ua_condition_impl.js.map +1 -1
  158. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.d.ts +14 -14
  159. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.js +34 -34
  160. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.d.ts +24 -24
  161. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.js +56 -56
  162. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.d.ts +11 -11
  163. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.js +11 -11
  164. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.d.ts +23 -23
  165. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.js +86 -86
  166. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.js.map +1 -1
  167. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm_impl.d.ts +11 -11
  168. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm_impl.js +7 -7
  169. package/dist/src/alarms_and_conditions/ua_limit_alarm_impl.d.ts +79 -79
  170. package/dist/src/alarms_and_conditions/ua_limit_alarm_impl.js +250 -250
  171. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.d.ts +24 -24
  172. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.js +50 -50
  173. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.d.ts +19 -19
  174. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.js +162 -162
  175. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.js.map +1 -1
  176. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.d.ts +46 -46
  177. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js +166 -166
  178. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js.map +1 -1
  179. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.d.ts +18 -18
  180. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.js +17 -17
  181. package/dist/src/apply_condition_refresh.d.ts +6 -6
  182. package/dist/src/apply_condition_refresh.js +27 -27
  183. package/dist/src/base_node_impl.d.ts +281 -281
  184. package/dist/src/base_node_impl.js +1395 -1395
  185. package/dist/src/base_node_private.d.ts +61 -61
  186. package/dist/src/base_node_private.js +705 -705
  187. package/dist/src/data_access/add_dataItem_stuff.d.ts +11 -11
  188. package/dist/src/data_access/add_dataItem_stuff.js +61 -61
  189. package/dist/src/data_access/check_variant_compatibility_ua_analog_item.d.ts +1 -1
  190. package/dist/src/data_access/check_variant_compatibility_ua_analog_item.js +34 -34
  191. package/dist/src/data_access/ua_multistate_discrete_impl.d.ts +32 -32
  192. package/dist/src/data_access/ua_multistate_discrete_impl.js +130 -130
  193. package/dist/src/data_access/ua_multistate_value_discrete_impl.d.ts +51 -51
  194. package/dist/src/data_access/ua_multistate_value_discrete_impl.js +249 -249
  195. package/dist/src/data_access/ua_two_state_discrete_impl.d.ts +25 -25
  196. package/dist/src/data_access/ua_two_state_discrete_impl.js +153 -153
  197. package/dist/src/event_data.d.ts +34 -34
  198. package/dist/src/event_data.js +64 -64
  199. package/dist/src/extension_object_array_node.d.ts +61 -61
  200. package/dist/src/extension_object_array_node.js +276 -276
  201. package/dist/src/historical_access/address_space_historical_data_node.d.ts +26 -26
  202. package/dist/src/historical_access/address_space_historical_data_node.js +630 -630
  203. package/dist/src/index_current.d.ts +43 -43
  204. package/dist/src/index_current.js +74 -74
  205. package/dist/src/namespace_impl.d.ts +461 -461
  206. package/dist/src/namespace_impl.js +1732 -1732
  207. package/dist/src/namespace_private.d.ts +21 -21
  208. package/dist/src/namespace_private.js +32 -32
  209. package/dist/src/nodeid_manager.d.ts +36 -36
  210. package/dist/src/nodeid_manager.js +197 -197
  211. package/dist/src/nodeset_tools/adjust_namespace_array.d.ts +2 -2
  212. package/dist/src/nodeset_tools/adjust_namespace_array.js +13 -13
  213. package/dist/src/nodeset_tools/construct_namespace_dependency.d.ts +2 -2
  214. package/dist/src/nodeset_tools/construct_namespace_dependency.js +83 -83
  215. package/dist/src/nodeset_tools/nodeset_to_xml.d.ts +2 -2
  216. package/dist/src/nodeset_tools/nodeset_to_xml.js +1155 -1155
  217. package/dist/src/nodeset_tools/typedictionary_to_xml.d.ts +2 -2
  218. package/dist/src/nodeset_tools/typedictionary_to_xml.js +154 -154
  219. package/dist/src/reference_impl.d.ts +43 -43
  220. package/dist/src/reference_impl.js +139 -139
  221. package/dist/src/role_permissions.d.ts +2 -2
  222. package/dist/src/role_permissions.js +10 -10
  223. package/dist/src/state_machine/finite_state_machine.d.ts +67 -67
  224. package/dist/src/state_machine/finite_state_machine.js +353 -353
  225. package/dist/src/state_machine/ua_shelving_state_machine_ex.d.ts +38 -38
  226. package/dist/src/state_machine/ua_shelving_state_machine_ex.js +250 -250
  227. package/dist/src/state_machine/ua_two_state_variable.d.ts +61 -61
  228. package/dist/src/state_machine/ua_two_state_variable.js +331 -331
  229. package/dist/src/state_machine/ua_two_state_variable.js.map +1 -1
  230. package/dist/src/tool_isSupertypeOf.d.ts +17 -17
  231. package/dist/src/tool_isSupertypeOf.js +108 -108
  232. package/dist/src/ua_condition_type.d.ts +8 -8
  233. package/dist/src/ua_condition_type.js +2 -2
  234. package/dist/src/ua_data_type_impl.d.ts +93 -93
  235. package/dist/src/ua_data_type_impl.js +371 -371
  236. package/dist/src/ua_method_impl.d.ts +41 -41
  237. package/dist/src/ua_method_impl.js +208 -208
  238. package/dist/src/ua_object_impl.d.ts +35 -35
  239. package/dist/src/ua_object_impl.js +161 -161
  240. package/dist/src/ua_object_type_impl.d.ts +48 -48
  241. package/dist/src/ua_object_type_impl.js +124 -124
  242. package/dist/src/ua_reference_type_impl.d.ts +43 -43
  243. package/dist/src/ua_reference_type_impl.js +139 -139
  244. package/dist/src/ua_variable_impl.d.ts +351 -351
  245. package/dist/src/ua_variable_impl.js +1604 -1604
  246. package/dist/src/ua_variable_impl_ext_obj.d.ts +17 -17
  247. package/dist/src/ua_variable_impl_ext_obj.js +437 -437
  248. package/dist/src/ua_variable_type_impl.d.ts +62 -62
  249. package/dist/src/ua_variable_type_impl.js +570 -570
  250. package/dist/src/ua_view_impl.d.ts +19 -19
  251. package/dist/src/ua_view_impl.js +43 -43
  252. package/distHelpers/add_event_generator_object.d.ts +3 -3
  253. package/distHelpers/add_event_generator_object.js +64 -65
  254. package/distHelpers/add_event_generator_object.js.map +1 -1
  255. package/distHelpers/alarms_and_conditions_demo.d.ts +9 -9
  256. package/distHelpers/alarms_and_conditions_demo.js +115 -115
  257. package/distHelpers/assertHasMatchingReference.d.ts +19 -19
  258. package/distHelpers/assertHasMatchingReference.js +40 -40
  259. package/distHelpers/boiler_system.d.ts +113 -113
  260. package/distHelpers/boiler_system.js +395 -395
  261. package/distHelpers/create_minimalist_address_space_nodeset.d.ts +5 -5
  262. package/distHelpers/create_minimalist_address_space_nodeset.js +171 -171
  263. package/distHelpers/date_utils.d.ts +3 -3
  264. package/distHelpers/date_utils.js +9 -9
  265. package/distHelpers/dump_statemachine.js +127 -127
  266. package/distHelpers/get_address_space_fixture.d.ts +1 -1
  267. package/distHelpers/get_address_space_fixture.js +30 -30
  268. package/distHelpers/get_mini_address_space.d.ts +7 -7
  269. package/distHelpers/get_mini_address_space.js +36 -36
  270. package/distHelpers/index.d.ts +12 -12
  271. package/distHelpers/index.js +28 -28
  272. package/distHelpers/mock_session.d.ts +14 -14
  273. package/distHelpers/mock_session.js +25 -25
  274. package/distNodeJS/generate_address_space.d.ts +4 -4
  275. package/distNodeJS/generate_address_space.js +41 -41
  276. package/distNodeJS/index.d.ts +1 -1
  277. package/distNodeJS/index.js +17 -17
  278. package/generate.js +1 -1
  279. package/package.json +36 -38
  280. package/source/interfaces/alarms_and_conditions/ua_certificate_expiration_alarm_ex.ts +5 -0
  281. package/source/loader/namespace_post_step.ts +26 -3
  282. package/source/loader/register_node_promoter.ts +5 -4
  283. package/src/alarms_and_conditions/ua_alarm_condition_impl.ts +4 -1
  284. package/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.ts +106 -49
  285. package/src/alarms_and_conditions/ua_condition_impl.ts +4 -1
  286. package/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.ts +1 -1
  287. package/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.ts +3 -3
  288. package/src/alarms_and_conditions/ua_off_normal_alarm_impl.ts +12 -10
  289. package/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.ts +1 -1
  290. package/src/state_machine/ua_two_state_variable.ts +1 -2
  291. package/test_helpers/add_event_generator_object.ts +0 -1
  292. package/dist/source/helpers/check_event_clause.d.ts +0 -17
  293. package/dist/source/helpers/check_event_clause.js +0 -53
  294. package/dist/source/helpers/check_event_clause.js.map +0 -1
  295. package/dist/src/alarms_and_conditions/check_where_clause.d.ts +0 -4
  296. package/dist/src/alarms_and_conditions/check_where_clause.js +0 -110
  297. package/dist/src/alarms_and_conditions/check_where_clause.js.map +0 -1
  298. package/dist/src/alarms_and_conditions/condition_info.d.ts +0 -27
  299. package/dist/src/alarms_and_conditions/condition_info.js +0 -55
  300. package/dist/src/alarms_and_conditions/condition_info.js.map +0 -1
  301. package/dist/src/alarms_and_conditions/condition_snapshot.d.ts +0 -233
  302. package/dist/src/alarms_and_conditions/condition_snapshot.js +0 -667
  303. package/dist/src/alarms_and_conditions/condition_snapshot.js.map +0 -1
  304. package/dist/src/alarms_and_conditions/extract_event_fields.d.ts +0 -10
  305. package/dist/src/alarms_and_conditions/extract_event_fields.js +0 -90
  306. package/dist/src/alarms_and_conditions/extract_event_fields.js.map +0 -1
  307. package/dist/src/data_access/ua_multistate_value_discrete.d.ts +0 -51
  308. package/dist/src/data_access/ua_multistate_value_discrete.js +0 -250
  309. package/dist/src/data_access/ua_multistate_value_discrete.js.map +0 -1
  310. package/dist/src/data_access/ua_two_state_discrete.d.ts +0 -25
  311. package/dist/src/data_access/ua_two_state_discrete.js +0 -154
  312. package/dist/src/data_access/ua_two_state_discrete.js.map +0 -1
@@ -1,1156 +1,1156 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dumpXml = void 0;
4
- /**
5
- * @module node-opcua-address-space
6
- */
7
- // produce nodeset xml files
8
- const node_opcua_assert_1 = require("node-opcua-assert");
9
- const node_opcua_debug_1 = require("node-opcua-debug");
10
- const node_opcua_data_model_1 = require("node-opcua-data-model");
11
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
12
- const utils = require("node-opcua-utils");
13
- const node_opcua_variant_1 = require("node-opcua-variant");
14
- const node_opcua_basic_types_1 = require("node-opcua-basic-types");
15
- const node_opcua_types_1 = require("node-opcua-types");
16
- const reference_impl_1 = require("../reference_impl");
17
- const base_node_impl_1 = require("../base_node_impl");
18
- const ua_reference_type_impl_1 = require("../ua_reference_type_impl");
19
- const ua_object_type_impl_1 = require("../ua_object_type_impl");
20
- const ua_variable_impl_1 = require("../ua_variable_impl");
21
- const ua_object_impl_1 = require("../ua_object_impl");
22
- const namespace_impl_1 = require("../namespace_impl");
23
- const ua_method_impl_1 = require("../ua_method_impl");
24
- const ua_data_type_impl_1 = require("../ua_data_type_impl");
25
- const ua_variable_type_impl_1 = require("../ua_variable_type_impl");
26
- const decode_xml_extension_object_1 = require("../../source/loader/decode_xml_extension_object");
27
- const construct_namespace_dependency_1 = require("./construct_namespace_dependency");
28
- // tslint:disable:no-var-requires
29
- const XMLWriter = require("xml-writer");
30
- const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
31
- const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
32
- const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
33
- function _hash(node) {
34
- return node.nodeId.toString();
35
- }
36
- function _dumpDisplayName(xw, node) {
37
- if (node.displayName && node.displayName[0]) {
38
- xw.startElement("DisplayName").text(node.displayName[0].text).endElement();
39
- }
40
- }
41
- function _dumpDescription(xw, node) {
42
- if (node.description && node.description.text && node.description.text.length) {
43
- let desc = node.description.text;
44
- desc = desc || "";
45
- xw.startElement("Description").text(desc).endElement();
46
- }
47
- }
48
- function translateNodeId(xw, nodeId) {
49
- (0, node_opcua_assert_1.assert)(nodeId instanceof node_opcua_nodeid_1.NodeId);
50
- const nn = xw.translationTable[nodeId.namespace];
51
- const translatedNode = new node_opcua_nodeid_1.NodeId(nodeId.identifierType, nodeId.value, nn);
52
- return translatedNode;
53
- }
54
- function n(xw, nodeId) {
55
- return translateNodeId(xw, nodeId).toString().replace("ns=0;", "");
56
- }
57
- function translateBrowseName(xw, browseName) {
58
- (0, node_opcua_assert_1.assert)(browseName instanceof node_opcua_data_model_1.QualifiedName);
59
- const nn = xw.translationTable[browseName.namespaceIndex];
60
- const translatedBrowseName = new node_opcua_data_model_1.QualifiedName({ namespaceIndex: nn, name: browseName.name });
61
- return translatedBrowseName;
62
- }
63
- function b(xw, browseName) {
64
- return translateBrowseName(xw, browseName).toString().replace("ns=0;", "");
65
- }
66
- function _dumpReferences(xw, node) {
67
- xw.startElement("References");
68
- const addressSpace = node.addressSpace;
69
- const aggregateReferenceType = addressSpace.findReferenceType("Aggregates");
70
- const hasChildReferenceType = addressSpace.findReferenceType("HasChild");
71
- const hasSubtypeReferenceType = addressSpace.findReferenceType("HasSubtype");
72
- const hasTypeDefinitionReferenceType = addressSpace.findReferenceType("HasTypeDefinition");
73
- const nonHierarchicalReferencesType = addressSpace.findReferenceType("NonHierarchicalReferences");
74
- const organizesReferencesType = addressSpace.findReferenceType("Organizes");
75
- const connectsToReferenceType = addressSpace.findReferenceType("ConnectsTo");
76
- const hasEventSourceReferenceType = addressSpace.findReferenceType("HasEventSource");
77
- function referenceToKeep(reference) {
78
- const referenceType = reference._referenceType;
79
- // get the direct backward reference to a external namespace
80
- if (referenceType.isSupertypeOf(aggregateReferenceType) && !reference.isForward) {
81
- if (reference.nodeId.namespace !== node.nodeId.namespace) {
82
- // todo: may be check that reference.nodeId.namespace is one of the namespace
83
- // on which our namespace is build and not a derived one !
84
- // xx console.log("xxxxxxxxxxxxxx Keeping => ", referenceType.toString(), reference.node?.nodeId.toString());
85
- return true;
86
- }
87
- }
88
- // only keep
89
- if (referenceType.isSupertypeOf(aggregateReferenceType) && reference.isForward) {
90
- return true;
91
- }
92
- else if (referenceType.isSupertypeOf(hasSubtypeReferenceType) && !reference.isForward) {
93
- return true;
94
- }
95
- else if (referenceType.isSupertypeOf(hasTypeDefinitionReferenceType) && reference.isForward) {
96
- return true;
97
- }
98
- else if (referenceType.isSupertypeOf(nonHierarchicalReferencesType) && reference.isForward) {
99
- return true;
100
- }
101
- else if (referenceType.isSupertypeOf(organizesReferencesType) && !reference.isForward) {
102
- return true;
103
- }
104
- else if (connectsToReferenceType && referenceType.isSupertypeOf(connectsToReferenceType) && reference.isForward) {
105
- return true;
106
- }
107
- else if (referenceType.isSupertypeOf(hasEventSourceReferenceType) && reference.isForward) {
108
- return true;
109
- }
110
- return false;
111
- }
112
- const references = node.allReferences().filter(referenceToKeep);
113
- for (const reference of references.sort(sortByNodeId)) {
114
- if ((0, base_node_impl_1.getReferenceType)(reference).browseName.toString() === "HasSubtype" && reference.isForward) {
115
- continue;
116
- }
117
- // only output inverse Reference
118
- xw.startElement("Reference");
119
- xw.writeAttribute("ReferenceType", b(xw, (0, base_node_impl_1.getReferenceType)(reference).browseName));
120
- if (!reference.isForward) {
121
- xw.writeAttribute("IsForward", reference.isForward ? "true" : "false");
122
- }
123
- xw.text(n(xw, reference.nodeId));
124
- xw.endElement();
125
- }
126
- xw.endElement();
127
- }
128
- function _dumpLocalizedText(xw, v) {
129
- if (v.locale && v.locale.length) {
130
- xw.startElement("Locale");
131
- xw.text(v.locale);
132
- xw.endElement();
133
- }
134
- xw.startElement("Text");
135
- if (v.text) {
136
- xw.text(v.text);
137
- }
138
- xw.endElement();
139
- }
140
- function _dumpQualifiedName(xw, v) {
141
- const t = translateBrowseName(xw, v);
142
- if (t.name) {
143
- xw.startElement("Name");
144
- xw.text(t.name);
145
- xw.endElement();
146
- }
147
- if (t.namespaceIndex) {
148
- xw.startElement("NamespaceIndex");
149
- xw.text(t.namespaceIndex.toString());
150
- xw.endElement();
151
- }
152
- }
153
- function _dumpXmlElement(xw, v) {
154
- xw.text(v);
155
- }
156
- /*
157
- <uax:ExtensionObject>
158
- <uax:TypeId>
159
- <uax:Identifier>i=339</uax:Identifier>
160
- </uax:TypeId>
161
- <uax:Body>
162
- <BuildInfo xmlns="http://opcfoundation.org/UA/2008/02/Types.xsd">
163
- <ProductUri></ProductUri>
164
- <ManufacturerName></ManufacturerName>
165
- <ProductName></ProductName>
166
- <SoftwareVersion></SoftwareVersion>
167
- <BuildNumber></BuildNumber>
168
- <BuildDate>1900-01-01T00:00:00Z</BuildDate>
169
- </BuildInfo>
170
- </uax:Body>
171
- </uax:ExtensionObject>
172
- */
173
- function _dumpNodeId(xw, v) {
174
- xw.startElement("Identifier");
175
- xw.text(n(xw, v));
176
- xw.endElement();
177
- }
178
- // eslint-disable-next-line complexity
179
- function _dumpVariantValue(xw, dataType, node, value) {
180
- const dataTypeNode = node.addressSpace.findDataType(node.dataType);
181
- if (value === undefined || value === null) {
182
- return;
183
- }
184
- if (dataType === node_opcua_variant_1.DataType.Null) {
185
- return;
186
- }
187
- xw.startElement(node_opcua_variant_1.DataType[dataType]);
188
- const definitionMap = (0, decode_xml_extension_object_1.makeDefinitionMap)(node.addressSpace);
189
- _dumpVariantInnerValue(xw, dataType, dataTypeNode.nodeId, definitionMap, value);
190
- xw.endElement();
191
- }
192
- function _dumpVariantInnerExtensionObject(xw, definitionMap, definition, value) {
193
- for (const field of definition.fields || []) {
194
- const dataTypeNodeId = field.dataType;
195
- const fieldName = field.name;
196
- const lowerFieldName = utils.lowerFirstLetter(fieldName);
197
- const v = value[lowerFieldName];
198
- if (v !== null && v !== undefined) {
199
- if (dataTypeNodeId.namespace === 0 &&
200
- dataTypeNodeId.value === 0 &&
201
- dataTypeNodeId.identifierType === node_opcua_nodeid_1.NodeIdType.NUMERIC) {
202
- // to do ?? shall we do a extension Object here ?
203
- continue; // ns=0;i=0 is reserved
204
- }
205
- const { name, definition } = definitionMap.findDefinition(dataTypeNodeId);
206
- xw.startElement(fieldName);
207
- let fun = (value) => {
208
- /** */
209
- };
210
- if (definition instanceof node_opcua_types_1.StructureDefinition) {
211
- fun = _dumpVariantInnerExtensionObject.bind(null, xw, definitionMap, definition);
212
- }
213
- else if (definition instanceof node_opcua_types_1.EnumDefinition) {
214
- fun = _dumpVariantInnerValueEnum.bind(null, xw, definition);
215
- }
216
- else {
217
- const baseType = definition.dataType;
218
- fun = _dumpVariantInnerValue.bind(null, xw, baseType, dataTypeNodeId, definitionMap);
219
- }
220
- try {
221
- if (field.valueRank === -1) {
222
- fun(v);
223
- }
224
- else {
225
- // array
226
- for (const arrayItem of v) {
227
- xw.startElement(name);
228
- fun(arrayItem);
229
- xw.endElement();
230
- }
231
- }
232
- }
233
- catch (err) {
234
- // eslint-disable-next-line max-depth
235
- if (err instanceof Error) {
236
- errorLog("Error in _dumpVariantExtensionObjectValue_Body !!!", err.message);
237
- }
238
- console.log(name);
239
- console.log(field);
240
- // throw err;
241
- }
242
- xw.endElement();
243
- }
244
- }
245
- }
246
- function _dumpVariantInnerValueEnum(xw, definition, value) {
247
- if (!definition.fields) {
248
- return;
249
- }
250
- const field = definition.fields.find((f) => f.value[1] === value || f.name === value);
251
- xw.text(`${field === null || field === void 0 ? void 0 : field.name}_${field === null || field === void 0 ? void 0 : field.value[1]}`);
252
- }
253
- // eslint-disable-next-line complexity
254
- function _dumpVariantInnerValue(xw, dataType, dataTypeNodeId, definitionMap, value) {
255
- switch (dataType) {
256
- case null:
257
- case node_opcua_variant_1.DataType.Null:
258
- break;
259
- case node_opcua_variant_1.DataType.LocalizedText:
260
- _dumpLocalizedText(xw, value);
261
- break;
262
- case node_opcua_variant_1.DataType.QualifiedName:
263
- _dumpQualifiedName(xw, value);
264
- break;
265
- case node_opcua_variant_1.DataType.NodeId:
266
- _dumpNodeId(xw, value);
267
- break;
268
- case node_opcua_variant_1.DataType.DateTime:
269
- xw.text(value.toISOString());
270
- break;
271
- case node_opcua_variant_1.DataType.Int64:
272
- case node_opcua_variant_1.DataType.UInt64:
273
- xw.text(value[1].toString());
274
- break;
275
- case node_opcua_variant_1.DataType.Boolean:
276
- case node_opcua_variant_1.DataType.SByte:
277
- case node_opcua_variant_1.DataType.Byte:
278
- case node_opcua_variant_1.DataType.Float:
279
- case node_opcua_variant_1.DataType.Double:
280
- case node_opcua_variant_1.DataType.Int16:
281
- case node_opcua_variant_1.DataType.Int32:
282
- case node_opcua_variant_1.DataType.UInt16:
283
- case node_opcua_variant_1.DataType.UInt32:
284
- case node_opcua_variant_1.DataType.String:
285
- xw.text(value.toString());
286
- break;
287
- case node_opcua_variant_1.DataType.ByteString:
288
- {
289
- const base64 = value.toString("base64");
290
- xw.text(base64.length > 80 ? base64.match(/.{0,80}/g).join("\n") : base64);
291
- }
292
- break;
293
- case node_opcua_variant_1.DataType.Guid:
294
- /*
295
- <uax:Guid>
296
- <uax:String>947c29a7-490d-4dc9-adda-1109e3e8fcb7</uax:String>
297
- </uax:Guid>
298
- */
299
- if (value !== undefined && value !== null) {
300
- // xw.writeAttribute("xmlns", "http://opcfoundation.org/UA/2008/02/Types.xsd");
301
- xw.startElement("String");
302
- xw.text(value.toString());
303
- xw.endElement();
304
- }
305
- break;
306
- case node_opcua_variant_1.DataType.ExtensionObject:
307
- _dumpVariantExtensionObjectValue(xw, dataTypeNodeId, definitionMap, value);
308
- break;
309
- case node_opcua_variant_1.DataType.XmlElement:
310
- _dumpXmlElement(xw, value);
311
- break;
312
- case node_opcua_variant_1.DataType.StatusCode:
313
- xw.text(value.value.toString());
314
- break;
315
- default:
316
- errorLog("_dumpVariantInnerValue incomplete " + value + " " + "DataType=" + dataType + "=" + node_opcua_variant_1.DataType[dataType]);
317
- // throw new Error("_dumpVariantInnerValue incomplete " + value + " " + "DataType=" + dataType + "=" + DataType[dataType]);
318
- }
319
- }
320
- /**
321
- *
322
- * @param xw
323
- * @param schema
324
- * @param value
325
- * @private
326
- */
327
- function _dumpVariantExtensionObjectValue_Body(xw, definitionMap, name, definition, value) {
328
- if (value) {
329
- xw.startElement(name);
330
- if (value) {
331
- _dumpVariantInnerExtensionObject(xw, definitionMap, definition, value);
332
- }
333
- xw.endElement();
334
- }
335
- }
336
- function _dumpVariantExtensionObjectValue(xw, dataTypeNodeId, definitionMap, value) {
337
- const { name, definition } = definitionMap.findDefinition(dataTypeNodeId);
338
- // const encodingDefaultXml = (getStructureTypeConstructor(schema.name) as any).encodingDefaultXml;
339
- const encodingDefaultXml = value.schema.encodingDefaultXml;
340
- if (!encodingDefaultXml) {
341
- // throw new Error("Extension Object doesn't provide a XML ");
342
- return;
343
- }
344
- xw.startElement("ExtensionObject");
345
- {
346
- xw.startElement("TypeId");
347
- {
348
- // find HasEncoding node
349
- // xx var encodingDefaultXml = schema.encodingDefaultXml;
350
- xw.startElement("Identifier");
351
- xw.text(n(xw, encodingDefaultXml));
352
- xw.endElement();
353
- }
354
- xw.endElement();
355
- xw.startElement("Body");
356
- _dumpVariantExtensionObjectValue_Body(xw, definitionMap, name, definition, value);
357
- xw.endElement();
358
- }
359
- xw.endElement();
360
- }
361
- function _dumpVariantExtensionObjectValue2(xw, dataTypeNode, value) {
362
- const addressSpace = dataTypeNode.addressSpace;
363
- const definitionMap = (0, decode_xml_extension_object_1.makeDefinitionMap)(addressSpace);
364
- _dumpVariantExtensionObjectValue(xw, dataTypeNode.nodeId, definitionMap, value);
365
- }
366
- // eslint-disable-next-line complexity
367
- function _isDefaultValue(value) {
368
- // detect default value
369
- if (value.arrayType === node_opcua_variant_1.VariantArrayType.Scalar) {
370
- switch (value.dataType) {
371
- case node_opcua_variant_1.DataType.ExtensionObject:
372
- if (!value.value) {
373
- return true;
374
- }
375
- break;
376
- case node_opcua_variant_1.DataType.DateTime:
377
- if (!value.value || value.value.getTime() === node_opcua_basic_types_1.minOPCUADate) {
378
- return true;
379
- }
380
- break;
381
- case node_opcua_variant_1.DataType.ByteString:
382
- if (!value.value || value.value.length === 0) {
383
- return true;
384
- }
385
- break;
386
- case node_opcua_variant_1.DataType.Boolean:
387
- if (!value.value) {
388
- return true;
389
- }
390
- break;
391
- case node_opcua_variant_1.DataType.SByte:
392
- case node_opcua_variant_1.DataType.Byte:
393
- case node_opcua_variant_1.DataType.UInt16:
394
- case node_opcua_variant_1.DataType.UInt32:
395
- case node_opcua_variant_1.DataType.Int16:
396
- case node_opcua_variant_1.DataType.Int32:
397
- case node_opcua_variant_1.DataType.Double:
398
- case node_opcua_variant_1.DataType.Float:
399
- if (value.value === 0 || value.value === null) {
400
- return true;
401
- }
402
- break;
403
- case node_opcua_variant_1.DataType.String:
404
- if (value.value === null || value.value === "") {
405
- return true;
406
- }
407
- break;
408
- case node_opcua_variant_1.DataType.Int64:
409
- case node_opcua_variant_1.DataType.UInt64:
410
- if (0 === coerceInt64ToInt32(value.value)) {
411
- return true;
412
- }
413
- break;
414
- case node_opcua_variant_1.DataType.LocalizedText:
415
- if (!value.value) {
416
- return true;
417
- }
418
- {
419
- const l = value.value;
420
- if (!l.locale && !l.text) {
421
- return true;
422
- }
423
- }
424
- break;
425
- }
426
- return false;
427
- }
428
- else {
429
- if (!value.value || value.value.length === 0) {
430
- return true;
431
- }
432
- return false;
433
- }
434
- }
435
- // eslint-disable-next-line max-statements
436
- function _dumpValue(xw, node, value) {
437
- const addressSpace = node.addressSpace;
438
- // istanbul ignore next
439
- if (value === null || value === undefined) {
440
- return;
441
- }
442
- (0, node_opcua_assert_1.assert)(value instanceof node_opcua_variant_1.Variant);
443
- const dataTypeNode = addressSpace.findNode(node.dataType);
444
- if (!dataTypeNode) {
445
- console.log("Cannot find dataType:", node.dataType);
446
- return;
447
- }
448
- const dataTypeName = dataTypeNode.browseName.name.toString();
449
- const baseDataTypeName = node_opcua_variant_1.DataType[value.dataType];
450
- if (baseDataTypeName === "Null") {
451
- return;
452
- }
453
- (0, node_opcua_assert_1.assert)(typeof baseDataTypeName === "string");
454
- // determine if dataTypeName is a ExtensionObject
455
- const isExtensionObject = value.dataType === node_opcua_variant_1.DataType.ExtensionObject;
456
- if (_isDefaultValue(value)) {
457
- return;
458
- }
459
- xw.startElement("Value");
460
- if (isExtensionObject) {
461
- const dataTypeNode = addressSpace.findDataType(node.dataType);
462
- if (!dataTypeNode) {
463
- throw new Error("Cannot find data type " + node.dataType.toString());
464
- }
465
- const encodeXml = _dumpVariantExtensionObjectValue2.bind(null, xw, dataTypeNode);
466
- if (value.arrayType === node_opcua_variant_1.VariantArrayType.Array) {
467
- xw.startElement("ListOf" + baseDataTypeName);
468
- value.value.forEach(encodeXml);
469
- xw.endElement();
470
- }
471
- else if (value.arrayType === node_opcua_variant_1.VariantArrayType.Scalar) {
472
- encodeXml(value.value);
473
- }
474
- else {
475
- errorLog(node.toString());
476
- errorLog("_dumpValue : unsupported case , Matrix of ExtensionObjects");
477
- // throw new Error("Unsupported case");
478
- }
479
- }
480
- else {
481
- const encodeXml = _dumpVariantValue.bind(null, xw, value.dataType, node);
482
- if (value.arrayType === node_opcua_variant_1.VariantArrayType.Matrix) {
483
- // console.log("Warning _dumpValue : Matrix not supported yet");
484
- xw.startElement("ListOf" + dataTypeName);
485
- xw.writeAttribute("xmlns", "http://opcfoundation.org/UA/2008/02/Types.xsd");
486
- value.value.forEach(encodeXml);
487
- xw.endElement();
488
- }
489
- else if (value.arrayType === node_opcua_variant_1.VariantArrayType.Array) {
490
- xw.startElement("ListOf" + dataTypeName);
491
- xw.writeAttribute("xmlns", "http://opcfoundation.org/UA/2008/02/Types.xsd");
492
- value.value.forEach(encodeXml);
493
- xw.endElement();
494
- }
495
- else if (value.arrayType === node_opcua_variant_1.VariantArrayType.Scalar) {
496
- encodeXml(value.value);
497
- }
498
- else {
499
- errorLog(node.toString());
500
- errorLog("_dumpValue : unsupported case , Matrix");
501
- // xx throw new Error("Unsupported case");
502
- }
503
- }
504
- xw.endElement();
505
- }
506
- function _dumpArrayDimensionsAttribute(xw, node) {
507
- if (node.arrayDimensions) {
508
- if (node.valueRank === -1 || (node.arrayDimensions.length === 1 && node.arrayDimensions[0] === 0)) {
509
- return;
510
- }
511
- xw.writeAttribute("ArrayDimensions", node.arrayDimensions.join(","));
512
- }
513
- }
514
- function visitUANode(node, options, forward) {
515
- (0, node_opcua_assert_1.assert)(typeof forward === "boolean");
516
- const addressSpace = node.addressSpace;
517
- options.elements = options.elements || [];
518
- options.index_el = options.index_el || {};
519
- // visit references
520
- function process_reference(reference) {
521
- // only backward or forward references
522
- if (reference.isForward !== forward) {
523
- return;
524
- }
525
- if (reference.nodeId.namespace === 0) {
526
- return; // skip OPCUA namespace
527
- }
528
- const k = _hash(reference);
529
- if (!options.index_el[k]) {
530
- options.index_el[k] = 1;
531
- const o = addressSpace.findNode(k);
532
- if (o) {
533
- visitUANode(o, options, forward);
534
- }
535
- }
536
- }
537
- node.ownReferences().forEach(process_reference);
538
- options.elements.push(node);
539
- return node;
540
- }
541
- function dumpNodeInXml(xw, node) {
542
- return node.dumpXML(xw);
543
- }
544
- function dumpReferencedNodes(xw, node, forward) {
545
- const addressSpace = node.addressSpace;
546
- if (!forward) {
547
- {
548
- const r = node.findReferencesEx("HasTypeDefinition");
549
- if (r && r.length) {
550
- (0, node_opcua_assert_1.assert)(r.length === 1);
551
- const typeDefinitionObj = reference_impl_1.ReferenceImpl.resolveReferenceNode(addressSpace, r[0]);
552
- if (!typeDefinitionObj) {
553
- warningLog(node.toString());
554
- warningLog("dumpReferencedNodes: Warning : " + node.browseName.toString() + " unknown typeDefinition, ", r[0].toString());
555
- }
556
- else {
557
- (0, node_opcua_assert_1.assert)(typeDefinitionObj instanceof base_node_impl_1.BaseNodeImpl);
558
- if (typeDefinitionObj.nodeId.namespace === node.nodeId.namespace) {
559
- // only output node if it is on the same namespace
560
- if (!xw.visitedNode[_hash(typeDefinitionObj)]) {
561
- dumpNodeInXml(xw, typeDefinitionObj);
562
- }
563
- }
564
- }
565
- }
566
- }
567
- //
568
- {
569
- const r = node.findReferencesEx("HasSubtype", node_opcua_data_model_1.BrowseDirection.Inverse);
570
- if (r && r.length) {
571
- const subTypeOf = reference_impl_1.ReferenceImpl.resolveReferenceNode(addressSpace, r[0]);
572
- (0, node_opcua_assert_1.assert)(r.length === 1);
573
- if (subTypeOf.nodeId.namespace === node.nodeId.namespace) {
574
- // only output node if it is on the same namespace
575
- if (!xw.visitedNode[_hash(subTypeOf)]) {
576
- dumpNodeInXml(xw, subTypeOf);
577
- }
578
- }
579
- }
580
- }
581
- }
582
- else {
583
- const r = node.findReferencesEx("Aggregates", node_opcua_data_model_1.BrowseDirection.Forward);
584
- for (const reference of r) {
585
- const nodeChild = reference_impl_1.ReferenceImpl.resolveReferenceNode(addressSpace, reference);
586
- (0, node_opcua_assert_1.assert)(nodeChild instanceof base_node_impl_1.BaseNodeImpl);
587
- if (nodeChild.nodeId.namespace === node.nodeId.namespace) {
588
- if (!xw.visitedNode[_hash(nodeChild)]) {
589
- console.log(node.nodeId.toString(), " dumping child ", nodeChild.browseName.toString(), nodeChild.nodeId.toString());
590
- dumpNodeInXml(xw, nodeChild);
591
- }
592
- }
593
- }
594
- }
595
- }
596
- const currentReadFlag = (0, node_opcua_data_model_1.makeAccessLevelFlag)("CurrentRead");
597
- function dumpCommonAttributes(xw, node) {
598
- xw.writeAttribute("NodeId", n(xw, node.nodeId));
599
- xw.writeAttribute("BrowseName", b(xw, node.browseName));
600
- if (Object.prototype.hasOwnProperty.call(node, "symbolicName")) {
601
- xw.writeAttribute("SymbolicName", node.symbolicName);
602
- }
603
- if (Object.prototype.hasOwnProperty.call(node, "isAbstract")) {
604
- if (node.isAbstract) {
605
- xw.writeAttribute("IsAbstract", node.isAbstract ? "true" : "false");
606
- }
607
- }
608
- if (Object.prototype.hasOwnProperty.call(node, "accessLevel")) {
609
- // CurrentRead is by default
610
- if (node.accessLevel !== currentReadFlag) {
611
- xw.writeAttribute("AccessLevel", node.accessLevel.toString());
612
- }
613
- }
614
- }
615
- function dumpCommonElements(xw, node) {
616
- _dumpDisplayName(xw, node);
617
- _dumpDescription(xw, node);
618
- _dumpReferences(xw, node);
619
- }
620
- function coerceInt64ToInt32(int64) {
621
- if (typeof int64 === "number") {
622
- return int64;
623
- }
624
- if (int64[0] === 4294967295 && int64[1] === 4294967295) {
625
- return 0xffffffff;
626
- }
627
- if (int64[0] !== 0) {
628
- debugLog("coerceInt64ToInt32 , loosing high word in conversion");
629
- }
630
- return int64[1];
631
- }
632
- function _dumpEnumDefinition(xw, enumDefinition) {
633
- enumDefinition.fields = enumDefinition.fields || [];
634
- for (const defItem of enumDefinition.fields) {
635
- xw.startElement("Field");
636
- xw.writeAttribute("Name", defItem.name);
637
- if (!utils.isNullOrUndefined(defItem.value)) {
638
- xw.writeAttribute("Value", coerceInt64ToInt32(defItem.value));
639
- }
640
- _dumpDescription(xw, defItem);
641
- xw.endElement();
642
- }
643
- }
644
- function _dumpStructureDefinition(xw, structureDefinition, baseStructureDefinition) {
645
- var _a;
646
- /*
647
- * note: baseDataType and defaultEncodingId are implicit and not stored in the XML file ??
648
- *
649
- */
650
- const baseDataType = structureDefinition.baseDataType;
651
- const defaultEncodingId = structureDefinition.defaultEncodingId;
652
- // do not repeat elements that are already defined in base structure in the xml ouput!
653
- const fields = structureDefinition.fields || [];
654
- const nbFieldsInBase = baseStructureDefinition ? ((_a = baseStructureDefinition.fields) === null || _a === void 0 ? void 0 : _a.length) || 0 : 0;
655
- for (let index = nbFieldsInBase; index < fields.length; index++) {
656
- const defItem = fields[index];
657
- xw.startElement("Field");
658
- xw.writeAttribute("Name", defItem.name);
659
- if (defItem.arrayDimensions) {
660
- xw.writeAttribute("ArrayDimensions", defItem.arrayDimensions.map((x) => x.toString()).join(","));
661
- }
662
- if (defItem.valueRank !== undefined && defItem.valueRank !== -1) {
663
- xw.writeAttribute("ValueRank", defItem.valueRank);
664
- }
665
- if (defItem.isOptional /* && defItem.isOptional !== false */) {
666
- xw.writeAttribute("IsOptional", defItem.isOptional.toString());
667
- }
668
- if (defItem.maxStringLength !== undefined && defItem.maxStringLength !== 0) {
669
- xw.writeAttribute("MaxStringLength", defItem.maxStringLength);
670
- }
671
- // todo : SymbolicName ( see AutoId )
672
- if (defItem.dataType) {
673
- // todo : namespace translation !
674
- xw.writeAttribute("DataType", n(xw, defItem.dataType));
675
- }
676
- _dumpDescription(xw, defItem);
677
- xw.endElement();
678
- }
679
- }
680
- function _dumpEncodings(xw, uaDataType) {
681
- const encodings = uaDataType.findReferencesExAsObject("HasEncoding", node_opcua_data_model_1.BrowseDirection.Forward);
682
- for (const encoding of encodings) {
683
- if (encoding.nodeClass !== node_opcua_data_model_1.NodeClass.Object) {
684
- continue;
685
- }
686
- _dumpUAObject(xw, encoding);
687
- }
688
- }
689
- function _dumpUADataTypeDefinition(xw, uaDataType) {
690
- const uaDataTypeBase = uaDataType.subtypeOfObj;
691
- if (uaDataType.isEnumeration()) {
692
- xw.startElement("Definition");
693
- xw.writeAttribute("Name", b(xw, uaDataType.browseName));
694
- _dumpEnumDefinition(xw, uaDataType.getEnumDefinition());
695
- xw.endElement();
696
- return;
697
- }
698
- if (uaDataType.isStructure()) {
699
- const definition = uaDataType.getStructureDefinition();
700
- const baseDefinition = uaDataTypeBase ? uaDataTypeBase.getStructureDefinition() : null;
701
- xw.startElement("Definition");
702
- xw.writeAttribute("Name", b(xw, uaDataType.browseName));
703
- if (definition.structureType === node_opcua_types_1.StructureType.Union) {
704
- xw.writeAttribute("IsUnion", "true");
705
- }
706
- _dumpStructureDefinition(xw, definition, baseDefinition);
707
- xw.endElement();
708
- return;
709
- }
710
- }
711
- function dumpUADataType(xw, node) {
712
- _markAsVisited(xw, node);
713
- xw.startElement("UADataType");
714
- xw.writeAttribute("NodeId", n(xw, node.nodeId));
715
- xw.writeAttribute("BrowseName", b(xw, node.browseName));
716
- if (node.symbolicName !== node.browseName.name) {
717
- xw.writeAttribute("SymbolicName", node.symbolicName);
718
- }
719
- if (node.isAbstract) {
720
- xw.writeAttribute("IsAbstract", node.isAbstract ? "true" : "false");
721
- }
722
- _dumpDisplayName(xw, node);
723
- _dumpReferences(xw, node);
724
- _dumpUADataTypeDefinition(xw, node);
725
- xw.endElement();
726
- _dumpEncodings(xw, node);
727
- dumpAggregates(xw, node);
728
- }
729
- function _markAsVisited(xw, node) {
730
- xw.visitedNode = xw.visitedNode || {};
731
- (0, node_opcua_assert_1.assert)(!xw.visitedNode[_hash(node)]);
732
- xw.visitedNode[_hash(node)] = 1;
733
- }
734
- function dumpUAVariable(xw, node) {
735
- _markAsVisited(xw, node);
736
- dumpReferencedNodes(xw, node, false);
737
- const addressSpace = node.addressSpace;
738
- xw.startElement("UAVariable");
739
- {
740
- // attributes
741
- dumpCommonAttributes(xw, node);
742
- if (node.valueRank !== -1) {
743
- // -1 = Scalar
744
- xw.writeAttribute("ValueRank", node.valueRank);
745
- }
746
- _dumpArrayDimensionsAttribute(xw, node);
747
- const dataTypeNode = addressSpace.findNode(node.dataType);
748
- if (dataTypeNode) {
749
- // verify that data Type is in alias
750
- // xx const dataTypeName = dataTypeNode.browseName.toString();
751
- const dataTypeName = b(xw, resolveDataTypeName(addressSpace, dataTypeNode.nodeId));
752
- xw.writeAttribute("DataType", dataTypeName);
753
- }
754
- }
755
- {
756
- // sub elements
757
- dumpCommonElements(xw, node);
758
- const value = node.$dataValue.value;
759
- if (value) {
760
- _dumpValue(xw, node, value);
761
- }
762
- }
763
- xw.endElement();
764
- dumpAggregates(xw, node);
765
- }
766
- function dumpUAVariableType(xw, node) {
767
- xw.visitedNode = xw.visitedNode || {};
768
- (0, node_opcua_assert_1.assert)(!xw.visitedNode[_hash(node)]);
769
- xw.visitedNode[_hash(node)] = 1;
770
- dumpReferencedNodes(xw, node, false);
771
- const addressSpace = node.addressSpace;
772
- xw.startElement("UAVariableType");
773
- {
774
- // attributes
775
- dumpCommonAttributes(xw, node);
776
- if (node.valueRank !== -1) {
777
- xw.writeAttribute("ValueRank", node.valueRank);
778
- }
779
- const dataTypeNode = addressSpace.findNode(node.dataType);
780
- if (!dataTypeNode) {
781
- // throw new Error(" cannot find datatype " + node.dataType);
782
- console.log(" cannot find datatype " +
783
- node.dataType +
784
- " for node " +
785
- node.browseName.toString() +
786
- " id =" +
787
- node.nodeId.toString());
788
- }
789
- else {
790
- const dataTypeName = b(xw, resolveDataTypeName(addressSpace, dataTypeNode.nodeId));
791
- xw.writeAttribute("DataType", dataTypeName);
792
- }
793
- }
794
- {
795
- _dumpArrayDimensionsAttribute(xw, node);
796
- // sub elements
797
- dumpCommonElements(xw, node);
798
- const value = node.value;
799
- if (value) {
800
- _dumpValue(xw, node, value);
801
- }
802
- }
803
- xw.endElement();
804
- dumpAggregates(xw, node);
805
- }
806
- function dumpUAObject(xw, node) {
807
- xw.writeComment("Object - " + b(xw, node.browseName) + " {{{{ ");
808
- _dumpUAObject(xw, node);
809
- xw.writeComment("Object - " + b(xw, node.browseName) + " }}}} ");
810
- }
811
- function _dumpUAObject(xw, node) {
812
- xw.visitedNode = xw.visitedNode || {};
813
- (0, node_opcua_assert_1.assert)(!xw.visitedNode[_hash(node)]);
814
- xw.visitedNode[_hash(node)] = 1;
815
- // dump SubTypeOf and HasTypeDefinition
816
- dumpReferencedNodes(xw, node, false);
817
- xw.startElement("UAObject");
818
- dumpCommonAttributes(xw, node);
819
- dumpCommonElements(xw, node);
820
- xw.endElement();
821
- // dump aggregates nodes ( Properties / components )
822
- dumpAggregates(xw, node);
823
- dumpElementInFolder(xw, node);
824
- }
825
- function dumpElementInFolder(xw, node) {
826
- const aggregates = node
827
- .getFolderElements()
828
- .sort((x, y) => (x.browseName.name.toString() > y.browseName.name.toString() ? 1 : -1));
829
- for (const aggregate of aggregates.sort(sortByNodeId)) {
830
- // do not export node that do not belong to our namespace
831
- if (node.nodeId.namespace !== aggregate.nodeId.namespace) {
832
- return;
833
- }
834
- if (!xw.visitedNode[_hash(aggregate)]) {
835
- aggregate.dumpXML(xw);
836
- }
837
- }
838
- }
839
- function dumpAggregates(xw, node) {
840
- // Xx xw.writeComment("Aggregates {{ ");
841
- const aggregates = node
842
- .getAggregates()
843
- .sort((x, y) => (x.browseName.name.toString() > y.browseName.name.toString() ? 1 : -1));
844
- for (const aggregate of aggregates.sort(sortByNodeId)) {
845
- // do not export node that do not belong to our namespace
846
- if (node.nodeId.namespace !== aggregate.nodeId.namespace) {
847
- return;
848
- }
849
- if (!xw.visitedNode[_hash(aggregate)]) {
850
- aggregate.dumpXML(xw);
851
- }
852
- }
853
- // Xx xw.writeComment("Aggregates }} ");
854
- }
855
- function dumpUAObjectType(xw, node) {
856
- (0, node_opcua_assert_1.assert)(node instanceof ua_object_type_impl_1.UAObjectTypeImpl);
857
- xw.writeComment("ObjectType - " + b(xw, node.browseName) + " {{{{ ");
858
- _markAsVisited(xw, node);
859
- // dump SubtypeOf and HasTypeDefinition
860
- dumpReferencedNodes(xw, node, false);
861
- xw.startElement("UAObjectType");
862
- dumpCommonAttributes(xw, node);
863
- dumpCommonElements(xw, node);
864
- xw.endElement();
865
- dumpAggregates(xw, node);
866
- xw.writeComment("ObjectType - " + b(xw, node.browseName) + " }}}}");
867
- }
868
- function dumpUAMethod(xw, node) {
869
- _markAsVisited(xw, node);
870
- dumpReferencedNodes(xw, node, false);
871
- xw.startElement("UAMethod");
872
- dumpCommonAttributes(xw, node);
873
- if (node.methodDeclarationId) {
874
- xw.writeAttribute("MethodDeclarationId", n(xw, node.methodDeclarationId));
875
- }
876
- dumpCommonElements(xw, node);
877
- xw.endElement();
878
- dumpAggregates(xw, node);
879
- }
880
- function resolveDataTypeName(addressSpace, dataType) {
881
- let dataTypeNode = null;
882
- // istanbul ignore next
883
- if (typeof dataType === "string") {
884
- dataTypeNode = addressSpace.findDataType(dataType);
885
- }
886
- else {
887
- (0, node_opcua_assert_1.assert)(dataType instanceof node_opcua_nodeid_1.NodeId);
888
- const o = addressSpace.findNode(dataType.toString());
889
- dataTypeNode = o ? o : null;
890
- }
891
- if (!dataTypeNode) {
892
- errorLog("resolveDataTypeName: warning cannot find DataType " + dataType.toString());
893
- return new node_opcua_data_model_1.QualifiedName({ name: "", namespaceIndex: 0 });
894
- }
895
- return dataTypeNode.browseName;
896
- }
897
- function buildUpAliases(node, xw, options) {
898
- const addressSpace = node.addressSpace;
899
- options.aliases = options.aliases || {};
900
- options.aliases_visited = options.aliases_visited || {};
901
- const k = _hash(node);
902
- // istanbul ignore next
903
- if (options.aliases_visited[k]) {
904
- return;
905
- }
906
- options.aliases_visited[k] = 1;
907
- // put datatype into aliases list
908
- if (node.nodeClass === node_opcua_data_model_1.NodeClass.Variable || node.nodeClass === node_opcua_data_model_1.NodeClass.VariableType) {
909
- const nodeV = node;
910
- if (nodeV.dataType && nodeV.dataType.namespace === 0 && nodeV.dataType.value !== 0) {
911
- // name
912
- const dataTypeName = b(xw, resolveDataTypeName(addressSpace, nodeV.dataType));
913
- if (dataTypeName) {
914
- if (!options.aliases[dataTypeName]) {
915
- options.aliases[dataTypeName] = n(xw, nodeV.dataType);
916
- }
917
- }
918
- }
919
- if (nodeV.dataType && nodeV.dataType.namespace !== 0 && nodeV.dataType.value !== 0) {
920
- // name
921
- const dataTypeName = b(xw, resolveDataTypeName(addressSpace, nodeV.dataType));
922
- if (dataTypeName) {
923
- if (!options.aliases[dataTypeName]) {
924
- options.aliases[dataTypeName] = n(xw, nodeV.dataType);
925
- }
926
- }
927
- }
928
- }
929
- function collectReferenceNameInAlias(reference) {
930
- // reference.referenceType
931
- const key = b(xw, (0, base_node_impl_1.getReferenceType)(reference).browseName);
932
- if (!options.aliases.key) {
933
- if (reference.referenceType.namespace === 0) {
934
- options.aliases[key] = reference.referenceType.toString().replace("ns=0;", "");
935
- }
936
- else {
937
- options.aliases[key] = n(xw, reference.referenceType);
938
- }
939
- }
940
- }
941
- node.allReferences().forEach(collectReferenceNameInAlias);
942
- }
943
- function writeAliases(xw, aliases) {
944
- xw.startElement("Aliases");
945
- if (aliases) {
946
- const keys = Object.keys(aliases).sort();
947
- for (const key of keys) {
948
- xw.startElement("Alias");
949
- xw.writeAttribute("Alias", key);
950
- xw.text(aliases[key].toString().replace(/ns=0;/, ""));
951
- xw.endElement();
952
- }
953
- }
954
- xw.endElement();
955
- }
956
- function constructNamespaceTranslationTable(dependency) {
957
- const translationTable = {};
958
- for (let i = 0; i < dependency.length; i++) {
959
- translationTable[dependency[i].index] = i;
960
- }
961
- return translationTable;
962
- }
963
- function dumpReferenceType(xw, referenceType) {
964
- _markAsVisited(xw, referenceType);
965
- xw.startElement("UAReferenceType");
966
- dumpCommonAttributes(xw, referenceType);
967
- dumpCommonElements(xw, referenceType);
968
- if (referenceType.inverseName /* LocalizedText*/) {
969
- xw.startElement("InverseName");
970
- xw.text(referenceType.inverseName.text || "");
971
- xw.endElement();
972
- }
973
- xw.endElement();
974
- }
975
- function sortByBrowseName(x, y) {
976
- const x_str = x.browseName.toString();
977
- const y_str = y.browseName.toString();
978
- if (x_str > y_str) {
979
- return -1;
980
- }
981
- else if (x_str < y_str) {
982
- return 1;
983
- }
984
- return 0;
985
- }
986
- function sortByNodeId(a, b) {
987
- return a.nodeId.toString() < b.nodeId.toString() ? -1 : 1;
988
- }
989
- function dumpXml(node, options) {
990
- const namespace = node.namespace;
991
- // make a first visit so that we determine which node to output and in which order
992
- const nodesToVisit = {};
993
- const dependency = (0, construct_namespace_dependency_1.constructNamespaceDependency)(namespace);
994
- const translationTable = constructNamespaceTranslationTable(dependency);
995
- const xw = new XMLWriter(true);
996
- xw.translationTable = translationTable;
997
- visitUANode(node, nodesToVisit, false);
998
- xw.startDocument({ encoding: "utf-8" });
999
- xw.startElement("UANodeSet");
1000
- xw.writeAttribute("xmlns:xs", "http://www.w3.org/2001/XMLSchema-instance");
1001
- xw.writeAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
1002
- xw.writeAttribute("Version", "1.02");
1003
- xw.writeAttribute("LastModified", new Date().toISOString());
1004
- xw.writeAttribute("xmlns", "http://opcfoundation.org/UA/2011/03/UANodeSet.xsd");
1005
- buildUpAliases(node, xw, nodesToVisit);
1006
- writeAliases(xw, nodesToVisit.aliases);
1007
- for (const el of nodesToVisit.elements) {
1008
- el.dumpXML(xw);
1009
- }
1010
- xw.endElement();
1011
- xw.endDocument();
1012
- return xw.toString();
1013
- }
1014
- exports.dumpXml = dumpXml;
1015
- ua_method_impl_1.UAMethodImpl.prototype.dumpXML = function (xw) {
1016
- dumpUAMethod(xw, this);
1017
- };
1018
- ua_object_impl_1.UAObjectImpl.prototype.dumpXML = function (xw) {
1019
- dumpUAObject(xw, this);
1020
- };
1021
- ua_variable_impl_1.UAVariableImpl.prototype.dumpXML = function (xw) {
1022
- dumpUAVariable(xw, this);
1023
- };
1024
- ua_variable_type_impl_1.UAVariableTypeImpl.prototype.dumpXML = function (xw) {
1025
- dumpUAVariableType(xw, this);
1026
- };
1027
- ua_reference_type_impl_1.UAReferenceTypeImpl.prototype.dumpXML = function (xw) {
1028
- dumpReferenceType(xw, this);
1029
- };
1030
- ua_object_type_impl_1.UAObjectTypeImpl.prototype.dumpXML = function (xw) {
1031
- dumpUAObjectType(xw, this);
1032
- };
1033
- ua_data_type_impl_1.UADataTypeImpl.prototype.dumpXML = function (xw) {
1034
- dumpUADataType(xw, this);
1035
- };
1036
- // eslint-disable-next-line max-statements
1037
- namespace_impl_1.NamespaceImpl.prototype.toNodeset2XML = function () {
1038
- const dependency = (0, construct_namespace_dependency_1.constructNamespaceDependency)(this);
1039
- const translationTable = constructNamespaceTranslationTable(dependency);
1040
- const xw = new XMLWriter(true);
1041
- xw.translationTable = translationTable;
1042
- xw.startDocument({ encoding: "utf-8", version: "1.0" });
1043
- xw.startElement("UANodeSet");
1044
- xw.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
1045
- xw.writeAttribute("xmlns:uax", "http://opcfoundation.org/UA/2008/02/Types.xsd");
1046
- xw.writeAttribute("xmlns", "http://opcfoundation.org/UA/2011/03/UANodeSet.xsd");
1047
- // xx xw.writeAttribute("Version", "1.02");
1048
- // xx xw.writeAttribute("LastModified", (new Date()).toISOString());
1049
- // ------------- INamespace Uris
1050
- xw.startElement("NamespaceUris");
1051
- // xx const namespaceArray = namespace.addressSpace.getNamespaceArray();
1052
- for (const depend of dependency) {
1053
- if (depend.index === 0) {
1054
- continue; // ignore namespace 0
1055
- }
1056
- xw.startElement("Uri");
1057
- xw.text(depend.namespaceUri);
1058
- xw.endElement();
1059
- }
1060
- xw.endElement();
1061
- // ------------- INamespace Uris
1062
- xw.startElement("Models");
1063
- {
1064
- xw.startElement("Model");
1065
- xw.writeAttribute("ModelUri", this.namespaceUri);
1066
- xw.writeAttribute("Version", this.version);
1067
- xw.writeAttribute("PublicationDate", this.publicationDate.toISOString());
1068
- for (const depend of dependency) {
1069
- if (depend.index === this.index) {
1070
- continue; // ignore our namespace 0
1071
- }
1072
- xw.startElement("RequiredModel");
1073
- xw.writeAttribute("ModelUri", depend.namespaceUri);
1074
- xw.writeAttribute("Version", depend.version);
1075
- xw.writeAttribute("PublicationDate", depend.publicationDate.toISOString());
1076
- xw.endElement();
1077
- }
1078
- xw.endElement();
1079
- }
1080
- xw.endElement();
1081
- const s = {};
1082
- for (const node of this.nodeIterator()) {
1083
- buildUpAliases(node, xw, s);
1084
- }
1085
- writeAliases(xw, s.aliases);
1086
- xw.visitedNode = {};
1087
- // -------------- writeReferences
1088
- xw.writeComment("ReferenceTypes");
1089
- const referenceTypes = [...this._referenceTypeIterator()].sort(sortByBrowseName);
1090
- for (const referenceType of referenceTypes) {
1091
- dumpReferenceType(xw, referenceType);
1092
- }
1093
- // -------------- Dictionaries
1094
- const addressSpace = this.addressSpace;
1095
- const opcBinaryTypeSystem = addressSpace.findNode("OPCBinarySchema_TypeSystem");
1096
- if (opcBinaryTypeSystem) {
1097
- // let find all DataType dictionary node corresponding to a given namespace
1098
- // (have DataTypeDictionaryType)
1099
- const nodeToBrowse = new node_opcua_types_1.BrowseDescription({
1100
- browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
1101
- includeSubtypes: false,
1102
- nodeClassMask: (0, node_opcua_data_model_1.makeNodeClassMask)("Variable"),
1103
- nodeId: opcBinaryTypeSystem.nodeId,
1104
- referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasComponent"),
1105
- resultMask: (0, node_opcua_data_model_1.makeResultMask)("ReferenceType | IsForward | BrowseName | NodeClass | TypeDefinition")
1106
- });
1107
- const result = opcBinaryTypeSystem.browseNode(nodeToBrowse).filter((r) => r.nodeId.namespace === this.index);
1108
- (0, node_opcua_assert_1.assert)(result.length <= 1);
1109
- if (result.length === 1) {
1110
- xw.writeComment("DataSystem");
1111
- const dataSystemType = addressSpace.findNode(result[0].nodeId);
1112
- dumpNodeInXml(xw, dataSystemType);
1113
- }
1114
- }
1115
- // -------------- DataTypes
1116
- const dataTypes = [...this._dataTypeIterator()].sort(sortByBrowseName);
1117
- if (dataTypes.length) {
1118
- xw.writeComment("DataTypes");
1119
- // xx xw.writeComment(" "+ objectTypes.map(x=>x.browseName.name.toString()).join(" "));
1120
- for (const dataType of dataTypes.sort(sortByNodeId)) {
1121
- if (!xw.visitedNode[_hash(dataType)]) {
1122
- dumpNodeInXml(xw, dataType);
1123
- }
1124
- }
1125
- }
1126
- // -------------- ObjectTypes
1127
- xw.writeComment("ObjectTypes");
1128
- const objectTypes = [...this._objectTypeIterator()].sort(sortByBrowseName);
1129
- // xx xw.writeComment(" "+ objectTypes.map(x=>x.browseName.name.toString()).join(" "));
1130
- for (const objectType of objectTypes.sort(sortByNodeId)) {
1131
- if (!xw.visitedNode[_hash(objectType)]) {
1132
- dumpNodeInXml(xw, objectType);
1133
- }
1134
- }
1135
- // -------------- VariableTypes
1136
- xw.writeComment("VariableTypes");
1137
- const variableTypes = [...this._variableTypeIterator()].sort(sortByBrowseName);
1138
- // xx xw.writeComment("ObjectTypes "+ variableTypes.map(x=>x.browseName.name.toString()).join(" "));
1139
- for (const variableType of variableTypes.sort(sortByNodeId)) {
1140
- if (!xw.visitedNode[_hash(variableType)]) {
1141
- dumpNodeInXml(xw, variableType);
1142
- }
1143
- }
1144
- // -------------- Any thing else
1145
- xw.writeComment("Other Nodes");
1146
- const nodes = [...this.nodeIterator()].sort(sortByBrowseName);
1147
- for (const node of nodes.sort(sortByNodeId)) {
1148
- if (!xw.visitedNode[_hash(node)]) {
1149
- dumpNodeInXml(xw, node);
1150
- }
1151
- }
1152
- xw.endElement();
1153
- xw.endDocument();
1154
- return xw.toString();
1155
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dumpXml = void 0;
4
+ /**
5
+ * @module node-opcua-address-space
6
+ */
7
+ // produce nodeset xml files
8
+ const node_opcua_assert_1 = require("node-opcua-assert");
9
+ const node_opcua_debug_1 = require("node-opcua-debug");
10
+ const node_opcua_data_model_1 = require("node-opcua-data-model");
11
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
12
+ const utils = require("node-opcua-utils");
13
+ const node_opcua_variant_1 = require("node-opcua-variant");
14
+ const node_opcua_basic_types_1 = require("node-opcua-basic-types");
15
+ const node_opcua_types_1 = require("node-opcua-types");
16
+ const reference_impl_1 = require("../reference_impl");
17
+ const base_node_impl_1 = require("../base_node_impl");
18
+ const ua_reference_type_impl_1 = require("../ua_reference_type_impl");
19
+ const ua_object_type_impl_1 = require("../ua_object_type_impl");
20
+ const ua_variable_impl_1 = require("../ua_variable_impl");
21
+ const ua_object_impl_1 = require("../ua_object_impl");
22
+ const namespace_impl_1 = require("../namespace_impl");
23
+ const ua_method_impl_1 = require("../ua_method_impl");
24
+ const ua_data_type_impl_1 = require("../ua_data_type_impl");
25
+ const ua_variable_type_impl_1 = require("../ua_variable_type_impl");
26
+ const decode_xml_extension_object_1 = require("../../source/loader/decode_xml_extension_object");
27
+ const construct_namespace_dependency_1 = require("./construct_namespace_dependency");
28
+ // tslint:disable:no-var-requires
29
+ const XMLWriter = require("xml-writer");
30
+ const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
31
+ const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
32
+ const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
33
+ function _hash(node) {
34
+ return node.nodeId.toString();
35
+ }
36
+ function _dumpDisplayName(xw, node) {
37
+ if (node.displayName && node.displayName[0]) {
38
+ xw.startElement("DisplayName").text(node.displayName[0].text).endElement();
39
+ }
40
+ }
41
+ function _dumpDescription(xw, node) {
42
+ if (node.description && node.description.text && node.description.text.length) {
43
+ let desc = node.description.text;
44
+ desc = desc || "";
45
+ xw.startElement("Description").text(desc).endElement();
46
+ }
47
+ }
48
+ function translateNodeId(xw, nodeId) {
49
+ (0, node_opcua_assert_1.assert)(nodeId instanceof node_opcua_nodeid_1.NodeId);
50
+ const nn = xw.translationTable[nodeId.namespace];
51
+ const translatedNode = new node_opcua_nodeid_1.NodeId(nodeId.identifierType, nodeId.value, nn);
52
+ return translatedNode;
53
+ }
54
+ function n(xw, nodeId) {
55
+ return translateNodeId(xw, nodeId).toString().replace("ns=0;", "");
56
+ }
57
+ function translateBrowseName(xw, browseName) {
58
+ (0, node_opcua_assert_1.assert)(browseName instanceof node_opcua_data_model_1.QualifiedName);
59
+ const nn = xw.translationTable[browseName.namespaceIndex];
60
+ const translatedBrowseName = new node_opcua_data_model_1.QualifiedName({ namespaceIndex: nn, name: browseName.name });
61
+ return translatedBrowseName;
62
+ }
63
+ function b(xw, browseName) {
64
+ return translateBrowseName(xw, browseName).toString().replace("ns=0;", "");
65
+ }
66
+ function _dumpReferences(xw, node) {
67
+ xw.startElement("References");
68
+ const addressSpace = node.addressSpace;
69
+ const aggregateReferenceType = addressSpace.findReferenceType("Aggregates");
70
+ const hasChildReferenceType = addressSpace.findReferenceType("HasChild");
71
+ const hasSubtypeReferenceType = addressSpace.findReferenceType("HasSubtype");
72
+ const hasTypeDefinitionReferenceType = addressSpace.findReferenceType("HasTypeDefinition");
73
+ const nonHierarchicalReferencesType = addressSpace.findReferenceType("NonHierarchicalReferences");
74
+ const organizesReferencesType = addressSpace.findReferenceType("Organizes");
75
+ const connectsToReferenceType = addressSpace.findReferenceType("ConnectsTo");
76
+ const hasEventSourceReferenceType = addressSpace.findReferenceType("HasEventSource");
77
+ function referenceToKeep(reference) {
78
+ const referenceType = reference._referenceType;
79
+ // get the direct backward reference to a external namespace
80
+ if (referenceType.isSupertypeOf(aggregateReferenceType) && !reference.isForward) {
81
+ if (reference.nodeId.namespace !== node.nodeId.namespace) {
82
+ // todo: may be check that reference.nodeId.namespace is one of the namespace
83
+ // on which our namespace is build and not a derived one !
84
+ // xx console.log("xxxxxxxxxxxxxx Keeping => ", referenceType.toString(), reference.node?.nodeId.toString());
85
+ return true;
86
+ }
87
+ }
88
+ // only keep
89
+ if (referenceType.isSupertypeOf(aggregateReferenceType) && reference.isForward) {
90
+ return true;
91
+ }
92
+ else if (referenceType.isSupertypeOf(hasSubtypeReferenceType) && !reference.isForward) {
93
+ return true;
94
+ }
95
+ else if (referenceType.isSupertypeOf(hasTypeDefinitionReferenceType) && reference.isForward) {
96
+ return true;
97
+ }
98
+ else if (referenceType.isSupertypeOf(nonHierarchicalReferencesType) && reference.isForward) {
99
+ return true;
100
+ }
101
+ else if (referenceType.isSupertypeOf(organizesReferencesType) && !reference.isForward) {
102
+ return true;
103
+ }
104
+ else if (connectsToReferenceType && referenceType.isSupertypeOf(connectsToReferenceType) && reference.isForward) {
105
+ return true;
106
+ }
107
+ else if (referenceType.isSupertypeOf(hasEventSourceReferenceType) && reference.isForward) {
108
+ return true;
109
+ }
110
+ return false;
111
+ }
112
+ const references = node.allReferences().filter(referenceToKeep);
113
+ for (const reference of references.sort(sortByNodeId)) {
114
+ if ((0, base_node_impl_1.getReferenceType)(reference).browseName.toString() === "HasSubtype" && reference.isForward) {
115
+ continue;
116
+ }
117
+ // only output inverse Reference
118
+ xw.startElement("Reference");
119
+ xw.writeAttribute("ReferenceType", b(xw, (0, base_node_impl_1.getReferenceType)(reference).browseName));
120
+ if (!reference.isForward) {
121
+ xw.writeAttribute("IsForward", reference.isForward ? "true" : "false");
122
+ }
123
+ xw.text(n(xw, reference.nodeId));
124
+ xw.endElement();
125
+ }
126
+ xw.endElement();
127
+ }
128
+ function _dumpLocalizedText(xw, v) {
129
+ if (v.locale && v.locale.length) {
130
+ xw.startElement("Locale");
131
+ xw.text(v.locale);
132
+ xw.endElement();
133
+ }
134
+ xw.startElement("Text");
135
+ if (v.text) {
136
+ xw.text(v.text);
137
+ }
138
+ xw.endElement();
139
+ }
140
+ function _dumpQualifiedName(xw, v) {
141
+ const t = translateBrowseName(xw, v);
142
+ if (t.name) {
143
+ xw.startElement("Name");
144
+ xw.text(t.name);
145
+ xw.endElement();
146
+ }
147
+ if (t.namespaceIndex) {
148
+ xw.startElement("NamespaceIndex");
149
+ xw.text(t.namespaceIndex.toString());
150
+ xw.endElement();
151
+ }
152
+ }
153
+ function _dumpXmlElement(xw, v) {
154
+ xw.text(v);
155
+ }
156
+ /*
157
+ <uax:ExtensionObject>
158
+ <uax:TypeId>
159
+ <uax:Identifier>i=339</uax:Identifier>
160
+ </uax:TypeId>
161
+ <uax:Body>
162
+ <BuildInfo xmlns="http://opcfoundation.org/UA/2008/02/Types.xsd">
163
+ <ProductUri></ProductUri>
164
+ <ManufacturerName></ManufacturerName>
165
+ <ProductName></ProductName>
166
+ <SoftwareVersion></SoftwareVersion>
167
+ <BuildNumber></BuildNumber>
168
+ <BuildDate>1900-01-01T00:00:00Z</BuildDate>
169
+ </BuildInfo>
170
+ </uax:Body>
171
+ </uax:ExtensionObject>
172
+ */
173
+ function _dumpNodeId(xw, v) {
174
+ xw.startElement("Identifier");
175
+ xw.text(n(xw, v));
176
+ xw.endElement();
177
+ }
178
+ // eslint-disable-next-line complexity
179
+ function _dumpVariantValue(xw, dataType, node, value) {
180
+ const dataTypeNode = node.addressSpace.findDataType(node.dataType);
181
+ if (value === undefined || value === null) {
182
+ return;
183
+ }
184
+ if (dataType === node_opcua_variant_1.DataType.Null) {
185
+ return;
186
+ }
187
+ xw.startElement(node_opcua_variant_1.DataType[dataType]);
188
+ const definitionMap = (0, decode_xml_extension_object_1.makeDefinitionMap)(node.addressSpace);
189
+ _dumpVariantInnerValue(xw, dataType, dataTypeNode.nodeId, definitionMap, value);
190
+ xw.endElement();
191
+ }
192
+ function _dumpVariantInnerExtensionObject(xw, definitionMap, definition, value) {
193
+ for (const field of definition.fields || []) {
194
+ const dataTypeNodeId = field.dataType;
195
+ const fieldName = field.name;
196
+ const lowerFieldName = utils.lowerFirstLetter(fieldName);
197
+ const v = value[lowerFieldName];
198
+ if (v !== null && v !== undefined) {
199
+ if (dataTypeNodeId.namespace === 0 &&
200
+ dataTypeNodeId.value === 0 &&
201
+ dataTypeNodeId.identifierType === node_opcua_nodeid_1.NodeIdType.NUMERIC) {
202
+ // to do ?? shall we do a extension Object here ?
203
+ continue; // ns=0;i=0 is reserved
204
+ }
205
+ const { name, definition } = definitionMap.findDefinition(dataTypeNodeId);
206
+ xw.startElement(fieldName);
207
+ let fun = (value) => {
208
+ /** */
209
+ };
210
+ if (definition instanceof node_opcua_types_1.StructureDefinition) {
211
+ fun = _dumpVariantInnerExtensionObject.bind(null, xw, definitionMap, definition);
212
+ }
213
+ else if (definition instanceof node_opcua_types_1.EnumDefinition) {
214
+ fun = _dumpVariantInnerValueEnum.bind(null, xw, definition);
215
+ }
216
+ else {
217
+ const baseType = definition.dataType;
218
+ fun = _dumpVariantInnerValue.bind(null, xw, baseType, dataTypeNodeId, definitionMap);
219
+ }
220
+ try {
221
+ if (field.valueRank === -1) {
222
+ fun(v);
223
+ }
224
+ else {
225
+ // array
226
+ for (const arrayItem of v) {
227
+ xw.startElement(name);
228
+ fun(arrayItem);
229
+ xw.endElement();
230
+ }
231
+ }
232
+ }
233
+ catch (err) {
234
+ // eslint-disable-next-line max-depth
235
+ if (err instanceof Error) {
236
+ errorLog("Error in _dumpVariantExtensionObjectValue_Body !!!", err.message);
237
+ }
238
+ console.log(name);
239
+ console.log(field);
240
+ // throw err;
241
+ }
242
+ xw.endElement();
243
+ }
244
+ }
245
+ }
246
+ function _dumpVariantInnerValueEnum(xw, definition, value) {
247
+ if (!definition.fields) {
248
+ return;
249
+ }
250
+ const field = definition.fields.find((f) => f.value[1] === value || f.name === value);
251
+ xw.text(`${field === null || field === void 0 ? void 0 : field.name}_${field === null || field === void 0 ? void 0 : field.value[1]}`);
252
+ }
253
+ // eslint-disable-next-line complexity
254
+ function _dumpVariantInnerValue(xw, dataType, dataTypeNodeId, definitionMap, value) {
255
+ switch (dataType) {
256
+ case null:
257
+ case node_opcua_variant_1.DataType.Null:
258
+ break;
259
+ case node_opcua_variant_1.DataType.LocalizedText:
260
+ _dumpLocalizedText(xw, value);
261
+ break;
262
+ case node_opcua_variant_1.DataType.QualifiedName:
263
+ _dumpQualifiedName(xw, value);
264
+ break;
265
+ case node_opcua_variant_1.DataType.NodeId:
266
+ _dumpNodeId(xw, value);
267
+ break;
268
+ case node_opcua_variant_1.DataType.DateTime:
269
+ xw.text(value.toISOString());
270
+ break;
271
+ case node_opcua_variant_1.DataType.Int64:
272
+ case node_opcua_variant_1.DataType.UInt64:
273
+ xw.text(value[1].toString());
274
+ break;
275
+ case node_opcua_variant_1.DataType.Boolean:
276
+ case node_opcua_variant_1.DataType.SByte:
277
+ case node_opcua_variant_1.DataType.Byte:
278
+ case node_opcua_variant_1.DataType.Float:
279
+ case node_opcua_variant_1.DataType.Double:
280
+ case node_opcua_variant_1.DataType.Int16:
281
+ case node_opcua_variant_1.DataType.Int32:
282
+ case node_opcua_variant_1.DataType.UInt16:
283
+ case node_opcua_variant_1.DataType.UInt32:
284
+ case node_opcua_variant_1.DataType.String:
285
+ xw.text(value.toString());
286
+ break;
287
+ case node_opcua_variant_1.DataType.ByteString:
288
+ {
289
+ const base64 = value.toString("base64");
290
+ xw.text(base64.length > 80 ? base64.match(/.{0,80}/g).join("\n") : base64);
291
+ }
292
+ break;
293
+ case node_opcua_variant_1.DataType.Guid:
294
+ /*
295
+ <uax:Guid>
296
+ <uax:String>947c29a7-490d-4dc9-adda-1109e3e8fcb7</uax:String>
297
+ </uax:Guid>
298
+ */
299
+ if (value !== undefined && value !== null) {
300
+ // xw.writeAttribute("xmlns", "http://opcfoundation.org/UA/2008/02/Types.xsd");
301
+ xw.startElement("String");
302
+ xw.text(value.toString());
303
+ xw.endElement();
304
+ }
305
+ break;
306
+ case node_opcua_variant_1.DataType.ExtensionObject:
307
+ _dumpVariantExtensionObjectValue(xw, dataTypeNodeId, definitionMap, value);
308
+ break;
309
+ case node_opcua_variant_1.DataType.XmlElement:
310
+ _dumpXmlElement(xw, value);
311
+ break;
312
+ case node_opcua_variant_1.DataType.StatusCode:
313
+ xw.text(value.value.toString());
314
+ break;
315
+ default:
316
+ errorLog("_dumpVariantInnerValue incomplete " + value + " " + "DataType=" + dataType + "=" + node_opcua_variant_1.DataType[dataType]);
317
+ // throw new Error("_dumpVariantInnerValue incomplete " + value + " " + "DataType=" + dataType + "=" + DataType[dataType]);
318
+ }
319
+ }
320
+ /**
321
+ *
322
+ * @param xw
323
+ * @param schema
324
+ * @param value
325
+ * @private
326
+ */
327
+ function _dumpVariantExtensionObjectValue_Body(xw, definitionMap, name, definition, value) {
328
+ if (value) {
329
+ xw.startElement(name);
330
+ if (value) {
331
+ _dumpVariantInnerExtensionObject(xw, definitionMap, definition, value);
332
+ }
333
+ xw.endElement();
334
+ }
335
+ }
336
+ function _dumpVariantExtensionObjectValue(xw, dataTypeNodeId, definitionMap, value) {
337
+ const { name, definition } = definitionMap.findDefinition(dataTypeNodeId);
338
+ // const encodingDefaultXml = (getStructureTypeConstructor(schema.name) as any).encodingDefaultXml;
339
+ const encodingDefaultXml = value.schema.encodingDefaultXml;
340
+ if (!encodingDefaultXml) {
341
+ // throw new Error("Extension Object doesn't provide a XML ");
342
+ return;
343
+ }
344
+ xw.startElement("ExtensionObject");
345
+ {
346
+ xw.startElement("TypeId");
347
+ {
348
+ // find HasEncoding node
349
+ // xx var encodingDefaultXml = schema.encodingDefaultXml;
350
+ xw.startElement("Identifier");
351
+ xw.text(n(xw, encodingDefaultXml));
352
+ xw.endElement();
353
+ }
354
+ xw.endElement();
355
+ xw.startElement("Body");
356
+ _dumpVariantExtensionObjectValue_Body(xw, definitionMap, name, definition, value);
357
+ xw.endElement();
358
+ }
359
+ xw.endElement();
360
+ }
361
+ function _dumpVariantExtensionObjectValue2(xw, dataTypeNode, value) {
362
+ const addressSpace = dataTypeNode.addressSpace;
363
+ const definitionMap = (0, decode_xml_extension_object_1.makeDefinitionMap)(addressSpace);
364
+ _dumpVariantExtensionObjectValue(xw, dataTypeNode.nodeId, definitionMap, value);
365
+ }
366
+ // eslint-disable-next-line complexity
367
+ function _isDefaultValue(value) {
368
+ // detect default value
369
+ if (value.arrayType === node_opcua_variant_1.VariantArrayType.Scalar) {
370
+ switch (value.dataType) {
371
+ case node_opcua_variant_1.DataType.ExtensionObject:
372
+ if (!value.value) {
373
+ return true;
374
+ }
375
+ break;
376
+ case node_opcua_variant_1.DataType.DateTime:
377
+ if (!value.value || value.value.getTime() === node_opcua_basic_types_1.minOPCUADate) {
378
+ return true;
379
+ }
380
+ break;
381
+ case node_opcua_variant_1.DataType.ByteString:
382
+ if (!value.value || value.value.length === 0) {
383
+ return true;
384
+ }
385
+ break;
386
+ case node_opcua_variant_1.DataType.Boolean:
387
+ if (!value.value) {
388
+ return true;
389
+ }
390
+ break;
391
+ case node_opcua_variant_1.DataType.SByte:
392
+ case node_opcua_variant_1.DataType.Byte:
393
+ case node_opcua_variant_1.DataType.UInt16:
394
+ case node_opcua_variant_1.DataType.UInt32:
395
+ case node_opcua_variant_1.DataType.Int16:
396
+ case node_opcua_variant_1.DataType.Int32:
397
+ case node_opcua_variant_1.DataType.Double:
398
+ case node_opcua_variant_1.DataType.Float:
399
+ if (value.value === 0 || value.value === null) {
400
+ return true;
401
+ }
402
+ break;
403
+ case node_opcua_variant_1.DataType.String:
404
+ if (value.value === null || value.value === "") {
405
+ return true;
406
+ }
407
+ break;
408
+ case node_opcua_variant_1.DataType.Int64:
409
+ case node_opcua_variant_1.DataType.UInt64:
410
+ if (0 === coerceInt64ToInt32(value.value)) {
411
+ return true;
412
+ }
413
+ break;
414
+ case node_opcua_variant_1.DataType.LocalizedText:
415
+ if (!value.value) {
416
+ return true;
417
+ }
418
+ {
419
+ const l = value.value;
420
+ if (!l.locale && !l.text) {
421
+ return true;
422
+ }
423
+ }
424
+ break;
425
+ }
426
+ return false;
427
+ }
428
+ else {
429
+ if (!value.value || value.value.length === 0) {
430
+ return true;
431
+ }
432
+ return false;
433
+ }
434
+ }
435
+ // eslint-disable-next-line max-statements
436
+ function _dumpValue(xw, node, value) {
437
+ const addressSpace = node.addressSpace;
438
+ // istanbul ignore next
439
+ if (value === null || value === undefined) {
440
+ return;
441
+ }
442
+ (0, node_opcua_assert_1.assert)(value instanceof node_opcua_variant_1.Variant);
443
+ const dataTypeNode = addressSpace.findNode(node.dataType);
444
+ if (!dataTypeNode) {
445
+ console.log("Cannot find dataType:", node.dataType);
446
+ return;
447
+ }
448
+ const dataTypeName = dataTypeNode.browseName.name.toString();
449
+ const baseDataTypeName = node_opcua_variant_1.DataType[value.dataType];
450
+ if (baseDataTypeName === "Null") {
451
+ return;
452
+ }
453
+ (0, node_opcua_assert_1.assert)(typeof baseDataTypeName === "string");
454
+ // determine if dataTypeName is a ExtensionObject
455
+ const isExtensionObject = value.dataType === node_opcua_variant_1.DataType.ExtensionObject;
456
+ if (_isDefaultValue(value)) {
457
+ return;
458
+ }
459
+ xw.startElement("Value");
460
+ if (isExtensionObject) {
461
+ const dataTypeNode = addressSpace.findDataType(node.dataType);
462
+ if (!dataTypeNode) {
463
+ throw new Error("Cannot find data type " + node.dataType.toString());
464
+ }
465
+ const encodeXml = _dumpVariantExtensionObjectValue2.bind(null, xw, dataTypeNode);
466
+ if (value.arrayType === node_opcua_variant_1.VariantArrayType.Array) {
467
+ xw.startElement("ListOf" + baseDataTypeName);
468
+ value.value.forEach(encodeXml);
469
+ xw.endElement();
470
+ }
471
+ else if (value.arrayType === node_opcua_variant_1.VariantArrayType.Scalar) {
472
+ encodeXml(value.value);
473
+ }
474
+ else {
475
+ errorLog(node.toString());
476
+ errorLog("_dumpValue : unsupported case , Matrix of ExtensionObjects");
477
+ // throw new Error("Unsupported case");
478
+ }
479
+ }
480
+ else {
481
+ const encodeXml = _dumpVariantValue.bind(null, xw, value.dataType, node);
482
+ if (value.arrayType === node_opcua_variant_1.VariantArrayType.Matrix) {
483
+ // console.log("Warning _dumpValue : Matrix not supported yet");
484
+ xw.startElement("ListOf" + dataTypeName);
485
+ xw.writeAttribute("xmlns", "http://opcfoundation.org/UA/2008/02/Types.xsd");
486
+ value.value.forEach(encodeXml);
487
+ xw.endElement();
488
+ }
489
+ else if (value.arrayType === node_opcua_variant_1.VariantArrayType.Array) {
490
+ xw.startElement("ListOf" + dataTypeName);
491
+ xw.writeAttribute("xmlns", "http://opcfoundation.org/UA/2008/02/Types.xsd");
492
+ value.value.forEach(encodeXml);
493
+ xw.endElement();
494
+ }
495
+ else if (value.arrayType === node_opcua_variant_1.VariantArrayType.Scalar) {
496
+ encodeXml(value.value);
497
+ }
498
+ else {
499
+ errorLog(node.toString());
500
+ errorLog("_dumpValue : unsupported case , Matrix");
501
+ // xx throw new Error("Unsupported case");
502
+ }
503
+ }
504
+ xw.endElement();
505
+ }
506
+ function _dumpArrayDimensionsAttribute(xw, node) {
507
+ if (node.arrayDimensions) {
508
+ if (node.valueRank === -1 || (node.arrayDimensions.length === 1 && node.arrayDimensions[0] === 0)) {
509
+ return;
510
+ }
511
+ xw.writeAttribute("ArrayDimensions", node.arrayDimensions.join(","));
512
+ }
513
+ }
514
+ function visitUANode(node, options, forward) {
515
+ (0, node_opcua_assert_1.assert)(typeof forward === "boolean");
516
+ const addressSpace = node.addressSpace;
517
+ options.elements = options.elements || [];
518
+ options.index_el = options.index_el || {};
519
+ // visit references
520
+ function process_reference(reference) {
521
+ // only backward or forward references
522
+ if (reference.isForward !== forward) {
523
+ return;
524
+ }
525
+ if (reference.nodeId.namespace === 0) {
526
+ return; // skip OPCUA namespace
527
+ }
528
+ const k = _hash(reference);
529
+ if (!options.index_el[k]) {
530
+ options.index_el[k] = 1;
531
+ const o = addressSpace.findNode(k);
532
+ if (o) {
533
+ visitUANode(o, options, forward);
534
+ }
535
+ }
536
+ }
537
+ node.ownReferences().forEach(process_reference);
538
+ options.elements.push(node);
539
+ return node;
540
+ }
541
+ function dumpNodeInXml(xw, node) {
542
+ return node.dumpXML(xw);
543
+ }
544
+ function dumpReferencedNodes(xw, node, forward) {
545
+ const addressSpace = node.addressSpace;
546
+ if (!forward) {
547
+ {
548
+ const r = node.findReferencesEx("HasTypeDefinition");
549
+ if (r && r.length) {
550
+ (0, node_opcua_assert_1.assert)(r.length === 1);
551
+ const typeDefinitionObj = reference_impl_1.ReferenceImpl.resolveReferenceNode(addressSpace, r[0]);
552
+ if (!typeDefinitionObj) {
553
+ warningLog(node.toString());
554
+ warningLog("dumpReferencedNodes: Warning : " + node.browseName.toString() + " unknown typeDefinition, ", r[0].toString());
555
+ }
556
+ else {
557
+ (0, node_opcua_assert_1.assert)(typeDefinitionObj instanceof base_node_impl_1.BaseNodeImpl);
558
+ if (typeDefinitionObj.nodeId.namespace === node.nodeId.namespace) {
559
+ // only output node if it is on the same namespace
560
+ if (!xw.visitedNode[_hash(typeDefinitionObj)]) {
561
+ dumpNodeInXml(xw, typeDefinitionObj);
562
+ }
563
+ }
564
+ }
565
+ }
566
+ }
567
+ //
568
+ {
569
+ const r = node.findReferencesEx("HasSubtype", node_opcua_data_model_1.BrowseDirection.Inverse);
570
+ if (r && r.length) {
571
+ const subTypeOf = reference_impl_1.ReferenceImpl.resolveReferenceNode(addressSpace, r[0]);
572
+ (0, node_opcua_assert_1.assert)(r.length === 1);
573
+ if (subTypeOf.nodeId.namespace === node.nodeId.namespace) {
574
+ // only output node if it is on the same namespace
575
+ if (!xw.visitedNode[_hash(subTypeOf)]) {
576
+ dumpNodeInXml(xw, subTypeOf);
577
+ }
578
+ }
579
+ }
580
+ }
581
+ }
582
+ else {
583
+ const r = node.findReferencesEx("Aggregates", node_opcua_data_model_1.BrowseDirection.Forward);
584
+ for (const reference of r) {
585
+ const nodeChild = reference_impl_1.ReferenceImpl.resolveReferenceNode(addressSpace, reference);
586
+ (0, node_opcua_assert_1.assert)(nodeChild instanceof base_node_impl_1.BaseNodeImpl);
587
+ if (nodeChild.nodeId.namespace === node.nodeId.namespace) {
588
+ if (!xw.visitedNode[_hash(nodeChild)]) {
589
+ console.log(node.nodeId.toString(), " dumping child ", nodeChild.browseName.toString(), nodeChild.nodeId.toString());
590
+ dumpNodeInXml(xw, nodeChild);
591
+ }
592
+ }
593
+ }
594
+ }
595
+ }
596
+ const currentReadFlag = (0, node_opcua_data_model_1.makeAccessLevelFlag)("CurrentRead");
597
+ function dumpCommonAttributes(xw, node) {
598
+ xw.writeAttribute("NodeId", n(xw, node.nodeId));
599
+ xw.writeAttribute("BrowseName", b(xw, node.browseName));
600
+ if (Object.prototype.hasOwnProperty.call(node, "symbolicName")) {
601
+ xw.writeAttribute("SymbolicName", node.symbolicName);
602
+ }
603
+ if (Object.prototype.hasOwnProperty.call(node, "isAbstract")) {
604
+ if (node.isAbstract) {
605
+ xw.writeAttribute("IsAbstract", node.isAbstract ? "true" : "false");
606
+ }
607
+ }
608
+ if (Object.prototype.hasOwnProperty.call(node, "accessLevel")) {
609
+ // CurrentRead is by default
610
+ if (node.accessLevel !== currentReadFlag) {
611
+ xw.writeAttribute("AccessLevel", node.accessLevel.toString());
612
+ }
613
+ }
614
+ }
615
+ function dumpCommonElements(xw, node) {
616
+ _dumpDisplayName(xw, node);
617
+ _dumpDescription(xw, node);
618
+ _dumpReferences(xw, node);
619
+ }
620
+ function coerceInt64ToInt32(int64) {
621
+ if (typeof int64 === "number") {
622
+ return int64;
623
+ }
624
+ if (int64[0] === 4294967295 && int64[1] === 4294967295) {
625
+ return 0xffffffff;
626
+ }
627
+ if (int64[0] !== 0) {
628
+ debugLog("coerceInt64ToInt32 , loosing high word in conversion");
629
+ }
630
+ return int64[1];
631
+ }
632
+ function _dumpEnumDefinition(xw, enumDefinition) {
633
+ enumDefinition.fields = enumDefinition.fields || [];
634
+ for (const defItem of enumDefinition.fields) {
635
+ xw.startElement("Field");
636
+ xw.writeAttribute("Name", defItem.name);
637
+ if (!utils.isNullOrUndefined(defItem.value)) {
638
+ xw.writeAttribute("Value", coerceInt64ToInt32(defItem.value));
639
+ }
640
+ _dumpDescription(xw, defItem);
641
+ xw.endElement();
642
+ }
643
+ }
644
+ function _dumpStructureDefinition(xw, structureDefinition, baseStructureDefinition) {
645
+ var _a;
646
+ /*
647
+ * note: baseDataType and defaultEncodingId are implicit and not stored in the XML file ??
648
+ *
649
+ */
650
+ const baseDataType = structureDefinition.baseDataType;
651
+ const defaultEncodingId = structureDefinition.defaultEncodingId;
652
+ // do not repeat elements that are already defined in base structure in the xml ouput!
653
+ const fields = structureDefinition.fields || [];
654
+ const nbFieldsInBase = baseStructureDefinition ? ((_a = baseStructureDefinition.fields) === null || _a === void 0 ? void 0 : _a.length) || 0 : 0;
655
+ for (let index = nbFieldsInBase; index < fields.length; index++) {
656
+ const defItem = fields[index];
657
+ xw.startElement("Field");
658
+ xw.writeAttribute("Name", defItem.name);
659
+ if (defItem.arrayDimensions) {
660
+ xw.writeAttribute("ArrayDimensions", defItem.arrayDimensions.map((x) => x.toString()).join(","));
661
+ }
662
+ if (defItem.valueRank !== undefined && defItem.valueRank !== -1) {
663
+ xw.writeAttribute("ValueRank", defItem.valueRank);
664
+ }
665
+ if (defItem.isOptional /* && defItem.isOptional !== false */) {
666
+ xw.writeAttribute("IsOptional", defItem.isOptional.toString());
667
+ }
668
+ if (defItem.maxStringLength !== undefined && defItem.maxStringLength !== 0) {
669
+ xw.writeAttribute("MaxStringLength", defItem.maxStringLength);
670
+ }
671
+ // todo : SymbolicName ( see AutoId )
672
+ if (defItem.dataType) {
673
+ // todo : namespace translation !
674
+ xw.writeAttribute("DataType", n(xw, defItem.dataType));
675
+ }
676
+ _dumpDescription(xw, defItem);
677
+ xw.endElement();
678
+ }
679
+ }
680
+ function _dumpEncodings(xw, uaDataType) {
681
+ const encodings = uaDataType.findReferencesExAsObject("HasEncoding", node_opcua_data_model_1.BrowseDirection.Forward);
682
+ for (const encoding of encodings) {
683
+ if (encoding.nodeClass !== node_opcua_data_model_1.NodeClass.Object) {
684
+ continue;
685
+ }
686
+ _dumpUAObject(xw, encoding);
687
+ }
688
+ }
689
+ function _dumpUADataTypeDefinition(xw, uaDataType) {
690
+ const uaDataTypeBase = uaDataType.subtypeOfObj;
691
+ if (uaDataType.isEnumeration()) {
692
+ xw.startElement("Definition");
693
+ xw.writeAttribute("Name", b(xw, uaDataType.browseName));
694
+ _dumpEnumDefinition(xw, uaDataType.getEnumDefinition());
695
+ xw.endElement();
696
+ return;
697
+ }
698
+ if (uaDataType.isStructure()) {
699
+ const definition = uaDataType.getStructureDefinition();
700
+ const baseDefinition = uaDataTypeBase ? uaDataTypeBase.getStructureDefinition() : null;
701
+ xw.startElement("Definition");
702
+ xw.writeAttribute("Name", b(xw, uaDataType.browseName));
703
+ if (definition.structureType === node_opcua_types_1.StructureType.Union) {
704
+ xw.writeAttribute("IsUnion", "true");
705
+ }
706
+ _dumpStructureDefinition(xw, definition, baseDefinition);
707
+ xw.endElement();
708
+ return;
709
+ }
710
+ }
711
+ function dumpUADataType(xw, node) {
712
+ _markAsVisited(xw, node);
713
+ xw.startElement("UADataType");
714
+ xw.writeAttribute("NodeId", n(xw, node.nodeId));
715
+ xw.writeAttribute("BrowseName", b(xw, node.browseName));
716
+ if (node.symbolicName !== node.browseName.name) {
717
+ xw.writeAttribute("SymbolicName", node.symbolicName);
718
+ }
719
+ if (node.isAbstract) {
720
+ xw.writeAttribute("IsAbstract", node.isAbstract ? "true" : "false");
721
+ }
722
+ _dumpDisplayName(xw, node);
723
+ _dumpReferences(xw, node);
724
+ _dumpUADataTypeDefinition(xw, node);
725
+ xw.endElement();
726
+ _dumpEncodings(xw, node);
727
+ dumpAggregates(xw, node);
728
+ }
729
+ function _markAsVisited(xw, node) {
730
+ xw.visitedNode = xw.visitedNode || {};
731
+ (0, node_opcua_assert_1.assert)(!xw.visitedNode[_hash(node)]);
732
+ xw.visitedNode[_hash(node)] = 1;
733
+ }
734
+ function dumpUAVariable(xw, node) {
735
+ _markAsVisited(xw, node);
736
+ dumpReferencedNodes(xw, node, false);
737
+ const addressSpace = node.addressSpace;
738
+ xw.startElement("UAVariable");
739
+ {
740
+ // attributes
741
+ dumpCommonAttributes(xw, node);
742
+ if (node.valueRank !== -1) {
743
+ // -1 = Scalar
744
+ xw.writeAttribute("ValueRank", node.valueRank);
745
+ }
746
+ _dumpArrayDimensionsAttribute(xw, node);
747
+ const dataTypeNode = addressSpace.findNode(node.dataType);
748
+ if (dataTypeNode) {
749
+ // verify that data Type is in alias
750
+ // xx const dataTypeName = dataTypeNode.browseName.toString();
751
+ const dataTypeName = b(xw, resolveDataTypeName(addressSpace, dataTypeNode.nodeId));
752
+ xw.writeAttribute("DataType", dataTypeName);
753
+ }
754
+ }
755
+ {
756
+ // sub elements
757
+ dumpCommonElements(xw, node);
758
+ const value = node.$dataValue.value;
759
+ if (value) {
760
+ _dumpValue(xw, node, value);
761
+ }
762
+ }
763
+ xw.endElement();
764
+ dumpAggregates(xw, node);
765
+ }
766
+ function dumpUAVariableType(xw, node) {
767
+ xw.visitedNode = xw.visitedNode || {};
768
+ (0, node_opcua_assert_1.assert)(!xw.visitedNode[_hash(node)]);
769
+ xw.visitedNode[_hash(node)] = 1;
770
+ dumpReferencedNodes(xw, node, false);
771
+ const addressSpace = node.addressSpace;
772
+ xw.startElement("UAVariableType");
773
+ {
774
+ // attributes
775
+ dumpCommonAttributes(xw, node);
776
+ if (node.valueRank !== -1) {
777
+ xw.writeAttribute("ValueRank", node.valueRank);
778
+ }
779
+ const dataTypeNode = addressSpace.findNode(node.dataType);
780
+ if (!dataTypeNode) {
781
+ // throw new Error(" cannot find datatype " + node.dataType);
782
+ console.log(" cannot find datatype " +
783
+ node.dataType +
784
+ " for node " +
785
+ node.browseName.toString() +
786
+ " id =" +
787
+ node.nodeId.toString());
788
+ }
789
+ else {
790
+ const dataTypeName = b(xw, resolveDataTypeName(addressSpace, dataTypeNode.nodeId));
791
+ xw.writeAttribute("DataType", dataTypeName);
792
+ }
793
+ }
794
+ {
795
+ _dumpArrayDimensionsAttribute(xw, node);
796
+ // sub elements
797
+ dumpCommonElements(xw, node);
798
+ const value = node.value;
799
+ if (value) {
800
+ _dumpValue(xw, node, value);
801
+ }
802
+ }
803
+ xw.endElement();
804
+ dumpAggregates(xw, node);
805
+ }
806
+ function dumpUAObject(xw, node) {
807
+ xw.writeComment("Object - " + b(xw, node.browseName) + " {{{{ ");
808
+ _dumpUAObject(xw, node);
809
+ xw.writeComment("Object - " + b(xw, node.browseName) + " }}}} ");
810
+ }
811
+ function _dumpUAObject(xw, node) {
812
+ xw.visitedNode = xw.visitedNode || {};
813
+ (0, node_opcua_assert_1.assert)(!xw.visitedNode[_hash(node)]);
814
+ xw.visitedNode[_hash(node)] = 1;
815
+ // dump SubTypeOf and HasTypeDefinition
816
+ dumpReferencedNodes(xw, node, false);
817
+ xw.startElement("UAObject");
818
+ dumpCommonAttributes(xw, node);
819
+ dumpCommonElements(xw, node);
820
+ xw.endElement();
821
+ // dump aggregates nodes ( Properties / components )
822
+ dumpAggregates(xw, node);
823
+ dumpElementInFolder(xw, node);
824
+ }
825
+ function dumpElementInFolder(xw, node) {
826
+ const aggregates = node
827
+ .getFolderElements()
828
+ .sort((x, y) => (x.browseName.name.toString() > y.browseName.name.toString() ? 1 : -1));
829
+ for (const aggregate of aggregates.sort(sortByNodeId)) {
830
+ // do not export node that do not belong to our namespace
831
+ if (node.nodeId.namespace !== aggregate.nodeId.namespace) {
832
+ return;
833
+ }
834
+ if (!xw.visitedNode[_hash(aggregate)]) {
835
+ aggregate.dumpXML(xw);
836
+ }
837
+ }
838
+ }
839
+ function dumpAggregates(xw, node) {
840
+ // Xx xw.writeComment("Aggregates {{ ");
841
+ const aggregates = node
842
+ .getAggregates()
843
+ .sort((x, y) => (x.browseName.name.toString() > y.browseName.name.toString() ? 1 : -1));
844
+ for (const aggregate of aggregates.sort(sortByNodeId)) {
845
+ // do not export node that do not belong to our namespace
846
+ if (node.nodeId.namespace !== aggregate.nodeId.namespace) {
847
+ return;
848
+ }
849
+ if (!xw.visitedNode[_hash(aggregate)]) {
850
+ aggregate.dumpXML(xw);
851
+ }
852
+ }
853
+ // Xx xw.writeComment("Aggregates }} ");
854
+ }
855
+ function dumpUAObjectType(xw, node) {
856
+ (0, node_opcua_assert_1.assert)(node instanceof ua_object_type_impl_1.UAObjectTypeImpl);
857
+ xw.writeComment("ObjectType - " + b(xw, node.browseName) + " {{{{ ");
858
+ _markAsVisited(xw, node);
859
+ // dump SubtypeOf and HasTypeDefinition
860
+ dumpReferencedNodes(xw, node, false);
861
+ xw.startElement("UAObjectType");
862
+ dumpCommonAttributes(xw, node);
863
+ dumpCommonElements(xw, node);
864
+ xw.endElement();
865
+ dumpAggregates(xw, node);
866
+ xw.writeComment("ObjectType - " + b(xw, node.browseName) + " }}}}");
867
+ }
868
+ function dumpUAMethod(xw, node) {
869
+ _markAsVisited(xw, node);
870
+ dumpReferencedNodes(xw, node, false);
871
+ xw.startElement("UAMethod");
872
+ dumpCommonAttributes(xw, node);
873
+ if (node.methodDeclarationId) {
874
+ xw.writeAttribute("MethodDeclarationId", n(xw, node.methodDeclarationId));
875
+ }
876
+ dumpCommonElements(xw, node);
877
+ xw.endElement();
878
+ dumpAggregates(xw, node);
879
+ }
880
+ function resolveDataTypeName(addressSpace, dataType) {
881
+ let dataTypeNode = null;
882
+ // istanbul ignore next
883
+ if (typeof dataType === "string") {
884
+ dataTypeNode = addressSpace.findDataType(dataType);
885
+ }
886
+ else {
887
+ (0, node_opcua_assert_1.assert)(dataType instanceof node_opcua_nodeid_1.NodeId);
888
+ const o = addressSpace.findNode(dataType.toString());
889
+ dataTypeNode = o ? o : null;
890
+ }
891
+ if (!dataTypeNode) {
892
+ errorLog("resolveDataTypeName: warning cannot find DataType " + dataType.toString());
893
+ return new node_opcua_data_model_1.QualifiedName({ name: "", namespaceIndex: 0 });
894
+ }
895
+ return dataTypeNode.browseName;
896
+ }
897
+ function buildUpAliases(node, xw, options) {
898
+ const addressSpace = node.addressSpace;
899
+ options.aliases = options.aliases || {};
900
+ options.aliases_visited = options.aliases_visited || {};
901
+ const k = _hash(node);
902
+ // istanbul ignore next
903
+ if (options.aliases_visited[k]) {
904
+ return;
905
+ }
906
+ options.aliases_visited[k] = 1;
907
+ // put datatype into aliases list
908
+ if (node.nodeClass === node_opcua_data_model_1.NodeClass.Variable || node.nodeClass === node_opcua_data_model_1.NodeClass.VariableType) {
909
+ const nodeV = node;
910
+ if (nodeV.dataType && nodeV.dataType.namespace === 0 && nodeV.dataType.value !== 0) {
911
+ // name
912
+ const dataTypeName = b(xw, resolveDataTypeName(addressSpace, nodeV.dataType));
913
+ if (dataTypeName) {
914
+ if (!options.aliases[dataTypeName]) {
915
+ options.aliases[dataTypeName] = n(xw, nodeV.dataType);
916
+ }
917
+ }
918
+ }
919
+ if (nodeV.dataType && nodeV.dataType.namespace !== 0 && nodeV.dataType.value !== 0) {
920
+ // name
921
+ const dataTypeName = b(xw, resolveDataTypeName(addressSpace, nodeV.dataType));
922
+ if (dataTypeName) {
923
+ if (!options.aliases[dataTypeName]) {
924
+ options.aliases[dataTypeName] = n(xw, nodeV.dataType);
925
+ }
926
+ }
927
+ }
928
+ }
929
+ function collectReferenceNameInAlias(reference) {
930
+ // reference.referenceType
931
+ const key = b(xw, (0, base_node_impl_1.getReferenceType)(reference).browseName);
932
+ if (!options.aliases.key) {
933
+ if (reference.referenceType.namespace === 0) {
934
+ options.aliases[key] = reference.referenceType.toString().replace("ns=0;", "");
935
+ }
936
+ else {
937
+ options.aliases[key] = n(xw, reference.referenceType);
938
+ }
939
+ }
940
+ }
941
+ node.allReferences().forEach(collectReferenceNameInAlias);
942
+ }
943
+ function writeAliases(xw, aliases) {
944
+ xw.startElement("Aliases");
945
+ if (aliases) {
946
+ const keys = Object.keys(aliases).sort();
947
+ for (const key of keys) {
948
+ xw.startElement("Alias");
949
+ xw.writeAttribute("Alias", key);
950
+ xw.text(aliases[key].toString().replace(/ns=0;/, ""));
951
+ xw.endElement();
952
+ }
953
+ }
954
+ xw.endElement();
955
+ }
956
+ function constructNamespaceTranslationTable(dependency) {
957
+ const translationTable = {};
958
+ for (let i = 0; i < dependency.length; i++) {
959
+ translationTable[dependency[i].index] = i;
960
+ }
961
+ return translationTable;
962
+ }
963
+ function dumpReferenceType(xw, referenceType) {
964
+ _markAsVisited(xw, referenceType);
965
+ xw.startElement("UAReferenceType");
966
+ dumpCommonAttributes(xw, referenceType);
967
+ dumpCommonElements(xw, referenceType);
968
+ if (referenceType.inverseName /* LocalizedText*/) {
969
+ xw.startElement("InverseName");
970
+ xw.text(referenceType.inverseName.text || "");
971
+ xw.endElement();
972
+ }
973
+ xw.endElement();
974
+ }
975
+ function sortByBrowseName(x, y) {
976
+ const x_str = x.browseName.toString();
977
+ const y_str = y.browseName.toString();
978
+ if (x_str > y_str) {
979
+ return -1;
980
+ }
981
+ else if (x_str < y_str) {
982
+ return 1;
983
+ }
984
+ return 0;
985
+ }
986
+ function sortByNodeId(a, b) {
987
+ return a.nodeId.toString() < b.nodeId.toString() ? -1 : 1;
988
+ }
989
+ function dumpXml(node, options) {
990
+ const namespace = node.namespace;
991
+ // make a first visit so that we determine which node to output and in which order
992
+ const nodesToVisit = {};
993
+ const dependency = (0, construct_namespace_dependency_1.constructNamespaceDependency)(namespace);
994
+ const translationTable = constructNamespaceTranslationTable(dependency);
995
+ const xw = new XMLWriter(true);
996
+ xw.translationTable = translationTable;
997
+ visitUANode(node, nodesToVisit, false);
998
+ xw.startDocument({ encoding: "utf-8" });
999
+ xw.startElement("UANodeSet");
1000
+ xw.writeAttribute("xmlns:xs", "http://www.w3.org/2001/XMLSchema-instance");
1001
+ xw.writeAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
1002
+ xw.writeAttribute("Version", "1.02");
1003
+ xw.writeAttribute("LastModified", new Date().toISOString());
1004
+ xw.writeAttribute("xmlns", "http://opcfoundation.org/UA/2011/03/UANodeSet.xsd");
1005
+ buildUpAliases(node, xw, nodesToVisit);
1006
+ writeAliases(xw, nodesToVisit.aliases);
1007
+ for (const el of nodesToVisit.elements) {
1008
+ el.dumpXML(xw);
1009
+ }
1010
+ xw.endElement();
1011
+ xw.endDocument();
1012
+ return xw.toString();
1013
+ }
1014
+ exports.dumpXml = dumpXml;
1015
+ ua_method_impl_1.UAMethodImpl.prototype.dumpXML = function (xw) {
1016
+ dumpUAMethod(xw, this);
1017
+ };
1018
+ ua_object_impl_1.UAObjectImpl.prototype.dumpXML = function (xw) {
1019
+ dumpUAObject(xw, this);
1020
+ };
1021
+ ua_variable_impl_1.UAVariableImpl.prototype.dumpXML = function (xw) {
1022
+ dumpUAVariable(xw, this);
1023
+ };
1024
+ ua_variable_type_impl_1.UAVariableTypeImpl.prototype.dumpXML = function (xw) {
1025
+ dumpUAVariableType(xw, this);
1026
+ };
1027
+ ua_reference_type_impl_1.UAReferenceTypeImpl.prototype.dumpXML = function (xw) {
1028
+ dumpReferenceType(xw, this);
1029
+ };
1030
+ ua_object_type_impl_1.UAObjectTypeImpl.prototype.dumpXML = function (xw) {
1031
+ dumpUAObjectType(xw, this);
1032
+ };
1033
+ ua_data_type_impl_1.UADataTypeImpl.prototype.dumpXML = function (xw) {
1034
+ dumpUADataType(xw, this);
1035
+ };
1036
+ // eslint-disable-next-line max-statements
1037
+ namespace_impl_1.NamespaceImpl.prototype.toNodeset2XML = function () {
1038
+ const dependency = (0, construct_namespace_dependency_1.constructNamespaceDependency)(this);
1039
+ const translationTable = constructNamespaceTranslationTable(dependency);
1040
+ const xw = new XMLWriter(true);
1041
+ xw.translationTable = translationTable;
1042
+ xw.startDocument({ encoding: "utf-8", version: "1.0" });
1043
+ xw.startElement("UANodeSet");
1044
+ xw.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
1045
+ xw.writeAttribute("xmlns:uax", "http://opcfoundation.org/UA/2008/02/Types.xsd");
1046
+ xw.writeAttribute("xmlns", "http://opcfoundation.org/UA/2011/03/UANodeSet.xsd");
1047
+ // xx xw.writeAttribute("Version", "1.02");
1048
+ // xx xw.writeAttribute("LastModified", (new Date()).toISOString());
1049
+ // ------------- INamespace Uris
1050
+ xw.startElement("NamespaceUris");
1051
+ // xx const namespaceArray = namespace.addressSpace.getNamespaceArray();
1052
+ for (const depend of dependency) {
1053
+ if (depend.index === 0) {
1054
+ continue; // ignore namespace 0
1055
+ }
1056
+ xw.startElement("Uri");
1057
+ xw.text(depend.namespaceUri);
1058
+ xw.endElement();
1059
+ }
1060
+ xw.endElement();
1061
+ // ------------- INamespace Uris
1062
+ xw.startElement("Models");
1063
+ {
1064
+ xw.startElement("Model");
1065
+ xw.writeAttribute("ModelUri", this.namespaceUri);
1066
+ xw.writeAttribute("Version", this.version);
1067
+ xw.writeAttribute("PublicationDate", this.publicationDate.toISOString());
1068
+ for (const depend of dependency) {
1069
+ if (depend.index === this.index) {
1070
+ continue; // ignore our namespace 0
1071
+ }
1072
+ xw.startElement("RequiredModel");
1073
+ xw.writeAttribute("ModelUri", depend.namespaceUri);
1074
+ xw.writeAttribute("Version", depend.version);
1075
+ xw.writeAttribute("PublicationDate", depend.publicationDate.toISOString());
1076
+ xw.endElement();
1077
+ }
1078
+ xw.endElement();
1079
+ }
1080
+ xw.endElement();
1081
+ const s = {};
1082
+ for (const node of this.nodeIterator()) {
1083
+ buildUpAliases(node, xw, s);
1084
+ }
1085
+ writeAliases(xw, s.aliases);
1086
+ xw.visitedNode = {};
1087
+ // -------------- writeReferences
1088
+ xw.writeComment("ReferenceTypes");
1089
+ const referenceTypes = [...this._referenceTypeIterator()].sort(sortByBrowseName);
1090
+ for (const referenceType of referenceTypes) {
1091
+ dumpReferenceType(xw, referenceType);
1092
+ }
1093
+ // -------------- Dictionaries
1094
+ const addressSpace = this.addressSpace;
1095
+ const opcBinaryTypeSystem = addressSpace.findNode("OPCBinarySchema_TypeSystem");
1096
+ if (opcBinaryTypeSystem) {
1097
+ // let find all DataType dictionary node corresponding to a given namespace
1098
+ // (have DataTypeDictionaryType)
1099
+ const nodeToBrowse = new node_opcua_types_1.BrowseDescription({
1100
+ browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
1101
+ includeSubtypes: false,
1102
+ nodeClassMask: (0, node_opcua_data_model_1.makeNodeClassMask)("Variable"),
1103
+ nodeId: opcBinaryTypeSystem.nodeId,
1104
+ referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasComponent"),
1105
+ resultMask: (0, node_opcua_data_model_1.makeResultMask)("ReferenceType | IsForward | BrowseName | NodeClass | TypeDefinition")
1106
+ });
1107
+ const result = opcBinaryTypeSystem.browseNode(nodeToBrowse).filter((r) => r.nodeId.namespace === this.index);
1108
+ (0, node_opcua_assert_1.assert)(result.length <= 1);
1109
+ if (result.length === 1) {
1110
+ xw.writeComment("DataSystem");
1111
+ const dataSystemType = addressSpace.findNode(result[0].nodeId);
1112
+ dumpNodeInXml(xw, dataSystemType);
1113
+ }
1114
+ }
1115
+ // -------------- DataTypes
1116
+ const dataTypes = [...this._dataTypeIterator()].sort(sortByBrowseName);
1117
+ if (dataTypes.length) {
1118
+ xw.writeComment("DataTypes");
1119
+ // xx xw.writeComment(" "+ objectTypes.map(x=>x.browseName.name.toString()).join(" "));
1120
+ for (const dataType of dataTypes.sort(sortByNodeId)) {
1121
+ if (!xw.visitedNode[_hash(dataType)]) {
1122
+ dumpNodeInXml(xw, dataType);
1123
+ }
1124
+ }
1125
+ }
1126
+ // -------------- ObjectTypes
1127
+ xw.writeComment("ObjectTypes");
1128
+ const objectTypes = [...this._objectTypeIterator()].sort(sortByBrowseName);
1129
+ // xx xw.writeComment(" "+ objectTypes.map(x=>x.browseName.name.toString()).join(" "));
1130
+ for (const objectType of objectTypes.sort(sortByNodeId)) {
1131
+ if (!xw.visitedNode[_hash(objectType)]) {
1132
+ dumpNodeInXml(xw, objectType);
1133
+ }
1134
+ }
1135
+ // -------------- VariableTypes
1136
+ xw.writeComment("VariableTypes");
1137
+ const variableTypes = [...this._variableTypeIterator()].sort(sortByBrowseName);
1138
+ // xx xw.writeComment("ObjectTypes "+ variableTypes.map(x=>x.browseName.name.toString()).join(" "));
1139
+ for (const variableType of variableTypes.sort(sortByNodeId)) {
1140
+ if (!xw.visitedNode[_hash(variableType)]) {
1141
+ dumpNodeInXml(xw, variableType);
1142
+ }
1143
+ }
1144
+ // -------------- Any thing else
1145
+ xw.writeComment("Other Nodes");
1146
+ const nodes = [...this.nodeIterator()].sort(sortByBrowseName);
1147
+ for (const node of nodes.sort(sortByNodeId)) {
1148
+ if (!xw.visitedNode[_hash(node)]) {
1149
+ dumpNodeInXml(xw, node);
1150
+ }
1151
+ }
1152
+ xw.endElement();
1153
+ xw.endDocument();
1154
+ return xw.toString();
1155
+ };
1156
1156
  //# sourceMappingURL=nodeset_to_xml.js.map