node-opcua-address-space 2.56.2 → 2.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/LICENSE +20 -20
  2. package/dist/source/address_space_ts.d.ts +0 -2
  3. package/dist/source/helpers/argument_list.js +12 -1
  4. package/dist/source/helpers/argument_list.js.map +1 -1
  5. package/dist/source/loader/load_nodeset2.js +76 -67
  6. package/dist/source/loader/load_nodeset2.js.map +1 -1
  7. package/dist/source/session_context.js +2 -2
  8. package/dist/source/session_context.js.map +1 -1
  9. package/dist/source/set_namespace_meta_data.js +1 -1
  10. package/dist/src/address_space.d.ts +2 -3
  11. package/dist/src/address_space.js +9 -6
  12. package/dist/src/address_space.js.map +1 -1
  13. package/dist/src/address_space_private.d.ts +2 -3
  14. package/dist/src/alarms_and_conditions/condition_snapshot.js +3 -3
  15. package/dist/src/alarms_and_conditions/condition_snapshot.js.map +1 -1
  16. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js +2 -1
  17. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js.map +1 -1
  18. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js +1 -1
  19. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js.map +1 -1
  20. package/dist/src/alarms_and_conditions/ua_condition_impl.js +8 -6
  21. package/dist/src/alarms_and_conditions/ua_condition_impl.js.map +1 -1
  22. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js +1 -1
  23. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js.map +1 -1
  24. package/dist/src/base_node_private.js +2 -2
  25. package/dist/src/base_node_private.js.map +1 -1
  26. package/dist/src/event_data.js +1 -1
  27. package/dist/src/event_data.js.map +1 -1
  28. package/dist/src/namespace_impl.d.ts +2 -2
  29. package/dist/src/namespace_impl.js +9 -9
  30. package/dist/src/namespace_impl.js.map +1 -1
  31. package/dist/src/nodeset_tools/nodeset_to_xml.js +16 -10
  32. package/dist/src/nodeset_tools/nodeset_to_xml.js.map +1 -1
  33. package/dist/src/nodeset_tools/typedictionary_to_xml.js +17 -10
  34. package/dist/src/nodeset_tools/typedictionary_to_xml.js.map +1 -1
  35. package/dist/src/reference_impl.js +1 -1
  36. package/dist/src/reference_impl.js.map +1 -1
  37. package/dist/src/state_machine/ua_shelving_state_machine_ex.js +20 -13
  38. package/dist/src/state_machine/ua_shelving_state_machine_ex.js.map +1 -1
  39. package/dist/src/ua_data_type_impl.d.ts +15 -5
  40. package/dist/src/ua_data_type_impl.js +129 -51
  41. package/dist/src/ua_data_type_impl.js.map +1 -1
  42. package/dist/src/ua_method_impl.d.ts +3 -2
  43. package/dist/src/ua_method_impl.js +5 -0
  44. package/dist/src/ua_method_impl.js.map +1 -1
  45. package/dist/src/ua_variable_impl.d.ts +6 -6
  46. package/dist/src/ua_variable_impl.js +236 -188
  47. package/dist/src/ua_variable_impl.js.map +1 -1
  48. package/dist/src/ua_variable_type_impl.d.ts +3 -4
  49. package/dist/src/ua_variable_type_impl.js +13 -18
  50. package/dist/src/ua_variable_type_impl.js.map +1 -1
  51. package/distHelpers/add_event_generator_object.js.map +1 -1
  52. package/distHelpers/mock_session.js +1 -1
  53. package/distHelpers/mock_session.js.map +1 -1
  54. package/generate.js +1 -1
  55. package/nodeJS.d.ts +1 -1
  56. package/package.json +36 -36
  57. package/source/address_space_ts.ts +0 -1
  58. package/source/helpers/argument_list.ts +13 -3
  59. package/source/loader/load_nodeset2.ts +99 -79
  60. package/source/session_context.ts +1 -1
  61. package/source/set_namespace_meta_data.ts +1 -1
  62. package/source_nodejs/index.ts +1 -1
  63. package/src/address_space.ts +21 -14
  64. package/src/address_space_private.ts +3 -3
  65. package/src/alarms_and_conditions/condition_snapshot.ts +4 -4
  66. package/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.ts +7 -6
  67. package/src/alarms_and_conditions/ua_alarm_condition_impl.ts +2 -2
  68. package/src/alarms_and_conditions/ua_condition_impl.ts +29 -15
  69. package/src/alarms_and_conditions/ua_off_normal_alarm_impl.ts +1 -1
  70. package/src/base_node_private.ts +6 -2
  71. package/src/event_data.ts +1 -1
  72. package/src/namespace_impl.ts +9 -9
  73. package/src/nodeset_tools/nodeset_to_xml.ts +22 -12
  74. package/src/nodeset_tools/typedictionary_to_xml.ts +17 -7
  75. package/src/reference_impl.ts +3 -3
  76. package/src/state_machine/ua_shelving_state_machine_ex.ts +32 -19
  77. package/src/ua_data_type_impl.ts +168 -61
  78. package/src/ua_method_impl.ts +11 -5
  79. package/src/ua_variable_impl.ts +290 -218
  80. package/src/ua_variable_type_impl.ts +9 -15
  81. package/testHelpers.d.ts +1 -1
  82. package/test_helpers/add_event_generator_object.ts +4 -3
  83. package/test_helpers/mock_session.ts +1 -1
  84. package/test_helpers/test_fixtures/dataType_in_separateNamespace.xml +150 -150
  85. package/test_helpers/test_fixtures/dataType_in_separateNamespace_basic.xml +57 -57
  86. package/test_helpers/test_fixtures/dataType_in_separateNamespace_mix.xml +135 -135
  87. package/test_helpers/test_fixtures/dataType_withEnumeration.xml +82 -82
  88. package/test_helpers/test_fixtures/dataType_with_isOptionSet.xml +194 -194
  89. package/test_helpers/test_fixtures/dataType_with_union.xml +1 -1
  90. package/test_helpers/test_fixtures/fixture_empty_nodeset2.xml +106 -106
  91. package/test_helpers/test_fixtures/fixture_simple_statemachine_nodeset2.xml +1312 -1303
  92. package/test_helpers/test_fixtures/fixuture_nodeset_objects_with_some_methods.xml +362 -362
  93. package/test_helpers/test_fixtures/issue_846.xml +3172 -3172
  94. package/test_helpers/test_fixtures/issue_899_variable_with_nodeid_value.xml +32 -32
  95. package/test_helpers/test_fixtures/mini.Node.Set2.xml +14 -0
  96. package/test_helpers/test_fixtures/mini.nodeset.withVariousVariables.xml +194 -194
  97. package/test_helpers/test_fixtures/minimalist_nodeset_with_models.xml +8 -8
  98. package/test_helpers/test_fixtures/minimalist_nodeset_with_models_more_complex.xml +16 -16
  99. package/test_helpers/test_fixtures/nodeset_with_analog_items.xml +45 -45
  100. package/dist/source/interfaces/alarms_and_conditions/ua_condition_base_i.d.ts +0 -23
  101. package/dist/source/interfaces/alarms_and_conditions/ua_condition_base_i.js +0 -3
  102. package/dist/source/interfaces/alarms_and_conditions/ua_condition_base_i.js.map +0 -1
  103. package/dist/source/interfaces/data_access/ua_discrete_item.d.ts +0 -6
  104. package/dist/source/interfaces/data_access/ua_discrete_item.js +0 -3
  105. package/dist/source/interfaces/data_access/ua_discrete_item.js.map +0 -1
  106. package/dist/source/interfaces/data_access/ua_multistate_discrete.d.ts +0 -25
  107. package/dist/source/interfaces/data_access/ua_multistate_discrete.js +0 -3
  108. package/dist/source/interfaces/data_access/ua_multistate_discrete.js.map +0 -1
  109. package/dist/source/interfaces/data_access/ua_multistate_value_discrete.d.ts +0 -27
  110. package/dist/source/interfaces/data_access/ua_multistate_value_discrete.js +0 -3
  111. package/dist/source/interfaces/data_access/ua_multistate_value_discrete.js.map +0 -1
  112. package/dist/source/interfaces/data_access/ua_two_state_discrete.d.ts +0 -17
  113. package/dist/source/interfaces/data_access/ua_two_state_discrete.js +0 -3
  114. package/dist/source/interfaces/data_access/ua_two_state_discrete.js.map +0 -1
  115. package/dist/source/interfaces/data_access/ua_y_array_item.d.ts +0 -19
  116. package/dist/source/interfaces/data_access/ua_y_array_item.js +0 -3
  117. package/dist/source/interfaces/data_access/ua_y_array_item.js.map +0 -1
  118. package/dist/source/interfaces/state_machine/exclusive_limit_state_machine.d.ts +0 -11
  119. package/dist/source/interfaces/state_machine/exclusive_limit_state_machine.js +0 -3
  120. package/dist/source/interfaces/state_machine/exclusive_limit_state_machine.js.map +0 -1
  121. package/dist/source/interfaces/state_machine/finite_state_machine.d.ts +0 -70
  122. package/dist/source/interfaces/state_machine/finite_state_machine.js +0 -3
  123. package/dist/source/interfaces/state_machine/finite_state_machine.js.map +0 -1
  124. package/dist/source/interfaces/state_machine/program_finite_state_machine.d.ts +0 -74
  125. package/dist/source/interfaces/state_machine/program_finite_state_machine.js +0 -3
  126. package/dist/source/interfaces/state_machine/program_finite_state_machine.js.map +0 -1
  127. package/dist/source/interfaces/state_machine/state_machine.d.ts +0 -342
  128. package/dist/source/interfaces/state_machine/state_machine.js +0 -3
  129. package/dist/source/interfaces/state_machine/state_machine.js.map +0 -1
  130. package/dist/source/interfaces/state_machine/ua_finite_state_variable.d.ts +0 -18
  131. package/dist/source/interfaces/state_machine/ua_finite_state_variable.js +0 -3
  132. package/dist/source/interfaces/state_machine/ua_finite_state_variable.js.map +0 -1
  133. package/dist/source/interfaces/state_machine/ua_state_variable.d.ts +0 -29
  134. package/dist/source/interfaces/state_machine/ua_state_variable.js +0 -3
  135. package/dist/source/interfaces/state_machine/ua_state_variable.js.map +0 -1
  136. package/dist/source/interfaces/state_machine/ua_two_state_variable.d.ts +0 -26
  137. package/dist/source/interfaces/state_machine/ua_two_state_variable.js +0 -3
  138. package/dist/source/interfaces/state_machine/ua_two_state_variable.js.map +0 -1
  139. package/dist/source/interfaces/subscription_diagnostics_variable.d.ts +0 -41
  140. package/dist/source/interfaces/subscription_diagnostics_variable.js +0 -3
  141. package/dist/source/interfaces/subscription_diagnostics_variable.js.map +0 -1
  142. package/dist/src/alarms_and_conditions/base_event_type.d.ts +0 -26
  143. package/dist/src/alarms_and_conditions/base_event_type.js +0 -41
  144. package/dist/src/alarms_and_conditions/base_event_type.js.map +0 -1
  145. package/dist/src/alarms_and_conditions/shelving_state_machine.d.ts +0 -22
  146. package/dist/src/alarms_and_conditions/shelving_state_machine.js +0 -241
  147. package/dist/src/alarms_and_conditions/shelving_state_machine.js.map +0 -1
  148. package/dist/src/alarms_and_conditions/trip_alarm.d.ts +0 -16
  149. package/dist/src/alarms_and_conditions/trip_alarm.js +0 -21
  150. package/dist/src/alarms_and_conditions/trip_alarm.js.map +0 -1
  151. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_base.d.ts +0 -54
  152. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_base.js +0 -255
  153. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_base.js.map +0 -1
  154. package/dist/src/alarms_and_conditions/ua_alarm_condition_base.d.ts +0 -138
  155. package/dist/src/alarms_and_conditions/ua_alarm_condition_base.js +0 -460
  156. package/dist/src/alarms_and_conditions/ua_alarm_condition_base.js.map +0 -1
  157. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm.d.ts +0 -35
  158. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm.js +0 -32
  159. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm.js.map +0 -1
  160. package/dist/src/alarms_and_conditions/ua_condition_base.d.ts +0 -191
  161. package/dist/src/alarms_and_conditions/ua_condition_base.js +0 -1029
  162. package/dist/src/alarms_and_conditions/ua_condition_base.js.map +0 -1
  163. package/dist/src/alarms_and_conditions/ua_discrete_alarm.d.ts +0 -11
  164. package/dist/src/alarms_and_conditions/ua_discrete_alarm.js +0 -58
  165. package/dist/src/alarms_and_conditions/ua_discrete_alarm.js.map +0 -1
  166. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm.d.ts +0 -24
  167. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm.js +0 -59
  168. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm.js.map +0 -1
  169. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm.d.ts +0 -14
  170. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm.js +0 -17
  171. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm.js.map +0 -1
  172. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm.d.ts +0 -22
  173. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm.js +0 -87
  174. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm.js.map +0 -1
  175. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm.d.ts +0 -6
  176. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm.js +0 -11
  177. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm.js.map +0 -1
  178. package/dist/src/alarms_and_conditions/ua_limit_alarm.d.ts +0 -76
  179. package/dist/src/alarms_and_conditions/ua_limit_alarm.js +0 -237
  180. package/dist/src/alarms_and_conditions/ua_limit_alarm.js.map +0 -1
  181. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm.d.ts +0 -27
  182. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm.js +0 -62
  183. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm.js.map +0 -1
  184. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm.d.ts +0 -49
  185. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm.js +0 -176
  186. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm.js.map +0 -1
  187. package/dist/src/alarms_and_conditions/ua_off_normal_alarm.d.ts +0 -47
  188. package/dist/src/alarms_and_conditions/ua_off_normal_alarm.js +0 -151
  189. package/dist/src/alarms_and_conditions/ua_off_normal_alarm.js.map +0 -1
  190. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm.d.ts +0 -16
  191. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm.js +0 -18
  192. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm.js.map +0 -1
  193. package/dist/src/base_node.d.ts +0 -289
  194. package/dist/src/base_node.js +0 -1345
  195. package/dist/src/base_node.js.map +0 -1
  196. package/dist/src/data_access/ua_analog_item.d.ts +0 -13
  197. package/dist/src/data_access/ua_analog_item.js +0 -37
  198. package/dist/src/data_access/ua_analog_item.js.map +0 -1
  199. package/dist/src/data_access/ua_data_item.d.ts +0 -16
  200. package/dist/src/data_access/ua_data_item.js +0 -66
  201. package/dist/src/data_access/ua_data_item.js.map +0 -1
  202. package/dist/src/data_access/ua_multistate_discrete.d.ts +0 -24
  203. package/dist/src/data_access/ua_multistate_discrete.js +0 -132
  204. package/dist/src/data_access/ua_multistate_discrete.js.map +0 -1
  205. package/dist/src/namespace.d.ts +0 -472
  206. package/dist/src/namespace.js +0 -1751
  207. package/dist/src/namespace.js.map +0 -1
  208. package/dist/src/reference.d.ts +0 -43
  209. package/dist/src/reference.js +0 -138
  210. package/dist/src/reference.js.map +0 -1
  211. package/dist/src/session_context.d.ts +0 -4
  212. package/dist/src/session_context.js +0 -9
  213. package/dist/src/session_context.js.map +0 -1
  214. package/dist/src/ua_data_type.d.ts +0 -83
  215. package/dist/src/ua_data_type.js +0 -289
  216. package/dist/src/ua_data_type.js.map +0 -1
  217. package/dist/src/ua_method.d.ts +0 -41
  218. package/dist/src/ua_method.js +0 -202
  219. package/dist/src/ua_method.js.map +0 -1
  220. package/dist/src/ua_object.d.ts +0 -28
  221. package/dist/src/ua_object.js +0 -153
  222. package/dist/src/ua_object.js.map +0 -1
  223. package/dist/src/ua_object_type.d.ts +0 -49
  224. package/dist/src/ua_object_type.js +0 -123
  225. package/dist/src/ua_object_type.js.map +0 -1
  226. package/dist/src/ua_reference_type.d.ts +0 -42
  227. package/dist/src/ua_reference_type.js +0 -138
  228. package/dist/src/ua_reference_type.js.map +0 -1
  229. package/dist/src/ua_variable.d.ts +0 -339
  230. package/dist/src/ua_variable.js +0 -1706
  231. package/dist/src/ua_variable.js.map +0 -1
  232. package/dist/src/ua_variable_type.d.ts +0 -57
  233. package/dist/src/ua_variable_type.js +0 -530
  234. package/dist/src/ua_variable_type.js.map +0 -1
  235. package/dist/src/ua_view.d.ts +0 -16
  236. package/dist/src/ua_view.js +0 -42
  237. package/dist/src/ua_view.js.map +0 -1
