node-opcua-address-space 2.93.0 → 2.95.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.
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import * as chalk from "chalk";
5
5
 
6
- import { UAReference, BaseNode, UAObject, UAVariable } from "node-opcua-address-space-base";
6
+ import { UAReference, BaseNode, UAObject, UAVariable, UAObjectType, UAVariableType } from "node-opcua-address-space-base";
7
7
  import { assert } from "node-opcua-assert";
8
8
  import { BrowseDirection, NodeClass } from "node-opcua-data-model";
9
9
  import { Enum, EnumItem } from "node-opcua-enum";
@@ -101,40 +101,42 @@ try {
101
101
  export function _handle_model_change_event(node: BaseNodeImpl): void {
102
102
  const addressSpace = node.addressSpace as AddressSpacePrivate;
103
103
  //
104
- const parent = node.parent!;
104
+ const parents = node.parent ? [node.parent] : [];
105
105
 
106
- if (parent && (parent as BaseNode).nodeVersion) {
107
- addressSpace.modelChangeTransaction(() => {
108
- let typeDefinitionNodeId = null;
109
-
110
- if (node.nodeClass === NodeClass.Object || node.nodeClass === NodeClass.Variable) {
111
- typeDefinitionNodeId = node.typeDefinitionObj.nodeId;
112
- }
113
-
114
- const modelChange1 = new ModelChangeStructureDataType({
115
- affected: node.nodeId,
116
- affectedType: typeDefinitionNodeId,
117
- verb: makeVerb("NodeAdded")
118
- });
119
- addressSpace._collectModelChange(null, modelChange1);
120
-
121
- const modelChangeSrc = new ModelChangeStructureDataType({
122
- affected: parent.nodeId,
123
- affectedType: null,
124
- verb: makeVerb("ReferenceAdded")
125
- });
126
- addressSpace._collectModelChange(null, modelChangeSrc);
106
+ const containingFolders = node.findReferencesExAsObject("Organizes", BrowseDirection.Inverse);
127
107
 
128
- // bidirectional
129
- if ((node as BaseNode).nodeVersion) {
130
- const modelChangeTgt = new ModelChangeStructureDataType({
108
+ let typeDefinitionNodeId: NodeId | null = null;
109
+ if (node.nodeClass === NodeClass.Object || node.nodeClass === NodeClass.Variable) {
110
+ typeDefinitionNodeId = node.typeDefinitionObj.nodeId;
111
+ }
112
+ for (const parent of [...parents, ...containingFolders]) {
113
+ if (parent && (parent as BaseNode).nodeVersion) {
114
+ addressSpace.modelChangeTransaction(() => {
115
+ const modelChange1 = new ModelChangeStructureDataType({
131
116
  affected: node.nodeId,
132
117
  affectedType: typeDefinitionNodeId,
118
+ verb: makeVerb("NodeAdded")
119
+ });
120
+ addressSpace._collectModelChange(null, modelChange1);
121
+
122
+ const modelChangeSrc = new ModelChangeStructureDataType({
123
+ affected: parent.nodeId,
124
+ affectedType: null,
133
125
  verb: makeVerb("ReferenceAdded")
134
126
  });
135
- addressSpace._collectModelChange(null, modelChangeTgt);
136
- }
137
- });
127
+ addressSpace._collectModelChange(null, modelChangeSrc);
128
+
129
+ // bidirectional
130
+ if ((node as BaseNode).nodeVersion) {
131
+ const modelChangeTgt = new ModelChangeStructureDataType({
132
+ affected: node.nodeId,
133
+ affectedType: typeDefinitionNodeId,
134
+ verb: makeVerb("ReferenceAdded")
135
+ });
136
+ addressSpace._collectModelChange(null, modelChangeTgt);
137
+ }
138
+ });
139
+ }
138
140
  }
139
141
  }
140
142
 
@@ -670,7 +670,7 @@ export class NamespaceImpl implements NamespacePrivate {
670
670
 
671
671
  node.install_extra_properties();
672
672
 
673
- _handle_node_version(node, options);
673
+ _create_node_version_if_needed(node, options);
674
674
 
675
675
  _handle_model_change_event(node as BaseNodeImpl);
676
676
  });
@@ -2209,12 +2209,16 @@ export function isNonEmptyQualifiedName(browseName?: null | string | QualifiedNa
2209
2209
  return browseName.name!.length > 0;
2210
2210
  }
2211
2211
 
2212
- function _handle_node_version(node: BaseNode, options: any) {
2212
+ function _create_node_version_if_needed(node: BaseNode, options: {nodeVersion: boolean}) {
2213
2213
  assert(options);
2214
2214
  if (options.nodeVersion) {
2215
2215
  assert(node.nodeClass === NodeClass.Variable || node.nodeClass === NodeClass.Object);
2216
-
2217
- const nodeVersion = node.addressSpace.getOwnNamespace().addVariable({
2216
+ // istanbul ignore next
2217
+ if (node.getChildByName("NodeVersion")) {
2218
+ return; // already exists
2219
+ }
2220
+ const namespace = node.addressSpace.getOwnNamespace();
2221
+ const nodeVersion = namespace.addVariable({
2218
2222
  browseName: "NodeVersion",
2219
2223
  dataType: "String",
2220
2224
  propertyOf: node
@@ -446,7 +446,7 @@
446
446
 
447
447
  /**
448
448
  *
449
- *
449
+ *
450
450
  * from OPC.UA.Spec 1.02 part 4
451
451
  * 5.10.2.4 StatusCodes
452
452
  * Table 51 defines values for the operation level statusCode contained in the DataValue structure of
@@ -454,22 +454,22 @@
454
454
  *
455
455
  * Table 51 Read Operation Level Result Codes
456
456
  *
457
- * Symbolic Id Description
458
- *
459
- * BadNodeIdInvalid The syntax of the node id is not valid.
460
- * BadNodeIdUnknown The node id refers to a node that does not exist in the server address space.
461
- * BadAttributeIdInvalid BadAttributeIdInvalid The attribute is not supported for the specified node.
462
- * BadIndexRangeInvalid The syntax of the index range parameter is invalid.
463
- * BadIndexRangeNoData No data exists within the range of indexes specified.
464
- * BadDataEncodingInvalid The data encoding is invalid.
465
- * This result is used if no dataEncoding can be applied because an Attribute other
466
- * than Value was requested or the DataType of the Value Attribute is not a subtype
467
- * of the Structure DataType.
468
- * BadDataEncodingUnsupported The server does not support the requested data encoding for the node.
469
- * This result is used if a dataEncoding can be applied but the passed data encoding
470
- * is not known to the Server.
471
- * BadNotReadable The access level does not allow reading or subscribing to the Node.
472
- * BadUserAccessDenied User does not have permission to perform the requested operation. (table 165)
457
+ * | Symbolic Id | Description
458
+ * |-----------------------------|---------------------------------------------------------------------------------------------|
459
+ * |BadNodeIdInvalid | The syntax of the node id is not valid.|
460
+ * |BadNodeIdUnknown |The node id refers to a node that does not exist in the server address space.|
461
+ * |BadAttributeIdInvalid | BadAttributeIdInvalid The attribute is not supported for the specified node.|
462
+ * |BadIndexRangeInvalid | The syntax of the index range parameter is invalid.|
463
+ * |BadIndexRangeNoData | No data exists within the range of indexes specified.|
464
+ * |BadDataEncodingInvalid | The data encoding is invalid.|
465
+ * | | This result is used if no dataEncoding can be applied because an Attribute other|
466
+ * | | than Value was requested or the DataType of the Value Attribute is not a subtype|
467
+ * | | of the Structure DataType.|
468
+ * |BadDataEncodingUnsupported | The server does not support the requested data encoding for the node. |
469
+ * | | This result is used if a dataEncoding can be applied but the passed data encoding |
470
+ * | | is not known to the Server. |
471
+ * |BadNotReadable | The access level does not allow reading or subscribing to the Node.|
472
+ * |BadUserAccessDenied | User does not have permission to perform the requested operation. (table 165)|
473
473
  */
474
474
  public readValue(
475
475
  context?: ISessionContext | null,
@@ -589,7 +589,7 @@
589
589
  }
590
590
 
591
591
  if (this.$dataValue.serverTimestamp && oldestDate.getTime() <= this.$dataValue.serverTimestamp!.getTime()) {
592
- const dataValue = this.readValue();
592
+ const dataValue = this.readValue().clone();
593
593
  dataValue.serverTimestamp = oldestDate;
594
594
  dataValue.serverPicoseconds = 0;
595
595
  return callback(null, dataValue);
@@ -606,7 +606,7 @@
606
606
  );
607
607
  dataValue = { statusCode: StatusCodes.BadNoDataAvailable };
608
608
  }
609
- if (dataValue !== this.$dataValue) {
609
+ if (dataValue && dataValue !== this.$dataValue) {
610
610
  this._internal_set_dataValue(coerceDataValue(dataValue), null);
611
611
  }
612
612
  callback(err, this.$dataValue);
@@ -1,4 +1,4 @@
1
- import { ContinuationData, IContinuationPointInfo, IContinuationPointManager } from "node-opcua-address-space-base";
1
+ import { ContinuationData, IContinuationPointInfo, IContinuationPointManager, ISessionBase } from "node-opcua-address-space-base";
2
2
  import { DataValue } from "node-opcua-data-value";
3
3
  import { NodeId } from "node-opcua-nodeid";
4
4
  import { ReferenceDescription } from "node-opcua-service-browse";
@@ -26,7 +26,7 @@ export class MockContinuationPointManager implements IContinuationPointManager {
26
26
  }
27
27
  }
28
28
 
29
- export const mockSession = {
29
+ export const mockSession: ISessionBase = {
30
30
  getSessionId() {
31
31
  return new NodeId();
32
32
  },