node-opcua-client-proxy 2.139.0 → 2.141.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.
- package/dist/object_explorer.d.ts +6 -3
- package/dist/object_explorer.js +147 -255
- package/dist/object_explorer.js.map +1 -1
- package/dist/proxy_base_node.d.ts +3 -2
- package/dist/proxy_base_node.js +7 -26
- package/dist/proxy_base_node.js.map +1 -1
- package/dist/proxy_manager.d.ts +13 -17
- package/dist/proxy_manager.js +86 -138
- package/dist/proxy_manager.js.map +1 -1
- package/dist/proxy_transition.d.ts +0 -3
- package/dist/proxy_transition.js +0 -3
- package/dist/proxy_transition.js.map +1 -1
- package/dist/state_machine_proxy.js.map +1 -1
- package/package.json +9 -11
- package/source/object_explorer.ts +173 -331
- package/source/proxy_base_node.ts +10 -27
- package/source/proxy_manager.ts +94 -189
- package/source/proxy_transition.ts +1 -3
- package/source/state_machine_proxy.ts +1 -0
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module node-opcua-client-proxy
|
|
3
3
|
*/
|
|
4
|
-
import async from "async";
|
|
5
4
|
|
|
6
5
|
import { assert } from "node-opcua-assert";
|
|
7
|
-
import { Callback, ErrorCallback } from "node-opcua-status-code";
|
|
8
6
|
import { AttributeIds, BrowseDirection, makeNodeClassMask, makeResultMask } from "node-opcua-data-model";
|
|
9
|
-
import { DataValue } from "node-opcua-data-value";
|
|
10
7
|
import { NodeId } from "node-opcua-nodeid";
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
import {
|
|
9
|
+
IBasicSessionReadAsyncSimple,
|
|
10
|
+
IBasicSessionBrowseAsyncSimple
|
|
11
|
+
} from "node-opcua-pseudo-session";
|
|
12
|
+
import { ReferenceDescription } from "node-opcua-service-browse";
|
|
13
|
+
import { CallMethodRequest, Argument } from "node-opcua-service-call";
|
|
15
14
|
import { lowerFirstLetter } from "node-opcua-utils";
|
|
16
|
-
import { DataType, Variant, VariantArrayType
|
|
15
|
+
import { DataType, Variant, VariantArrayType } from "node-opcua-variant";
|
|
17
16
|
import { make_errorLog, make_debugLog } from "node-opcua-debug";
|
|
18
17
|
import { DataTypeIds } from "node-opcua-constants";
|
|
19
18
|
|
|
@@ -22,7 +21,6 @@ import { UAProxyManager } from "./proxy_manager";
|
|
|
22
21
|
import { ProxyVariable } from "./proxy_variable";
|
|
23
22
|
import { MethodDescription, ArgumentEx } from "./proxy_base_node";
|
|
24
23
|
|
|
25
|
-
|
|
26
24
|
const doDebug = false;
|
|
27
25
|
const errorLog = make_errorLog("Proxy");
|
|
28
26
|
const debugLog = make_debugLog("Proxy");
|
|
@@ -61,81 +59,55 @@ const resultMask = makeResultMask("ReferenceType | IsForward | BrowseName | Node
|
|
|
61
59
|
*
|
|
62
60
|
* for an enumeration dataType will be DataType.Int32
|
|
63
61
|
*/
|
|
64
|
-
function convertNodeIdToDataTypeAsync(
|
|
65
|
-
session:
|
|
66
|
-
dataTypeId: NodeId
|
|
67
|
-
|
|
68
|
-
) {
|
|
62
|
+
async function convertNodeIdToDataTypeAsync(
|
|
63
|
+
session: IBasicSessionReadAsyncSimple & IBasicSessionBrowseAsyncSimple,
|
|
64
|
+
dataTypeId: NodeId
|
|
65
|
+
): Promise<DataType> {
|
|
69
66
|
const nodeToRead = {
|
|
70
67
|
attributeId: AttributeIds.BrowseName,
|
|
71
68
|
nodeId: dataTypeId
|
|
72
69
|
};
|
|
73
|
-
session.read(nodeToRead
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
70
|
+
const dataValue = await session.read(nodeToRead);
|
|
71
|
+
let dataType: DataType;
|
|
72
|
+
// istanbul ignore next
|
|
73
|
+
if (dataValue.statusCode.isNotGood()) {
|
|
74
|
+
dataType = DataType.Null;
|
|
75
|
+
return dataType;
|
|
76
|
+
}
|
|
81
77
|
|
|
82
|
-
|
|
78
|
+
const dataTypeName = dataValue.value.value;
|
|
83
79
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
setImmediate(() => {
|
|
89
|
-
callback(null, dataType);
|
|
90
|
-
});
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
80
|
+
if (dataTypeId.namespace === 0 && dataTypeId.value === DataTypeIds.Enumeration) {
|
|
81
|
+
dataType = DataType.Int32;
|
|
82
|
+
return dataType;
|
|
83
|
+
}
|
|
93
84
|
|
|
94
|
-
|
|
85
|
+
if (dataTypeId.namespace === 0 && DataType[dataTypeId.value as number]) {
|
|
86
|
+
dataType = (DataType as any)[dataTypeId.value as number] as DataType;
|
|
87
|
+
return dataType;
|
|
88
|
+
}
|
|
95
89
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
90
|
+
/// example => Duration (i=290) => Double (i=11)
|
|
91
|
+
// read subTypeOf
|
|
92
|
+
const nodeToBrowse = {
|
|
93
|
+
browseDirection: BrowseDirection.Inverse,
|
|
94
|
+
includeSubtypes: false,
|
|
95
|
+
nodeId: dataTypeId,
|
|
96
|
+
// BrowseDescription
|
|
97
|
+
referenceTypeId: makeRefId("HasSubtype"),
|
|
98
|
+
// xx nodeClassMask: makeNodeClassMask("ObjectType"),
|
|
99
|
+
resultMask
|
|
100
|
+
};
|
|
101
|
+
// tslint:disable:no-shadowed-variable
|
|
102
|
+
const browseResult = await session.browse(nodeToBrowse);
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
dataType = (DataType as any)[dataTypeId.value as number] as DataType;
|
|
106
|
-
setImmediate(() => {
|
|
107
|
-
callback(null, dataType);
|
|
108
|
-
});
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
104
|
+
const references = browseResult!.references;
|
|
111
105
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
nodeId: dataTypeId,
|
|
118
|
-
// BrowseDescription
|
|
119
|
-
referenceTypeId: makeRefId("HasSubtype"),
|
|
120
|
-
// xx nodeClassMask: makeNodeClassMask("ObjectType"),
|
|
121
|
-
resultMask
|
|
122
|
-
};
|
|
123
|
-
// tslint:disable:no-shadowed-variable
|
|
124
|
-
session.browse(nodeToBrowse, (err: Error | null, browseResult?: BrowseResult) => {
|
|
125
|
-
// istanbul ignore next
|
|
126
|
-
if (err) {
|
|
127
|
-
return callback(err);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const references = browseResult!.references;
|
|
131
|
-
|
|
132
|
-
if (!references || references.length !== 1) {
|
|
133
|
-
return callback(new Error("cannot find SuperType of " + dataTypeName.toString()));
|
|
134
|
-
}
|
|
135
|
-
const nodeId = references[0].nodeId;
|
|
136
|
-
return convertNodeIdToDataTypeAsync(session, nodeId, callback);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
106
|
+
if (!references || references.length !== 1) {
|
|
107
|
+
throw new Error("cannot find SuperType of " + dataTypeName.toString());
|
|
108
|
+
}
|
|
109
|
+
const nodeId = references[0].nodeId;
|
|
110
|
+
return convertNodeIdToDataTypeAsync(session, nodeId);
|
|
139
111
|
}
|
|
140
112
|
|
|
141
113
|
function convertToVariant(value: unknown, arg: ArgumentEx, propName: string): Variant {
|
|
@@ -163,18 +135,13 @@ function convertToVariantArray(inputArgsDef: ArgumentEx[], inputArgs: Record<str
|
|
|
163
135
|
return inputArguments;
|
|
164
136
|
}
|
|
165
137
|
|
|
166
|
-
|
|
138
|
+
import { ProxyNode } from "./proxy_transition";
|
|
139
|
+
import { StatusCode } from "node-opcua-status-code";
|
|
167
140
|
|
|
168
141
|
function makeFunction(obj: any, methodName: string) {
|
|
169
|
-
return
|
|
170
|
-
this: any,
|
|
171
|
-
inputArgs: Record<string, unknown>,
|
|
172
|
-
callback: (err: Error | null, output?: Record<string, unknown>) => void
|
|
173
|
-
) {
|
|
142
|
+
return async function functionCaller(this: any, inputArgs: Record<string, unknown>): Promise<{ statusCode: StatusCode, output?: Record<string, unknown> }> {
|
|
174
143
|
const session = this.proxyManager.session;
|
|
175
144
|
|
|
176
|
-
assert(typeof callback === "function");
|
|
177
|
-
|
|
178
145
|
const methodDef = this.$methods[methodName];
|
|
179
146
|
// convert input arguments into Variants
|
|
180
147
|
const inputArgsDef = methodDef.inputArguments || [];
|
|
@@ -187,60 +154,48 @@ function makeFunction(obj: any, methodName: string) {
|
|
|
187
154
|
objectId: obj.nodeId
|
|
188
155
|
});
|
|
189
156
|
|
|
190
|
-
session.call(methodToCall
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
)
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
const output: Record<string, unknown> = {};
|
|
215
|
-
methodDef.outputArguments.map((arg: Argument, index: number) => {
|
|
216
|
-
const variant = callResult!.outputArguments![index];
|
|
217
|
-
const propName = lowerFirstLetter(arg.name!);
|
|
218
|
-
output[propName] = variant.value;
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
callback(err, output);
|
|
157
|
+
const callResult = await session.call(methodToCall);
|
|
158
|
+
|
|
159
|
+
if (callResult.statusCode.isNotGood()) {
|
|
160
|
+
return { statusCode: callResult.statusCode };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
callResult.outputArguments = callResult.outputArguments || [];
|
|
164
|
+
|
|
165
|
+
if (callResult.outputArguments.length !== methodDef.outputArguments.length) {
|
|
166
|
+
throw new Error(
|
|
167
|
+
"Internal error callResult.outputArguments.length " +
|
|
168
|
+
callResult.outputArguments.length +
|
|
169
|
+
" " +
|
|
170
|
+
obj[methodName].outputArguments.length
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
const output: Record<string, unknown> = {};
|
|
174
|
+
methodDef.outputArguments.map((arg: Argument, index: number) => {
|
|
175
|
+
const variant = callResult!.outputArguments![index];
|
|
176
|
+
const propName = lowerFirstLetter(arg.name!);
|
|
177
|
+
output[propName] = variant.value;
|
|
222
178
|
});
|
|
223
|
-
|
|
179
|
+
|
|
180
|
+
return { statusCode: callResult.statusCode, output };
|
|
181
|
+
};
|
|
224
182
|
}
|
|
225
183
|
|
|
226
|
-
function extractDataType(
|
|
184
|
+
async function extractDataType(
|
|
185
|
+
session: IBasicSessionReadAsyncSimple & IBasicSessionBrowseAsyncSimple,
|
|
186
|
+
arg: ArgumentEx
|
|
187
|
+
): Promise<void> {
|
|
227
188
|
if (arg.dataType && arg._basicDataType) {
|
|
228
|
-
setImmediate(callback); // already converted
|
|
229
189
|
return;
|
|
230
190
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
if (!err) {
|
|
234
|
-
arg._basicDataType = dataType!;
|
|
235
|
-
}
|
|
236
|
-
callback(err || undefined);
|
|
237
|
-
});
|
|
191
|
+
const dataType = await convertNodeIdToDataTypeAsync(session, arg.dataType);
|
|
192
|
+
arg._basicDataType = dataType!;
|
|
238
193
|
}
|
|
239
194
|
/**
|
|
240
|
-
|
|
195
|
+
|
|
241
196
|
* @private
|
|
242
197
|
*/
|
|
243
|
-
function add_method(proxyManager: UAProxyManager, obj: any, reference: ReferenceDescription
|
|
198
|
+
async function add_method(proxyManager: UAProxyManager, obj: any, reference: ReferenceDescription): Promise<void> {
|
|
244
199
|
const session = proxyManager.session;
|
|
245
200
|
|
|
246
201
|
const methodName = lowerFirstLetter(reference.browseName.name!);
|
|
@@ -249,93 +204,52 @@ function add_method(proxyManager: UAProxyManager, obj: any, reference: Reference
|
|
|
249
204
|
let outputArguments: ArgumentEx[] = [];
|
|
250
205
|
|
|
251
206
|
// tslint:disable:no-shadowed-variable
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
session.getArgumentDefinition(reference.nodeId, (err, argumentDefinition) => {
|
|
256
|
-
// istanbul ignore next
|
|
257
|
-
if (err) {
|
|
258
|
-
errorLog("getArgumentDefinition failed ", err);
|
|
259
|
-
return callback(err);
|
|
260
|
-
}
|
|
261
|
-
// istanbul ignore next
|
|
262
|
-
if (!argumentDefinition) {
|
|
263
|
-
return callback(new Error("Internal Error"));
|
|
264
|
-
}
|
|
265
|
-
inputArguments = (argumentDefinition.inputArguments as ArgumentEx[]) || [];
|
|
266
|
-
outputArguments = (argumentDefinition.outputArguments as ArgumentEx[]) || [];
|
|
267
|
-
|
|
268
|
-
const _extractDataType = extractDataType.bind(null, session);
|
|
269
|
-
async.series(
|
|
270
|
-
[
|
|
271
|
-
(innerCallback) => async.eachSeries(inputArguments, _extractDataType, innerCallback),
|
|
272
|
-
(innerCallback) => async.eachSeries(outputArguments, _extractDataType, innerCallback)
|
|
273
|
-
],
|
|
274
|
-
(err) => callback(err!)
|
|
275
|
-
);
|
|
276
|
-
});
|
|
277
|
-
},
|
|
278
|
-
|
|
279
|
-
(callback: ErrorCallback) => {
|
|
280
|
-
const methodObj: MethodDescription = {
|
|
281
|
-
browseName: methodName,
|
|
282
|
-
executableFlag: false,
|
|
283
|
-
func: makeFunction(obj, methodName),
|
|
284
|
-
nodeId: reference.nodeId,
|
|
285
|
-
inputArguments,
|
|
286
|
-
outputArguments
|
|
287
|
-
};
|
|
288
|
-
obj.$methods[methodName] = methodObj;
|
|
289
|
-
obj[methodName] = methodObj.func;
|
|
290
|
-
|
|
291
|
-
obj[methodName].inputArguments = inputArguments;
|
|
292
|
-
obj[methodName].outputArguments = outputArguments;
|
|
293
|
-
|
|
294
|
-
doDebug && debugLog("installing method name", methodName);
|
|
295
|
-
proxyManager._monitor_execution_flag(methodObj, () => {
|
|
296
|
-
callback();
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
],
|
|
300
|
-
(err) => {
|
|
301
|
-
if (err) {
|
|
302
|
-
errorLog("Error =>", err);
|
|
303
|
-
}
|
|
304
|
-
outerCallback(err!);
|
|
305
|
-
}
|
|
306
|
-
);
|
|
307
|
-
}
|
|
207
|
+
const argumentDefinition = await session.getArgumentDefinition(reference.nodeId);
|
|
208
|
+
inputArguments = (argumentDefinition.inputArguments as ArgumentEx[]) || [];
|
|
209
|
+
outputArguments = (argumentDefinition.outputArguments as ArgumentEx[]) || [];
|
|
308
210
|
|
|
309
|
-
|
|
310
|
-
const
|
|
211
|
+
const promises: Promise<void>[] = [];
|
|
212
|
+
for (const arg of inputArguments || []) {
|
|
213
|
+
promises.push(extractDataType(session, arg));
|
|
214
|
+
}
|
|
215
|
+
for (const arg of outputArguments || []) {
|
|
216
|
+
promises.push(extractDataType(session, arg));
|
|
217
|
+
}
|
|
218
|
+
await Promise.all(promises);
|
|
311
219
|
|
|
312
|
-
const
|
|
220
|
+
const methodObj: MethodDescription = {
|
|
221
|
+
browseName: methodName,
|
|
222
|
+
executableFlag: false,
|
|
223
|
+
func: makeFunction(obj, methodName) as any,
|
|
224
|
+
nodeId: reference.nodeId,
|
|
225
|
+
inputArguments,
|
|
226
|
+
outputArguments
|
|
227
|
+
};
|
|
228
|
+
obj.$methods[methodName] = methodObj;
|
|
229
|
+
obj[methodName] = methodObj.func;
|
|
313
230
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
231
|
+
obj[methodName].inputArguments = inputArguments;
|
|
232
|
+
obj[methodName].outputArguments = outputArguments;
|
|
233
|
+
|
|
234
|
+
doDebug && debugLog("installing method name", methodName);
|
|
235
|
+
await proxyManager._monitor_execution_flag(methodObj);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async function add_component(proxyManager: UAProxyManager, obj: any, reference: ReferenceDescription): Promise<void> {
|
|
239
|
+
const name = lowerFirstLetter(reference.browseName.name || "");
|
|
240
|
+
let childObj1 = await proxyManager.getObject(reference.nodeId);
|
|
241
|
+
const childObj = new ObjectExplorer({
|
|
242
|
+
name,
|
|
243
|
+
nodeId: reference.nodeId,
|
|
244
|
+
parent: obj,
|
|
245
|
+
proxyManager
|
|
330
246
|
});
|
|
247
|
+
obj[name] = childObj;
|
|
248
|
+
obj.$components.push(childObj);
|
|
249
|
+
await childObj.$resolve();
|
|
331
250
|
}
|
|
332
251
|
|
|
333
|
-
function addFolderElement(
|
|
334
|
-
proxyManager: UAProxyManager,
|
|
335
|
-
obj: any,
|
|
336
|
-
reference: ReferenceDescription,
|
|
337
|
-
callback: (err?: Error) => void
|
|
338
|
-
) {
|
|
252
|
+
async function addFolderElement(proxyManager: UAProxyManager, obj: any, reference: ReferenceDescription): Promise<void> {
|
|
339
253
|
const session = proxyManager.session;
|
|
340
254
|
|
|
341
255
|
const name = lowerFirstLetter(reference.browseName.name || "");
|
|
@@ -349,59 +263,39 @@ function addFolderElement(
|
|
|
349
263
|
|
|
350
264
|
obj[name] = childObj;
|
|
351
265
|
obj.$organizes.push(childObj);
|
|
352
|
-
childObj.$resolve(
|
|
266
|
+
await childObj.$resolve();
|
|
353
267
|
}
|
|
354
268
|
|
|
355
|
-
function add_property(proxyManager: UAProxyManager, obj: any, reference: ReferenceDescription
|
|
269
|
+
async function add_property(proxyManager: UAProxyManager, obj: any, reference: ReferenceDescription): Promise<void> {
|
|
356
270
|
const session = proxyManager.session;
|
|
357
271
|
|
|
358
272
|
const name = lowerFirstLetter(reference.browseName.name || "");
|
|
359
273
|
|
|
360
274
|
obj[name] = new ProxyVariable(proxyManager, reference.nodeId, reference);
|
|
361
275
|
obj.$properties[name] = obj[name];
|
|
362
|
-
|
|
363
|
-
setImmediate(callback);
|
|
364
276
|
}
|
|
365
277
|
|
|
366
|
-
function add_typeDefinition(
|
|
367
|
-
proxyManager: UAProxyManager,
|
|
368
|
-
obj: any,
|
|
369
|
-
references: ReferenceDescription[],
|
|
370
|
-
callback: (err?: Error) => void
|
|
371
|
-
): void {
|
|
278
|
+
async function add_typeDefinition(proxyManager: UAProxyManager, obj: any, references: ReferenceDescription[]): Promise<void> {
|
|
372
279
|
const session = proxyManager.session;
|
|
373
280
|
references = references || [];
|
|
374
281
|
if (references.length !== 1) {
|
|
375
|
-
setImmediate(callback);
|
|
376
282
|
return;
|
|
377
283
|
}
|
|
378
284
|
const reference = references[0];
|
|
379
285
|
assert(!obj.typeDefinition, "type definition can only be set once");
|
|
380
286
|
obj.typeDefinition = reference.browseName.name || "";
|
|
381
|
-
setImmediate(callback);
|
|
382
287
|
}
|
|
383
288
|
|
|
384
|
-
function addFromState(proxyManager: UAProxyManager, obj: any, reference: ReferenceDescription
|
|
385
|
-
proxyManager.getObject(reference.nodeId
|
|
386
|
-
|
|
387
|
-
callback(err);
|
|
388
|
-
}
|
|
389
|
-
obj.$fromState = childObj;
|
|
390
|
-
callback();
|
|
391
|
-
});
|
|
289
|
+
async function addFromState(proxyManager: UAProxyManager, obj: any, reference: ReferenceDescription): Promise<void> {
|
|
290
|
+
const childObj = await proxyManager.getObject(reference.nodeId);
|
|
291
|
+
obj.$fromState = childObj;
|
|
392
292
|
}
|
|
393
293
|
|
|
394
|
-
function addToState(proxyManager: UAProxyManager, obj: any, reference: ReferenceDescription
|
|
395
|
-
proxyManager.getObject(reference.nodeId
|
|
396
|
-
|
|
397
|
-
callback(err);
|
|
398
|
-
}
|
|
399
|
-
obj.$toState = childObj;
|
|
400
|
-
callback();
|
|
401
|
-
});
|
|
294
|
+
async function addToState(proxyManager: UAProxyManager, obj: any, reference: ReferenceDescription): Promise<void> {
|
|
295
|
+
const childObj = await proxyManager.getObject(reference.nodeId);
|
|
296
|
+
obj.$toState = childObj;
|
|
402
297
|
}
|
|
403
|
-
|
|
404
|
-
export class ObjectExplorer {
|
|
298
|
+
export class ObjectExplorer {
|
|
405
299
|
public proxyManager: UAProxyManager;
|
|
406
300
|
public name: string;
|
|
407
301
|
public nodeId: NodeId;
|
|
@@ -414,26 +308,19 @@ export class ObjectExplorer {
|
|
|
414
308
|
this.parent = options.parent;
|
|
415
309
|
}
|
|
416
310
|
|
|
417
|
-
public $resolve(
|
|
418
|
-
this.proxyManager.getObject(this.nodeId
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
return callback(err);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
this.parent[this.name] = childObj;
|
|
425
|
-
this.parent.$components.push(childObj);
|
|
426
|
-
|
|
427
|
-
callback();
|
|
428
|
-
});
|
|
311
|
+
public async $resolve(): Promise<void> {
|
|
312
|
+
const childObj = await this.proxyManager.getObject(this.nodeId);
|
|
313
|
+
this.parent[this.name] = childObj;
|
|
314
|
+
this.parent.$components.push(childObj);
|
|
429
315
|
}
|
|
430
316
|
}
|
|
317
|
+
|
|
431
318
|
function t(references: ReferenceDescription[] | null) {
|
|
432
319
|
if (!references) return "";
|
|
433
320
|
return references.map((r: ReferenceDescription) => r.browseName.name + " " + r.nodeId.toString());
|
|
434
321
|
}
|
|
435
322
|
|
|
436
|
-
export function readUAStructure(proxyManager: UAProxyManager, obj: { nodeId: NodeId }
|
|
323
|
+
export async function readUAStructure(proxyManager: UAProxyManager, obj: { nodeId: NodeId }): Promise<ProxyNode> {
|
|
437
324
|
const session = proxyManager.session;
|
|
438
325
|
|
|
439
326
|
// 0 Object
|
|
@@ -441,7 +328,7 @@ export function readUAStructure(proxyManager: UAProxyManager, obj: { nodeId: Nod
|
|
|
441
328
|
// 2 Method
|
|
442
329
|
const nodeId = obj.nodeId;
|
|
443
330
|
const nodesToBrowse = [
|
|
444
|
-
// Components (except Methods)
|
|
331
|
+
// 0. Components (except Methods)
|
|
445
332
|
{
|
|
446
333
|
// BrowseDescription
|
|
447
334
|
browseDirection: BrowseDirection.Forward,
|
|
@@ -451,7 +338,7 @@ export function readUAStructure(proxyManager: UAProxyManager, obj: { nodeId: Nod
|
|
|
451
338
|
referenceTypeId: makeRefId("HasComponent"),
|
|
452
339
|
resultMask
|
|
453
340
|
},
|
|
454
|
-
// Properties
|
|
341
|
+
// 1. Properties
|
|
455
342
|
{
|
|
456
343
|
// BrowseDescription
|
|
457
344
|
browseDirection: BrowseDirection.Forward,
|
|
@@ -462,7 +349,7 @@ export function readUAStructure(proxyManager: UAProxyManager, obj: { nodeId: Nod
|
|
|
462
349
|
resultMask
|
|
463
350
|
},
|
|
464
351
|
|
|
465
|
-
// Methods
|
|
352
|
+
// 2. Methods
|
|
466
353
|
{
|
|
467
354
|
// BrowseDescription
|
|
468
355
|
browseDirection: BrowseDirection.Forward,
|
|
@@ -509,83 +396,38 @@ export function readUAStructure(proxyManager: UAProxyManager, obj: { nodeId: Nod
|
|
|
509
396
|
resultMask
|
|
510
397
|
}
|
|
511
398
|
];
|
|
512
|
-
session.browse(nodesToBrowse
|
|
513
|
-
|
|
399
|
+
const browseResults = await session.browse(nodesToBrowse);
|
|
400
|
+
// istanbul ignore next
|
|
401
|
+
if (doDebug) {
|
|
402
|
+
debugLog("Components", t(browseResults[0].references));
|
|
403
|
+
debugLog("Properties", t(browseResults[1].references));
|
|
404
|
+
debugLog("Methods", t(browseResults[2].references));
|
|
405
|
+
}
|
|
514
406
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
},
|
|
542
|
-
|
|
543
|
-
// now enrich our object with nice callable async methods
|
|
544
|
-
(callback: ErrorCallback) => {
|
|
545
|
-
async.mapSeries(
|
|
546
|
-
browseResults![2].references!,
|
|
547
|
-
(reference, innerCallback) => add_method(proxyManager, obj, reference, innerCallback),
|
|
548
|
-
(err) => callback(err!)
|
|
549
|
-
);
|
|
550
|
-
},
|
|
551
|
-
|
|
552
|
-
// now set typeDefinition
|
|
553
|
-
(callback: ErrorCallback) => {
|
|
554
|
-
add_typeDefinition(proxyManager, obj, browseResults![3].references!, callback);
|
|
555
|
-
},
|
|
556
|
-
|
|
557
|
-
// FromState
|
|
558
|
-
(callback: ErrorCallback) => {
|
|
559
|
-
// fromState
|
|
560
|
-
const reference = browseResults![4].references ? browseResults![4].references![0] : null;
|
|
561
|
-
// fromState
|
|
562
|
-
if (reference) {
|
|
563
|
-
return addFromState(proxyManager, obj, reference, callback);
|
|
564
|
-
}
|
|
565
|
-
callback();
|
|
566
|
-
},
|
|
567
|
-
|
|
568
|
-
// ToState
|
|
569
|
-
(callback: ErrorCallback) => {
|
|
570
|
-
const reference = browseResults![5].references ? browseResults![5].references![0] : null;
|
|
571
|
-
// fromState
|
|
572
|
-
if (reference) {
|
|
573
|
-
return addToState(proxyManager, obj, reference, callback);
|
|
574
|
-
}
|
|
575
|
-
callback();
|
|
576
|
-
},
|
|
577
|
-
|
|
578
|
-
// Organizes
|
|
579
|
-
(callback: ErrorCallback) => {
|
|
580
|
-
async.mapSeries(
|
|
581
|
-
browseResults![6].references!,
|
|
582
|
-
(reference: ReferenceDescription, callback: ErrorCallback) =>
|
|
583
|
-
addFolderElement(proxyManager, obj, reference, callback),
|
|
584
|
-
(err) => callback(err!)
|
|
585
|
-
);
|
|
586
|
-
}
|
|
587
|
-
],
|
|
588
|
-
(err) => callback(err!)
|
|
589
|
-
);
|
|
590
|
-
});
|
|
407
|
+
const promises: Promise<void>[] = [];
|
|
408
|
+
|
|
409
|
+
for (const reference of browseResults[0].references || []) {
|
|
410
|
+
promises.push(add_component(proxyManager, obj, reference));
|
|
411
|
+
}
|
|
412
|
+
for (const reference of browseResults[1].references || []) {
|
|
413
|
+
promises.push(add_property(proxyManager, obj, reference));
|
|
414
|
+
}
|
|
415
|
+
for (const reference of browseResults[2].references || []) {
|
|
416
|
+
promises.push(add_method(proxyManager, obj, reference));
|
|
417
|
+
}
|
|
418
|
+
browseResults[3].references &&
|
|
419
|
+
browseResults[3].references.length &&
|
|
420
|
+
promises.push(add_typeDefinition(proxyManager, obj, browseResults[3].references || []));
|
|
421
|
+
browseResults[4].references &&
|
|
422
|
+
browseResults[4].references.length &&
|
|
423
|
+
promises.push(addFromState(proxyManager, obj, browseResults[4].references[0]));
|
|
424
|
+
browseResults[5].references &&
|
|
425
|
+
browseResults[5].references.length &&
|
|
426
|
+
promises.push(addToState(proxyManager, obj, browseResults[5].references[0]));
|
|
427
|
+
for (const reference of browseResults[6].references || []) {
|
|
428
|
+
promises.push(addFolderElement(proxyManager, obj, reference));
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
await Promise.all(promises);
|
|
432
|
+
return obj as ProxyNode;
|
|
591
433
|
}
|