node-opcua-client-proxy 2.177.0 → 2.179.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 (40) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +4 -4
  3. package/dist/index.js.map +1 -1
  4. package/dist/object_explorer.d.ts +11 -8
  5. package/dist/object_explorer.js +37 -31
  6. package/dist/object_explorer.js.map +1 -1
  7. package/dist/proxy.d.ts +1 -1
  8. package/dist/proxy.js +3 -3
  9. package/dist/proxy.js.map +1 -1
  10. package/dist/proxy_base_node.d.ts +19 -14
  11. package/dist/proxy_base_node.js +8 -8
  12. package/dist/proxy_base_node.js.map +1 -1
  13. package/dist/proxy_manager.d.ts +9 -10
  14. package/dist/proxy_manager.js +17 -15
  15. package/dist/proxy_manager.js.map +1 -1
  16. package/dist/proxy_object.d.ts +2 -2
  17. package/dist/proxy_state.d.ts +2 -2
  18. package/dist/proxy_state.js +2 -2
  19. package/dist/proxy_state.js.map +1 -1
  20. package/dist/proxy_state_machine.d.ts +3 -3
  21. package/dist/proxy_state_machine.js +2 -2
  22. package/dist/proxy_state_machine.js.map +1 -1
  23. package/dist/proxy_transition.d.ts +2 -2
  24. package/dist/proxy_variable.d.ts +4 -4
  25. package/dist/proxy_variable.js +1 -1
  26. package/dist/proxy_variable.js.map +1 -1
  27. package/dist/state_machine_proxy.d.ts +1 -1
  28. package/dist/state_machine_proxy.js.map +1 -1
  29. package/package.json +19 -19
  30. package/source/index.ts +2 -1
  31. package/source/object_explorer.ts +102 -63
  32. package/source/proxy.ts +6 -4
  33. package/source/proxy_base_node.ts +25 -23
  34. package/source/proxy_manager.ts +40 -34
  35. package/source/proxy_object.ts +2 -2
  36. package/source/proxy_state.ts +5 -5
  37. package/source/proxy_state_machine.ts +3 -3
  38. package/source/proxy_transition.ts +2 -2
  39. package/source/proxy_variable.ts +4 -4
  40. package/source/state_machine_proxy.ts +3 -4
@@ -1,16 +1,18 @@
1
1
  /**
2
2
  * @module node-opcua-client-proxy
3
3
  */
4
- import { EventEmitter } from "events";
4
+ import { EventEmitter } from "node:events";
5
5
  import { assert } from "node-opcua-assert";
6
- import { AttributeIds, NodeClass } from "node-opcua-data-model";
7
- import { DataValue } from "node-opcua-data-value";
8
- import { NodeId } from "node-opcua-nodeid";
9
- import { Argument } from "node-opcua-service-call";
10
- import { WriteValueOptions } from "node-opcua-service-write";
11
- import { DataType, Variant } from "node-opcua-variant";
12
- import { UAProxyManager } from "./proxy_manager";
13
- import { StatusCode } from "node-opcua-status-code";
6
+ import { AttributeIds, type NodeClass } from "node-opcua-data-model";
7
+ import type { DataValue } from "node-opcua-data-value";
8
+ import type { NodeId } from "node-opcua-nodeid";
9
+ import type { Argument } from "node-opcua-service-call";
10
+ import type { WriteValueOptions } from "node-opcua-service-write";
11
+ import type { StatusCode } from "node-opcua-status-code";
12
+ import type { DataType, Variant } from "node-opcua-variant";
13
+ import type { UAProxyManager } from "./proxy_manager";
14
+ import type { ProxyNode } from "./proxy_transition";
15
+ import type { ProxyVariable } from "./proxy_variable";
14
16
 
