node-opcua-address-space 2.168.0 → 2.170.1

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 (69) hide show
  1. package/dist/source/loader/namespace_post_step.js +25 -17
  2. package/dist/source/loader/namespace_post_step.js.map +1 -1
  3. package/dist/source/session_context.d.ts +3 -1
  4. package/dist/source/session_context.js +26 -1
  5. package/dist/source/session_context.js.map +1 -1
  6. package/dist/source/ua_interface.d.ts +2 -3
  7. package/dist/source/ua_interface.js +10 -33
  8. package/dist/source/ua_interface.js.map +1 -1
  9. package/dist/src/_instantiate_helpers.d.ts +1 -1
  10. package/dist/src/_instantiate_helpers.js +32 -9
  11. package/dist/src/_instantiate_helpers.js.map +1 -1
  12. package/dist/src/_mandatory_child_or_requested_optional_filter.js +3 -3
  13. package/dist/src/_mandatory_child_or_requested_optional_filter.js.map +1 -1
  14. package/dist/src/address_space.d.ts +15 -12
  15. package/dist/src/address_space.js +63 -64
  16. package/dist/src/address_space.js.map +1 -1
  17. package/dist/src/alarms_and_conditions/condition_snapshot_impl.js +1 -1
  18. package/dist/src/alarms_and_conditions/condition_snapshot_impl.js.map +1 -1
  19. package/dist/src/alarms_and_conditions/ua_condition_impl.js +1 -1
  20. package/dist/src/alarms_and_conditions/ua_condition_impl.js.map +1 -1
  21. package/dist/src/base_node_impl.d.ts +1 -0
  22. package/dist/src/base_node_impl.js +11 -0
  23. package/dist/src/base_node_impl.js.map +1 -1
  24. package/dist/src/base_node_private.d.ts +10 -7
  25. package/dist/src/base_node_private.js +74 -50
  26. package/dist/src/base_node_private.js.map +1 -1
  27. package/dist/src/check_value_rank_compatibility.js +1 -1
  28. package/dist/src/check_value_rank_compatibility.js.map +1 -1
  29. package/dist/src/event_data.d.ts +8 -21
  30. package/dist/src/event_data.js +24 -19
  31. package/dist/src/event_data.js.map +1 -1
  32. package/dist/src/namespace_impl.d.ts +2 -0
  33. package/dist/src/namespace_impl.js +13 -0
  34. package/dist/src/namespace_impl.js.map +1 -1
  35. package/dist/src/ua_method_impl.d.ts +11 -9
  36. package/dist/src/ua_method_impl.js +24 -27
  37. package/dist/src/ua_method_impl.js.map +1 -1
  38. package/dist/src/ua_object_impl.d.ts +6 -5
  39. package/dist/src/ua_object_impl.js +30 -4
  40. package/dist/src/ua_object_impl.js.map +1 -1
  41. package/dist/src/ua_object_type_impl.js +2 -2
  42. package/dist/src/ua_object_type_impl.js.map +1 -1
  43. package/dist/src/ua_variable_impl.d.ts +1 -0
  44. package/dist/src/ua_variable_impl.js +79 -1
  45. package/dist/src/ua_variable_impl.js.map +1 -1
  46. package/dist/tsconfig_base.tsbuildinfo +1 -1
  47. package/distHelpers/get_address_space_fixture.js +14 -14
  48. package/distHelpers/get_address_space_fixture.js.map +1 -1
  49. package/distHelpers/index.d.ts +2 -2
  50. package/distHelpers/index.js +2 -2
  51. package/distHelpers/index.js.map +1 -1
  52. package/package.json +34 -34
  53. package/source/loader/namespace_post_step.ts +28 -19
  54. package/source/session_context.ts +30 -1
  55. package/source/ua_interface.ts +24 -38
  56. package/src/_instantiate_helpers.ts +67 -24
  57. package/src/_mandatory_child_or_requested_optional_filter.ts +5 -5
  58. package/src/address_space.ts +127 -124
  59. package/src/alarms_and_conditions/condition_snapshot_impl.ts +3 -3
  60. package/src/alarms_and_conditions/ua_condition_impl.ts +1 -1
  61. package/src/base_node_impl.ts +13 -0
  62. package/src/base_node_private.ts +163 -139
  63. package/src/check_value_rank_compatibility.ts +1 -1
  64. package/src/event_data.ts +57 -54
  65. package/src/namespace_impl.ts +16 -0
  66. package/src/ua_method_impl.ts +43 -50
  67. package/src/ua_object_impl.ts +51 -22
  68. package/src/ua_object_type_impl.ts +3 -3
  69. package/src/ua_variable_impl.ts +79 -2
