node-opcua-client-dynamic-extension-object 2.70.3 → 2.71.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/client_dynamic_extension_object.d.ts +22 -0
- package/dist/client_dynamic_extension_object.js +1012 -0
- package/dist/client_dynamic_extension_object.js.map +1 -0
- package/dist/convert_data_type_definition_to_structuretype_schema.d.ts +12 -12
- package/dist/convert_data_type_definition_to_structuretype_schema.js +343 -331
- package/dist/convert_data_type_definition_to_structuretype_schema.js.map +1 -1
- package/dist/extra_data_type_manager.d.ts +16 -16
- package/dist/extra_data_type_manager.js +75 -75
- 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 +12 -12
- package/dist/index.js +28 -28
- package/dist/populate_data_type_manager.d.ts +3 -3
- package/dist/populate_data_type_manager.js +25 -25
- 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 +601 -601
- package/dist/private/populate_data_type_manager_104.d.ts +9 -9
- package/dist/private/populate_data_type_manager_104.js +182 -182
- package/dist/private/populate_data_type_manager_104.js.map +1 -1
- package/dist/promote_opaque_structure.d.ts +6 -6
- package/dist/promote_opaque_structure.js +41 -41
- 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 +4 -4
- package/dist/resolve_dynamic_extension_object.js +105 -105
- package/dist/resolve_dynamic_extension_object.js.map +1 -1
- package/package.json +16 -16
- package/source/convert_data_type_definition_to_structuretype_schema.ts +43 -30
- package/source/private/populate_data_type_manager_104.ts +1 -0
- package/source/resolve_dynamic_extension_object.ts +13 -10
|
@@ -1,332 +1,344 @@
|
|
|
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.convertDataTypeDefinitionToStructureTypeSchema = void 0;
|
|
13
|
-
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
14
|
-
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
15
|
-
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
16
|
-
const node_opcua_factory_1 = require("node-opcua-factory");
|
|
17
|
-
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
18
|
-
const node_opcua_pseudo_session_1 = require("node-opcua-pseudo-session");
|
|
19
|
-
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
20
|
-
const node_opcua_types_1 = require("node-opcua-types");
|
|
21
|
-
const node_opcua_extension_object_1 = require("node-opcua-extension-object");
|
|
22
|
-
//
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
case
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
let
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
case node_opcua_factory_1.FieldCategory.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
let
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
schema.
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
schema.
|
|
240
|
-
schema.
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
case node_opcua_types_1.StructureType.
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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
|
-
field.
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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.convertDataTypeDefinitionToStructureTypeSchema = void 0;
|
|
13
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
14
|
+
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
15
|
+
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
16
|
+
const node_opcua_factory_1 = require("node-opcua-factory");
|
|
17
|
+
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
18
|
+
const node_opcua_pseudo_session_1 = require("node-opcua-pseudo-session");
|
|
19
|
+
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
20
|
+
const node_opcua_types_1 = require("node-opcua-types");
|
|
21
|
+
const node_opcua_extension_object_1 = require("node-opcua-extension-object");
|
|
22
|
+
//
|
|
23
|
+
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
24
|
+
const find_encodings_1 = require("./private/find_encodings");
|
|
25
|
+
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
26
|
+
const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
|
|
27
|
+
function findSuperType(session, dataTypeNodeId) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const nodeToBrowse3 = {
|
|
30
|
+
browseDirection: node_opcua_data_model_1.BrowseDirection.Inverse,
|
|
31
|
+
includeSubtypes: false,
|
|
32
|
+
nodeClassMask: node_opcua_data_model_1.NodeClassMask.DataType,
|
|
33
|
+
nodeId: dataTypeNodeId,
|
|
34
|
+
referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasSubtype"),
|
|
35
|
+
resultMask: (0, node_opcua_data_model_1.makeResultMask)("NodeId | ReferenceType | BrowseName | NodeClass")
|
|
36
|
+
};
|
|
37
|
+
const result3 = yield (0, node_opcua_pseudo_session_1.browseAll)(session, nodeToBrowse3);
|
|
38
|
+
/* istanbul ignore next */
|
|
39
|
+
if (result3.statusCode !== node_opcua_status_code_1.StatusCodes.Good) {
|
|
40
|
+
throw new Error("Cannot find superType for " + dataTypeNodeId.toString());
|
|
41
|
+
}
|
|
42
|
+
result3.references = result3.references || [];
|
|
43
|
+
/* istanbul ignore next */
|
|
44
|
+
if (result3.references.length !== 1) {
|
|
45
|
+
console.log(result3.toString());
|
|
46
|
+
throw new Error("Invalid dataType with more than one superType " + dataTypeNodeId.toString());
|
|
47
|
+
}
|
|
48
|
+
return result3.references[0].nodeId;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function findDataTypeCategory(session, cache, dataTypeNodeId) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const subTypeNodeId = yield findSuperType(session, dataTypeNodeId);
|
|
54
|
+
debugLog("subTypeNodeId of ", dataTypeNodeId.toString(), " is ", subTypeNodeId.toString());
|
|
55
|
+
const key = subTypeNodeId.toString();
|
|
56
|
+
if (cache[key]) {
|
|
57
|
+
return cache[key].category;
|
|
58
|
+
}
|
|
59
|
+
let category;
|
|
60
|
+
if (subTypeNodeId.namespace === 0 && subTypeNodeId.value <= 29) {
|
|
61
|
+
// well known node ID !
|
|
62
|
+
switch (subTypeNodeId.value) {
|
|
63
|
+
case 22 /* Structure */:
|
|
64
|
+
category = node_opcua_factory_1.FieldCategory.complex;
|
|
65
|
+
break;
|
|
66
|
+
case 29 /* Enumeration */:
|
|
67
|
+
category = node_opcua_factory_1.FieldCategory.enumeration;
|
|
68
|
+
break;
|
|
69
|
+
default:
|
|
70
|
+
category = node_opcua_factory_1.FieldCategory.basic;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
return category;
|
|
74
|
+
}
|
|
75
|
+
// must drill down ...
|
|
76
|
+
return yield findDataTypeCategory(session, cache, subTypeNodeId);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function findDataTypeBasicType(session, cache, dataTypeNodeId) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const subTypeNodeId = yield findSuperType(session, dataTypeNodeId);
|
|
82
|
+
debugLog("subTypeNodeId of ", dataTypeNodeId.toString(), " is ", subTypeNodeId.toString());
|
|
83
|
+
const key = subTypeNodeId.toString();
|
|
84
|
+
if (cache[key]) {
|
|
85
|
+
return cache[key].schema;
|
|
86
|
+
}
|
|
87
|
+
if (subTypeNodeId.namespace === 0 && subTypeNodeId.value < 29) {
|
|
88
|
+
switch (subTypeNodeId.value) {
|
|
89
|
+
case 22: /* Structure */
|
|
90
|
+
case 29 /* Enumeration */:
|
|
91
|
+
throw new Error("Not expecting Structure or Enumeration");
|
|
92
|
+
default:
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
const nameDataValue = yield session.read({
|
|
96
|
+
attributeId: node_opcua_data_model_1.AttributeIds.BrowseName,
|
|
97
|
+
nodeId: subTypeNodeId
|
|
98
|
+
});
|
|
99
|
+
const name = nameDataValue.value.value.name;
|
|
100
|
+
return (0, node_opcua_factory_1.getBuildInType)(name);
|
|
101
|
+
}
|
|
102
|
+
// must drill down ...
|
|
103
|
+
return yield findDataTypeBasicType(session, cache, subTypeNodeId);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function readBrowseName(session, nodeId) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
const dataValue = yield session.read({ nodeId, attributeId: node_opcua_data_model_1.AttributeIds.BrowseName });
|
|
109
|
+
if (dataValue.statusCode !== node_opcua_status_code_1.StatusCodes.Good) {
|
|
110
|
+
const message = "cannot extract BrowseName of nodeId = " + nodeId.toString() + " statusCode = " + dataValue.statusCode.toString();
|
|
111
|
+
debugLog(message);
|
|
112
|
+
throw new Error(message);
|
|
113
|
+
}
|
|
114
|
+
return dataValue.value.value.name;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function resolve2(session, dataTypeNodeId, dataTypeFactory, fieldTypeName, cache) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
const category = yield findDataTypeCategory(session, cache, dataTypeNodeId);
|
|
120
|
+
debugLog(" type " + fieldTypeName + " has not been seen yet, let resolve it => (category = ", category, " )");
|
|
121
|
+
let schema = undefined;
|
|
122
|
+
switch (category) {
|
|
123
|
+
case node_opcua_factory_1.FieldCategory.basic:
|
|
124
|
+
schema = yield findDataTypeBasicType(session, cache, dataTypeNodeId);
|
|
125
|
+
/* istanbul ignore next */
|
|
126
|
+
if (!schema) {
|
|
127
|
+
errorLog("Cannot find basic type " + fieldTypeName);
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
default:
|
|
131
|
+
case node_opcua_factory_1.FieldCategory.enumeration:
|
|
132
|
+
case node_opcua_factory_1.FieldCategory.complex:
|
|
133
|
+
{
|
|
134
|
+
const dataTypeDefinitionDataValue = yield session.read({
|
|
135
|
+
attributeId: node_opcua_data_model_1.AttributeIds.DataTypeDefinition,
|
|
136
|
+
nodeId: dataTypeNodeId
|
|
137
|
+
});
|
|
138
|
+
/* istanbul ignore next */
|
|
139
|
+
if (dataTypeDefinitionDataValue.statusCode !== node_opcua_status_code_1.StatusCodes.Good) {
|
|
140
|
+
throw new Error(" Cannot find dataType Definition ! with nodeId =" + dataTypeNodeId.toString());
|
|
141
|
+
}
|
|
142
|
+
const definition = dataTypeDefinitionDataValue.value.value;
|
|
143
|
+
const convertIn64ToInteger = (a) => a[1];
|
|
144
|
+
const convert = (fields) => {
|
|
145
|
+
const retVal = {};
|
|
146
|
+
fields && fields.forEach((field) => (retVal[field.name || ""] = convertIn64ToInteger(field.value)));
|
|
147
|
+
return retVal;
|
|
148
|
+
};
|
|
149
|
+
if (category === node_opcua_factory_1.FieldCategory.enumeration) {
|
|
150
|
+
if (definition instanceof node_opcua_types_1.EnumDefinition) {
|
|
151
|
+
const e = new node_opcua_factory_1.EnumerationDefinitionSchema({
|
|
152
|
+
enumValues: convert(definition.fields),
|
|
153
|
+
name: fieldTypeName
|
|
154
|
+
});
|
|
155
|
+
dataTypeFactory.registerEnumeration(e);
|
|
156
|
+
schema = e;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
schema = yield convertDataTypeDefinitionToStructureTypeSchema(session, dataTypeNodeId, fieldTypeName, definition, dataTypeFactory, cache);
|
|
161
|
+
}
|
|
162
|
+
// xx const schema1 = dataTypeFactory.getStructuredTypeSchema(fieldTypeName);
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
return { schema, category };
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
// eslint-disable-next-line max-statements
|
|
170
|
+
function resolveFieldType(session, dataTypeNodeId, dataTypeFactory, cache) {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
if (dataTypeNodeId.namespace === 0 && dataTypeNodeId.value === 22) {
|
|
173
|
+
// ERN return null;
|
|
174
|
+
const category = node_opcua_factory_1.FieldCategory.complex;
|
|
175
|
+
const fieldTypeName = "Structure";
|
|
176
|
+
const schema = node_opcua_extension_object_1.ExtensionObject.schema;
|
|
177
|
+
return {
|
|
178
|
+
category,
|
|
179
|
+
fieldTypeName,
|
|
180
|
+
schema
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const key = dataTypeNodeId.toString();
|
|
184
|
+
const v = cache[key];
|
|
185
|
+
if (v) {
|
|
186
|
+
return v;
|
|
187
|
+
}
|
|
188
|
+
if (dataTypeNodeId.value === 0) {
|
|
189
|
+
const v3 = {
|
|
190
|
+
category: node_opcua_factory_1.FieldCategory.basic,
|
|
191
|
+
fieldTypeName: "Variant",
|
|
192
|
+
schema: dataTypeFactory.getSimpleType("Variant")
|
|
193
|
+
};
|
|
194
|
+
cache[key] = v3;
|
|
195
|
+
return v3;
|
|
196
|
+
}
|
|
197
|
+
const fieldTypeName = yield readBrowseName(session, dataTypeNodeId);
|
|
198
|
+
let schema;
|
|
199
|
+
let category = node_opcua_factory_1.FieldCategory.enumeration;
|
|
200
|
+
if (dataTypeFactory.hasStructuredType(fieldTypeName)) {
|
|
201
|
+
schema = dataTypeFactory.getStructuredTypeSchema(fieldTypeName);
|
|
202
|
+
category = node_opcua_factory_1.FieldCategory.complex;
|
|
203
|
+
}
|
|
204
|
+
else if (dataTypeFactory.hasSimpleType(fieldTypeName)) {
|
|
205
|
+
category = node_opcua_factory_1.FieldCategory.basic;
|
|
206
|
+
schema = dataTypeFactory.getSimpleType(fieldTypeName);
|
|
207
|
+
}
|
|
208
|
+
else if (dataTypeFactory.hasEnumeration(fieldTypeName)) {
|
|
209
|
+
category = node_opcua_factory_1.FieldCategory.enumeration;
|
|
210
|
+
schema = dataTypeFactory.getEnumeration(fieldTypeName);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
debugLog(" type " + fieldTypeName + " has not been seen yet, let resolve it");
|
|
214
|
+
const res = yield resolve2(session, dataTypeNodeId, dataTypeFactory, fieldTypeName, cache);
|
|
215
|
+
schema = res.schema;
|
|
216
|
+
category = res.category;
|
|
217
|
+
}
|
|
218
|
+
/* istanbul ignore next */
|
|
219
|
+
if (!schema) {
|
|
220
|
+
throw new Error("expecting a schema here fieldTypeName=" + fieldTypeName + " " + dataTypeNodeId.toString() + " category = " + category);
|
|
221
|
+
}
|
|
222
|
+
const v2 = {
|
|
223
|
+
category,
|
|
224
|
+
fieldTypeName,
|
|
225
|
+
schema
|
|
226
|
+
};
|
|
227
|
+
cache[key] = v2;
|
|
228
|
+
return v2;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
function _setupEncodings(session, dataTypeNodeId, schema) {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
// read abstract flag
|
|
234
|
+
const isAbstractDV = yield session.read({ nodeId: dataTypeNodeId, attributeId: node_opcua_data_model_1.AttributeIds.IsAbstract });
|
|
235
|
+
schema.dataTypeNodeId = dataTypeNodeId;
|
|
236
|
+
schema.id = dataTypeNodeId;
|
|
237
|
+
if (isAbstractDV.statusCode === node_opcua_status_code_1.StatusCodes.Good && isAbstractDV.value.value === false) {
|
|
238
|
+
const encodings = yield (0, find_encodings_1._findEncodings)(session, dataTypeNodeId);
|
|
239
|
+
schema.encodingDefaultBinary = (0, node_opcua_nodeid_1.makeExpandedNodeId)(encodings.binaryEncodingNodeId);
|
|
240
|
+
schema.encodingDefaultXml = (0, node_opcua_nodeid_1.makeExpandedNodeId)(encodings.xmlEncodingNodeId);
|
|
241
|
+
schema.encodingDefaultJson = (0, node_opcua_nodeid_1.makeExpandedNodeId)(encodings.jsonEncodingNodeId);
|
|
242
|
+
}
|
|
243
|
+
return schema;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
// eslint-disable-next-line max-statements
|
|
247
|
+
function convertDataTypeDefinitionToStructureTypeSchema(session, dataTypeNodeId, name, definition, dataTypeFactory, cache) {
|
|
248
|
+
var _a;
|
|
249
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
250
|
+
if (definition instanceof node_opcua_types_1.StructureDefinition) {
|
|
251
|
+
let fieldCountToIgnore = 0;
|
|
252
|
+
let base = (_a = dataTypeFactory.getConstructorForDataType(definition.baseDataType)) === null || _a === void 0 ? void 0 : _a.schema;
|
|
253
|
+
while (base && !(base.dataTypeNodeId.value === node_opcua_variant_1.DataType.ExtensionObject && base.dataTypeNodeId.namespace === 0)) {
|
|
254
|
+
fieldCountToIgnore += base._possibleFields.length;
|
|
255
|
+
base = base._baseSchema;
|
|
256
|
+
}
|
|
257
|
+
const fields = [];
|
|
258
|
+
const isUnion = definition.structureType === node_opcua_types_1.StructureType.Union;
|
|
259
|
+
switch (definition.structureType) {
|
|
260
|
+
case node_opcua_types_1.StructureType.Union:
|
|
261
|
+
// xx console.log("Union Found : ", name);
|
|
262
|
+
fields.push({
|
|
263
|
+
fieldType: "UInt32",
|
|
264
|
+
name: "SwitchField"
|
|
265
|
+
});
|
|
266
|
+
break;
|
|
267
|
+
case node_opcua_types_1.StructureType.Structure:
|
|
268
|
+
case node_opcua_types_1.StructureType.StructureWithOptionalFields:
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
let switchValue = 1;
|
|
272
|
+
let switchBit = 0;
|
|
273
|
+
const bitFields = isUnion ? undefined : [];
|
|
274
|
+
const postActions = [];
|
|
275
|
+
if (definition.fields) {
|
|
276
|
+
for (let i = fieldCountToIgnore; i < definition.fields.length; i++) {
|
|
277
|
+
const fieldD = definition.fields[i];
|
|
278
|
+
// we need to skip fields that have already been handled in base class
|
|
279
|
+
let field;
|
|
280
|
+
({ field, switchBit, switchValue } = createField(fieldD, switchBit, bitFields, isUnion, switchValue));
|
|
281
|
+
if (fieldD.dataType.value === dataTypeNodeId.value && fieldD.dataType.namespace === dataTypeNodeId.namespace) {
|
|
282
|
+
// this is a structure with a field of the same type
|
|
283
|
+
// push an empty placeholder that we will fill later
|
|
284
|
+
const fieldTypeName = yield readBrowseName(session, dataTypeNodeId);
|
|
285
|
+
(field.fieldType = fieldTypeName), (field.category = node_opcua_factory_1.FieldCategory.complex);
|
|
286
|
+
fields.push(field);
|
|
287
|
+
const capturedField = field;
|
|
288
|
+
postActions.push((schema) => {
|
|
289
|
+
capturedField.schema = schema;
|
|
290
|
+
});
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
const rt = (yield resolveFieldType(session, fieldD.dataType, dataTypeFactory, cache));
|
|
294
|
+
if (!rt) {
|
|
295
|
+
errorLog("convertDataTypeDefinitionToStructureTypeSchema cannot handle field", fieldD.name, "in", name, "because " + fieldD.dataType.toString() + " cannot be resolved");
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
const { schema, category, fieldTypeName } = rt;
|
|
299
|
+
(field.fieldType = fieldTypeName), (field.category = category);
|
|
300
|
+
field.schema = schema;
|
|
301
|
+
fields.push(field);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const a = yield resolveFieldType(session, definition.baseDataType, dataTypeFactory, cache);
|
|
305
|
+
const baseType = a ? a.fieldTypeName : "ExtensionObject";
|
|
306
|
+
const os = new node_opcua_factory_1.StructuredTypeSchema({
|
|
307
|
+
baseType,
|
|
308
|
+
bitFields,
|
|
309
|
+
fields,
|
|
310
|
+
id: 0,
|
|
311
|
+
name
|
|
312
|
+
});
|
|
313
|
+
const structuredTypeSchema = yield _setupEncodings(session, dataTypeNodeId, os);
|
|
314
|
+
postActions.forEach((action) => action(structuredTypeSchema));
|
|
315
|
+
return structuredTypeSchema;
|
|
316
|
+
}
|
|
317
|
+
throw new Error("Not Implemented");
|
|
318
|
+
function createField(fieldD, switchBit, bitFields, isUnion, switchValue) {
|
|
319
|
+
const field = {
|
|
320
|
+
fieldType: "",
|
|
321
|
+
name: fieldD.name,
|
|
322
|
+
schema: null
|
|
323
|
+
};
|
|
324
|
+
if (fieldD.isOptional) {
|
|
325
|
+
field.switchBit = switchBit++;
|
|
326
|
+
bitFields === null || bitFields === void 0 ? void 0 : bitFields.push({ name: fieldD.name + "Specified", length: 1 });
|
|
327
|
+
}
|
|
328
|
+
if (isUnion) {
|
|
329
|
+
field.switchValue = switchValue;
|
|
330
|
+
switchValue += 1;
|
|
331
|
+
}
|
|
332
|
+
(0, node_opcua_assert_1.assert)(fieldD.valueRank === -1 || fieldD.valueRank === 1 || fieldD.valueRank === 0);
|
|
333
|
+
if (fieldD.valueRank === 1) {
|
|
334
|
+
field.isArray = true;
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
field.isArray = false;
|
|
338
|
+
}
|
|
339
|
+
return { field, switchBit, switchValue };
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
exports.convertDataTypeDefinitionToStructureTypeSchema = convertDataTypeDefinitionToStructureTypeSchema;
|
|
332
344
|
//# sourceMappingURL=convert_data_type_definition_to_structuretype_schema.js.map
|