15
17
  export interface ArgumentEx extends Argument {
16
18
  _basicDataType: DataType;
@@ -18,7 +20,7 @@ export interface ArgumentEx extends Argument {
18
20
  export interface MethodDescription {
19
21
  browseName: string;
20
22
  executableFlag: boolean;
21
- func: (input: Record<string, unknown>, callback: (err: Error | null, output?: Record<string, unknown>) => void) => void;
23
+ func: (input: Record<string, unknown>) => Promise<{ statusCode: StatusCode; output?: Record<string, unknown> }>;
22
24
  nodeId: NodeId; // the method NodeId
23
25
  inputArguments: ArgumentEx[];
24
26
  outputArguments: ArgumentEx[];
@@ -36,25 +38,25 @@ export class ProxyBaseNode extends EventEmitter {
36
38
  * @property $components
37
39
  * @type {Array<ProxyBaseNode>}
38
40
  */
39
- public readonly $components: any[];
41
+ public readonly $components: ProxyNode[];
40
42
  /**
41
43
  * the object's properties
42
44
  * @property $properties
43
45
  * @type {Array<ProxyBaseNode>}
44
46
  */
45
- public $properties: any[];
47
+ public $properties: Record<string, ProxyVariable>;
46
48
  /**
47
49
  * the object's properties
48
50
  * @property $methods
49
51
  * @type {Array<ProxyBaseNode>}
50
52
  */
51
- public $methods: MethodDescription[];
53
+ public $methods: Record<string, MethodDescription>;
52
54
  /**
53
55
  * the Folder's elements
54
56
  * @property $organizes
55
57
  * @type {Array<ProxyBaseNode>}
56
58
  */
57
- public $organizes: any[];
59
+ public $organizes: ProxyNode[];
58
60
  /**
59
61
  * the object's description
60
62
  * @property description
@@ -72,7 +74,7 @@ export class ProxyBaseNode extends EventEmitter {
72
74
  * @property nodeClass
73
75
  * @type {NodeClass}
74
76
  */
75
- public readonly nodeClass: NodeClass;
77
+ public nodeClass: NodeClass;
76
78
 
77
79
  private readonly proxyManager: UAProxyManager;
78
80
 
@@ -88,8 +90,8 @@ export class ProxyBaseNode extends EventEmitter {
88
90
  writable: true
89
91
  });
90
92
  this.$components = [];
91
- this.$properties = [];
92
- this.$methods = [];
93
+ this.$properties = {};
94
+ this.$methods = {};
93
95
  this.$organizes = [];
94
96
 
95
97
  this.description = "";
@@ -111,7 +113,7 @@ export class ProxyBaseNode extends EventEmitter {
111
113
  nodeId: this.nodeId
112
114
  };
113
115
  const dataValue = await this.proxyManager.session.read(nodeToRead);
114
- const data = dataValue!.value;
116
+ const data = dataValue?.value;
115
117
  return data;
116
118
  }
117
119
 
@@ -130,18 +132,18 @@ export class ProxyBaseNode extends EventEmitter {
130
132
  value: dataValue
131
133
  };
132
134
  const statusCode = await this.proxyManager.session.write(nodeToWrite);
133
-
135
+
134
136
  return statusCode;
135
137
  }
136
138
 
137
139
  public toString(): string {
138
140
  const str = [];
139
141
  str.push(" ProxyObject ");
140
- str.push(" browseName : " + this.browseName.toString());
142
+ str.push(` browseName : ${this.browseName.toString()}`);
141
143
  // str.push(" typeDefinition : " + this.typeDefinition.toString());
142
- str.push(" $components# : " + this.$components.length.toString());
143
- str.push(" $properties# : " + this.$properties.length.toString());
144
+ str.push(` $components# : ${this.$components.length.toString()}`);
145
+ str.push(` $properties# : ${Object.keys(this.$properties).length.toString()}`);
144
146
 
145
147
  return str.join("\n");
146
148
  }
147
- }
149
+ }
@@ -1,28 +1,34 @@
1
1
  /**
2
2
  * @module node-opcua-client-proxy
3
3
  */
4
- // tslint:disable:no-shadowed-variable
5
- import { EventEmitter } from "events";
4
+ import type { EventEmitter } from "node:events";
6
5
  import { assert } from "node-opcua-assert";
7
6
 
8
- import { AttributeIds, NodeClass, coerceAccessLevelFlag } from "node-opcua-data-model";
9
- import { NodeId, coerceNodeId } from "node-opcua-nodeid";
10
- import { DataValue, TimestampsToReturn } from "node-opcua-data-value";
11
- import { NodeIdLike } from "node-opcua-nodeid";
12
- import { CreateSubscriptionRequestOptions, MonitoringParametersOptions } from "node-opcua-service-subscription";
7
+ import { type AccessLevelFlag, AttributeIds, coerceAccessLevelFlag, NodeClass } from "node-opcua-data-model";
8
+ import { type DataValue, TimestampsToReturn } from "node-opcua-data-value";
9
+ import { checkDebugFlag, make_debugLog } from "node-opcua-debug";
10
+ import { coerceNodeId, NodeId, type NodeIdLike } from "node-opcua-nodeid";
11
+ import type { IBasicSessionAsync, IBasicSessionGetArgumentDefinitionAsync } from "node-opcua-pseudo-session";
12
+ import type { ReadValueIdOptions } from "node-opcua-service-read";
13
+ import type { CreateSubscriptionRequestOptions, MonitoringParametersOptions } from "node-opcua-service-subscription";
13
14
  import { StatusCodes } from "node-opcua-status-code";