@@ -1,1345 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseNode = exports.makeAttributeEventName = void 0;
4
- /**
5
- * @module node-opcua-address-space
6
- */
7
- const chalk = require("chalk");
8
- const events_1 = require("events");
9
- const lodash_1 = require("lodash");
10
- const node_opcua_assert_1 = require("node-opcua-assert");
11
- const node_opcua_data_model_1 = require("node-opcua-data-model");
12
- const node_opcua_data_value_1 = require("node-opcua-data-value");
13
- const node_opcua_debug_1 = require("node-opcua-debug");
14
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
15
- const node_opcua_status_code_1 = require("node-opcua-status-code");
16
- const node_opcua_types_1 = require("node-opcua-types");
17
- const utils = require("node-opcua-utils");
18
- const node_opcua_utils_1 = require("node-opcua-utils");
19
- const node_opcua_variant_1 = require("node-opcua-variant");
20
- const source_1 = require("../source");
21
- const cetools = require("./address_space_change_event_tools");
22
- const base_node_private_1 = require("./base_node_private");
23
- const reference_1 = require("./reference");
24
- // tslint:disable:no-var-requires
25
- // tslint:disable:no-bitwise
26
- // tslint:disable:no-console
27
- const doDebug = false;
28
- const warningLog = node_opcua_debug_1.make_warningLog(__filename);
29
- function defaultBrowseFilterFunc(context) {
30
- return true;
31
- }
32
- function _get_QualifiedBrowseName(browseName) {
33
- return node_opcua_data_model_1.coerceQualifiedName(browseName);
34
- }
35
- function _is_valid_BrowseDirection(browseDirection) {
36
- return (browseDirection === node_opcua_data_model_1.BrowseDirection.Forward ||
37
- browseDirection === node_opcua_data_model_1.BrowseDirection.Inverse ||
38
- browseDirection === node_opcua_data_model_1.BrowseDirection.Both);
39
- }
40
- function coerceRolePermissions(rolePermissions) {
41
- if (!rolePermissions)
42
- return undefined;
43
- return rolePermissions.map(rp => new node_opcua_types_1.RolePermissionType(rp));
44
- }
45
- function makeAttributeEventName(attributeId) {
46
- const attributeName = node_opcua_data_model_1.attributeNameById[attributeId];
47
- return attributeName + "_changed";
48
- }
49
- exports.makeAttributeEventName = makeAttributeEventName;
50
- /**
51
- * Base class for all Node classes
52
- *
53
- * BaseNode is the base class for all the OPCUA objects in the address space
54
- * It provides attributes and a set of references to other nodes.
55
- * see:
56
- * {{#crossLink "UAObject"}}{{/crossLink}},
57
- * {{#crossLink "UAVariable"}}{{/crossLink}},
58
- * {{#crossLink "Reference"}}{{/crossLink}},
59
- * {{#crossLink "UAMethod"}}{{/crossLink}},
60
- * {{#crossLink "UAView"}}{{/crossLink}},
61
- * {{#crossLink "UAObjectType"}}{{/crossLink}},
62
- * {{#crossLink "UADataType"}}{{/crossLink}},
63
- * {{#crossLink "UAVariableType"}}{{/crossLink}},
64
- *
65
- *
66
- */
67
- class BaseNode extends events_1.EventEmitter {
68
- /**
69
- * @internal
70
- * @param options
71
- */
72
- constructor(options) {
73
- super();
74
- this.nodeClass = node_opcua_data_model_1.NodeClass.Unspecified;
75
- node_opcua_assert_1.assert(this.nodeClass === node_opcua_data_model_1.NodeClass.Unspecified, "must not be specify a nodeClass");
76
- node_opcua_assert_1.assert(options.addressSpace); // expecting an address space
77
- node_opcua_assert_1.assert(options.browseName instanceof node_opcua_data_model_1.QualifiedName, "Expecting a valid QualifiedName");
78
- node_opcua_assert_1.assert(options.nodeId instanceof node_opcua_nodeid_1.NodeId, "Expecting a valid NodeId");
79
- options.references = options.references || [];
80
- const _private = base_node_private_1.BaseNode_initPrivate(this);
81
- _private.__address_space = options.addressSpace;
82
- this.nodeId = node_opcua_nodeid_1.resolveNodeId(options.nodeId);
83
- // QualifiedName
84
- /**
85
- * the node browseName
86
- * @property browseName
87
- * @type QualifiedName
88
- * @static
89
- */
90
- this.browseName = _get_QualifiedBrowseName(options.browseName);
91
- // re-use browseName as displayName if displayName is missing
92
- options.displayName = options.displayName || this.browseName.name.toString();
93
- if (options.description === undefined) {
94
- options.description = null;
95
- }
96
- this._setDisplayName(options.displayName);
97
- this._setDescription(options.description);
98
- // user defined filter function for browsing
99
- const _browseFilter = options.browseFilter || defaultBrowseFilterFunc;
100
- node_opcua_assert_1.assert(typeof _browseFilter === "function");
101
- _private._browseFilter = _browseFilter;
102
- // normalize reference type
103
- // this will convert any referenceType expressed with its inverseName into
104
- // its normal name and fix the isForward flag accordingly.
105
- // ( e.g "ComponentOf" isForward:true => "HasComponent", isForward:false)
106
- for (const reference of options.references) {
107
- this.__addReference(reference);
108
- }
109
- this.accessRestrictions = options.accessRestrictions;
110
- this.rolePermissions = coerceRolePermissions(options.rolePermissions);
111
- }
112
- get addressSpace() {
113
- const _private = base_node_private_1.BaseNode_getPrivate(this);
114
- // istanbul ignore next
115
- if (!_private) {
116
- throw new Error("Internal error , cannot extract private data from " + this.browseName.toString());
117
- }
118
- return _private.__address_space;
119
- }
120
- get displayName() {
121
- const _private = base_node_private_1.BaseNode_getPrivate(this);
122
- return _private._displayName;
123
- }
124
- set displayName(value) {
125
- this._setDisplayName(value);
126
- /**
127
- * fires when the displayName is changed.
128
- * @event DisplayName_changed
129
- * @param dataValue {DataValue}
130
- */
131
- this._notifyAttributeChange(node_opcua_data_model_1.AttributeIds.DisplayName);
132
- }
133
- get description() {
134
- const _private = base_node_private_1.BaseNode_getPrivate(this);
135
- return _private._description;
136
- }
137
- set description(value) {
138
- this._setDescription(value);
139
- /**
140
- * fires when the description attribute is changed.
141
- * @event Description_changed
142
- * @param dataValue {DataValue}
143
- */
144
- this._notifyAttributeChange(node_opcua_data_model_1.AttributeIds.Description);
145
- }
146
- /**
147
- * returns the nodeId of this node's Type Definition
148
- */
149
- get typeDefinition() {
150
- const _cache = base_node_private_1.BaseNode_getCache(this);
151
- if (!_cache.typeDefinition) {
152
- const has_type_definition_ref = this.findReference("HasTypeDefinition", true);
153
- _cache.typeDefinition = has_type_definition_ref ? has_type_definition_ref.nodeId : null;
154
- }
155
- return _cache.typeDefinition;
156
- }
157
- /**
158
- * returns the nodeId of this node's Type Definition
159
- */
160
- get typeDefinitionObj() {
161
- const _cache = base_node_private_1.BaseNode_getCache(this);
162
- if (undefined === _cache.typeDefinitionObj) {
163
- const nodeId = this.typeDefinition;
164
- _cache.typeDefinitionObj = nodeId ? this.addressSpace.findNode(nodeId) : null;
165
- }
166
- return _cache.typeDefinitionObj;
167
- }
168
- get parentNodeId() {
169
- const parent = this.parent;
170
- return parent ? parent.nodeId : undefined;
171
- }
172
- /**
173
- * namespace index
174
- */
175
- get namespaceIndex() {
176
- return this.nodeId.namespace;
177
- }
178
- /**
179
- * namespace uri
180
- */
181
- get namespaceUri() {
182
- return this.addressSpace.getNamespaceUri(this.namespaceIndex);
183
- }
184
- /**
185
- * the parent node
186
- */
187
- get parent() {
188
- const _private = base_node_private_1.BaseNode_getPrivate(this);
189
- if (_private._parent === undefined) {
190
- // never been set before
191
- _private._parent = _setup_parent_item.call(this, _private._referenceIdx);
192
- }
193
- return _private._parent || null;
194
- }
195
- /**
196
- * @property modellingRule
197
- * @type {String|undefined}
198
- */
199
- get modellingRule() {
200
- const node = this;
201
- const r = node.findReferencesAsObject("HasModellingRule");
202
- if (!r || r.length === 0) {
203
- return null; /// "? modellingRule missing ?"; // consider "Mandatory"
204
- }
205
- const r0 = r[0];
206
- return r0.browseName.toString();
207
- }
208
- static makeAttributeEventName(attributeId) {
209
- return makeAttributeEventName(attributeId);
210
- }
211
- getDisplayName(locale) {
212
- const _private = base_node_private_1.BaseNode_getPrivate(this);
213
- return _private._displayName[0].text;
214
- }
215
- get namespace() {
216
- return this.addressSpace.getNamespace(this.nodeId.namespace);
217
- }
218
- // ---------------------------------------------------------------------------------------------------
219
- // Finders
220
- // ---------------------------------------------------------------------------------------------------
221
- findReferencesEx(strReference, browseDirection) {
222
- browseDirection = browseDirection !== undefined ? browseDirection : node_opcua_data_model_1.BrowseDirection.Forward;
223
- node_opcua_assert_1.assert(_is_valid_BrowseDirection(browseDirection));
224
- node_opcua_assert_1.assert(browseDirection !== node_opcua_data_model_1.BrowseDirection.Both);
225
- let referenceType = null;
226
- if (typeof strReference === "string") {
227
- // xx strReference = strReference.browseName.toString();
228
- referenceType = this.addressSpace.findReferenceType(strReference);
229
- if (!referenceType) {
230
- throw new Error("Cannot resolve referenceType : " + strReference);
231
- }
232
- }
233
- else {
234
- referenceType = strReference;
235
- }
236
- if (!referenceType) {
237
- // note: when loading nodeset2.xml files, reference type may not exit yet
238
- // throw new Error("expecting valid reference name " + strReference);
239
- return [];
240
- }
241
- const isForward = browseDirection === node_opcua_data_model_1.BrowseDirection.Forward;
242
- const results = [];
243
- function process(referenceIdx) {
244
- const references = Object.values(referenceIdx);
245
- for (const ref of references) {
246
- if (ref.isForward === isForward && referenceType && referenceType.checkHasSubtype(ref.referenceType)) {
247
- results.push(ref);
248
- }
249
- }
250
- }
251
- const _private = base_node_private_1.BaseNode_getPrivate(this);
252
- process(_private._referenceIdx);
253
- process(_private._back_referenceIdx);
254
- return results;
255
- }
256
- /**
257
- * @method findReferences
258
- * @param referenceType {String|NodeId|ReferenceType} the referenceType as a string.
259
- * @param [isForward] default=true
260
- * @return an array with references
261
- */
262
- findReferences(referenceType, isForward) {
263
- const _cache = base_node_private_1.BaseNode_getCache(this);
264
- const _private = base_node_private_1.BaseNode_getPrivate(this);
265
- isForward = utils.isNullOrUndefined(isForward) ? true : !!isForward;
266
- const referenceTypeNode = this._coerceReferenceType(referenceType);
267
- const hash = "_ref_" + referenceTypeNode.nodeId.toString() + isForward.toString();
268
- if (_cache[hash]) {
269
- return _cache[hash];
270
- }
271
- // istanbul ignore next
272
- if (doDebug && !this.addressSpace.findReferenceType(referenceTypeNode)) {
273
- throw new Error("expecting valid reference name " + referenceType);
274
- }
275
- const result = [];
276
- for (const ref of Object.values(_private._referenceIdx)) {
277
- if (ref.isForward === isForward) {
278
- if (node_opcua_nodeid_1.sameNodeId(ref.referenceType, referenceTypeNode.nodeId)) {
279
- result.push(ref);
280
- }
281
- }
282
- }
283
- for (const ref of Object.values(_private._back_referenceIdx)) {
284
- if (ref.isForward === isForward) {
285
- if (node_opcua_nodeid_1.sameNodeId(ref.referenceType, referenceTypeNode.nodeId)) {
286
- result.push(ref);
287
- }
288
- }
289
- }
290
- _cache[hash] = result;
291
- return result;
292
- }
293
- /**
294
- * @method findReference
295
- * @param strReference the referenceType as a string.
296
- * @param [isForward]
297
- * @return {Reference}
298
- */
299
- findReference(strReference, isForward) {
300
- const refs = this.findReferences(strReference, isForward);
301
- // yy if (optionalSymbolicName) {
302
- // yy // search reference that matches symbolic name
303
- // yy refs = refs.filter((ref: Reference) => ref.symbolicName === optionalSymbolicName);
304
- // yy }
305
- node_opcua_assert_1.assert(refs.length === 1 || refs.length === 0, "findReference: expecting only one or zero element here");
306
- return refs.length === 0 ? null : refs[0];
307
- }
308
- findReferencesExAsObject(strReference, browseDirection) {
309
- const references = this.findReferencesEx(strReference, browseDirection);
310
- return _asObject(references, this.addressSpace);
311
- }
312
- findReferencesAsObject(strReference, isForward) {
313
- const references = this.findReferences(strReference, isForward);
314
- return _asObject(references, this.addressSpace);
315
- }
316
- /**
317
- * return an array with the Aggregates of this object.
318
- */
319
- getAggregates() {
320
- const _cache = base_node_private_1.BaseNode_getCache(this);
321
- if (!_cache._aggregates) {
322
- _cache._aggregates = this.findReferencesExAsObject("Aggregates", node_opcua_data_model_1.BrowseDirection.Forward);
323
- }
324
- return _cache._aggregates;
325
- }
326
- /**
327
- * return an array with the components of this object.
328
- */
329
- getComponents() {
330
- const _cache = base_node_private_1.BaseNode_getCache(this);
331
- if (!_cache._components) {
332
- _cache._components = this.findReferencesExAsObject("HasComponent", node_opcua_data_model_1.BrowseDirection.Forward);
333
- }
334
- return _cache._components;
335
- }
336
- /**
337
- * return a array with the properties of this object.
338
- */
339
- getProperties() {
340
- const _cache = base_node_private_1.BaseNode_getCache(this);
341
- if (!_cache._properties) {
342
- _cache._properties = this.findReferencesExAsObject("HasProperty", node_opcua_data_model_1.BrowseDirection.Forward);
343
- }
344
- return _cache._properties;
345
- }
346
- /**
347
- * return a array with the notifiers of this object.
348
- */
349
- getNotifiers() {
350
- const _cache = base_node_private_1.BaseNode_getCache(this);
351
- if (!_cache._notifiers) {
352
- _cache._notifiers = this.findReferencesAsObject("HasNotifier", true);
353
- }
354
- return _cache._notifiers;
355
- }
356
- /**
357
- * return a array with the event source of this object.
358
- */
359
- getEventSources() {
360
- const _cache = base_node_private_1.BaseNode_getCache(this);
361
- if (!_cache._eventSources) {
362
- _cache._eventSources = this.findReferencesAsObject("HasEventSource", true);
363
- }
364
- return _cache._eventSources;
365
- }
366
- /**
367
- * return a array of the objects for which this node is an EventSource
368
- */
369
- getEventSourceOfs() {
370
- const _cache = base_node_private_1.BaseNode_getCache(this);
371
- if (!_cache._eventSources) {
372
- _cache._eventSources = this.findReferencesAsObject("HasEventSource", false);
373
- }
374
- return _cache._eventSources;
375
- }
376
- getComponentByName(browseName, namespaceIndex) {
377
- const components = this.getComponents();
378
- const select = _filter_by_browse_name(components, browseName, namespaceIndex);
379
- node_opcua_assert_1.assert(select.length <= 1, "BaseNode#getComponentByName found duplicated reference");
380
- if (select.length === 1) {
381
- const component = select[0];
382
- if (component.nodeClass === node_opcua_data_model_1.NodeClass.Method) {
383
- warningLog("please use getMethodByName to retrieve a method");
384
- return null;
385
- }
386
- node_opcua_assert_1.assert(component.nodeClass === node_opcua_data_model_1.NodeClass.Variable || component.nodeClass === node_opcua_data_model_1.NodeClass.Object);
387
- return component;
388
- }
389
- else {
390
- return null;
391
- }
392
- }
393
- getPropertyByName(browseName, namespaceIndex) {
394
- const properties = this.getProperties();
395
- const select = _filter_by_browse_name(properties, browseName, namespaceIndex);
396
- node_opcua_assert_1.assert(select.length <= 1, "BaseNode#getPropertyByName found duplicated reference");
397
- if (select.length === 1 && select[0].nodeClass !== node_opcua_data_model_1.NodeClass.Variable) {
398
- throw new Error("Expecting a property to be of nodeClass==NodeClass.Variable");
399
- }
400
- return select.length === 1 ? select[0] : null;
401
- }
402
- getFolderElementByName(browseName, namespaceIndex) {
403
- const elements = this.getFolderElements();
404
- const select = _filter_by_browse_name(elements, browseName, namespaceIndex);
405
- return select.length === 1 ? select[0] : null;
406
- }
407
- /**
408
- * returns the list of nodes that this folder object organizes
409
- */
410
- getFolderElements() {
411
- return this.findReferencesAsObject("Organizes", true);
412
- }
413
- /**
414
- * returns the list of methods that this object provides
415
- * @method getMethods
416
- * @return an array with Method objects.
417
- *
418
- *
419
- * Note: internally, methods are special types of components
420
- */
421
- getMethods() {
422
- const _cache = base_node_private_1.BaseNode_getCache(this);
423
- if (!_cache._methods) {
424
- const components = this.getComponents();
425
- _cache._methods = components.filter((obj) => obj.nodeClass === node_opcua_data_model_1.NodeClass.Method);
426
- }
427
- return _cache._methods;
428
- }
429
- /**
430
- * returns the method exposed by this object and with the given nodeId
431
- */
432
- getMethodById(nodeId) {
433
- const methods = this.getMethods();
434
- const found = methods.find((m) => m.nodeId.toString() === nodeId.toString());
435
- return found || null;
436
- }
437
- getMethodByName(browseName, namespaceIndex) {
438
- const methods = this.getMethods();
439
- const select = _filter_by_browse_name(methods, browseName, namespaceIndex);
440
- node_opcua_assert_1.assert(select.length <= 1, "BaseNode#getMethodByName found duplicated reference");
441
- return select.length === 1 ? select[0] : null;
442
- }
443
- getWriteMask() {
444
- return 0;
445
- }
446
- getUserWriteMask() {
447
- return 0;
448
- }
449
- readAttribute(context, attributeId, indexRange, dataEncoding) {
450
- node_opcua_assert_1.assert(!context || context instanceof source_1.SessionContext);
451
- const options = {};
452
- options.statusCode = node_opcua_status_code_1.StatusCodes.Good;
453
- switch (attributeId) {
454
- case node_opcua_data_model_1.AttributeIds.NodeId: // NodeId
455
- options.value = { dataType: node_opcua_variant_1.DataType.NodeId, value: this.nodeId };
456
- break;
457
- case node_opcua_data_model_1.AttributeIds.NodeClass: // NodeClass
458
- node_opcua_assert_1.assert(isFinite(this.nodeClass));
459
- options.value = { dataType: node_opcua_variant_1.DataType.Int32, value: this.nodeClass };
460
- break;
461
- case node_opcua_data_model_1.AttributeIds.BrowseName: // QualifiedName
462
- node_opcua_assert_1.assert(this.browseName instanceof node_opcua_data_model_1.QualifiedName);
463
- options.value = { dataType: node_opcua_variant_1.DataType.QualifiedName, value: this.browseName };
464
- break;
465
- case node_opcua_data_model_1.AttributeIds.DisplayName: // LocalizedText
466
- options.value = { dataType: node_opcua_variant_1.DataType.LocalizedText, value: this.displayName[0] };
467
- break;
468
- case node_opcua_data_model_1.AttributeIds.Description: // LocalizedText
469
- options.value = { dataType: node_opcua_variant_1.DataType.LocalizedText, value: this.description };
470
- break;
471
- case node_opcua_data_model_1.AttributeIds.WriteMask:
472
- options.value = { dataType: node_opcua_variant_1.DataType.UInt32, value: this.getWriteMask() };
473
- break;
474
- case node_opcua_data_model_1.AttributeIds.UserWriteMask:
475
- options.value = { dataType: node_opcua_variant_1.DataType.UInt32, value: this.getUserWriteMask() };
476
- break;
477
- case node_opcua_data_model_1.AttributeIds.AccessRestrictions:
478
- return this._readAccessRestrictions(context);
479
- case node_opcua_data_model_1.AttributeIds.RolePermissions:
480
- return this._readRolePermissions(context);
481
- case node_opcua_data_model_1.AttributeIds.UserRolePermissions:
482
- return this._readUserRolePermissions(context);
483
- default:
484
- options.value = null;
485
- options.statusCode = node_opcua_status_code_1.StatusCodes.BadAttributeIdInvalid;
486
- break;
487
- }
488
- // xx options.serverTimestamp = new Date();
489
- return new node_opcua_data_value_1.DataValue(options);
490
- }
491
- writeAttribute(context, writeValue, callback) {
492
- context = context || source_1.SessionContext.defaultContext;
493
- node_opcua_assert_1.assert(context instanceof source_1.SessionContext);
494
- node_opcua_assert_1.assert(typeof callback === "function");
495
- if (writeValue.attributeId <= 0 || writeValue.attributeId > node_opcua_data_model_1.AttributeIds.UserExecutable) {
496
- return callback(null, node_opcua_status_code_1.StatusCodes.BadAttributeIdInvalid);
497
- }
498
- // by default Node is read-only,
499
- // this method needs to be overridden to change the behavior
500
- callback(null, node_opcua_status_code_1.StatusCodes.BadNotWritable);
501
- }
502
- fullName() {
503
- if (this.parentNodeId) {
504
- const parent = this.addressSpace.findNode(this.parentNodeId);
505
- // istanbul ignore else
506
- if (parent) {
507
- return parent.fullName() + "." + this.browseName.toString() + "";
508
- }
509
- else {
510
- return "NOT YET REGISTERED" + this.parentNodeId.toString() + "." + this.browseName.toString() + "";
511
- }
512
- }
513
- return this.browseName.toString();
514
- }
515
- ownReferences() {
516
- const _private = base_node_private_1.BaseNode_getPrivate(this);
517
- return Object.values(_private._referenceIdx);
518
- }
519
- /**
520
- * @method browseNodeByTargetName
521
- *
522
- * @param relativePathElement
523
- * @param isLast
524
- * @return {NodeId[]}
525
- */
526
- browseNodeByTargetName(relativePathElement, isLast) {
527
- relativePathElement.targetName = relativePathElement.targetName || new node_opcua_data_model_1.QualifiedName({});
528
- // part 4.0 v1.03 $7.26 RelativePath
529
- // The BrowseName of the target node.
530
- // The final element may have an empty targetName. In this situation all targets of the references identified by
531
- // the referenceTypeId are the targets of the RelativePath.
532
- // The targetName shall be specified for all other elements.
533
- // The current path cannot be followed any further if no targets with the specified BrowseName exist.
534
- node_opcua_assert_1.assert(relativePathElement.targetName instanceof node_opcua_data_model_1.QualifiedName);
535
- node_opcua_assert_1.assert(relativePathElement.targetName.namespaceIndex >= 0);
536
- node_opcua_assert_1.assert(relativePathElement.targetName.name.length > 0);
537
- // The type of reference to follow from the current node.
538
- // The current path cannot be followed any further if the referenceTypeId is not available on the Node instance.
539
- // If not specified then all References are included and the parameter includeSubtypes is ignored.
540
- node_opcua_assert_1.assert(relativePathElement.hasOwnProperty("referenceTypeId"));
541
- // Indicates whether the inverse Reference should be followed.
542
- // The inverse reference is followed if this value is TRUE.
543
- node_opcua_assert_1.assert(relativePathElement.hasOwnProperty("isInverse"));
544
- // Indicates whether subtypes of the ReferenceType should be followed.
545
- // Subtypes are included if this value is TRUE.
546
- node_opcua_assert_1.assert(relativePathElement.hasOwnProperty("includeSubtypes"));
547
- const references = this.allReferences();
548
- const _check_reference = (reference) => {
549
- if (relativePathElement.referenceTypeId.isEmpty()) {
550
- return true;
551
- }
552
- node_opcua_assert_1.assert(relativePathElement.referenceTypeId instanceof node_opcua_nodeid_1.NodeId);
553
- if ((relativePathElement.isInverse && reference.isForward) ||
554
- (!relativePathElement.isInverse && !reference.isForward)) {
555
- return false;
556
- }
557
- node_opcua_assert_1.assert(reference.hasOwnProperty("isForward"));
558
- const referenceType = resolveReferenceType(this.addressSpace, reference);
559
- const referenceTypeId = referenceType.nodeId;
560
- if (node_opcua_nodeid_1.sameNodeId(relativePathElement.referenceTypeId, referenceTypeId)) {
561
- return true;
562
- }
563
- if (relativePathElement.includeSubtypes) {
564
- const baseType = this.addressSpace.findReferenceType(relativePathElement.referenceTypeId);
565
- if (baseType && referenceType.isSupertypeOf(baseType)) {
566
- return true;
567
- }
568
- }
569
- return false;
570
- };
571
- const nodeIdsMap = {};
572
- let nodeIds = [];
573
- for (const reference of references) {
574
- if (!_check_reference(reference)) {
575
- continue;
576
- }
577
- const obj = resolveReferenceNode(this.addressSpace, reference);
578
- // istanbul ignore next
579
- if (!obj) {
580
- throw new Error(" cannot find node with id " + reference.nodeId.toString());
581
- }
582
- if (lodash_1.isEqual(obj.browseName, relativePathElement.targetName)) {
583
- // compare QualifiedName
584
- const key = obj.nodeId.toString();
585
- if (!nodeIdsMap.hasOwnProperty(key)) {
586
- nodeIds.push(obj.nodeId);
587
- nodeIdsMap[key] = obj;
588
- }
589
- }
590
- }
591
- if (nodeIds.length === 0 && (this.nodeClass === node_opcua_data_model_1.NodeClass.ObjectType || this.nodeClass === node_opcua_data_model_1.NodeClass.VariableType)) {
592
- const nodeType = this;
593
- if (nodeType.subtypeOf) {
594
- // browsing also InstanceDeclarations included in base type
595
- const baseType = this.addressSpace.findNode(nodeType.subtypeOf);
596
- const n = baseType.browseNodeByTargetName(relativePathElement, isLast);
597
- nodeIds = [].concat(nodeIds, n);
598
- }
599
- }
600
- return nodeIds;
601
- }
602
- /**
603
- * browse the node to extract information requested in browseDescription
604
- * @method browseNode
605
- * @param browseDescription
606
- * @param context
607
- * @return an array with reference descriptions
608
- */
609
- browseNode(browseDescription, context) {
610
- node_opcua_assert_1.assert(isFinite(browseDescription.nodeClassMask));
611
- node_opcua_assert_1.assert(isFinite(browseDescription.browseDirection));
612
- const do_debug = false;
613
- const _private = base_node_private_1.BaseNode_getPrivate(this);
614
- const addressSpace = this.addressSpace;
615
- const referenceTypeId = normalize_referenceTypeId(addressSpace, browseDescription.referenceTypeId);
616
- node_opcua_assert_1.assert(referenceTypeId instanceof node_opcua_nodeid_1.NodeId);
617
- const browseDirection = browseDescription.browseDirection !== undefined ? browseDescription.browseDirection : node_opcua_data_model_1.BrowseDirection.Both;
618
- // get all possible references
619
- let references = [].concat(Object.values(_private._referenceIdx), Object.values(_private._back_referenceIdx));
620
- /* istanbul ignore next */
621
- if (do_debug) {
622
- console.log("all references :", this.nodeId.toString(), this.browseName.toString());
623
- source_1.dumpReferences(addressSpace, Object.values(_private._referenceIdx));
624
- }
625
- // filter out references not matching referenceType
626
- references = _filter_by_referenceType.call(this, browseDescription, references, referenceTypeId);
627
- references = _filter_by_direction(references, browseDirection);
628
- references = _filter_by_nodeClass.call(this, references, browseDescription.nodeClassMask);
629
- references = _filter_by_userFilter.call(this, references, context);
630
- if (context) {
631
- references = _filter_by_context(this, references, context);
632
- }
633
- const referenceDescriptions = base_node_private_1._constructReferenceDescription(addressSpace, references, browseDescription.resultMask);
634
- /* istanbul ignore next */
635
- if (do_debug) {
636
- source_1.dumpReferenceDescriptions(this.addressSpace, referenceDescriptions);
637
- }
638
- return referenceDescriptions;
639
- }
640
- allReferences() {
641
- const _private = base_node_private_1.BaseNode_getPrivate(this);
642
- return [].concat(Object.values(_private._referenceIdx), Object.values(_private._back_referenceIdx));
643
- }
644
- /**
645
- * @method addReference
646
- * @param reference
647
- * @param reference.referenceType {String}
648
- * @param [reference.isForward = true] {Boolean}
649
- * @param reference.nodeId {Node|NodeId|String}
650
- *
651
- * @example
652
- *
653
- * view.addReference({ referenceType: "Organizes", nodeId: myDevice });
654
- *
655
- * or
656
- *
657
- * myDevice1.addReference({ referenceType: "OrganizedBy", nodeId: view });
658
- */
659
- addReference(reference) {
660
- const referenceNode = this.__addReference(reference);
661
- const addressSpace = this.addressSpace;
662
- if (!resolveReferenceType(addressSpace, referenceNode)) {
663
- throw new Error("BaseNode#addReference : invalid reference " + reference.toString());
664
- }
665
- this._clear_caches();
666
- _propagate_ref.call(this, addressSpace, referenceNode);
667
- this.install_extra_properties();
668
- cetools._handle_add_reference_change_event(this, referenceNode.nodeId);
669
- }
670
- removeReference(referenceOpts) {
671
- const _private = base_node_private_1.BaseNode_getPrivate(this);
672
- node_opcua_assert_1.assert(referenceOpts.hasOwnProperty("referenceType"));
673
- // xx isForward is optional : assert(reference.hasOwnProperty("isForward"));
674
- node_opcua_assert_1.assert(referenceOpts.hasOwnProperty("nodeId"));
675
- const addressSpace = this.addressSpace;
676
- if (!addressSpace) {
677
- console.log(" Where is addressSpace ?");
678
- }
679
- const reference = addressSpace.normalizeReferenceTypes([referenceOpts])[0];
680
- const h = reference.hash;
681
- const relatedNode = addressSpace.findNode(reference.nodeId);
682
- const invReference = new reference_1.Reference({
683
- isForward: !reference.isForward,
684
- nodeId: this.nodeId,
685
- referenceType: reference.referenceType
686
- });
687
- if (_private._referenceIdx[h]) {
688
- delete _private._referenceIdx[h];
689
- base_node_private_1.BaseNode_remove_backward_reference.call(relatedNode, invReference);
690
- }
691
- else if (_private._back_referenceIdx[h]) {
692
- relatedNode.removeReference(invReference);
693
- }
694
- else {
695
- // throw new Error("Cannot find reference " + reference);
696
- }
697
- base_node_private_1._handle_HierarchicalReference(this, reference);
698
- this.uninstall_extra_properties(reference);
699
- this._clear_caches();
700
- }
701
- /**
702
- *
703
- */
704
- resolveNodeId(nodeId) {
705
- return this.addressSpace.resolveNodeId(nodeId);
706
- }
707
- install_extra_properties() {
708
- const addressSpace = this.addressSpace;
709
- if (addressSpace.isFrugal) {
710
- // skipping
711
- return;
712
- }
713
- install_components_as_object_properties(this);
714
- function install_extra_properties_on_parent(ref) {
715
- const node = reference_1.Reference.resolveReferenceNode(addressSpace, ref);
716
- install_components_as_object_properties(node);
717
- }
718
- // make sure parent have extra properties updated
719
- const parentComponents = this.findReferences("HasComponent", false);
720
- const parentSubfolders = this.findReferences("Organizes", false);
721
- const parentProperties = this.findReferences("HasProperty", false);
722
- for (const p of parentComponents) {
723
- install_extra_properties_on_parent(p);
724
- }
725
- for (const p of parentSubfolders) {
726
- install_extra_properties_on_parent(p);
727
- }
728
- for (const p of parentProperties) {
729
- install_extra_properties_on_parent(p);
730
- }
731
- }
732
- uninstall_extra_properties(reference) {
733
- const addressSpace = this.addressSpace;
734
- if (addressSpace.isFrugal) {
735
- // skipping
736
- return;
737
- }
738
- const childNode = resolveReferenceNode(addressSpace, reference);
739
- const name = node_opcua_utils_1.lowerFirstLetter(childNode.browseName.name.toString());
740
- if (reservedNames.hasOwnProperty(name)) {
741
- if (doDebug) {
742
- // tslint:disable-next-line:no-console
743
- console.log(chalk.bgWhite.red("Ignoring reserved keyword " + name));
744
- }
745
- return;
746
- }
747
- /* istanbul ignore next */
748
- if (!this.hasOwnProperty(name)) {
749
- return;
750
- }
751
- Object.defineProperty(this, name, {
752
- value: undefined
753
- });
754
- }
755
- toString() {
756
- const options = new base_node_private_1.ToStringBuilder();
757
- base_node_private_1.BaseNode_toString.call(this, options);
758
- return options.toString();
759
- }
760
- /**
761
- * @property isFalseSubStateOf
762
- * @type {BaseNode|null}
763
- */
764
- get isFalseSubStateOf() {
765
- const node = this;
766
- const r = node.findReferencesAsObject("HasFalseSubState", false);
767
- if (!r || r.length === 0) {
768
- return null;
769
- }
770
- node_opcua_assert_1.assert(r.length === 1);
771
- return r[0];
772
- }
773
- /**
774
- * @property isTrueSubStateOf
775
- * @type {BaseNode|null}
776
- */
777
- get isTrueSubStateOf() {
778
- const node = this;
779
- const r = node.findReferencesAsObject("HasTrueSubState", false);
780
- if (!r || r.length === 0) {
781
- return null;
782
- }
783
- node_opcua_assert_1.assert(r.length === 1);
784
- return r[0];
785
- }
786
- /**
787
- * @method getFalseSubStates
788
- * @return {UAStateVariable[]} return an array with the SubStates of this object.
789
- */
790
- getFalseSubStates() {
791
- return this.findReferencesAsObject("HasFalseSubState");
792
- }
793
- /**
794
- * @method getTrueSubStates
795
- * @return {UAStateVariable[]} return an array with the SubStates of this object.
796
- */
797
- getTrueSubStates() {
798
- return this.findReferencesAsObject("HasTrueSubState");
799
- }
800
- findHierarchicalReferences() {
801
- const node = this;
802
- return node.findReferencesEx("HierarchicalReferences", node_opcua_data_model_1.BrowseDirection.Forward);
803
- }
804
- getChildByName(browseName, namespaceIndex) {
805
- // Attention: getChild doesn't care about namespace on browseName
806
- // !!!!
807
- if (browseName instanceof node_opcua_data_model_1.QualifiedName) {
808
- browseName = browseName.name.toString();
809
- }
810
- node_opcua_assert_1.assert(typeof browseName === "string");
811
- const node = this;
812
- const _cache = base_node_private_1.BaseNode_getCache(this);
813
- const addressSpace = node.addressSpace;
814
- if (!_cache._childByNameMap) {
815
- _cache._childByNameMap = {};
816
- const childReferenceTypes = node.findReferencesEx("HasChild");
817
- for (const r of childReferenceTypes) {
818
- const child = resolveReferenceNode(addressSpace, r);
819
- _cache._childByNameMap[child.browseName.name.toString()] = child;
820
- }
821
- }
822
- const ret = _cache._childByNameMap[browseName.toString()] || null;
823
- return ret;
824
- }
825
- get toStateNode() {
826
- const nodes = this.findReferencesAsObject("ToState", true);
827
- node_opcua_assert_1.assert(nodes.length <= 1);
828
- return nodes.length === 1 ? nodes[0] : null;
829
- }
830
- get fromStateNode() {
831
- const nodes = this.findReferencesAsObject("FromState", true);
832
- node_opcua_assert_1.assert(nodes.length <= 1);
833
- return nodes.length === 1 ? nodes[0] : null;
834
- }
835
- /**
836
- * this methods propagates the forward references to the pointed node
837
- * by inserting backward references to the counter part node
838
- */
839
- propagate_back_references() {
840
- const _private = base_node_private_1.BaseNode_getPrivate(this);
841
- if (this.addressSpace.suspendBackReference) {
842
- // this indicates that the base node is constructed from an xml definition
843
- // propagate_back_references will be called later once the file has been completely processed.
844
- return;
845
- }
846
- const addressSpace = this.addressSpace;
847
- for (const reference of Object.values(_private._referenceIdx)) {
848
- _propagate_ref.call(this, addressSpace, reference);
849
- }
850
- }
851
- /**
852
- * the dispose method should be called when the node is no longer used, to release
853
- * back pointer to the address space and clear caches.
854
- *
855
- * @method dispose
856
- *
857
- */
858
- dispose() {
859
- this.emit("dispose");
860
- this.removeAllListeners();
861
- this._clear_caches();
862
- const _private = base_node_private_1.BaseNode_getPrivate(this);
863
- Object.values(_private._back_referenceIdx).forEach((ref) => ref.dispose());
864
- Object.values(_private._referenceIdx).forEach((ref) => ref.dispose());
865
- base_node_private_1.BaseNode_removePrivate(this);
866
- }
867
- // istanbul ignore next
868
- dumpXML(xmlWriter) {
869
- console.error(" This ", node_opcua_data_model_1.NodeClass[this.nodeClass]);
870
- node_opcua_assert_1.assert(false, "BaseNode#dumpXML NOT IMPLEMENTED !");
871
- node_opcua_assert_1.assert(xmlWriter);
872
- }
873
- /**
874
- * Undo the effect of propagate_back_references
875
- */
876
- unpropagate_back_references() {
877
- const _private = base_node_private_1.BaseNode_getPrivate(this);
878
- const addressSpace = this.addressSpace;
879
- for (const reference of Object.values(_private._referenceIdx)) {
880
- // filter out non Hierarchical References
881
- const referenceType = resolveReferenceType(addressSpace, reference);
882
- // istanbul ignore next
883
- if (!referenceType) {
884
- console.error(chalk.red(" ERROR"), " cannot find reference ", reference.referenceType, reference.toString());
885
- }
886
- const related_node = resolveReferenceNode(addressSpace, reference);
887
- if (related_node) {
888
- node_opcua_assert_1.assert(reference.nodeId.toString() !== this.nodeId.toString());
889
- base_node_private_1.BaseNode_remove_backward_reference.call(related_node, new reference_1.Reference({
890
- isForward: !reference.isForward,
891
- nodeId: this.nodeId,
892
- referenceType: reference.referenceType
893
- }));
894
- } // else addressSpace may be incomplete
895
- }
896
- }
897
- installPostInstallFunc(f) {
898
- if (!f) {
899
- // nothing to do
900
- return;
901
- }
902
- function chain(f1, f2) {
903
- return function chaiFunc() {
904
- const args = arguments;
905
- if (f1) {
906
- f1.apply(this, args);
907
- }
908
- if (f2) {
909
- f2.apply(this, args);
910
- }
911
- };
912
- }
913
- this._postInstantiateFunc = chain.call(this, this._postInstantiateFunc, f);
914
- }
915
- _on_child_added() {
916
- this._clear_caches();
917
- }
918
- _on_child_removed(obj) {
919
- // obj; // unused;
920
- this._clear_caches();
921
- }
922
- _add_backward_reference(reference) {
923
- base_node_private_1.BaseNode_add_backward_reference.call(this, reference);
924
- }
925
- _coerceReferenceType(referenceType) {
926
- let result;
927
- if (typeof referenceType === "string") {
928
- result = this.addressSpace.findReferenceType(referenceType);
929
- /* istanbul ignore next */
930
- if (!result) {
931
- throw new Error("Cannot coerce reference with name " + referenceType);
932
- }
933
- }
934
- else if (referenceType instanceof node_opcua_nodeid_1.NodeId) {
935
- result = this.addressSpace.findNode(referenceType);
936
- }
937
- else {
938
- result = referenceType;
939
- }
940
- node_opcua_assert_1.assert(result.nodeClass === node_opcua_data_model_1.NodeClass.ReferenceType);
941
- return result;
942
- }
943
- __addReference(referenceOpts) {
944
- const _private = base_node_private_1.BaseNode_getPrivate(this);
945
- node_opcua_assert_1.assert(referenceOpts.hasOwnProperty("referenceType"));
946
- // xx isForward is optional : assert(reference.hasOwnProperty("isForward"));
947
- node_opcua_assert_1.assert(referenceOpts.hasOwnProperty("nodeId"));
948
- const addressSpace = this.addressSpace;
949
- const reference = addressSpace.normalizeReferenceTypes([referenceOpts])[0];
950
- node_opcua_assert_1.assert(reference instanceof reference_1.Reference);
951
- const h = reference.hash;
952
- node_opcua_assert_1.assert(!_private._back_referenceIdx[h], "reference exists already in _back_references");
953
- node_opcua_assert_1.assert(!_private._referenceIdx[h], "reference exists already in _references");
954
- _private._referenceIdx[h] = reference;
955
- base_node_private_1._handle_HierarchicalReference(this, reference);
956
- return reference;
957
- }
958
- _setDisplayName(displayName) {
959
- const displayNames = Array.isArray(displayName) ? displayName : [displayName];
960
- const _displayNames = displayNames.map(node_opcua_data_model_1.coerceLocalizedText);
961
- const _private = base_node_private_1.BaseNode_getPrivate(this);
962
- _private._displayName = _displayNames;
963
- }
964
- _setDescription(description) {
965
- const __description = node_opcua_data_model_1.coerceLocalizedText(description);
966
- const _private = base_node_private_1.BaseNode_getPrivate(this);
967
- _private._description = __description;
968
- }
969
- _notifyAttributeChange(attributeId) {
970
- const event_name = BaseNode.makeAttributeEventName(attributeId);
971
- this.emit(event_name, this.readAttribute(source_1.SessionContext.defaultContext, attributeId));
972
- }
973
- _clear_caches() {
974
- base_node_private_1.BaseNode_clearCache(this);
975
- }
976
- _readAccessRestrictions(context) {
977
- // https://reference.opcfoundation.org/v104/Core/docs/Part3/8.56/
978
- if (this.accessRestrictions === undefined) {
979
- return new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadAttributeIdInvalid });
980
- }
981
- return new node_opcua_data_value_1.DataValue({
982
- statusCode: node_opcua_status_code_1.StatusCodes.Good,
983
- value: {
984
- dataType: node_opcua_variant_1.DataType.UInt16,
985
- value: this.accessRestrictions
986
- }
987
- });
988
- }
989
- _readRolePermissions(context) {
990
- // https://reference.opcfoundation.org/v104/Core/docs/Part3/4.8.3/
991
- // to do check that current user can read permission
992
- if (context && !(context === null || context === void 0 ? void 0 : context.checkPermission(this, node_opcua_types_1.PermissionType.ReadRolePermissions))) {
993
- return new node_opcua_data_value_1.DataValue({
994
- statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied
995
- });
996
- }
997
- if (this.rolePermissions === undefined) {
998
- // to do : If not specified, the value of DefaultUserRolePermissions Property from
999
- // the Namespace Metadata Object associated with the Node is used instead.
1000
- return new node_opcua_data_value_1.DataValue({
1001
- statusCode: node_opcua_status_code_1.StatusCodes.BadAttributeIdInvalid
1002
- });
1003
- }
1004
- const rolePermissions = this.rolePermissions
1005
- .map(({ roleId, permissions }) => {
1006
- return new node_opcua_types_1.RolePermissionType({
1007
- roleId: toRoleNodeId(roleId),
1008
- permissions
1009
- });
1010
- });
1011
- return new node_opcua_data_value_1.DataValue({
1012
- statusCode: node_opcua_status_code_1.StatusCodes.Good,
1013
- value: {
1014
- dataType: node_opcua_variant_1.DataType.ExtensionObject,
1015
- arrayType: node_opcua_variant_1.VariantArrayType.Array,
1016
- value: rolePermissions
1017
- }
1018
- });
1019
- }
1020
- _readUserRolePermissions(context) {
1021
- // for the time being ...
1022
- return this._readRolePermissions(context);
1023
- }
1024
- /**
1025
- *
1026
- * @param rolePermissions
1027
- */
1028
- setRolePermissions(rolePermissions) {
1029
- this.rolePermissions = coerceRolePermissions(rolePermissions);
1030
- }
1031
- setAccessRestrictions(accessRestrictions) {
1032
- this.accessRestrictions = accessRestrictions;
1033
- }
1034
- }
1035
- exports.BaseNode = BaseNode;
1036
- function toRoleNodeId(s) {
1037
- if (typeof s === "string") {
1038
- return node_opcua_nodeid_1.resolveNodeId(source_1.WellKnownRolesNodeId[s]);
1039
- }
1040
- return node_opcua_nodeid_1.coerceNodeId(s);
1041
- }
1042
- let displayWarning = true;
1043
- function toString_ReferenceDescription(ref, options) {
1044
- const addressSpace = options.addressSpace;
1045
- // xx assert(ref instanceof ReferenceDescription);
1046
- const refNode = addressSpace.findNode(ref.referenceType);
1047
- if (!refNode) {
1048
- return "Unknown Ref : " + ref;
1049
- }
1050
- const r = new reference_1.Reference({
1051
- isForward: ref.isForward,
1052
- nodeId: ref.nodeId,
1053
- referenceType: refNode.browseName.toString()
1054
- });
1055
- const str = r.toString(options);
1056
- r.dispose();
1057
- return str;
1058
- }
1059
- /* jshint latedef: false */
1060
- function _setup_parent_item(references) {
1061
- references = Object.values(references);
1062
- const _private = base_node_private_1.BaseNode_getPrivate(this);
1063
- node_opcua_assert_1.assert(!_private._parent, "_setup_parent_item has been already called");
1064
- const addressSpace = this.addressSpace;
1065
- if (references.length > 0) {
1066
- references = this.findReferencesEx("HasChild", node_opcua_data_model_1.BrowseDirection.Inverse);
1067
- if (references.length >= 1) {
1068
- // istanbul ignore next
1069
- if (references.length > 1) {
1070
- if (displayWarning) {
1071
- const options = { addressSpace };
1072
- // tslint:disable-next-line:no-console
1073
- console.warn(" More than one HasChild reference have been found for parent of object");
1074
- // tslint:disable-next-line:no-console
1075
- console.warn(" object node id:", this.nodeId.toString(), chalk.cyan(this.browseName.toString()));
1076
- // tslint:disable-next-line:no-console
1077
- console.warn(" browseResults:");
1078
- // tslint:disable-next-line:no-console
1079
- console.warn(references.map((f) => toString_ReferenceDescription(f, options)).join("\n"));
1080
- // tslint:disable-next-line:no-console
1081
- console.warn(" first one will be used as parent");
1082
- // xx assert(browseResults.length === 1);
1083
- displayWarning = false;
1084
- }
1085
- }
1086
- return reference_1.Reference.resolveReferenceNode(addressSpace, references[0]);
1087
- }
1088
- }
1089
- return null;
1090
- }
1091
- function _asObject(references, addressSpace) {
1092
- function toObject(reference) {
1093
- const obj = resolveReferenceNode(addressSpace, reference);
1094
- // istanbul ignore next
1095
- if (false && !obj) {
1096
- // tslint:disable-next-line:no-console
1097
- console.log(chalk.red(" Warning : object with nodeId ") +
1098
- chalk.cyan(reference.nodeId.toString()) +
1099
- chalk.red(" cannot be found in the address space !"));
1100
- }
1101
- return obj;
1102
- }
1103
- function remove_null(o) {
1104
- return !!o;
1105
- }
1106
- return references.map(toObject).filter(remove_null);
1107
- }
1108
- function _filter_by_browse_name(components, browseName, namespaceIndex) {
1109
- let select = [];
1110
- if ((namespaceIndex === null || namespaceIndex === undefined) && (typeof browseName === "string")) {
1111
- select = components.filter((c) => c.browseName.name.toString() === browseName);
1112
- if (select && select.length > 1) {
1113
- warningLog("Multiple children exist with name ", browseName, " please specify a namespace index");
1114
- }
1115
- }
1116
- else {
1117
- const _browseName = node_opcua_data_model_1.coerceQualifiedName(typeof browseName === "string" ? { name: browseName, namespaceIndex } : browseName);
1118
- select = components.filter((c) => c.browseName.name === _browseName.name && c.browseName.namespaceIndex === _browseName.namespaceIndex);
1119
- }
1120
- return select;
1121
- }
1122
- let displayWarningReferencePointingToItSelf = true;
1123
- function _is_massively_used_reference(referenceType) {
1124
- const name = referenceType.browseName.toString();
1125
- return name === "HasTypeDefinition" || name === "HasModellingRule";
1126
- }
1127
- function _propagate_ref(addressSpace, reference) {
1128
- // filter out non Hierarchical References
1129
- const referenceType = reference_1.Reference.resolveReferenceType(addressSpace, reference);
1130
- // istanbul ignore next
1131
- if (!referenceType) {
1132
- // tslint:disable-next-line:no-console
1133
- console.error(chalk.red(" ERROR"), " cannot find reference ", reference.referenceType, reference.toString());
1134
- }
1135
- // ------------------------------- Filter out back reference when reference type
1136
- // is HasTypeDefinition, HasModellingRule, etc ...
1137
- //
1138
- // var referenceNode = Reference.resolveReferenceNode(addressSpace,reference);
1139
- // ignore propagation on back reference to UAVariableType or UAObject Type reference
1140
- // because there are too many !
1141
- if (!referenceType || _is_massively_used_reference(referenceType)) {
1142
- return;
1143
- }
1144
- // ------------------------------- EXPERIMENT
1145
- // xx if (!referenceType.isSupertypeOf(hierarchicalReferencesId)) { return; }
1146
- const related_node = resolveReferenceNode(addressSpace, reference);
1147
- if (related_node) {
1148
- // verify that reference doesn't point to object itthis (see mantis 3099)
1149
- if (node_opcua_nodeid_1.sameNodeId(reference.nodeId, this.nodeId)) {
1150
- // istanbul ignore next
1151
- if (displayWarningReferencePointingToItSelf) {
1152
- // this could happen with method
1153
- console.warn(" Warning: a Reference is pointing to itthis ", this.nodeId.toString(), this.browseName.toString());
1154
- displayWarningReferencePointingToItSelf = false;
1155
- }
1156
- }
1157
- // xx ignore this assert(reference.nodeId.toString() !== this.nodeId.toString());
1158
- // function w(s,l) { return (s+" ").substr(0,l);}
1159
- // if (reference.isForward) {
1160
- // console.log(" CHILD => ",w(related_node.browseName + " " + related_node.nodeId.toString(),30),
1161
- // " PARENT ",w(this.browseName + " " + this.nodeId.toString(),30) , reference.toString());
1162
- // } else {
1163
- // console.log(" CHILD => ",w(this.browseName + " " + this.nodeId.toString(),30),
1164
- // " PARENT ",w(related_node.browseName + " " + related_node.nodeId.toString(),30) , reference.toString());
1165
- //
1166
- // }
1167
- related_node._add_backward_reference(new reference_1.Reference({
1168
- _referenceType: reference._referenceType,
1169
- isForward: !reference.isForward,
1170
- node: this,
1171
- nodeId: this.nodeId,
1172
- referenceType: reference.referenceType
1173
- }));
1174
- } // else addressSpace may be incomplete and under construction (while loading a nodeset.xml file for instance)
1175
- }
1176
- function nodeid_is_nothing(nodeid) {
1177
- return nodeid.value === 0 && nodeid.namespace === 0;
1178
- }
1179
- /**
1180
- * @method normalize_referenceTypeId
1181
- * @param addressSpace {AddressSpace}
1182
- * @param referenceTypeId {String|NodeId|null} : the referenceType either as a string or a nodeId
1183
- * @return {NodeId}
1184
- */
1185
- function normalize_referenceTypeId(addressSpace, referenceTypeId) {
1186
- if (!referenceTypeId) {
1187
- return node_opcua_nodeid_1.makeNodeId(0);
1188
- }
1189
- if (typeof referenceTypeId === "string") {
1190
- const ref = addressSpace.findReferenceType(referenceTypeId);
1191
- if (ref) {
1192
- return ref.nodeId;
1193
- }
1194
- }
1195
- let nodeId;
1196
- try {
1197
- nodeId = addressSpace.resolveNodeId(referenceTypeId);
1198
- }
1199
- catch (err) {
1200
- console.log("cannot normalize_referenceTypeId", referenceTypeId);
1201
- throw err;
1202
- }
1203
- node_opcua_assert_1.assert(nodeId);
1204
- return nodeId;
1205
- }
1206
- const resolveReferenceNode = reference_1.Reference.resolveReferenceNode;
1207
- const resolveReferenceType = reference_1.Reference.resolveReferenceType;
1208
- function _filter_by_referenceType(browseDescription, references, referenceTypeId) {
1209
- // make sure we have a valid referenceTypeId if not null
1210
- if (!nodeid_is_nothing(referenceTypeId)) {
1211
- node_opcua_assert_1.assert(referenceTypeId instanceof node_opcua_nodeid_1.NodeId);
1212
- const referenceType = this.addressSpace.findNode(referenceTypeId);
1213
- node_opcua_debug_1.dumpIf(!referenceType, referenceTypeId);
1214
- if (!referenceType || referenceType.nodeClass !== node_opcua_data_model_1.NodeClass.ReferenceType) {
1215
- throw new Error("Cannot find reference type");
1216
- }
1217
- references = references.filter((reference) => {
1218
- const ref = resolveReferenceType(this.addressSpace, reference);
1219
- if (!ref) {
1220
- return false;
1221
- } // unknown type ... this may happen when the address space is not fully build
1222
- node_opcua_assert_1.assert(ref.nodeClass === node_opcua_data_model_1.NodeClass.ReferenceType);
1223
- const is_of_type = ref.nodeId.toString() === referenceType.nodeId.toString();
1224
- if (is_of_type) {
1225
- return true;
1226
- }
1227
- if (browseDescription.includeSubtypes) {
1228
- return ref.isSupertypeOf(referenceType);
1229
- }
1230
- else {
1231
- return false;
1232
- }
1233
- });
1234
- }
1235
- return references;
1236
- }
1237
- function forwardOnly(reference) {
1238
- return reference.isForward;
1239
- }
1240
- function reverseOnly(reference) {
1241
- return !reference.isForward;
1242
- }
1243
- function _filter_by_direction(references, browseDirection) {
1244
- if (browseDirection === node_opcua_data_model_1.BrowseDirection.Both) {
1245
- return references;
1246
- }
1247
- if (browseDirection === node_opcua_data_model_1.BrowseDirection.Forward) {
1248
- return references.filter(forwardOnly);
1249
- }
1250
- else {
1251
- return references.filter(reverseOnly);
1252
- }
1253
- }
1254
- function _filter_by_context(node, references, context) {
1255
- if (!context.isBrowseAccessRestricted(node)) {
1256
- return references;
1257
- }
1258
- // browse access is restricted for forward
1259
- return [];
1260
- }
1261
- function _filter_by_nodeClass(references, nodeClassMask) {
1262
- node_opcua_assert_1.assert(isFinite(nodeClassMask));
1263
- if (nodeClassMask === 0) {
1264
- return references;
1265
- }
1266
- const addressSpace = this.addressSpace;
1267
- return references.filter((reference) => {
1268
- const obj = resolveReferenceNode(addressSpace, reference);
1269
- if (!obj) {
1270
- return false;
1271
- }
1272
- const nodeClassName = node_opcua_data_model_1.NodeClass[obj.nodeClass];
1273
- const value = node_opcua_data_model_1.makeNodeClassMask(nodeClassName);
1274
- return (value & nodeClassMask) === value;
1275
- });
1276
- }
1277
- function _filter_by_userFilter(references, context) {
1278
- const addressSpace = this.addressSpace;
1279
- return references.filter((reference) => {
1280
- const obj = resolveReferenceNode(addressSpace, reference);
1281
- // istanbul ignore next
1282
- if (!obj) {
1283
- return false;
1284
- }
1285
- const _private = base_node_private_1.BaseNode_getPrivate(obj);
1286
- // istanbul ignore next
1287
- if (!_private._browseFilter) {
1288
- throw Error("Internal error : cannot find browseFilter");
1289
- }
1290
- const filter1 = _private._browseFilter.call(obj, context);
1291
- return filter1;
1292
- });
1293
- }
1294
- const reservedNames = {
1295
- __description: 0,
1296
- __displayName: 0,
1297
- browseName: 0,
1298
- description: 0,
1299
- displayName: 0,
1300
- nodeClass: 0,
1301
- nodeId: 0,
1302
- typeDefinition: 0
1303
- };
1304
- /*
1305
- * install hierarchical references as javascript properties
1306
- * Components/Properties/Organizes
1307
- */
1308
- function install_components_as_object_properties(parentObj) {
1309
- if (!parentObj) {
1310
- return;
1311
- }
1312
- const addressSpace = parentObj.addressSpace;
1313
- const hierarchicalRefs = parentObj.findHierarchicalReferences();
1314
- const children = hierarchicalRefs.map((r) => reference_1.Reference.resolveReferenceNode(addressSpace, r));
1315
- for (const child of children) {
1316
- if (!child) {
1317
- continue;
1318
- }
1319
- // assumption: we ignore namespace here .
1320
- const name = node_opcua_utils_1.lowerFirstLetter(child.browseName.name.toString());
1321
- if (reservedNames.hasOwnProperty(name)) {
1322
- if (doDebug) {
1323
- console.log(chalk.bgWhite.red("Ignoring reserved keyword " + name));
1324
- }
1325
- continue;
1326
- }
1327
- if (doDebug) {
1328
- console.log("Installing property " + name, " on ", parentObj.browseName.toString());
1329
- }
1330
- /* istanbul ignore next */
1331
- if (parentObj.hasOwnProperty(name)) {
1332
- continue;
1333
- }
1334
- Object.defineProperty(parentObj, name, {
1335
- configurable: true,
1336
- enumerable: true,
1337
- // xx writable: false,
1338
- get() {
1339
- return child;
1340
- }
1341
- // value: child
1342
- });
1343
- }
1344
- }
1345
- //# sourceMappingURL=base_node.js.map