node-opcua-address-space 2.152.0 → 2.154.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 (60) hide show
  1. package/dist/source/helpers/dump_tools.d.ts +1 -1
  2. package/dist/source/helpers/dump_tools.js.map +1 -1
  3. package/dist/source/interfaces/alarms_and_conditions/ua_condition_ex.d.ts +2 -2
  4. package/dist/source/loader/load_nodeset2.js +1 -7
  5. package/dist/source/loader/load_nodeset2.js.map +1 -1
  6. package/dist/source/ua_addin.d.ts +4 -1
  7. package/dist/source/ua_addin.js +3 -2
  8. package/dist/source/ua_addin.js.map +1 -1
  9. package/dist/src/address_space.d.ts +1 -1
  10. package/dist/src/address_space.js +10 -4
  11. package/dist/src/address_space.js.map +1 -1
  12. package/dist/src/address_space_change_event_tools.js +13 -11
  13. package/dist/src/address_space_change_event_tools.js.map +1 -1
  14. package/dist/src/address_space_private.d.ts +1 -1
  15. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.js +2 -2
  16. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.js.map +1 -1
  17. package/dist/src/alarms_and_conditions/ua_condition_impl.d.ts +2 -2
  18. package/dist/src/base_node_impl.d.ts +13 -6
  19. package/dist/src/base_node_impl.js +129 -102
  20. package/dist/src/base_node_impl.js.map +1 -1
  21. package/dist/src/base_node_private.d.ts +16 -10
  22. package/dist/src/base_node_private.js +80 -27
  23. package/dist/src/base_node_private.js.map +1 -1
  24. package/dist/src/data_access/ua_multistate_value_discrete_impl.js +3 -1
  25. package/dist/src/data_access/ua_multistate_value_discrete_impl.js.map +1 -1
  26. package/dist/src/namespace_impl.d.ts +1 -2
  27. package/dist/src/namespace_impl.js +12 -7
  28. package/dist/src/namespace_impl.js.map +1 -1
  29. package/dist/src/namespace_private.d.ts +1 -1
  30. package/dist/src/namespace_private.js.map +1 -1
  31. package/dist/src/nodeid_manager.d.ts +4 -4
  32. package/dist/src/nodeid_manager.js +3 -1
  33. package/dist/src/nodeid_manager.js.map +1 -1
  34. package/dist/src/reference_impl.js.map +1 -1
  35. package/dist/src/state_machine/finite_state_machine.d.ts +1 -4
  36. package/dist/src/state_machine/finite_state_machine.js.map +1 -1
  37. package/dist/src/ua_reference_type_impl.d.ts +1 -1
  38. package/dist/tsconfig_common.tsbuildinfo +1 -1
  39. package/distHelpers/boiler_system.js +11 -0
  40. package/distHelpers/boiler_system.js.map +1 -1
  41. package/distHelpers/create_minimalist_address_space_nodeset.js +2 -0
  42. package/distHelpers/create_minimalist_address_space_nodeset.js.map +1 -1
  43. package/package.json +36 -35
  44. package/source/helpers/dump_tools.ts +4 -1
  45. package/source/interfaces/alarms_and_conditions/ua_condition_ex.ts +2 -2
  46. package/source/loader/load_nodeset2.ts +4 -9
  47. package/source/ua_addin.ts +8 -3
  48. package/src/address_space.ts +13 -6
  49. package/src/address_space_change_event_tools.ts +16 -12
  50. package/src/address_space_private.ts +1 -1
  51. package/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.ts +4 -3
  52. package/src/alarms_and_conditions/ua_condition_impl.ts +2 -2
  53. package/src/base_node_impl.ts +167 -123
  54. package/src/base_node_private.ts +134 -76
  55. package/src/data_access/ua_multistate_value_discrete_impl.ts +3 -1
  56. package/src/namespace_impl.ts +26 -22
  57. package/src/namespace_private.ts +4 -1
  58. package/src/nodeid_manager.ts +14 -10
  59. package/src/reference_impl.ts +1 -3
  60. package/src/state_machine/finite_state_machine.ts +1 -2
@@ -2,7 +2,7 @@
2
2
  * @module node-opcua-address-space
3
3
  */
