node-opcua-address-space 2.120.0 → 2.121.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 (54) hide show
  1. package/dist/source/continuation_points/continuation_point_manager.d.ts +9 -2
  2. package/dist/source/continuation_points/continuation_point_manager.js +42 -14
  3. package/dist/source/continuation_points/continuation_point_manager.js.map +1 -1
  4. package/dist/source/helpers/argument_list.js +8 -3
  5. package/dist/source/helpers/argument_list.js.map +1 -1
  6. package/dist/source/helpers/call_helpers.js +2 -2
  7. package/dist/source/interfaces/alarms_and_conditions/ua_condition_ex.d.ts +2 -0
  8. package/dist/source/loader/load_nodeset2.js +4 -3
  9. package/dist/source/loader/load_nodeset2.js.map +1 -1
  10. package/dist/source/pseudo_session.js +1 -6
  11. package/dist/source/pseudo_session.js.map +1 -1
  12. package/dist/src/_mandatory_child_or_requested_optional_filter.js +2 -1
  13. package/dist/src/_mandatory_child_or_requested_optional_filter.js.map +1 -1
  14. package/dist/src/address_space.d.ts +3 -1
  15. package/dist/src/address_space.js +5 -2
  16. package/dist/src/address_space.js.map +1 -1
  17. package/dist/src/alarms_and_conditions/ua_condition_impl.d.ts +2 -0
  18. package/dist/src/alarms_and_conditions/ua_condition_impl.js.map +1 -1
  19. package/dist/src/base_node_impl.d.ts +2 -0
  20. package/dist/src/base_node_impl.js +7 -3
  21. package/dist/src/base_node_impl.js.map +1 -1
  22. package/dist/src/base_node_private.js +4 -1
  23. package/dist/src/base_node_private.js.map +1 -1
  24. package/dist/src/historical_access/address_space_historical_data_node.js +2 -2
  25. package/dist/src/historical_access/address_space_historical_data_node.js.map +1 -1
  26. package/dist/src/namespace_impl.js +1 -1
  27. package/dist/src/namespace_impl.js.map +1 -1
  28. package/dist/src/ua_method_impl.js +1 -1
  29. package/dist/src/ua_method_impl.js.map +1 -1
  30. package/dist/src/ua_object_impl.js +9 -0
  31. package/dist/src/ua_object_impl.js.map +1 -1
  32. package/dist/src/ua_reference_type_impl.d.ts +1 -1
  33. package/dist/src/ua_variable_impl.js +52 -27
  34. package/dist/src/ua_variable_impl.js.map +1 -1
  35. package/dist/tsconfig_common.tsbuildinfo +1 -1
  36. package/distHelpers/boiler_system.js +18 -8
  37. package/distHelpers/boiler_system.js.map +1 -1
  38. package/package.json +36 -36
  39. package/source/continuation_points/continuation_point_manager.ts +49 -21
  40. package/source/helpers/argument_list.ts +26 -21
  41. package/source/helpers/call_helpers.ts +2 -2
  42. package/source/interfaces/alarms_and_conditions/ua_condition_ex.ts +4 -4
  43. package/source/loader/load_nodeset2.ts +5 -3
  44. package/source/pseudo_session.ts +2 -6
  45. package/src/_mandatory_child_or_requested_optional_filter.ts +2 -2
  46. package/src/address_space.ts +7 -4
  47. package/src/alarms_and_conditions/ua_condition_impl.ts +2 -3
  48. package/src/base_node_impl.ts +8 -5
  49. package/src/base_node_private.ts +5 -2
  50. package/src/historical_access/address_space_historical_data_node.ts +2 -2
  51. package/src/namespace_impl.ts +1 -1
  52. package/src/ua_method_impl.ts +1 -1
  53. package/src/ua_object_impl.ts +12 -0
  54. package/src/ua_variable_impl.ts +66 -31
@@ -87,6 +87,8 @@ const warningLog = make_warningLog(__filename);
87
87
  const errorLog = make_errorLog(__filename);
88
88
  const debugLog = make_debugLog(__filename);
89
89
 
