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
@@ -35,16 +35,18 @@ import {
35
35
  UAReference,
36
36
  CloneOptions,
37
37
  CloneHelper,
38
- fullPath2
38
+ fullPath2,
39
+ UAVariableT
39
40
  } from "node-opcua-address-space-base";
40
41
  import { DataValue } from "node-opcua-data-value";
41
42
  import { ObjectTypeIds, VariableTypeIds } from "node-opcua-constants";
42
43
 
43
44
  import { UANamespace_process_modelling_rule } from "./namespace_private";
44
- import { ReferenceImpl } from "./reference_impl";
45
+ import { ReferenceImpl, resolveReferenceNode } from "./reference_impl";
45
46
  import { BaseNodeImpl, getReferenceType } from "./base_node_impl";
46
47
  import { AddressSpacePrivate } from "./address_space_private";
47
48
  import { wipeMemorizedStuff } from "./tool_isSubtypeOf";
49
+ import { DataType } from "node-opcua-basic-types";
48
50
 
49
51
  // eslint-disable-next-line prefer-const
50
52
  const errorLog = make_errorLog(__filename);
@@ -57,11 +59,13 @@ const warningLog = make_warningLog(__filename);
57
59
 
58
60
  interface BaseNodeCacheInner {
59
61
  typeDefinition?: NodeId;
60
- _childByNameMap?: Map<string, BaseNode>;
61
62
  typeDefinitionObj?: UAVariableType | UAObjectType | null;
62
63
  _aggregates?: BaseNode[];
63
64
  _components?: BaseNode[];
64
65
  _properties?: BaseNode[];
66
+ _children?: BaseNode[];
67
+ _versionNode?: UAVariableT<string, DataType.String> | null;
68
+
65
69
  _notifiers?: BaseNode[];
66
70
  _eventSources?: BaseNode[];
67
71
  _methods?: UAMethod[];
@@ -74,23 +78,28 @@ interface BaseNodeCacheInner {
74
78
  _subtypeOfObj?: BaseNode | null;
75
79
  }
76
80
 
81
+ export type UAReferenceWithNodeRef = UAReference & { node: BaseNode };
82
+ export type HierarchicalIndexMap = Map<string, UAReferenceWithNodeRef | UAReferenceWithNodeRef[]>;
83
+
77
84
  interface BaseNodeCache {
85
+
86
+ _childByNameMap?: HierarchicalIndexMap;
78
87
  __address_space: IAddressSpace | null;
79
88
  _browseFilter?: (this: BaseNode, context?: ISessionContext) => boolean;
80
89
  _cache: BaseNodeCacheInner;
81
90
  _description?: LocalizedText;
82
91
  _displayName: LocalizedText[];
83
92
  _parent?: BaseNode | null;
84
- _back_referenceIdx: { [key: string]: UAReference };
85
- _referenceIdx: { [key: string]: UAReference };
93
+ _back_referenceIdx: Map<string, UAReference>;
94
+ _referenceIdx: Map<string, UAReference>;
86
95
  }
87
96
 
88
97
  export function BaseNode_initPrivate(self: BaseNode): BaseNodeCache {
89
98
  const _private: BaseNodeCache = {
90
99
  __address_space: null,
91
100
 
92
- _referenceIdx: {},
93
- _back_referenceIdx: {},
101
+ _referenceIdx: new Map(),
102
+ _back_referenceIdx: new Map(),
94
103
 
95
104
  _browseFilter: undefined,
96
105
  _cache: {},
@@ -109,8 +118,8 @@ export function BaseNode_removePrivate(self: BaseNode): void {
109
118
  const _private = BaseNode_getPrivate(self);
110
119
  _private._cache = {};
111
120
  _private.__address_space = null;
112
- _private._back_referenceIdx = {};
113
- _private._referenceIdx = {};
121
+ _private._back_referenceIdx = new Map();
122
+ _private._referenceIdx = new Map();
114
123
  _private._description = undefined;
115
124
  _private._displayName = [];
116
125
  }
@@ -189,8 +198,8 @@ export function BaseNode_toString(this: BaseNode, options: ToStringOption): void
189
198
  options.add(options.padding + chalk.yellow(" browseName : ") + this.browseName.toString());
190
199
  options.add(
191
200
  options.padding +
192
- chalk.yellow(" displayName : ") +
193
- this.displayName.map((f) => f.locale + " " + f.text).join(" | ")
201
+ chalk.yellow(" displayName : ") +
202
+ this.displayName.map((f) => f.locale + " " + f.text).join(" | ")
194
203
  );
195
204
 
196
205
  options.add(
@@ -209,9 +218,9 @@ export function BaseNode_References_toString(this: BaseNode, options: ToStringOp
209
218
 
210
219
  options.add(
211
220
  options.padding +
212
- chalk.yellow(" references : ") +
213
- " length =" +
214
- Object.keys(_private._referenceIdx).length
221
+ chalk.yellow(" references : ") +
222
+ " length =" +
223
+ _private._referenceIdx.size
215
224
  );
216
225
 
217
226
  function dump_reference(follow: boolean, reference: UAReference | null) {
@@ -250,12 +259,12 @@ export function BaseNode_References_toString(this: BaseNode, options: ToStringOp
250
259
  })();
251
260
  options.add(
252
261
  options.padding +
253
- chalk.yellow(" +-> ") +
254
- reference.toString(displayOptions) +
255
- " " +
256
- chalk.cyan(name.padEnd(25, " ")) +
257
- " " +
258
- chalk.magentaBright(extra)
262
+ chalk.yellow(" +-> ") +
263
+ reference.toString(displayOptions) +
264
+ " " +
265
+ chalk.cyan(name.padEnd(25, " ")) +
266
+ " " +
267
+ chalk.magentaBright(extra)
259
268
  );
260
269
 
261
270
  // ignore HasTypeDefinition as it has been already handled
@@ -278,30 +287,33 @@ export function BaseNode_References_toString(this: BaseNode, options: ToStringOp
278
287
  }
279
288
 
280
289
  // direct reference
281
- (Object.values(_private._referenceIdx) as UAReference[]).forEach(dump_reference.bind(null, true));
290
+ for (var r of _private._referenceIdx.values()) {
291
+ dump_reference(false, r);
292
+ }
282
293
 
283
- const br = Object.values(_private._back_referenceIdx).map((x) => x);
284
294
 
285
295
  options.add(
286
296
  options.padding +
287
- chalk.yellow(" back_references : ") +
288
- chalk.cyan(" length =") +
289
- br.length +
290
- chalk.grey(" ( references held by other nodes involving this node)")
297
+ chalk.yellow(" back_references : ") +
298
+ chalk.cyan(" length =") +
299
+ _private._back_referenceIdx.size +
300
+ chalk.grey(" ( references held by other nodes involving this node)")
291
301
  );
302
+ for (const r of _private._back_referenceIdx.values()) {
303
+ dump_reference(false, r);
304
+ }
292
305
  // backward reference
293
- br.forEach(dump_reference.bind(null, false));
294
306
  }
295
307
 
296
308
  function _UAType_toString(this: UAReferenceType | UADataType | UAObjectType | UAVariableType, options: ToStringOption): void {
297
309
  if (this.subtypeOfObj) {
298
310
  options.add(
299
311
  options.padding +
300
- chalk.yellow(" subtypeOf : ") +
301
- this.subtypeOfObj.browseName.toString() +
302
- " (" +
303
- this.subtypeOfObj.nodeId.toString() +
304
- ")"
312
+ chalk.yellow(" subtypeOf : ") +
313
+ this.subtypeOfObj.browseName.toString() +
314
+ " (" +
315
+ this.subtypeOfObj.nodeId.toString() +
316
+ ")"
305
317
  );
306
318
  }
307
319
  }
@@ -310,11 +322,11 @@ function _UAInstance_toString(this: UAVariable | UAMethod | UAObject, options: T
310
322
  if (this.typeDefinitionObj) {
311
323
  options.add(
312
324
  options.padding +
313
- chalk.yellow(" typeDefinition : ") +
314
- this.typeDefinitionObj.browseName.toString() +
315
- " (" +
316
- this.typeDefinitionObj.nodeId.toString() +
317
- ")"
325
+ chalk.yellow(" typeDefinition : ") +
326
+ this.typeDefinitionObj.browseName.toString() +
327
+ " (" +
328
+ this.typeDefinitionObj.nodeId.toString() +
329
+ ")"
318
330
  );
319
331
  }
320
332
  }
@@ -421,9 +433,9 @@ export function VariableOrVariableType_toString(this: UAVariableType | UAVariabl
421
433
  if (_dataValue) {
422
434
  options.add(
423
435
  options.padding +
424
- chalk.yellow(" value : ") +
425
- "\n" +
426
- options.indent(_dataValue.toString(), options.padding + " | ")
436
+ chalk.yellow(" value : ") +
437
+ "\n" +
438
+ options.indent(_dataValue.toString(), options.padding + " | ")
427
439
  );
428
440
  }
429
441
  }
@@ -440,19 +452,19 @@ export function VariableOrVariableType_toString(this: UAVariableType | UAVariabl
440
452
  if (this.minimumSamplingInterval !== undefined) {
441
453
  options.add(
442
454
  options.padding +
443
- chalk.yellow(" minimumSamplingInterval : ") +
444
- " " +
445
- this.minimumSamplingInterval.toString() +
446
- " ms"
455
+ chalk.yellow(" minimumSamplingInterval : ") +
456
+ " " +
457
+ this.minimumSamplingInterval.toString() +
458
+ " ms"
447
459
  );
448
460
  }
449
461
  if (this.arrayDimensions) {
450
462
  options.add(
451
463
  options.padding +
452
- chalk.yellow(" arrayDimension : ") +
453
- " [" +
454
- this.arrayDimensions.join(",").toString() +
455
- " ]"
464
+ chalk.yellow(" arrayDimension : ") +
465
+ " [" +
466
+ this.arrayDimensions.join(",").toString() +
467
+ " ]"
456
468
  );
457
469
  }
458
470
  }
@@ -628,11 +640,11 @@ function _clone_collection_new(
628
640
  // tslint:disable-next-line:no-console
629
641
  warningLog(
630
642
  chalk.red("Warning : cannot clone node ") +
631
- fullPath2(node) +
632
- " of class " +
633
- NodeClass[node.nodeClass].toString() +
634
- " while cloning " +
635
- fullPath2(newParent)
643
+ fullPath2(node) +
644
+ " of class " +
645
+ NodeClass[node.nodeClass].toString() +
646
+ " while cloning " +
647
+ fullPath2(newParent)
636
648
  );
637
649
  continue;
638
650
  }
@@ -1026,7 +1038,7 @@ export function _clone<T extends UAObject | UAVariable | UAMethod>(
1026
1038
  let typeDefinitionNode: UAVariableType | UAObjectType | null = originalNode.typeDefinitionObj;
1027
1039
 
1028
1040
  extraInfo.pushContext({
1029
- clonedParent : clonedNode,
1041
+ clonedParent: clonedNode,
1030
1042
  originalParent: originalNode
1031
1043
  });
1032
1044
 
@@ -1070,36 +1082,83 @@ export function _clone<T extends UAObject | UAVariable | UAMethod>(
1070
1082
  return clonedNode;
1071
1083
  }
1072
1084
 
1085
+ function _add(_childByNameMap: HierarchicalIndexMap, reference: UAReferenceWithNodeRef)
1086
+ {
1087
+ assert(reference.node);// const targetNode = ReferenceImpl.resolveReferenceNode(addressSpace, reference);
1088
+ const targetNode = reference.node;
1089
+ const hash = targetNode.browseName!.name || "";
1090
+ const existing = _childByNameMap.get(hash);
1091
+ if (existing) {
1092
+ if (Array.isArray(existing)) {
1093
+ existing.push(reference);
1094
+ } else {
1095
+ _childByNameMap.set(hash, [existing, reference as UAReferenceWithNodeRef]);
1096
+ }
1097
+ } else {
1098
+ _childByNameMap.set(hash, reference as UAReferenceWithNodeRef);
1099
+ }
1100
+ }
1101
+
1102
+ function sameRef(a: UAReference, b: UAReference) {
1103
+ if (a.isForward != b.isForward) return false;
1104
+ if (!sameNodeId(a.nodeId, b.nodeId)) return false;
1105
+ if (!sameNodeId(a.referenceType, b.referenceType)) return false;
1106
+ return true;
1107
+ }
1108
+ function _remove(_childByNameMap: HierarchicalIndexMap, reference: UAReferenceWithNodeRef) {
1109
+
1110
+ const target = reference.node;
1111
+ const hash = target.browseName.name || "";
1112
+ const existing = _childByNameMap.get(hash);
1113
+ if (Array.isArray(existing)) {
1114
+ existing.filter(r=>!sameRef(r, reference));
1115
+ } else {
1116
+ _childByNameMap.delete(hash);
1117
+ }
1118
+ }
1073
1119
  export function _handle_HierarchicalReference(node: BaseNode, reference: UAReference): void {
1074
- const _cache = BaseNode_getCache(node);
1120
+ const _private = BaseNode_getPrivate(node);
1075
1121
  if (!reference.isForward) return;
1076
- if (_cache._childByNameMap) {
1122
+ if (_private._childByNameMap) {
1077
1123
  const addressSpace = node.addressSpace;
1078
1124
  const referenceType = ReferenceImpl.resolveReferenceType(addressSpace, reference);
1079
1125
 
1080
1126
  if (referenceType) {
1081
1127
  const HierarchicalReferencesType = addressSpace.findReferenceType("HierarchicalReferences");
1082
1128
  if (referenceType.isSubtypeOf(HierarchicalReferencesType!)) {
1083
- assert(reference.isForward);
1084
- const targetNode = ReferenceImpl.resolveReferenceNode(addressSpace, reference);
1085
- _cache._childByNameMap.set(targetNode.browseName!.name!.toString(), targetNode);
1129
+ ReferenceImpl.resolveReferenceNode(addressSpace, reference);
1130
+ _add(_private._childByNameMap, reference as UAReferenceWithNodeRef)
1086
1131
  }
1087
1132
  }
1088
1133
  }
1089
1134
  }
1090
1135
 
1091
- function _remove_HierarchicalReference(node: BaseNode, reference: UAReference) {
1092
- const _cache = BaseNode_getCache(node);
1093
- if (_cache._childByNameMap) {
1136
+ export function _get_HierarchicalReference(node: BaseNode): HierarchicalIndexMap {
1137
+ const addressSpace = node.addressSpace;
1138
+ const _private = BaseNode_getPrivate(node);
1139
+ if (!_private._childByNameMap) {
1140
+ _private._childByNameMap = new Map();
1141
+ const references = node.findReferencesEx("HierarchicalReferences");
1142
+ for (var reference of references) {
1143
+ ReferenceImpl.resolveReferenceNode(addressSpace, reference);
1144
+ _add(_private._childByNameMap, reference as UAReferenceWithNodeRef);
1145
+ }
1146
+ }
1147
+ return _private._childByNameMap;
1148
+
1149
+ }
1150
+ export function _remove_HierarchicalReference(node: BaseNodeImpl, reference: UAReference) {
1151
+ const _private = BaseNode_getPrivate(node);
1152
+ if (_private._childByNameMap && reference.isForward) {
1094
1153
  const addressSpace = node.addressSpace;
1095
1154
  const referenceType = ReferenceImpl.resolveReferenceType(addressSpace, reference);
1096
1155
 
1097
1156
  if (referenceType) {
1098
1157
  const HierarchicalReferencesType = addressSpace.findReferenceType("HierarchicalReferences");
1099
1158
  if (referenceType.isSubtypeOf(HierarchicalReferencesType!)) {
1100
- assert(reference.isForward);
1101
- const targetNode = ReferenceImpl.resolveReferenceNode(addressSpace, reference);
1102
- _cache._childByNameMap.delete(targetNode.browseName!.name!.toString());
1159
+
1160
+ ReferenceImpl.resolveReferenceNode(addressSpace, reference);
1161
+ _remove(_private._childByNameMap, reference as UAReferenceWithNodeRef);
1103
1162
  }
1104
1163
  }
1105
1164
  }
@@ -1151,39 +1210,38 @@ export function _constructReferenceDescription(
1151
1210
  return references.map((reference: UAReference) => _makeReferenceDescription(addressSpace, reference, resultMask));
1152
1211
  }
1153
1212
 
1154
- export function BaseNode_remove_backward_reference(this: BaseNode, reference: UAReference): void {
1213
+ export function BaseNode_remove_backward_reference(this: BaseNodeImpl, reference: UAReference): void {
1155
1214
  const _private = BaseNode_getPrivate(this);
1156
1215
  _remove_HierarchicalReference(this, reference);
1157
1216
  const h = (<ReferenceImpl>reference).hash;
1158
- if (_private._back_referenceIdx && _private._back_referenceIdx[h]) {
1217
+ if (_private._back_referenceIdx?.has(h)) {
1159
1218
  // note : h may not exist in _back_referenceIdx since we are not indexing
1160
1219
  // _back_referenceIdx to UAObjectType and UAVariableType for performance reasons
1161
- (<ReferenceImpl>_private._back_referenceIdx[h]).dispose();
1162
- delete _private._back_referenceIdx[h];
1220
+ (<ReferenceImpl>_private._back_referenceIdx.get(h)).dispose();
1221
+ _private._back_referenceIdx.delete(h);
1163
1222
  }
1164
1223
  (<ReferenceImpl>reference).dispose();
1165
1224
  }
1166
1225
 
1167
- export function BaseNode_add_backward_reference(this: BaseNode, reference: UAReference): void {
1226
+ export function BaseNode_add_backward_reference(this: BaseNodeImpl, reference: UAReference): void {
1168
1227
  const _private = BaseNode_getPrivate(this);
1169
-
1170
1228
  const h = (<ReferenceImpl>reference).hash;
1171
1229
  assert(typeof h === "string");
1172
1230
  // istanbul ignore next
1173
- if (_private._referenceIdx[h]) {
1231
+ if (_private._referenceIdx.has(h)) {
1174
1232
  // the reference exists already in the forward references
1175
1233
  // this append for instance when the XML NotSetFile has redundant <UAReference>
1176
1234
  // in this case there is nothing to do
1177
1235
  return;
1178
1236
  }
1179
1237
  // istanbul ignore next
1180
- if (_private._back_referenceIdx[h]) {
1238
+ if (_private._back_referenceIdx.has(h)) {
1181
1239
  const opts = { addressSpace: this.addressSpace };
1182
1240
  warningLog(" Warning !", this.browseName.toString());
1183
1241
  warningLog(" ", reference.toString(opts));
1184
1242
  warningLog(" already found in ===>");
1185
1243
  warningLog(
1186
- (Object.values(_private._back_referenceIdx) as UAReference[]).map((c: UAReference) => c.toString(opts)).join("\n")
1244
+ [..._private._back_referenceIdx.values()].map((c: UAReference) => c.toString(opts)).join("\n")
1187
1245
  );
1188
1246
  // tslint:disable-next-line:no-console
1189
1247
  warningLog("===>");
@@ -1194,7 +1252,7 @@ export function BaseNode_add_backward_reference(this: BaseNode, reference: UARef
1194
1252
  const stop_here = 1;
1195
1253
  }
1196
1254
  // assert(reference._referenceType instanceof ReferenceType);
1197
- _private._back_referenceIdx[h] = reference;
1255
+ _private._back_referenceIdx.set(h, reference);
1198
1256
  _handle_HierarchicalReference(this, reference);
1199
- (this as any)._clear_caches();
1257
+ BaseNode_clearCache(this);
1200
1258
  }
@@ -344,7 +344,9 @@ const validBasicNumericDataTypes = [
344
344
  DataType.Byte,
345
345
  DataType.Byte,
346
346
  DataType.SByte,
347
- 26 /*Number*/
347
+ 26, /* Number (abstract)*/
348
+ 27, /* Integer (abstract)*/
349
+ 28 /* UInteger (abstract)*/
348
350
  ];
349
351
  export function validateIsNumericDataType(dataTypeValue: any): void {
350
352
  if (typeof dataTypeValue !== "number" || validBasicNumericDataTypes.indexOf(dataTypeValue) < 0) {
@@ -232,7 +232,7 @@ export class NamespaceImpl implements NamespacePrivate {
232
232
  private _dataTypeMap: Map<string, UADataType>;
233
233
  private _referenceTypeMapInv: Map<string, UAReferenceType>;
234
234
  private _nodeIdManager: NodeIdManager;
235
- private _nodeid_index: Map<string | number, BaseNode>;
235
+ private _nodeid_index: Map<string | number| Buffer, BaseNode>;
236
236
  private _aliases: Map<string, NodeId>;
237
237
  private defaultAccessRestrictions?: AccessRestrictionsFlag;
238
238
  private defaultRolePermissions?: RolePermissionType[];
@@ -519,7 +519,7 @@ export class NamespaceImpl implements NamespacePrivate {
519
519
  const typeDefinition = options.typeDefinition || "BaseObjectType";
520
520
  options.references = options.references || [];
521
521
  options.references.push({ referenceType: "HasTypeDefinition", isForward: true, nodeId: typeDefinition });
522
- options.eventNotifier = +options.eventNotifier;
522
+ options.eventNotifier = +(options.eventNotifier || 0);
523
523
  const obj = this.createNode(options) as UAObject;
524
524
  assert(obj instanceof UAObjectImpl);
525
525
  assert(obj.nodeClass === NodeClass.Object);
@@ -537,6 +537,7 @@ export class NamespaceImpl implements NamespacePrivate {
537
537
  * @return {BaseNode}
538
538
  */
539
539
  public addFolder(parentFolder: UAObject, options: AddFolderOptions | string): UAObject {
540
+
540
541
  if (typeof options === "string") {
541
542
  options = { browseName: options };
542
543
  }
@@ -551,7 +552,7 @@ export class NamespaceImpl implements NamespacePrivate {
551
552
  { referenceType: "HasTypeDefinition", isForward: true, nodeId: typeDefinition },
552
553
  { referenceType: "Organizes", isForward: false, nodeId: parentFolder.nodeId }
553
554
  ];
554
- const node = this.createNode(options) as UAObject;
555
+ const node = this.createNode(options as CreateNodeOptions) as UAObject;
555
556
  return node;
556
557
  }
557
558
 
@@ -568,7 +569,7 @@ export class NamespaceImpl implements NamespacePrivate {
568
569
  const options1 = options as CreateNodeOptions;
569
570
  options1.nodeClass = NodeClass.ReferenceType;
570
571
  options1.references = options.references || [];
571
- options1.nodeId = options.nodeId;
572
+ options1.nodeId = options.nodeId!;
572
573
 
573
574
  if (options.subtypeOf) {
574
575
  const subtypeOfNodeId = addressSpace._coerceType(options.subtypeOf, "References", NodeClass.ReferenceType);
@@ -1716,7 +1717,7 @@ export class NamespaceImpl implements NamespacePrivate {
1716
1717
  // ? (options.browseName.namespaceIndex === this.index): true,
1717
1718
  // "Expecting browseName to have the same namespaceIndex as the namespace");
1718
1719
 
1719
- options.description = coerceLocalizedText(options.description);
1720
+ options.description = coerceLocalizedText(options.description)!;
1720
1721
 
1721
1722
  // browseName adjustment
1722
1723
  if (typeof options.browseName === "string") {
@@ -1759,21 +1760,23 @@ export class NamespaceImpl implements NamespacePrivate {
1759
1760
  // ------------- set display name
1760
1761
  if (!options.displayName) {
1761
1762
  assert(typeof options.browseName.name === "string");
1762
- options.displayName = options.browseName.name;
1763
+ options.displayName = coerceLocalizedText(options.browseName.name)!;
1764
+ }
1765
+ if (!options.nodeClass || options.nodeClass == undefined) {
1766
+ throw new Error("nodeclass must be specified");
1763
1767
  }
1764
-
1765
1768
  // --- nodeId adjustment
1766
- options.nodeId = this.constructNodeId(options);
1769
+ options.nodeId = this.constructNodeId(options as ConstructNodeIdOptions)
1767
1770
  dumpIf(!options.nodeId, options); // missing node Id
1768
1771
  assert(options.nodeId instanceof NodeId);
1769
1772
 
1770
1773
  // assert(options.browseName.namespaceIndex === this.index,"Expecting browseName to have
1771
1774
  // the same namespaceIndex as the namespace");
1772
1775
 
1773
- const Constructor = _constructors_map[NodeClass[options.nodeClass]];
1776
+ const Constructor = _constructors_map[NodeClass[options.nodeClass!]];
1774
1777
 
1775
1778
  if (!Constructor) {
1776
- throw new Error(" missing constructor for NodeClass " + NodeClass[options.nodeClass]);
1779
+ throw new Error(" missing constructor for NodeClass " + NodeClass[options.nodeClass!]);
1777
1780
  }
1778
1781
 
1779
1782
  options.addressSpace = this.addressSpace;
@@ -1863,7 +1866,7 @@ export class NamespaceImpl implements NamespacePrivate {
1863
1866
  browseName: options.browseName,
1864
1867
  displayName: options.displayName,
1865
1868
  description: options.description,
1866
- eventNotifier: +options.eventNotifier,
1869
+ eventNotifier: +(options.eventNotifier || 0),
1867
1870
  isAbstract: !!options.isAbstract,
1868
1871
  nodeClass,
1869
1872
  nodeId: options.nodeId,
@@ -1874,7 +1877,9 @@ export class NamespaceImpl implements NamespacePrivate {
1874
1877
 
1875
1878
  objectType.install_extra_properties();
1876
1879
 
1877
- (<BaseNodeImpl>objectType).installPostInstallFunc(options.postInstantiateFunc);
1880
+ if (options.postInstantiateFunc) {
1881
+ (<BaseNodeImpl>objectType).installPostInstallFunc(options.postInstantiateFunc);
1882
+ }
1878
1883
  return objectType;
1879
1884
  }
1880
1885
 
@@ -1981,7 +1986,7 @@ export class NamespaceImpl implements NamespacePrivate {
1981
1986
  assert(typeof options.valueRank === "number" && isFinite(options.valueRank!));
1982
1987
 
1983
1988
  options.arrayDimensions = options.arrayDimensions || null;
1984
- assert(Array.isArray(options.arrayDimensions) || options.arrayDimensions === null);
1989
+ assert(options.arrayDimensions === null || Array.isArray(options.arrayDimensions));
1985
1990
 
1986
1991
  // -----------------------------------------------------
1987
1992
  const hasGetter = (options: AddVariableOptions2) => {
@@ -2024,7 +2029,7 @@ export class NamespaceImpl implements NamespacePrivate {
2024
2029
 
2025
2030
  options.references = references;
2026
2031
 
2027
- const variable = this.createNode(options) as UAVariable;
2032
+ const variable = this.createNode(options as CreateNodeOptions) as UAVariable;
2028
2033
  return variable;
2029
2034
  }
2030
2035
 
@@ -2083,7 +2088,7 @@ const _constructors_map: any = {
2083
2088
  */
2084
2089
  function _coerce_parent(
2085
2090
  addressSpace: AddressSpacePrivate,
2086
- value: null | string | BaseNode,
2091
+ value: null | string | BaseNode| undefined | NodeIdLike,
2087
2092
  coerceFunc: (data: string | NodeId | BaseNode) => BaseNode | null
2088
2093
  ): BaseNode | null {
2089
2094
  assert(typeof coerceFunc === "function");
@@ -2199,7 +2204,7 @@ export function _handle_hierarchy_parent(addressSpace: AddressSpacePrivate, refe
2199
2204
  }
2200
2205
  }
2201
2206
 
2202
- function _copy_reference(reference: UAReference): AddReferenceOpts {
2207
+ function _copy_reference(reference: UAReference | AddReferenceOpts): AddReferenceOpts {
2203
2208
  assert(Object.prototype.hasOwnProperty.call(reference, "referenceType"));
2204
2209
  assert(Object.prototype.hasOwnProperty.call(reference, "isForward"));
2205
2210
  assert(Object.prototype.hasOwnProperty.call(reference, "nodeId"));
@@ -2211,12 +2216,12 @@ function _copy_reference(reference: UAReference): AddReferenceOpts {
2211
2216
  };
2212
2217
  }
2213
2218
 
2214
- function _copy_references(references?: UAReference[] | null): AddReferenceOpts[] {
2219
+ function _copy_references(references?: UAReference[] | AddReferenceOpts[] | null): AddReferenceOpts[] {
2215
2220
  references = references || [];
2216
2221
  return references.map(_copy_reference);
2217
2222
  }
2218
2223
 
2219
- export function isNonEmptyQualifiedName(browseName?: null | string | QualifiedName): boolean {
2224
+ export function isNonEmptyQualifiedName(browseName: QualifiedNameLike): boolean {
2220
2225
  if (!browseName) {
2221
2226
  return false;
2222
2227
  }
@@ -2230,12 +2235,12 @@ export function isNonEmptyQualifiedName(browseName?: null | string | QualifiedNa
2230
2235
  return browseName.name!.length > 0;
2231
2236
  }
2232
2237
 
2233
- function _create_node_version_if_needed(node: BaseNode, options: { nodeVersion: boolean }) {
2238
+ function _create_node_version_if_needed(node: BaseNode, options: { nodeVersion?: string }) {
2234
2239
  assert(options);
2235
- if (options.nodeVersion) {
2240
+ if (typeof options.nodeVersion == "string") {
2236
2241
  assert(node.nodeClass === NodeClass.Variable || node.nodeClass === NodeClass.Object);
2237
2242
  // istanbul ignore next
2238
- if (node.getChildByName("NodeVersion")) {
2243
+ if (node.getNodeVersion()) {
2239
2244
  return; // already exists
2240
2245
  }
2241
2246
 
@@ -2245,7 +2250,6 @@ function _create_node_version_if_needed(node: BaseNode, options: { nodeVersion:
2245
2250
  dataType: DataType.String,
2246
2251
  propertyOf: node
2247
2252
  });
2248
-
2249
2253
  const initialValue = typeof options.nodeVersion === "string" ? options.nodeVersion : "0";
2250
2254
  nodeVersion.setValueFromSource({ dataType: "String", value: initialValue });
2251
2255
  }
@@ -61,7 +61,10 @@ function isValidModellingRule(ruleName: string) {
61
61
  * @param modellingRule
62
62
  * @private
63
63
  */
64
- export function UANamespace_process_modelling_rule(references: AddReferenceOpts[], modellingRule: ModellingRuleType): void {
64
+ export function UANamespace_process_modelling_rule(
65
+ references: AddReferenceOpts[],
66
+ modellingRule?: ModellingRuleType
67
+ ): void {
65
68
  if (modellingRule) {
66
69
  assert(isValidModellingRule(modellingRule), "expecting a valid modelling rule");
67
70
  const modellingRuleName = "ModellingRule_" + modellingRule;