node-opcua-address-space 2.76.0 → 2.77.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (291) hide show
  1. package/dist/source/address_space_ts.d.ts +118 -118
  2. package/dist/source/address_space_ts.js +17 -17
  3. package/dist/source/continuation_points/continuation_point_manager.d.ts +32 -32
  4. package/dist/source/continuation_points/continuation_point_manager.js +195 -195
  5. package/dist/source/helpers/adjust_browse_direction.d.ts +5 -5
  6. package/dist/source/helpers/adjust_browse_direction.js +11 -11
  7. package/dist/source/helpers/argument_list.d.ts +33 -33
  8. package/dist/source/helpers/argument_list.js +258 -258
  9. package/dist/source/helpers/call_helpers.d.ts +6 -6
  10. package/dist/source/helpers/call_helpers.js +70 -70
  11. package/dist/source/helpers/check_event_clause.d.ts +17 -0
  12. package/dist/source/helpers/check_event_clause.js +53 -0
  13. package/dist/source/helpers/check_event_clause.js.map +1 -0
  14. package/dist/source/helpers/coerce_enum_value.d.ts +6 -6
  15. package/dist/source/helpers/coerce_enum_value.js +33 -33
  16. package/dist/source/helpers/dump_tools.d.ts +14 -14
  17. package/dist/source/helpers/dump_tools.js +78 -78
  18. package/dist/source/helpers/ensure_secure_access.d.ts +9 -9
  19. package/dist/source/helpers/ensure_secure_access.js +76 -76
  20. package/dist/source/helpers/make_optionals_map.d.ts +21 -21
  21. package/dist/source/helpers/make_optionals_map.js +29 -29
  22. package/dist/source/helpers/multiform_func.d.ts +11 -11
  23. package/dist/source/helpers/multiform_func.js +75 -75
  24. package/dist/source/helpers/resolve_opaque_on_address_space.d.ts +3 -3
  25. package/dist/source/helpers/resolve_opaque_on_address_space.js +36 -36
  26. package/dist/source/index.d.ts +56 -56
  27. package/dist/source/index.js +83 -83
  28. package/dist/source/interfaces/alarms_and_conditions/condition_info_i.d.ts +19 -19
  29. package/dist/source/interfaces/alarms_and_conditions/condition_info_i.js +2 -2
  30. package/dist/source/interfaces/alarms_and_conditions/condition_snapshot.d.ts +193 -193
  31. package/dist/source/interfaces/alarms_and_conditions/condition_snapshot.js +2 -2
  32. package/dist/source/interfaces/alarms_and_conditions/deviation_stuff.d.ts +12 -12
  33. package/dist/source/interfaces/alarms_and_conditions/deviation_stuff.js +2 -2
  34. package/dist/source/interfaces/alarms_and_conditions/install_setpoint_options.d.ts +10 -10
  35. package/dist/source/interfaces/alarms_and_conditions/install_setpoint_options.js +2 -2
  36. package/dist/source/interfaces/alarms_and_conditions/instantiate_alarm_condition_options.d.ts +7 -7
  37. package/dist/source/interfaces/alarms_and_conditions/instantiate_alarm_condition_options.js +2 -2
  38. package/dist/source/interfaces/alarms_and_conditions/instantiate_condition_options.d.ts +7 -7
  39. package/dist/source/interfaces/alarms_and_conditions/instantiate_condition_options.js +2 -2
  40. package/dist/source/interfaces/alarms_and_conditions/instantiate_exclusive_deviation_alarm_options.d.ts +4 -4
  41. package/dist/source/interfaces/alarms_and_conditions/instantiate_exclusive_deviation_alarm_options.js +2 -2
  42. package/dist/source/interfaces/alarms_and_conditions/instantiate_exclusive_limit_alarm_options.d.ts +4 -4
  43. package/dist/source/interfaces/alarms_and_conditions/instantiate_exclusive_limit_alarm_options.js +2 -2
  44. package/dist/source/interfaces/alarms_and_conditions/instantiate_limit_alarm_options.d.ts +9 -9
  45. package/dist/source/interfaces/alarms_and_conditions/instantiate_limit_alarm_options.js +2 -2
  46. package/dist/source/interfaces/alarms_and_conditions/instantiate_non_exclusive_deviation_alarm_options.d.ts +4 -4
  47. package/dist/source/interfaces/alarms_and_conditions/instantiate_non_exclusive_deviation_alarm_options.js +2 -2
  48. package/dist/source/interfaces/alarms_and_conditions/instantiate_non_exclusive_limit_alarm_options.d.ts +4 -4
  49. package/dist/source/interfaces/alarms_and_conditions/instantiate_non_exclusive_limit_alarm_options.js +2 -2
  50. package/dist/source/interfaces/alarms_and_conditions/instantiate_off_normal_alarm_options.d.ts +20 -20
  51. package/dist/source/interfaces/alarms_and_conditions/instantiate_off_normal_alarm_options.js +2 -2
  52. package/dist/source/interfaces/alarms_and_conditions/ua_acknowledgeable_condition_ex.d.ts +23 -23
  53. package/dist/source/interfaces/alarms_and_conditions/ua_acknowledgeable_condition_ex.js +2 -2
  54. package/dist/source/interfaces/alarms_and_conditions/ua_alarm_condition_ex.d.ts +32 -32
  55. package/dist/source/interfaces/alarms_and_conditions/ua_alarm_condition_ex.js +2 -2
  56. package/dist/source/interfaces/alarms_and_conditions/ua_certificate_expiration_alarm_ex.d.ts +19 -19
  57. package/dist/source/interfaces/alarms_and_conditions/ua_certificate_expiration_alarm_ex.js +2 -2
  58. package/dist/source/interfaces/alarms_and_conditions/ua_condition_ex.d.ts +42 -42
  59. package/dist/source/interfaces/alarms_and_conditions/ua_condition_ex.js +2 -2
  60. package/dist/source/interfaces/alarms_and_conditions/ua_discrete_alarm_ex.d.ts +7 -7
  61. package/dist/source/interfaces/alarms_and_conditions/ua_discrete_alarm_ex.js +25 -25
  62. package/dist/source/interfaces/alarms_and_conditions/ua_exclusive_deviation_alarm_ex.d.ts +5 -5
  63. package/dist/source/interfaces/alarms_and_conditions/ua_exclusive_deviation_alarm_ex.js +2 -2
  64. package/dist/source/interfaces/alarms_and_conditions/ua_exclusive_limit_alarm_ex.d.ts +20 -20
  65. package/dist/source/interfaces/alarms_and_conditions/ua_exclusive_limit_alarm_ex.js +2 -2
  66. package/dist/source/interfaces/alarms_and_conditions/ua_limit_alarm_ex.d.ts +26 -26
  67. package/dist/source/interfaces/alarms_and_conditions/ua_limit_alarm_ex.js +2 -2
  68. package/dist/source/interfaces/alarms_and_conditions/ua_non_exclusive_deviation_alarm_ex.d.ts +8 -8
  69. package/dist/source/interfaces/alarms_and_conditions/ua_non_exclusive_deviation_alarm_ex.js +2 -2
  70. package/dist/source/interfaces/alarms_and_conditions/ua_non_exclusive_limit_alarm_ex.d.ts +10 -10
  71. package/dist/source/interfaces/alarms_and_conditions/ua_non_exclusive_limit_alarm_ex.js +2 -2
  72. package/dist/source/interfaces/data_access/ua_multistate_discrete_ex.d.ts +21 -21
  73. package/dist/source/interfaces/data_access/ua_multistate_discrete_ex.js +2 -2
  74. package/dist/source/interfaces/data_access/ua_multistate_value_discrete_ex.d.ts +24 -24
  75. package/dist/source/interfaces/data_access/ua_multistate_value_discrete_ex.js +2 -2
  76. package/dist/source/interfaces/data_access/ua_two_state_discrete_ex.d.ts +12 -12
  77. package/dist/source/interfaces/data_access/ua_two_state_discrete_ex.js +2 -2
  78. package/dist/source/interfaces/data_access/ua_y_array_item_ex.d.ts +8 -8
  79. package/dist/source/interfaces/data_access/ua_y_array_item_ex.js +2 -2
  80. package/dist/source/interfaces/state_machine/ua_exclusive_limit_state_machine_type_ex.d.ts +12 -12
  81. package/dist/source/interfaces/state_machine/ua_exclusive_limit_state_machine_type_ex.js +2 -2
  82. package/dist/source/interfaces/state_machine/ua_finite_state_machine_type.d.ts +49 -49
  83. package/dist/source/interfaces/state_machine/ua_finite_state_machine_type.js +2 -2
  84. package/dist/source/interfaces/state_machine/ua_program_state_machine_type.d.ts +11 -11
  85. package/dist/source/interfaces/state_machine/ua_program_state_machine_type.js +2 -2
  86. package/dist/source/interfaces/state_machine/ua_shelved_state_machine_ex.d.ts +30 -30
  87. package/dist/source/interfaces/state_machine/ua_shelved_state_machine_ex.js +2 -2
  88. package/dist/source/interfaces/state_machine/ua_state_machine_type.d.ts +222 -222
  89. package/dist/source/interfaces/state_machine/ua_state_machine_type.js +2 -2
  90. package/dist/source/interfaces/state_machine/ua_transition_ex.d.ts +6 -6
  91. package/dist/source/interfaces/state_machine/ua_transition_ex.js +2 -2
  92. package/dist/source/interfaces/ua_subscription_diagnostics_variable_ex.d.ts +8 -8
  93. package/dist/source/interfaces/ua_subscription_diagnostics_variable_ex.js +2 -2
  94. package/dist/source/loader/decode_xml_extension_object.d.ts +6 -6
  95. package/dist/source/loader/decode_xml_extension_object.js +71 -71
  96. package/dist/source/loader/ensure_datatype_extracted.d.ts +5 -5
  97. package/dist/source/loader/ensure_datatype_extracted.js +45 -45
  98. package/dist/source/loader/generateAddressSpaceRaw.d.ts +10 -10
  99. package/dist/source/loader/generateAddressSpaceRaw.js +45 -45
  100. package/dist/source/loader/load_nodeset2.d.ts +16 -16
  101. package/dist/source/loader/load_nodeset2.js +1461 -1461
  102. package/dist/source/loader/make_semver_compatible.d.ts +6 -6
  103. package/dist/source/loader/make_semver_compatible.js +25 -25
  104. package/dist/source/loader/make_xml_extension_object_parser.d.ts +28 -28
  105. package/dist/source/loader/make_xml_extension_object_parser.js +325 -325
  106. package/dist/source/loader/namespace_post_step.d.ts +10 -10
  107. package/dist/source/loader/namespace_post_step.js +61 -61
  108. package/dist/source/loader/register_node_promoter.d.ts +2 -2
  109. package/dist/source/loader/register_node_promoter.js +9 -9
  110. package/dist/source/namespace.d.ts +6 -6
  111. package/dist/source/namespace.js +2 -2
  112. package/dist/source/namespace_alarm_and_condition.d.ts +32 -32
  113. package/dist/source/namespace_alarm_and_condition.js +2 -2
  114. package/dist/source/namespace_data_access.d.ts +42 -42
  115. package/dist/source/namespace_data_access.js +2 -2
  116. package/dist/source/namespace_machine_state.d.ts +7 -7
  117. package/dist/source/namespace_machine_state.js +2 -2
  118. package/dist/source/pseudo_session.d.ts +55 -55
  119. package/dist/source/pseudo_session.js +203 -203
  120. package/dist/source/session_context.d.ts +111 -111
  121. package/dist/source/session_context.js +265 -265
  122. package/dist/source/set_namespace_meta_data.d.ts +2 -2
  123. package/dist/source/set_namespace_meta_data.js +59 -59
  124. package/dist/source/ua_root_folder.d.ts +9 -9
  125. package/dist/source/ua_root_folder.js +2 -2
  126. package/dist/source/ua_two_state_variable_ex.d.ts +23 -23
  127. package/dist/source/ua_two_state_variable_ex.js +2 -2
  128. package/dist/source/xml_writer.d.ts +9 -9
  129. package/dist/source/xml_writer.js +2 -2
  130. package/dist/src/address_space.d.ts +392 -392
  131. package/dist/src/address_space.js +1392 -1392
  132. package/dist/src/address_space_change_event_tools.d.ts +6 -6
  133. package/dist/src/address_space_change_event_tools.js +149 -149
  134. package/dist/src/address_space_private.d.ts +43 -43
  135. package/dist/src/address_space_private.js +2 -2
  136. package/dist/src/alarms_and_conditions/check_where_clause.d.ts +4 -0
  137. package/dist/src/alarms_and_conditions/check_where_clause.js +110 -0
  138. package/dist/src/alarms_and_conditions/check_where_clause.js.map +1 -0
  139. package/dist/src/alarms_and_conditions/condition.d.ts +5 -5
  140. package/dist/src/alarms_and_conditions/condition.js +78 -78
  141. package/dist/src/alarms_and_conditions/condition_info.d.ts +27 -0
  142. package/dist/src/alarms_and_conditions/condition_info.js +55 -0
  143. package/dist/src/alarms_and_conditions/condition_info.js.map +1 -0
  144. package/dist/src/alarms_and_conditions/condition_info_impl.d.ts +26 -26
  145. package/dist/src/alarms_and_conditions/condition_info_impl.js +54 -54
  146. package/dist/src/alarms_and_conditions/condition_snapshot.d.ts +233 -0
  147. package/dist/src/alarms_and_conditions/condition_snapshot.js +667 -0
  148. package/dist/src/alarms_and_conditions/condition_snapshot.js.map +1 -0
  149. package/dist/src/alarms_and_conditions/condition_snapshot_impl.d.ts +222 -222
  150. package/dist/src/alarms_and_conditions/condition_snapshot_impl.js +657 -657
  151. package/dist/src/alarms_and_conditions/deviation_alarm_helper.d.ts +9 -9
  152. package/dist/src/alarms_and_conditions/deviation_alarm_helper.js +61 -61
  153. package/dist/src/alarms_and_conditions/extract_event_fields.d.ts +10 -0
  154. package/dist/src/alarms_and_conditions/extract_event_fields.js +90 -0
  155. package/dist/src/alarms_and_conditions/extract_event_fields.js.map +1 -0
  156. package/dist/src/alarms_and_conditions/index.d.ts +16 -16
  157. package/dist/src/alarms_and_conditions/index.js +32 -32
  158. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.d.ts +44 -44
  159. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js +244 -244
  160. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.d.ts +93 -93
  161. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js +419 -419
  162. package/dist/src/alarms_and_conditions/ua_base_event_impl.d.ts +26 -26
  163. package/dist/src/alarms_and_conditions/ua_base_event_impl.js +38 -38
  164. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.d.ts +44 -44
  165. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.js +183 -183
  166. package/dist/src/alarms_and_conditions/ua_condition_impl.d.ts +153 -153
  167. package/dist/src/alarms_and_conditions/ua_condition_impl.js +1028 -1028
  168. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.d.ts +14 -14
  169. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.js +34 -34
  170. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.d.ts +24 -24
  171. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.js +56 -56
  172. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.d.ts +11 -11
  173. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.js +11 -11
  174. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.d.ts +23 -23
  175. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.js +86 -86
  176. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm_impl.d.ts +11 -11
  177. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm_impl.js +7 -7
  178. package/dist/src/alarms_and_conditions/ua_limit_alarm_impl.d.ts +79 -79
  179. package/dist/src/alarms_and_conditions/ua_limit_alarm_impl.js +250 -250
  180. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.d.ts +24 -24
  181. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.js +50 -50
  182. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.d.ts +19 -19
  183. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.js +162 -162
  184. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.d.ts +46 -46
  185. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js +166 -166
  186. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.d.ts +18 -18
  187. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.js +17 -17
  188. package/dist/src/apply_condition_refresh.d.ts +6 -6
  189. package/dist/src/apply_condition_refresh.js +27 -27
  190. package/dist/src/base_node_impl.d.ts +281 -281
  191. package/dist/src/base_node_impl.js +1395 -1395
  192. package/dist/src/base_node_private.d.ts +61 -61
  193. package/dist/src/base_node_private.js +705 -705
  194. package/dist/src/data_access/add_dataItem_stuff.d.ts +11 -11
  195. package/dist/src/data_access/add_dataItem_stuff.js +61 -61
  196. package/dist/src/data_access/check_variant_compatibility_ua_analog_item.d.ts +1 -1
  197. package/dist/src/data_access/check_variant_compatibility_ua_analog_item.js +34 -34
  198. package/dist/src/data_access/ua_multistate_discrete_impl.d.ts +32 -32
  199. package/dist/src/data_access/ua_multistate_discrete_impl.js +130 -130
  200. package/dist/src/data_access/ua_multistate_value_discrete.d.ts +51 -0
  201. package/dist/src/data_access/ua_multistate_value_discrete.js +250 -0
  202. package/dist/src/data_access/ua_multistate_value_discrete.js.map +1 -0
  203. package/dist/src/data_access/ua_multistate_value_discrete_impl.d.ts +51 -51
  204. package/dist/src/data_access/ua_multistate_value_discrete_impl.js +249 -249
  205. package/dist/src/data_access/ua_two_state_discrete.d.ts +25 -0
  206. package/dist/src/data_access/ua_two_state_discrete.js +154 -0
  207. package/dist/src/data_access/ua_two_state_discrete.js.map +1 -0
  208. package/dist/src/data_access/ua_two_state_discrete_impl.d.ts +25 -25
  209. package/dist/src/data_access/ua_two_state_discrete_impl.js +153 -153
  210. package/dist/src/event_data.d.ts +34 -34
  211. package/dist/src/event_data.js +64 -64
  212. package/dist/src/extension_object_array_node.d.ts +61 -61
  213. package/dist/src/extension_object_array_node.js +276 -276
  214. package/dist/src/historical_access/address_space_historical_data_node.d.ts +26 -26
  215. package/dist/src/historical_access/address_space_historical_data_node.js +630 -630
  216. package/dist/src/index_current.d.ts +43 -43
  217. package/dist/src/index_current.js +74 -74
  218. package/dist/src/namespace_impl.d.ts +461 -461
  219. package/dist/src/namespace_impl.js +1732 -1732
  220. package/dist/src/namespace_private.d.ts +21 -21
  221. package/dist/src/namespace_private.js +32 -32
  222. package/dist/src/nodeid_manager.d.ts +36 -36
  223. package/dist/src/nodeid_manager.js +197 -197
  224. package/dist/src/nodeset_tools/adjust_namespace_array.d.ts +2 -2
  225. package/dist/src/nodeset_tools/adjust_namespace_array.js +13 -13
  226. package/dist/src/nodeset_tools/construct_namespace_dependency.d.ts +2 -2
  227. package/dist/src/nodeset_tools/construct_namespace_dependency.js +83 -83
  228. package/dist/src/nodeset_tools/nodeset_to_xml.d.ts +2 -2
  229. package/dist/src/nodeset_tools/nodeset_to_xml.js +1155 -1155
  230. package/dist/src/nodeset_tools/typedictionary_to_xml.d.ts +2 -2
  231. package/dist/src/nodeset_tools/typedictionary_to_xml.js +154 -154
  232. package/dist/src/reference_impl.d.ts +43 -43
  233. package/dist/src/reference_impl.js +139 -139
  234. package/dist/src/role_permissions.d.ts +2 -2
  235. package/dist/src/role_permissions.js +10 -10
  236. package/dist/src/state_machine/finite_state_machine.d.ts +67 -67
  237. package/dist/src/state_machine/finite_state_machine.js +353 -353
  238. package/dist/src/state_machine/ua_shelving_state_machine_ex.d.ts +38 -38
  239. package/dist/src/state_machine/ua_shelving_state_machine_ex.js +250 -250
  240. package/dist/src/state_machine/ua_two_state_variable.d.ts +61 -61
  241. package/dist/src/state_machine/ua_two_state_variable.js +331 -331
  242. package/dist/src/tool_isSupertypeOf.d.ts +17 -17
  243. package/dist/src/tool_isSupertypeOf.js +108 -108
  244. package/dist/src/ua_condition_type.d.ts +8 -8
  245. package/dist/src/ua_condition_type.js +2 -2
  246. package/dist/src/ua_data_type_impl.d.ts +93 -93
  247. package/dist/src/ua_data_type_impl.js +371 -371
  248. package/dist/src/ua_method_impl.d.ts +41 -41
  249. package/dist/src/ua_method_impl.js +208 -208
  250. package/dist/src/ua_object_impl.d.ts +35 -35
  251. package/dist/src/ua_object_impl.js +161 -161
  252. package/dist/src/ua_object_type_impl.d.ts +48 -48
  253. package/dist/src/ua_object_type_impl.js +124 -124
  254. package/dist/src/ua_reference_type_impl.d.ts +43 -43
  255. package/dist/src/ua_reference_type_impl.js +139 -139
  256. package/dist/src/ua_variable_impl.d.ts +351 -351
  257. package/dist/src/ua_variable_impl.js +1604 -1604
  258. package/dist/src/ua_variable_impl.js.map +1 -1
  259. package/dist/src/ua_variable_impl_ext_obj.d.ts +17 -17
  260. package/dist/src/ua_variable_impl_ext_obj.js +437 -437
  261. package/dist/src/ua_variable_type_impl.d.ts +62 -62
  262. package/dist/src/ua_variable_type_impl.js +570 -570
  263. package/dist/src/ua_view_impl.d.ts +19 -19
  264. package/dist/src/ua_view_impl.js +43 -43
  265. package/distHelpers/add_event_generator_object.d.ts +3 -3
  266. package/distHelpers/add_event_generator_object.js +64 -64
  267. package/distHelpers/alarms_and_conditions_demo.d.ts +9 -9
  268. package/distHelpers/alarms_and_conditions_demo.js +115 -115
  269. package/distHelpers/assertHasMatchingReference.d.ts +19 -19
  270. package/distHelpers/assertHasMatchingReference.js +40 -40
  271. package/distHelpers/boiler_system.d.ts +113 -113
  272. package/distHelpers/boiler_system.js +395 -395
  273. package/distHelpers/create_minimalist_address_space_nodeset.d.ts +5 -5
  274. package/distHelpers/create_minimalist_address_space_nodeset.js +171 -171
  275. package/distHelpers/date_utils.d.ts +3 -3
  276. package/distHelpers/date_utils.js +9 -9
  277. package/distHelpers/dump_statemachine.js +127 -127
  278. package/distHelpers/get_address_space_fixture.d.ts +1 -1
  279. package/distHelpers/get_address_space_fixture.js +30 -30
  280. package/distHelpers/get_mini_address_space.d.ts +7 -7
  281. package/distHelpers/get_mini_address_space.js +36 -36
  282. package/distHelpers/index.d.ts +12 -12
  283. package/distHelpers/index.js +28 -28
  284. package/distHelpers/mock_session.d.ts +14 -14
  285. package/distHelpers/mock_session.js +25 -25
  286. package/distNodeJS/generate_address_space.d.ts +4 -4
  287. package/distNodeJS/generate_address_space.js +41 -41
  288. package/distNodeJS/index.d.ts +1 -1
  289. package/distNodeJS/index.js +17 -17
  290. package/package.json +42 -40
  291. package/src/ua_variable_impl.ts +3 -2
