node-opcua-address-space 2.57.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 (88) hide show
  1. package/dist/source/address_space_ts.d.ts +0 -2
  2. package/dist/source/helpers/argument_list.js +12 -1
  3. package/dist/source/helpers/argument_list.js.map +1 -1
  4. package/dist/source/helpers/multiform_func.d.ts +11 -0
  5. package/dist/source/helpers/multiform_func.js +74 -0
  6. package/dist/source/helpers/multiform_func.js.map +1 -0
  7. package/dist/source/loader/load_nodeset2.js +47 -64
  8. package/dist/source/loader/load_nodeset2.js.map +1 -1
  9. package/dist/source/set_namespace_meta_data.js +1 -1
  10. package/dist/src/address_space.js +12 -6
  11. package/dist/src/address_space.js.map +1 -1
  12. package/dist/src/alarms_and_conditions/condition_snapshot.js +3 -3
  13. package/dist/src/alarms_and_conditions/condition_snapshot.js.map +1 -1
  14. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js +2 -1
  15. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js.map +1 -1
  16. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js +1 -1
  17. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js.map +1 -1
  18. package/dist/src/alarms_and_conditions/ua_condition_impl.js +8 -6
  19. package/dist/src/alarms_and_conditions/ua_condition_impl.js.map +1 -1
  20. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js +1 -1
  21. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js.map +1 -1
  22. package/dist/src/base_node_impl.js +2 -0
  23. package/dist/src/base_node_impl.js.map +1 -1
  24. package/dist/src/base_node_private.d.ts +3 -3
  25. package/dist/src/base_node_private.js +198 -25
  26. package/dist/src/base_node_private.js.map +1 -1
  27. package/dist/src/event_data.js +1 -1
  28. package/dist/src/event_data.js.map +1 -1
  29. package/dist/src/namespace_impl.js +5 -5
  30. package/dist/src/namespace_impl.js.map +1 -1
  31. package/dist/src/nodeset_tools/nodeset_to_xml.js +15 -9
  32. package/dist/src/nodeset_tools/nodeset_to_xml.js.map +1 -1
  33. package/dist/src/nodeset_tools/typedictionary_to_xml.js +17 -10
  34. package/dist/src/nodeset_tools/typedictionary_to_xml.js.map +1 -1
  35. package/dist/src/reference_impl.js +1 -1
  36. package/dist/src/reference_impl.js.map +1 -1
  37. package/dist/src/state_machine/ua_shelving_state_machine_ex.js +20 -13
  38. package/dist/src/state_machine/ua_shelving_state_machine_ex.js.map +1 -1
  39. package/dist/src/ua_data_type_impl.d.ts +15 -5
  40. package/dist/src/ua_data_type_impl.js +129 -51
  41. package/dist/src/ua_data_type_impl.js.map +1 -1
  42. package/dist/src/ua_method_impl.d.ts +3 -2
  43. package/dist/src/ua_method_impl.js +7 -1
  44. package/dist/src/ua_method_impl.js.map +1 -1
  45. package/dist/src/ua_object_impl.js +2 -1
  46. package/dist/src/ua_object_impl.js.map +1 -1
  47. package/dist/src/ua_variable_impl.d.ts +12 -18
  48. package/dist/src/ua_variable_impl.js +285 -215
  49. package/dist/src/ua_variable_impl.js.map +1 -1
  50. package/dist/src/ua_variable_type_impl.d.ts +3 -4
  51. package/dist/src/ua_variable_type_impl.js +60 -52
  52. package/dist/src/ua_variable_type_impl.js.map +1 -1
  53. package/dist/src/ua_view_impl.js +1 -1
  54. package/dist/src/ua_view_impl.js.map +1 -1
  55. package/distHelpers/add_event_generator_object.js.map +1 -1
  56. package/distHelpers/mock_session.js +1 -1
  57. package/distHelpers/mock_session.js.map +1 -1
  58. package/package.json +35 -35
  59. package/source/address_space_ts.ts +0 -1
  60. package/source/helpers/argument_list.ts +13 -3
  61. package/source/helpers/multiform_func.ts +76 -0
  62. package/source/loader/load_nodeset2.ts +64 -80
  63. package/source/set_namespace_meta_data.ts +1 -1
  64. package/src/address_space.ts +16 -7
  65. package/src/alarms_and_conditions/condition_snapshot.ts +4 -4
  66. package/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.ts +7 -6
  67. package/src/alarms_and_conditions/ua_alarm_condition_impl.ts +2 -2
  68. package/src/alarms_and_conditions/ua_condition_impl.ts +29 -15
  69. package/src/alarms_and_conditions/ua_off_normal_alarm_impl.ts +1 -1
  70. package/src/base_node_impl.ts +3 -1
  71. package/src/base_node_private.ts +282 -36
  72. package/src/event_data.ts +1 -1
  73. package/src/namespace_impl.ts +6 -6
  74. package/src/nodeset_tools/nodeset_to_xml.ts +20 -10
  75. package/src/nodeset_tools/typedictionary_to_xml.ts +17 -7
  76. package/src/reference_impl.ts +3 -3
  77. package/src/state_machine/ua_shelving_state_machine_ex.ts +32 -19
  78. package/src/ua_data_type_impl.ts +168 -61
  79. package/src/ua_method_impl.ts +21 -7
  80. package/src/ua_object_impl.ts +10 -2
  81. package/src/ua_variable_impl.ts +419 -325
  82. package/src/ua_variable_type_impl.ts +86 -52
  83. package/src/ua_view_impl.ts +1 -1
  84. package/test_helpers/add_event_generator_object.ts +4 -3
  85. package/test_helpers/mock_session.ts +1 -1
  86. package/test_helpers/test_fixtures/fixture_simple_statemachine_nodeset2.xml +18 -0
  87. package/test_helpers/test_fixtures/fixuture_nodeset_objects_with_some_methods.xml +9 -1
  88. package/test_helpers/test_fixtures/mini.Node.Set2.xml +22 -1