14
- import { IBasicSessionAsync, IBasicSessionGetArgumentDefinitionAsync } from "node-opcua-pseudo-session";
15
- import { ReadValueIdOptions } from "node-opcua-service-read";
16
- import { Variant } from "node-opcua-variant";
17
- import { make_debugLog } from "node-opcua-debug";
15
+ import type { Variant } from "node-opcua-variant";
18
16
 
19
17
  import { readUAStructure } from "./object_explorer";
20
18
  import { makeRefId } from "./proxy";
21
19
  import { ProxyObject } from "./proxy_object";
20
+ import type { ProxyNode } from "./proxy_transition";
22
21
  import { ProxyStateMachineType } from "./state_machine_proxy";
23
- import { ProxyNode } from "./proxy_transition";
22
+
23
+ interface ProxyObjectWithDynamicFields extends ProxyObject {
24
+ dataValue?: DataValue;
25
+ userAccessLevel?: AccessLevelFlag;
26
+ accessLevel?: AccessLevelFlag;
27
+ [dynamicChildName: string]: unknown;
28
+ }
24
29
 
25
30
  const debugLog = make_debugLog(__filename);
31
+ const doDebug = checkDebugFlag(__filename);
26
32
 
27
33
  export interface IProxy1 {
28
34
  nodeId: NodeId;
@@ -31,14 +37,14 @@ export interface IProxy1 {
31
37
  __monitoredItem?: EventEmitter;
32
38
  }
33
39
  export interface IProxy extends EventEmitter, IProxy1 {
34
- dataValue: DataValue;
40
+ dataValue?: DataValue;
35
41
  }
36
42
 
37
43
  async function internalGetObject(
38
- proxyManager: UAProxyManager,
39
- nodeId: NodeIdLike | NodeId, options: any
44
+ proxyManager: UAProxyManager,
45
+ nodeId: NodeIdLike | NodeId,
46
+ _options: { depth?: number }
40
47
  ): Promise<ProxyNode> {
41
-
42
48
  const session = proxyManager.session;
43
49
 
44
50
  nodeId = coerceNodeId(nodeId) as NodeId;
@@ -62,7 +68,7 @@ async function internalGetObject(
62
68
  }
63
69
  ];
64
70
 
65
- async function read_accessLevels(clientObject: any) {
71
+ async function read_accessLevels(clientObject: ProxyObjectWithDynamicFields) {
66
72
  const nodesToRead = [
67
73
  {
68
74
  attributeId: AttributeIds.Value,
@@ -81,7 +87,10 @@ async function internalGetObject(
81
87
  const dataValues = await session.read(nodesToRead);
82
88
 
83
89
  if (dataValues[0].statusCode.isGood()) {
84
- clientObject.dataValue = dataValues[0].value;
90
+ // store the full DataValue (statusCode + timestamps + value), consistent with
91
+ // what _monitor_value's "changed" handler assigns here on later updates —
92
+ // assigning just the Variant (dataValues[0].value) would be a narrower shape.
93
+ clientObject.dataValue = dataValues[0];
85
94
  }
86
95
  if (dataValues[1].statusCode.isGood()) {
87
96
  clientObject.userAccessLevel = coerceAccessLevelFlag(dataValues[1].value.value);
@@ -91,15 +100,15 @@ async function internalGetObject(
91
100
  }
92
101
  }
93
102
 
94
- let clientObject: any;
103
+ let clientObject: ProxyObjectWithDynamicFields;
95
104
 
96
105
  const dataValues = await session.read(nodesToRead);
97
106
 
98
107
  if (dataValues[0].statusCode.equals(StatusCodes.BadNodeIdUnknown)) {
99
- throw new Error("Invalid Node " + nodeId.toString());
108
+ throw new Error(`Invalid Node ${nodeId.toString()}`);
100
109
  }
101
110
 
102
- clientObject = new ProxyObject(proxyManager, nodeId as NodeId);
111
+ clientObject = new ProxyObject(proxyManager, nodeId as NodeId) as ProxyObjectWithDynamicFields;
103
112
 
104
113
  clientObject.browseName = dataValues[0].value.value;
105
114
  clientObject.description = dataValues[1].value ? dataValues[1].value.value : "";
@@ -134,11 +143,10 @@ export interface IBasicSessionWithSubscriptionAsync extends IBasicSessionAsync,
134
143
  createSubscription2(options: CreateSubscriptionRequestOptions): Promise<IClientSubscription>;
135
144
  }
136
145
 
137
- // tslint:disable-next-line: max-classes-per-file
138
146
  export class UAProxyManager {
139
147
  public readonly session: IBasicSessionWithSubscriptionAsync;
140
148
  public subscription?: IClientSubscription;
141
- #_map: any;
149
+ #_map: Record<string, ProxyNode>;
142
150
 
143
151
  constructor(session: IBasicSessionWithSubscriptionAsync) {
144
152
  this.session = session;
@@ -146,7 +154,6 @@ export class UAProxyManager {
146
154
  }
147
155
 
148
156
  public async start(): Promise<void> {
149
-
150
157
  const createSubscriptionRequest: CreateSubscriptionRequestOptions = {
151
158
  maxNotificationsPerPublish: 1000,
152
159
  priority: 10,
@@ -157,8 +164,8 @@ export class UAProxyManager {
157
164
  };
158
165
 
159
166
  const subscription = await this.session.createSubscription2(createSubscriptionRequest);
160
- this.subscription = subscription!;
161
- this.subscription!.on("terminated", () => {
167
+ this.subscription = subscription;
168
+ this.subscription?.on("terminated", () => {
162
169
  this.subscription = undefined;
163
170
  });
164
171
  }
@@ -174,13 +181,11 @@ export class UAProxyManager {
174
181
 
175
182
  // todo: rename getObject as getNode
176
183
  public async getObject(nodeId: NodeIdLike): Promise<ProxyNode> {
177
- let options: any = {};
178
- options = options || {};
179
- options.depth = options.depth || 1;
184
+ const options: { depth: number } = { depth: 1 };
180
185
 
181
186
  const key = nodeId.toString();
182
187
  // the object already exist in the map ?
183
- if (Object.prototype.hasOwnProperty.call(this.#_map, key)) {
188
+ if (Object.hasOwn(this.#_map, key)) {
184
189
  return this.#_map[key];
185
190
  }
186
191
 
@@ -212,12 +217,13 @@ export class UAProxyManager {
212
217
  const monitoredItem = await this.subscription.monitor(itemToMonitor, monitoringParameters, requestedParameters);
213
218
 
214
219
  Object.defineProperty(proxyObject, "__monitoredItem", { value: monitoredItem, enumerable: false });
215
- proxyObject.__monitoredItem!.on("changed", (dataValue: DataValue) => {
220
+ proxyObject.__monitoredItem?.on("changed", (dataValue: DataValue) => {
216
221
  proxyObject.dataValue = dataValue;
217
222
  proxyObject.emit("value_changed", dataValue);
218
223
  });
219
- proxyObject.__monitoredItem!.on("err", (err: Error) => {
220
- debugLog("Proxy: cannot monitor variable ", itemToMonitor.nodeId?.toString(), err.message);
224
+ proxyObject.__monitoredItem?.on("err", (err: Error) => {
225
+ // c8 ignore next
226
+ doDebug && debugLog("Proxy: cannot monitor variable ", itemToMonitor.nodeId?.toString(), err.message);
221
227
  });
222
228
  }
223
229
 
@@ -250,7 +256,7 @@ export class UAProxyManager {
250
256
 
251
257
  enumerable: false
252
258
  });
253
- proxyObject.__monitoredItem_execution_flag!.on("changed", (dataValue: DataValue) => {
259
+ proxyObject.__monitoredItem_execution_flag?.on("changed", (dataValue: DataValue) => {
254
260
  proxyObject.executableFlag = dataValue.value.value;
255
261
  });
256
262
  }
@@ -2,9 +2,9 @@
2
2
  * @module node-opcua-client-proxy
3
3
  */
4
4
  import { NodeClass } from "node-opcua-data-model";
5
- import { NodeId } from "node-opcua-nodeid";
5
+ import type { NodeId } from "node-opcua-nodeid";
6
6
  import { ProxyBaseNode } from "./proxy_base_node";
7
- import { UAProxyManager } from "./proxy_manager";
7
+ import type { UAProxyManager } from "./proxy_manager";
8
8
 
9
9
  export class ProxyObject extends ProxyBaseNode {
10
10
  constructor(proxyManager: UAProxyManager, nodeId: NodeId) {
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * @module node-opcua-client-proxy
3
3
  */
4
- import { NodeId } from "node-opcua-nodeid";
5
- import { ProxyNode } from "./proxy_transition";
4
+ import type { NodeId } from "node-opcua-nodeid";
5
+ import type { ProxyNode } from "./proxy_transition";
6
6
 
7
7
  export class ProxyState {
8
- private _node: any;
8
+ private _node: ProxyNode & { stateNumber?: ProxyNode };
9
9
 
10
10
  constructor(proxyNode: ProxyNode) {
11
11
  this._node = proxyNode;
@@ -17,7 +17,7 @@ export class ProxyState {
17
17
 
18
18
  public get stateNumber(): string {
19
19
  // note stateNumber has no real dataValue
20
- return this._node.stateNumber.nodeId.value.toString();
20
+ return this._node.stateNumber?.nodeId.value.toString() || "";
21
21
  }
22
22
 
23
23
  public get nodeId(): NodeId {
@@ -26,7 +26,7 @@ export class ProxyState {
26
26
  }
27
27
 
28
28
  public toString(): string {
29
- return "state " + this.browseName + " stateNumber :" + this.stateNumber.toString();
29
+ return `state ${this.browseName} stateNumber :${this.stateNumber.toString()}`;
30
30
  }
31
31
  }
32
32
 
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * @module node-opcua-client-proxy
3
3
  */
4
- import { EventEmitter } from "events";
4
+ import { EventEmitter } from "node:events";
5
5
  import { assert } from "node-opcua-assert";
6
- import { NodeId } from "node-opcua-nodeid";
7
- import { UAProxyManager } from "./proxy_manager";
6
+ import type { NodeId } from "node-opcua-nodeid";
7
+ import type { UAProxyManager } from "./proxy_manager";
8
8
 
9
9
  export class StateMachineProxy extends EventEmitter {
10
10
  public nodeId: NodeId;
@@ -1,5 +1,5 @@
1
- import { QualifiedName } from "node-opcua-data-model";
2
- import { NodeId } from "node-opcua-nodeid";
1
+ import type { QualifiedName } from "node-opcua-data-model";
2
+ import type { NodeId } from "node-opcua-nodeid";
3
3
 
4
4
  export interface ProxyNode {
5
5
  nodeId: NodeId;
@@ -2,13 +2,13 @@
2
2
  * @module node-opcua-client-proxy
3
3
  */
4
4
  import { NodeClass } from "node-opcua-data-model";
5
- import { NodeId } from "node-opcua-nodeid";
6
- import { ReferenceDescription } from "node-opcua-service-browse";
5
+ import type { NodeId } from "node-opcua-nodeid";
6
+ import type { ReferenceDescription } from "node-opcua-service-browse";
7
7
  import { ProxyBaseNode } from "./proxy_base_node";
8
- import { UAProxyManager } from "./proxy_manager";
8
+ import type { UAProxyManager } from "./proxy_manager";
9
9
 
10
10
  export class ProxyVariable extends ProxyBaseNode {
11
- constructor(proxyManager: UAProxyManager, nodeId: NodeId, reference: ReferenceDescription) {
11
+ constructor(proxyManager: UAProxyManager, nodeId: NodeId, _reference: ReferenceDescription) {
12
12
  super(proxyManager, nodeId, NodeClass.Variable);
13
13
  }
14
14
  }
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import { assert } from "node-opcua-assert";
5
5
  import { makeProxyState, ProxyState } from "./proxy_state";
6
- import { makeProxyTransition, ProxyNode, ProxyTransition } from "./proxy_transition";
6
+ import { makeProxyTransition, type ProxyNode, type ProxyTransition } from "./proxy_transition";
7
7
 
8
8
  export class ProxyStateMachineType {
9
9
  public initialState: ProxyState | undefined;
@@ -11,8 +11,7 @@ export class ProxyStateMachineType {
11
11
  public transitions: ProxyTransition[];
12
12
 
13
13
  constructor(obj: ProxyNode) {
14
-
15
- const localInitialState = obj.$components.filter((component: any) => {
14
+ const localInitialState = obj.$components.filter((component: ProxyNode) => {
16
15
  if (!component.typeDefinition) {
17
16
  return false;
18
17
  }
@@ -27,7 +26,7 @@ export class ProxyStateMachineType {
27
26
  }
28
27
 
29
28
  this.states = obj.$components
30
- .filter((component: any) => {
29
+ .filter((component: ProxyNode) => {
31
30
  if (!component.typeDefinition) {
32
31
  return false;
33
32
  }