4
4
  import { EventEmitter } from "events";
5
- import { AddReferenceOpts, ModellingRuleType, ISessionContext, UAMethod, UAObject, UAObjectType, UAReference, UAVariable, UAVariableType, BaseNode, UAReferenceType, IAddressSpace, INamespace, BrowseDescriptionOptions2 } from "node-opcua-address-space-base";
5
+ import { AddReferenceOpts, ModellingRuleType, ISessionContext, UAMethod, UAObject, UAObjectType, UAReference, UAVariable, UAVariableType, BaseNode, UAReferenceType, IAddressSpace, INamespace, BrowseDescriptionOptions2, UAProperty } from "node-opcua-address-space-base";
6
6
  import { AttributeIds, BrowseDirection, LocalizedText, LocalizedTextLike, NodeClass, QualifiedName, QualifiedNameLike, QualifiedNameOptions, AccessRestrictionsFlag } from "node-opcua-data-model";
7
7
  import { DataValue } from "node-opcua-data-value";
8
8
  import { NodeId, NodeIdLike } from "node-opcua-nodeid";
@@ -10,9 +10,11 @@ import { NumericRange } from "node-opcua-numeric-range";
10
10
  import { ReferenceDescription } from "node-opcua-service-browse";
11
11
  import { StatusCode } from "node-opcua-status-code";
12
12
  import { RelativePathElement, RolePermissionType, RolePermissionTypeOptions, WriteValueOptions } from "node-opcua-types";
13
+ import { DataType } from "node-opcua-variant";
13
14
  import { UAStateVariable } from "node-opcua-nodeset-ua";
14
15
  import { XmlWriter } from "../source/xml_writer";
15
16
  import { AddressSpacePrivate } from "./address_space_private";
