node-opcua-client-dynamic-extension-object 2.97.0 → 2.98.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.
- package/dist/convert_data_type_definition_to_structuretype_schema.d.ts +14 -14
- package/dist/convert_data_type_definition_to_structuretype_schema.js +410 -410
- package/dist/convert_structuretype_schema_to_structure_definition.d.ts +3 -3
- package/dist/convert_structuretype_schema_to_structure_definition.js +53 -53
- package/dist/extra_data_type_manager.d.ts +16 -16
- package/dist/extra_data_type_manager.js +78 -78
- package/dist/get_extension_object_constructor.d.ts +7 -7
- package/dist/get_extension_object_constructor.js +37 -37
- package/dist/get_extra_data_type_manager.d.ts +3 -3
- package/dist/get_extra_data_type_manager.js +51 -51
- package/dist/index.d.ts +13 -13
- package/dist/index.js +29 -29
- package/dist/populate_data_type_manager.d.ts +3 -3
- package/dist/populate_data_type_manager.js +88 -88
- package/dist/private/find_encodings.d.ts +4 -4
- package/dist/private/find_encodings.js +55 -55
- package/dist/private/populate_data_type_manager_103.d.ts +9 -9
- package/dist/private/populate_data_type_manager_103.js +639 -639
- package/dist/private/populate_data_type_manager_104.d.ts +9 -9
- package/dist/private/populate_data_type_manager_104.js +217 -217
- package/dist/promote_opaque_structure.d.ts +7 -7
- package/dist/promote_opaque_structure.js +46 -46
- package/dist/promote_opaque_structure_in_notification_data.d.ts +3 -3
- package/dist/promote_opaque_structure_in_notification_data.js +51 -51
- package/dist/resolve_dynamic_extension_object.d.ts +6 -6
- package/dist/resolve_dynamic_extension_object.js +177 -177
- package/package.json +22 -18
- package/test/test_convertStructureTypeSchemaToStructureDefinition.ts +0 -117
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.promoteOpaqueStructureInNotificationData = void 0;
|
|
13
|
-
const node_opcua_types_1 = require("node-opcua-types");
|
|
14
|
-
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
15
|
-
const promote_opaque_structure_1 = require("./promote_opaque_structure");
|
|
16
|
-
function promoteOpaqueStructureInNotificationData(session, notificationData) {
|
|
17
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
const dataValuesToPromote = [];
|
|
19
|
-
for (const notification of notificationData) {
|
|
20
|
-
if (!notification) {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
if (notification instanceof node_opcua_types_1.DataChangeNotification) {
|
|
24
|
-
if (notification.monitoredItems) {
|
|
25
|
-
for (const monitoredItem of notification.monitoredItems) {
|
|
26
|
-
if (monitoredItem.value.value && monitoredItem.value.value.dataType === node_opcua_variant_1.DataType.ExtensionObject) {
|
|
27
|
-
dataValuesToPromote.push(monitoredItem.value);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
else if (notification instanceof node_opcua_types_1.EventNotificationList) {
|
|
33
|
-
if (notification.events) {
|
|
34
|
-
for (const events of notification.events) {
|
|
35
|
-
if (events.eventFields) {
|
|
36
|
-
// eslint-disable-next-line max-depth
|
|
37
|
-
for (const eventField of events.eventFields) {
|
|
38
|
-
// eslint-disable-next-line max-depth
|
|
39
|
-
if (eventField.dataType === node_opcua_variant_1.DataType.ExtensionObject) {
|
|
40
|
-
dataValuesToPromote.push({ value: eventField });
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
yield (0, promote_opaque_structure_1.promoteOpaqueStructure)(session, dataValuesToPromote);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
exports.promoteOpaqueStructureInNotificationData = promoteOpaqueStructureInNotificationData;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.promoteOpaqueStructureInNotificationData = void 0;
|
|
13
|
+
const node_opcua_types_1 = require("node-opcua-types");
|
|
14
|
+
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
15
|
+
const promote_opaque_structure_1 = require("./promote_opaque_structure");
|
|
16
|
+
function promoteOpaqueStructureInNotificationData(session, notificationData) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const dataValuesToPromote = [];
|
|
19
|
+
for (const notification of notificationData) {
|
|
20
|
+
if (!notification) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (notification instanceof node_opcua_types_1.DataChangeNotification) {
|
|
24
|
+
if (notification.monitoredItems) {
|
|
25
|
+
for (const monitoredItem of notification.monitoredItems) {
|
|
26
|
+
if (monitoredItem.value.value && monitoredItem.value.value.dataType === node_opcua_variant_1.DataType.ExtensionObject) {
|
|
27
|
+
dataValuesToPromote.push(monitoredItem.value);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else if (notification instanceof node_opcua_types_1.EventNotificationList) {
|
|
33
|
+
if (notification.events) {
|
|
34
|
+
for (const events of notification.events) {
|
|
35
|
+
if (events.eventFields) {
|
|
36
|
+
// eslint-disable-next-line max-depth
|
|
37
|
+
for (const eventField of events.eventFields) {
|
|
38
|
+
// eslint-disable-next-line max-depth
|
|
39
|
+
if (eventField.dataType === node_opcua_variant_1.DataType.ExtensionObject) {
|
|
40
|
+
dataValuesToPromote.push({ value: eventField });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
yield (0, promote_opaque_structure_1.promoteOpaqueStructure)(session, dataValuesToPromote);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.promoteOpaqueStructureInNotificationData = promoteOpaqueStructureInNotificationData;
|
|
52
52
|
//# sourceMappingURL=promote_opaque_structure_in_notification_data.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ExtensionObject } from "node-opcua-extension-object";
|
|
2
|
-
import { Variant } from "node-opcua-variant";
|
|
3
|
-
import { IBasicSession } from "node-opcua-pseudo-session";
|
|
4
|
-
import { ExtraDataTypeManager } from "./extra_data_type_manager";
|
|
5
|
-
export declare function resolveOpaqueStructureInExtentionObject(session: IBasicSession, dataTypeManager: ExtraDataTypeManager, object: ExtensionObject): Promise<void>;
|
|
6
|
-
export declare function resolveDynamicExtensionObject(session: IBasicSession, variant: Variant, dataTypeManager: ExtraDataTypeManager): Promise<void>;
|
|
1
|
+
import { ExtensionObject } from "node-opcua-extension-object";
|
|
2
|
+
import { Variant } from "node-opcua-variant";
|
|
3
|
+
import { IBasicSession } from "node-opcua-pseudo-session";
|
|
4
|
+
import { ExtraDataTypeManager } from "./extra_data_type_manager";
|
|
5
|
+
export declare function resolveOpaqueStructureInExtentionObject(session: IBasicSession, dataTypeManager: ExtraDataTypeManager, object: ExtensionObject): Promise<void>;
|
|
6
|
+
export declare function resolveDynamicExtensionObject(session: IBasicSession, variant: Variant, dataTypeManager: ExtraDataTypeManager): Promise<void>;
|
|
@@ -1,178 +1,178 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.resolveDynamicExtensionObject = exports.resolveOpaqueStructureInExtentionObject = void 0;
|
|
13
|
-
const node_opcua_binary_stream_1 = require("node-opcua-binary-stream");
|
|
14
|
-
const node_opcua_extension_object_1 = require("node-opcua-extension-object");
|
|
15
|
-
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
16
|
-
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
17
|
-
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
18
|
-
const populate_data_type_manager_104_1 = require("./private/populate_data_type_manager_104");
|
|
19
|
-
const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
|
|
20
|
-
function getOrExtractConstructor(session, binaryEncodingNodeId, dataTypeManager) {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
const dataTypeFactory = dataTypeManager.getDataTypeFactoryForNamespace(binaryEncodingNodeId.namespace);
|
|
23
|
-
const Constructor = dataTypeFactory.getConstructor(binaryEncodingNodeId);
|
|
24
|
-
if (Constructor) {
|
|
25
|
-
return Constructor;
|
|
26
|
-
}
|
|
27
|
-
if (binaryEncodingNodeId.namespace === 0) {
|
|
28
|
-
throw new Error("Internal Error");
|
|
29
|
-
}
|
|
30
|
-
// need to extract it
|
|
31
|
-
const browseResult = yield session.browse({
|
|
32
|
-
nodeId: binaryEncodingNodeId,
|
|
33
|
-
referenceTypeId: "HasEncoding",
|
|
34
|
-
browseDirection: node_opcua_data_model_1.BrowseDirection.Inverse,
|
|
35
|
-
includeSubtypes: false,
|
|
36
|
-
nodeClassMask: node_opcua_data_model_1.NodeClassMask.DataType,
|
|
37
|
-
resultMask: node_opcua_data_model_1.ResultMask.BrowseName
|
|
38
|
-
});
|
|
39
|
-
if (browseResult.statusCode.isNotGood() || browseResult.references.length !== 1) {
|
|
40
|
-
throw new Error("browse failed");
|
|
41
|
-
}
|
|
42
|
-
const r = browseResult.references[0];
|
|
43
|
-
const dataTypeNodeId = r.nodeId;
|
|
44
|
-
if (dataTypeFactory.getStructureInfoForDataType(dataTypeNodeId)) {
|
|
45
|
-
throw new Error("Internal Error: we are not expecting this dataType to be processed already " + dataTypeNodeId.toString());
|
|
46
|
-
}
|
|
47
|
-
yield (0, populate_data_type_manager_104_1.readDataTypeDefinitionAndBuildType)(session, dataTypeNodeId, r.browseName.name, dataTypeFactory, {});
|
|
48
|
-
const structureInfo = dataTypeFactory.getStructureInfoForDataType(dataTypeNodeId);
|
|
49
|
-
if (!structureInfo.constructor) {
|
|
50
|
-
throw new Error("Cannot find constructor for abstract DataType");
|
|
51
|
-
}
|
|
52
|
-
return structureInfo.constructor;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
function resolveOpaqueStructureInExtentionObject(session, dataTypeManager, object) {
|
|
56
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
const schema = object.schema;
|
|
58
|
-
function fixOpaqueStructureOnElement(element, field, data, args) {
|
|
59
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
if (element instanceof node_opcua_variant_1.Variant) {
|
|
61
|
-
yield resolveDynamicExtensionObject(session, element, dataTypeManager);
|
|
62
|
-
return element;
|
|
63
|
-
}
|
|
64
|
-
if (!(element instanceof node_opcua_extension_object_1.OpaqueStructure)) {
|
|
65
|
-
return element;
|
|
66
|
-
}
|
|
67
|
-
const variant = new node_opcua_variant_1.Variant({ dataType: node_opcua_variant_1.DataType.ExtensionObject, value: element });
|
|
68
|
-
yield resolveDynamicExtensionObject(session, variant, dataTypeManager);
|
|
69
|
-
return variant.value;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
function fixOpaqueStructure(object, field, data, args) {
|
|
73
|
-
if (field.category === "complex" && !field.allowSubType) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (field.category === "basic" && field.fieldType !== "Variant") {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
console.log("field", field.name, field.category, field.fieldType);
|
|
80
|
-
const a = object[field.name];
|
|
81
|
-
if (!a) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
if (field.isArray) {
|
|
85
|
-
for (let i = 0; i < a.length; i++) {
|
|
86
|
-
const x = a[i];
|
|
87
|
-
promises.push((() => __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
a[i] = yield fixOpaqueStructureOnElement(x, field, data, args);
|
|
89
|
-
}))());
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
promises.push((() => __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
object[field.name] = yield fixOpaqueStructureOnElement(a, field, data, args);
|
|
95
|
-
}))());
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const promises = [];
|
|
99
|
-
object.applyOnAllFields(fixOpaqueStructure, { dataTypeManager, promises });
|
|
100
|
-
yield Promise.all(promises);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
exports.resolveOpaqueStructureInExtentionObject = resolveOpaqueStructureInExtentionObject;
|
|
104
|
-
// async function resolveInnerVariantType(session: IBasicSession, object: ExtensionObject, dataTypeManager: ExtraDataTypeManager) {
|
|
105
|
-
// console.log("object = ", object.constructor.name);
|
|
106
|
-
// const fields = object.schema.fields;
|
|
107
|
-
// const _object = object as unknown as Record<string, unknown>;
|
|
108
|
-
// for (const field of fields) {
|
|
109
|
-
// console.log("field = ", field.name);
|
|
110
|
-
// if (field.category !== "complex") continue;
|
|
111
|
-
// const p = _object[field.name];
|
|
112
|
-
// if (p === undefined || p === null) continue;
|
|
113
|
-
// console.log("=>", field.name, (p as any).toString());
|
|
114
|
-
// if (p instanceof ExtensionObject) {
|
|
115
|
-
// resolveInnerVariantType(session, p, dataTypeManager);
|
|
116
|
-
// }
|
|
117
|
-
// if (p instanceof Variant && p.value instanceof OpaqueStructure) {
|
|
118
|
-
// console.log("§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§");
|
|
119
|
-
// p.value = resolveDynamicExtensionObjectV(session, p.value, dataTypeManager);
|
|
120
|
-
// }
|
|
121
|
-
// }
|
|
122
|
-
// }
|
|
123
|
-
function resolveDynamicExtensionObjectV(session, opaque, dataTypeManager) {
|
|
124
|
-
var _a;
|
|
125
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
-
try {
|
|
127
|
-
const Constructor = yield getOrExtractConstructor(session, opaque.nodeId, dataTypeManager);
|
|
128
|
-
const object = new Constructor();
|
|
129
|
-
const stream = new node_opcua_binary_stream_1.BinaryStream(opaque.buffer);
|
|
130
|
-
try {
|
|
131
|
-
object.decode(stream);
|
|
132
|
-
yield resolveOpaqueStructureInExtentionObject(session, dataTypeManager, object);
|
|
133
|
-
return object;
|
|
134
|
-
}
|
|
135
|
-
catch (err) {
|
|
136
|
-
warningLog("Constructor = ", Constructor.name);
|
|
137
|
-
warningLog("opaqueStructure = ", (_a = opaque === null || opaque === void 0 ? void 0 : opaque.nodeId) === null || _a === void 0 ? void 0 : _a.toString());
|
|
138
|
-
warningLog("opaqueStructure = ", (0, node_opcua_debug_1.hexDump)(opaque.buffer, 132, 100));
|
|
139
|
-
warningLog((0, node_opcua_debug_1.hexDump)(opaque.buffer));
|
|
140
|
-
warningLog("resolveDynamicExtensionObjectV err = ", err);
|
|
141
|
-
// try again for debugging
|
|
142
|
-
object.decode(stream);
|
|
143
|
-
return opaque;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
catch (err) {
|
|
147
|
-
warningLog("err", err);
|
|
148
|
-
warningLog("opaqueStructure = ", opaque.nodeId.toString());
|
|
149
|
-
warningLog("opaqueStructure = ", "0x" + (0, node_opcua_debug_1.hexDump)(opaque.buffer, 132, 100));
|
|
150
|
-
warningLog((0, node_opcua_debug_1.hexDump)(opaque.buffer));
|
|
151
|
-
warningLog(dataTypeManager.toString());
|
|
152
|
-
throw err;
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
function resolveDynamicExtensionObject(session, variant, dataTypeManager) {
|
|
157
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
-
if (variant.dataType !== node_opcua_variant_1.DataType.ExtensionObject) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
if (variant.arrayType !== node_opcua_variant_1.VariantArrayType.Scalar) {
|
|
162
|
-
if (variant.value instanceof Array) {
|
|
163
|
-
for (let i = 0; i < variant.value.length; i++) {
|
|
164
|
-
if (variant.value[i] instanceof node_opcua_extension_object_1.OpaqueStructure) {
|
|
165
|
-
variant.value[i] = yield resolveDynamicExtensionObjectV(session, variant.value[i], dataTypeManager);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
if (!(variant.value instanceof node_opcua_extension_object_1.OpaqueStructure)) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
variant.value = yield resolveDynamicExtensionObjectV(session, variant.value, dataTypeManager);
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
exports.resolveDynamicExtensionObject = resolveDynamicExtensionObject;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.resolveDynamicExtensionObject = exports.resolveOpaqueStructureInExtentionObject = void 0;
|
|
13
|
+
const node_opcua_binary_stream_1 = require("node-opcua-binary-stream");
|
|
14
|
+
const node_opcua_extension_object_1 = require("node-opcua-extension-object");
|
|
15
|
+
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
16
|
+
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
17
|
+
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
18
|
+
const populate_data_type_manager_104_1 = require("./private/populate_data_type_manager_104");
|
|
19
|
+
const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
|
|
20
|
+
function getOrExtractConstructor(session, binaryEncodingNodeId, dataTypeManager) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const dataTypeFactory = dataTypeManager.getDataTypeFactoryForNamespace(binaryEncodingNodeId.namespace);
|
|
23
|
+
const Constructor = dataTypeFactory.getConstructor(binaryEncodingNodeId);
|
|
24
|
+
if (Constructor) {
|
|
25
|
+
return Constructor;
|
|
26
|
+
}
|
|
27
|
+
if (binaryEncodingNodeId.namespace === 0) {
|
|
28
|
+
throw new Error("Internal Error");
|
|
29
|
+
}
|
|
30
|
+
// need to extract it
|
|
31
|
+
const browseResult = yield session.browse({
|
|
32
|
+
nodeId: binaryEncodingNodeId,
|
|
33
|
+
referenceTypeId: "HasEncoding",
|
|
34
|
+
browseDirection: node_opcua_data_model_1.BrowseDirection.Inverse,
|
|
35
|
+
includeSubtypes: false,
|
|
36
|
+
nodeClassMask: node_opcua_data_model_1.NodeClassMask.DataType,
|
|
37
|
+
resultMask: node_opcua_data_model_1.ResultMask.BrowseName
|
|
38
|
+
});
|
|
39
|
+
if (browseResult.statusCode.isNotGood() || browseResult.references.length !== 1) {
|
|
40
|
+
throw new Error("browse failed");
|
|
41
|
+
}
|
|
42
|
+
const r = browseResult.references[0];
|
|
43
|
+
const dataTypeNodeId = r.nodeId;
|
|
44
|
+
if (dataTypeFactory.getStructureInfoForDataType(dataTypeNodeId)) {
|
|
45
|
+
throw new Error("Internal Error: we are not expecting this dataType to be processed already " + dataTypeNodeId.toString());
|
|
46
|
+
}
|
|
47
|
+
yield (0, populate_data_type_manager_104_1.readDataTypeDefinitionAndBuildType)(session, dataTypeNodeId, r.browseName.name, dataTypeFactory, {});
|
|
48
|
+
const structureInfo = dataTypeFactory.getStructureInfoForDataType(dataTypeNodeId);
|
|
49
|
+
if (!structureInfo.constructor) {
|
|
50
|
+
throw new Error("Cannot find constructor for abstract DataType");
|
|
51
|
+
}
|
|
52
|
+
return structureInfo.constructor;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function resolveOpaqueStructureInExtentionObject(session, dataTypeManager, object) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const schema = object.schema;
|
|
58
|
+
function fixOpaqueStructureOnElement(element, field, data, args) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
if (element instanceof node_opcua_variant_1.Variant) {
|
|
61
|
+
yield resolveDynamicExtensionObject(session, element, dataTypeManager);
|
|
62
|
+
return element;
|
|
63
|
+
}
|
|
64
|
+
if (!(element instanceof node_opcua_extension_object_1.OpaqueStructure)) {
|
|
65
|
+
return element;
|
|
66
|
+
}
|
|
67
|
+
const variant = new node_opcua_variant_1.Variant({ dataType: node_opcua_variant_1.DataType.ExtensionObject, value: element });
|
|
68
|
+
yield resolveDynamicExtensionObject(session, variant, dataTypeManager);
|
|
69
|
+
return variant.value;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function fixOpaqueStructure(object, field, data, args) {
|
|
73
|
+
if (field.category === "complex" && !field.allowSubType) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (field.category === "basic" && field.fieldType !== "Variant") {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
console.log("field", field.name, field.category, field.fieldType);
|
|
80
|
+
const a = object[field.name];
|
|
81
|
+
if (!a) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (field.isArray) {
|
|
85
|
+
for (let i = 0; i < a.length; i++) {
|
|
86
|
+
const x = a[i];
|
|
87
|
+
promises.push((() => __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
a[i] = yield fixOpaqueStructureOnElement(x, field, data, args);
|
|
89
|
+
}))());
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
promises.push((() => __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
object[field.name] = yield fixOpaqueStructureOnElement(a, field, data, args);
|
|
95
|
+
}))());
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const promises = [];
|
|
99
|
+
object.applyOnAllFields(fixOpaqueStructure, { dataTypeManager, promises });
|
|
100
|
+
yield Promise.all(promises);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
exports.resolveOpaqueStructureInExtentionObject = resolveOpaqueStructureInExtentionObject;
|
|
104
|
+
// async function resolveInnerVariantType(session: IBasicSession, object: ExtensionObject, dataTypeManager: ExtraDataTypeManager) {
|
|
105
|
+
// console.log("object = ", object.constructor.name);
|
|
106
|
+
// const fields = object.schema.fields;
|
|
107
|
+
// const _object = object as unknown as Record<string, unknown>;
|
|
108
|
+
// for (const field of fields) {
|
|
109
|
+
// console.log("field = ", field.name);
|
|
110
|
+
// if (field.category !== "complex") continue;
|
|
111
|
+
// const p = _object[field.name];
|
|
112
|
+
// if (p === undefined || p === null) continue;
|
|
113
|
+
// console.log("=>", field.name, (p as any).toString());
|
|
114
|
+
// if (p instanceof ExtensionObject) {
|
|
115
|
+
// resolveInnerVariantType(session, p, dataTypeManager);
|
|
116
|
+
// }
|
|
117
|
+
// if (p instanceof Variant && p.value instanceof OpaqueStructure) {
|
|
118
|
+
// console.log("§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§");
|
|
119
|
+
// p.value = resolveDynamicExtensionObjectV(session, p.value, dataTypeManager);
|
|
120
|
+
// }
|
|
121
|
+
// }
|
|
122
|
+
// }
|
|
123
|
+
function resolveDynamicExtensionObjectV(session, opaque, dataTypeManager) {
|
|
124
|
+
var _a;
|
|
125
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
try {
|
|
127
|
+
const Constructor = yield getOrExtractConstructor(session, opaque.nodeId, dataTypeManager);
|
|
128
|
+
const object = new Constructor();
|
|
129
|
+
const stream = new node_opcua_binary_stream_1.BinaryStream(opaque.buffer);
|
|
130
|
+
try {
|
|
131
|
+
object.decode(stream);
|
|
132
|
+
yield resolveOpaqueStructureInExtentionObject(session, dataTypeManager, object);
|
|
133
|
+
return object;
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
warningLog("Constructor = ", Constructor.name);
|
|
137
|
+
warningLog("opaqueStructure = ", (_a = opaque === null || opaque === void 0 ? void 0 : opaque.nodeId) === null || _a === void 0 ? void 0 : _a.toString());
|
|
138
|
+
warningLog("opaqueStructure = ", (0, node_opcua_debug_1.hexDump)(opaque.buffer, 132, 100));
|
|
139
|
+
warningLog((0, node_opcua_debug_1.hexDump)(opaque.buffer));
|
|
140
|
+
warningLog("resolveDynamicExtensionObjectV err = ", err);
|
|
141
|
+
// try again for debugging
|
|
142
|
+
object.decode(stream);
|
|
143
|
+
return opaque;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
warningLog("err", err);
|
|
148
|
+
warningLog("opaqueStructure = ", opaque.nodeId.toString());
|
|
149
|
+
warningLog("opaqueStructure = ", "0x" + (0, node_opcua_debug_1.hexDump)(opaque.buffer, 132, 100));
|
|
150
|
+
warningLog((0, node_opcua_debug_1.hexDump)(opaque.buffer));
|
|
151
|
+
warningLog(dataTypeManager.toString());
|
|
152
|
+
throw err;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function resolveDynamicExtensionObject(session, variant, dataTypeManager) {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
if (variant.dataType !== node_opcua_variant_1.DataType.ExtensionObject) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (variant.arrayType !== node_opcua_variant_1.VariantArrayType.Scalar) {
|
|
162
|
+
if (variant.value instanceof Array) {
|
|
163
|
+
for (let i = 0; i < variant.value.length; i++) {
|
|
164
|
+
if (variant.value[i] instanceof node_opcua_extension_object_1.OpaqueStructure) {
|
|
165
|
+
variant.value[i] = yield resolveDynamicExtensionObjectV(session, variant.value[i], dataTypeManager);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (!(variant.value instanceof node_opcua_extension_object_1.OpaqueStructure)) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
variant.value = yield resolveDynamicExtensionObjectV(session, variant.value, dataTypeManager);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
exports.resolveDynamicExtensionObject = resolveDynamicExtensionObject;
|
|
178
178
|
//# sourceMappingURL=resolve_dynamic_extension_object.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-opcua-client-dynamic-extension-object",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.98.1",
|
|
4
4
|
"description": "pure nodejs OPCUA SDK - module client-dynamic-extension-object",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -11,22 +11,22 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"chalk": "4.1.2",
|
|
14
|
-
"node-opcua-assert": "2.
|
|
15
|
-
"node-opcua-binary-stream": "2.
|
|
16
|
-
"node-opcua-constants": "2.
|
|
17
|
-
"node-opcua-data-model": "2.
|
|
18
|
-
"node-opcua-data-value": "2.
|
|
19
|
-
"node-opcua-debug": "2.
|
|
20
|
-
"node-opcua-extension-object": "2.
|
|
21
|
-
"node-opcua-factory": "2.
|
|
22
|
-
"node-opcua-nodeid": "2.
|
|
23
|
-
"node-opcua-pseudo-session": "2.
|
|
24
|
-
"node-opcua-schemas": "2.
|
|
25
|
-
"node-opcua-service-browse": "2.
|
|
26
|
-
"node-opcua-service-translate-browse-path": "2.
|
|
27
|
-
"node-opcua-status-code": "2.
|
|
28
|
-
"node-opcua-types": "2.
|
|
29
|
-
"node-opcua-variant": "2.
|
|
14
|
+
"node-opcua-assert": "2.98.1",
|
|
15
|
+
"node-opcua-binary-stream": "2.98.1",
|
|
16
|
+
"node-opcua-constants": "2.98.1",
|
|
17
|
+
"node-opcua-data-model": "2.98.1",
|
|
18
|
+
"node-opcua-data-value": "2.98.1",
|
|
19
|
+
"node-opcua-debug": "2.98.1",
|
|
20
|
+
"node-opcua-extension-object": "2.98.1",
|
|
21
|
+
"node-opcua-factory": "2.98.1",
|
|
22
|
+
"node-opcua-nodeid": "2.98.1",
|
|
23
|
+
"node-opcua-pseudo-session": "2.98.1",
|
|
24
|
+
"node-opcua-schemas": "2.98.1",
|
|
25
|
+
"node-opcua-service-browse": "2.98.1",
|
|
26
|
+
"node-opcua-service-translate-browse-path": "2.98.1",
|
|
27
|
+
"node-opcua-status-code": "2.98.1",
|
|
28
|
+
"node-opcua-types": "2.98.1",
|
|
29
|
+
"node-opcua-variant": "2.98.1"
|
|
30
30
|
},
|
|
31
31
|
"author": "Etienne Rossignon",
|
|
32
32
|
"license": "MIT",
|
|
@@ -43,5 +43,9 @@
|
|
|
43
43
|
"internet of things"
|
|
44
44
|
],
|
|
45
45
|
"homepage": "http://node-opcua.github.io/",
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "07dcdd8e8c7f2b55544c6e23023093e35674829c",
|
|
47
|
+
"files": [
|
|
48
|
+
"dist",
|
|
49
|
+
"source"
|
|
50
|
+
]
|
|
47
51
|
}
|