@@ -1,1733 +1,1733 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNonEmptyQualifiedName = exports._handle_hierarchy_parent = exports.NamespaceImpl = void 0;
4
- /**
5
- * @module node-opcua-address-space
6
- */
7
- // tslint:disable:no-console
8
- const chalk = require("chalk");
9
- const node_opcua_assert_1 = require("node-opcua-assert");
10
- const node_opcua_basic_types_1 = require("node-opcua-basic-types");
11
- const node_opcua_data_access_1 = require("node-opcua-data-access");
12
- const node_opcua_data_model_1 = require("node-opcua-data-model");
13
- const node_opcua_data_model_2 = require("node-opcua-data-model");
14
- const node_opcua_data_model_3 = require("node-opcua-data-model");
15
- const node_opcua_data_model_4 = require("node-opcua-data-model");
16
- const node_opcua_debug_1 = require("node-opcua-debug");
17
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
18
- const node_opcua_nodeid_2 = require("node-opcua-nodeid");
19
- const node_opcua_status_code_1 = require("node-opcua-status-code");
20
- const node_opcua_types_1 = require("node-opcua-types");
21
- const utils = require("node-opcua-utils");
22
- const node_opcua_variant_1 = require("node-opcua-variant");
23
- const address_space_change_event_tools_1 = require("./address_space_change_event_tools");
24
- const ua_condition_impl_1 = require("./alarms_and_conditions/ua_condition_impl");
25
- const ua_discrete_alarm_impl_1 = require("./alarms_and_conditions/ua_discrete_alarm_impl");
26
- const ua_exclusive_deviation_alarm_impl_1 = require("./alarms_and_conditions/ua_exclusive_deviation_alarm_impl");
27
- const ua_exclusive_limit_alarm_impl_1 = require("./alarms_and_conditions/ua_exclusive_limit_alarm_impl");
28
- const ua_limit_alarm_impl_1 = require("./alarms_and_conditions/ua_limit_alarm_impl");
29
- const ua_non_exclusive_deviation_alarm_impl_1 = require("./alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl");
30
- const ua_non_exclusive_limit_alarm_impl_1 = require("./alarms_and_conditions/ua_non_exclusive_limit_alarm_impl");
31
- const alarms_and_conditions_1 = require("./alarms_and_conditions");
32
- const ua_off_normal_alarm_impl_1 = require("./alarms_and_conditions/ua_off_normal_alarm_impl");
33
- const add_dataItem_stuff_1 = require("./data_access/add_dataItem_stuff");
34
- const ua_multistate_discrete_impl_1 = require("./data_access/ua_multistate_discrete_impl");
35
- // state machine
36
- const ua_two_state_variable_1 = require("./state_machine/ua_two_state_variable");
37
- //
38
- const namespace_private_1 = require("./namespace_private");
39
- const base_node_impl_1 = require("./base_node_impl");
40
- const ua_variable_impl_1 = require("./ua_variable_impl");
41
- const nodeid_manager_1 = require("./nodeid_manager");
42
- const ua_two_state_discrete_impl_1 = require("./data_access/ua_two_state_discrete_impl");
43
- const role_permissions_1 = require("./role_permissions");
44
- const ua_object_impl_1 = require("./ua_object_impl");
45
- const ua_data_type_impl_1 = require("./ua_data_type_impl");
46
- const ua_object_type_impl_1 = require("./ua_object_type_impl");
47
- const ua_method_impl_1 = require("./ua_method_impl");
48
- const ua_variable_type_impl_1 = require("./ua_variable_type_impl");
49
- const ua_reference_type_impl_1 = require("./ua_reference_type_impl");
50
- const ua_view_impl_1 = require("./ua_view_impl");
51
- const ua_multistate_value_discrete_impl_1 = require("./data_access/ua_multistate_value_discrete_impl");
52
- function _makeHashKey(nodeId) {
53
- switch (nodeId.identifierType) {
54
- case node_opcua_nodeid_1.NodeIdType.STRING:
55
- case node_opcua_nodeid_1.NodeIdType.GUID:
56
- return nodeId.value;
57
- case node_opcua_nodeid_1.NodeIdType.NUMERIC:
58
- return nodeId.value;
59
- default:
60
- // istanbul ignore next
61
- if (nodeId.identifierType !== node_opcua_nodeid_1.NodeIdType.BYTESTRING) {
62
- throw new Error("invalid nodeIdType");
63
- }
64
- return nodeId.value ? nodeId.value.toString() : "OPAQUE:0";
65
- }
66
- }
67
- const doDebug = false;
68
- const errorLog = (0, node_opcua_debug_1.make_errorLog)("AddressSpace");
69
- const regExp1 = /^(s|i|b|g)=/;
70
- const regExpNamespaceDotBrowseName = /^[0-9]+:(.*)/;
71
- function detachNode(node) {
72
- const addressSpace = node.addressSpace;
73
- const nonHierarchicalReferences = node.findReferencesEx("NonHierarchicalReferences", node_opcua_data_model_3.BrowseDirection.Inverse);
74
- for (const ref of nonHierarchicalReferences) {
75
- (0, node_opcua_assert_1.assert)(!ref.isForward);
76
- ref.node.removeReference({
77
- isForward: !ref.isForward,
78
- nodeId: node.nodeId,
79
- referenceType: ref.referenceType
80
- });
81
- }
82
- const nonHierarchicalReferencesF = node.findReferencesEx("NonHierarchicalReferences", node_opcua_data_model_3.BrowseDirection.Forward);
83
- for (const ref of nonHierarchicalReferencesF) {
84
- if (!ref.node) {
85
- // could be a special case of a frequently use target node such as ModellingRule_Mandatory that do not back trace
86
- // their reference
87
- continue;
88
- }
89
- (0, node_opcua_assert_1.assert)(ref.isForward);
90
- ref.node.removeReference({
91
- isForward: !ref.isForward,
92
- nodeId: node.nodeId,
93
- referenceType: ref.referenceType
94
- });
95
- }
96
- // remove reversed Hierarchical references
97
- const hierarchicalReferences = node.findReferencesEx("HierarchicalReferences", node_opcua_data_model_3.BrowseDirection.Inverse);
98
- for (const ref of hierarchicalReferences) {
99
- (0, node_opcua_assert_1.assert)(!ref.isForward);
100
- const parent = addressSpace.findNode(ref.nodeId);
101
- parent.removeReference({
102
- isForward: !ref.isForward,
103
- nodeId: node.nodeId,
104
- referenceType: ref.referenceType
105
- });
106
- }
107
- node.unpropagate_back_references();
108
- }
109
- /**
110
- *
111
- * @constructor
112
- * @params options {Object}
113
- * @params options.namespaceUri {string}
114
- * @params options.addressSpace {IAddressSpace}
115
- * @params options.index {number}
116
- * @params options.version="" {string}
117
- * @params options.publicationDate="" {Date}
118
- *
119
- */
120
- class NamespaceImpl {
121
- constructor(options) {
122
- this.version = "0.0.0";
123
- this.publicationDate = new Date(Date.UTC(1900, 0, 1));
124
- // istanbul ignore next
125
- if (!(typeof options.namespaceUri === "string")) {
126
- throw new Error("NamespaceImpl constructor: namespaceUri must exists and be a string : got " + options.namespaceUri);
127
- }
128
- // istanbul ignore next
129
- if (typeof options.index !== "number") {
130
- throw new Error("NamespaceImpl constructor: index must be a number");
131
- }
132
- // istanbul ignore next
133
- if (!options.addressSpace) {
134
- throw new Error("NamespaceImpl constructor: Must specify a valid address space");
135
- }
136
- this.namespaceUri = options.namespaceUri;
137
- this.addressSpace = options.addressSpace;
138
- this.index = options.index;
139
- this._nodeid_index = new Map();
140
- this._aliases = new Map();
141
- this._objectTypeMap = new Map();
142
- this._variableTypeMap = new Map();
143
- this._referenceTypeMap = new Map();
144
- this._referenceTypeMapInv = new Map();
145
- this._dataTypeMap = new Map();
146
- this._nodeIdManager = new nodeid_manager_1.NodeIdManager(this.index, this.addressSpace);
147
- }
148
- getDefaultNamespace() {
149
- return this.index === 0 ? this : this.addressSpace.getDefaultNamespace();
150
- }
151
- dispose() {
152
- for (const node of this.nodeIterator()) {
153
- node.dispose();
154
- }
155
- this._nodeid_index = new Map();
156
- this._aliases = new Map();
157
- this.addressSpace = {};
158
- this._objectTypeMap = new Map();
159
- this._variableTypeMap = new Map();
160
- this._referenceTypeMap = new Map();
161
- this._referenceTypeMapInv = new Map();
162
- this._dataTypeMap = new Map();
163
- }
164
- nodeIterator() {
165
- return this._nodeid_index.values();
166
- }
167
- _objectTypeIterator() {
168
- return this._objectTypeMap.values();
169
- }
170
- _objectTypeCount() {
171
- return this._objectTypeMap.size;
172
- }
173
- _variableTypeIterator() {
174
- return this._variableTypeMap.values();
175
- }
176
- _variableTypeCount() {
177
- return this._variableTypeMap.size;
178
- }
179
- _dataTypeIterator() {
180
- return this._dataTypeMap.values();
181
- }
182
- _dataTypeCount() {
183
- return this._dataTypeMap.size;
184
- }
185
- _referenceTypeIterator() {
186
- return this._referenceTypeMap.values();
187
- }
188
- _referenceTypeCount() {
189
- return this._referenceTypeMap.size;
190
- }
191
- _aliasCount() {
192
- return this._aliases.size;
193
- }
194
- findNode2(nodeId) {
195
- // this one is faster assuming you have a nodeId
196
- (0, node_opcua_assert_1.assert)(nodeId.namespace === this.index);
197
- return this._nodeid_index.get(_makeHashKey(nodeId)) || null;
198
- }
199
- findNode(nodeId) {
200
- if (typeof nodeId === "string") {
201
- if (nodeId.match(regExp1)) {
202
- nodeId = "ns=" + this.index + ";" + nodeId;
203
- }
204
- }
205
- nodeId = (0, node_opcua_nodeid_1.resolveNodeId)(nodeId);
206
- return this.findNode2(nodeId);
207
- }
208
- /**
209
- *
210
- * @param objectTypeName {String}
211
- * @return {UAObjectType|null}
212
- */
213
- findObjectType(objectTypeName) {
214
- return this._objectTypeMap.get(objectTypeName) || null;
215
- }
216
- /**
217
- *
218
- * @param variableTypeName {String}
219
- * @returns {UAVariableType|null}
220
- */
221
- findVariableType(variableTypeName) {
222
- return this._variableTypeMap.get(variableTypeName) || null;
223
- }
224
- /**
225
- *
226
- * @param dataTypeName {String}
227
- * @returns {UADataType|null}
228
- */
229
- findDataType(dataTypeName) {
230
- return this._dataTypeMap.get(dataTypeName) || null;
231
- }
232
- /**
233
- *
234
- * @param referenceTypeName {String}
235
- * @returns {ReferenceType|null}
236
- */
237
- findReferenceType(referenceTypeName) {
238
- return this._referenceTypeMap.get(referenceTypeName) || null;
239
- }
240
- /**
241
- * find a ReferenceType by its inverse name.
242
- * @method findReferenceTypeFromInverseName
243
- * @param inverseName {String} the inverse name of the ReferenceType to find
244
- * @return {ReferenceType}
245
- */
246
- findReferenceTypeFromInverseName(inverseName) {
247
- (0, node_opcua_assert_1.assert)(typeof inverseName === "string");
248
- const node = this._referenceTypeMapInv.get(inverseName);
249
- (0, node_opcua_assert_1.assert)(!node || (node.nodeClass === node_opcua_data_model_4.NodeClass.ReferenceType && node.inverseName.text === inverseName));
250
- return node ? node : null;
251
- }
252
- /**
253
- *
254
- * @method addAlias
255
- * @param alias_name {String} the alias name
256
- * @param nodeId {NodeId} NodeId must belong to this namespace
257
- */
258
- addAlias(alias_name, nodeId) {
259
- (0, node_opcua_assert_1.assert)(typeof alias_name === "string");
260
- (0, node_opcua_assert_1.assert)(nodeId instanceof node_opcua_nodeid_2.NodeId);
261
- (0, node_opcua_assert_1.assert)(nodeId.namespace === this.index);
262
- this._aliases.set(alias_name, nodeId);
263
- }
264
- resolveAlias(name) {
265
- return this._aliases.get(name) || null;
266
- }
267
- /**
268
- * add a new Object type to the address space
269
- * @method addObjectType
270
- * @param options
271
- * @param options.browseName {String} the object type name
272
- * @param [options.displayName] {String|LocalizedText} the display name
273
- * @param [options.subtypeOf="BaseObjectType"] {String|NodeId|BaseNode} the base class
274
- * @param [options.nodeId] {String|NodeId} an optional nodeId for this objectType,
275
- * if not provided a new nodeId will be created
276
- * @param [options.isAbstract = false] {Boolean}
277
- * @param [options.eventNotifier = 0] {Integer}
278
- * @param [options.postInstantiateFunc = null] {Function}
279
- *
280
- */
281
- addObjectType(options) {
282
- (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(options, "dataType"), "an objectType should not have a dataType");
283
- (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(options, "valueRank"), "an objectType should not have a valueRank");
284
- (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(options, "arrayDimensions"), "an objectType should not have a arrayDimensions");
285
- return this._addObjectOrVariableType(options, "BaseObjectType", node_opcua_data_model_4.NodeClass.ObjectType);
286
- }
287
- /**
288
- * add a new Variable type to the address space
289
- * @method addVariableType
290
- * @param options
291
- * @param options.browseName {String} the object type name
292
- * @param [options.displayName] {String|LocalizedText} the display name
293
- * @param [options.subtypeOf="BaseVariableType"] {String|NodeId|BaseNode} the base class
294
- * @param [options.nodeId] {String|NodeId} an optional nodeId for this objectType,
295
- * if not provided a new nodeId will be created
296
- * @param [options.isAbstract = false] {Boolean}
297
- * @param options.dataType {String|NodeId} the variable DataType
298
- * @param [options.valueRank = -1]
299
- * @param [options.arrayDimensions = null] { Array<Int>>
300
- *
301
- */
302
- addVariableType(options) {
303
- (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(options, "arrayDimension"), "Do you mean ArrayDimensions ?");
304
- // dataType
305
- options.dataType = options.dataType || "Int32";
306
- options.dataType = this.addressSpace._coerce_DataType(options.dataType);
307
- // valueRank/ arrayDimensions
308
- (0, node_opcua_variant_1.verifyRankAndDimensions)(options);
309
- // arrayDimensions
310
- const variableType = this._addObjectOrVariableType(options, "BaseVariableType", node_opcua_data_model_4.NodeClass.VariableType);
311
- variableType.dataType = options.dataType;
312
- variableType.valueRank = options.valueRank || 0;
313
- variableType.arrayDimensions = options.arrayDimensions;
314
- return variableType;
315
- }
316
- /**
317
- * add a variable as a component of the parent node
318
- *
319
- * @method addVariable
320
- * @param options
321
- * @param options.browseName the variable name
322
- * @param options.dataType the variable datatype ( "Double", "UInt8" etc...)
323
- * @param [options.typeDefinition="BaseDataVariableType"]
324
- * @param [options.modellingRule=null] the Modelling rule : "Optional" , "Mandatory"
325
- * @param [options.valueRank= -1] the valueRank
326
- * @param [options.arrayDimensions]
327
- * @return UAVariable
328
- */
329
- addVariable(options) {
330
- (0, node_opcua_assert_1.assert)(arguments.length === 1, "Invalid arguments IAddressSpace#addVariable now takes only one argument.");
331
- if (Object.prototype.hasOwnProperty.call(options, "propertyOf") && options.propertyOf) {
332
- (0, node_opcua_assert_1.assert)(!options.typeDefinition || options.typeDefinition === "PropertyType");
333
- options.typeDefinition = options.typeDefinition || "PropertyType";
334
- }
335
- else {
336
- (0, node_opcua_assert_1.assert)(!options.typeDefinition || options.typeDefinition !== "PropertyType");
337
- }
338
- return this._addVariable(options);
339
- }
340
- addView(options) {
341
- (0, node_opcua_assert_1.assert)(arguments.length === 1, "Namespace#addView expecting a single argument");
342
- (0, node_opcua_assert_1.assert)(options);
343
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "browseName"));
344
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "organizedBy"));
345
- const browseName = options.browseName;
346
- (0, node_opcua_assert_1.assert)(typeof browseName === "string");
347
- const addressSpace = this.addressSpace;
348
- const baseDataVariableTypeId = addressSpace.findVariableType("BaseDataVariableType").nodeId;
349
- // ------------------------------------------ TypeDefinition
350
- const typeDefinition = options.typeDefinition || baseDataVariableTypeId;
351
- options.references = options.references || [];
352
- options.references.push({
353
- isForward: true,
354
- nodeId: typeDefinition,
355
- referenceType: "HasTypeDefinition"
356
- });
357
- // xx assert(this.FolderTypeId && this.BaseObjectTypeId); // is default address space generated.?
358
- const createOptions = options;
359
- (0, node_opcua_assert_1.assert)(!createOptions.nodeClass);
360
- createOptions.nodeClass = node_opcua_data_model_4.NodeClass.View;
361
- const view = this.createNode(createOptions);
362
- (0, node_opcua_assert_1.assert)(view.nodeId instanceof node_opcua_nodeid_2.NodeId);
363
- (0, node_opcua_assert_1.assert)(view.nodeClass === node_opcua_data_model_4.NodeClass.View);
364
- return view;
365
- }
366
- addObject(options1) {
367
- const options = options1;
368
- (0, node_opcua_assert_1.assert)(!options.nodeClass || options.nodeClass === node_opcua_data_model_4.NodeClass.Object);
369
- options.nodeClass = node_opcua_data_model_4.NodeClass.Object;
370
- const typeDefinition = options.typeDefinition || "BaseObjectType";
371
- options.references = options.references || [];
372
- options.references.push({ referenceType: "HasTypeDefinition", isForward: true, nodeId: typeDefinition });
373
- options.eventNotifier = +options.eventNotifier;
374
- const obj = this.createNode(options);
375
- (0, node_opcua_assert_1.assert)(obj instanceof ua_object_impl_1.UAObjectImpl);
376
- (0, node_opcua_assert_1.assert)(obj.nodeClass === node_opcua_data_model_4.NodeClass.Object);
377
- return obj;
378
- }
379
- /**
380
- *
381
- * @method addFolder
382
- * @param parentFolder
383
- * @param options {String|Object}
384
- * @param options.browseName {String} the name of the folder
385
- * @param [options.nodeId] {NodeId}. An optional nodeId for this object
386
- *
387
- * @return {BaseNode}
388
- */
389
- addFolder(parentFolder, options) {
390
- if (typeof options === "string") {
391
- options = { browseName: options };
392
- }
393
- const addressSpace = this.addressSpace;
394
- (0, node_opcua_assert_1.assert)(!options.typeDefinition, "addFolder does not expect typeDefinition to be defined ");
395
- const typeDefinition = addressSpace._coerceTypeDefinition("FolderType");
396
- parentFolder = addressSpace._coerceFolder(parentFolder);
397
- options.nodeClass = node_opcua_data_model_4.NodeClass.Object;
398
- options.references = [
399
- { referenceType: "HasTypeDefinition", isForward: true, nodeId: typeDefinition },
400
- { referenceType: "Organizes", isForward: false, nodeId: parentFolder.nodeId }
401
- ];
402
- const node = this.createNode(options);
403
- return node;
404
- }
405
- /**
406
- * @method addReferenceType
407
- * @param options
408
- * @param options.isAbstract
409
- * @param options.browseName
410
- * @param options.inverseName
411
- */
412
- addReferenceType(options) {
413
- const addressSpace = this.addressSpace;
414
- const options1 = options;
415
- options1.nodeClass = node_opcua_data_model_4.NodeClass.ReferenceType;
416
- options1.references = options1.references || [];
417
- if (options.subtypeOf) {
418
- const subtypeOfNodeId = addressSpace._coerceType(options.subtypeOf, "References", node_opcua_data_model_4.NodeClass.ReferenceType);
419
- (0, node_opcua_assert_1.assert)(subtypeOfNodeId);
420
- options1.references.push({
421
- isForward: false,
422
- nodeId: subtypeOfNodeId,
423
- referenceType: "HasSubtype"
424
- });
425
- }
426
- const node = this.internalCreateNode(options1);
427
- node.propagate_back_references();
428
- return node;
429
- }
430
- /**
431
- */
432
- addMultiStateDiscrete(options) {
433
- return (0, ua_multistate_discrete_impl_1._addMultiStateDiscrete)(this, options);
434
- }
435
- /**
436
- * @method createDataType
437
- */
438
- createDataType(options) {
439
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "isAbstract"), "must provide isAbstract");
440
- (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(options, "nodeClass"));
441
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "browseName"), "must provide a browseName");
442
- const options1 = options;
443
- options1.nodeClass = node_opcua_data_model_4.NodeClass.DataType;
444
- options1.references = options.references || [];
445
- if (options1.references.length === 0) {
446
- if (!options1.subtypeOf) {
447
- throw new Error("must provide a subtypeOf");
448
- }
449
- }
450
- if (options1.subtypeOf) {
451
- if (!(options1.subtypeOf instanceof ua_data_type_impl_1.UADataTypeImpl)) {
452
- options1.subtypeOf = this.addressSpace.findDataType(options1.subtypeOf);
453
- }
454
- if (!options1.subtypeOf) {
455
- throw new Error("cannot find subtypeOf ");
456
- }
457
- options1.references.push({
458
- isForward: false,
459
- nodeId: options1.subtypeOf.nodeId,
460
- referenceType: "HasSubtype"
461
- });
462
- }
463
- const node = this.internalCreateNode(options);
464
- return node;
465
- }
466
- /**
467
- * @method createNode
468
- * @param options
469
- * @param options.nodeClass
470
- * @param [options.nodeVersion {String} = "0" ] install nodeVersion
471
- * @param [options.modellingRule {String} = null]
472
- * @internal
473
- */
474
- createNode(options) {
475
- let node = null;
476
- const addressSpace = this.addressSpace;
477
- addressSpace.modelChangeTransaction(() => {
478
- (0, node_opcua_assert_1.assert)(isNonEmptyQualifiedName(options.browseName));
479
- // xx assert(Object.prototype.hasOwnProperty.call(options,"browseName") && options.browseName.length > 0);
480
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "nodeClass"));
481
- options.references = addressSpace.normalizeReferenceTypes(options.references);
482
- const references = _copy_references(options.references);
483
- _handle_hierarchy_parent(addressSpace, references, options);
484
- _handle_event_hierarchy_parent(addressSpace, references, options);
485
- (0, namespace_private_1.UANamespace_process_modelling_rule)(references, options.modellingRule);
486
- options.references = references;
487
- node = this.internalCreateNode(options);
488
- (0, node_opcua_assert_1.assert)(node.nodeId instanceof node_opcua_nodeid_2.NodeId);
489
- node.propagate_back_references();
490
- node.install_extra_properties();
491
- _handle_node_version(node, options);
492
- (0, address_space_change_event_tools_1._handle_model_change_event)(node);
493
- });
494
- return node;
495
- }
496
- /**
497
- * remove the specified Node from the address space
498
- *
499
- * @method deleteNode
500
- * @param nodeOrNodeId
501
- *
502
- *
503
- */
504
- deleteNode(nodeOrNodeId) {
505
- let node = null;
506
- let nodeId = new node_opcua_nodeid_2.NodeId();
507
- if (nodeOrNodeId instanceof node_opcua_nodeid_2.NodeId) {
508
- nodeId = nodeOrNodeId;
509
- node = this.findNode(nodeId);
510
- // istanbul ignore next
511
- if (!node) {
512
- throw new Error(" deleteNode : cannot find node with nodeId" + nodeId.toString());
513
- }
514
- }
515
- else if (nodeOrNodeId instanceof base_node_impl_1.BaseNodeImpl) {
516
- node = nodeOrNodeId;
517
- nodeId = node.nodeId;
518
- }
519
- // istanbul ignore next
520
- if (nodeId.namespace !== this.index) {
521
- throw new Error("this node doesn't belong to this namespace");
522
- }
523
- const addressSpace = this.addressSpace;
524
- addressSpace.modelChangeTransaction(() => {
525
- /* istanbul ignore next */
526
- if (!node) {
527
- throw new Error("this node doesn't belong to this namespace");
528
- }
529
- // notify parent that node is being removed
530
- const hierarchicalReferences = node.findReferencesEx("HierarchicalReferences", node_opcua_data_model_3.BrowseDirection.Inverse);
531
- for (const ref of hierarchicalReferences) {
532
- (0, node_opcua_assert_1.assert)(!ref.isForward);
533
- const parent = addressSpace.findNode(ref.nodeId);
534
- (0, node_opcua_assert_1.assert)(parent);
535
- parent._on_child_removed(node);
536
- }
537
- function deleteNodePointedByReference(ref) {
538
- const o = addressSpace.findNode(ref.nodeId);
539
- addressSpace.deleteNode(o.nodeId);
540
- }
541
- // recursively delete all nodes below in the hierarchy of nodes
542
- // TODO : a better idea would be to extract any references of type "HasChild"
543
- const components = node.findReferencesEx("HasComponent", node_opcua_data_model_3.BrowseDirection.Forward);
544
- const properties = node.findReferencesEx("HasProperty", node_opcua_data_model_3.BrowseDirection.Forward);
545
- // TODO: shall we delete nodes pointed by "Organizes" links here ?
546
- const subFolders = node.findReferencesEx("Organizes", node_opcua_data_model_3.BrowseDirection.Forward);
547
- for (const r of components) {
548
- deleteNodePointedByReference(r);
549
- }
550
- for (const r of properties) {
551
- deleteNodePointedByReference(r);
552
- }
553
- for (const r of subFolders) {
554
- deleteNodePointedByReference(r);
555
- }
556
- (0, address_space_change_event_tools_1._handle_delete_node_model_change_event)(node);
557
- detachNode(node);
558
- // delete nodes from global index
559
- const namespace = addressSpace.getNamespace(node.nodeId.namespace);
560
- namespace._deleteNode(node);
561
- });
562
- }
563
- /**
564
- * @internals
565
- */
566
- getStandardsNodeIds() {
567
- const standardNodeIds = {
568
- objectTypeIds: {},
569
- referenceTypeIds: {}
570
- };
571
- for (const referenceType of this._referenceTypeMap.values()) {
572
- standardNodeIds.referenceTypeIds[referenceType.browseName.name] = referenceType.nodeId.toString();
573
- }
574
- for (const objectType of this._objectTypeMap.values()) {
575
- standardNodeIds.objectTypeIds[objectType.browseName.name] = objectType.nodeId.toString();
576
- }
577
- return standardNodeIds;
578
- }
579
- // - Events --------------------------------------------------------------------------------------
580
- /**
581
- * add a new event type to the address space
582
- * @method addEventType
583
- * @param options
584
- * @param options.browseName {String} the eventType name
585
- * @param [options.subtypeOf ="BaseEventType"]
586
- * @param [options.isAbstract = true]
587
- * @return {UAObjectType} : the object type
588
- *
589
- * @example
590
- *
591
- * var evtType = namespace.addEventType({
592
- * browseName: "MyAuditEventType",
593
- * subtypeOf: "AuditEventType"
594
- * });
595
- * var myConditionType = namespace.addEventType({
596
- * browseName: "MyConditionType",
597
- * subtypeOf: "ConditionType",
598
- * isAbstract: false
599
- * });
600
- *
601
- */
602
- addEventType(options) {
603
- options.subtypeOf = options.subtypeOf || "BaseEventType";
604
- // are eventType always abstract ?? No => Condition can be instantiated!
605
- // but, by default is abstract is true
606
- options.isAbstract = Object.prototype.hasOwnProperty.call(options, "isAbstract") ? !!options.isAbstract : true;
607
- return this.addObjectType(options);
608
- }
609
- // ---------------------------------------------------------------------------------------------------
610
- /**
611
- * @method addDataItem
612
- * @param options
613
- * @param options.browseName {String}
614
- * @param options.definition {String}
615
- * @param [options.valuePrecision {Double |null} =null]
616
- * @param options.dataType {NodeId} // todo :check
617
- * @param options.value
618
- * @param options.componentOf
619
- * @return {UAVariable}
620
- */
621
- addDataItem(options) {
622
- const addressSpace = this.addressSpace;
623
- const dataType = options.dataType || "Number";
624
- const dataItemType = addressSpace.findVariableType("DataItemType");
625
- if (!dataItemType) {
626
- throw new Error("Cannot find DataItemType");
627
- }
628
- const variable = this.addVariable(Object.assign(Object.assign({}, options), { dataType, typeDefinition: dataItemType.nodeId }));
629
- (0, add_dataItem_stuff_1.add_dataItem_stuff)(variable, options);
630
- variable.install_extra_properties();
631
- return variable;
632
- }
633
- /**
634
- *
635
- * @method addAnalogDataItem
636
- *
637
- * AnalogDataItem DataItems that represent continuously-variable physical quantities ( e.g., length, temperature),
638
- * in contrast to the digital representation of data in discrete items
639
- * NOTE Typical examples are the values provided by temperature sensors or pressure sensors. OPC UA defines a
640
- * specific UAVariableType to identify an AnalogItem. Properties describe the possible ranges of AnalogItems.
641
- *
642
- *
643
- * @example:
644
- *
645
- *
646
- * namespace.add_analog_dataItem({
647
- * componentOf: parentObject,
648
- * browseName: "TemperatureSensor",
649
- *
650
- * definition: "(tempA -25) + tempB",
651
- * valuePrecision: 0.5,
652
- * //-
653
- * instrumentRange: { low: 100 , high: 200}, // optional
654
- * engineeringUnitsRange: { low: 100 , high: 200}, // mandatory
655
- * engineeringUnits: standardUnits.degree_celsius,, // optional
656
- *
657
- * // access level
658
- * accessLevel: 1
659
- * minimumSamplingInterval: 10,
660
- *
661
- * });
662
- *
663
-
664
- * @return {UAVariable}
665
- */
666
- addAnalogDataItem(options) {
667
- const addressSpace = this.addressSpace;
668
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "engineeringUnitsRange"), "expecting engineeringUnitsRange");
669
- const dataType = options.dataType || "Number";
670
- const analogItemType = addressSpace.findVariableType("AnalogItemType");
671
- if (!analogItemType) {
672
- throw new Error("expecting AnalogItemType to be defined , check nodeset xml file");
673
- }
674
- const clone_options = Object.assign(Object.assign({}, options), { dataType, typeDefinition: analogItemType.nodeId });
675
- const variable = this.addVariable(clone_options);
676
- (0, add_dataItem_stuff_1.add_dataItem_stuff)(variable, options);
677
- // mandatory (EURange in the specs)
678
- // OPC Unified Architecture, Part 8 6 Release 1.02
679
- // EURange defines the value range likely to be obtained in normal operation. It is intended for such
680
- // use as automatically scaling a bar graph display
681
- // Sensor or instrument failure or deactivation can result in a return ed item value which is actually
682
- // outside of this range. Client software must be prepared to deal with this possibility. Similarly a client
683
- // may attempt to write a value that is outside of this range back to the server. The exact behavior
684
- // (accept, reject, clamp, etc.) in this case is server - dependent. However , in general servers shall be
685
- // prepared to handle this.
686
- // Example: EURange ::= {-200.0,1400.0}
687
- const euRange = this.addVariable({
688
- browseName: { name: "EURange", namespaceIndex: 0 },
689
- dataType: "Range",
690
- minimumSamplingInterval: 0,
691
- modellingRule: options.modellingRule,
692
- propertyOf: variable,
693
- typeDefinition: "PropertyType",
694
- value: new node_opcua_variant_1.Variant({
695
- dataType: node_opcua_variant_1.DataType.ExtensionObject,
696
- value: new node_opcua_types_1.Range(options.engineeringUnitsRange)
697
- })
698
- });
699
- (0, node_opcua_assert_1.assert)(euRange.readValue().value.value instanceof node_opcua_types_1.Range);
700
- const handler = variable.handle_semantic_changed.bind(variable);
701
- euRange.on("value_changed", handler);
702
- if (Object.prototype.hasOwnProperty.call(options, "instrumentRange")) {
703
- const instrumentRange = this.addVariable({
704
- accessLevel: "CurrentRead | CurrentWrite",
705
- browseName: { name: "InstrumentRange", namespaceIndex: 0 },
706
- dataType: "Range",
707
- minimumSamplingInterval: 0,
708
- modellingRule: options.modellingRule ? "Mandatory" : undefined,
709
- propertyOf: variable,
710
- typeDefinition: "PropertyType",
711
- value: new node_opcua_variant_1.Variant({
712
- dataType: node_opcua_variant_1.DataType.ExtensionObject,
713
- value: new node_opcua_types_1.Range(options.instrumentRange)
714
- })
715
- });
716
- instrumentRange.on("value_changed", handler);
717
- }
718
- if (Object.prototype.hasOwnProperty.call(options, "engineeringUnits")) {
719
- const engineeringUnits = new node_opcua_types_1.EUInformation(options.engineeringUnits);
720
- (0, node_opcua_assert_1.assert)(engineeringUnits instanceof node_opcua_types_1.EUInformation, "expecting engineering units");
721
- // EngineeringUnits specifies the units for the DataItem‟s value (e.g., degree, hertz, seconds). The
722
- // EUInformation type is specified in 5.6.3.
723
- const eu = this.addVariable({
724
- accessLevel: "CurrentRead",
725
- browseName: { name: "EngineeringUnits", namespaceIndex: 0 },
726
- dataType: "EUInformation",
727
- minimumSamplingInterval: 0,
728
- modellingRule: options.modellingRule ? "Mandatory" : undefined,
729
- propertyOf: variable,
730
- typeDefinition: "PropertyType",
731
- value: new node_opcua_variant_1.Variant({
732
- dataType: node_opcua_variant_1.DataType.ExtensionObject,
733
- value: engineeringUnits
734
- })
735
- });
736
- eu.on("value_changed", handler);
737
- }
738
- variable.install_extra_properties();
739
- return variable;
740
- }
741
- /**
742
- *
743
- * @method addMultiStateValueDiscrete
744
- * @param options {Object}
745
- * @param options.browseName {String}
746
- * @param [options.nodeId {NodeId}]
747
- * @param [options.value {UInt32} = 0 }
748
- * @param options.enumValues { EnumValueType[]| {Key,Value} }
749
- * @return {Object|UAVariable}
750
- *
751
- * @example
752
- *
753
- *
754
- * namespace.addMultiStateValueDiscrete({
755
- * componentOf:parentObj,
756
- * browseName: "myVar",
757
- * enumValues: {
758
- * "Red": 0xFF0000,
759
- * "Green": 0x00FF00,
760
- * "Blue": 0x0000FF
761
- * }
762
- * });
763
- * addMultiStateValueDiscrete(parentObj,{
764
- * browseName: "myVar",
765
- * enumValues: [
766
- * {
767
- * value: 0xFF0000,
768
- * displayName: "Red",
769
- * description: " The color Red"
770
- * },
771
- * {
772
- * value: 0x00FF000,
773
- * displayName: "Green",
774
- * description: " The color Green"
775
- * },
776
- * {
777
- * value: 0x0000FF,
778
- * displayName: "Blue",
779
- * description: " The color Blue"
780
- * }
781
- *
782
- * ]
783
- * });
784
- */
785
- addMultiStateValueDiscrete(options) {
786
- return (0, ua_multistate_value_discrete_impl_1._addMultiStateValueDiscrete)(this, options);
787
- }
788
- // -
789
- /**
790
- *
791
- * @method addYArrayItem
792
- * @param options
793
- * @param options.componentOf {NodeId}
794
- * @param options.browseName {String}
795
- * @param options.title {String}
796
- * @param [options.instrumentRange]
797
- * @param [options.instrumentRange.low] {Double}
798
- * @param [options.instrumentRange.high] {Double}
799
- * @param options.engineeringUnitsRange.low {Double}
800
- * @param options.engineeringUnitsRange.high {Double}
801
- * @param options.engineeringUnits {String}
802
- * @param [options.nodeId = {NodeId}]
803
- * @param options.accessLevel
804
- * @param options.userAccessLevel
805
- * @param options.title {String}
806
- * @param options.axisScaleType {AxisScaleEnumeration}
807
- *
808
- * @param options.xAxisDefinition {AxisInformation}
809
- * @param options.xAxisDefinition.engineeringUnits EURange
810
- * @param options.xAxisDefinition.range
811
- * @param options.xAxisDefinition.range.low
812
- * @param options.xAxisDefinition.range.high
813
- * @param options.xAxisDefinition.title {LocalizedText}
814
- * @param options.xAxisDefinition.axisScaleType {AxisScaleEnumeration}
815
- * @param options.xAxisDefinition.axisSteps = <null> {Array<Double>}
816
- * @param options.value
817
- */
818
- addYArrayItem(options) {
819
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "engineeringUnitsRange"), "expecting engineeringUnitsRange");
820
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "axisScaleType"), "expecting axisScaleType");
821
- (0, node_opcua_assert_1.assert)(options.xAxisDefinition !== null && typeof options.xAxisDefinition === "object", "expecting a xAxisDefinition");
822
- const addressSpace = this.addressSpace;
823
- const YArrayItemType = addressSpace.findVariableType("YArrayItemType");
824
- if (!YArrayItemType) {
825
- throw new Error("expecting YArrayItemType to be defined , check nodeset xml file");
826
- }
827
- function toNodeId(options) {
828
- if (!options) {
829
- return (0, node_opcua_nodeid_1.resolveNodeId)(node_opcua_variant_1.DataType.Float);
830
- }
831
- if (Object.prototype.hasOwnProperty.call(options, "nodeId") || options instanceof base_node_impl_1.BaseNodeImpl) {
832
- return options.nodeId;
833
- }
834
- return (0, node_opcua_nodeid_1.resolveNodeId)(options);
835
- }
836
- const dataType = toNodeId(options.dataType);
837
- const optionals = [];
838
- if (Object.prototype.hasOwnProperty.call(options, "instrumentRange")) {
839
- optionals.push("InstrumentRange");
840
- }
841
- const variable = YArrayItemType.instantiate({
842
- browseName: options.browseName,
843
- componentOf: options.componentOf,
844
- dataType,
845
- optionals
846
- });
847
- function coerceAxisScale(value) {
848
- const ret = node_opcua_data_access_1.AxisScaleEnumeration[value];
849
- (0, node_opcua_assert_1.assert)(!utils.isNullOrUndefined(ret));
850
- return ret;
851
- }
852
- variable.setValueFromSource(options.value, node_opcua_status_code_1.StatusCodes.Good);
853
- variable.euRange.setValueFromSource(new node_opcua_variant_1.Variant({
854
- dataType: node_opcua_variant_1.DataType.ExtensionObject,
855
- value: new node_opcua_types_1.Range(options.engineeringUnitsRange)
856
- }));
857
- if (Object.prototype.hasOwnProperty.call(options, "instrumentRange") && variable.instrumentRange) {
858
- variable.instrumentRange.setValueFromSource(new node_opcua_variant_1.Variant({
859
- dataType: node_opcua_variant_1.DataType.ExtensionObject,
860
- value: new node_opcua_types_1.Range(options.instrumentRange)
861
- }));
862
- }
863
- variable.title.setValueFromSource(new node_opcua_variant_1.Variant({
864
- dataType: node_opcua_variant_1.DataType.LocalizedText,
865
- value: (0, node_opcua_data_model_1.coerceLocalizedText)(options.title || "")
866
- }));
867
- // Linear/Log/Ln
868
- variable.axisScaleType.setValueFromSource(new node_opcua_variant_1.Variant({
869
- dataType: node_opcua_variant_1.DataType.Int32,
870
- value: coerceAxisScale(options.axisScaleType)
871
- }));
872
- variable.xAxisDefinition.setValueFromSource(new node_opcua_variant_1.Variant({
873
- dataType: node_opcua_variant_1.DataType.ExtensionObject,
874
- value: new node_opcua_types_1.AxisInformation(options.xAxisDefinition)
875
- }));
876
- return variable;
877
- }
878
- // - Methods ----------------------------------------------------------------------------------------------------
879
- /**
880
- * @method addMethod
881
- * @param parentObject {Object}
882
- * @param options {Object}
883
- * @param [options.nodeId=null] {NodeId} the object nodeid.
884
- * @param [options.browseName=""] {String} the object browse name.
885
- * @param [options.description=""] {String} the object description.
886
- * @param options.inputArguments {Array<Argument>}
887
- * @param options.outputArguments {Array<Argument>}
888
- * @return {Object}
889
- */
890
- addMethod(parentObject, options) {
891
- const addressSpace = this.addressSpace;
892
- (0, node_opcua_assert_1.assert)(parentObject !== null && typeof parentObject === "object" && parentObject instanceof base_node_impl_1.BaseNodeImpl, "expecting a valid parent object");
893
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "browseName"));
894
- options.componentOf = parentObject;
895
- const method = this._addMethod(options);
896
- const propertyTypeId = addressSpace._coerce_VariableTypeIds("PropertyType");
897
- const nodeId_ArgumentDataType = "Argument"; // makeNodeId(DataTypeIds.Argument);
898
- if (options.inputArguments) {
899
- const _inputArgs = new node_opcua_variant_1.Variant({
900
- arrayType: node_opcua_variant_1.VariantArrayType.Array,
901
- dataType: node_opcua_variant_1.DataType.ExtensionObject,
902
- value: options.inputArguments.map((opt) => new node_opcua_types_1.Argument(opt))
903
- });
904
- const inputArguments = this.addVariable({
905
- accessLevel: "CurrentRead",
906
- arrayDimensions: [_inputArgs.value.length],
907
- browseName: { name: "InputArguments", namespaceIndex: 0 },
908
- dataType: nodeId_ArgumentDataType,
909
- description: "the definition of the input argument of method " +
910
- parentObject.browseName.toString() +
911
- "." +
912
- method.browseName.toString(),
913
- minimumSamplingInterval: -1,
914
- modellingRule: "Mandatory",
915
- propertyOf: method,
916
- typeDefinition: "PropertyType",
917
- value: _inputArgs,
918
- valueRank: 1
919
- });
920
- inputArguments.setValueFromSource(_inputArgs);
921
- (0, node_opcua_assert_1.assert)(inputArguments.typeDefinition.toString() === propertyTypeId.toString());
922
- (0, node_opcua_assert_1.assert)(Array.isArray(inputArguments.arrayDimensions));
923
- }
924
- if (options.outputArguments) {
925
- const _outputArgs = new node_opcua_variant_1.Variant({
926
- arrayType: node_opcua_variant_1.VariantArrayType.Array,
927
- dataType: node_opcua_variant_1.DataType.ExtensionObject,
928
- value: options.outputArguments.map((opts) => new node_opcua_types_1.Argument(opts))
929
- });
930
- const outputArguments = this.addVariable({
931
- accessLevel: "CurrentRead",
932
- arrayDimensions: [_outputArgs.value.length],
933
- browseName: { name: "OutputArguments", namespaceIndex: 0 },
934
- dataType: nodeId_ArgumentDataType,
935
- description: "the definition of the output arguments of method " +
936
- parentObject.browseName.toString() +
937
- "." +
938
- method.browseName.toString(),
939
- minimumSamplingInterval: -1,
940
- modellingRule: "Mandatory",
941
- propertyOf: method,
942
- typeDefinition: "PropertyType",
943
- value: _outputArgs,
944
- valueRank: 1
945
- });
946
- outputArguments.setValueFromSource(_outputArgs);
947
- (0, node_opcua_assert_1.assert)(outputArguments.typeDefinition.toString() === propertyTypeId.toString());
948
- (0, node_opcua_assert_1.assert)(Array.isArray(outputArguments.arrayDimensions));
949
- }
950
- // verifying post-conditions
951
- parentObject.install_extra_properties();
952
- return method;
953
- }
954
- // - Enumeration ------------------------------------------------------------------------------------------------
955
- /**
956
- *
957
- * @method addEnumerationType
958
- * @param options
959
- * @param options.browseName {String}
960
- * @param options.enumeration {Array}
961
- * @param options.enumeration[].displayName {String|LocalizedText}
962
- * @param options.enumeration[].value {Number}
963
- * @param options.enumeration[].description {String|LocalizedText|null}
964
- */
965
- addEnumerationType(options) {
966
- // Release 1.03 OPC Unified Architecture, Part 3 - page 34
967
- // Enumeration DataTypes are DataTypes that represent discrete sets of named values.
968
- // Enumerations are always encoded as Int32 on the wire as defined in Part 6. Enumeration
969
- // DataTypes inherit directly or indirectly from the DataType Enumeration defined in 8.14.
970
- // Enumerations have no encodings exposed in the IAddressSpace. To expose the human readable
971
- // representation of an enumerated value the DataType Node may have the EnumString
972
- // Property that contains an array of LocalizedText. The Integer representation of the enumeration
973
- // value points to a position within that array. EnumValues Property can be used instead of the
974
- // EnumStrings to support integer representation of enumerations that are not zero-based or have
975
- // gaps. It contains an array of a Structured DataType containing the integer representation as
976
- // well as the human-readable representation. An example of an enumeration DataType containing
977
- // a sparse list of Integers is NodeClass which is defined in 8.30.
978
- // OPC Unified Architecture, Part 3 Release 1.03 page 35
979
- // Table 11 – DataType NodeClass
980
- // EnumStrings O LocalizedText[] The EnumStrings Property only applies for Enumeration DataTypes.
981
- // It shall not be applied for other DataTypes. If the EnumValues
982
- // Property is provided, the EnumStrings Property shall not be provided.
983
- // Each entry of the array of LocalizedText in this Property represents
984
- // the human-readable representation of an enumerated value. The
985
- // Integer representation of the enumeration value points to a position
986
- // of the array.
987
- // EnumValues O EnumValueType[] The EnumValues Property only applies for Enumeration DataTypes.
988
- // It shall not be applied for other DataTypes. If the EnumStrings
989
- // Property is provided, the EnumValues Property shall not be provided.
990
- // Using the EnumValues Property it is possible to represent.
991
- // Enumerations with integers that are not zero-based or have gaps
992
- // (e.g. 1, 2, 4, 8, 16).
993
- // Each entry of the array of EnumValueType in this Property
994
- // represents one enumeration value with its integer notation, human readable
995
- // representation and help information.
996
- // The Property EnumStrings contains human-readable representations of enumeration values and is
997
- // only applied to Enumeration DataTypes. Instead of the EnumStrings Property an Enumeration
998
- // DataType can also use the EnumValues Property to represent Enumerations with integer values that are not
999
- // zero-based or containing gaps. There are no additional Properties defined for DataTypes in this standard.
1000
- // Additional parts of this series of standards may define additional Properties for DataTypes.
1001
- // 8.40 EnumValueType
1002
- // This Structured DataType is used to represent a human-readable representation of an
1003
- // Enumeration. Its elements are described inTable 27. When this type is used in an array representing
1004
- // human-readable representations of an enumeration, each Value shall be unique in that array.
1005
- // Table 27 – EnumValueType Definition
1006
- // Name Type Description
1007
- // EnumValueType structure
1008
- // Value Int64 The Integer representation of an Enumeration.
1009
- // DisplayName LocalizedText A human-readable representation of the Value of the Enumeration.
1010
- // Description LocalizedText A localized description of the enumeration value. This field can
1011
- // contain an empty string if no description is available.
1012
- // Note that the EnumValueType has been defined with a Int64 Value to meet a variety of usages.
1013
- // When it is used to define the string representation of an Enumeration DataType, the value range
1014
- // is limited to Int32, because the Enumeration DataType is a subtype of Int32. Part 8 specifies
1015
- // other usages where the actual value might be between 8 and 64 Bit.
1016
- (0, node_opcua_assert_1.assert)(typeof options.browseName === "string");
1017
- (0, node_opcua_assert_1.assert)(Array.isArray(options.enumeration));
1018
- const addressSpace = this.addressSpace;
1019
- let definition;
1020
- const enumerationType = addressSpace.findDataType("Enumeration");
1021
- (0, node_opcua_assert_1.assert)(enumerationType.nodeId instanceof node_opcua_nodeid_2.NodeId);
1022
- (0, node_opcua_assert_1.assert)(enumerationType instanceof ua_data_type_impl_1.UADataTypeImpl);
1023
- const references = [{ referenceType: "HasSubtype", isForward: false, nodeId: enumerationType.nodeId }];
1024
- const opts = {
1025
- browseName: options.browseName,
1026
- definition,
1027
- description: (0, node_opcua_data_model_1.coerceLocalizedText)(options.description) || null,
1028
- displayName: options.displayName || null,
1029
- isAbstract: false,
1030
- nodeClass: node_opcua_data_model_4.NodeClass.DataType,
1031
- references
1032
- };
1033
- const enumType = this.internalCreateNode(opts); // as UAEnumeration;
1034
- enumType.propagate_back_references();
1035
- if (typeof options.enumeration[0] === "string") {
1036
- const enumeration = options.enumeration;
1037
- // enumeration is a array of string
1038
- definition = enumeration.map((str, index) => (0, node_opcua_data_model_1.coerceLocalizedText)(str));
1039
- const value = new node_opcua_variant_1.Variant({
1040
- arrayType: node_opcua_variant_1.VariantArrayType.Array,
1041
- dataType: node_opcua_variant_1.DataType.LocalizedText,
1042
- value: definition
1043
- });
1044
- const enumStrings = this.addVariable({
1045
- browseName: { name: "EnumStrings", namespaceIndex: 0 },
1046
- dataType: "LocalizedText",
1047
- description: "",
1048
- modellingRule: "Mandatory",
1049
- propertyOf: enumType,
1050
- value,
1051
- valueRank: 1
1052
- });
1053
- (0, node_opcua_assert_1.assert)(enumStrings.browseName.toString() === "EnumStrings");
1054
- // set $definition
1055
- // EnumDefinition
1056
- // This Structured DataType is used to provide the metadata for a custom Enumeration or
1057
- // OptionSet DataType. It is derived from the DataType DataTypeDefinition.
1058
- // Enum Field:
1059
- // This Structured DataType is used to provide the metadata for a field of a custom Enumeration
1060
- // or OptionSet DataType. It is derived from the DataType EnumValueType. If used for an
1061
- // OptionSet, the corresponding Value in the base type contains the number of the bit associated
1062
- // with the field. The EnumField is formally defined in Table 37.
1063
- enumType.$fullDefinition = new node_opcua_types_1.EnumDefinition({
1064
- fields: enumeration.map((x, index) => new node_opcua_types_1.EnumField({
1065
- name: x,
1066
- description: (0, node_opcua_data_model_1.coerceLocalizedText)(x),
1067
- value: (0, node_opcua_basic_types_1.coerceInt64)(index)
1068
- }))
1069
- });
1070
- }
1071
- else {
1072
- const enumeration = options.enumeration;
1073
- // construct the definition object
1074
- definition = enumeration.map((enumItem) => {
1075
- return new node_opcua_types_1.EnumValueType({
1076
- description: (0, node_opcua_data_model_1.coerceLocalizedText)(enumItem.description),
1077
- displayName: (0, node_opcua_data_model_1.coerceLocalizedText)(enumItem.displayName),
1078
- value: [0, enumItem.value]
1079
- });
1080
- });
1081
- const value = new node_opcua_variant_1.Variant({
1082
- arrayType: node_opcua_variant_1.VariantArrayType.Array,
1083
- dataType: node_opcua_variant_1.DataType.ExtensionObject,
1084
- value: definition
1085
- });
1086
- const enumValues = this.addVariable({
1087
- browseName: { name: "EnumValues", namespaceIndex: 0 },
1088
- dataType: "EnumValueType",
1089
- description: undefined,
1090
- modellingRule: "Mandatory",
1091
- propertyOf: enumType,
1092
- value,
1093
- valueRank: 1
1094
- });
1095
- (0, node_opcua_assert_1.assert)(enumValues.browseName.toString() === "EnumValues");
1096
- enumType.$fullDefinition = new node_opcua_types_1.EnumDefinition({
1097
- fields: enumeration.map((x, index) => new node_opcua_types_1.EnumField({
1098
- name: x.displayName.toString(),
1099
- description: x.description || "",
1100
- value: (0, node_opcua_basic_types_1.coerceInt64)(x.value)
1101
- }))
1102
- });
1103
- }
1104
- // now create the string value property
1105
- // <UAVariable NodeId="i=7612" BrowseName="EnumStrings"
1106
- // ParentNodeId="i=852" DataType="LocalizedText" ValueRank="1">
1107
- // <DisplayName>EnumStrings</DisplayName>
1108
- // <References>
1109
- // <Reference ReferenceType="HasTypeDefinition">i=68</Reference>
1110
- // <Reference ReferenceType="HasModellingRule">i=78</Reference>
1111
- // <Reference ReferenceType="HasProperty" IsForward="false">i=852</Reference>
1112
- // </References>
1113
- // <Value>
1114
- // <ListOfLocalizedText xmlns="http://opcfoundation.org/UA/2008/02/Types.xsd">
1115
- // <LocalizedText><Locale></Locale><Text>Running</Text></LocalizedText>
1116
- // <LocalizedText><Locale></Locale><Text>Failed</Text>
1117
- // </ListOfLocalizedText>
1118
- // </Value>
1119
- // </UAVariable>
1120
- return enumType;
1121
- }
1122
- // -------------------------------------------------------------------------
1123
- // State and Transition
1124
- // -------------------------------------------------------------------------
1125
- toNodeset2XML() {
1126
- return "";
1127
- }
1128
- // -------------------------------------------------------------------------
1129
- // State and Transition
1130
- // -------------------------------------------------------------------------
1131
- /**
1132
- * @class IAddressSpace
1133
- * @method addState
1134
- * @param component
1135
- * @param stateName {string}
1136
- * @param stateNumber {number}
1137
- * @param isInitialState {boolean}
1138
- * @return {UAObject} {StateType|InitialStateType}
1139
- */
1140
- addState(component, stateName, stateNumber, isInitialState) {
1141
- const addressSpace = this.addressSpace;
1142
- isInitialState = !!isInitialState;
1143
- const _component = component;
1144
- (0, node_opcua_assert_1.assert)(_component.nodeClass === node_opcua_data_model_4.NodeClass.Object || _component.nodeClass === node_opcua_data_model_4.NodeClass.ObjectType);
1145
- (0, node_opcua_assert_1.assert)(typeof stateName === "string");
1146
- (0, node_opcua_assert_1.assert)(typeof isInitialState === "boolean");
1147
- const initialStateType = addressSpace.findObjectType("InitialStateType");
1148
- const stateType = addressSpace.findObjectType("StateType");
1149
- let state;
1150
- if (isInitialState) {
1151
- state = initialStateType.instantiate({
1152
- browseName: stateName,
1153
- componentOf: _component
1154
- });
1155
- }
1156
- else {
1157
- state = stateType.instantiate({
1158
- browseName: stateName,
1159
- componentOf: _component
1160
- });
1161
- }
1162
- // ensure state number is unique
1163
- state.stateNumber.setValueFromSource({
1164
- dataType: node_opcua_variant_1.DataType.UInt32,
1165
- value: stateNumber
1166
- });
1167
- return state;
1168
- }
1169
- /**
1170
- */
1171
- addTransition(component, fromState, toState, transitionNumber) {
1172
- const addressSpace = this.addressSpace;
1173
- const _component = component;
1174
- (0, node_opcua_assert_1.assert)(_component.nodeClass === node_opcua_data_model_4.NodeClass.Object || _component.nodeClass === node_opcua_data_model_4.NodeClass.ObjectType);
1175
- (0, node_opcua_assert_1.assert)(typeof fromState === "string");
1176
- (0, node_opcua_assert_1.assert)(typeof toState === "string");
1177
- (0, node_opcua_assert_1.assert)(isFinite(transitionNumber));
1178
- const fromStateNode = _component.getComponentByName(fromState, _component.nodeId.namespace);
1179
- // istanbul ignore next
1180
- if (!fromStateNode) {
1181
- throw new Error("Cannot find state with name " + fromState);
1182
- }
1183
- (0, node_opcua_assert_1.assert)(fromStateNode.browseName.name.toString() === fromState);
1184
- const toStateNode = _component.getComponentByName(toState);
1185
- // istanbul ignore next
1186
- if (!toStateNode) {
1187
- throw new Error("Cannot find state with name " + toState);
1188
- }
1189
- (0, node_opcua_assert_1.assert)(toStateNode.browseName.name.toString() === toState);
1190
- const transitionType = addressSpace.findObjectType("TransitionType");
1191
- if (!transitionType) {
1192
- throw new Error("Cannot find TransitionType");
1193
- }
1194
- const transition = transitionType.instantiate({
1195
- browseName: fromState + "To" + toState + "Transition",
1196
- componentOf: _component
1197
- });
1198
- transition.addReference({
1199
- isForward: true,
1200
- nodeId: toStateNode.nodeId,
1201
- referenceType: "ToState"
1202
- });
1203
- transition.addReference({
1204
- isForward: true,
1205
- nodeId: fromStateNode.nodeId,
1206
- referenceType: "FromState"
1207
- });
1208
- transition.transitionNumber.setValueFromSource({
1209
- dataType: node_opcua_variant_1.DataType.UInt32,
1210
- value: transitionNumber
1211
- });
1212
- return transition;
1213
- }
1214
- /**
1215
- * @method addTwoStateVariable
1216
- *
1217
- * @return {UATwoStateVariable}
1218
- */
1219
- addTwoStateVariable(options) {
1220
- return (0, ua_two_state_variable_1._addTwoStateVariable)(this, options);
1221
- }
1222
- /**
1223
- * @method addTwoStateDiscrete
1224
- *
1225
- * Add a TwoStateDiscrete Variable
1226
- * @return {UATwoStateDiscrete}
1227
- */
1228
- addTwoStateDiscrete(options) {
1229
- return (0, ua_two_state_discrete_impl_1._addTwoStateDiscrete)(this, options);
1230
- }
1231
- // --- Alarms & Conditions -------------------------------------------------
1232
- instantiateCondition(conditionTypeId, options, data) {
1233
- return ua_condition_impl_1.UAConditionImpl.instantiate(this, conditionTypeId, options, data);
1234
- }
1235
- instantiateAcknowledgeableCondition(conditionTypeId, options, data) {
1236
- return alarms_and_conditions_1.UAAcknowledgeableConditionImpl.instantiate(this, conditionTypeId, options, data);
1237
- }
1238
- instantiateAlarmCondition(alarmConditionTypeId, options, data) {
1239
- return alarms_and_conditions_1.UAAlarmConditionImpl.instantiate(this, alarmConditionTypeId, options, data);
1240
- }
1241
- instantiateLimitAlarm(limitAlarmTypeId, options, data) {
1242
- return ua_limit_alarm_impl_1.UALimitAlarmImpl.instantiate(this, limitAlarmTypeId, options, data);
1243
- }
1244
- instantiateExclusiveLimitAlarm(exclusiveLimitAlarmTypeId, options, data) {
1245
- return ua_exclusive_limit_alarm_impl_1.UAExclusiveLimitAlarmImpl.instantiate(this, exclusiveLimitAlarmTypeId, options, data);
1246
- }
1247
- instantiateExclusiveDeviationAlarm(options, data) {
1248
- return ua_exclusive_deviation_alarm_impl_1.UAExclusiveDeviationAlarmImpl.instantiate(this, "ExclusiveDeviationAlarmType", options, data);
1249
- }
1250
- instantiateNonExclusiveLimitAlarm(nonExclusiveLimitAlarmTypeId, options, data) {
1251
- return ua_non_exclusive_limit_alarm_impl_1.UANonExclusiveLimitAlarmImpl.instantiate(this, nonExclusiveLimitAlarmTypeId, options, data);
1252
- }
1253
- instantiateNonExclusiveDeviationAlarm(options, data) {
1254
- return ua_non_exclusive_deviation_alarm_impl_1.UANonExclusiveDeviationAlarmImpl.instantiate(this, "NonExclusiveDeviationAlarmType", options, data);
1255
- }
1256
- instantiateDiscreteAlarm(discreteAlarmType, options, data) {
1257
- return ua_discrete_alarm_impl_1.UADiscreteAlarmImpl.instantiate(this, discreteAlarmType, options, data);
1258
- }
1259
- instantiateOffNormalAlarm(options, data) {
1260
- return ua_off_normal_alarm_impl_1.UAOffNormalAlarmImpl.instantiate(this, "OffNormalAlarmType", options, data);
1261
- }
1262
- // default roles and permissions
1263
- setDefaultRolePermissions(rolePermissions) {
1264
- this.defaultRolePermissions = rolePermissions ? (0, role_permissions_1.coerceRolePermissions)(rolePermissions) : undefined;
1265
- }
1266
- getDefaultRolePermissions() {
1267
- return this.defaultRolePermissions || null;
1268
- }
1269
- setDefaultAccessRestrictions(accessRestrictions) {
1270
- this.defaultAccessRestrictions = accessRestrictions;
1271
- }
1272
- getDefaultAccessRestrictions() {
1273
- return this.defaultAccessRestrictions || node_opcua_data_model_1.AccessRestrictionsFlag.None;
1274
- }
1275
- // --- internal stuff
1276
- constructNodeId(options) {
1277
- return this._nodeIdManager.constructNodeId(options);
1278
- }
1279
- _register(node) {
1280
- (0, node_opcua_assert_1.assert)(node instanceof base_node_impl_1.BaseNodeImpl, "Expecting a instance of BaseNode in _register");
1281
- (0, node_opcua_assert_1.assert)(node.nodeId instanceof node_opcua_nodeid_2.NodeId, "Expecting a NodeId");
1282
- if (node.nodeId.namespace !== this.index) {
1283
- throw new Error("node must belongs to this namespace");
1284
- }
1285
- (0, node_opcua_assert_1.assert)(node.nodeId.namespace === this.index, "node must belongs to this namespace");
1286
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(node, "browseName"), "Node must have a browseName");
1287
- // assert(node.browseName.namespaceIndex === this.index,"browseName must belongs to this namespace");
1288
- const hashKey = _makeHashKey(node.nodeId);
1289
- // istanbul ignore next
1290
- if (this._nodeid_index.has(hashKey)) {
1291
- throw new Error("node " +
1292
- node.browseName.toString() +
1293
- "nodeId = " +
1294
- node.nodeId.displayText() +
1295
- " already registered " +
1296
- node.nodeId.toString() +
1297
- "\n" +
1298
- " in namespace " +
1299
- this.namespaceUri +
1300
- " index = " +
1301
- this.index +
1302
- "\n" +
1303
- " browseName = " +
1304
- node.browseName.toString());
1305
- }
1306
- this._nodeid_index.set(hashKey, node);
1307
- switch (node.nodeClass) {
1308
- case node_opcua_data_model_4.NodeClass.ObjectType:
1309
- this._registerObjectType(node);
1310
- break;
1311
- case node_opcua_data_model_4.NodeClass.VariableType:
1312
- this._registerVariableType(node);
1313
- break;
1314
- case node_opcua_data_model_4.NodeClass.ReferenceType:
1315
- this._registerReferenceType(node);
1316
- break;
1317
- case node_opcua_data_model_4.NodeClass.DataType:
1318
- this._registerDataType(node);
1319
- break;
1320
- case node_opcua_data_model_4.NodeClass.Object:
1321
- case node_opcua_data_model_4.NodeClass.Variable:
1322
- case node_opcua_data_model_4.NodeClass.Method:
1323
- case node_opcua_data_model_4.NodeClass.View:
1324
- break;
1325
- default:
1326
- // tslint:disable-next-line:no-console
1327
- console.log("Invalid class Name", node.nodeClass);
1328
- throw new Error("Invalid class name specified");
1329
- }
1330
- }
1331
- /**
1332
- * @method internalCreateNode
1333
- * @internal
1334
- */
1335
- internalCreateNode(options) {
1336
- (0, node_opcua_assert_1.assert)(options.nodeClass !== undefined, " options.nodeClass must be specified");
1337
- (0, node_opcua_assert_1.assert)(options.browseName, "options.browseName must be specified");
1338
- // xx assert(options.browseName instanceof QualifiedName
1339
- // ? (options.browseName.namespaceIndex === this.index): true,
1340
- // "Expecting browseName to have the same namespaceIndex as the namespace");
1341
- options.description = (0, node_opcua_data_model_1.coerceLocalizedText)(options.description);
1342
- // browseName adjustment
1343
- if (typeof options.browseName === "string") {
1344
- const match = options.browseName.match(regExpNamespaceDotBrowseName);
1345
- if (match) {
1346
- const correctedName = match[1];
1347
- // the application is using an old scheme
1348
- console.log(chalk.green("Warning : since node-opcua 0.4.2 " + "namespace index should not be prepended to the browse name anymore"));
1349
- console.log(" ", options.browseName, " will be replaced with ", correctedName);
1350
- console.log(" Please update your code");
1351
- const indexVerif = parseInt(match[0], 10);
1352
- if (indexVerif !== this.index) {
1353
- errorLog(chalk.red.bold("Error: namespace index used at the front of the browseName " +
1354
- indexVerif +
1355
- " do not match the index of the current namespace (" +
1356
- this.index +
1357
- ")"));
1358
- errorLog(" Please fix your code so that the created node is inserted in the correct namespace," +
1359
- " please refer to the NodeOPCUA documentation");
1360
- }
1361
- }
1362
- options.browseName = new node_opcua_data_model_2.QualifiedName({ name: options.browseName, namespaceIndex: this.index });
1363
- }
1364
- else if (!(options.browseName instanceof node_opcua_data_model_2.QualifiedName)) {
1365
- options.browseName = new node_opcua_data_model_2.QualifiedName(options.browseName);
1366
- }
1367
- (0, node_opcua_assert_1.assert)(options.browseName instanceof node_opcua_data_model_2.QualifiedName, "Expecting options.browseName to be instanceof QualifiedName ");
1368
- // ------------- set display name
1369
- if (!options.displayName) {
1370
- (0, node_opcua_assert_1.assert)(typeof options.browseName.name === "string");
1371
- options.displayName = options.browseName.name;
1372
- }
1373
- // --- nodeId adjustment
1374
- options.nodeId = this.constructNodeId(options);
1375
- (0, node_opcua_debug_1.dumpIf)(!options.nodeId, options); // missing node Id
1376
- (0, node_opcua_assert_1.assert)(options.nodeId instanceof node_opcua_nodeid_2.NodeId);
1377
- // assert(options.browseName.namespaceIndex === this.index,"Expecting browseName to have
1378
- // the same namespaceIndex as the namespace");
1379
- const Constructor = _constructors_map[node_opcua_data_model_4.NodeClass[options.nodeClass]];
1380
- if (!Constructor) {
1381
- throw new Error(" missing constructor for NodeClass " + node_opcua_data_model_4.NodeClass[options.nodeClass]);
1382
- }
1383
- options.addressSpace = this.addressSpace;
1384
- const node = new Constructor(options);
1385
- this._register(node);
1386
- // object shall now be registered
1387
- // istanbul ignore next
1388
- if (doDebug) {
1389
- (0, node_opcua_assert_1.assert)(this.findNode(node.nodeId) !== null && typeof this.findNode(node.nodeId) === "object");
1390
- }
1391
- return node;
1392
- }
1393
- _deleteNode(node) {
1394
- (0, node_opcua_assert_1.assert)(node instanceof base_node_impl_1.BaseNodeImpl);
1395
- const hashKey = _makeHashKey(node.nodeId);
1396
- // istanbul ignore next
1397
- if (!this._nodeid_index.has(hashKey)) {
1398
- throw new Error("deleteNode : nodeId " + node.nodeId.displayText() + " is not registered " + node.nodeId.toString());
1399
- }
1400
- switch (node.nodeClass) {
1401
- case node_opcua_data_model_4.NodeClass.ObjectType:
1402
- this._unregisterObjectType(node);
1403
- break;
1404
- case node_opcua_data_model_4.NodeClass.VariableType:
1405
- this._unregisterVariableType(node);
1406
- break;
1407
- case node_opcua_data_model_4.NodeClass.Object:
1408
- case node_opcua_data_model_4.NodeClass.Variable:
1409
- case node_opcua_data_model_4.NodeClass.Method:
1410
- case node_opcua_data_model_4.NodeClass.View:
1411
- break;
1412
- default:
1413
- // tslint:disable:no-console
1414
- console.log("Invalid class Name", node.nodeClass);
1415
- throw new Error("Invalid class name specified");
1416
- }
1417
- const deleted = this._nodeid_index.delete(hashKey);
1418
- (0, node_opcua_assert_1.assert)(deleted);
1419
- node.dispose();
1420
- }
1421
- // --- Private stuff
1422
- _addObjectOrVariableType(options1, topMostBaseType, nodeClass) {
1423
- const addressSpace = this.addressSpace;
1424
- (0, node_opcua_assert_1.assert)(typeof topMostBaseType === "string");
1425
- (0, node_opcua_assert_1.assert)(nodeClass === node_opcua_data_model_4.NodeClass.ObjectType || nodeClass === node_opcua_data_model_4.NodeClass.VariableType);
1426
- const options = options1;
1427
- (0, node_opcua_assert_1.assert)(!options.nodeClass);
1428
- (0, node_opcua_assert_1.assert)(options.browseName);
1429
- (0, node_opcua_assert_1.assert)(typeof options.browseName === "string");
1430
- if (Object.prototype.hasOwnProperty.call(options, "references")) {
1431
- throw new Error("options.references should not be provided, use options.subtypeOf instead");
1432
- }
1433
- const references = [];
1434
- function process_subtypeOf_options(options2, references1) {
1435
- // check common misspelling mistake
1436
- (0, node_opcua_assert_1.assert)(!options2.subTypeOf, "misspell error : it should be 'subtypeOf' instead");
1437
- if (Object.prototype.hasOwnProperty.call(options2, "hasTypeDefinition")) {
1438
- throw new Error("hasTypeDefinition option is invalid. Do you mean typeDefinition instead ?");
1439
- }
1440
- (0, node_opcua_assert_1.assert)(!options2.typeDefinition, " do you mean subtypeOf ?");
1441
- const subtypeOfNodeId = addressSpace._coerceType(options2.subtypeOf, topMostBaseType, nodeClass);
1442
- (0, node_opcua_assert_1.assert)(subtypeOfNodeId);
1443
- references1.push({
1444
- isForward: false,
1445
- nodeId: subtypeOfNodeId,
1446
- referenceType: "HasSubtype"
1447
- });
1448
- }
1449
- process_subtypeOf_options.call(this, options, references);
1450
- const objectType = this.internalCreateNode({
1451
- browseName: options.browseName,
1452
- displayName: options.displayName,
1453
- description: options.description,
1454
- eventNotifier: +options.eventNotifier,
1455
- isAbstract: !!options.isAbstract,
1456
- nodeClass,
1457
- nodeId: options.nodeId,
1458
- references
1459
- });
1460
- objectType.propagate_back_references();
1461
- objectType.install_extra_properties();
1462
- objectType.installPostInstallFunc(options.postInstantiateFunc);
1463
- return objectType;
1464
- }
1465
- // private _adjust_options(options: any) {
1466
- // const ns = this.addressSpace.getNamespaceIndex(this.namespaceUri);
1467
- // if (!options.nodeId) {
1468
- // const id = this._getNextAvailableId();
1469
- // options.nodeId = new NodeId(NodeId.NodeIdType.NUMERIC, id, ns);
1470
- // }
1471
- // options.nodeId = NodeId.coerce(options.nodeId);
1472
- // if (typeof options.browseName === "string") {
1473
- // options.browseName = new QualifiedName({
1474
- // name: options.browseName,
1475
- // namespaceIndex: ns
1476
- // });
1477
- // }
1478
- // return options;
1479
- // }
1480
- _registerObjectType(node) {
1481
- (0, node_opcua_assert_1.assert)(this.index === node.nodeId.namespace);
1482
- const key = node.browseName.name;
1483
- (0, node_opcua_assert_1.assert)(!this._objectTypeMap.has(key), " UAObjectType already declared");
1484
- this._objectTypeMap.set(key, node);
1485
- }
1486
- _registerVariableType(node) {
1487
- (0, node_opcua_assert_1.assert)(this.index === node.nodeId.namespace);
1488
- const key = node.browseName.name;
1489
- (0, node_opcua_assert_1.assert)(!this._variableTypeMap.has(key), " UAVariableType already declared");
1490
- this._variableTypeMap.set(key, node);
1491
- }
1492
- _registerReferenceType(node) {
1493
- (0, node_opcua_assert_1.assert)(this.index === node.nodeId.namespace);
1494
- (0, node_opcua_assert_1.assert)(node.browseName instanceof node_opcua_data_model_2.QualifiedName);
1495
- const key = node.browseName.name;
1496
- this._referenceTypeMap.set(key, node);
1497
- this._referenceTypeMapInv.set(node.inverseName.text, node);
1498
- }
1499
- _registerDataType(node) {
1500
- (0, node_opcua_assert_1.assert)(this.index === node.nodeId.namespace);
1501
- const key = node.browseName.name;
1502
- (0, node_opcua_assert_1.assert)(node.browseName instanceof node_opcua_data_model_2.QualifiedName);
1503
- (0, node_opcua_assert_1.assert)(!this._dataTypeMap.has(key), " DataType already declared");
1504
- this._dataTypeMap.set(key, node);
1505
- }
1506
- _unregisterObjectType(node) {
1507
- const key = node.browseName.name;
1508
- this._objectTypeMap.delete(key);
1509
- }
1510
- _unregisterVariableType(node) {
1511
- const key = node.browseName.name;
1512
- this._variableTypeMap.delete(key);
1513
- }
1514
- /**
1515
- * @private
1516
- */
1517
- _addVariable(options) {
1518
- const addressSpace = this.addressSpace;
1519
- const baseDataVariableType = addressSpace.findVariableType("BaseDataVariableType");
1520
- if (!baseDataVariableType) {
1521
- throw new Error("cannot find BaseDataVariableType");
1522
- }
1523
- const baseDataVariableTypeId = baseDataVariableType.nodeId;
1524
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "browseName"), "options.browseName must be provided");
1525
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "dataType"), "options.dataType must be provided");
1526
- options.historizing = !!options.historizing;
1527
- // xx assert(this.FolderTypeId && this.BaseObjectTypeId); // is default address space generated.?
1528
- // istanbul ignore next
1529
- if (Object.prototype.hasOwnProperty.call(options, "hasTypeDefinition")) {
1530
- throw new Error("hasTypeDefinition option is invalid. Do you mean typeDefinition instead ?");
1531
- }
1532
- // ------------------------------------------ TypeDefinition
1533
- let typeDefinition = options.typeDefinition || baseDataVariableTypeId;
1534
- typeDefinition = addressSpace._coerce_VariableTypeIds(typeDefinition);
1535
- (0, node_opcua_assert_1.assert)(typeDefinition instanceof node_opcua_nodeid_2.NodeId);
1536
- // ------------------------------------------ DataType
1537
- options.dataType = addressSpace._coerce_DataType(options.dataType);
1538
- options.valueRank = utils.isNullOrUndefined(options.valueRank)
1539
- ? options.arrayDimensions
1540
- ? options.arrayDimensions.length
1541
- : -1
1542
- : options.valueRank;
1543
- (0, node_opcua_assert_1.assert)(typeof options.valueRank === "number" && isFinite(options.valueRank));
1544
- options.arrayDimensions = options.arrayDimensions || null;
1545
- (0, node_opcua_assert_1.assert)(Array.isArray(options.arrayDimensions) || options.arrayDimensions === null);
1546
- // -----------------------------------------------------
1547
- options.minimumSamplingInterval = options.minimumSamplingInterval !== undefined ? +options.minimumSamplingInterval : 0;
1548
- let references = options.references || [];
1549
- references = [].concat(references, [
1550
- {
1551
- isForward: true,
1552
- nodeId: typeDefinition,
1553
- referenceType: "HasTypeDefinition"
1554
- }
1555
- ]);
1556
- (0, node_opcua_assert_1.assert)(!options.nodeClass || options.nodeClass === node_opcua_data_model_4.NodeClass.Variable);
1557
- options.nodeClass = node_opcua_data_model_4.NodeClass.Variable;
1558
- options.references = references;
1559
- const variable = this.createNode(options);
1560
- return variable;
1561
- }
1562
- /**
1563
- * @private
1564
- */
1565
- _addMethod(options) {
1566
- const addressSpace = this.addressSpace;
1567
- (0, node_opcua_assert_1.assert)(isNonEmptyQualifiedName(options.browseName));
1568
- const references = [];
1569
- (0, node_opcua_assert_1.assert)(isNonEmptyQualifiedName(options.browseName));
1570
- _handle_hierarchy_parent(addressSpace, references, options);
1571
- (0, namespace_private_1.UANamespace_process_modelling_rule)(references, options.modellingRule);
1572
- const method = this.internalCreateNode({
1573
- browseName: options.browseName,
1574
- description: options.description || "",
1575
- displayName: options.displayName,
1576
- eventNotifier: +options.eventNotifier,
1577
- isAbstract: false,
1578
- nodeClass: node_opcua_data_model_4.NodeClass.Method,
1579
- nodeId: options.nodeId,
1580
- references,
1581
- rolePermissions: options.rolePermissions
1582
- });
1583
- (0, node_opcua_assert_1.assert)(method.nodeId !== null);
1584
- method.propagate_back_references();
1585
- (0, node_opcua_assert_1.assert)(!method.typeDefinition);
1586
- return method;
1587
- }
1588
- }
1589
- exports.NamespaceImpl = NamespaceImpl;
1590
- NamespaceImpl._handle_hierarchy_parent = _handle_hierarchy_parent;
1591
- NamespaceImpl.isNonEmptyQualifiedName = isNonEmptyQualifiedName;
1592
- const _constructors_map = {
1593
- DataType: ua_data_type_impl_1.UADataTypeImpl,
1594
- Method: ua_method_impl_1.UAMethodImpl,
1595
- Object: ua_object_impl_1.UAObjectImpl,
1596
- ObjectType: ua_object_type_impl_1.UAObjectTypeImpl,
1597
- ReferenceType: ua_reference_type_impl_1.UAReferenceTypeImpl,
1598
- Variable: ua_variable_impl_1.UAVariableImpl,
1599
- VariableType: ua_variable_type_impl_1.UAVariableTypeImpl,
1600
- View: ua_view_impl_1.UAViewImpl
1601
- };
1602
- /**
1603
- * @method _coerce_parent
1604
- * convert a 'string' , NodeId or Object into a valid and existing object
1605
- * @param addressSpace {IAddressSpace}
1606
- * @param value
1607
- * @param coerceFunc
1608
- * @private
1609
- */
1610
- function _coerce_parent(addressSpace, value, coerceFunc) {
1611
- (0, node_opcua_assert_1.assert)(typeof coerceFunc === "function");
1612
- if (value) {
1613
- if (typeof value === "string") {
1614
- value = coerceFunc.call(addressSpace, value);
1615
- }
1616
- if (value instanceof node_opcua_nodeid_2.NodeId) {
1617
- value = addressSpace.findNode(value);
1618
- }
1619
- }
1620
- (0, node_opcua_assert_1.assert)(!value || value instanceof base_node_impl_1.BaseNodeImpl);
1621
- return value;
1622
- }
1623
- function _handle_event_hierarchy_parent(addressSpace, references, options) {
1624
- options.eventSourceOf = _coerce_parent(addressSpace, options.eventSourceOf, addressSpace._coerceNode);
1625
- options.notifierOf = _coerce_parent(addressSpace, options.notifierOf, addressSpace._coerceNode);
1626
- if (options.eventSourceOf) {
1627
- (0, node_opcua_assert_1.assert)(!options.notifierOf, "notifierOf shall not be provided with eventSourceOf ");
1628
- references.push({
1629
- isForward: false,
1630
- nodeId: options.eventSourceOf.nodeId,
1631
- referenceType: "HasEventSource"
1632
- });
1633
- options.eventNotifier = options.eventNotifier || 1;
1634
- }
1635
- else if (options.notifierOf) {
1636
- (0, node_opcua_assert_1.assert)(!options.eventSourceOf, "eventSourceOf shall not be provided with notifierOf ");
1637
- references.push({
1638
- isForward: false,
1639
- nodeId: options.notifierOf.nodeId,
1640
- referenceType: "HasNotifier"
1641
- });
1642
- }
1643
- }
1644
- function _handle_hierarchy_parent(addressSpace, references, options) {
1645
- options.componentOf = _coerce_parent(addressSpace, options.componentOf, addressSpace._coerceNode);
1646
- options.propertyOf = _coerce_parent(addressSpace, options.propertyOf, addressSpace._coerceNode);
1647
- options.organizedBy = _coerce_parent(addressSpace, options.organizedBy, addressSpace._coerceFolder);
1648
- options.encodingOf = _coerce_parent(addressSpace, options.encodingOf, addressSpace._coerceNode);
1649
- if (options.componentOf) {
1650
- (0, node_opcua_assert_1.assert)(!options.propertyOf);
1651
- (0, node_opcua_assert_1.assert)(!options.organizedBy);
1652
- (0, node_opcua_assert_1.assert)(addressSpace.rootFolder.objects, "addressSpace must have a rootFolder.objects folder");
1653
- (0, node_opcua_assert_1.assert)(options.componentOf.nodeId !== addressSpace.rootFolder.objects.nodeId, "Only Organizes References are used to relate Objects to the 'Objects' standard Object.");
1654
- references.push({
1655
- isForward: false,
1656
- nodeId: options.componentOf.nodeId,
1657
- referenceType: "HasComponent"
1658
- });
1659
- }
1660
- if (options.propertyOf) {
1661
- (0, node_opcua_assert_1.assert)(!options.componentOf);
1662
- (0, node_opcua_assert_1.assert)(!options.organizedBy);
1663
- (0, node_opcua_assert_1.assert)(options.propertyOf.nodeId !== addressSpace.rootFolder.objects.nodeId, "Only Organizes References are used to relate Objects to the 'Objects' standard Object.");
1664
- references.push({
1665
- isForward: false,
1666
- nodeId: options.propertyOf.nodeId,
1667
- referenceType: "HasProperty"
1668
- });
1669
- }
1670
- if (options.organizedBy) {
1671
- (0, node_opcua_assert_1.assert)(!options.propertyOf);
1672
- (0, node_opcua_assert_1.assert)(!options.componentOf);
1673
- references.push({
1674
- isForward: false,
1675
- nodeId: options.organizedBy.nodeId,
1676
- referenceType: "Organizes"
1677
- });
1678
- }
1679
- if (options.encodingOf) {
1680
- // parent must be a DataType
1681
- (0, node_opcua_assert_1.assert)(options.encodingOf.nodeClass === node_opcua_data_model_4.NodeClass.DataType, "encodingOf must be toward a DataType");
1682
- references.push({
1683
- isForward: false,
1684
- nodeId: options.encodingOf.nodeId,
1685
- referenceType: "HasEncoding"
1686
- });
1687
- }
1688
- }
1689
- exports._handle_hierarchy_parent = _handle_hierarchy_parent;
1690
- function _copy_reference(reference) {
1691
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(reference, "referenceType"));
1692
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(reference, "isForward"));
1693
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(reference, "nodeId"));
1694
- (0, node_opcua_assert_1.assert)(reference.nodeId instanceof node_opcua_nodeid_2.NodeId);
1695
- return {
1696
- isForward: reference.isForward,
1697
- nodeId: reference.nodeId,
1698
- referenceType: reference.referenceType
1699
- };
1700
- }
1701
- function _copy_references(references) {
1702
- references = references || [];
1703
- return references.map(_copy_reference);
1704
- }
1705
- function isNonEmptyQualifiedName(browseName) {
1706
- if (!browseName) {
1707
- return false;
1708
- }
1709
- if (typeof browseName === "string") {
1710
- return browseName.length >= 0;
1711
- }
1712
- if (!(browseName instanceof node_opcua_data_model_2.QualifiedName)) {
1713
- browseName = new node_opcua_data_model_2.QualifiedName(browseName);
1714
- }
1715
- (0, node_opcua_assert_1.assert)(browseName instanceof node_opcua_data_model_2.QualifiedName);
1716
- return browseName.name.length > 0;
1717
- }
1718
- exports.isNonEmptyQualifiedName = isNonEmptyQualifiedName;
1719
- function _handle_node_version(node, options) {
1720
- (0, node_opcua_assert_1.assert)(options);
1721
- if (options.nodeVersion) {
1722
- (0, node_opcua_assert_1.assert)(node.nodeClass === node_opcua_data_model_4.NodeClass.Variable || node.nodeClass === node_opcua_data_model_4.NodeClass.Object);
1723
- const nodeVersion = node.addressSpace.getOwnNamespace().addVariable({
1724
- browseName: "NodeVersion",
1725
- dataType: "String",
1726
- propertyOf: node
1727
- });
1728
- const initialValue = typeof options.nodeVersion === "string" ? options.nodeVersion : "0";
1729
- // xx console.log(" init value =",initialValue);
1730
- nodeVersion.setValueFromSource({ dataType: "String", value: initialValue });
1731
- }
1732
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNonEmptyQualifiedName = exports._handle_hierarchy_parent = exports.NamespaceImpl = void 0;
4
+ /**
5
+ * @module node-opcua-address-space
6
+ */
7
+ // tslint:disable:no-console
8
+ const chalk = require("chalk");
9
+ const node_opcua_assert_1 = require("node-opcua-assert");
10
+ const node_opcua_basic_types_1 = require("node-opcua-basic-types");
11
+ const node_opcua_data_access_1 = require("node-opcua-data-access");
12
+ const node_opcua_data_model_1 = require("node-opcua-data-model");
13
+ const node_opcua_data_model_2 = require("node-opcua-data-model");
14
+ const node_opcua_data_model_3 = require("node-opcua-data-model");
15
+ const node_opcua_data_model_4 = require("node-opcua-data-model");
16
+ const node_opcua_debug_1 = require("node-opcua-debug");
17
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
18
+ const node_opcua_nodeid_2 = require("node-opcua-nodeid");
19
+ const node_opcua_status_code_1 = require("node-opcua-status-code");
20
+ const node_opcua_types_1 = require("node-opcua-types");
21
+ const utils = require("node-opcua-utils");
22
+ const node_opcua_variant_1 = require("node-opcua-variant");
23
+ const address_space_change_event_tools_1 = require("./address_space_change_event_tools");
24
+ const ua_condition_impl_1 = require("./alarms_and_conditions/ua_condition_impl");
25
+ const ua_discrete_alarm_impl_1 = require("./alarms_and_conditions/ua_discrete_alarm_impl");
26
+ const ua_exclusive_deviation_alarm_impl_1 = require("./alarms_and_conditions/ua_exclusive_deviation_alarm_impl");
27
+ const ua_exclusive_limit_alarm_impl_1 = require("./alarms_and_conditions/ua_exclusive_limit_alarm_impl");
28
+ const ua_limit_alarm_impl_1 = require("./alarms_and_conditions/ua_limit_alarm_impl");
29
+ const ua_non_exclusive_deviation_alarm_impl_1 = require("./alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl");
30
+ const ua_non_exclusive_limit_alarm_impl_1 = require("./alarms_and_conditions/ua_non_exclusive_limit_alarm_impl");
31
+ const alarms_and_conditions_1 = require("./alarms_and_conditions");
32
+ const ua_off_normal_alarm_impl_1 = require("./alarms_and_conditions/ua_off_normal_alarm_impl");
33
+ const add_dataItem_stuff_1 = require("./data_access/add_dataItem_stuff");
34
+ const ua_multistate_discrete_impl_1 = require("./data_access/ua_multistate_discrete_impl");
35
+ // state machine
36
+ const ua_two_state_variable_1 = require("./state_machine/ua_two_state_variable");
37
+ //
38
+ const namespace_private_1 = require("./namespace_private");
39
+ const base_node_impl_1 = require("./base_node_impl");
40
+ const ua_variable_impl_1 = require("./ua_variable_impl");
41
+ const nodeid_manager_1 = require("./nodeid_manager");
42
+ const ua_two_state_discrete_impl_1 = require("./data_access/ua_two_state_discrete_impl");
43
+ const role_permissions_1 = require("./role_permissions");
44
+ const ua_object_impl_1 = require("./ua_object_impl");
45
+ const ua_data_type_impl_1 = require("./ua_data_type_impl");
46
+ const ua_object_type_impl_1 = require("./ua_object_type_impl");
47
+ const ua_method_impl_1 = require("./ua_method_impl");
48
+ const ua_variable_type_impl_1 = require("./ua_variable_type_impl");
49
+ const ua_reference_type_impl_1 = require("./ua_reference_type_impl");
50
+ const ua_view_impl_1 = require("./ua_view_impl");
51
+ const ua_multistate_value_discrete_impl_1 = require("./data_access/ua_multistate_value_discrete_impl");
52
+ function _makeHashKey(nodeId) {
53
+ switch (nodeId.identifierType) {
54
+ case node_opcua_nodeid_1.NodeIdType.STRING:
55
+ case node_opcua_nodeid_1.NodeIdType.GUID:
56
+ return nodeId.value;
57
+ case node_opcua_nodeid_1.NodeIdType.NUMERIC:
58
+ return nodeId.value;
59
+ default:
60
+ // istanbul ignore next
61
+ if (nodeId.identifierType !== node_opcua_nodeid_1.NodeIdType.BYTESTRING) {
62
+ throw new Error("invalid nodeIdType");
63
+ }
64
+ return nodeId.value ? nodeId.value.toString() : "OPAQUE:0";
65
+ }
66
+ }
67
+ const doDebug = false;
68
+ const errorLog = (0, node_opcua_debug_1.make_errorLog)("AddressSpace");
69
+ const regExp1 = /^(s|i|b|g)=/;
70
+ const regExpNamespaceDotBrowseName = /^[0-9]+:(.*)/;
71
+ function detachNode(node) {
72
+ const addressSpace = node.addressSpace;
73
+ const nonHierarchicalReferences = node.findReferencesEx("NonHierarchicalReferences", node_opcua_data_model_3.BrowseDirection.Inverse);
74
+ for (const ref of nonHierarchicalReferences) {
75
+ (0, node_opcua_assert_1.assert)(!ref.isForward);
76
+ ref.node.removeReference({
77
+ isForward: !ref.isForward,
78
+ nodeId: node.nodeId,
79
+ referenceType: ref.referenceType
80
+ });
81
+ }
82
+ const nonHierarchicalReferencesF = node.findReferencesEx("NonHierarchicalReferences", node_opcua_data_model_3.BrowseDirection.Forward);
83
+ for (const ref of nonHierarchicalReferencesF) {
84
+ if (!ref.node) {
85
+ // could be a special case of a frequently use target node such as ModellingRule_Mandatory that do not back trace
86
+ // their reference
87
+ continue;
88
+ }
89
+ (0, node_opcua_assert_1.assert)(ref.isForward);
90
+ ref.node.removeReference({
91
+ isForward: !ref.isForward,
92
+ nodeId: node.nodeId,
93
+ referenceType: ref.referenceType
94
+ });
95
+ }
96
+ // remove reversed Hierarchical references
97
+ const hierarchicalReferences = node.findReferencesEx("HierarchicalReferences", node_opcua_data_model_3.BrowseDirection.Inverse);
98
+ for (const ref of hierarchicalReferences) {
99
+ (0, node_opcua_assert_1.assert)(!ref.isForward);
100
+ const parent = addressSpace.findNode(ref.nodeId);
101
+ parent.removeReference({
102
+ isForward: !ref.isForward,
103
+ nodeId: node.nodeId,
104
+ referenceType: ref.referenceType
105
+ });
106
+ }
107
+ node.unpropagate_back_references();
108
+ }
109
+ /**
110
+ *
111
+ * @constructor
112
+ * @params options {Object}
113
+ * @params options.namespaceUri {string}
114
+ * @params options.addressSpace {IAddressSpace}
115
+ * @params options.index {number}
116
+ * @params options.version="" {string}
117
+ * @params options.publicationDate="" {Date}
118
+ *
119
+ */
120
+ class NamespaceImpl {
121
+ constructor(options) {
122
+ this.version = "0.0.0";
123
+ this.publicationDate = new Date(Date.UTC(1900, 0, 1));
124
+ // istanbul ignore next
125
+ if (!(typeof options.namespaceUri === "string")) {
126
+ throw new Error("NamespaceImpl constructor: namespaceUri must exists and be a string : got " + options.namespaceUri);
127
+ }
128
+ // istanbul ignore next
129
+ if (typeof options.index !== "number") {
130
+ throw new Error("NamespaceImpl constructor: index must be a number");
131
+ }
132
+ // istanbul ignore next
133
+ if (!options.addressSpace) {
134
+ throw new Error("NamespaceImpl constructor: Must specify a valid address space");
135
+ }
136
+ this.namespaceUri = options.namespaceUri;
137
+ this.addressSpace = options.addressSpace;
138
+ this.index = options.index;
139
+ this._nodeid_index = new Map();
140
+ this._aliases = new Map();
141
+ this._objectTypeMap = new Map();
142
+ this._variableTypeMap = new Map();
143
+ this._referenceTypeMap = new Map();
144
+ this._referenceTypeMapInv = new Map();
145
+ this._dataTypeMap = new Map();
146
+ this._nodeIdManager = new nodeid_manager_1.NodeIdManager(this.index, this.addressSpace);
147
+ }
148
+ getDefaultNamespace() {
149
+ return this.index === 0 ? this : this.addressSpace.getDefaultNamespace();
150
+ }
151
+ dispose() {
152
+ for (const node of this.nodeIterator()) {
153
+ node.dispose();
154
+ }
155
+ this._nodeid_index = new Map();
156
+ this._aliases = new Map();
157
+ this.addressSpace = {};
158
+ this._objectTypeMap = new Map();
159
+ this._variableTypeMap = new Map();
160
+ this._referenceTypeMap = new Map();
161
+ this._referenceTypeMapInv = new Map();
162
+ this._dataTypeMap = new Map();
163
+ }
164
+ nodeIterator() {
165
+ return this._nodeid_index.values();
166
+ }
167
+ _objectTypeIterator() {
168
+ return this._objectTypeMap.values();
169
+ }
170
+ _objectTypeCount() {
171
+ return this._objectTypeMap.size;
172
+ }
173
+ _variableTypeIterator() {
174
+ return this._variableTypeMap.values();
175
+ }
176
+ _variableTypeCount() {
177
+ return this._variableTypeMap.size;
178
+ }
179
+ _dataTypeIterator() {
180
+ return this._dataTypeMap.values();
181
+ }
182
+ _dataTypeCount() {
183
+ return this._dataTypeMap.size;
184
+ }
185
+ _referenceTypeIterator() {
186
+ return this._referenceTypeMap.values();
187
+ }
188
+ _referenceTypeCount() {
189
+ return this._referenceTypeMap.size;
190
+ }
191
+ _aliasCount() {
192
+ return this._aliases.size;
193
+ }
194
+ findNode2(nodeId) {
195
+ // this one is faster assuming you have a nodeId
196
+ (0, node_opcua_assert_1.assert)(nodeId.namespace === this.index);
197
+ return this._nodeid_index.get(_makeHashKey(nodeId)) || null;
198
+ }
199
+ findNode(nodeId) {
200
+ if (typeof nodeId === "string") {
201
+ if (nodeId.match(regExp1)) {
202
+ nodeId = "ns=" + this.index + ";" + nodeId;
203
+ }
204
+ }
205
+ nodeId = (0, node_opcua_nodeid_1.resolveNodeId)(nodeId);
206
+ return this.findNode2(nodeId);
207
+ }
208
+ /**
209
+ *
210
+ * @param objectTypeName {String}
211
+ * @return {UAObjectType|null}
212
+ */
213
+ findObjectType(objectTypeName) {
214
+ return this._objectTypeMap.get(objectTypeName) || null;
215
+ }
216
+ /**
217
+ *
218
+ * @param variableTypeName {String}
219
+ * @returns {UAVariableType|null}
220
+ */
221
+ findVariableType(variableTypeName) {
222
+ return this._variableTypeMap.get(variableTypeName) || null;
223
+ }
224
+ /**
225
+ *
226
+ * @param dataTypeName {String}
227
+ * @returns {UADataType|null}
228
+ */
229
+ findDataType(dataTypeName) {
230
+ return this._dataTypeMap.get(dataTypeName) || null;
231
+ }
232
+ /**
233
+ *
234
+ * @param referenceTypeName {String}
235
+ * @returns {ReferenceType|null}
236
+ */
237
+ findReferenceType(referenceTypeName) {
238
+ return this._referenceTypeMap.get(referenceTypeName) || null;
239
+ }
240
+ /**
241
+ * find a ReferenceType by its inverse name.
242
+ * @method findReferenceTypeFromInverseName
243
+ * @param inverseName {String} the inverse name of the ReferenceType to find
244
+ * @return {ReferenceType}
245
+ */
246
+ findReferenceTypeFromInverseName(inverseName) {
247
+ (0, node_opcua_assert_1.assert)(typeof inverseName === "string");
248
+ const node = this._referenceTypeMapInv.get(inverseName);
249
+ (0, node_opcua_assert_1.assert)(!node || (node.nodeClass === node_opcua_data_model_4.NodeClass.ReferenceType && node.inverseName.text === inverseName));
250
+ return node ? node : null;
251
+ }
252
+ /**
253
+ *
254
+ * @method addAlias
255
+ * @param alias_name {String} the alias name
256
+ * @param nodeId {NodeId} NodeId must belong to this namespace
257
+ */
258
+ addAlias(alias_name, nodeId) {
259
+ (0, node_opcua_assert_1.assert)(typeof alias_name === "string");
260
+ (0, node_opcua_assert_1.assert)(nodeId instanceof node_opcua_nodeid_2.NodeId);
261
+ (0, node_opcua_assert_1.assert)(nodeId.namespace === this.index);
262
+ this._aliases.set(alias_name, nodeId);
263
+ }
264
+ resolveAlias(name) {
265
+ return this._aliases.get(name) || null;
266
+ }
267
+ /**
268
+ * add a new Object type to the address space
269
+ * @method addObjectType
270
+ * @param options
271
+ * @param options.browseName {String} the object type name
272
+ * @param [options.displayName] {String|LocalizedText} the display name
273
+ * @param [options.subtypeOf="BaseObjectType"] {String|NodeId|BaseNode} the base class
274
+ * @param [options.nodeId] {String|NodeId} an optional nodeId for this objectType,
275
+ * if not provided a new nodeId will be created
276
+ * @param [options.isAbstract = false] {Boolean}
277
+ * @param [options.eventNotifier = 0] {Integer}
278
+ * @param [options.postInstantiateFunc = null] {Function}
279
+ *
280
+ */
281
+ addObjectType(options) {
282
+ (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(options, "dataType"), "an objectType should not have a dataType");
283
+ (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(options, "valueRank"), "an objectType should not have a valueRank");
284
+ (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(options, "arrayDimensions"), "an objectType should not have a arrayDimensions");
285
+ return this._addObjectOrVariableType(options, "BaseObjectType", node_opcua_data_model_4.NodeClass.ObjectType);
286
+ }
287
+ /**
288
+ * add a new Variable type to the address space
289
+ * @method addVariableType
290
+ * @param options
291
+ * @param options.browseName {String} the object type name
292
+ * @param [options.displayName] {String|LocalizedText} the display name
293
+ * @param [options.subtypeOf="BaseVariableType"] {String|NodeId|BaseNode} the base class
294
+ * @param [options.nodeId] {String|NodeId} an optional nodeId for this objectType,
295
+ * if not provided a new nodeId will be created
296
+ * @param [options.isAbstract = false] {Boolean}
297
+ * @param options.dataType {String|NodeId} the variable DataType
298
+ * @param [options.valueRank = -1]
299
+ * @param [options.arrayDimensions = null] { Array<Int>>
300
+ *
301
+ */
302
+ addVariableType(options) {
303
+ (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(options, "arrayDimension"), "Do you mean ArrayDimensions ?");
304
+ // dataType
305
+ options.dataType = options.dataType || "Int32";
306
+ options.dataType = this.addressSpace._coerce_DataType(options.dataType);
307
+ // valueRank/ arrayDimensions
308
+ (0, node_opcua_variant_1.verifyRankAndDimensions)(options);
309
+ // arrayDimensions
310
+ const variableType = this._addObjectOrVariableType(options, "BaseVariableType", node_opcua_data_model_4.NodeClass.VariableType);
311
+ variableType.dataType = options.dataType;
312
+ variableType.valueRank = options.valueRank || 0;
313
+ variableType.arrayDimensions = options.arrayDimensions;
314
+ return variableType;
315
+ }
316
+ /**
317
+ * add a variable as a component of the parent node
318
+ *
319
+ * @method addVariable
320
+ * @param options
321
+ * @param options.browseName the variable name
322
+ * @param options.dataType the variable datatype ( "Double", "UInt8" etc...)
323
+ * @param [options.typeDefinition="BaseDataVariableType"]
324
+ * @param [options.modellingRule=null] the Modelling rule : "Optional" , "Mandatory"
325
+ * @param [options.valueRank= -1] the valueRank
326
+ * @param [options.arrayDimensions]
327
+ * @return UAVariable
328
+ */
329
+ addVariable(options) {
330
+ (0, node_opcua_assert_1.assert)(arguments.length === 1, "Invalid arguments IAddressSpace#addVariable now takes only one argument.");
331
+ if (Object.prototype.hasOwnProperty.call(options, "propertyOf") && options.propertyOf) {
332
+ (0, node_opcua_assert_1.assert)(!options.typeDefinition || options.typeDefinition === "PropertyType");
333
+ options.typeDefinition = options.typeDefinition || "PropertyType";
334
+ }
335
+ else {
336
+ (0, node_opcua_assert_1.assert)(!options.typeDefinition || options.typeDefinition !== "PropertyType");
337
+ }
338
+ return this._addVariable(options);
339
+ }
340
+ addView(options) {
341
+ (0, node_opcua_assert_1.assert)(arguments.length === 1, "Namespace#addView expecting a single argument");
342
+ (0, node_opcua_assert_1.assert)(options);
343
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "browseName"));
344
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "organizedBy"));
345
+ const browseName = options.browseName;
346
+ (0, node_opcua_assert_1.assert)(typeof browseName === "string");
347
+ const addressSpace = this.addressSpace;
348
+ const baseDataVariableTypeId = addressSpace.findVariableType("BaseDataVariableType").nodeId;
349
+ // ------------------------------------------ TypeDefinition
350
+ const typeDefinition = options.typeDefinition || baseDataVariableTypeId;
351
+ options.references = options.references || [];
352
+ options.references.push({
353
+ isForward: true,
354
+ nodeId: typeDefinition,
355
+ referenceType: "HasTypeDefinition"
356
+ });
357
+ // xx assert(this.FolderTypeId && this.BaseObjectTypeId); // is default address space generated.?
358
+ const createOptions = options;
359
+ (0, node_opcua_assert_1.assert)(!createOptions.nodeClass);
360
+ createOptions.nodeClass = node_opcua_data_model_4.NodeClass.View;
361
+ const view = this.createNode(createOptions);
362
+ (0, node_opcua_assert_1.assert)(view.nodeId instanceof node_opcua_nodeid_2.NodeId);
363
+ (0, node_opcua_assert_1.assert)(view.nodeClass === node_opcua_data_model_4.NodeClass.View);
364
+ return view;
365
+ }
366
+ addObject(options1) {
367
+ const options = options1;
368
+ (0, node_opcua_assert_1.assert)(!options.nodeClass || options.nodeClass === node_opcua_data_model_4.NodeClass.Object);
369
+ options.nodeClass = node_opcua_data_model_4.NodeClass.Object;
370
+ const typeDefinition = options.typeDefinition || "BaseObjectType";
371
+ options.references = options.references || [];
372
+ options.references.push({ referenceType: "HasTypeDefinition", isForward: true, nodeId: typeDefinition });
373
+ options.eventNotifier = +options.eventNotifier;
374
+ const obj = this.createNode(options);
375
+ (0, node_opcua_assert_1.assert)(obj instanceof ua_object_impl_1.UAObjectImpl);
376
+ (0, node_opcua_assert_1.assert)(obj.nodeClass === node_opcua_data_model_4.NodeClass.Object);
377
+ return obj;
378
+ }
379
+ /**
380
+ *
381
+ * @method addFolder
382
+ * @param parentFolder
383
+ * @param options {String|Object}
384
+ * @param options.browseName {String} the name of the folder
385
+ * @param [options.nodeId] {NodeId}. An optional nodeId for this object
386
+ *
387
+ * @return {BaseNode}
388
+ */
389
+ addFolder(parentFolder, options) {
390
+ if (typeof options === "string") {
391
+ options = { browseName: options };
392
+ }
393
+ const addressSpace = this.addressSpace;
394
+ (0, node_opcua_assert_1.assert)(!options.typeDefinition, "addFolder does not expect typeDefinition to be defined ");
395
+ const typeDefinition = addressSpace._coerceTypeDefinition("FolderType");
396
+ parentFolder = addressSpace._coerceFolder(parentFolder);
397
+ options.nodeClass = node_opcua_data_model_4.NodeClass.Object;
398
+ options.references = [
399
+ { referenceType: "HasTypeDefinition", isForward: true, nodeId: typeDefinition },
400
+ { referenceType: "Organizes", isForward: false, nodeId: parentFolder.nodeId }
401
+ ];
402
+ const node = this.createNode(options);
403
+ return node;
404
+ }
405
+ /**
406
+ * @method addReferenceType
407
+ * @param options
408
+ * @param options.isAbstract
409
+ * @param options.browseName
410
+ * @param options.inverseName
411
+ */
412
+ addReferenceType(options) {
413
+ const addressSpace = this.addressSpace;
414
+ const options1 = options;
415
+ options1.nodeClass = node_opcua_data_model_4.NodeClass.ReferenceType;
416
+ options1.references = options1.references || [];
417
+ if (options.subtypeOf) {
418
+ const subtypeOfNodeId = addressSpace._coerceType(options.subtypeOf, "References", node_opcua_data_model_4.NodeClass.ReferenceType);
419
+ (0, node_opcua_assert_1.assert)(subtypeOfNodeId);
420
+ options1.references.push({
421
+ isForward: false,
422
+ nodeId: subtypeOfNodeId,
423
+ referenceType: "HasSubtype"
424
+ });
425
+ }
426
+ const node = this.internalCreateNode(options1);
427
+ node.propagate_back_references();
428
+ return node;
429
+ }
430
+ /**
431
+ */
432
+ addMultiStateDiscrete(options) {
433
+ return (0, ua_multistate_discrete_impl_1._addMultiStateDiscrete)(this, options);
434
+ }
435
+ /**
436
+ * @method createDataType
437
+ */
438
+ createDataType(options) {
439
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "isAbstract"), "must provide isAbstract");
440
+ (0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(options, "nodeClass"));
441
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "browseName"), "must provide a browseName");
442
+ const options1 = options;
443
+ options1.nodeClass = node_opcua_data_model_4.NodeClass.DataType;
444
+ options1.references = options.references || [];
445
+ if (options1.references.length === 0) {
446
+ if (!options1.subtypeOf) {
447
+ throw new Error("must provide a subtypeOf");
448
+ }
449
+ }
450
+ if (options1.subtypeOf) {
451
+ if (!(options1.subtypeOf instanceof ua_data_type_impl_1.UADataTypeImpl)) {
452
+ options1.subtypeOf = this.addressSpace.findDataType(options1.subtypeOf);
453
+ }
454
+ if (!options1.subtypeOf) {
455
+ throw new Error("cannot find subtypeOf ");
456
+ }
457
+ options1.references.push({
458
+ isForward: false,
459
+ nodeId: options1.subtypeOf.nodeId,
460
+ referenceType: "HasSubtype"
461
+ });
462
+ }
463
+ const node = this.internalCreateNode(options);
464
+ return node;
465
+ }
466
+ /**
467
+ * @method createNode
468
+ * @param options
469
+ * @param options.nodeClass
470
+ * @param [options.nodeVersion {String} = "0" ] install nodeVersion
471
+ * @param [options.modellingRule {String} = null]
472
+ * @internal
473
+ */
474
+ createNode(options) {
475
+ let node = null;
476
+ const addressSpace = this.addressSpace;
477
+ addressSpace.modelChangeTransaction(() => {
478
+ (0, node_opcua_assert_1.assert)(isNonEmptyQualifiedName(options.browseName));
479
+ // xx assert(Object.prototype.hasOwnProperty.call(options,"browseName") && options.browseName.length > 0);
480
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "nodeClass"));
481
+ options.references = addressSpace.normalizeReferenceTypes(options.references);
482
+ const references = _copy_references(options.references);
483
+ _handle_hierarchy_parent(addressSpace, references, options);
484
+ _handle_event_hierarchy_parent(addressSpace, references, options);
485
+ (0, namespace_private_1.UANamespace_process_modelling_rule)(references, options.modellingRule);
486
+ options.references = references;
487
+ node = this.internalCreateNode(options);
488
+ (0, node_opcua_assert_1.assert)(node.nodeId instanceof node_opcua_nodeid_2.NodeId);
489
+ node.propagate_back_references();
490
+ node.install_extra_properties();
491
+ _handle_node_version(node, options);
492
+ (0, address_space_change_event_tools_1._handle_model_change_event)(node);
493
+ });
494
+ return node;
495
+ }
496
+ /**
497
+ * remove the specified Node from the address space
498
+ *
499
+ * @method deleteNode
500
+ * @param nodeOrNodeId
501
+ *
502
+ *
503
+ */
504
+ deleteNode(nodeOrNodeId) {
505
+ let node = null;
506
+ let nodeId = new node_opcua_nodeid_2.NodeId();
507
+ if (nodeOrNodeId instanceof node_opcua_nodeid_2.NodeId) {
508
+ nodeId = nodeOrNodeId;
509
+ node = this.findNode(nodeId);
510
+ // istanbul ignore next
511
+ if (!node) {
512
+ throw new Error(" deleteNode : cannot find node with nodeId" + nodeId.toString());
513
+ }
514
+ }
515
+ else if (nodeOrNodeId instanceof base_node_impl_1.BaseNodeImpl) {
516
+ node = nodeOrNodeId;
517
+ nodeId = node.nodeId;
518
+ }
519
+ // istanbul ignore next
520
+ if (nodeId.namespace !== this.index) {
521
+ throw new Error("this node doesn't belong to this namespace");
522
+ }
523
+ const addressSpace = this.addressSpace;
524
+ addressSpace.modelChangeTransaction(() => {
525
+ /* istanbul ignore next */
526
+ if (!node) {
527
+ throw new Error("this node doesn't belong to this namespace");
528
+ }
529
+ // notify parent that node is being removed
530
+ const hierarchicalReferences = node.findReferencesEx("HierarchicalReferences", node_opcua_data_model_3.BrowseDirection.Inverse);
531
+ for (const ref of hierarchicalReferences) {
532
+ (0, node_opcua_assert_1.assert)(!ref.isForward);
533
+ const parent = addressSpace.findNode(ref.nodeId);
534
+ (0, node_opcua_assert_1.assert)(parent);
535
+ parent._on_child_removed(node);
536
+ }
537
+ function deleteNodePointedByReference(ref) {
538
+ const o = addressSpace.findNode(ref.nodeId);
539
+ addressSpace.deleteNode(o.nodeId);
540
+ }
541
+ // recursively delete all nodes below in the hierarchy of nodes
542
+ // TODO : a better idea would be to extract any references of type "HasChild"
543
+ const components = node.findReferencesEx("HasComponent", node_opcua_data_model_3.BrowseDirection.Forward);
544
+ const properties = node.findReferencesEx("HasProperty", node_opcua_data_model_3.BrowseDirection.Forward);
545
+ // TODO: shall we delete nodes pointed by "Organizes" links here ?
546
+ const subFolders = node.findReferencesEx("Organizes", node_opcua_data_model_3.BrowseDirection.Forward);
547
+ for (const r of components) {
548
+ deleteNodePointedByReference(r);
549
+ }
550
+ for (const r of properties) {
551
+ deleteNodePointedByReference(r);
552
+ }
553
+ for (const r of subFolders) {
554
+ deleteNodePointedByReference(r);
555
+ }
556
+ (0, address_space_change_event_tools_1._handle_delete_node_model_change_event)(node);
557
+ detachNode(node);
558
+ // delete nodes from global index
559
+ const namespace = addressSpace.getNamespace(node.nodeId.namespace);
560
+ namespace._deleteNode(node);
561
+ });
562
+ }
563
+ /**
564
+ * @internals
565
+ */
566
+ getStandardsNodeIds() {
567
+ const standardNodeIds = {
568
+ objectTypeIds: {},
569
+ referenceTypeIds: {}
570
+ };
571
+ for (const referenceType of this._referenceTypeMap.values()) {
572
+ standardNodeIds.referenceTypeIds[referenceType.browseName.name] = referenceType.nodeId.toString();
573
+ }
574
+ for (const objectType of this._objectTypeMap.values()) {
575
+ standardNodeIds.objectTypeIds[objectType.browseName.name] = objectType.nodeId.toString();
576
+ }
577
+ return standardNodeIds;
578
+ }
579
+ // - Events --------------------------------------------------------------------------------------
580
+ /**
581
+ * add a new event type to the address space
582
+ * @method addEventType
583
+ * @param options
584
+ * @param options.browseName {String} the eventType name
585
+ * @param [options.subtypeOf ="BaseEventType"]
586
+ * @param [options.isAbstract = true]
587
+ * @return {UAObjectType} : the object type
588
+ *
589
+ * @example
590
+ *
591
+ * var evtType = namespace.addEventType({
592
+ * browseName: "MyAuditEventType",
593
+ * subtypeOf: "AuditEventType"
594
+ * });
595
+ * var myConditionType = namespace.addEventType({
596
+ * browseName: "MyConditionType",
597
+ * subtypeOf: "ConditionType",
598
+ * isAbstract: false
599
+ * });
600
+ *
601
+ */
602
+ addEventType(options) {
603
+ options.subtypeOf = options.subtypeOf || "BaseEventType";
604
+ // are eventType always abstract ?? No => Condition can be instantiated!
605
+ // but, by default is abstract is true
606
+ options.isAbstract = Object.prototype.hasOwnProperty.call(options, "isAbstract") ? !!options.isAbstract : true;
607
+ return this.addObjectType(options);
608
+ }
609
+ // ---------------------------------------------------------------------------------------------------
610
+ /**
611
+ * @method addDataItem
612
+ * @param options
613
+ * @param options.browseName {String}
614
+ * @param options.definition {String}
615
+ * @param [options.valuePrecision {Double |null} =null]
616
+ * @param options.dataType {NodeId} // todo :check
617
+ * @param options.value
618
+ * @param options.componentOf
619
+ * @return {UAVariable}
620
+ */
621
+ addDataItem(options) {
622
+ const addressSpace = this.addressSpace;
623
+ const dataType = options.dataType || "Number";
624
+ const dataItemType = addressSpace.findVariableType("DataItemType");
625
+ if (!dataItemType) {
626
+ throw new Error("Cannot find DataItemType");
627
+ }
628
+ const variable = this.addVariable(Object.assign(Object.assign({}, options), { dataType, typeDefinition: dataItemType.nodeId }));
629
+ (0, add_dataItem_stuff_1.add_dataItem_stuff)(variable, options);
630
+ variable.install_extra_properties();
631
+ return variable;
632
+ }
633
+ /**
634
+ *
635
+ * @method addAnalogDataItem
636
+ *
637
+ * AnalogDataItem DataItems that represent continuously-variable physical quantities ( e.g., length, temperature),
638
+ * in contrast to the digital representation of data in discrete items
639
+ * NOTE Typical examples are the values provided by temperature sensors or pressure sensors. OPC UA defines a
640
+ * specific UAVariableType to identify an AnalogItem. Properties describe the possible ranges of AnalogItems.
641
+ *
642
+ *
643
+ * @example:
644
+ *
645
+ *
646
+ * namespace.add_analog_dataItem({
647
+ * componentOf: parentObject,
648
+ * browseName: "TemperatureSensor",
649
+ *
650
+ * definition: "(tempA -25) + tempB",
651
+ * valuePrecision: 0.5,
652
+ * //-
653
+ * instrumentRange: { low: 100 , high: 200}, // optional
654
+ * engineeringUnitsRange: { low: 100 , high: 200}, // mandatory
655
+ * engineeringUnits: standardUnits.degree_celsius,, // optional
656
+ *
657
+ * // access level
658
+ * accessLevel: 1
659
+ * minimumSamplingInterval: 10,
660
+ *
661
+ * });
662
+ *
663
+
664
+ * @return {UAVariable}
665
+ */
666
+ addAnalogDataItem(options) {
667
+ const addressSpace = this.addressSpace;
668
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "engineeringUnitsRange"), "expecting engineeringUnitsRange");
669
+ const dataType = options.dataType || "Number";
670
+ const analogItemType = addressSpace.findVariableType("AnalogItemType");
671
+ if (!analogItemType) {
672
+ throw new Error("expecting AnalogItemType to be defined , check nodeset xml file");
673
+ }
674
+ const clone_options = Object.assign(Object.assign({}, options), { dataType, typeDefinition: analogItemType.nodeId });
675
+ const variable = this.addVariable(clone_options);
676
+ (0, add_dataItem_stuff_1.add_dataItem_stuff)(variable, options);
677
+ // mandatory (EURange in the specs)
678
+ // OPC Unified Architecture, Part 8 6 Release 1.02
679
+ // EURange defines the value range likely to be obtained in normal operation. It is intended for such
680
+ // use as automatically scaling a bar graph display
681
+ // Sensor or instrument failure or deactivation can result in a return ed item value which is actually
682
+ // outside of this range. Client software must be prepared to deal with this possibility. Similarly a client
683
+ // may attempt to write a value that is outside of this range back to the server. The exact behavior
684
+ // (accept, reject, clamp, etc.) in this case is server - dependent. However , in general servers shall be
685
+ // prepared to handle this.
686
+ // Example: EURange ::= {-200.0,1400.0}
687
+ const euRange = this.addVariable({
688
+ browseName: { name: "EURange", namespaceIndex: 0 },
689
+ dataType: "Range",
690
+ minimumSamplingInterval: 0,
691
+ modellingRule: options.modellingRule,
692
+ propertyOf: variable,
693
+ typeDefinition: "PropertyType",
694
+ value: new node_opcua_variant_1.Variant({
695
+ dataType: node_opcua_variant_1.DataType.ExtensionObject,
696
+ value: new node_opcua_types_1.Range(options.engineeringUnitsRange)
697
+ })
698
+ });
699
+ (0, node_opcua_assert_1.assert)(euRange.readValue().value.value instanceof node_opcua_types_1.Range);
700
+ const handler = variable.handle_semantic_changed.bind(variable);
701
+ euRange.on("value_changed", handler);
702
+ if (Object.prototype.hasOwnProperty.call(options, "instrumentRange")) {
703
+ const instrumentRange = this.addVariable({
704
+ accessLevel: "CurrentRead | CurrentWrite",
705
+ browseName: { name: "InstrumentRange", namespaceIndex: 0 },
706
+ dataType: "Range",
707
+ minimumSamplingInterval: 0,
708
+ modellingRule: options.modellingRule ? "Mandatory" : undefined,
709
+ propertyOf: variable,
710
+ typeDefinition: "PropertyType",
711
+ value: new node_opcua_variant_1.Variant({
712
+ dataType: node_opcua_variant_1.DataType.ExtensionObject,
713
+ value: new node_opcua_types_1.Range(options.instrumentRange)
714
+ })
715
+ });
716
+ instrumentRange.on("value_changed", handler);
717
+ }
718
+ if (Object.prototype.hasOwnProperty.call(options, "engineeringUnits")) {
719
+ const engineeringUnits = new node_opcua_types_1.EUInformation(options.engineeringUnits);
720
+ (0, node_opcua_assert_1.assert)(engineeringUnits instanceof node_opcua_types_1.EUInformation, "expecting engineering units");
721
+ // EngineeringUnits specifies the units for the DataItem‟s value (e.g., degree, hertz, seconds). The
722
+ // EUInformation type is specified in 5.6.3.
723
+ const eu = this.addVariable({
724
+ accessLevel: "CurrentRead",
725
+ browseName: { name: "EngineeringUnits", namespaceIndex: 0 },
726
+ dataType: "EUInformation",
727
+ minimumSamplingInterval: 0,
728
+ modellingRule: options.modellingRule ? "Mandatory" : undefined,
729
+ propertyOf: variable,
730
+ typeDefinition: "PropertyType",
731
+ value: new node_opcua_variant_1.Variant({
732
+ dataType: node_opcua_variant_1.DataType.ExtensionObject,
733
+ value: engineeringUnits
734
+ })
735
+ });
736
+ eu.on("value_changed", handler);
737
+ }
738
+ variable.install_extra_properties();
739
+ return variable;
740
+ }
741
+ /**
742
+ *
743
+ * @method addMultiStateValueDiscrete
744
+ * @param options {Object}
745
+ * @param options.browseName {String}
746
+ * @param [options.nodeId {NodeId}]
747
+ * @param [options.value {UInt32} = 0 }
748
+ * @param options.enumValues { EnumValueType[]| {Key,Value} }
749
+ * @return {Object|UAVariable}
750
+ *
751
+ * @example
752
+ *
753
+ *
754
+ * namespace.addMultiStateValueDiscrete({
755
+ * componentOf:parentObj,
756
+ * browseName: "myVar",
757
+ * enumValues: {
758
+ * "Red": 0xFF0000,
759
+ * "Green": 0x00FF00,
760
+ * "Blue": 0x0000FF
761
+ * }
762
+ * });
763
+ * addMultiStateValueDiscrete(parentObj,{
764
+ * browseName: "myVar",
765
+ * enumValues: [
766
+ * {
767
+ * value: 0xFF0000,
768
+ * displayName: "Red",
769
+ * description: " The color Red"
770
+ * },
771
+ * {
772
+ * value: 0x00FF000,
773
+ * displayName: "Green",
774
+ * description: " The color Green"
775
+ * },
776
+ * {
777
+ * value: 0x0000FF,
778
+ * displayName: "Blue",
779
+ * description: " The color Blue"
780
+ * }
781
+ *
782
+ * ]
783
+ * });
784
+ */
785
+ addMultiStateValueDiscrete(options) {
786
+ return (0, ua_multistate_value_discrete_impl_1._addMultiStateValueDiscrete)(this, options);
787
+ }
788
+ // -
789
+ /**
790
+ *
791
+ * @method addYArrayItem
792
+ * @param options
793
+ * @param options.componentOf {NodeId}
794
+ * @param options.browseName {String}
795
+ * @param options.title {String}
796
+ * @param [options.instrumentRange]
797
+ * @param [options.instrumentRange.low] {Double}
798
+ * @param [options.instrumentRange.high] {Double}
799
+ * @param options.engineeringUnitsRange.low {Double}
800
+ * @param options.engineeringUnitsRange.high {Double}
801
+ * @param options.engineeringUnits {String}
802
+ * @param [options.nodeId = {NodeId}]
803
+ * @param options.accessLevel
804
+ * @param options.userAccessLevel
805
+ * @param options.title {String}
806
+ * @param options.axisScaleType {AxisScaleEnumeration}
807
+ *
808
+ * @param options.xAxisDefinition {AxisInformation}
809
+ * @param options.xAxisDefinition.engineeringUnits EURange
810
+ * @param options.xAxisDefinition.range
811
+ * @param options.xAxisDefinition.range.low
812
+ * @param options.xAxisDefinition.range.high
813
+ * @param options.xAxisDefinition.title {LocalizedText}
814
+ * @param options.xAxisDefinition.axisScaleType {AxisScaleEnumeration}
815
+ * @param options.xAxisDefinition.axisSteps = <null> {Array<Double>}
816
+ * @param options.value
817
+ */
818
+ addYArrayItem(options) {
819
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "engineeringUnitsRange"), "expecting engineeringUnitsRange");
820
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "axisScaleType"), "expecting axisScaleType");
821
+ (0, node_opcua_assert_1.assert)(options.xAxisDefinition !== null && typeof options.xAxisDefinition === "object", "expecting a xAxisDefinition");
822
+ const addressSpace = this.addressSpace;
823
+ const YArrayItemType = addressSpace.findVariableType("YArrayItemType");
824
+ if (!YArrayItemType) {
825
+ throw new Error("expecting YArrayItemType to be defined , check nodeset xml file");
826
+ }
827
+ function toNodeId(options) {
828
+ if (!options) {
829
+ return (0, node_opcua_nodeid_1.resolveNodeId)(node_opcua_variant_1.DataType.Float);
830
+ }
831
+ if (Object.prototype.hasOwnProperty.call(options, "nodeId") || options instanceof base_node_impl_1.BaseNodeImpl) {
832
+ return options.nodeId;
833
+ }
834
+ return (0, node_opcua_nodeid_1.resolveNodeId)(options);
835
+ }
836
+ const dataType = toNodeId(options.dataType);
837
+ const optionals = [];
838
+ if (Object.prototype.hasOwnProperty.call(options, "instrumentRange")) {
839
+ optionals.push("InstrumentRange");
840
+ }
841
+ const variable = YArrayItemType.instantiate({
842
+ browseName: options.browseName,
843
+ componentOf: options.componentOf,
844
+ dataType,
845
+ optionals
846
+ });
847
+ function coerceAxisScale(value) {
848
+ const ret = node_opcua_data_access_1.AxisScaleEnumeration[value];
849
+ (0, node_opcua_assert_1.assert)(!utils.isNullOrUndefined(ret));
850
+ return ret;
851
+ }
852
+ variable.setValueFromSource(options.value, node_opcua_status_code_1.StatusCodes.Good);
853
+ variable.euRange.setValueFromSource(new node_opcua_variant_1.Variant({
854
+ dataType: node_opcua_variant_1.DataType.ExtensionObject,
855
+ value: new node_opcua_types_1.Range(options.engineeringUnitsRange)
856
+ }));
857
+ if (Object.prototype.hasOwnProperty.call(options, "instrumentRange") && variable.instrumentRange) {
858
+ variable.instrumentRange.setValueFromSource(new node_opcua_variant_1.Variant({
859
+ dataType: node_opcua_variant_1.DataType.ExtensionObject,
860
+ value: new node_opcua_types_1.Range(options.instrumentRange)
861
+ }));
862
+ }
863
+ variable.title.setValueFromSource(new node_opcua_variant_1.Variant({
864
+ dataType: node_opcua_variant_1.DataType.LocalizedText,
865
+ value: (0, node_opcua_data_model_1.coerceLocalizedText)(options.title || "")
866
+ }));
867
+ // Linear/Log/Ln
868
+ variable.axisScaleType.setValueFromSource(new node_opcua_variant_1.Variant({
869
+ dataType: node_opcua_variant_1.DataType.Int32,
870
+ value: coerceAxisScale(options.axisScaleType)
871
+ }));
872
+ variable.xAxisDefinition.setValueFromSource(new node_opcua_variant_1.Variant({
873
+ dataType: node_opcua_variant_1.DataType.ExtensionObject,
874
+ value: new node_opcua_types_1.AxisInformation(options.xAxisDefinition)
875
+ }));
876
+ return variable;
877
+ }
878
+ // - Methods ----------------------------------------------------------------------------------------------------
879
+ /**
880
+ * @method addMethod
881
+ * @param parentObject {Object}
882
+ * @param options {Object}
883
+ * @param [options.nodeId=null] {NodeId} the object nodeid.
884
+ * @param [options.browseName=""] {String} the object browse name.
885
+ * @param [options.description=""] {String} the object description.
886
+ * @param options.inputArguments {Array<Argument>}
887
+ * @param options.outputArguments {Array<Argument>}
888
+ * @return {Object}
889
+ */
890
+ addMethod(parentObject, options) {
891
+ const addressSpace = this.addressSpace;
892
+ (0, node_opcua_assert_1.assert)(parentObject !== null && typeof parentObject === "object" && parentObject instanceof base_node_impl_1.BaseNodeImpl, "expecting a valid parent object");
893
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "browseName"));
894
+ options.componentOf = parentObject;
895
+ const method = this._addMethod(options);
896
+ const propertyTypeId = addressSpace._coerce_VariableTypeIds("PropertyType");
897
+ const nodeId_ArgumentDataType = "Argument"; // makeNodeId(DataTypeIds.Argument);
898
+ if (options.inputArguments) {
899
+ const _inputArgs = new node_opcua_variant_1.Variant({
900
+ arrayType: node_opcua_variant_1.VariantArrayType.Array,
901
+ dataType: node_opcua_variant_1.DataType.ExtensionObject,
902
+ value: options.inputArguments.map((opt) => new node_opcua_types_1.Argument(opt))
903
+ });
904
+ const inputArguments = this.addVariable({
905
+ accessLevel: "CurrentRead",
906
+ arrayDimensions: [_inputArgs.value.length],
907
+ browseName: { name: "InputArguments", namespaceIndex: 0 },
908
+ dataType: nodeId_ArgumentDataType,
909
+ description: "the definition of the input argument of method " +
910
+ parentObject.browseName.toString() +
911
+ "." +
912
+ method.browseName.toString(),
913
+ minimumSamplingInterval: -1,
914
+ modellingRule: "Mandatory",
915
+ propertyOf: method,
916
+ typeDefinition: "PropertyType",
917
+ value: _inputArgs,
918
+ valueRank: 1
919
+ });
920
+ inputArguments.setValueFromSource(_inputArgs);
921
+ (0, node_opcua_assert_1.assert)(inputArguments.typeDefinition.toString() === propertyTypeId.toString());
922
+ (0, node_opcua_assert_1.assert)(Array.isArray(inputArguments.arrayDimensions));
923
+ }
924
+ if (options.outputArguments) {
925
+ const _outputArgs = new node_opcua_variant_1.Variant({
926
+ arrayType: node_opcua_variant_1.VariantArrayType.Array,
927
+ dataType: node_opcua_variant_1.DataType.ExtensionObject,
928
+ value: options.outputArguments.map((opts) => new node_opcua_types_1.Argument(opts))
929
+ });
930
+ const outputArguments = this.addVariable({
931
+ accessLevel: "CurrentRead",
932
+ arrayDimensions: [_outputArgs.value.length],
933
+ browseName: { name: "OutputArguments", namespaceIndex: 0 },
934
+ dataType: nodeId_ArgumentDataType,
935
+ description: "the definition of the output arguments of method " +
936
+ parentObject.browseName.toString() +
937
+ "." +
938
+ method.browseName.toString(),
939
+ minimumSamplingInterval: -1,
940
+ modellingRule: "Mandatory",
941
+ propertyOf: method,
942
+ typeDefinition: "PropertyType",
943
+ value: _outputArgs,
944
+ valueRank: 1
945
+ });
946
+ outputArguments.setValueFromSource(_outputArgs);
947
+ (0, node_opcua_assert_1.assert)(outputArguments.typeDefinition.toString() === propertyTypeId.toString());
948
+ (0, node_opcua_assert_1.assert)(Array.isArray(outputArguments.arrayDimensions));
949
+ }
950
+ // verifying post-conditions
951
+ parentObject.install_extra_properties();
952
+ return method;
953
+ }
954
+ // - Enumeration ------------------------------------------------------------------------------------------------
955
+ /**
956
+ *
957
+ * @method addEnumerationType
958
+ * @param options
959
+ * @param options.browseName {String}
960
+ * @param options.enumeration {Array}
961
+ * @param options.enumeration[].displayName {String|LocalizedText}
962
+ * @param options.enumeration[].value {Number}
963
+ * @param options.enumeration[].description {String|LocalizedText|null}
964
+ */
965
+ addEnumerationType(options) {
966
+ // Release 1.03 OPC Unified Architecture, Part 3 - page 34
967
+ // Enumeration DataTypes are DataTypes that represent discrete sets of named values.
968
+ // Enumerations are always encoded as Int32 on the wire as defined in Part 6. Enumeration
969
+ // DataTypes inherit directly or indirectly from the DataType Enumeration defined in 8.14.
970
+ // Enumerations have no encodings exposed in the IAddressSpace. To expose the human readable
971
+ // representation of an enumerated value the DataType Node may have the EnumString
972
+ // Property that contains an array of LocalizedText. The Integer representation of the enumeration
973
+ // value points to a position within that array. EnumValues Property can be used instead of the
974
+ // EnumStrings to support integer representation of enumerations that are not zero-based or have
975
+ // gaps. It contains an array of a Structured DataType containing the integer representation as
976
+ // well as the human-readable representation. An example of an enumeration DataType containing
977
+ // a sparse list of Integers is NodeClass which is defined in 8.30.
978
+ // OPC Unified Architecture, Part 3 Release 1.03 page 35
979
+ // Table 11 – DataType NodeClass
980
+ // EnumStrings O LocalizedText[] The EnumStrings Property only applies for Enumeration DataTypes.
981
+ // It shall not be applied for other DataTypes. If the EnumValues
982
+ // Property is provided, the EnumStrings Property shall not be provided.
983
+ // Each entry of the array of LocalizedText in this Property represents
984
+ // the human-readable representation of an enumerated value. The
985
+ // Integer representation of the enumeration value points to a position
986
+ // of the array.
987
+ // EnumValues O EnumValueType[] The EnumValues Property only applies for Enumeration DataTypes.
988
+ // It shall not be applied for other DataTypes. If the EnumStrings
989
+ // Property is provided, the EnumValues Property shall not be provided.
990
+ // Using the EnumValues Property it is possible to represent.
991
+ // Enumerations with integers that are not zero-based or have gaps
992
+ // (e.g. 1, 2, 4, 8, 16).
993
+ // Each entry of the array of EnumValueType in this Property
994
+ // represents one enumeration value with its integer notation, human readable
995
+ // representation and help information.
996
+ // The Property EnumStrings contains human-readable representations of enumeration values and is
997
+ // only applied to Enumeration DataTypes. Instead of the EnumStrings Property an Enumeration
998
+ // DataType can also use the EnumValues Property to represent Enumerations with integer values that are not
999
+ // zero-based or containing gaps. There are no additional Properties defined for DataTypes in this standard.
1000
+ // Additional parts of this series of standards may define additional Properties for DataTypes.
1001
+ // 8.40 EnumValueType
1002
+ // This Structured DataType is used to represent a human-readable representation of an
1003
+ // Enumeration. Its elements are described inTable 27. When this type is used in an array representing
1004
+ // human-readable representations of an enumeration, each Value shall be unique in that array.
1005
+ // Table 27 – EnumValueType Definition
1006
+ // Name Type Description
1007
+ // EnumValueType structure
1008
+ // Value Int64 The Integer representation of an Enumeration.
1009
+ // DisplayName LocalizedText A human-readable representation of the Value of the Enumeration.
1010
+ // Description LocalizedText A localized description of the enumeration value. This field can
1011
+ // contain an empty string if no description is available.
1012
+ // Note that the EnumValueType has been defined with a Int64 Value to meet a variety of usages.
1013
+ // When it is used to define the string representation of an Enumeration DataType, the value range
1014
+ // is limited to Int32, because the Enumeration DataType is a subtype of Int32. Part 8 specifies
1015
+ // other usages where the actual value might be between 8 and 64 Bit.
1016
+ (0, node_opcua_assert_1.assert)(typeof options.browseName === "string");
1017
+ (0, node_opcua_assert_1.assert)(Array.isArray(options.enumeration));
1018
+ const addressSpace = this.addressSpace;
1019
+ let definition;
1020
+ const enumerationType = addressSpace.findDataType("Enumeration");
1021
+ (0, node_opcua_assert_1.assert)(enumerationType.nodeId instanceof node_opcua_nodeid_2.NodeId);
1022
+ (0, node_opcua_assert_1.assert)(enumerationType instanceof ua_data_type_impl_1.UADataTypeImpl);
1023
+ const references = [{ referenceType: "HasSubtype", isForward: false, nodeId: enumerationType.nodeId }];
1024
+ const opts = {
1025
+ browseName: options.browseName,
1026
+ definition,
1027
+ description: (0, node_opcua_data_model_1.coerceLocalizedText)(options.description) || null,
1028
+ displayName: options.displayName || null,
1029
+ isAbstract: false,
1030
+ nodeClass: node_opcua_data_model_4.NodeClass.DataType,
1031
+ references
1032
+ };
1033
+ const enumType = this.internalCreateNode(opts); // as UAEnumeration;
1034
+ enumType.propagate_back_references();
1035
+ if (typeof options.enumeration[0] === "string") {
1036
+ const enumeration = options.enumeration;
1037
+ // enumeration is a array of string
1038
+ definition = enumeration.map((str, index) => (0, node_opcua_data_model_1.coerceLocalizedText)(str));
1039
+ const value = new node_opcua_variant_1.Variant({
1040
+ arrayType: node_opcua_variant_1.VariantArrayType.Array,
1041
+ dataType: node_opcua_variant_1.DataType.LocalizedText,
1042
+ value: definition
1043
+ });
1044
+ const enumStrings = this.addVariable({
1045
+ browseName: { name: "EnumStrings", namespaceIndex: 0 },
1046
+ dataType: "LocalizedText",
1047
+ description: "",
1048
+ modellingRule: "Mandatory",
1049
+ propertyOf: enumType,
1050
+ value,
1051
+ valueRank: 1
1052
+ });
1053
+ (0, node_opcua_assert_1.assert)(enumStrings.browseName.toString() === "EnumStrings");
1054
+ // set $definition
1055
+ // EnumDefinition
1056
+ // This Structured DataType is used to provide the metadata for a custom Enumeration or
1057
+ // OptionSet DataType. It is derived from the DataType DataTypeDefinition.
1058
+ // Enum Field:
1059
+ // This Structured DataType is used to provide the metadata for a field of a custom Enumeration
1060
+ // or OptionSet DataType. It is derived from the DataType EnumValueType. If used for an
1061
+ // OptionSet, the corresponding Value in the base type contains the number of the bit associated
1062
+ // with the field. The EnumField is formally defined in Table 37.
1063
+ enumType.$fullDefinition = new node_opcua_types_1.EnumDefinition({
1064
+ fields: enumeration.map((x, index) => new node_opcua_types_1.EnumField({
1065
+ name: x,
1066
+ description: (0, node_opcua_data_model_1.coerceLocalizedText)(x),
1067
+ value: (0, node_opcua_basic_types_1.coerceInt64)(index)
1068
+ }))
1069
+ });
1070
+ }
1071
+ else {
1072
+ const enumeration = options.enumeration;
1073
+ // construct the definition object
1074
+ definition = enumeration.map((enumItem) => {
1075
+ return new node_opcua_types_1.EnumValueType({
1076
+ description: (0, node_opcua_data_model_1.coerceLocalizedText)(enumItem.description),
1077
+ displayName: (0, node_opcua_data_model_1.coerceLocalizedText)(enumItem.displayName),
1078
+ value: [0, enumItem.value]
1079
+ });
1080
+ });
1081
+ const value = new node_opcua_variant_1.Variant({
1082
+ arrayType: node_opcua_variant_1.VariantArrayType.Array,
1083
+ dataType: node_opcua_variant_1.DataType.ExtensionObject,
1084
+ value: definition
1085
+ });
1086
+ const enumValues = this.addVariable({
1087
+ browseName: { name: "EnumValues", namespaceIndex: 0 },
1088
+ dataType: "EnumValueType",
1089
+ description: undefined,
1090
+ modellingRule: "Mandatory",
1091
+ propertyOf: enumType,
1092
+ value,
1093
+ valueRank: 1
1094
+ });
1095
+ (0, node_opcua_assert_1.assert)(enumValues.browseName.toString() === "EnumValues");
1096
+ enumType.$fullDefinition = new node_opcua_types_1.EnumDefinition({
1097
+ fields: enumeration.map((x, index) => new node_opcua_types_1.EnumField({
1098
+ name: x.displayName.toString(),
1099
+ description: x.description || "",
1100
+ value: (0, node_opcua_basic_types_1.coerceInt64)(x.value)
1101
+ }))
1102
+ });
1103
+ }
1104
+ // now create the string value property
1105
+ // <UAVariable NodeId="i=7612" BrowseName="EnumStrings"
1106
+ // ParentNodeId="i=852" DataType="LocalizedText" ValueRank="1">
1107
+ // <DisplayName>EnumStrings</DisplayName>
1108
+ // <References>
1109
+ // <Reference ReferenceType="HasTypeDefinition">i=68</Reference>
1110
+ // <Reference ReferenceType="HasModellingRule">i=78</Reference>
1111
+ // <Reference ReferenceType="HasProperty" IsForward="false">i=852</Reference>
1112
+ // </References>
1113
+ // <Value>
1114
+ // <ListOfLocalizedText xmlns="http://opcfoundation.org/UA/2008/02/Types.xsd">
1115
+ // <LocalizedText><Locale></Locale><Text>Running</Text></LocalizedText>
1116
+ // <LocalizedText><Locale></Locale><Text>Failed</Text>
1117
+ // </ListOfLocalizedText>
1118
+ // </Value>
1119
+ // </UAVariable>
1120
+ return enumType;
1121
+ }
1122
+ // -------------------------------------------------------------------------
1123
+ // State and Transition
1124
+ // -------------------------------------------------------------------------
1125
+ toNodeset2XML() {
1126
+ return "";
1127
+ }
1128
+ // -------------------------------------------------------------------------
1129
+ // State and Transition
1130
+ // -------------------------------------------------------------------------
1131
+ /**
1132
+ * @class IAddressSpace
1133
+ * @method addState
1134
+ * @param component
1135
+ * @param stateName {string}
1136
+ * @param stateNumber {number}
1137
+ * @param isInitialState {boolean}
1138
+ * @return {UAObject} {StateType|InitialStateType}
1139
+ */
1140
+ addState(component, stateName, stateNumber, isInitialState) {
1141
+ const addressSpace = this.addressSpace;
1142
+ isInitialState = !!isInitialState;
1143
+ const _component = component;
1144
+ (0, node_opcua_assert_1.assert)(_component.nodeClass === node_opcua_data_model_4.NodeClass.Object || _component.nodeClass === node_opcua_data_model_4.NodeClass.ObjectType);
1145
+ (0, node_opcua_assert_1.assert)(typeof stateName === "string");
1146
+ (0, node_opcua_assert_1.assert)(typeof isInitialState === "boolean");
1147
+ const initialStateType = addressSpace.findObjectType("InitialStateType");
1148
+ const stateType = addressSpace.findObjectType("StateType");
1149
+ let state;
1150
+ if (isInitialState) {
1151
+ state = initialStateType.instantiate({
1152
+ browseName: stateName,
1153
+ componentOf: _component
1154
+ });
1155
+ }
1156
+ else {
1157
+ state = stateType.instantiate({
1158
+ browseName: stateName,
1159
+ componentOf: _component
1160
+ });
1161
+ }
1162
+ // ensure state number is unique
1163
+ state.stateNumber.setValueFromSource({
1164
+ dataType: node_opcua_variant_1.DataType.UInt32,
1165
+ value: stateNumber
1166
+ });
1167
+ return state;
1168
+ }
1169
+ /**
1170
+ */
1171
+ addTransition(component, fromState, toState, transitionNumber) {
1172
+ const addressSpace = this.addressSpace;
1173
+ const _component = component;
1174
+ (0, node_opcua_assert_1.assert)(_component.nodeClass === node_opcua_data_model_4.NodeClass.Object || _component.nodeClass === node_opcua_data_model_4.NodeClass.ObjectType);
1175
+ (0, node_opcua_assert_1.assert)(typeof fromState === "string");
1176
+ (0, node_opcua_assert_1.assert)(typeof toState === "string");
1177
+ (0, node_opcua_assert_1.assert)(isFinite(transitionNumber));
1178
+ const fromStateNode = _component.getComponentByName(fromState, _component.nodeId.namespace);
1179
+ // istanbul ignore next
1180
+ if (!fromStateNode) {
1181
+ throw new Error("Cannot find state with name " + fromState);
1182
+ }
1183
+ (0, node_opcua_assert_1.assert)(fromStateNode.browseName.name.toString() === fromState);
1184
+ const toStateNode = _component.getComponentByName(toState);
1185
+ // istanbul ignore next
1186
+ if (!toStateNode) {
1187
+ throw new Error("Cannot find state with name " + toState);
1188
+ }
1189
+ (0, node_opcua_assert_1.assert)(toStateNode.browseName.name.toString() === toState);
1190
+ const transitionType = addressSpace.findObjectType("TransitionType");
1191
+ if (!transitionType) {
1192
+ throw new Error("Cannot find TransitionType");
1193
+ }
1194
+ const transition = transitionType.instantiate({
1195
+ browseName: fromState + "To" + toState + "Transition",
1196
+ componentOf: _component
1197
+ });
1198
+ transition.addReference({
1199
+ isForward: true,
1200
+ nodeId: toStateNode.nodeId,
1201
+ referenceType: "ToState"
1202
+ });
1203
+ transition.addReference({
1204
+ isForward: true,
1205
+ nodeId: fromStateNode.nodeId,
1206
+ referenceType: "FromState"
1207
+ });
1208
+ transition.transitionNumber.setValueFromSource({
1209
+ dataType: node_opcua_variant_1.DataType.UInt32,
1210
+ value: transitionNumber
1211
+ });
1212
+ return transition;
1213
+ }
1214
+ /**
1215
+ * @method addTwoStateVariable
1216
+ *
1217
+ * @return {UATwoStateVariable}
1218
+ */
1219
+ addTwoStateVariable(options) {
1220
+ return (0, ua_two_state_variable_1._addTwoStateVariable)(this, options);
1221
+ }
1222
+ /**
1223
+ * @method addTwoStateDiscrete
1224
+ *
1225
+ * Add a TwoStateDiscrete Variable
1226
+ * @return {UATwoStateDiscrete}
1227
+ */
1228
+ addTwoStateDiscrete(options) {
1229
+ return (0, ua_two_state_discrete_impl_1._addTwoStateDiscrete)(this, options);
1230
+ }
1231
+ // --- Alarms & Conditions -------------------------------------------------
1232
+ instantiateCondition(conditionTypeId, options, data) {
1233
+ return ua_condition_impl_1.UAConditionImpl.instantiate(this, conditionTypeId, options, data);
1234
+ }
1235
+ instantiateAcknowledgeableCondition(conditionTypeId, options, data) {
1236
+ return alarms_and_conditions_1.UAAcknowledgeableConditionImpl.instantiate(this, conditionTypeId, options, data);
1237
+ }
1238
+ instantiateAlarmCondition(alarmConditionTypeId, options, data) {
1239
+ return alarms_and_conditions_1.UAAlarmConditionImpl.instantiate(this, alarmConditionTypeId, options, data);
1240
+ }
1241
+ instantiateLimitAlarm(limitAlarmTypeId, options, data) {
1242
+ return ua_limit_alarm_impl_1.UALimitAlarmImpl.instantiate(this, limitAlarmTypeId, options, data);
1243
+ }
1244
+ instantiateExclusiveLimitAlarm(exclusiveLimitAlarmTypeId, options, data) {
1245
+ return ua_exclusive_limit_alarm_impl_1.UAExclusiveLimitAlarmImpl.instantiate(this, exclusiveLimitAlarmTypeId, options, data);
1246
+ }
1247
+ instantiateExclusiveDeviationAlarm(options, data) {
1248
+ return ua_exclusive_deviation_alarm_impl_1.UAExclusiveDeviationAlarmImpl.instantiate(this, "ExclusiveDeviationAlarmType", options, data);
1249
+ }
1250
+ instantiateNonExclusiveLimitAlarm(nonExclusiveLimitAlarmTypeId, options, data) {
1251
+ return ua_non_exclusive_limit_alarm_impl_1.UANonExclusiveLimitAlarmImpl.instantiate(this, nonExclusiveLimitAlarmTypeId, options, data);
1252
+ }
1253
+ instantiateNonExclusiveDeviationAlarm(options, data) {
1254
+ return ua_non_exclusive_deviation_alarm_impl_1.UANonExclusiveDeviationAlarmImpl.instantiate(this, "NonExclusiveDeviationAlarmType", options, data);
1255
+ }
1256
+ instantiateDiscreteAlarm(discreteAlarmType, options, data) {
1257
+ return ua_discrete_alarm_impl_1.UADiscreteAlarmImpl.instantiate(this, discreteAlarmType, options, data);
1258
+ }
1259
+ instantiateOffNormalAlarm(options, data) {
1260
+ return ua_off_normal_alarm_impl_1.UAOffNormalAlarmImpl.instantiate(this, "OffNormalAlarmType", options, data);
1261
+ }
1262
+ // default roles and permissions
1263
+ setDefaultRolePermissions(rolePermissions) {
1264
+ this.defaultRolePermissions = rolePermissions ? (0, role_permissions_1.coerceRolePermissions)(rolePermissions) : undefined;
1265
+ }
1266
+ getDefaultRolePermissions() {
1267
+ return this.defaultRolePermissions || null;
1268
+ }
1269
+ setDefaultAccessRestrictions(accessRestrictions) {
1270
+ this.defaultAccessRestrictions = accessRestrictions;
1271
+ }
1272
+ getDefaultAccessRestrictions() {
1273
+ return this.defaultAccessRestrictions || node_opcua_data_model_1.AccessRestrictionsFlag.None;
1274
+ }
1275
+ // --- internal stuff
1276
+ constructNodeId(options) {
1277
+ return this._nodeIdManager.constructNodeId(options);
1278
+ }
1279
+ _register(node) {
1280
+ (0, node_opcua_assert_1.assert)(node instanceof base_node_impl_1.BaseNodeImpl, "Expecting a instance of BaseNode in _register");
1281
+ (0, node_opcua_assert_1.assert)(node.nodeId instanceof node_opcua_nodeid_2.NodeId, "Expecting a NodeId");
1282
+ if (node.nodeId.namespace !== this.index) {
1283
+ throw new Error("node must belongs to this namespace");
1284
+ }
1285
+ (0, node_opcua_assert_1.assert)(node.nodeId.namespace === this.index, "node must belongs to this namespace");
1286
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(node, "browseName"), "Node must have a browseName");
1287
+ // assert(node.browseName.namespaceIndex === this.index,"browseName must belongs to this namespace");
1288
+ const hashKey = _makeHashKey(node.nodeId);
1289
+ // istanbul ignore next
1290
+ if (this._nodeid_index.has(hashKey)) {
1291
+ throw new Error("node " +
1292
+ node.browseName.toString() +
1293
+ "nodeId = " +
1294
+ node.nodeId.displayText() +
1295
+ " already registered " +
1296
+ node.nodeId.toString() +
1297
+ "\n" +
1298
+ " in namespace " +
1299
+ this.namespaceUri +
1300
+ " index = " +
1301
+ this.index +
1302
+ "\n" +
1303
+ " browseName = " +
1304
+ node.browseName.toString());
1305
+ }
1306
+ this._nodeid_index.set(hashKey, node);
1307
+ switch (node.nodeClass) {
1308
+ case node_opcua_data_model_4.NodeClass.ObjectType:
1309
+ this._registerObjectType(node);
1310
+ break;
1311
+ case node_opcua_data_model_4.NodeClass.VariableType:
1312
+ this._registerVariableType(node);
1313
+ break;
1314
+ case node_opcua_data_model_4.NodeClass.ReferenceType:
1315
+ this._registerReferenceType(node);
1316
+ break;
1317
+ case node_opcua_data_model_4.NodeClass.DataType:
1318
+ this._registerDataType(node);
1319
+ break;
1320
+ case node_opcua_data_model_4.NodeClass.Object:
1321
+ case node_opcua_data_model_4.NodeClass.Variable:
1322
+ case node_opcua_data_model_4.NodeClass.Method:
1323
+ case node_opcua_data_model_4.NodeClass.View:
1324
+ break;
1325
+ default:
1326
+ // tslint:disable-next-line:no-console
1327
+ console.log("Invalid class Name", node.nodeClass);
1328
+ throw new Error("Invalid class name specified");
1329
+ }
1330
+ }
1331
+ /**
1332
+ * @method internalCreateNode
1333
+ * @internal
1334
+ */
1335
+ internalCreateNode(options) {
1336
+ (0, node_opcua_assert_1.assert)(options.nodeClass !== undefined, " options.nodeClass must be specified");
1337
+ (0, node_opcua_assert_1.assert)(options.browseName, "options.browseName must be specified");
1338
+ // xx assert(options.browseName instanceof QualifiedName
1339
+ // ? (options.browseName.namespaceIndex === this.index): true,
1340
+ // "Expecting browseName to have the same namespaceIndex as the namespace");
1341
+ options.description = (0, node_opcua_data_model_1.coerceLocalizedText)(options.description);
1342
+ // browseName adjustment
1343
+ if (typeof options.browseName === "string") {
1344
+ const match = options.browseName.match(regExpNamespaceDotBrowseName);
1345
+ if (match) {
1346
+ const correctedName = match[1];
1347
+ // the application is using an old scheme
1348
+ console.log(chalk.green("Warning : since node-opcua 0.4.2 " + "namespace index should not be prepended to the browse name anymore"));
1349
+ console.log(" ", options.browseName, " will be replaced with ", correctedName);
1350
+ console.log(" Please update your code");
1351
+ const indexVerif = parseInt(match[0], 10);
1352
+ if (indexVerif !== this.index) {
1353
+ errorLog(chalk.red.bold("Error: namespace index used at the front of the browseName " +
1354
+ indexVerif +
1355
+ " do not match the index of the current namespace (" +
1356
+ this.index +
1357
+ ")"));
1358
+ errorLog(" Please fix your code so that the created node is inserted in the correct namespace," +
1359
+ " please refer to the NodeOPCUA documentation");
1360
+ }
1361
+ }
1362
+ options.browseName = new node_opcua_data_model_2.QualifiedName({ name: options.browseName, namespaceIndex: this.index });
1363
+ }
1364
+ else if (!(options.browseName instanceof node_opcua_data_model_2.QualifiedName)) {
1365
+ options.browseName = new node_opcua_data_model_2.QualifiedName(options.browseName);
1366
+ }
1367
+ (0, node_opcua_assert_1.assert)(options.browseName instanceof node_opcua_data_model_2.QualifiedName, "Expecting options.browseName to be instanceof QualifiedName ");
1368
+ // ------------- set display name
1369
+ if (!options.displayName) {
1370
+ (0, node_opcua_assert_1.assert)(typeof options.browseName.name === "string");
1371
+ options.displayName = options.browseName.name;
1372
+ }
1373
+ // --- nodeId adjustment
1374
+ options.nodeId = this.constructNodeId(options);
1375
+ (0, node_opcua_debug_1.dumpIf)(!options.nodeId, options); // missing node Id
1376
+ (0, node_opcua_assert_1.assert)(options.nodeId instanceof node_opcua_nodeid_2.NodeId);
1377
+ // assert(options.browseName.namespaceIndex === this.index,"Expecting browseName to have
1378
+ // the same namespaceIndex as the namespace");
1379
+ const Constructor = _constructors_map[node_opcua_data_model_4.NodeClass[options.nodeClass]];
1380
+ if (!Constructor) {
1381
+ throw new Error(" missing constructor for NodeClass " + node_opcua_data_model_4.NodeClass[options.nodeClass]);
1382
+ }
1383
+ options.addressSpace = this.addressSpace;
1384
+ const node = new Constructor(options);
1385
+ this._register(node);
1386
+ // object shall now be registered
1387
+ // istanbul ignore next
1388
+ if (doDebug) {
1389
+ (0, node_opcua_assert_1.assert)(this.findNode(node.nodeId) !== null && typeof this.findNode(node.nodeId) === "object");
1390
+ }
1391
+ return node;
1392
+ }
1393
+ _deleteNode(node) {
1394
+ (0, node_opcua_assert_1.assert)(node instanceof base_node_impl_1.BaseNodeImpl);
1395
+ const hashKey = _makeHashKey(node.nodeId);
1396
+ // istanbul ignore next
1397
+ if (!this._nodeid_index.has(hashKey)) {
1398
+ throw new Error("deleteNode : nodeId " + node.nodeId.displayText() + " is not registered " + node.nodeId.toString());
1399
+ }
1400
+ switch (node.nodeClass) {
1401
+ case node_opcua_data_model_4.NodeClass.ObjectType:
1402
+ this._unregisterObjectType(node);
1403
+ break;
1404
+ case node_opcua_data_model_4.NodeClass.VariableType:
1405
+ this._unregisterVariableType(node);
1406
+ break;
1407
+ case node_opcua_data_model_4.NodeClass.Object:
1408
+ case node_opcua_data_model_4.NodeClass.Variable:
1409
+ case node_opcua_data_model_4.NodeClass.Method:
1410
+ case node_opcua_data_model_4.NodeClass.View:
1411
+ break;
1412
+ default:
1413
+ // tslint:disable:no-console
1414
+ console.log("Invalid class Name", node.nodeClass);
1415
+ throw new Error("Invalid class name specified");
1416
+ }
1417
+ const deleted = this._nodeid_index.delete(hashKey);
1418
+ (0, node_opcua_assert_1.assert)(deleted);
1419
+ node.dispose();
1420
+ }
1421
+ // --- Private stuff
1422
+ _addObjectOrVariableType(options1, topMostBaseType, nodeClass) {
1423
+ const addressSpace = this.addressSpace;
1424
+ (0, node_opcua_assert_1.assert)(typeof topMostBaseType === "string");
1425
+ (0, node_opcua_assert_1.assert)(nodeClass === node_opcua_data_model_4.NodeClass.ObjectType || nodeClass === node_opcua_data_model_4.NodeClass.VariableType);
1426
+ const options = options1;
1427
+ (0, node_opcua_assert_1.assert)(!options.nodeClass);
1428
+ (0, node_opcua_assert_1.assert)(options.browseName);
1429
+ (0, node_opcua_assert_1.assert)(typeof options.browseName === "string");
1430
+ if (Object.prototype.hasOwnProperty.call(options, "references")) {
1431
+ throw new Error("options.references should not be provided, use options.subtypeOf instead");
1432
+ }
1433
+ const references = [];
1434
+ function process_subtypeOf_options(options2, references1) {
1435
+ // check common misspelling mistake
1436
+ (0, node_opcua_assert_1.assert)(!options2.subTypeOf, "misspell error : it should be 'subtypeOf' instead");
1437
+ if (Object.prototype.hasOwnProperty.call(options2, "hasTypeDefinition")) {
1438
+ throw new Error("hasTypeDefinition option is invalid. Do you mean typeDefinition instead ?");
1439
+ }
1440
+ (0, node_opcua_assert_1.assert)(!options2.typeDefinition, " do you mean subtypeOf ?");
1441
+ const subtypeOfNodeId = addressSpace._coerceType(options2.subtypeOf, topMostBaseType, nodeClass);
1442
+ (0, node_opcua_assert_1.assert)(subtypeOfNodeId);
1443
+ references1.push({
1444
+ isForward: false,
1445
+ nodeId: subtypeOfNodeId,
1446
+ referenceType: "HasSubtype"
1447
+ });
1448
+ }
1449
+ process_subtypeOf_options.call(this, options, references);
1450
+ const objectType = this.internalCreateNode({
1451
+ browseName: options.browseName,
1452
+ displayName: options.displayName,
1453
+ description: options.description,
1454
+ eventNotifier: +options.eventNotifier,
1455
+ isAbstract: !!options.isAbstract,
1456
+ nodeClass,
1457
+ nodeId: options.nodeId,
1458
+ references
1459
+ });
1460
+ objectType.propagate_back_references();
1461
+ objectType.install_extra_properties();
1462
+ objectType.installPostInstallFunc(options.postInstantiateFunc);
1463
+ return objectType;
1464
+ }
1465
+ // private _adjust_options(options: any) {
1466
+ // const ns = this.addressSpace.getNamespaceIndex(this.namespaceUri);
1467
+ // if (!options.nodeId) {
1468
+ // const id = this._getNextAvailableId();
1469
+ // options.nodeId = new NodeId(NodeId.NodeIdType.NUMERIC, id, ns);
1470
+ // }
1471
+ // options.nodeId = NodeId.coerce(options.nodeId);
1472
+ // if (typeof options.browseName === "string") {
1473
+ // options.browseName = new QualifiedName({
1474
+ // name: options.browseName,
1475
+ // namespaceIndex: ns
1476
+ // });
1477
+ // }
1478
+ // return options;
1479
+ // }
1480
+ _registerObjectType(node) {
1481
+ (0, node_opcua_assert_1.assert)(this.index === node.nodeId.namespace);
1482
+ const key = node.browseName.name;
1483
+ (0, node_opcua_assert_1.assert)(!this._objectTypeMap.has(key), " UAObjectType already declared");
1484
+ this._objectTypeMap.set(key, node);
1485
+ }
1486
+ _registerVariableType(node) {
1487
+ (0, node_opcua_assert_1.assert)(this.index === node.nodeId.namespace);
1488
+ const key = node.browseName.name;
1489
+ (0, node_opcua_assert_1.assert)(!this._variableTypeMap.has(key), " UAVariableType already declared");
1490
+ this._variableTypeMap.set(key, node);
1491
+ }
1492
+ _registerReferenceType(node) {
1493
+ (0, node_opcua_assert_1.assert)(this.index === node.nodeId.namespace);
1494
+ (0, node_opcua_assert_1.assert)(node.browseName instanceof node_opcua_data_model_2.QualifiedName);
1495
+ const key = node.browseName.name;
1496
+ this._referenceTypeMap.set(key, node);
1497
+ this._referenceTypeMapInv.set(node.inverseName.text, node);
1498
+ }
1499
+ _registerDataType(node) {
1500
+ (0, node_opcua_assert_1.assert)(this.index === node.nodeId.namespace);
1501
+ const key = node.browseName.name;
1502
+ (0, node_opcua_assert_1.assert)(node.browseName instanceof node_opcua_data_model_2.QualifiedName);
1503
+ (0, node_opcua_assert_1.assert)(!this._dataTypeMap.has(key), " DataType already declared");
1504
+ this._dataTypeMap.set(key, node);
1505
+ }
1506
+ _unregisterObjectType(node) {
1507
+ const key = node.browseName.name;
1508
+ this._objectTypeMap.delete(key);
1509
+ }
1510
+ _unregisterVariableType(node) {
1511
+ const key = node.browseName.name;
1512
+ this._variableTypeMap.delete(key);
1513
+ }
1514
+ /**
1515
+ * @private
1516
+ */
1517
+ _addVariable(options) {
1518
+ const addressSpace = this.addressSpace;
1519
+ const baseDataVariableType = addressSpace.findVariableType("BaseDataVariableType");
1520
+ if (!baseDataVariableType) {
1521
+ throw new Error("cannot find BaseDataVariableType");
1522
+ }
1523
+ const baseDataVariableTypeId = baseDataVariableType.nodeId;
1524
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "browseName"), "options.browseName must be provided");
1525
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "dataType"), "options.dataType must be provided");
1526
+ options.historizing = !!options.historizing;
1527
+ // xx assert(this.FolderTypeId && this.BaseObjectTypeId); // is default address space generated.?
1528
+ // istanbul ignore next
1529
+ if (Object.prototype.hasOwnProperty.call(options, "hasTypeDefinition")) {
1530
+ throw new Error("hasTypeDefinition option is invalid. Do you mean typeDefinition instead ?");
1531
+ }
1532
+ // ------------------------------------------ TypeDefinition
1533
+ let typeDefinition = options.typeDefinition || baseDataVariableTypeId;
1534
+ typeDefinition = addressSpace._coerce_VariableTypeIds(typeDefinition);
1535
+ (0, node_opcua_assert_1.assert)(typeDefinition instanceof node_opcua_nodeid_2.NodeId);
1536
+ // ------------------------------------------ DataType
1537
+ options.dataType = addressSpace._coerce_DataType(options.dataType);
1538
+ options.valueRank = utils.isNullOrUndefined(options.valueRank)
1539
+ ? options.arrayDimensions
1540
+ ? options.arrayDimensions.length
1541
+ : -1
1542
+ : options.valueRank;
1543
+ (0, node_opcua_assert_1.assert)(typeof options.valueRank === "number" && isFinite(options.valueRank));
1544
+ options.arrayDimensions = options.arrayDimensions || null;
1545
+ (0, node_opcua_assert_1.assert)(Array.isArray(options.arrayDimensions) || options.arrayDimensions === null);
1546
+ // -----------------------------------------------------
1547
+ options.minimumSamplingInterval = options.minimumSamplingInterval !== undefined ? +options.minimumSamplingInterval : 0;
1548
+ let references = options.references || [];
1549
+ references = [].concat(references, [
1550
+ {
1551
+ isForward: true,
1552
+ nodeId: typeDefinition,
1553
+ referenceType: "HasTypeDefinition"
1554
+ }
1555
+ ]);
1556
+ (0, node_opcua_assert_1.assert)(!options.nodeClass || options.nodeClass === node_opcua_data_model_4.NodeClass.Variable);
1557
+ options.nodeClass = node_opcua_data_model_4.NodeClass.Variable;
1558
+ options.references = references;
1559
+ const variable = this.createNode(options);
1560
+ return variable;
1561
+ }
1562
+ /**
1563
+ * @private
1564
+ */
1565
+ _addMethod(options) {
1566
+ const addressSpace = this.addressSpace;
1567
+ (0, node_opcua_assert_1.assert)(isNonEmptyQualifiedName(options.browseName));
1568
+ const references = [];
1569
+ (0, node_opcua_assert_1.assert)(isNonEmptyQualifiedName(options.browseName));
1570
+ _handle_hierarchy_parent(addressSpace, references, options);
1571
+ (0, namespace_private_1.UANamespace_process_modelling_rule)(references, options.modellingRule);
1572
+ const method = this.internalCreateNode({
1573
+ browseName: options.browseName,
1574
+ description: options.description || "",
1575
+ displayName: options.displayName,
1576
+ eventNotifier: +options.eventNotifier,
1577
+ isAbstract: false,
1578
+ nodeClass: node_opcua_data_model_4.NodeClass.Method,
1579
+ nodeId: options.nodeId,
1580
+ references,
1581
+ rolePermissions: options.rolePermissions
1582
+ });
1583
+ (0, node_opcua_assert_1.assert)(method.nodeId !== null);
1584
+ method.propagate_back_references();
1585
+ (0, node_opcua_assert_1.assert)(!method.typeDefinition);
1586
+ return method;
1587
+ }
1588
+ }
1589
+ exports.NamespaceImpl = NamespaceImpl;
1590
+ NamespaceImpl._handle_hierarchy_parent = _handle_hierarchy_parent;
1591
+ NamespaceImpl.isNonEmptyQualifiedName = isNonEmptyQualifiedName;
1592
+ const _constructors_map = {
1593
+ DataType: ua_data_type_impl_1.UADataTypeImpl,
1594
+ Method: ua_method_impl_1.UAMethodImpl,
1595
+ Object: ua_object_impl_1.UAObjectImpl,
1596
+ ObjectType: ua_object_type_impl_1.UAObjectTypeImpl,
1597
+ ReferenceType: ua_reference_type_impl_1.UAReferenceTypeImpl,
1598
+ Variable: ua_variable_impl_1.UAVariableImpl,
1599
+ VariableType: ua_variable_type_impl_1.UAVariableTypeImpl,
1600
+ View: ua_view_impl_1.UAViewImpl
1601
+ };
1602
+ /**
1603
+ * @method _coerce_parent
1604
+ * convert a 'string' , NodeId or Object into a valid and existing object
1605
+ * @param addressSpace {IAddressSpace}
1606
+ * @param value
1607
+ * @param coerceFunc
1608
+ * @private
1609
+ */
1610
+ function _coerce_parent(addressSpace, value, coerceFunc) {
1611
+ (0, node_opcua_assert_1.assert)(typeof coerceFunc === "function");
1612
+ if (value) {
1613
+ if (typeof value === "string") {
1614
+ value = coerceFunc.call(addressSpace, value);
1615
+ }
1616
+ if (value instanceof node_opcua_nodeid_2.NodeId) {
1617
+ value = addressSpace.findNode(value);
1618
+ }
1619
+ }
1620
+ (0, node_opcua_assert_1.assert)(!value || value instanceof base_node_impl_1.BaseNodeImpl);
1621
+ return value;
1622
+ }
1623
+ function _handle_event_hierarchy_parent(addressSpace, references, options) {
1624
+ options.eventSourceOf = _coerce_parent(addressSpace, options.eventSourceOf, addressSpace._coerceNode);
1625
+ options.notifierOf = _coerce_parent(addressSpace, options.notifierOf, addressSpace._coerceNode);
1626
+ if (options.eventSourceOf) {
1627
+ (0, node_opcua_assert_1.assert)(!options.notifierOf, "notifierOf shall not be provided with eventSourceOf ");
1628
+ references.push({
1629
+ isForward: false,
1630
+ nodeId: options.eventSourceOf.nodeId,
1631
+ referenceType: "HasEventSource"
1632
+ });
1633
+ options.eventNotifier = options.eventNotifier || 1;
1634
+ }
1635
+ else if (options.notifierOf) {
1636
+ (0, node_opcua_assert_1.assert)(!options.eventSourceOf, "eventSourceOf shall not be provided with notifierOf ");
1637
+ references.push({
1638
+ isForward: false,
1639
+ nodeId: options.notifierOf.nodeId,
1640
+ referenceType: "HasNotifier"
1641
+ });
1642
+ }
1643
+ }
1644
+ function _handle_hierarchy_parent(addressSpace, references, options) {
1645
+ options.componentOf = _coerce_parent(addressSpace, options.componentOf, addressSpace._coerceNode);
1646
+ options.propertyOf = _coerce_parent(addressSpace, options.propertyOf, addressSpace._coerceNode);
1647
+ options.organizedBy = _coerce_parent(addressSpace, options.organizedBy, addressSpace._coerceFolder);
1648
+ options.encodingOf = _coerce_parent(addressSpace, options.encodingOf, addressSpace._coerceNode);
1649
+ if (options.componentOf) {
1650
+ (0, node_opcua_assert_1.assert)(!options.propertyOf);
1651
+ (0, node_opcua_assert_1.assert)(!options.organizedBy);
1652
+ (0, node_opcua_assert_1.assert)(addressSpace.rootFolder.objects, "addressSpace must have a rootFolder.objects folder");
1653
+ (0, node_opcua_assert_1.assert)(options.componentOf.nodeId !== addressSpace.rootFolder.objects.nodeId, "Only Organizes References are used to relate Objects to the 'Objects' standard Object.");
1654
+ references.push({
1655
+ isForward: false,
1656
+ nodeId: options.componentOf.nodeId,
1657
+ referenceType: "HasComponent"
1658
+ });
1659
+ }
1660
+ if (options.propertyOf) {
1661
+ (0, node_opcua_assert_1.assert)(!options.componentOf);
1662
+ (0, node_opcua_assert_1.assert)(!options.organizedBy);
1663
+ (0, node_opcua_assert_1.assert)(options.propertyOf.nodeId !== addressSpace.rootFolder.objects.nodeId, "Only Organizes References are used to relate Objects to the 'Objects' standard Object.");
1664
+ references.push({
1665
+ isForward: false,
1666
+ nodeId: options.propertyOf.nodeId,
1667
+ referenceType: "HasProperty"
1668
+ });
1669
+ }
1670
+ if (options.organizedBy) {
1671
+ (0, node_opcua_assert_1.assert)(!options.propertyOf);
1672
+ (0, node_opcua_assert_1.assert)(!options.componentOf);
1673
+ references.push({
1674
+ isForward: false,
1675
+ nodeId: options.organizedBy.nodeId,
1676
+ referenceType: "Organizes"
1677
+ });
1678
+ }
1679
+ if (options.encodingOf) {
1680
+ // parent must be a DataType
1681
+ (0, node_opcua_assert_1.assert)(options.encodingOf.nodeClass === node_opcua_data_model_4.NodeClass.DataType, "encodingOf must be toward a DataType");
1682
+ references.push({
1683
+ isForward: false,
1684
+ nodeId: options.encodingOf.nodeId,
1685
+ referenceType: "HasEncoding"
1686
+ });
1687
+ }
1688
+ }
1689
+ exports._handle_hierarchy_parent = _handle_hierarchy_parent;
1690
+ function _copy_reference(reference) {
1691
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(reference, "referenceType"));
1692
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(reference, "isForward"));
1693
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(reference, "nodeId"));
1694
+ (0, node_opcua_assert_1.assert)(reference.nodeId instanceof node_opcua_nodeid_2.NodeId);
1695
+ return {
1696
+ isForward: reference.isForward,
1697
+ nodeId: reference.nodeId,
1698
+ referenceType: reference.referenceType
1699
+ };
1700
+ }
1701
+ function _copy_references(references) {
1702
+ references = references || [];
1703
+ return references.map(_copy_reference);
1704
+ }
1705
+ function isNonEmptyQualifiedName(browseName) {
1706
+ if (!browseName) {
1707
+ return false;
1708
+ }
1709
+ if (typeof browseName === "string") {
1710
+ return browseName.length >= 0;
1711
+ }
1712
+ if (!(browseName instanceof node_opcua_data_model_2.QualifiedName)) {
1713
+ browseName = new node_opcua_data_model_2.QualifiedName(browseName);
1714
+ }
1715
+ (0, node_opcua_assert_1.assert)(browseName instanceof node_opcua_data_model_2.QualifiedName);
1716
+ return browseName.name.length > 0;
1717
+ }
1718
+ exports.isNonEmptyQualifiedName = isNonEmptyQualifiedName;
1719
+ function _handle_node_version(node, options) {
1720
+ (0, node_opcua_assert_1.assert)(options);
1721
+ if (options.nodeVersion) {
1722
+ (0, node_opcua_assert_1.assert)(node.nodeClass === node_opcua_data_model_4.NodeClass.Variable || node.nodeClass === node_opcua_data_model_4.NodeClass.Object);
1723
+ const nodeVersion = node.addressSpace.getOwnNamespace().addVariable({
1724
+ browseName: "NodeVersion",
1725
+ dataType: "String",
1726
+ propertyOf: node
1727
+ });
1728
+ const initialValue = typeof options.nodeVersion === "string" ? options.nodeVersion : "0";
1729
+ // xx console.log(" init value =",initialValue);
1730
+ nodeVersion.setValueFromSource({ dataType: "String", value: initialValue });
1731
+ }
1732
+ }
1733
1733
  //# sourceMappingURL=namespace_impl.js.map