@@ -7,12 +7,14 @@
7
7
  // --------------------------------------------------------------------------------------------------
8
8
 
9
9
  import { assert } from "node-opcua-assert";
10
- import { StatusCodes } from "node-opcua-status-code";
10
+ import { Callback, CallbackT, StatusCodes } from "node-opcua-status-code";
11
11
  import { DataType, Variant, VariantLike } from "node-opcua-variant";
12
12
 
13
- import { UAProperty, MethodFunctorCallback, ISessionContext, UAMethod, UAObject } from "node-opcua-address-space-base";
13
+ import { UAProperty, ISessionContext, UAMethod, UAObject } from "node-opcua-address-space-base";
14
14
  import { checkDebugFlag, make_debugLog } from "node-opcua-debug";
15
15
  import { UAShelvedStateMachine_Base, UAState } from "node-opcua-nodeset-ua";
16
+ import { CallMethodResultOptions } from "node-opcua-service-call";
17
+ import { DataValue } from "node-opcua-data-value";
16
18
 
17
19
  import { UAAlarmConditionImpl } from "../alarms_and_conditions/ua_alarm_condition_impl";
18
20
  import { UATransitionEx } from "../../source/interfaces/state_machine/ua_transition_ex";
@@ -75,7 +77,7 @@ export class UAShelvedStateMachineEx extends UAStateMachineImpl implements UAShe
75
77
  shelvingState.unshelveTime.minimumSamplingInterval = 500;
76
78
  shelvingState.unshelveTime.bindVariable(
77
79
  {
78
- get: _unShelveTimeFunc.bind(null, shelvingState)
80
+ timestamped_get: _unShelveTimeFunc.bind(null, shelvingState)
79
81
  },
80
82
  true
81
83
  );
@@ -93,7 +95,7 @@ export class UAShelvedStateMachineEx extends UAStateMachineImpl implements UAShe
93
95
  // specifying ConditionId as the ObjectId. The Method cannot be called with an ObjectId of the
94
96
  // ShelvedStateMachineType Node.
