node-opcua-address-space 2.60.0 → 2.61.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 (34) hide show
  1. package/dist/source/helpers/multiform_func.d.ts +11 -0
  2. package/dist/source/helpers/multiform_func.js +74 -0
  3. package/dist/source/helpers/multiform_func.js.map +1 -0
  4. package/dist/src/address_space.js +4 -1
  5. package/dist/src/address_space.js.map +1 -1
  6. package/dist/src/base_node_impl.js +2 -0
  7. package/dist/src/base_node_impl.js.map +1 -1
  8. package/dist/src/base_node_private.d.ts +3 -3
  9. package/dist/src/base_node_private.js +196 -23
  10. package/dist/src/base_node_private.js.map +1 -1
  11. package/dist/src/ua_method_impl.js +2 -1
  12. package/dist/src/ua_method_impl.js.map +1 -1
  13. package/dist/src/ua_object_impl.js +2 -1
  14. package/dist/src/ua_object_impl.js.map +1 -1
  15. package/dist/src/ua_variable_impl.d.ts +6 -12
  16. package/dist/src/ua_variable_impl.js +58 -36
  17. package/dist/src/ua_variable_impl.js.map +1 -1
  18. package/dist/src/ua_variable_type_impl.js +47 -34
  19. package/dist/src/ua_variable_type_impl.js.map +1 -1
  20. package/dist/src/ua_view_impl.js +1 -1
  21. package/dist/src/ua_view_impl.js.map +1 -1
  22. package/package.json +30 -30
  23. package/source/helpers/multiform_func.ts +76 -0
  24. package/src/address_space.ts +11 -8
  25. package/src/base_node_impl.ts +3 -1
  26. package/src/base_node_private.ts +276 -34
  27. package/src/ua_method_impl.ts +10 -2
  28. package/src/ua_object_impl.ts +10 -2
  29. package/src/ua_variable_impl.ts +153 -131
  30. package/src/ua_variable_type_impl.ts +79 -39
  31. package/src/ua_view_impl.ts +1 -1
  32. package/test_helpers/test_fixtures/fixture_simple_statemachine_nodeset2.xml +9 -0
  33. package/test_helpers/test_fixtures/fixuture_nodeset_objects_with_some_methods.xml +9 -1
  34. package/test_helpers/test_fixtures/mini.Node.Set2.xml +8 -1
@@ -21,10 +21,10 @@ import {
21
21
  UAVariableType,
22
22
  CloneFilter
23
23
  } from "node-opcua-address-space-base";
24
- import { ReferenceTypeIds } from "node-opcua-constants";
24
+ import { ObjectTypeIds, ReferenceTypeIds, VariableTypeIds } from "node-opcua-constants";
25
25
  import { coerceQualifiedName, NodeClass, QualifiedName, BrowseDirection, AttributeIds } from "node-opcua-data-model";
26
26
  import { DataValue, DataValueLike } from "node-opcua-data-value";
27
- import { checkDebugFlag, make_debugLog, make_warningLog } from "node-opcua-debug";
27
+ import { checkDebugFlag, make_debugLog, make_warningLog, make_errorLog } from "node-opcua-debug";
28
28
  import { coerceNodeId, makeNodeId, NodeId, NodeIdLike, sameNodeId } from "node-opcua-nodeid";
29
29
  import { StatusCodes } from "node-opcua-status-code";
30
30
  import { UInt32 } from "node-opcua-basic-types";
@@ -40,10 +40,16 @@ import { _clone_children_references, ToStringBuilder, UAVariableType_toString }
40
40
  import * as tools from "./tool_isSupertypeOf";
41
41
  import { get_subtypeOfObj } from "./tool_isSupertypeOf";
42
42
  import { get_subtypeOf } from "./tool_isSupertypeOf";
43
+ import { resolveReferenceNode } from "./reference_impl";
43
44
 
44
45
  const debugLog = make_debugLog(__filename);
45
46
  const doDebug = checkDebugFlag(__filename);
46
47
  const warningLog = make_warningLog(__filename);
48
+ const errorLog = make_errorLog(__filename);
49
+
50
+ // eslint-disable-next-line prefer-const
51
+ let doTrace = false;
52
+ const traceLog = errorLog;
47
53
 