17
+ import { UAString } from "node-opcua-basic-types";
16
18
  export interface InternalBaseNodeOptions {
17
19
  /**
18
20
  * the parent address space
@@ -88,7 +90,7 @@ export declare class BaseNodeImpl extends EventEmitter implements BaseNode {
88
90
  readonly nodeClass: NodeClass;
89
91
  readonly nodeId: NodeId;
90
92
  readonly browseName: QualifiedName;
91
- protected _postInstantiateFunc?: any;
93
+ protected _postInstantiateFunc?: (instance: BaseNode, instanceType: BaseNode, options?: any) => void;
92
94
  /**
93
95
  * @internal
94
96
  * @param options
@@ -114,6 +116,8 @@ export declare class BaseNodeImpl extends EventEmitter implements BaseNode {
114
116
  * return a array with the properties of this object.
115
117
  */
116
118
  getProperties(): BaseNode[];
119
+ private static _hasChild;
120
+ getChildren(): BaseNode[];
117
121
  /**
118
122
  * return a array with the notifiers of this object.
119
123
  * only reference of exact type HasNotifier are returned.
@@ -228,19 +232,22 @@ export declare class BaseNodeImpl extends EventEmitter implements BaseNode {
228
232
  findHierarchicalReferences(): UAReference[];
229
233
  getChildByName(browseName: QualifiedNameOptions): BaseNode | null;
230
234
  getChildByName(browseName: string, namespaceIndex?: number): BaseNode | null;
235
+ getNodeVersion(): UAProperty<UAString, DataType.String> | null;
236
+ get nodeVersion(): UAProperty<UAString, DataType.String> | undefined;
237
+ set nodeVersion(n: any);
231
238
  get toStateNode(): BaseNode | null;
232
239
  get fromStateNode(): BaseNode | null;
233
240
  /**
234
241
  * this methods propagates the forward references to the pointed node
235
242
  * by inserting backward references to the counter part node
243
+ * @private
236
244
  */
237
245
  propagate_back_references(): void;
238
246
  /**
239
247
  * the dispose method should be called when the node is no longer used, to release
240
248
  * back pointer to the address space and clear caches.
241
249
  *
242
-
243
- *
250
+ * @private
244
251
  */
245
252
  dispose(): void;
246
253
  isDisposed(): boolean;
@@ -249,8 +256,8 @@ export declare class BaseNodeImpl extends EventEmitter implements BaseNode {
249
256
  * Undo the effect of propagate_back_references
250
257
  */
251
258
  unpropagate_back_references(): void;
252
- installPostInstallFunc(f: () => void): void;
253
- _on_child_added(): void;
259
+ installPostInstallFunc(f: (instance: BaseNode, tpyeNode: BaseNode, opts?: any) => void): void;
260
+ _on_child_added(childNode: BaseNode): void;
254
261
  _on_child_removed(obj: BaseNode): void;
255
262
  /**
256
263
  * @private
@@ -261,8 +261,7 @@ class BaseNodeImpl extends events_1.EventEmitter {
261
261
  const isForward = browseDirection === node_opcua_data_model_1.BrowseDirection.Forward;
262
262
  const results = [];
263
263
  const process = (referenceIdx) => {
264
- const references = Object.values(referenceIdx);
265
- for (const ref of references) {
264
+ for (const ref of referenceIdx.values()) {
266
265
  if (ref.isForward === isForward && referenceTypeNode && referenceTypeNode.checkHasSubtype(ref.referenceType)) {
267
266
  results.push(ref);
268
267
  }
@@ -276,14 +275,14 @@ class BaseNodeImpl extends events_1.EventEmitter {
276
275
  findReferences_no_cache(referenceTypeNode, isForward = true) {
277
276
  const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
278
277
  const result = [];
279
- for (const ref of Object.values(_private._referenceIdx)) {
278
+ for (const ref of _private._referenceIdx.values()) {
280
279
  if (ref.isForward === isForward) {
281
280
  if ((0, node_opcua_nodeid_1.sameNodeId)(ref.referenceType, referenceTypeNode.nodeId)) {
282
281
  result.push(ref);
283
282
  }
284
283
  }
285
284
  }
286
- for (const ref of Object.values(_private._back_referenceIdx)) {
285
+ for (const ref of _private._back_referenceIdx.values()) {
287
286
  if (ref.isForward === isForward) {
288
287
  if ((0, node_opcua_nodeid_1.sameNodeId)(ref.referenceType, referenceTypeNode.nodeId)) {
289
288
  result.push(ref);
@@ -301,7 +300,7 @@ class BaseNodeImpl extends events_1.EventEmitter {
301
300
  return [];
302
301
  }
303
302
  _cache._ref = _cache._ref || new Map();
304
- const hash = "_ref_" + referenceTypeNode.nodeId.toString() + isForward.toString();
303
+ const hash = `r|${referenceTypeNode.nodeId.toString()}|${isForward ? "f" : "b"}`;
305
304
  if (_cache._ref.has(hash)) {
306
305
  return _cache._ref.get(hash);
307
306
  }
@@ -332,45 +331,34 @@ class BaseNodeImpl extends events_1.EventEmitter {
332
331
  * return an array with the Aggregates of this object.
333
332
  */
334
333
  getAggregates() {
335
- // const _cache = BaseNode_getCache(this);
336
- // if (!_cache._aggregates) {
337
- // _cache._aggregates = this.findReferencesExAsObject("Aggregates", BrowseDirection.Forward);
338
- // }
339
- // return _cache._aggregates;
340
334
  return this.findReferencesExAsObject("Aggregates", node_opcua_data_model_1.BrowseDirection.Forward);
341
335
  }
342
336
  /**
343
337
  * return an array with the components of this object.
344
338
  */
345
339
  getComponents() {
346
- // const _cache = BaseNode_getCache(this);
347
- // if (!_cache._components) {
348
- // _cache._components = this.findReferencesExAsObject("HasComponent", BrowseDirection.Forward);
349
- // }
350
- // return _cache._components;
351
340
  return this.findReferencesExAsObject("HasComponent", node_opcua_data_model_1.BrowseDirection.Forward);
352
341
  }
353
342
  /**
354
343
  * return a array with the properties of this object.
355
344
  */
356
345
  getProperties() {
357
- // const _cache = BaseNode_getCache(this);
358
- // if (!_cache._properties) {
359
- // _cache._properties = this.findReferencesExAsObject("HasProperty", BrowseDirection.Forward);
360
- // }
361
- // return _cache._properties;
362
346
  return this.findReferencesExAsObject("HasProperty", node_opcua_data_model_1.BrowseDirection.Forward);
363
347
  }
348
+ getChildren() {
349
+ // return this.findReferencesExAsObject(BaseNodeImpl._hasChild, BrowseDirection.Forward);
350
+ const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
351
+ if (!_cache._children) {
352
+ _cache._children = this.findReferencesExAsObject(BaseNodeImpl._hasChild, node_opcua_data_model_1.BrowseDirection.Forward);
353
+ }
354
+ ;
355
+ return _cache._children;
356
+ }
364
357
  /**
365
358
  * return a array with the notifiers of this object.
366
359
  * only reference of exact type HasNotifier are returned.
367
360
  */
368
361
  getNotifiers() {
369
- // const _cache = BaseNode_getCache(this);
370
- // if (!_cache._notifiers) {
371
- // _cache._notifiers = this.findReferencesAsObject("HasNotifier", true);
372
- // }
373
- // return _cache._notifiers;
374
362
  return this.findReferencesAsObject(HasNotifierReferenceType, true);
375
363
  }
376
364
  /**
@@ -378,22 +366,12 @@ class BaseNodeImpl extends events_1.EventEmitter {
378
366
  * only reference of exact type HasEventSource are returned.
379
367
  */
380
368
  getEventSources() {
381
- // const _cache = BaseNode_getCache(this);
382
- // if (!_cache._eventSources) {
383
- // _cache._eventSources = this.findReferencesAsObject("HasEventSource", true);
384
- // }
385
- // return _cache._eventSources;
386
369
  return this.findReferencesAsObject(HasEventSourceReferenceType, true);
387
370
  }
388
371
  /**
389
372
  * return a array of the objects for which this node is an EventSource
390
373
  */
391
374
  getEventSourceOfs() {
392
- // const _cache = BaseNode_getCache(this);
393
- // if (!_cache._eventSources) {
394
- // _cache._eventSources = this.findReferencesAsObject("HasEventSource", false);
395
- // }
396
- // return _cache._eventSources;
397
375
  return this.findReferencesAsObject(HasEventSourceReferenceType, false);
398
376
  }
399
377
  getComponentByName(browseName, namespaceIndex) {
@@ -441,12 +419,6 @@ class BaseNodeImpl extends events_1.EventEmitter {
441
419
  * Note: internally, methods are special types of components
442
420
  */
443
421
  getMethods() {
444
- // const _cache = BaseNode_getCache(this);
445
- // if (!_cache._methods) {
446
- // const components = this.getComponents();
447
- // _cache._methods = components.filter((obj) => obj.nodeClass === NodeClass.Method) as UAMethod[];
448
- // }
449
- // return _cache._methods;
450
422
  const components = this.getComponents();
451
423
  return components.filter((obj) => obj.nodeClass === node_opcua_data_model_1.NodeClass.Method);
452
424
  }
@@ -545,7 +517,7 @@ class BaseNodeImpl extends events_1.EventEmitter {
545
517
  }
546
518
  ownReferences() {
547
519
  const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
548
- return Object.values(_private._referenceIdx);
520
+ return [..._private._referenceIdx.values()];
549
521
  }
550
522
  /**
551
523
  *
@@ -649,7 +621,7 @@ class BaseNodeImpl extends events_1.EventEmitter {
649
621
  /* istanbul ignore next */
650
622
  if (do_debug) {
651
623
  debugLog("all references :", this.nodeId.toString(), this.browseName.toString());
652
- (0, dump_tools_1.dumpReferences)(addressSpace, Object.values(_private._referenceIdx));
624
+ (0, dump_tools_1.dumpReferences)(addressSpace, _private._referenceIdx.values());
653
625
  }
654
626
  // filter out references not matching referenceType
655
627
  references = _filter_by_referenceType.call(this, browseDescription, references, referenceTypeId);
@@ -668,7 +640,7 @@ class BaseNodeImpl extends events_1.EventEmitter {
668
640
  }
669
641
  allReferences() {
670
642
  const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
671
- return Object.values(_private._referenceIdx).concat(Object.values(_private._back_referenceIdx));
643
+ return [..._private._referenceIdx.values(), ..._private._back_referenceIdx.values()];
672
644
  }
673
645
  /**
674
646
  * @param reference
@@ -690,7 +662,6 @@ class BaseNodeImpl extends events_1.EventEmitter {
690
662
  if (!resolveReferenceType(addressSpace, referenceNode)) {
691
663
  throw new Error("BaseNode#addReference : invalid reference " + reference.toString());
692
664
  }
693
- this._clear_caches();
694
665
  _propagate_ref.call(this, addressSpace, referenceNode);
695
666
  this.install_extra_properties();
696
667
  (0, address_space_change_event_tools_1._handle_add_reference_change_event)(this, referenceNode.nodeId);
@@ -704,24 +675,24 @@ class BaseNodeImpl extends events_1.EventEmitter {
704
675
  const reference = addressSpace.normalizeReferenceTypes([referenceOpts])[0];
705
676
  const h = reference.hash;
706
677
  const relatedNode = addressSpace.findNode(reference.nodeId);
707
- const invReference = new reference_impl_1.ReferenceImpl({
678
+ const backwardReference = new reference_impl_1.ReferenceImpl({
708
679
  isForward: !reference.isForward,
709
680
  nodeId: this.nodeId,
710
681
  referenceType: reference.referenceType
711
682
  });
712
- if (_private._referenceIdx[h]) {
713
- delete _private._referenceIdx[h];
714
- base_node_private_1.BaseNode_remove_backward_reference.call(relatedNode, invReference);
683
+ if (_private._referenceIdx.has(h)) {
684
+ _private._referenceIdx.delete(h);
685
+ base_node_private_1.BaseNode_remove_backward_reference.call(relatedNode, backwardReference);
686
+ (0, base_node_private_1._remove_HierarchicalReference)(this, reference);
687
+ this.uninstall_extra_properties(reference);
688
+ this._clear_caches();
715
689
  }
716
- else if (_private._back_referenceIdx[h]) {
717
- relatedNode.removeReference(invReference);
690
+ else if (_private._back_referenceIdx.has(h)) {
691
+ return relatedNode.removeReference(backwardReference);
718
692
  }
719
693
  else {
720
- // throw new Error("Cannot find reference " + reference);
694
+ warningLog("Cannot find reference to remove: " + reference.toString());
721
695
  }
722
- (0, base_node_private_1._handle_HierarchicalReference)(this, reference);
723
- this.uninstall_extra_properties(reference);
724
- this._clear_caches();
725
696
  }
726
697
  /**
727
698
  *
@@ -832,25 +803,41 @@ class BaseNodeImpl extends events_1.EventEmitter {
832
803
  findHierarchicalReferences() {
833
804
  return this.findReferencesEx("HierarchicalReferences", node_opcua_data_model_1.BrowseDirection.Forward);
834
805
  }
806
+ //
835
807
  getChildByName(browseName, namespaceIndex) {
836
- // Attention: getChild doesn't care about namespace on browseName
837
- // !!!!
838
- if (browseName instanceof node_opcua_data_model_1.QualifiedName) {
839
- browseName = browseName.name.toString();
808
+ var childrenMap = (0, base_node_private_1._get_HierarchicalReference)(this);
809
+ const select = _select_by_browse_name(childrenMap, browseName, namespaceIndex);
810
+ if (select.length == 0) {
811
+ return null;
840
812
  }
841
- (0, node_opcua_assert_1.assert)(typeof browseName === "string");
842
- const _cache = (0, base_node_private_1.BaseNode_getCache)(this);
843
- const addressSpace = this.addressSpace;
844
- if (!_cache._childByNameMap) {
845
- _cache._childByNameMap = new Map();
846
- const childReferenceTypes = this.findReferencesEx("HasChild");
847
- for (const r of childReferenceTypes) {
848
- const child = resolveReferenceNode(addressSpace, r);
849
- _cache._childByNameMap.set(child.browseName.name.toString(), child);
850
- }
813
+ const ref = select[0];
814
+ const r = this.addressSpace.findReferenceType(ref.referenceType);
815
+ if (!r)
816
+ return null;
817
+ const hasChild = this.addressSpace.findReferenceType("HasChild");
818
+ if (!hasChild) {
819
+ return null; // too early, bmy be namespace 0 is still loading
851
820
  }
852
- const ret = _cache._childByNameMap.get(browseName.toString()) || null;
853
- return ret;
821
+ if (r.isSubtypeOf(hasChild)) {
822
+ return ref.node;
823
+ }
824
+ return null;
825
+ }
826
+ getNodeVersion() {
827
+ return this.getChildByName("NodeVersion", 0);
828
+ /*
829
+ const cache = BaseNode_getCache(this);
830
+ if (cache._versionNode == undefined) {
831
+ cache._versionNode = this.getChildByName("NodeVersion", 0) as UAProperty<string, DataType.String> | null;
832
+ }
833
+ return cache._versionNode as UAProperty<UAString, DataType.String> | null;
834
+ */
835
+ }
836
+ get nodeVersion() {
837
+ return this.getNodeVersion() || undefined;
838
+ }
839
+ set nodeVersion(n) {
840
+ (0, node_opcua_assert_1.assert)(false);
854
841
  }
855
842
  get toStateNode() {
856
843
  const nodes = this.findReferencesAsObject("ToState", true);
@@ -865,6 +852,7 @@ class BaseNodeImpl extends events_1.EventEmitter {
865
852
  /**
866
853
  * this methods propagates the forward references to the pointed node
867
854
  * by inserting backward references to the counter part node
855
+ * @private
868
856
  */
869
857
  propagate_back_references() {
870
858
  const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
@@ -874,7 +862,7 @@ class BaseNodeImpl extends events_1.EventEmitter {
874
862
  return;
875
863
  }
876
864
  const addressSpace = this.addressSpace;
877
- for (const reference of Object.values(_private._referenceIdx)) {
865
+ for (const reference of _private._referenceIdx.values()) {
878
866
  _propagate_ref.call(this, addressSpace, reference);
879
867
  }
880
868
  }
@@ -882,16 +870,19 @@ class BaseNodeImpl extends events_1.EventEmitter {
882
870
  * the dispose method should be called when the node is no longer used, to release
883
871
  * back pointer to the address space and clear caches.
884
872
  *
885
-
886
- *
873
+ * @private
887
874
  */
888
875
  dispose() {
889
876
  this.emit("dispose");
890
877
  this.removeAllListeners();
891
878
  this._clear_caches();
892
879
  const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
893
- Object.values(_private._back_referenceIdx).forEach((ref) => ref.dispose());
894
- Object.values(_private._referenceIdx).forEach((ref) => ref.dispose());
880
+ for (let ref of _private._back_referenceIdx.values()) {
881
+ ref.dispose();
882
+ }
883
+ for (let ref of _private._referenceIdx.values()) {
884
+ ref.dispose();
885
+ }
895
886
  (0, base_node_private_1.BaseNode_removePrivate)(this);
896
887
  }
897
888
  isDisposed() {
@@ -909,7 +900,7 @@ class BaseNodeImpl extends events_1.EventEmitter {
909
900
  unpropagate_back_references() {
910
901
  const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
911
902
  const addressSpace = this.addressSpace;
912
- for (const reference of Object.values(_private._referenceIdx)) {
903
+ for (const reference of _private._referenceIdx.values()) {
913
904
  // filter out non Hierarchical References
914
905
  const referenceType = resolveReferenceType(addressSpace, reference);
915
906
  // istanbul ignore next
@@ -944,8 +935,19 @@ class BaseNodeImpl extends events_1.EventEmitter {
944
935
  }
945
936
  this._postInstantiateFunc = chain.call(this, this._postInstantiateFunc, f);
946
937
  }
947
- _on_child_added() {
938
+ _on_child_added(childNode) {
939
+ // this._clear_caches();
940
+ // return;
941
+ const cache = (0, base_node_private_1.BaseNode_getCache)(this);
942
+ const tmpV = cache._versionNode;
943
+ const tmpC = cache._children;
948
944
  this._clear_caches();
945
+ const newCache = (0, base_node_private_1.BaseNode_getCache)(this);
946
+ newCache._versionNode = tmpV;
947
+ newCache._children = tmpC;
948
+ if (newCache._children) {
949
+ newCache._children.push(childNode);
950
+ }
949
951
  }
950
952
  _on_child_removed(obj) {
951
953
  // obj; // unused;
@@ -982,18 +984,19 @@ class BaseNodeImpl extends events_1.EventEmitter {
982
984
  return result;
983
985
  }
984
986
  __addReference(referenceOpts) {
987
+ const addressSpace = this.addressSpace;
985
988
  const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
986
989
  (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(referenceOpts, "referenceType"));
987
990
  // xx isForward is optional : assert(Object.prototype.hasOwnProperty.call(reference,"isForward"));
988
991
  (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(referenceOpts, "nodeId"));
989
- const addressSpace = this.addressSpace;
990
992
  const reference = addressSpace.normalizeReferenceTypes([referenceOpts])[0];
991
993
  (0, node_opcua_assert_1.assert)(reference instanceof reference_impl_1.ReferenceImpl);
992
994
  const h = reference.hash;
993
- (0, node_opcua_assert_1.assert)(!_private._back_referenceIdx[h], "reference exists already in _back_references");
994
- (0, node_opcua_assert_1.assert)(!_private._referenceIdx[h], "reference exists already in _references");
995
- _private._referenceIdx[h] = reference;
995
+ (0, node_opcua_assert_1.assert)(!_private._back_referenceIdx.has(h), "reference exists already in _back_references");
996
+ (0, node_opcua_assert_1.assert)(!_private._referenceIdx.has(h), "reference exists already in _references");
997
+ _private._referenceIdx.set(h, reference);
996
998
  (0, base_node_private_1._handle_HierarchicalReference)(this, reference);
999
+ this._clear_caches();
997
1000
  return reference;
998
1001
  }
999
1002
  _setDisplayName(displayName) {
@@ -1139,6 +1142,7 @@ class BaseNodeImpl extends events_1.EventEmitter {
1139
1142
  }
1140
1143
  }
1141
1144
  exports.BaseNodeImpl = BaseNodeImpl;
1145
+ BaseNodeImpl._hasChild = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeIdType.NUMERIC, node_opcua_constants_1.ReferenceTypeIds.HasChild);
1142
1146
  function toRoleNodeId(s) {
1143
1147
  if (typeof s === "string") {
1144
1148
  return (0, node_opcua_nodeid_1.resolveNodeId)(session_context_1.WellKnownRolesNodeId[s]);
@@ -1162,12 +1166,12 @@ function toString_ReferenceDescription(ref, options) {
1162
1166
  r.dispose();
1163
1167
  return str;
1164
1168
  }
1165
- function _setup_parent_item(references) {
1166
- references = Object.values(references);
1169
+ function _setup_parent_item(referencesMap) {
1170
+ let references = referencesMap.values();
1167
1171
  const _private = (0, base_node_private_1.BaseNode_getPrivate)(this);
1168
1172
  (0, node_opcua_assert_1.assert)(!_private._parent, "_setup_parent_item has been already called");
1169
1173
  const addressSpace = this.addressSpace;
1170
- if (references.length > 0) {
1174
+ if (referencesMap.size > 0) {
1171
1175
  references = this.findReferencesEx("Aggregates", node_opcua_data_model_1.BrowseDirection.Inverse);
1172
1176
  if (references.length >= 1) {
1173
1177
  // istanbul ignore next
@@ -1193,26 +1197,52 @@ function _setup_parent_item(references) {
1193
1197
  }
1194
1198
  return null;
1195
1199
  }
1200
+ function toObject(addressSpace, reference) {
1201
+ const obj = resolveReferenceNode(addressSpace, reference);
1202
+ // istanbul ignore next
1203
+ if (doDebug && !obj) {
1204
+ debugLog(chalk_1.default.red(" Warning : object with nodeId ") +
1205
+ chalk_1.default.cyan(reference.nodeId.toString()) +
1206
+ chalk_1.default.red(" cannot be found in the address space !"));
1207
+ }
1208
+ return obj;
1209
+ }
1196
1210
  function _asObject(references, addressSpace) {
1197
- function toObject(reference) {
1198
- const obj = resolveReferenceNode(addressSpace, reference);
1199
- // istanbul ignore next
1200
- if (doDebug && !obj) {
1201
- debugLog(chalk_1.default.red(" Warning : object with nodeId ") +
1202
- chalk_1.default.cyan(reference.nodeId.toString()) +
1203
- chalk_1.default.red(" cannot be found in the address space !"));
1211
+ return references.map((a) => toObject(addressSpace, a)).filter((o) => o != null && o != undefined);
1212
+ }
1213
+ function _select_by_browse_name(map, browseName, namespaceIndex) {
1214
+ if ((namespaceIndex === null || namespaceIndex === undefined) && typeof browseName === "string") {
1215
+ // no namespace specified and needed
1216
+ const result = map.get(browseName);
1217
+ if (result) {
1218
+ if (Array.isArray(result)) {
1219
+ return result;
1220
+ }
1221
+ return [result];
1204
1222
  }
1205
- return obj;
1206
1223
  }
1207
- function remove_null(o) {
1208
- return !!o;
1224
+ else {
1225
+ const _browseName = (0, node_opcua_data_model_1.coerceQualifiedName)(typeof browseName === "string" ? { name: browseName, namespaceIndex } : browseName);
1226
+ const result = map.get(_browseName.name || "");
1227
+ if (result) {
1228
+ if (Array.isArray(result)) {
1229
+ // only select the one with the matching namepsace index
1230
+ return result.filter((t) => t.node.browseName.namespaceIndex == _browseName.namespaceIndex);
1231
+ }
1232
+ else {
1233
+ if (result.node.browseName.namespaceIndex == _browseName.namespaceIndex) {
1234
+ return [result];
1235
+ }
1236
+ return [];
1237
+ }
1238
+ }
1209
1239
  }
1210
- return references.map(toObject).filter(remove_null);
1240
+ return [];
1211
1241
  }
1212
1242
  function _filter_by_browse_name(components, browseName, namespaceIndex) {
1213
1243
  let select = [];
1214
1244
  if ((namespaceIndex === null || namespaceIndex === undefined) && typeof browseName === "string") {
1215
- select = components.filter((c) => c.browseName.name.toString() === browseName);
1245
+ select = components.filter((c) => c.browseName.name === browseName);
1216
1246
  if (select && select.length > 1) {
1217
1247
  warningLog("Multiple children exist with name ", browseName, " please specify a namespace index");
1218
1248
  }
@@ -1233,8 +1263,7 @@ function _propagate_ref(addressSpace, reference) {
1233
1263
  const referenceType = reference_impl_1.ReferenceImpl.resolveReferenceType(addressSpace, reference);
1234
1264
  // istanbul ignore next
1235
1265
  if (!referenceType) {
1236
- // tslint:disable-next-line:no-console
1237
- console.error(chalk_1.default.red(" ERROR"), " cannot find reference ", reference.referenceType, reference.toString());
1266
+ errorLog(chalk_1.default.red(" ERROR"), " cannot find reference ", reference.referenceType, reference.toString());
1238
1267
  }
1239
1268
  // ------------------------------- Filter out back reference when reference type
1240
1269
  // is HasTypeDefinition, HasModellingRule, etc ...
@@ -1245,8 +1274,6 @@ function _propagate_ref(addressSpace, reference) {
1245
1274
  if (!referenceType || _is_massively_used_reference(referenceType)) {
1246
1275
  return;
1247
1276
  }
1248
- // ------------------------------- EXPERIMENT
1249
- // xx if (!referenceType.isSubtypeOf(hierarchicalReferencesId)) { return; }
1250
1277
  const related_node = resolveReferenceNode(addressSpace, reference);
1251
1278
  if (related_node) {
1252
1279
  // verify that reference doesn't point to object it this (see mantis 3099)
@@ -1254,7 +1281,7 @@ function _propagate_ref(addressSpace, reference) {
1254
1281
  // istanbul ignore next
1255
1282
  if (displayWarningReferencePointingToItSelf) {
1256
1283
  // this could happen with method
1257
- console.warn(" Warning: a Reference is pointing to this ", this.nodeId.toString(), this.browseName.toString());
1284
+ warningLog(" Warning: a Reference is pointing to source ", this.nodeId.toString(), this.browseName.toString(), ". Is this intentional ?");
1258
1285
  displayWarningReferencePointingToItSelf = false;
1259
1286
  }
1260
1287
  }