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