48
54
  interface InstantiateS {
49
55
  propertyOf?: any;
@@ -125,7 +131,6 @@ export class UAVariableTypeImpl extends BaseNodeImpl implements UAVariableType {
125
131
 
126
132
  if (options.value) {
127
133
  this.value = new Variant(options.value);
128
- // xx console.log("setting ",this.value.toString());
129
134
  }
130
135
  }
131
136
 
@@ -303,7 +308,7 @@ class MandatoryChildOrRequestedOptionalFilter implements CloneFilter {
303
308
  const n = addressSpace.findNode(r.nodeId)!;
304
309
  // istanbul ignore next
305
310
  if (!n) {
306
- console.log(" cannot find node ", r.nodeId.toString());
311
+ warningLog(" cannot find node ", r.nodeId.toString());
307
312
  return false;
308
313
  }
309
314
  return n.browseName!.name!.toString() === node.browseName!.name!.toString();
@@ -321,7 +326,24 @@ class MandatoryChildOrRequestedOptionalFilter implements CloneFilter {
321
326
  switch (modellingRule) {
322
327
  case null:
323
328
  case undefined:
324
- return false; // skip
329
+ debugLog(
330
+ "node ",
331
+ node.browseName.toString(),
332
+ node.nodeId.toString(),
333
+ " has no modellingRule ",
334
+ node.parentNodeId?.toString()
335
+ );
336
+ /**
337
+ * in some badly generated NodeSet2.xml file, the modellingRule is not specified
338
+ *
339
+ * but in some other NodeSet2.xml, this means that the data are only attached to the Type node and shall not be
340
+ * instantiate in the corresponding instance (example is the state variable of a finite state machine that are only
341
+ * defined in the Type node)
342
+ *
343
+ * we should not consider it as an error, and treat it as not present
344
+ */
345
+ return false;
346
+
325
347
  case "Mandatory":
326
348
  return true; // keep;
327
349
  case "Optional":
@@ -364,11 +386,11 @@ function _get_parent_as_VariableOrObjectType(originalObject: BaseNode): UAVariab
364
386
 
365
387
  // istanbul ignore next
366
388
  if (parents.length > 1) {
367
- console.warn(" object ", originalObject.browseName.toString(), " has more than one parent !");
368
- console.warn(originalObject.toString());
369
- console.warn(" parents : ");
389
+ warningLog(" object ", originalObject.browseName.toString(), " has more than one parent !");
390
+ warningLog(originalObject.toString());
391
+ warningLog(" parents : ");
370
392
  for (const parent of parents) {
371
- console.log(" ", parent.toString(), addressSpace.findNode(parent.nodeId)!.browseName.toString());
393
+ warningLog(" ", parent.toString(), addressSpace.findNode(parent.nodeId)!.browseName.toString());
372
394
  }
373
395
  return null;
374
396
  }
@@ -389,8 +411,12 @@ interface CloneInfo {
389
411
  original: UAVariableType | UAObjectType;
390
412
  }
391
413
  class CloneHelper {
414
+ public level = 0;
392
415
  private readonly mapOrgToClone: Map<string, CloneInfo> = new Map();
393
416
 
417
+ public pad(): string {
418
+ return " ".padEnd(this.level * 2, " ");
419
+ }
394
420
  public registerClonedObject<TT extends UAVariableType | UAObjectType, T extends UAObject | UAVariable | UAMethod>(
395
421
  objInType: TT,
396
422
  clonedObj: T
@@ -433,7 +459,6 @@ class CloneHelper {
433
459
  // find subTypeOf
434
460
  }
435
461
  }
436
-
437
462
  // install properties and components on a instantiated Object
438
463
  //
439
464
  // based on their ModelingRule
@@ -446,39 +471,66 @@ class CloneHelper {
446
471
  function _initialize_properties_and_components<B extends UAObject | UAVariable | UAMethod, T extends UAObjectType | UAVariableType>(
447
472
  instance: B,
448
473
  topMostType: T,
449
- typeNode: T,
474
+ typeDefinitionNode: T,
450
475
  copyAlsoModellingRules: boolean,
451
476
  optionalsMap: OptionalMap,
452
477
  extraInfo: CloneHelper
453
478
  ) {
454
479
  if (doDebug) {
455
- console.log("instance browseName =", instance.browseName.toString());
456
- console.log("typeNode =", typeNode.browseName.toString());
457
- console.log("optionalsMap =", Object.keys(optionalsMap).join(" "));
480
+ debugLog("instance browseName =", instance.browseName.toString());
481
+ debugLog("typeNode =", typeDefinitionNode.browseName.toString());
482
+ debugLog("optionalsMap =", Object.keys(optionalsMap).join(" "));
458
483
 
459
- const c = typeNode.findReferencesEx("Aggregates");
460
- console.log("type possibilities =", c.map((x) => x.node!.browseName.toString()).join(" "));
484
+ const c = typeDefinitionNode.findReferencesEx("Aggregates");
485
+ debugLog("typeDefinition aggregates =", c.map((x) => x.node!.browseName.toString()).join(" "));
461
486
  }
462
487
  optionalsMap = optionalsMap || {};
463
488
 
464
- if (sameNodeId(topMostType.nodeId, typeNode.nodeId)) {
489
+ if (sameNodeId(topMostType.nodeId, typeDefinitionNode.nodeId)) {
465
490
  return; // nothing to do
466
491
  }
467
492
 
468
- const baseTypeNodeId = typeNode.subtypeOf;
469
- const baseType = typeNode.subtypeOfObj;
493
+ const filter = new MandatoryChildOrRequestedOptionalFilter(instance, optionalsMap);
470
494
 
471
- // istanbul ignore next
472
- if (!baseType) {
473
- throw new Error(chalk.red("Cannot find object with nodeId ") + baseTypeNodeId);
474
- }
495
+ doTrace &&
496
+ traceLog(
497
+ chalk.cyan(extraInfo.pad(), "cloning relevant member of typeDefinition class"),
498
+ typeDefinitionNode.browseName.toString()
499
+ );
475
500
 
476
- const filter = new MandatoryChildOrRequestedOptionalFilter(instance, optionalsMap);
501
+ const browseNameMap = new Set<string>();
477
502
 
478
- _clone_children_references(typeNode, instance, copyAlsoModellingRules, filter, extraInfo);
503
+ _clone_children_references(typeDefinitionNode, instance, copyAlsoModellingRules, filter, extraInfo, browseNameMap);
504
+
505
+ // now apply recursion on baseTypeDefinition to get properties and components from base class
506
+
507
+ const baseTypeDefinitionNodeId = typeDefinitionNode.subtypeOf;
508
+ const baseTypeDefinition = typeDefinitionNode.subtypeOfObj!;
509
+
510
+ doTrace &&
511
+ traceLog(
512
+ chalk.cyan(
513
+ extraInfo.pad(),
514
+ "now apply recursion on baseTypeDefinition to get properties and components from base class"
515
+ ),
516
+ baseTypeDefinition.browseName.toString()
517
+ );
518
+
519
+ // istanbul ignore next
520
+ if (!baseTypeDefinition) {
521
+ throw new Error(chalk.red("Cannot find object with nodeId ") + baseTypeDefinitionNodeId);
522
+ }
523
+ extraInfo.level++;
524
+ _initialize_properties_and_components(
525
+ instance,
526
+ topMostType,
527
+ baseTypeDefinition,
528
+ copyAlsoModellingRules,
529
+ optionalsMap,
530
+ extraInfo
531
+ );
532
+ extraInfo.level--;
479
533
 
480
- // get properties and components from base class
481
- _initialize_properties_and_components(instance, topMostType, baseType, copyAlsoModellingRules, optionalsMap, extraInfo);
482
534
  }
483
535
 
484
536
  /**
@@ -589,8 +641,6 @@ function findNonHierarchicalReferences(originalObject: BaseNode): UAReference[]
589
641
 
590
642
  if (child) {
591
643
  const baseRef = findNonHierarchicalReferences(child);
592
- // xx console.log(" ... ",originalObject.browseName.toString(),
593
- // parent.browseName.toString(), references.length, baseRef.length);
594
644
  references = ([] as UAReference[]).concat(references, baseRef);
595
645
  }
596
646
  }
@@ -685,15 +735,6 @@ function reconstructFunctionalGroupType(extraInfo: any) {
685
735
  for (const { original, cloned } of extraInfo.mapOrgToClone.values()) {
686
736
  const organizedByArray = original.findReferencesEx("Organizes", BrowseDirection.Inverse);
687
737
 
688
- // function dumpRef(r) {
689
- // var referenceTd = addressSpace.findNode(r.referenceTypeId);
690
- // var obj = addressSpace.findNode(r.nodeId);
691
- // return "<-- " + referenceTd.browseName.toString() + " -- " + obj.browseName.toString();
692
- // }
693
- //
694
- // console.log("xxxxx ========================================================",
695
- // originalObject.browseName.toString(),
696
- // organizedByArray.map(dumpRef).join("\n"));
697
738
  for (const ref of organizedByArray) {
698
739
  const info = extraInfo.mapOrgToClone.get(ref.nodeId.toString());
699
740
  if (!info) continue;
@@ -712,7 +753,6 @@ function reconstructFunctionalGroupType(extraInfo: any) {
712
753
  nodeId: cloned.nodeId,
713
754
  referenceType: ref.referenceType
714
755
  });
715
- // xx console.log("xxx ============> adding reference ",ref.browse )
716
756
  }
717
757
  }
718
758
  }
@@ -34,7 +34,7 @@ export class UAViewImpl extends BaseNodeImpl implements UAView {
34
34
 
35
35
  switch (attributeId) {
36
36
  case AttributeIds.EventNotifier:
37
- options.value = { dataType: DataType.UInt32, value: this.eventNotifier };
37
+ options.value = { dataType: DataType.Byte, value: this.eventNotifier };
38
38
  options.statusCode = StatusCodes.Good;
39
39
  break;
40
40
 
@@ -240,6 +240,15 @@
240
240
  </References>
241
241
  <InverseName>EncodingOf</InverseName>
242
242
  </UAReferenceType>
243
+ <UAReferenceType NodeId="i=17603" BrowseName="HasInterface">
244
+ <DisplayName>HasInterface</DisplayName>
245
+ <Documentation>https://reference.opcfoundation.org/v104/Core/docs/Amendment7/11.20</Documentation>
246
+ <References>
247
+ <Reference ReferenceType="HasSubtype" IsForward="false">i=32</Reference>
248
+ </References>
249
+ <InverseName>InterfaceOf</InverseName>
250
+ </UAReferenceType>
251
+
243
252
  <UAObjectType NodeId="i=58" BrowseName="BaseObjectType">
244
253
  <DisplayName>BaseObjectType</DisplayName>
245
254
  <Description>The base type for all object nodes.</Description>
@@ -357,6 +357,14 @@
357
357
  <Reference ReferenceType="HasSubtype" IsForward="false">i=58</Reference>
358
358
  </References>
359
359
  </UAObjectType>
360
-
360
+
361
+ <UAReferenceType NodeId="i=38" BrowseName="HasEncoding">
362
+ <DisplayName>HasEncoding</DisplayName>
363
+ <Documentation>https://reference.opcfoundation.org/v104/Core/docs/Part5/11.13</Documentation>
364
+ <References>
365
+ <Reference ReferenceType="HasSubtype" IsForward="false">i=32</Reference>
366
+ </References>
367
+ <InverseName>EncodingOf</InverseName>
368
+ </UAReferenceType>
361
369
 
362
370
  </UANodeSet>
@@ -442,7 +442,14 @@
442
442
  </References>
443
443
  <InverseName>HistoricalConfigurationOf</InverseName>
444
444
  </UAReferenceType>
445
-
445
+ <UAReferenceType NodeId="i=17603" BrowseName="HasInterface">
446
+ <DisplayName>HasInterface</DisplayName>
447
+ <Documentation>https://reference.opcfoundation.org/v104/Core/docs/Amendment7/11.20</Documentation>
448
+ <References>
449
+ <Reference ReferenceType="HasSubtype" IsForward="false">i=32</Reference>
450
+ </References>
451
+ <InverseName>InterfaceOf</InverseName>
452
+ </UAReferenceType>
446
453
 
447
454
 
448
455
  <UAObjectType NodeId="i=75" BrowseName="DataTypeSystemType">