@@ -7,33 +7,33 @@ exports.getAddressSpaceFixture = getAddressSpaceFixture;
7
7
  /**
8
8
  * @module node-opcua-address-space
9
9
  */
10
- const fs_1 = __importDefault(require("fs"));
11
- const path_1 = __importDefault(require("path"));
10
+ const node_fs_1 = __importDefault(require("node:fs"));
11
+ const node_path_1 = __importDefault(require("node:path"));
12
12
  function getAddressSpaceFixture(pathname) {
13
13
  // find in nodesets folder in the first place
14
- const folder1 = path_1.default.join(__dirname, "../nodesets");
15
- if (fs_1.default.existsSync(folder1)) {
16
- const filename = path_1.default.join(folder1, pathname);
17
- if (fs_1.default.existsSync(filename)) {
14
+ const folder1 = node_path_1.default.join(__dirname, "../nodesets");
15
+ if (node_fs_1.default.existsSync(folder1)) {
16
+ const filename = node_path_1.default.join(folder1, pathname);
17
+ if (node_fs_1.default.existsSync(filename)) {
18
18
  return filename;
19
19
  }
20
20
  }
21
21
  // find in test_fixtures seconds
22
- let folder = path_1.default.join(__dirname, "./test_fixtures");
23
- if (!fs_1.default.existsSync(folder)) {
24
- folder = path_1.default.join(__dirname, "../test_helpers/test_fixtures");
25
- if (!fs_1.default.existsSync(folder)) {
26
- folder = path_1.default.join(__dirname, "../../test_helpers/test_fixtures");
22
+ let folder = node_path_1.default.join(__dirname, "./test_fixtures");
23
+ if (!node_fs_1.default.existsSync(folder)) {
24
+ folder = node_path_1.default.join(__dirname, "../test_helpers/test_fixtures");
25
+ if (!node_fs_1.default.existsSync(folder)) {
26
+ folder = node_path_1.default.join(__dirname, "../../test_helpers/test_fixtures");
27
27
  // c8 ignore next
28
- if (!fs_1.default.existsSync(folder)) {
28
+ if (!node_fs_1.default.existsSync(folder)) {
29
29
  // tslint:disable:no-console
30
30
  console.log(" cannot find test_fixtures folder ");
31
31
  }
32
32
  }
33
33
  }
34
- const filename = path_1.default.join(folder, pathname);
34
+ const filename = node_path_1.default.join(folder, pathname);
35
35
  // c8 ignore next
36
- if (!fs_1.default.existsSync(filename)) {
36
+ if (!node_fs_1.default.existsSync(filename)) {
37
37
  throw new Error(" cannot find fixture with name " + pathname);
38
38
  }
39
39
  return filename;
@@ -1 +1 @@
1
- {"version":3,"file":"get_address_space_fixture.js","sourceRoot":"","sources":["../test_helpers/get_address_space_fixture.ts"],"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CAAC,CAAC;IAE7C,iBAAiB;IACjB,IAAI,CAAC,iBAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,iCAAiC,GAAG,QAAQ,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,QAAQ,CAAC;AACpB,CAAC"}
@@ -4,9 +4,9 @@
4
4
  export * from "./add_event_generator_object";
5
5
  export * from "./alarms_and_conditions_demo";
6
6
  export * from "./assertHasMatchingReference";
7
+ export * from "./boiler_system";
7
8
  export * from "./create_minimalist_address_space_nodeset";
9
+ export * from "./date_utils";
8
10
  export * from "./get_address_space_fixture";
9
11
  export * from "./get_mini_address_space";
10
- export * from "./boiler_system";
11
12
  export * from "./mock_session";
12
- export * from "./date_utils";
@@ -20,10 +20,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
20
20
  __exportStar(require("./add_event_generator_object"), exports);
21
21
  __exportStar(require("./alarms_and_conditions_demo"), exports);
22
22
  __exportStar(require("./assertHasMatchingReference"), exports);
23
+ __exportStar(require("./boiler_system"), exports);
23
24
  __exportStar(require("./create_minimalist_address_space_nodeset"), exports);
25
+ __exportStar(require("./date_utils"), exports);
24
26
  __exportStar(require("./get_address_space_fixture"), exports);
25
27
  __exportStar(require("./get_mini_address_space"), exports);
26
- __exportStar(require("./boiler_system"), exports);
27
28
  __exportStar(require("./mock_session"), exports);
28
- __exportStar(require("./date_utils"), exports);
29
29
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../test_helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,+DAA6C;AAC7C,+DAA6C;AAC7C,+DAA6C;AAC7C,4EAA0D;AAC1D,8DAA4C;AAC5C,2DAAyC;AACzC,kDAAgC;AAChC,iDAA+B;AAC/B,+CAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../test_helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,+DAA6C;AAC7C,+DAA6C;AAC7C,+DAA6C;AAC7C,kDAAgC;AAChC,4EAA0D;AAC1D,+CAA6B;AAC7B,8DAA4C;AAC5C,2DAAyC;AACzC,iDAA+B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-opcua-address-space",
3
- "version": "2.168.0",
3
+ "version": "2.170.1",
4
4
  "description": "pure nodejs OPCUA SDK - module address-space",
5
5
  "main": "./dist/src/index_current.js",
6
6
  "types": "./dist/source/index.d.ts",
@@ -21,48 +21,48 @@
21
21
  "@types/semver": "7.7.1",
22
22
  "chalk": "4.1.2",
23
23
  "dequeue": "^1.0.5",
24
- "node-opcua-address-space-base": "2.168.0",
24
+ "node-opcua-address-space-base": "2.170.1",
25
25
  "node-opcua-assert": "2.164.0",
26
- "node-opcua-basic-types": "2.168.0",
27
- "node-opcua-binary-stream": "2.168.0",
28
- "node-opcua-client-dynamic-extension-object": "2.168.0",
26
+ "node-opcua-basic-types": "2.169.0",
27
+ "node-opcua-binary-stream": "2.169.0",
28
+ "node-opcua-client-dynamic-extension-object": "2.170.1",
29
29
  "node-opcua-constants": "2.157.0",
30
- "node-opcua-crypto": "5.3.3",
31
- "node-opcua-data-access": "2.168.0",
32
- "node-opcua-data-model": "2.168.0",
33
- "node-opcua-data-value": "2.168.0",
34
- "node-opcua-date-time": "2.168.0",
30
+ "node-opcua-crypto": "5.3.5",
31
+ "node-opcua-data-access": "2.170.0",
32
+ "node-opcua-data-model": "2.170.0",
33
+ "node-opcua-data-value": "2.170.0",
34
+ "node-opcua-date-time": "2.169.0",
35
35
  "node-opcua-debug": "2.168.0",
36
- "node-opcua-enum": "2.168.0",
37
- "node-opcua-extension-object": "2.168.0",
38
- "node-opcua-factory": "2.168.0",
39
- "node-opcua-nodeid": "2.168.0",
40
- "node-opcua-nodeset-ua": "2.168.0",
41
- "node-opcua-numeric-range": "2.168.0",
42
- "node-opcua-object-registry": "2.168.0",
43
- "node-opcua-pseudo-session": "2.168.0",
44
- "node-opcua-service-browse": "2.168.0",
45
- "node-opcua-service-call": "2.168.0",
46
- "node-opcua-service-history": "2.168.0",
47
- "node-opcua-service-translate-browse-path": "2.168.0",
48
- "node-opcua-service-write": "2.168.0",
49
- "node-opcua-status-code": "2.168.0",
50
- "node-opcua-types": "2.168.0",
51
- "node-opcua-utils": "2.168.0",
52
- "node-opcua-variant": "2.168.0",
53
- "node-opcua-xml2json": "2.168.0",
36
+ "node-opcua-enum": "2.169.0",
37
+ "node-opcua-extension-object": "2.169.0",
38
+ "node-opcua-factory": "2.169.0",
39
+ "node-opcua-nodeid": "2.169.0",
40
+ "node-opcua-nodeset-ua": "2.170.1",
41
+ "node-opcua-numeric-range": "2.169.0",
42
+ "node-opcua-object-registry": "2.169.0",
43
+ "node-opcua-pseudo-session": "2.170.1",
44
+ "node-opcua-service-browse": "2.170.0",
45
+ "node-opcua-service-call": "2.170.0",
46
+ "node-opcua-service-history": "2.170.0",
47
+ "node-opcua-service-translate-browse-path": "2.170.0",
48
+ "node-opcua-service-write": "2.170.0",
49
+ "node-opcua-status-code": "2.169.0",
50
+ "node-opcua-types": "2.170.0",
51
+ "node-opcua-utils": "2.169.0",
52
+ "node-opcua-variant": "2.170.0",
53
+ "node-opcua-xml2json": "2.169.0",
54
54
  "semver": "^7.7.4",
55
55
  "thenify-ex": "4.4.0",
56
56
  "xml-writer": "^1.7.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "humanize": "0.0.9",
60
- "node-opcua-benchmarker": "2.168.0",
61
- "node-opcua-leak-detector": "2.168.0",
60
+ "node-opcua-benchmarker": "2.169.0",
61
+ "node-opcua-leak-detector": "2.169.0",
62
62
  "node-opcua-nodesets": "2.163.1",
63
- "node-opcua-packet-analyzer": "2.168.0",
64
- "node-opcua-schemas": "2.168.0",
65
- "node-opcua-service-filter": "2.168.0",
63
+ "node-opcua-packet-analyzer": "2.169.0",
64
+ "node-opcua-schemas": "2.170.0",
65
+ "node-opcua-service-filter": "2.170.1",
66
66
  "node-opcua-test-fixtures": "2.157.0"
67
67
  },
68
68
  "author": "Etienne Rossignon",
@@ -80,7 +80,7 @@
80
80
  "internet of things"
81
81
  ],
82
82
  "homepage": "http://node-opcua.github.io/",
83
- "gitHead": "653b6d6df801ca17298308089dee32e5b12102b6",
83
+ "gitHead": "40629feaff284ba70596149e58b3cc2a7a0e8f68",
84
84
  "files": [
85
85
  "dist",
86
86
  "distHelpers",
@@ -29,28 +29,37 @@ function parentIsObjectOrVariableType(node: UAVariable | UAObject): boolean {
29
29
 
30
30
  export async function promoteObjectAndVariablesInNamespace(namespace: INamespace): Promise<void> {
31
31
  const namespaceP = namespace as NamespacePrivate;
32
- for (const a of namespaceP.nodeIterator()) {
33
- if (a.nodeClass === NodeClass.Object || a.nodeClass === NodeClass.Variable) {
34
- // skip object & variable that belong to a ObjectType or VariableType
35
- const aa = a as UAObject | UAVariable;
36
-
37
- if (aa.typeDefinition) {
38
- const promoter = g_promotableObject.get(aa.typeDefinition.toString());
39
- if (promoter) {
40
- if (promoter.onInstanceOnly && parentIsObjectOrVariableType(aa)) {
41
- continue;
42
- }
43
- const before = a.constructor.name;
44
-
45
- promoter.promoter(a as any);
46
- const after = a.constructor.name;
47
- // c8 ignore next
48
- if (doDebug) {
49
- debugLog(`promoting ${a.browseName.toString()} from ${before} to ${after}`);
50
- }
32
+
33
+ const promoteNode = (a: UAObject | UAVariable) => {
34
+ if (a.typeDefinition) {
35
+ const promoter = g_promotableObject.get(a.typeDefinition.toString());
36
+ if (promoter) {
37
+ if (promoter.onInstanceOnly && parentIsObjectOrVariableType(a)) {
38
+ return;
39
+ }
40
+ const before = a.constructor.name;
41
+
42
+ promoter.promoter(a as any);
43
+ const after = a.constructor.name;
44
+ // c8 ignore next
45
+ if (doDebug) {
46
+ debugLog(`promoting ${a.browseName.toString()} from ${before} to ${after}`);
51
47
  }
52
48
  }
53
49
  }
50
+ };
51
+
52
+ // Promote variables first so that TwoStateVariables and other variable types
53
+ // are fully promoted before objects (like StateMachines or Alarms) that contain them.
54
+ for (const a of namespaceP.nodeIterator()) {
55
+ if (a.nodeClass === NodeClass.Variable) {
56
+ promoteNode(a as UAVariable);
57
+ }
58
+ }
59
+ for (const a of namespaceP.nodeIterator()) {
60
+ if (a.nodeClass === NodeClass.Object) {
61
+ promoteNode(a as UAObject);
62
+ }
54
63
  }
55
64
  }
56
65
  export async function promoteObjectsAndVariables(addressSpace: IAddressSpace): Promise<void> {
@@ -207,13 +207,13 @@ export function makeRoles(roleIds: NodeIdLike[] | string | WellKnownRoles): Node
207
207
  }
208
208
  return roleIds.map((r) => resolveNodeId(r));
209
209
  }
210
+
210
211
  export class SessionContext implements ISessionContext {
211
212
  public static defaultContext = new SessionContext({});
212
213
 
213
214
  public object: UAObject | UAObjectType | undefined;
214
215
  public currentTime?: PreciseClock;
215
216
  public continuationPoints: Buffer[] = [];
216
- public userIdentity?: string;
217
217
  public readonly session?: ISessionBase;
218
218
  public readonly server?: IServerBase;
219
219
 
@@ -252,6 +252,35 @@ export class SessionContext implements ISessionContext {
252
252
  }
253
253
  }
254
254
 
255
+ public toJSON(): Record<string, string | null> {
256
+ return {
257
+ userName: this.getUserName(),
258
+ clientApplicationUri: this.clientApplicationUri,
259
+ session: this.session ? this.session.getSessionId().toString() : null
260
+ };
261
+ }
262
+
263
+ public toString(): string {
264
+ if (this === SessionContext.defaultContext) {
265
+ return "SessionContext({ default })";
266
+ }
267
+ return `SessionContext({ userName: "${this.getUserName()}", session: ${this.session ? this.session.getSessionId().toString() : "none"} })`;
268
+ }
269
+
270
+ public [Symbol.for("nodejs.util.inspect.custom")](): string {
271
+ return this.toString();
272
+ }
273
+
274
+ public getUserName(): string {
275
+ if (!this.session) {
276
+ return "<unknown client user id>";
277
+ }
278
+ const userIdentityToken = this.session.userIdentityToken;
279
+ if (!userIdentityToken) {
280
+ return "<unknown client user id>";
281
+ }
282
+ return getUserName(userIdentityToken);
283
+ }
255
284
  /**
256
285
  * getCurrentUserRoles
257
286
  *
@@ -1,49 +1,35 @@
1
-
2
-
3
- import { UAObject, UAObjectType, UAVariable, UAVariableType } from "node-opcua-address-space-base";
4
- import { BrowseDirection } from "node-opcua-data-model";
1
+ import type { UAObject, UAObjectType, UAVariable, UAVariableType } from "node-opcua-address-space-base";
2
+ import { NodeClass } from "node-opcua-types";
5
3
  import { initialize_properties_and_components } from "../src/_instantiate_helpers";
6
4
 
7
- export function implementInterfaceBad(uaNode: UAObject | UAObjectType | UAVariable | UAVariableType, interfaceType: UAObjectType) {
5
+ export function implementInterface(
6
+ uaNode: UAObject | UAObjectType | UAVariable | UAVariableType,
7
+ interfaceType: UAObjectType,
8
+ optionals?: string[],
9
+ isModellingType?: boolean
10
+ ) {
8
11
 
9
- const addressSpace = uaNode.addressSpace;
10
- const tmp = interfaceType.instantiate({
11
- browseName: uaNode.browseName,
12
- copyAlsoModellingRules: true,
13
- copyAlsoAllOptionals: true,
14
- modellingRule: "Mandatory"
15
- });
16
- //
17
- uaNode.addReference({
18
- nodeId: interfaceType,
19
- referenceType: "HasInterface"
20
- });
21
- const childrenRef = tmp.findReferencesEx("HasChild", BrowseDirection.Forward);
22
- // transfer children to uaNode
23
- for (const childRef of childrenRef) {
12
+ optionals = optionals || [];
24
13
 
25
- tmp.removeReference({
26
- nodeId: childRef.nodeId,
27
- referenceType: childRef.referenceType,
28
- isForward: childRef.isForward
29
- });
30
- uaNode.addReference({
31
- nodeId: childRef.nodeId,
32
- referenceType: childRef.referenceType,
33
- isForward: childRef.isForward
34
- });
14
+ const addressSpace = uaNode.addressSpace;
15
+ const topMost = addressSpace.findObjectType("BaseInterfaceType");
16
+ if (!topMost) {
17
+ throw new Error("cannot find BaseInterfaceType");
35
18
  }
36
- addressSpace.deleteNode(tmp);
37
- }
38
19
 
39
- export function implementInterface(uaNode: UAObject | UAObjectType | UAVariable | UAVariableType, interfaceType: UAObjectType) {
40
-
41
- const addressSpace = uaNode.addressSpace;
42
- const topMost = addressSpace.findObjectType("BaseInterfaceType")!;
43
- initialize_properties_and_components(uaNode as any, topMost, interfaceType, true, true, []);
20
+ isModellingType = isModellingType === undefined ? uaNode.nodeClass === NodeClass.ObjectType || uaNode.nodeClass === NodeClass.VariableType : isModellingType;
21
+
22
+ const copyAlsoModellingRules = isModellingType;
23
+ const copyAlsoAllOptionals = isModellingType;
24
+ initialize_properties_and_components(
25
+ uaNode as UAObject | UAVariable,
26
+ topMost, interfaceType,
27
+ copyAlsoModellingRules,
28
+ copyAlsoAllOptionals,
29
+ optionals
30
+ );
44
31
  uaNode.addReference({
45
32
  nodeId: interfaceType,
46
33
  referenceType: "HasInterface"
47
34
  });
48
-
49
35
  }
@@ -4,33 +4,30 @@
4
4
  // tslint:disable:max-classes-per-file
5
5
  // tslint:disable:no-console
6
6
  import chalk from "chalk";
7
-
8
7
  import {
9
- UAMethod,
10
- UAObject,
11
- UAObjectType,
12
- UAVariable,
13
- UAVariableType,
8
+ CloneHelper,
14
9
  reconstructFunctionalGroupType,
15
10
  reconstructNonHierarchicalReferences,
16
- CloneHelper
11
+ type UAMethod,
12
+ type UAObject,
13
+ type UAObjectType,
14
+ type UAVariable,
15
+ type UAVariableType,
17
16
  } from "node-opcua-address-space-base";
18
-
19
- import { checkDebugFlag, make_debugLog, make_warningLog, make_errorLog } from "node-opcua-debug";
20
- import { sameNodeId } from "node-opcua-nodeid";
21
-
22
- import { makeOptionalsMap, OptionalMap } from "../source/helpers/make_optionals_map";
23
-
24
- import { _clone_hierarchical_references } from "./base_node_private";
17
+ import { checkDebugFlag, make_errorLog, make_warningLog} from "node-opcua-debug";
18
+ import { resolveNodeId, sameNodeId } from "node-opcua-nodeid";
19
+ import { makeOptionalsMap, type OptionalMap } from "../source/helpers/make_optionals_map";
25
20
  import { MandatoryChildOrRequestedOptionalFilter } from "./_mandatory_child_or_requested_optional_filter";
21
+ import { _clone_hierarchical_references } from "./base_node_private";
22
+ import { BrowseDirection } from "node-opcua-data-model";
26
23
 
27
- const debugLog = make_debugLog(__filename);
28
- const doDebug = checkDebugFlag(__filename);
29
- const warningLog = make_warningLog(__filename);
30
- const errorLog = make_errorLog(__filename);
24
+ // const debugLog = make_debugLog("INSTANTIATE");
25
+ // const doDebug = checkDebugFlag("INSTANTIATE");
26
+ const warningLog = make_warningLog("INSTANTIATE");
27
+ const errorLog = make_errorLog("INSTANTIATE");
31
28
 
32
29
  // eslint-disable-next-line prefer-const
33
- let doTrace = checkDebugFlag("INSTANTIATE");
30
+ const doTrace = checkDebugFlag("INSTANTIATE");
34
31
  const traceLog = errorLog;
35
32
 
36
33
  // install properties and components on a instantiated Object
@@ -58,7 +55,7 @@ function _initialize_properties_and_components<B extends UAObject | UAVariable |
58
55
  warningLog("optionalsMap =", Object.keys(optionalsMap).join(" "));
59
56
 
60
57
  const c = typeDefinitionNode.findReferencesEx("Aggregates");
61
- warningLog("typeDefinition aggregates =", c.map((x) => x.node!.browseName.toString()).join(" "));
58
+ warningLog("typeDefinition aggregates =", c.map((x) => x.node?.browseName.toString()).join(" "));
62
59
  }
63
60
  optionalsMap = optionalsMap || {};
64
61
 
@@ -71,7 +68,7 @@ function _initialize_properties_and_components<B extends UAObject | UAVariable |
71
68
  doTrace &&
72
69
  traceLog(
73
70
  chalk.cyan(extraInfo.pad(), "cloning relevant member of typeDefinition class"),
74
- typeDefinitionNode.browseName.toString()+ "\n optionals" + (JSON.stringify(optionalsMap))
71
+ `${typeDefinitionNode.browseName.toString()}\n optionals${JSON.stringify(optionalsMap)}`
75
72
  );
76
73
 
77
74
  _clone_hierarchical_references(typeDefinitionNode, instance, copyAlsoModellingRules, filter, extraInfo, browseNameMap);
@@ -79,7 +76,7 @@ function _initialize_properties_and_components<B extends UAObject | UAVariable |
79
76
  // now apply recursion on baseTypeDefinition to get properties and components from base class
80
77
 
81
78
  const baseTypeDefinitionNodeId = typeDefinitionNode.subtypeOf;
82
- const baseTypeDefinition = typeDefinitionNode.subtypeOfObj!;
79
+ const baseTypeDefinition = typeDefinitionNode.subtypeOfObj;
83
80
 
84
81
  doTrace &&
85
82
  traceLog(
@@ -87,9 +84,9 @@ function _initialize_properties_and_components<B extends UAObject | UAVariable |
87
84
  extraInfo.pad(),
88
85
  "now apply recursion on baseTypeDefinition to get properties and components from base class"
89
86
  ),
90
- baseTypeDefinition.browseName.toString()
87
+ baseTypeDefinition ? baseTypeDefinition.browseName.toString() : "undefined"
91
88
  );
92
-
89
+
93
90
  // c8 ignore next
94
91
  if (!baseTypeDefinition) {
95
92
  throw new Error(chalk.red("Cannot find object with nodeId ") + baseTypeDefinitionNodeId);
@@ -141,7 +138,53 @@ export function initialize_properties_and_components<
141
138
  browseNameMap
142
139
  );
143
140
 
141
+ // instantiate optionals from interfaces
142
+ instantiate_interface_children<B>(nodeType, extraInfo, instance, copyAlsoModellingRules, copyAlsoAllOptionals, optionalsMap, browseNameMap);
143
+
144
144
  reconstructFunctionalGroupType(extraInfo);
145
145
 
146
146
  reconstructNonHierarchicalReferences(extraInfo);
147
147
  }
148
+
149
+ function instantiate_interface_children<B extends UAObject | UAVariable | UAMethod>(
150
+ nodeType: UAObjectType | UAVariableType,
151
+ extraInfo: CloneHelper,
152
+ instance: B,
153
+ copyAlsoModellingRules: boolean,
154
+ copyAlsoAllOptionals: boolean,
155
+ optionalsMap: OptionalMap,
156
+ browseNameMap: Set<string>
157
+ ) {
158
+ const interfaces = nodeType.findReferencesEx(resolveNodeId("HasInterface"), BrowseDirection.Forward);
159
+ if (interfaces.length === 0) {
160
+ return;
161
+ }
162
+ for (const reference of interfaces) {
163
+ const interfaceType =
164
+ (reference.node as UAObjectType) || nodeType.addressSpace.findObjectType(reference.nodeId);
165
+ if (!interfaceType) {
166
+ warningLog(" cannot find node ", reference.nodeId.toString());
167
+ continue;
168
+ }
169
+ const topMostTypeBaseInterface = nodeType.addressSpace.findObjectType("BaseInterfaceType");
170
+ if (!topMostTypeBaseInterface) {
171
+ throw new Error("cannot find BaseInterfaceType");
172
+ }
173
+ doTrace &&
174
+ traceLog(
175
+ chalk.cyan(extraInfo.pad(), "instantiating optionals from interface"),
176
+ `${interfaceType.browseName.toString()}`
177
+ );
178
+ _initialize_properties_and_components(
179
+ instance,
180
+ topMostTypeBaseInterface,
181
+ interfaceType,
182
+ copyAlsoModellingRules,
183
+ copyAlsoAllOptionals,
184
+ optionalsMap,
185
+ extraInfo,
186
+ browseNameMap
187
+ );
188
+ }
189
+ }
190
+
@@ -32,13 +32,13 @@ export class MandatoryChildOrRequestedOptionalFilter implements CloneFilter {
32
32
  const addressSpace = node.addressSpace;
33
33
 
34
34
  const alreadyIn = this.references.filter((r: UAReference) => {
35
- const n = addressSpace.findNode(r.nodeId)!;
35
+ const n = addressSpace.findNode(r.nodeId);
36
36
  // c8 ignore next
37
37
  if (!n) {
38
38
  warningLog(" cannot find node ", r.nodeId.toString());
39
39
  return false;
40
40
  }
41
- return n.browseName!.name!.toString() === node.browseName!.name!.toString();
41
+ return n.browseName?.name?.toString() === node.browseName?.name?.toString();
42
42
  });
43
43
 
44
44
  if (alreadyIn.length > 0) {
@@ -76,7 +76,7 @@ export class MandatoryChildOrRequestedOptionalFilter implements CloneFilter {
76
76
  return true; // keep;
77
77
  case "Optional":
78
78
  // only if in requested optionals
79
- return this.copyAlsoAllOptionals || (node.browseName!.name! in this.optionalsMap);
79
+ return this.copyAlsoAllOptionals || ((node.browseName?.name || "") in this.optionalsMap);
80
80
  case "OptionalPlaceholder":
81
81
  return false; // ignored
82
82
  default:
@@ -85,12 +85,12 @@ export class MandatoryChildOrRequestedOptionalFilter implements CloneFilter {
85
85
  }
86
86
 
87
87
  public filterFor(childInstance: UAVariable | UAObject | UAMethod): CloneFilter {
88
- const browseName: string = childInstance.browseName.name!;
88
+ const browseName: string = childInstance.browseName.name || "";
89
89
 
90
90
  let map: OptionalMap = Object.create(null);
91
91
 
92
92
  if (browseName in this.optionalsMap) {
93
- map = this.optionalsMap[browseName] as any;
93
+ map = this.optionalsMap[browseName] as OptionalMap;
94
94
  }
95
95
  // c8 ignore next
96
96
  doTrace && traceLog("filterFor ", browseName, map);