node-opcua-client-dynamic-extension-object 2.113.0 → 2.116.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/convert_data_type_definition_to_structuretype_schema.js +323 -348
- package/dist/convert_data_type_definition_to_structuretype_schema.js.map +1 -1
- package/dist/convert_structuretype_schema_to_structure_definition.js +1 -2
- package/dist/convert_structuretype_schema_to_structure_definition.js.map +1 -1
- package/dist/get_extension_object_constructor.js +13 -24
- package/dist/get_extension_object_constructor.js.map +1 -1
- package/dist/get_extra_data_type_manager.js +58 -74
- package/dist/get_extra_data_type_manager.js.map +1 -1
- package/dist/populate_data_type_manager.js +91 -104
- package/dist/populate_data_type_manager.js.map +1 -1
- package/dist/private/find_encodings.js +36 -47
- package/dist/private/find_encodings.js.map +1 -1
- package/dist/private/populate_data_type_manager_103.js +450 -482
- package/dist/private/populate_data_type_manager_103.js.map +1 -1
- package/dist/private/populate_data_type_manager_104.js +139 -160
- package/dist/private/populate_data_type_manager_104.js.map +1 -1
- package/dist/promote_opaque_structure.js +11 -22
- package/dist/promote_opaque_structure.js.map +1 -1
- package/dist/promote_opaque_structure_in_notification_data.js +22 -33
- package/dist/promote_opaque_structure_in_notification_data.js.map +1 -1
- package/dist/resolve_dynamic_extension_object.js +107 -127
- package/dist/resolve_dynamic_extension_object.js.map +1 -1
- package/package.json +17 -17
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.convertDataTypeDefinitionToStructureTypeSchema = void 0;
|
|
13
4
|
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
@@ -25,159 +16,149 @@ const find_encodings_1 = require("./private/find_encodings");
|
|
|
25
16
|
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
26
17
|
const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
|
|
27
18
|
const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
|
|
28
|
-
function findSuperType(session, dataTypeNodeId) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return result3.references[0].nodeId;
|
|
54
|
-
});
|
|
19
|
+
async function findSuperType(session, dataTypeNodeId) {
|
|
20
|
+
if (dataTypeNodeId.namespace === 0 && dataTypeNodeId.value === 24) {
|
|
21
|
+
// BaseDataType !
|
|
22
|
+
return (0, node_opcua_nodeid_2.coerceNodeId)(0);
|
|
23
|
+
}
|
|
24
|
+
const nodeToBrowse3 = {
|
|
25
|
+
browseDirection: node_opcua_data_model_1.BrowseDirection.Inverse,
|
|
26
|
+
includeSubtypes: false,
|
|
27
|
+
nodeClassMask: node_opcua_data_model_1.NodeClassMask.DataType,
|
|
28
|
+
nodeId: dataTypeNodeId,
|
|
29
|
+
referenceTypeId: (0, node_opcua_nodeid_2.resolveNodeId)("HasSubtype"),
|
|
30
|
+
resultMask: (0, node_opcua_data_model_1.makeResultMask)("NodeId | ReferenceType | BrowseName | NodeClass")
|
|
31
|
+
};
|
|
32
|
+
const result3 = await (0, node_opcua_pseudo_session_1.browseAll)(session, nodeToBrowse3);
|
|
33
|
+
/* istanbul ignore next */
|
|
34
|
+
if (result3.statusCode.isNotGood()) {
|
|
35
|
+
throw new Error("Cannot find superType for " + dataTypeNodeId.toString());
|
|
36
|
+
}
|
|
37
|
+
result3.references = result3.references || [];
|
|
38
|
+
/* istanbul ignore next */
|
|
39
|
+
if (result3.references.length !== 1) {
|
|
40
|
+
errorLog("Invalid dataType with more than one (or 0) superType", result3.toString());
|
|
41
|
+
throw new Error("Invalid dataType with more than one (or 0) superType " + dataTypeNodeId.toString() + " l=" + result3.references.length);
|
|
42
|
+
}
|
|
43
|
+
return result3.references[0].nodeId;
|
|
55
44
|
}
|
|
56
|
-
function findDataTypeCategory(session, cache, dataTypeNodeId) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
return category;
|
|
45
|
+
async function findDataTypeCategory(session, cache, dataTypeNodeId) {
|
|
46
|
+
const subTypeNodeId = await findSuperType(session, dataTypeNodeId);
|
|
47
|
+
debugLog("subTypeNodeId of ", dataTypeNodeId.toString(), " is ", subTypeNodeId.toString());
|
|
48
|
+
const key = subTypeNodeId.toString();
|
|
49
|
+
if (cache[key]) {
|
|
50
|
+
return cache[key].category;
|
|
51
|
+
}
|
|
52
|
+
let category;
|
|
53
|
+
const n = subTypeNodeId;
|
|
54
|
+
if (n.identifierType === node_opcua_nodeid_1.NodeIdType.NUMERIC && n.namespace === 0 && n.value <= 29) {
|
|
55
|
+
// well known node ID !
|
|
56
|
+
switch (n.value) {
|
|
57
|
+
case 22 /* Structure */:
|
|
58
|
+
category = node_opcua_factory_1.FieldCategory.complex;
|
|
59
|
+
break;
|
|
60
|
+
case 29 /* Enumeration */:
|
|
61
|
+
category = node_opcua_factory_1.FieldCategory.enumeration;
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
category = node_opcua_factory_1.FieldCategory.basic;
|
|
65
|
+
break;
|
|
80
66
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
67
|
+
return category;
|
|
68
|
+
}
|
|
69
|
+
// must drill down ...
|
|
70
|
+
return await findDataTypeCategory(session, cache, subTypeNodeId);
|
|
84
71
|
}
|
|
85
|
-
function findDataTypeBasicType(session, cache, dataTypeNodeId) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
const nameDataValue = yield session.read({
|
|
103
|
-
attributeId: node_opcua_data_model_1.AttributeIds.BrowseName,
|
|
104
|
-
nodeId: subTypeNodeId
|
|
105
|
-
});
|
|
106
|
-
const name = nameDataValue.value.value.name;
|
|
107
|
-
return (0, node_opcua_factory_1.getBuiltInType)(name);
|
|
72
|
+
async function findDataTypeBasicType(session, cache, dataTypeNodeId) {
|
|
73
|
+
const subTypeNodeId = await findSuperType(session, dataTypeNodeId);
|
|
74
|
+
debugLog("subTypeNodeId of ", dataTypeNodeId.toString(), " is ", subTypeNodeId.toString());
|
|
75
|
+
const key = subTypeNodeId.toString();
|
|
76
|
+
if (cache[key]) {
|
|
77
|
+
return cache[key].schema;
|
|
78
|
+
}
|
|
79
|
+
const n = subTypeNodeId;
|
|
80
|
+
if (n.identifierType === node_opcua_nodeid_1.NodeIdType.NUMERIC && n.namespace === 0 && n.value < 29) {
|
|
81
|
+
switch (n.value) {
|
|
82
|
+
case 22: /* Structure */
|
|
83
|
+
case 29 /* Enumeration */:
|
|
84
|
+
throw new Error("Not expecting Structure or Enumeration");
|
|
85
|
+
default:
|
|
86
|
+
break;
|
|
108
87
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
88
|
+
const nameDataValue = await session.read({
|
|
89
|
+
attributeId: node_opcua_data_model_1.AttributeIds.BrowseName,
|
|
90
|
+
nodeId: subTypeNodeId
|
|
91
|
+
});
|
|
92
|
+
const name = nameDataValue.value.value.name;
|
|
93
|
+
return (0, node_opcua_factory_1.getBuiltInType)(name);
|
|
94
|
+
}
|
|
95
|
+
// must drill down ...
|
|
96
|
+
return await findDataTypeBasicType(session, cache, subTypeNodeId);
|
|
112
97
|
}
|
|
113
|
-
function readBrowseName(session, nodeId) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return dataValue.value.value.name;
|
|
122
|
-
});
|
|
98
|
+
async function readBrowseName(session, nodeId) {
|
|
99
|
+
const dataValue = await session.read({ nodeId, attributeId: node_opcua_data_model_1.AttributeIds.BrowseName });
|
|
100
|
+
if (dataValue.statusCode.isNotGood()) {
|
|
101
|
+
const message = "cannot extract BrowseName of nodeId = " + nodeId.toString() + " statusCode = " + dataValue.statusCode.toString();
|
|
102
|
+
debugLog(message);
|
|
103
|
+
throw new Error(message);
|
|
104
|
+
}
|
|
105
|
+
return dataValue.value.value.name;
|
|
123
106
|
}
|
|
124
|
-
function resolve2(session, dataTypeNodeId, dataTypeFactory, fieldTypeName, cache) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
107
|
+
async function resolve2(session, dataTypeNodeId, dataTypeFactory, fieldTypeName, cache) {
|
|
108
|
+
const category = await findDataTypeCategory(session, cache, dataTypeNodeId);
|
|
109
|
+
debugLog(" type " + fieldTypeName + " has not been seen yet, let resolve it => (category = ", category, " )");
|
|
110
|
+
let schema = undefined;
|
|
111
|
+
switch (category) {
|
|
112
|
+
case node_opcua_factory_1.FieldCategory.basic:
|
|
113
|
+
schema = await findDataTypeBasicType(session, cache, dataTypeNodeId);
|
|
114
|
+
/* istanbul ignore next */
|
|
115
|
+
if (!schema) {
|
|
116
|
+
errorLog("Cannot find basic type " + fieldTypeName);
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
default:
|
|
120
|
+
case node_opcua_factory_1.FieldCategory.complex:
|
|
121
|
+
{
|
|
122
|
+
const dataTypeDefinitionDataValue = await session.read({
|
|
123
|
+
attributeId: node_opcua_data_model_1.AttributeIds.DataTypeDefinition,
|
|
124
|
+
nodeId: dataTypeNodeId
|
|
125
|
+
});
|
|
132
126
|
/* istanbul ignore next */
|
|
133
|
-
if (
|
|
134
|
-
|
|
127
|
+
if (dataTypeDefinitionDataValue.statusCode.isNotGood()) {
|
|
128
|
+
throw new Error(" Cannot find dataType Definition ! with nodeId =" + dataTypeNodeId.toString());
|
|
135
129
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const retVal = {};
|
|
152
|
-
fields && fields.forEach((field) => (retVal[field.name || ""] = convertIn64ToInteger(field.value)));
|
|
153
|
-
return retVal;
|
|
154
|
-
};
|
|
155
|
-
if (category === node_opcua_factory_1.FieldCategory.enumeration) {
|
|
156
|
-
if (definition instanceof node_opcua_types_1.EnumDefinition) {
|
|
157
|
-
const e = new node_opcua_factory_1.EnumerationDefinitionSchema(dataTypeNodeId, {
|
|
158
|
-
enumValues: convert(definition.fields),
|
|
159
|
-
name: fieldTypeName
|
|
160
|
-
});
|
|
161
|
-
dataTypeFactory.registerEnumeration(e);
|
|
162
|
-
schema = e;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
const isAbstract = false;
|
|
167
|
-
schema = yield convertDataTypeDefinitionToStructureTypeSchema(session, dataTypeNodeId, fieldTypeName, definition, dataTypeFactory, isAbstract, cache);
|
|
130
|
+
const definition = dataTypeDefinitionDataValue.value.value;
|
|
131
|
+
const convertIn64ToInteger = (a) => a[1];
|
|
132
|
+
const convert = (fields) => {
|
|
133
|
+
const retVal = {};
|
|
134
|
+
fields && fields.forEach((field) => (retVal[field.name || ""] = convertIn64ToInteger(field.value)));
|
|
135
|
+
return retVal;
|
|
136
|
+
};
|
|
137
|
+
if (category === node_opcua_factory_1.FieldCategory.enumeration) {
|
|
138
|
+
if (definition instanceof node_opcua_types_1.EnumDefinition) {
|
|
139
|
+
const e = new node_opcua_factory_1.EnumerationDefinitionSchema(dataTypeNodeId, {
|
|
140
|
+
enumValues: convert(definition.fields),
|
|
141
|
+
name: fieldTypeName
|
|
142
|
+
});
|
|
143
|
+
dataTypeFactory.registerEnumeration(e);
|
|
144
|
+
schema = e;
|
|
168
145
|
}
|
|
169
|
-
// xx const schema1 = dataTypeFactory.getStructuredTypeSchema(fieldTypeName);
|
|
170
146
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
147
|
+
else {
|
|
148
|
+
const isAbstract = false;
|
|
149
|
+
schema = await convertDataTypeDefinitionToStructureTypeSchema(session, dataTypeNodeId, fieldTypeName, definition, dataTypeFactory, isAbstract, cache);
|
|
150
|
+
}
|
|
151
|
+
// xx const schema1 = dataTypeFactory.getStructuredTypeSchema(fieldTypeName);
|
|
152
|
+
}
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
return { schema, category };
|
|
175
156
|
}
|
|
176
|
-
const isExtensionObject = (session, dataTypeNodeId) =>
|
|
157
|
+
const isExtensionObject = async (session, dataTypeNodeId) => {
|
|
177
158
|
if (dataTypeNodeId.namespace === 0 && dataTypeNodeId.value === node_opcua_variant_1.DataType.ExtensionObject) {
|
|
178
159
|
return true;
|
|
179
160
|
}
|
|
180
|
-
const baseDataType =
|
|
161
|
+
const baseDataType = await findSuperType(session, dataTypeNodeId);
|
|
181
162
|
const bn = baseDataType;
|
|
182
163
|
if (bn.identifierType === node_opcua_nodeid_1.NodeIdType.NUMERIC) {
|
|
183
164
|
if (bn.namespace === 0 && bn.value === node_opcua_variant_1.DataType.ExtensionObject) {
|
|
@@ -187,224 +168,218 @@ const isExtensionObject = (session, dataTypeNodeId) => __awaiter(void 0, void 0,
|
|
|
187
168
|
return false;
|
|
188
169
|
}
|
|
189
170
|
}
|
|
190
|
-
return
|
|
191
|
-
}
|
|
171
|
+
return await isExtensionObject(session, baseDataType);
|
|
172
|
+
};
|
|
192
173
|
// eslint-disable-next-line max-statements
|
|
193
|
-
function resolveFieldType(session, dataTypeNodeId, dataTypeFactory, cache) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
174
|
+
async function resolveFieldType(session, dataTypeNodeId, dataTypeFactory, cache) {
|
|
175
|
+
if (dataTypeNodeId.namespace === 0 && dataTypeNodeId.value === 22) {
|
|
176
|
+
// ERN return null;
|
|
177
|
+
const category = node_opcua_factory_1.FieldCategory.complex;
|
|
178
|
+
const fieldTypeName = "Structure";
|
|
179
|
+
const schema = node_opcua_extension_object_1.ExtensionObject.schema;
|
|
180
|
+
return {
|
|
181
|
+
category,
|
|
182
|
+
fieldTypeName,
|
|
183
|
+
schema,
|
|
184
|
+
allowSubType: true,
|
|
185
|
+
dataType: (0, node_opcua_nodeid_2.coerceNodeId)(node_opcua_variant_1.DataType.ExtensionObject)
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
const key = dataTypeNodeId.toString();
|
|
189
|
+
const v = cache[key];
|
|
190
|
+
if (v) {
|
|
191
|
+
return v;
|
|
192
|
+
}
|
|
193
|
+
if (dataTypeNodeId.value === 0) {
|
|
194
|
+
const v3 = {
|
|
195
|
+
category: node_opcua_factory_1.FieldCategory.basic,
|
|
196
|
+
fieldTypeName: "Variant",
|
|
197
|
+
schema: dataTypeFactory.getBuiltInType("Variant")
|
|
198
|
+
};
|
|
199
|
+
cache[key] = v3;
|
|
200
|
+
return v3;
|
|
201
|
+
}
|
|
202
|
+
const isAbstract = (await session.read({ nodeId: dataTypeNodeId, attributeId: node_opcua_data_model_1.AttributeIds.IsAbstract })).value.value;
|
|
203
|
+
const fieldTypeName = await readBrowseName(session, dataTypeNodeId);
|
|
204
|
+
if (isAbstract) {
|
|
205
|
+
const _isExtensionObject = await isExtensionObject(session, dataTypeNodeId);
|
|
206
|
+
debugLog(" dataType " + dataTypeNodeId.toString() + " " + fieldTypeName + " is abstract => extObj ?= " + _isExtensionObject);
|
|
207
|
+
if (_isExtensionObject) {
|
|
208
|
+
// we could have complex => Structure
|
|
209
|
+
const v3 = {
|
|
210
|
+
category: node_opcua_factory_1.FieldCategory.complex,
|
|
211
|
+
fieldTypeName: fieldTypeName,
|
|
212
|
+
schema: node_opcua_extension_object_1.ExtensionObject.schema,
|
|
204
213
|
allowSubType: true,
|
|
205
|
-
dataType:
|
|
214
|
+
dataType: dataTypeNodeId
|
|
206
215
|
};
|
|
216
|
+
cache[key] = v3;
|
|
217
|
+
return v3;
|
|
207
218
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
if (v) {
|
|
211
|
-
return v;
|
|
212
|
-
}
|
|
213
|
-
if (dataTypeNodeId.value === 0) {
|
|
219
|
+
else {
|
|
220
|
+
// we could have basic => Variant
|
|
214
221
|
const v3 = {
|
|
215
222
|
category: node_opcua_factory_1.FieldCategory.basic,
|
|
216
|
-
fieldTypeName:
|
|
217
|
-
schema: dataTypeFactory.getBuiltInType("Variant")
|
|
223
|
+
fieldTypeName: fieldTypeName,
|
|
224
|
+
schema: dataTypeFactory.getBuiltInType("Variant"),
|
|
225
|
+
allowSubType: true,
|
|
226
|
+
dataType: dataTypeNodeId
|
|
218
227
|
};
|
|
219
228
|
cache[key] = v3;
|
|
220
229
|
return v3;
|
|
221
230
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (dataTypeFactory.hasStructureByTypeName(fieldTypeName)) {
|
|
255
|
-
schema = dataTypeFactory.getStructuredTypeSchema(fieldTypeName);
|
|
256
|
-
category = node_opcua_factory_1.FieldCategory.complex;
|
|
257
|
-
}
|
|
258
|
-
else if (dataTypeFactory.hasBuiltInType(fieldTypeName)) {
|
|
259
|
-
category = node_opcua_factory_1.FieldCategory.basic;
|
|
260
|
-
schema = dataTypeFactory.getBuiltInType(fieldTypeName);
|
|
261
|
-
}
|
|
262
|
-
else if (dataTypeFactory.hasEnumeration(fieldTypeName)) {
|
|
263
|
-
category = node_opcua_factory_1.FieldCategory.enumeration;
|
|
264
|
-
schema = dataTypeFactory.getEnumeration(fieldTypeName);
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
debugLog(" type " + fieldTypeName + " has not been seen yet, let resolve it");
|
|
268
|
-
const res = yield resolve2(session, dataTypeNodeId, dataTypeFactory, fieldTypeName, cache);
|
|
269
|
-
schema = res.schema;
|
|
270
|
-
category = res.category;
|
|
271
|
-
}
|
|
272
|
-
/* istanbul ignore next */
|
|
273
|
-
if (!schema) {
|
|
274
|
-
throw new Error("expecting a schema here fieldTypeName=" + fieldTypeName + " " + dataTypeNodeId.toString() + " category = " + category);
|
|
275
|
-
}
|
|
276
|
-
const v2 = {
|
|
277
|
-
category,
|
|
278
|
-
fieldTypeName,
|
|
279
|
-
schema
|
|
280
|
-
};
|
|
281
|
-
cache[key] = v2;
|
|
282
|
-
return v2;
|
|
283
|
-
});
|
|
231
|
+
}
|
|
232
|
+
let schema;
|
|
233
|
+
let category = node_opcua_factory_1.FieldCategory.enumeration;
|
|
234
|
+
if (dataTypeFactory.hasStructureByTypeName(fieldTypeName)) {
|
|
235
|
+
schema = dataTypeFactory.getStructuredTypeSchema(fieldTypeName);
|
|
236
|
+
category = node_opcua_factory_1.FieldCategory.complex;
|
|
237
|
+
}
|
|
238
|
+
else if (dataTypeFactory.hasBuiltInType(fieldTypeName)) {
|
|
239
|
+
category = node_opcua_factory_1.FieldCategory.basic;
|
|
240
|
+
schema = dataTypeFactory.getBuiltInType(fieldTypeName);
|
|
241
|
+
}
|
|
242
|
+
else if (dataTypeFactory.hasEnumeration(fieldTypeName)) {
|
|
243
|
+
category = node_opcua_factory_1.FieldCategory.enumeration;
|
|
244
|
+
schema = dataTypeFactory.getEnumeration(fieldTypeName);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
debugLog(" type " + fieldTypeName + " has not been seen yet, let resolve it");
|
|
248
|
+
const res = await resolve2(session, dataTypeNodeId, dataTypeFactory, fieldTypeName, cache);
|
|
249
|
+
schema = res.schema;
|
|
250
|
+
category = res.category;
|
|
251
|
+
}
|
|
252
|
+
/* istanbul ignore next */
|
|
253
|
+
if (!schema) {
|
|
254
|
+
throw new Error("expecting a schema here fieldTypeName=" + fieldTypeName + " " + dataTypeNodeId.toString() + " category = " + category);
|
|
255
|
+
}
|
|
256
|
+
const v2 = {
|
|
257
|
+
category,
|
|
258
|
+
fieldTypeName,
|
|
259
|
+
schema
|
|
260
|
+
};
|
|
261
|
+
cache[key] = v2;
|
|
262
|
+
return v2;
|
|
284
263
|
}
|
|
285
|
-
function _setupEncodings(session, dataTypeNodeId, schema) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
return schema;
|
|
297
|
-
});
|
|
264
|
+
async function _setupEncodings(session, dataTypeNodeId, schema) {
|
|
265
|
+
// read abstract flag
|
|
266
|
+
const isAbstractDV = await session.read({ nodeId: dataTypeNodeId, attributeId: node_opcua_data_model_1.AttributeIds.IsAbstract });
|
|
267
|
+
schema.dataTypeNodeId = dataTypeNodeId;
|
|
268
|
+
if (isAbstractDV.statusCode.isGood() && isAbstractDV.value.value === false) {
|
|
269
|
+
const encodings = await (0, find_encodings_1._findEncodings)(session, dataTypeNodeId);
|
|
270
|
+
schema.encodingDefaultBinary = (0, node_opcua_nodeid_2.makeExpandedNodeId)(encodings.binaryEncodingNodeId);
|
|
271
|
+
schema.encodingDefaultXml = (0, node_opcua_nodeid_2.makeExpandedNodeId)(encodings.xmlEncodingNodeId);
|
|
272
|
+
schema.encodingDefaultJson = (0, node_opcua_nodeid_2.makeExpandedNodeId)(encodings.jsonEncodingNodeId);
|
|
273
|
+
}
|
|
274
|
+
return schema;
|
|
298
275
|
}
|
|
299
276
|
// eslint-disable-next-line max-statements
|
|
300
|
-
function convertDataTypeDefinitionToStructureTypeSchema(session, dataTypeNodeId, name, definition, dataTypeFactory, isAbstract, cache) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
(field.fieldType = fieldTypeName), (field.category = node_opcua_factory_1.FieldCategory.complex);
|
|
342
|
-
fields.push(field);
|
|
343
|
-
const capturedField = field;
|
|
344
|
-
postActions.push((schema) => {
|
|
345
|
-
capturedField.schema = schema;
|
|
346
|
-
});
|
|
347
|
-
continue;
|
|
348
|
-
}
|
|
349
|
-
const rt = (yield resolveFieldType(session, fieldD.dataType, dataTypeFactory, cache));
|
|
350
|
-
if (!rt) {
|
|
351
|
-
errorLog("convertDataTypeDefinitionToStructureTypeSchema cannot handle field", fieldD.name, "in", name, "because " + fieldD.dataType.toString() + " cannot be resolved");
|
|
352
|
-
continue;
|
|
353
|
-
}
|
|
354
|
-
const { schema, category, fieldTypeName, dataType, allowSubType } = rt;
|
|
355
|
-
field.fieldType = fieldTypeName;
|
|
356
|
-
field.category = category;
|
|
357
|
-
field.schema = schema;
|
|
358
|
-
field.dataType = dataType || fieldD.dataType;
|
|
359
|
-
field.allowSubType = allowSubType || false;
|
|
360
|
-
field.basicDataType = yield (0, node_opcua_pseudo_session_1.findBasicDataType)(session, field.dataType);
|
|
277
|
+
async function convertDataTypeDefinitionToStructureTypeSchema(session, dataTypeNodeId, name, definition, dataTypeFactory, isAbstract, cache) {
|
|
278
|
+
if (definition instanceof node_opcua_types_1.StructureDefinition) {
|
|
279
|
+
let fieldCountToIgnore = 0;
|
|
280
|
+
const structureInfo = dataTypeFactory.getStructureInfoForDataType(definition.baseDataType);
|
|
281
|
+
const baseSchema = structureInfo?.schema;
|
|
282
|
+
if (baseSchema) {
|
|
283
|
+
const possibleFields = (0, node_opcua_factory_1.extractAllPossibleFields)(baseSchema);
|
|
284
|
+
fieldCountToIgnore += possibleFields.length;
|
|
285
|
+
}
|
|
286
|
+
// while (base && !(base.dataTypeNodeId.value === DataType.ExtensionObject && base.dataTypeNodeId.namespace === 0)) {
|
|
287
|
+
// fieldCountToIgnore += base..length;
|
|
288
|
+
// base = base.getBaseSchema();
|
|
289
|
+
// }
|
|
290
|
+
const fields = [];
|
|
291
|
+
const isUnion = definition.structureType === node_opcua_types_1.StructureType.Union;
|
|
292
|
+
switch (definition.structureType) {
|
|
293
|
+
case node_opcua_types_1.StructureType.Union:
|
|
294
|
+
fields.push({
|
|
295
|
+
fieldType: "UInt32",
|
|
296
|
+
name: "SwitchField"
|
|
297
|
+
});
|
|
298
|
+
break;
|
|
299
|
+
case node_opcua_types_1.StructureType.Structure:
|
|
300
|
+
case node_opcua_types_1.StructureType.StructureWithOptionalFields:
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
let switchValue = 1;
|
|
304
|
+
let switchBit = 0;
|
|
305
|
+
const bitFields = isUnion ? undefined : [];
|
|
306
|
+
const postActions = [];
|
|
307
|
+
if (definition.fields) {
|
|
308
|
+
for (let i = fieldCountToIgnore; i < definition.fields.length; i++) {
|
|
309
|
+
const fieldD = definition.fields[i];
|
|
310
|
+
// we need to skip fields that have already been handled in base class
|
|
311
|
+
let field;
|
|
312
|
+
({ field, switchBit, switchValue } = createField(fieldD, switchBit, bitFields, isUnion, switchValue));
|
|
313
|
+
if (fieldD.dataType.value === dataTypeNodeId.value && fieldD.dataType.namespace === dataTypeNodeId.namespace) {
|
|
314
|
+
// this is a structure with a field of the same type
|
|
315
|
+
// push an empty placeholder that we will fill later
|
|
316
|
+
const fieldTypeName = await readBrowseName(session, dataTypeNodeId);
|
|
317
|
+
(field.fieldType = fieldTypeName), (field.category = node_opcua_factory_1.FieldCategory.complex);
|
|
361
318
|
fields.push(field);
|
|
319
|
+
const capturedField = field;
|
|
320
|
+
postActions.push((schema) => {
|
|
321
|
+
capturedField.schema = schema;
|
|
322
|
+
});
|
|
323
|
+
continue;
|
|
362
324
|
}
|
|
325
|
+
const rt = (await resolveFieldType(session, fieldD.dataType, dataTypeFactory, cache));
|
|
326
|
+
if (!rt) {
|
|
327
|
+
errorLog("convertDataTypeDefinitionToStructureTypeSchema cannot handle field", fieldD.name, "in", name, "because " + fieldD.dataType.toString() + " cannot be resolved");
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
const { schema, category, fieldTypeName, dataType, allowSubType } = rt;
|
|
331
|
+
field.fieldType = fieldTypeName;
|
|
332
|
+
field.category = category;
|
|
333
|
+
field.schema = schema;
|
|
334
|
+
field.dataType = dataType || fieldD.dataType;
|
|
335
|
+
field.allowSubType = allowSubType || false;
|
|
336
|
+
field.basicDataType = await (0, node_opcua_pseudo_session_1.findBasicDataType)(session, field.dataType);
|
|
337
|
+
fields.push(field);
|
|
363
338
|
}
|
|
364
|
-
/// some server may provide definition.baseDataType to be i=22 (ExtensionObject)
|
|
365
|
-
/// instead of 12756 Union;
|
|
366
|
-
if (isUnion && (0, node_opcua_nodeid_1.sameNodeId)(definition.baseDataType, (0, node_opcua_nodeid_2.coerceNodeId)("i=22"))) {
|
|
367
|
-
definition.baseDataType = (0, node_opcua_nodeid_2.resolveNodeId)("i=1276"); // aka DataTypeIds.Union
|
|
368
|
-
}
|
|
369
|
-
const a = yield resolveFieldType(session, definition.baseDataType, dataTypeFactory, cache);
|
|
370
|
-
const baseType = a ? a.fieldTypeName : isUnion ? "Union" : "ExtensionObject";
|
|
371
|
-
const os = new node_opcua_factory_1.StructuredTypeSchema({
|
|
372
|
-
baseType,
|
|
373
|
-
bitFields,
|
|
374
|
-
fields,
|
|
375
|
-
name,
|
|
376
|
-
dataTypeFactory
|
|
377
|
-
});
|
|
378
|
-
const structuredTypeSchema = yield _setupEncodings(session, dataTypeNodeId, os);
|
|
379
|
-
postActions.forEach((action) => action(structuredTypeSchema));
|
|
380
|
-
return structuredTypeSchema;
|
|
381
339
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
340
|
+
/// some server may provide definition.baseDataType to be i=22 (ExtensionObject)
|
|
341
|
+
/// instead of 12756 Union;
|
|
342
|
+
if (isUnion && (0, node_opcua_nodeid_1.sameNodeId)(definition.baseDataType, (0, node_opcua_nodeid_2.coerceNodeId)("i=22"))) {
|
|
343
|
+
definition.baseDataType = (0, node_opcua_nodeid_2.resolveNodeId)("i=1276"); // aka DataTypeIds.Union
|
|
344
|
+
}
|
|
345
|
+
const a = await resolveFieldType(session, definition.baseDataType, dataTypeFactory, cache);
|
|
346
|
+
const baseType = a ? a.fieldTypeName : isUnion ? "Union" : "ExtensionObject";
|
|
347
|
+
const os = new node_opcua_factory_1.StructuredTypeSchema({
|
|
348
|
+
baseType,
|
|
349
|
+
bitFields,
|
|
350
|
+
fields,
|
|
351
|
+
name,
|
|
352
|
+
dataTypeFactory
|
|
353
|
+
});
|
|
354
|
+
const structuredTypeSchema = await _setupEncodings(session, dataTypeNodeId, os);
|
|
355
|
+
postActions.forEach((action) => action(structuredTypeSchema));
|
|
356
|
+
return structuredTypeSchema;
|
|
357
|
+
}
|
|
358
|
+
throw new Error("Not Implemented");
|
|
359
|
+
function createField(fieldD, switchBit, bitFields, isUnion, switchValue) {
|
|
360
|
+
const field = {
|
|
361
|
+
fieldType: "",
|
|
362
|
+
name: fieldD.name,
|
|
363
|
+
schema: undefined
|
|
364
|
+
};
|
|
365
|
+
if (fieldD.isOptional) {
|
|
366
|
+
field.switchBit = switchBit++;
|
|
367
|
+
bitFields?.push({ name: fieldD.name + "Specified", length: 1 });
|
|
368
|
+
}
|
|
369
|
+
if (isUnion) {
|
|
370
|
+
field.switchValue = switchValue;
|
|
371
|
+
switchValue += 1;
|
|
372
|
+
}
|
|
373
|
+
// (fieldD.valueRank === -1 || fieldD.valueRank === 1 || fieldD.valueRank === 0);
|
|
374
|
+
if (fieldD.valueRank >= 1) {
|
|
375
|
+
field.valueRank = fieldD.valueRank;
|
|
376
|
+
field.isArray = true;
|
|
406
377
|
}
|
|
407
|
-
|
|
378
|
+
else {
|
|
379
|
+
field.isArray = false;
|
|
380
|
+
}
|
|
381
|
+
return { field, switchBit, switchValue };
|
|
382
|
+
}
|
|
408
383
|
}
|
|
409
384
|
exports.convertDataTypeDefinitionToStructureTypeSchema = convertDataTypeDefinitionToStructureTypeSchema;
|
|
410
385
|
//# sourceMappingURL=convert_data_type_definition_to_structuretype_schema.js.map
|