90
+ const HasEventSourceReferenceType = resolveNodeId("HasEventSource");
91
+ const HasNotifierReferenceType = resolveNodeId("HasNotifier");
90
92
 
91
93
  function defaultBrowseFilterFunc(context?: ISessionContext): boolean {
92
94
  return true;
@@ -180,7 +182,6 @@ export class BaseNodeImpl extends EventEmitter implements BaseNode {
180
182
  return _private._displayName;
181
183
  }
182
184
 
183
-
184
185
  public setDisplayName(value: LocalizedTextLike[] | LocalizedTextLike): void {
185
186
  if (!Array.isArray(value)) {
186
187
  return this.setDisplayName([value]);
@@ -199,7 +200,7 @@ export class BaseNodeImpl extends EventEmitter implements BaseNode {
199
200
  return _private._description!;
200
201
  }
201
202
 
202
- public setDescription(value: LocalizedTextLike| null): void {
203
+ public setDescription(value: LocalizedTextLike | null): void {
203
204
  this._setDescription(value);
204
205
  /**
205
206
  * fires when the description attribute is changed.
@@ -504,6 +505,7 @@ export class BaseNodeImpl extends EventEmitter implements BaseNode {
504
505
 
505
506
  /**
506
507
  * return a array with the notifiers of this object.
508
+ * only reference of exact type HasNotifier are returned.
507
509
  */
508
510
  public getNotifiers(): BaseNode[] {
509
511
  // const _cache = BaseNode_getCache(this);
@@ -511,11 +513,12 @@ export class BaseNodeImpl extends EventEmitter implements BaseNode {
511
513
  // _cache._notifiers = this.findReferencesAsObject("HasNotifier", true);
512
514
  // }
513
515
  // return _cache._notifiers;
514
- return this.findReferencesAsObject("HasNotifier", true);
516
+ return this.findReferencesAsObject(HasNotifierReferenceType, true);
515
517
  }
516
518
 
517
519
  /**
518
520
  * return a array with the event source of this object.
521
+ * only reference of exact type HasEventSource are returned.
519
522
  */
520
523
  public getEventSources(): BaseNode[] {
521
524
  // const _cache = BaseNode_getCache(this);
@@ -523,7 +526,7 @@ export class BaseNodeImpl extends EventEmitter implements BaseNode {
523
526
  // _cache._eventSources = this.findReferencesAsObject("HasEventSource", true);
524
527
  // }
525
528
  // return _cache._eventSources;
526
- return this.findReferencesAsObject("HasEventSource", true);
529
+ return this.findReferencesAsObject(HasEventSourceReferenceType, true);
527
530
  }
528
531
 
529
532
  /**
@@ -535,7 +538,7 @@ export class BaseNodeImpl extends EventEmitter implements BaseNode {
535
538
  // _cache._eventSources = this.findReferencesAsObject("HasEventSource", false);
536
539
  // }
537
540
  // return _cache._eventSources;
538
- return this.findReferencesAsObject("HasEventSource", false);
541
+ return this.findReferencesAsObject(HasEventSourceReferenceType, false);
539
542
  }
540
543
 
541
544
  /**
@@ -542,7 +542,10 @@ function _clone_children_on_template(
542
542
  )
543
543
  );
544
544
 
545
- const typeDefinitionChild = typeDefinitionNode.getChildByName(node.browseName);
545
+ // Find aggregates with same browseName as node. Do not search children as this includes nodes with HasSubType relation which we do
546
+ // not want. See issue #1326.
547
+ const aggregates = typeDefinitionNode.getAggregates().filter((n) => n.browseName.equals(node.browseName));
548
+ const typeDefinitionChild = aggregates.length > 0 ? aggregates[0] : null;
546
549
  if (typeDefinitionChild) {
547
550
  const references = typeDefinitionChild.findReferencesEx("Aggregates", BrowseDirection.Forward);
548
551
 
@@ -1053,7 +1056,7 @@ export function _clone<T extends UAObject | UAVariable | UAMethod>(
1053
1056
  );
1054
1057
  typeDefinitionNode = typeDefinitionNode.subtypeOfObj;
1055
1058
  }
1056
-
1059
+
1057
1060
  extraInfo.popContext();
1058
1061
 
1059
1062
  }
@@ -445,9 +445,9 @@ function _historyReadRaw(
445
445
  historyReadRawModifiedDetails.numValuesPerNode,
446
446
  continuationData
447
447
  );
448
- const { statusCode, values } = cnt;
448
+ const { statusCode, values, continuationPoint } = cnt;
449
449
  const result2 = new HistoryReadResult({
450
- continuationPoint: cnt.continuationPoint,
450
+ continuationPoint,
451
451
  historyData: new HistoryData({ dataValues: values }),
452
452
  statusCode
453
453
  });
@@ -2000,7 +2000,7 @@ export class NamespaceImpl implements NamespacePrivate {
2000
2000
  // a getter has been specified and no options.minimumSamplingInterval has been specified
2001
2001
  warningLog(
2002
2002
  "[NODE-OPCUA-W30",
2003
- "namespace#addVariable a getter has been specified and minimumSamplingInterval is missing.\nMinimumSamplingInterval has been adjusted to 1000 ms"
2003
+ "namespace#addVariable a getter has been specified and minimumSamplingInterval is missing.\nMinimumSamplingInterval has been adjusted to 1000 ms\nvariable = "+ options?.browseName?.toString()
2004
2004
  );
2005
2005
  options.minimumSamplingInterval = 1000;
2006
2006
  }
@@ -135,7 +135,7 @@ export class UAMethodImpl extends BaseNodeImpl implements UAMethod {
135
135
  if (async_func.length === 2) {
136
136
  async_func = callbackify(async_func as MethodFunctorA) as MethodFunctorC;
137
137
  }
138
- assert(async_func.length === 3);
138
+ assert(async_func.length === 3, " a method with callback should have 3 arguments : got " + async_func.length);
139
139
  this._asyncExecutionFunction = async_func;
140
140
  }
141
141
  public execute(
@@ -42,6 +42,18 @@ export class UAObjectImpl extends BaseNodeImpl implements UAObject {
42
42
  private _eventNotifier: EventNotifierFlags;
43
43
  public readonly nodeClass = NodeClass.Object;
44
44
  public get eventNotifier(): EventNotifierFlags {
45
+
46
+ // ensure eventNotifier is set if the node has some event
47
+
48
+ if (!this._eventNotifier) {
49
+ // const s = this.getEventSources();
50
+ const s = this.getEventSources();
51
+ const n = this.getNotifiers();
52
+ if (s.length > 0 || n.length > 0) {
53
+ this._eventNotifier = this._eventNotifier | EventNotifierFlags.SubscribeToEvents;
54
+ }
55
+ }
56
+
45
57
  return this._eventNotifier;
46
58
  }
47
59
  public readonly symbolicName: string | null;
@@ -1870,19 +1870,19 @@ function check_valid_array(dataType: DataType, array: any): boolean {
1870
1870
  return false;
1871
1871
  }
1872
1872
 
1873
- function _apply_default_timestamps(dataValue: DataValue): void {
1874
- const now = getCurrentClock();
1875
- assert(dataValue instanceof DataValue);
1876
-
1877
- if (!dataValue.sourceTimestamp) {
1878
- dataValue.sourceTimestamp = now.timestamp;
1879
- dataValue.sourcePicoseconds = now.picoseconds;
1880
- }
1881
- if (!dataValue.serverTimestamp) {
1882
- dataValue.serverTimestamp = now.timestamp;
1883
- dataValue.serverPicoseconds = now.picoseconds;
1884
- }
1885
- }
1873
+ // function _apply_default_timestamps(dataValue: DataValue): void {
1874
+ // const now = getCurrentClock();
1875
+ // assert(dataValue instanceof DataValue);
1876
+
1877
+ // if (!dataValue.sourceTimestamp) {
1878
+ // dataValue.sourceTimestamp = now.timestamp;
1879
+ // dataValue.sourcePicoseconds = now.picoseconds;
1880
+ // }
1881
+ // if (!dataValue.serverTimestamp) {
1882
+ // dataValue.serverTimestamp = now.timestamp;
1883
+ // dataValue.serverPicoseconds = now.picoseconds;
1884
+ // }
1885
+ // }
1886
1886
 
1887
1887
  function unsetFlag(flags: number, mask: number): number {
1888
1888
  return flags & ~mask;
@@ -1949,17 +1949,33 @@ function _default_writable_timestamped_set_func(
1949
1949
  callback(null, StatusCodes.Good, dataValue);
1950
1950
  }
1951
1951
 
1952
- function turn_sync_to_async<T, D, R>(f: (this: T, data: D) => R, numberOfArgs: number) {
1952
+ type f1<T, D, R> = (this: T, data: D) => R;
1953
+ type f2<T, D, R> = (this: T, data: D) => Promise<R>;
1954
+ type f3<T, D, R> = (this: T, data: D, callback: (err: Error | null, r?: R) => void) => void;
1955
+
1956
+ function turn_sync_to_async<T, D, R>(f: f1<T, D, R> | f2<T, D, R> | f3<T, D, R>, numberOfArgs: number): f3<T, D, R> {
1953
1957
  if (f.length <= numberOfArgs) {
1954
1958
  return function (this: T, data: D, callback: (err: Error | null, r?: R) => void) {
1955
- try {
1956
- const r = f.call(this, data);
1957
- setImmediate(() => {
1958
- return callback(null, r);
1959
+ new Promise<R>((resolve, reject) => {
1960
+ try {
1961
+ // const ff1 = f as f1<T, D, R>;
1962
+ const ff2 = f as f2<T, D, R>;
1963
+ const r: R | Promise<R> = ff2.call(this, data);
1964
+ if (r instanceof Promise) {
1965
+ r.then(resolve, reject);
1966
+ } else {
1967
+ resolve(r);
1968
+ }
1969
+ } catch (err) {
1970
+ reject(err);
1971
+ }
1972
+ })
1973
+ .then((r) => {
1974
+ callback(null, r);
1975
+ })
1976
+ .catch((err) => {
1977
+ callback(err as Error);
1959
1978
  });
1960
- } catch (err) {
1961
- return callback(err as Error);
1962
- }
1963
1979
  };
1964
1980
  } else {
1965
1981
  assert(f.length === numberOfArgs + 1);
@@ -1977,8 +1993,10 @@ function coerceDataValue(dataValue: DataValue | DataValueLike): DataValue {
1977
1993
  }
1978
1994
 
1979
1995
  // variation #3 :
1980
- function _Variable_bind_with_async_refresh(this: UAVariableImpl, options: any) {
1981
- /* jshint validthis: true */
1996
+ function _Variable_bind_with_async_refresh(
1997
+ this: UAVariableImpl,
1998
+ options: { refreshFunc: RefreshFunc; get?: undefined; timestamped_get?: undefined }
1999
+ ) {
1982
2000
  assert(this instanceof UAVariableImpl);
1983
2001
 
1984
2002
  assert(typeof options.refreshFunc === "function");
@@ -2050,7 +2068,6 @@ function _Variable_bind_with_timestamped_get(
2050
2068
 
2051
2069
  // variation 1
2052
2070
  function _Variable_bind_with_simple_get(this: UAVariableImpl, options: GetterOptions) {
2053
- /* jshint validthis: true */
2054
2071
  assert(this instanceof UAVariableImpl);
2055
2072
  assert(typeof options.get === "function", "should specify get function");
2056
2073
  assert(options.get!.length === 0, "get function should not have arguments");
@@ -2082,7 +2099,14 @@ function _Variable_bind_with_simple_get(this: UAVariableImpl, options: GetterOpt
2082
2099
  !this.$dataValue.statusCode.isGoodish() ||
2083
2100
  !sameVariant(this.$dataValue.value, value as Variant)
2084
2101
  ) {
2085
- this._inner_replace_dataValue(new DataValue({ value }));
2102
+ // rebuilding artificially timestamps with current clock as they are not provided
2103
+ // by the underlying getter function
2104
+ const { timestamp: sourceTimestamp, picoseconds: sourcePicoseconds } = getCurrentClock();
2105
+ const serverTimestamp = sourceTimestamp;
2106
+ const serverPicoseconds = sourcePicoseconds;
2107
+ this._inner_replace_dataValue(
2108
+ new DataValue({ value, sourceTimestamp, sourcePicoseconds, serverTimestamp, serverPicoseconds })
2109
+ );
2086
2110
  }
2087
2111
  return this.$dataValue;
2088
2112
  }
@@ -2094,7 +2118,8 @@ function _Variable_bind_with_simple_get(this: UAVariableImpl, options: GetterOpt
2094
2118
  });
2095
2119
  }
2096
2120
 
2097
- function _Variable_bind_with_simple_set(this: UAVariableImpl, options: any) {
2121
+ type SimpleSetOptions = { set?: SetFunc; timestamped_set: undefined };
2122
+ function _Variable_bind_with_simple_set(this: UAVariableImpl, options: SimpleSetOptions) {
2098
2123
  assert(this instanceof UAVariableImpl);
2099
2124
  assert(typeof options.set === "function", "should specify set function");
2100
2125
  assert(!options.timestamped_set, "should not specify a timestamped_set function");
@@ -2102,7 +2127,9 @@ function _Variable_bind_with_simple_set(this: UAVariableImpl, options: any) {
2102
2127
  assert(!this._timestamped_set_func);
2103
2128
  assert(!this._set_func);
2104
2129
 
2105
- this._set_func = turn_sync_to_async(options.set, 1);
2130
+ //
2131
+ this._set_func = turn_sync_to_async(options.set!, 1);
2132
+
2106
2133
  assert(this._set_func.length === 2, " set function must have 2 arguments ( variant, callback)");
2107
2134
 
2108
2135
  this._timestamped_set_func = (
@@ -2149,9 +2176,13 @@ interface SetterOptions {
2149
2176
  timestamped_get?: TimestampGetFunc;
2150
2177
  }
2151
2178
  function bind_setter(this: UAVariableImpl, options: SetterOptions) {
2152
- if (typeof options.set === "function") {
2179
+ if (options.set && typeof options.set === "function") {
2153
2180
  // variation 1
2154
- _Variable_bind_with_simple_set.call(this, options);
2181
+ if (options.timestamped_set === undefined) {
2182
+ _Variable_bind_with_simple_set.call(this, options as SimpleSetOptions);
2183
+ } else {
2184
+ throw new Error("bind_setter : options should not specify both set and timestamped_set ");
2185
+ }
2155
2186
  } else if (typeof options.timestamped_set === "function") {
2156
2187
  // variation 2
2157
2188
  assert(typeof options.timestamped_get === "function", "timestamped_set must be used with timestamped_get ");
@@ -2174,10 +2205,11 @@ function bind_setter(this: UAVariableImpl, options: SetterOptions) {
2174
2205
  }
2175
2206
  }
2176
2207
 
2208
+ type RefreshFunc = (callback: CallbackT<DataValue>) => void;
2177
2209
  interface GetterOptions {
2178
2210
  get?: GetFunc;
2179
2211
  timestamped_get?: TimestampGetFunc;
2180
- refreshFunc?: (callback: CallbackT<DataValue>) => void;
2212
+ refreshFunc?: RefreshFunc;
2181
2213
  dataType?: DataType | string;
2182
2214
  value?: any;
2183
2215
  }
@@ -2193,7 +2225,10 @@ function bind_getter(this: UAVariableImpl, options: GetterOptions) {
2193
2225
  });
2194
2226
  } else if (typeof options.refreshFunc === "function") {
2195
2227
  // variation 3
2196
- _Variable_bind_with_async_refresh.call(this, options);
2228
+ if (options.get !== undefined || options.timestamped_get !== undefined) {
2229
+ throw new Error("bind_getter : options should not specify both get and timestamped_get ");
2230
+ }
2231
+ _Variable_bind_with_async_refresh.call(this, { refreshFunc: options.refreshFunc! });
2197
2232
  } else {
2198
2233
  assert(
2199
2234
  !Object.prototype.hasOwnProperty.call(options, "set"),