95
97
  // output => BadConditionNotShelved
96
- function _unshelve_method(inputArguments: VariantLike[], context: ISessionContext, callback: any) {
98
+ function _unshelve_method(inputArguments: VariantLike[], context: ISessionContext, callback: CallbackT<CallMethodResultOptions>) {
97
99
  assert(inputArguments.length === 0);
98
100
  // var alarmNode = context.object.parent;
99
101
  // if (!(alarmNode instanceof UAAlarmConditionImpl)) {
@@ -188,7 +190,11 @@ function _start_timer_for_automatic_unshelve(shelvingState: UAShelvedStateMachin
188
190
  // a reset of the shelved timer.
189
191
  // BadShelvingTimeOutOfRange
190
192
 
191
- function _timedShelve_method(inputArguments: VariantLike[], context: ISessionContext, callback: any) {
193
+ function _timedShelve_method(
194
+ inputArguments: VariantLike[],
195
+ context: ISessionContext,
196
+ callback: CallbackT<CallMethodResultOptions>
197
+ ) {
192
198
  assert(inputArguments.length === 1);
193
199
  if (!context.object) {
194
200
  return;
@@ -250,7 +256,7 @@ function _oneShotShelve_method(
250
256
  this: UAMethod,
251
257
  inputArguments: Variant[],
252
258
  context: ISessionContext,
253
- callback: MethodFunctorCallback
259
+ callback: CallbackT<CallMethodResultOptions>
254
260
  ) {
255
261
  assert(inputArguments.length === 0);
256
262
  const shelvingState = context.object! as UAShelvedStateMachineEx;
@@ -290,24 +296,27 @@ function _oneShotShelve_method(
290
296
  // TimedShelve Method call.
291
297
  // * For the OneShotShelved state the UnshelveTime will be a constant set to the maximum Duration
292
298
  // except if a MaxTimeShelved Property is provided.
293
- function _unShelveTimeFunc(shelvingState: UAShelvedStateMachineEx) {
299
+ function _unShelveTimeFunc(shelvingState: UAShelvedStateMachineEx): DataValue {
294
300
  if (shelvingState.getCurrentState() === "Unshelved") {
295
- return new Variant({
296
- dataType: DataType.StatusCode,
297
- value: StatusCodes.BadConditionNotShelved
301
+ return new DataValue({
302
+ statusCode: StatusCodes.BadConditionNotShelved,
303
+ value: { dataType: DataType.Double, value: 0 }
298
304
  });
299
305
  }
300
306
 
301
307
  if (!shelvingState._sheveldTime) {
302
- return new Variant({
303
- dataType: DataType.StatusCode,
304
- value: StatusCodes.BadConditionNotShelved
308
+ return new DataValue({
309
+ statusCode: StatusCodes.BadConditionNotShelved,
310
+ value: { dataType: DataType.Double, value: 0 }
305
311
  });
306
312
  }
307
313
  if (shelvingState.getCurrentState() === "OneShotShelved" && shelvingState._duration === UAAlarmConditionImpl.MaxDuration) {
308
- return new Variant({
309
- dataType: DataType.Double,
310
- value: UAAlarmConditionImpl.MaxDuration
314
+ return new DataValue({
315
+ statusCode: StatusCodes.Good,
316
+ value: {
317
+ dataType: DataType.Double,
318
+ value: UAAlarmConditionImpl.MaxDuration
319
+ }
311
320
  });
312
321
  }
313
322
  const now = new Date();
@@ -316,8 +325,12 @@ function _unShelveTimeFunc(shelvingState: UAShelvedStateMachineEx) {
316
325
 
317
326
  // timeToAutomaticUnshelvedState should always be greater than (or equal) zero
318
327
  timeToAutomaticUnshelvedState = Math.max(timeToAutomaticUnshelvedState, 0);
319
- return new Variant({
320
- dataType: DataType.Double, // duration
321
- value: timeToAutomaticUnshelvedState
328
+ return new DataValue({
329
+ statusCode: StatusCodes.Good,
330
+ value: {
331
+ dataType: DataType.Double, // duration
332
+ value: timeToAutomaticUnshelvedState
333
+ }
322
334
  });
323
335
  }
336
+
@@ -5,19 +5,28 @@ import * as chalk from "chalk";
5
5
 
6
6
  import { assert } from "node-opcua-assert";
7
7
  import { NodeClass, QualifiedNameLike } from "node-opcua-data-model";
8
- import { StructuredTypeSchema } from "node-opcua-factory";
8
+ import { EnumerationDefinition, StructuredTypeSchema } from "node-opcua-factory";
9
9
  import { AttributeIds } from "node-opcua-data-model";
10
10
  import { DataValue, DataValueLike } from "node-opcua-data-value";
11
11
  import { ExtensionObject } from "node-opcua-extension-object";
12
12
  import { ExpandedNodeId, NodeId } from "node-opcua-nodeid";
13
13
  import { NumericRange } from "node-opcua-numeric-range";
14
14
  import { StatusCodes } from "node-opcua-status-code";
15
- import { DataTypeDefinition, StructureDefinition, StructureField } from "node-opcua-types";
15
+ import {
16
+ DataTypeDefinition,
17
+ EnumDefinition,
18
+ EnumFieldOptions,
19
+ StructureDefinition,
20
+ StructureField,
21
+ StructureFieldOptions,
22
+ StructureType
23
+ } from "node-opcua-types";
16
24
  import { DataType } from "node-opcua-variant";
17
- import { UAObject, ISessionContext, UADataType, UAVariable, BaseNode } from "node-opcua-address-space-base";
25
+ import { UAObject, ISessionContext, UADataType, UAVariable, BaseNode, CreateDataTypeOptions } from "node-opcua-address-space-base";
26
+ import { DataTypeIds } from "node-opcua-constants";
18
27
 
19
28
  import { SessionContext } from "../source/session_context";
20
- import { BaseNodeImpl } from "./base_node_impl";
29
+ import { BaseNodeImpl, InternalBaseNodeOptions } from "./base_node_impl";
21
30
  import { BaseNode_References_toString, BaseNode_toString, ToStringBuilder, ToStringOption } from "./base_node_private";
22
31
  import * as tools from "./tool_isSupertypeOf";
23
32
  import { get_subtypeOf } from "./tool_isSupertypeOf";
@@ -44,13 +53,10 @@ export interface EnumerationInfo {
44
53
  nameIndex: { [id: string]: IEnumItem };
45
54
  valueIndex: { [id: number]: IEnumItem };
46
55
  }
47
-
48
- function findBasicDataType(dataType: UADataType): DataType {
49
- if (dataType.nodeId.namespace === 0 && dataType.nodeId.value <= 25) {
50
- // we have a well-known DataType
51
- return dataType.nodeId.value as DataType;
52
- }
53
- return findBasicDataType(dataType.subtypeOfObj as UADataType);
56
+ export interface UADataTypeOptions extends InternalBaseNodeOptions {
57
+ partialDefinition: StructureFieldOptions[] | EnumFieldOptions[];
58
+ isAbstract?: boolean;
59
+ symbolicName?: string;
54
60
  }
55
61
 
56
62
  export class UADataTypeImpl extends BaseNodeImpl implements UADataType {
@@ -83,18 +89,23 @@ export class UADataTypeImpl extends BaseNodeImpl implements UADataType {
83
89
 
84
90
  private enumStrings?: any;
85
91
  private enumValues?: any;
86
- private $definition?: DataTypeDefinition;
87
- private $fullDefinition?: DataTypeDefinition;
92
+ private $partialDefinition?: StructureFieldOptions[] | EnumFieldOptions[];
93
+ private $fullDefinition?: StructureDefinition | EnumDefinition;
88
94
 
89
- constructor(options: any) {
95
+ constructor(options: UADataTypeOptions) {
90
96
  super(options);
91
- this.$definition = options.$definition;
92
- this.isAbstract = options.isAbstract === null ? false : options.isAbstract;
97
+ if (options.partialDefinition) {
98
+ this.$partialDefinition = options.partialDefinition;
99
+ }
100
+ this.isAbstract = options.isAbstract === undefined || options.isAbstract === null ? false : options.isAbstract;
93
101
  this.symbolicName = options.symbolicName || this.browseName.name!;
94
102
  }
95
103
 
96
104
  public get basicDataType(): DataType {
97
- return findBasicDataType(this);
105
+ return this.getBasicDataType();
106
+ }
107
+ public getBasicDataType(): DataType {
108
+ return this.addressSpace.findCorrespondingBasicDataType(this);
98
109
  }
99
110
 
100
111
  public readAttribute(
@@ -113,7 +124,7 @@ export class UADataTypeImpl extends BaseNodeImpl implements UADataType {
113
124
  break;
114
125
  case AttributeIds.DataTypeDefinition:
115
126
  {
116
- const _definition = this._getDefinition(true);
127
+ const _definition = this._getDefinition()?.clone();
117
128
  if (_definition !== null) {
118
129
  options.value = { dataType: DataType.ExtensionObject, value: _definition };
119
130
  } else {
@@ -246,57 +257,92 @@ export class UADataTypeImpl extends BaseNodeImpl implements UADataType {
246
257
  return indexes;
247
258
  }
248
259
 
249
- public _getDefinition(mergeWithBase: boolean): DataTypeDefinition | null {
260
+ isStructure(): boolean {
261
+ const definition = this._getDefinition();
262
+ return definition instanceof StructureDefinition;
263
+ }
264
+ getStructureDefinition(): StructureDefinition {
265
+ const definition = this._getDefinition();
266
+ assert(definition instanceof StructureDefinition);
267
+ return definition as StructureDefinition;
268
+ }
269
+
270
+ isEnumeration(): boolean {
271
+ const definition = this._getDefinition();
272
+ return definition instanceof EnumDefinition;
273
+ }
274
+ getEnumDefinition(): EnumDefinition {
275
+ const definition = this._getDefinition();
276
+ assert(definition instanceof EnumDefinition);
277
+ return definition as EnumDefinition;
278
+ }
279
+
280
+ // eslint-disable-next-line complexity
281
+ public _getDefinition(): DataTypeDefinition | null {
250
282
  if (this.$fullDefinition !== undefined) {
251
- return mergeWithBase ? this.$fullDefinition : this.$definition!;
283
+ return this.$fullDefinition;
252
284
  }
253
- if (!this.$definition) {
254
- const structure = this.addressSpace.findDataType("Structure")!;
255
- if (!structure) {
256
- return null;
285
+ const addressSpace = this.addressSpace;
286
+ const enumeration = addressSpace.findDataType("Enumeration");
287
+ const structure = addressSpace.findDataType("Structure");
288
+ const union = addressSpace.findDataType("Union");
289
+
290
+ // we have a data type from a companion specification
291
+ // let's see if this data type need to be registered
292
+ const isEnumeration = enumeration && this.isSupertypeOf(enumeration);
293
+ const isStructure = structure && this.isSupertypeOf(structure);
294
+ const isUnion = !!(structure && union && this.isSupertypeOf(union));
295
+
296
+ const isRootDataType = (n: UADataType) => n.nodeId.namespace === 0 && n.nodeId.value === DataTypeIds.BaseDataType;
297
+ // https://reference.opcfoundation.org/v104/Core/docs/Part3/8.49/#Table34
298
+ if (isStructure) {
299
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
300
+ let dataTypeNode: UADataTypeImpl | null = this;
301
+ const allPartialDefinitions: StructureFieldOptions[][] = [];
302
+ while (dataTypeNode && !isRootDataType(dataTypeNode)) {
303
+ if (dataTypeNode.$partialDefinition) {
304
+ allPartialDefinitions.push(dataTypeNode.$partialDefinition as StructureFieldOptions[]);
305
+ }
306
+ dataTypeNode = dataTypeNode.subtypeOfObj as UADataTypeImpl | null;
257
307
  }
258
- if (this.isSupertypeOf(structure)) {
259
- // <Definition> tag was missing in XML file as it was empty
260
- this.$definition = new StructureDefinition({});
308
+ // merge them:
309
+ const definitionFields: StructureFieldOptions[] = [];
310
+ for (const dd of allPartialDefinitions.reverse()) {
311
+ definitionFields.push(...dd);
261
312
  }
262
- }
263
-
264
- // https://reference.opcfoundation.org/v104/Core/docs/Part3/8.49/#Table34
265
- // The list of fields that make up the data type.
266
- // This definition assumes the structure has a sequential layout.
267
- // The StructureField DataType is defined in 8.51.
268
- // For Structures derived from another Structure DataType this list shall begin with the fields
269
- // of the baseDataType followed by the fields of this StructureDefinition.
270
-
271
- // from OPC Unified Architecture, Part 6 86 Release 1.04
272
- // A DataTypeDefinition defines an abstract representation of _a UADataType that can be used by
273
- // design tools to automatically create serialization code. The fields in the DataTypeDefinition type
274
- // are defined in Table F.12.
275
- const _definition = this.$definition || null;
276
- if (_definition && _definition instanceof StructureDefinition && this.binaryEncodingNodeId) {
277
- _definition.defaultEncodingId = this.binaryEncodingNodeId!;
278
- const subtype = this.subtypeOf;
279
- if (subtype) {
280
- _definition.baseDataType = subtype;
313
+ const basicDataType = this.subtypeOfObj?.nodeId || new NodeId();
314
+ const defaultEncodingId = this.binaryEncodingNodeId || this.xmlEncodingNodeId || new NodeId();
315
+ const definitionName = this.browseName.name!;
316
+ this.$fullDefinition = makeStructureDefinition(
317
+ definitionName,
318
+ basicDataType,
319
+ defaultEncodingId,
320
+ definitionFields,
321
+ isUnion
322
+ );
323
+ } else if (isEnumeration) {
324
+ const allPartialDefinitions: StructureFieldOptions[][] = [];
325
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
326
+ let dataTypeNode: UADataTypeImpl | null = this;
327
+ while (dataTypeNode && !isRootDataType(dataTypeNode)) {
328
+ if (dataTypeNode.$partialDefinition) {
329
+ allPartialDefinitions.push(dataTypeNode.$partialDefinition as StructureFieldOptions[]);
330
+ }
331
+ dataTypeNode = dataTypeNode.subtypeOfObj as UADataTypeImpl | null;
281
332
  }
282
- }
283
- this.$fullDefinition = this.$definition?.clone();
284
-
285
- let _baseDefinition: DataTypeDefinition | null = null;
286
- if (this.subtypeOfObj) {
287
- _baseDefinition = (this.subtypeOfObj as UADataTypeImpl)._getDefinition(mergeWithBase);
288
- }
289
- if (this.$fullDefinition && this.$definition instanceof StructureDefinition && _baseDefinition) {
290
- const b = _baseDefinition as StructureDefinition;
291
- if (b.fields?.length) {
292
- const f = this.$fullDefinition as StructureDefinition;
293
- f.fields = (<StructureField[]>[]).concat(b.fields!, f.fields!);
333
+ // merge them:
334
+ const definitionFields: StructureFieldOptions[] = [];
335
+ for (const dd of allPartialDefinitions.reverse()) {
336
+ definitionFields.push(...dd);
294
337
  }
338
+ this.$fullDefinition = makeEnumDefinition(definitionFields);
295
339
  }
296
- return mergeWithBase ? this.$fullDefinition || null : this.$definition || null;
340
+
341
+ return this.$fullDefinition!;
297
342
  }
343
+
298
344
  public getDefinition(): DataTypeDefinition {
299
- const d = this._getDefinition(true);
345
+ const d = this._getDefinition();
300
346
  if (!d) {
301
347
  throw new Error("DataType has no definition property");
302
348
  }
@@ -315,7 +361,7 @@ export class UADataTypeImpl extends BaseNodeImpl implements UADataType {
315
361
  }
316
362
 
317
363
  function dataTypeDefinition_toString(this: UADataTypeImpl, options: ToStringOption) {
318
- const definition = this._getDefinition(false);
364
+ const definition = this._getDefinition();
319
365
  if (!definition) {
320
366
  return;
321
367
  }
@@ -354,3 +400,64 @@ export function DataType_toString(this: UADataTypeImpl, options: ToStringOption)
354
400
 
355
401
  dataTypeDefinition_toString.call(this, options);
356
402
  }
403
+
404
+ function makeEnumDefinition(definitionFields: EnumFieldOptions[]) {
405
+ return new EnumDefinition({
406
+ fields: definitionFields.map((x) => ({
407
+ description: x.description,
408
+ name: x.name,
409
+ value: x.value
410
+ }))
411
+ });
412
+ }
413
+ function makeStructureDefinition(
414
+ name: string,
415
+ baseDataType: NodeId,
416
+ defaultEncodingId: NodeId,
417
+ fields: StructureFieldOptions[],
418
+ isUnion: boolean
419
+ ): StructureDefinition {
420
+ // Structure = 0,
421
+ // StructureWithOptionalFields = 1,
422
+ // Union = 2,
423
+ const hasOptionalFields = fields.filter((field) => field.isOptional).length > 0;
424
+
425
+ const structureType = isUnion
426
+ ? StructureType.Union
427
+ : hasOptionalFields
428
+ ? StructureType.StructureWithOptionalFields
429
+ : StructureType.Structure;
430
+
431
+ const sd = new StructureDefinition({
432
+ baseDataType,
433
+ defaultEncodingId,
434
+ fields,
435
+ structureType
436
+ });
437
+ return sd;
438
+ }
439
+
440
+ /*
441
+ function lockReadOnlyWithWriteDetection<T>(obj: T): T {
442
+ if (obj instanceof Array) {
443
+ return obj.map(lockReadOnlyWithWriteDetection) as unknown as T;
444
+ }
445
+ if (obj instanceof Object) {
446
+ const _org = obj;
447
+ for (const [key, value] of Object.entries(obj)) {
448
+ lockReadOnlyWithWriteDetection(value);
449
+ }
450
+ obj = new Proxy(obj, {
451
+ get: (target: any, prop: string) => {
452
+ return target[prop];
453
+ },
454
+ set: (target: any, prop: string | symbol, value: any, receiver: any) => {
455
+ console.log("QQQQQ Cannot modify stuff ");
456
+ debugger;
457
+ throw new Error("Invalid");
458
+ }
459
+ });
460
+ }
461
+ return obj;
462
+ }
463
+ */
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @module node-opcua-address-space
3
3
  */
4
+ import { callbackify } from "util";
4
5
  import * as chalk from "chalk";
5
6
  import { assert } from "node-opcua-assert";
6
7
 
@@ -11,13 +12,14 @@ import { make_debugLog, make_errorLog, make_warningLog } from "node-opcua-debug"
11
12
  import { NodeId } from "node-opcua-nodeid";
12
13
  import { NumericRange } from "node-opcua-numeric-range";
13
14
  import { Argument } from "node-opcua-service-call";
14
- import { StatusCodes } from "node-opcua-status-code";
15
+ import { CallbackT, StatusCodes } from "node-opcua-status-code";
15
16
  import { CallMethodResultOptions, PermissionType } from "node-opcua-types";
16
17
  import { Variant } from "node-opcua-variant";
17
18
  import { DataType, VariantLike } from "node-opcua-variant";
18
19
  import {
19
20
  MethodFunctor,
20
- MethodFunctorCallback,
21
+ MethodFunctorA,
22
+ MethodFunctorC,
21
23
  UAMethod,
22
24
  UAObject,
23
25
  CloneExtraInfo,
@@ -25,7 +27,9 @@ import {
25
27
  CloneOptions,
26
28
  UAObjectType,
27
29
  ISessionContext,
28
- UAVariable
30
+ UAVariable,
31
+ defaultCloneFilter,
32
+ defaultCloneExtraInfo
29
33
  } from "node-opcua-address-space-base";
30
34
  import { SessionContext } from "../source";
31
35
  import { _clone } from "./base_node_private";
@@ -122,6 +126,10 @@ export class UAMethodImpl extends BaseNodeImpl implements UAMethod {
122
126
 
123
127
  public bindMethod(async_func: MethodFunctor): void {
124
128
  assert(typeof async_func === "function");
129
+ if (async_func.length === 2) {
130
+ async_func = callbackify(async_func as MethodFunctorA) as MethodFunctorC;
131
+ }
132
+ assert(async_func.length === 3);
125
133
  this._asyncExecutionFunction = async_func;
126
134
  }
127
135
  public execute(
@@ -133,13 +141,13 @@ export class UAMethodImpl extends BaseNodeImpl implements UAMethod {
133
141
  object: UAObject | UAObjectType | null,
134
142
  inputArguments: null | VariantLike[],
135
143
  context: ISessionContext,
136
- callback: MethodFunctorCallback
144
+ callback: CallbackT<CallMethodResultOptions>
137
145
  ): void;
138
146
  public execute(
139
147
  object: UAObject | UAObjectType | null,
140
148
  inputArguments: VariantLike[] | null,
141
149
  context: ISessionContext,
142
- callback?: MethodFunctorCallback
150
+ callback?: CallbackT<CallMethodResultOptions>
143
151
  ): any {
144
152
  // istanbul ignore next
145
153
  if (!callback) {
@@ -200,7 +208,7 @@ export class UAMethodImpl extends BaseNodeImpl implements UAMethod {
200
208
  this as UAMethodImpl,
201
209
  inputArguments as Variant[],
202
210
  context,
203
- (err: Error | null, callMethodResult: CallMethodResultOptions) => {
211
+ (err: Error | null, callMethodResult?: CallMethodResultOptions) => {
204
212
  if (err) {
205
213
  debugLog(err.message);
206
214
  debugLog(err);
@@ -250,7 +258,13 @@ export class UAMethodImpl extends BaseNodeImpl implements UAMethod {
250
258
 
251
259
  _handle_hierarchy_parent(addressSpace, options.references, options);
252
260
 
253
- const clonedMethod = _clone.call(this, UAMethodImpl, options, optionalFilter, extraInfo) as UAMethodImpl;
261
+ const clonedMethod = _clone.call(
262
+ this,
263
+ UAMethodImpl,
264
+ options,
265
+ optionalFilter || defaultCloneFilter,
266
+ extraInfo || defaultCloneExtraInfo
267
+ ) as UAMethodImpl;
254
268
 
255
269
  clonedMethod._asyncExecutionFunction = this._asyncExecutionFunction;
256
270
  clonedMethod._getExecutableFlag = this._getExecutableFlag;
@@ -25,7 +25,9 @@ import {
25
25
  CloneExtraInfo,
26
26
  BaseNode,
27
27
  UAEventType,
28
- IEventData
28
+ IEventData,
29
+ defaultCloneFilter,
30
+ defaultCloneExtraInfo
29
31
  } from "node-opcua-address-space-base";
30
32
 
31
33
  import { BaseNodeImpl, InternalBaseNodeOptions } from "./base_node_impl";
@@ -80,7 +82,13 @@ export class UAObjectImpl extends BaseNodeImpl implements UAObject {
80
82
  symbolicName: this.symbolicName || undefined
81
83
  };
82
84
 
83
- const cloneObject = _clone.call(this, UAObjectImpl, options, optionalFilter, extraInfo) as UAObject;
85
+ const cloneObject = _clone.call(
86
+ this,
87
+ UAObjectImpl,
88
+ options,
89
+ optionalFilter || defaultCloneFilter,
90
+ extraInfo || defaultCloneExtraInfo
91
+ ) as UAObject;
84
92
  // xx newObject.propagate_back_references();
85
93
  // xx newObject.install_extra_properties();
86
94
  return cloneObject;