node-opcua-convert-nodeset-to-javascript 2.113.0 → 2.115.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/_dataType.js +113 -126
- package/dist/_dataType.js.map +1 -1
- package/dist/convert_namespace_to_typescript.js +147 -168
- package/dist/convert_namespace_to_typescript.js.map +1 -1
- package/dist/convert_to_typescript.js +418 -448
- package/dist/convert_to_typescript.js.map +1 -1
- package/dist/main.js +13 -21
- package/dist/main.js.map +1 -1
- package/dist/private/cache.js +30 -46
- package/dist/private/cache.js.map +1 -1
- package/dist/private/get_corresponding_data_type.js +79 -92
- package/dist/private/get_corresponding_data_type.js.map +1 -1
- package/dist/private/utils.js +179 -228
- package/dist/private/utils.js.map +1 -1
- package/dist/update_parent_tsconfig.js +39 -50
- package/dist/update_parent_tsconfig.js.map +1 -1
- package/dist/walk_through.js +46 -67
- package/dist/walk_through.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
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -44,20 +35,18 @@ const m9 = !doDebug ? "" : `/* 9 */`;
|
|
|
44
35
|
const mA = !doDebug ? "" : `/* a */`;
|
|
45
36
|
const mB = !doDebug ? "" : `/* b */`;
|
|
46
37
|
const mC = !doDebug ? "" : `/* c */`;
|
|
47
|
-
function convertDataTypeToTypescript(session, dataTypeId) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
/** */
|
|
57
|
-
}
|
|
58
|
-
f.write(`}`);
|
|
38
|
+
async function convertDataTypeToTypescript(session, dataTypeId) {
|
|
39
|
+
const definition = await (0, utils_1.getDefinition)(session, dataTypeId);
|
|
40
|
+
const browseName = await (0, utils_1.getBrowseName)(session, dataTypeId);
|
|
41
|
+
const dataTypeTypescriptName = `UA${browseName.name.toString()}`;
|
|
42
|
+
const f = new node_opcua_utils_1.LineFile();
|
|
43
|
+
if (definition && definition instanceof node_opcua_types_1.StructureDefinition) {
|
|
44
|
+
f.write(`interface ${dataTypeTypescriptName} {`);
|
|
45
|
+
for (const field of definition.fields || []) {
|
|
46
|
+
/** */
|
|
59
47
|
}
|
|
60
|
-
|
|
48
|
+
f.write(`}`);
|
|
49
|
+
}
|
|
61
50
|
}
|
|
62
51
|
exports.convertDataTypeToTypescript = convertDataTypeToTypescript;
|
|
63
52
|
function makeTypeName2(nodeClass, browseName, suffix) {
|
|
@@ -68,139 +57,131 @@ function makeTypeName2(nodeClass, browseName, suffix) {
|
|
|
68
57
|
return (0, cache_1.makeTypeNameNew)(nodeClass, null, browseName, suffix);
|
|
69
58
|
}
|
|
70
59
|
exports.makeTypeName2 = makeTypeName2;
|
|
71
|
-
function extractClassDefinition(session, nodeId, cache) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
cache.ensureImported(i);
|
|
96
|
-
};
|
|
97
|
-
const { jtype } = yield (0, get_corresponding_data_type_1.getCorrespondingJavascriptType2)(session, nodeId, dataTypeNodeId, cache, importCollector);
|
|
98
|
-
dataTypeName = jtype; // with decoration
|
|
99
|
-
if (!(dataTypeNodeId === null || dataTypeNodeId === void 0 ? void 0 : dataTypeNodeId.isEmpty())) {
|
|
100
|
-
// "DT" + (await getBrowseName(session, dataTypeNodeId!))?.name! || "";
|
|
101
|
-
// const bn = await getBrowseName(session, dataTypeNodeId!);
|
|
102
|
-
dataTypeImport = extraImports; // makeTypeName2(NodeClass.DataType, bn);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
const baseClassDef = !superType ? null : yield extractClassDefinition(session, superType.nodeId, cache);
|
|
106
|
-
const description = yield (0, utils_1.getDescription)(session, nodeId);
|
|
107
|
-
// const definition = await getDefinition(session, nodeId);
|
|
108
|
-
const interfaceName = makeTypeName2(nodeClass, browseName);
|
|
109
|
-
const baseInterfaceName = !superType ? null : makeTypeName2(nodeClass, superType.browseName);
|
|
110
|
-
// extract member
|
|
111
|
-
const children = yield (0, utils_1.getChildrenOrFolderElements)(session, nodeId);
|
|
112
|
-
const members = [];
|
|
113
|
-
classDef = {
|
|
114
|
-
nodeClass,
|
|
115
|
-
browseName,
|
|
116
|
-
isAbstract,
|
|
117
|
-
dataType,
|
|
118
|
-
dataTypeNodeId,
|
|
119
|
-
dataTypeName,
|
|
120
|
-
dataTypeImport,
|
|
121
|
-
superType,
|
|
122
|
-
baseClassDef,
|
|
123
|
-
description,
|
|
124
|
-
// definition,
|
|
125
|
-
children,
|
|
126
|
-
members,
|
|
127
|
-
interfaceName,
|
|
128
|
-
baseInterfaceName
|
|
60
|
+
async function extractClassDefinition(session, nodeId, cache) {
|
|
61
|
+
const extraImports = [];
|
|
62
|
+
const _c = cache.classDefCache || {};
|
|
63
|
+
cache.classDefCache = _c;
|
|
64
|
+
let classDef = _c[nodeId.toString()];
|
|
65
|
+
if (classDef) {
|
|
66
|
+
return classDef;
|
|
67
|
+
}
|
|
68
|
+
const nodeClass = await (0, utils_1.getNodeClass)(session, nodeId);
|
|
69
|
+
if (nodeClass !== node_opcua_data_model_1.NodeClass.VariableType && nodeClass !== node_opcua_data_model_1.NodeClass.ObjectType) {
|
|
70
|
+
throw new Error("Invalid nodeClass " + node_opcua_data_model_1.NodeClass[nodeClass] + " nodeId " + nodeId.toString());
|
|
71
|
+
}
|
|
72
|
+
const browseName = await (0, utils_1.getBrowseName)(session, nodeId);
|
|
73
|
+
const isAbstract = await (0, utils_1.getIsAbstract)(session, nodeId);
|
|
74
|
+
const superType = (await (0, utils_1.getSubtypeNodeIdIfAny)(session, nodeId)) || undefined;
|
|
75
|
+
const dataTypeNodeId = await (0, utils_1.getDataTypeNodeId)(session, nodeId);
|
|
76
|
+
let dataTypeName = "";
|
|
77
|
+
let dataType = node_opcua_variant_1.DataType.Null;
|
|
78
|
+
let dataTypeImport = undefined;
|
|
79
|
+
if (nodeClass === node_opcua_data_model_1.NodeClass.VariableType) {
|
|
80
|
+
dataType = await (0, utils_1.extractBasicDataType)(session, dataTypeNodeId);
|
|
81
|
+
const importCollector = (i) => {
|
|
82
|
+
extraImports.push(i);
|
|
83
|
+
cache.ensureImported(i);
|
|
129
84
|
};
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
85
|
+
const { jtype } = await (0, get_corresponding_data_type_1.getCorrespondingJavascriptType2)(session, nodeId, dataTypeNodeId, cache, importCollector);
|
|
86
|
+
dataTypeName = jtype; // with decoration
|
|
87
|
+
if (!dataTypeNodeId?.isEmpty()) {
|
|
88
|
+
// "DT" + (await getBrowseName(session, dataTypeNodeId!))?.name! || "";
|
|
89
|
+
// const bn = await getBrowseName(session, dataTypeNodeId!);
|
|
90
|
+
dataTypeImport = extraImports; // makeTypeName2(NodeClass.DataType, bn);
|
|
134
91
|
}
|
|
135
|
-
|
|
136
|
-
|
|
92
|
+
}
|
|
93
|
+
const baseClassDef = !superType ? null : await extractClassDefinition(session, superType.nodeId, cache);
|
|
94
|
+
const description = await (0, utils_1.getDescription)(session, nodeId);
|
|
95
|
+
// const definition = await getDefinition(session, nodeId);
|
|
96
|
+
const interfaceName = makeTypeName2(nodeClass, browseName);
|
|
97
|
+
const baseInterfaceName = !superType ? null : makeTypeName2(nodeClass, superType.browseName);
|
|
98
|
+
// extract member
|
|
99
|
+
const children = await (0, utils_1.getChildrenOrFolderElements)(session, nodeId);
|
|
100
|
+
const members = [];
|
|
101
|
+
classDef = {
|
|
102
|
+
nodeClass,
|
|
103
|
+
browseName,
|
|
104
|
+
isAbstract,
|
|
105
|
+
dataType,
|
|
106
|
+
dataTypeNodeId,
|
|
107
|
+
dataTypeName,
|
|
108
|
+
dataTypeImport,
|
|
109
|
+
superType,
|
|
110
|
+
baseClassDef,
|
|
111
|
+
description,
|
|
112
|
+
// definition,
|
|
113
|
+
children,
|
|
114
|
+
members,
|
|
115
|
+
interfaceName,
|
|
116
|
+
baseInterfaceName
|
|
117
|
+
};
|
|
118
|
+
_c[nodeId.toString()] = classDef;
|
|
119
|
+
for (const child of children) {
|
|
120
|
+
const c = await extractClassMemberDef(session, child.nodeId, classDef, cache);
|
|
121
|
+
classDef.members.push(c);
|
|
122
|
+
}
|
|
123
|
+
return classDef;
|
|
137
124
|
}
|
|
138
125
|
exports.extractClassDefinition = extractClassDefinition;
|
|
139
|
-
function classify(session, refs, classDef) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (sameMember) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
modellingRule = "Mandatory";
|
|
160
|
-
}
|
|
126
|
+
async function classify(session, refs, classDef) {
|
|
127
|
+
const r = {
|
|
128
|
+
Mandatory: [],
|
|
129
|
+
Optional: [],
|
|
130
|
+
MandatoryPlaceholder: [],
|
|
131
|
+
OptionalPlaceholder: [],
|
|
132
|
+
ExposesItsArray: []
|
|
133
|
+
};
|
|
134
|
+
for (const mm of refs) {
|
|
135
|
+
let modellingRule = await (0, utils_1.getModellingRule)(session, mm.nodeId);
|
|
136
|
+
if (modellingRule) {
|
|
137
|
+
// if Optional, check that base class member is also Optional or force to Mandatory
|
|
138
|
+
if (modellingRule === "Optional" && classDef.baseClassDef) {
|
|
139
|
+
const sameMember = classDef.baseClassDef.members.find((m) => m.browseName.name === mm.browseName.name);
|
|
140
|
+
if (sameMember) {
|
|
141
|
+
if (!sameMember.isOptional) {
|
|
142
|
+
console.log(chalk_1.default.cyan("Warning: ") +
|
|
143
|
+
chalk_1.default.yellow(classDef.browseName.toString()) +
|
|
144
|
+
" ModellingRule is Optional but base class member is Mandatory");
|
|
145
|
+
modellingRule = "Mandatory";
|
|
161
146
|
}
|
|
162
147
|
}
|
|
163
|
-
r[modellingRule] = r[modellingRule] || [];
|
|
164
|
-
r[modellingRule].push(mm);
|
|
165
148
|
}
|
|
149
|
+
r[modellingRule] = r[modellingRule] || [];
|
|
150
|
+
r[modellingRule].push(mm);
|
|
166
151
|
}
|
|
167
|
-
|
|
168
|
-
|
|
152
|
+
}
|
|
153
|
+
return r;
|
|
169
154
|
}
|
|
170
|
-
function extractAllMembers(session, classDef, cache) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
m.push(mm);
|
|
182
|
-
}
|
|
155
|
+
async function extractAllMembers(session, classDef, cache) {
|
|
156
|
+
const m = [...classDef.children];
|
|
157
|
+
let s = classDef;
|
|
158
|
+
while (s.baseClassDef) {
|
|
159
|
+
s = s.baseClassDef;
|
|
160
|
+
// start from top most class
|
|
161
|
+
// do not overwrite most top member definition, so we get mandatory stuff
|
|
162
|
+
for (const mm of s.children) {
|
|
163
|
+
const found = m.findIndex((r) => r.browseName.toString() === mm.browseName.toString());
|
|
164
|
+
if (found < 0) {
|
|
165
|
+
m.push(mm);
|
|
183
166
|
}
|
|
184
167
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
168
|
+
}
|
|
169
|
+
// now separate mandatory and optionals
|
|
170
|
+
const members = await classify(session, m, classDef);
|
|
171
|
+
return members;
|
|
189
172
|
}
|
|
190
|
-
function findClassMember(session, browseName, baseParentDef, cache) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return yield findClassMember(session, browseName, baseBaseParentDef, cache);
|
|
203
|
-
});
|
|
173
|
+
async function findClassMember(session, browseName, baseParentDef, cache) {
|
|
174
|
+
const childBrowseName = browseName.toString();
|
|
175
|
+
const r = baseParentDef.children.find((a) => a.browseName.toString() === childBrowseName);
|
|
176
|
+
if (r) {
|
|
177
|
+
const d = await extractClassMemberDef(session, r.nodeId, baseParentDef, cache);
|
|
178
|
+
return d;
|
|
179
|
+
}
|
|
180
|
+
const baseBaseParentDef = baseParentDef.superType && (await extractClassDefinition(session, baseParentDef.superType.nodeId, cache));
|
|
181
|
+
if (!baseBaseParentDef) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
return await findClassMember(session, browseName, baseBaseParentDef, cache);
|
|
204
185
|
}
|
|
205
186
|
exports.findClassMember = findClassMember;
|
|
206
187
|
function hasNewMaterial(referenceMembers, instanceMembers) {
|
|
@@ -241,222 +222,215 @@ function sameInBaseClassIsMandatory(parent, browseName) {
|
|
|
241
222
|
return false;
|
|
242
223
|
return !originalClassMember.isOptional;
|
|
243
224
|
}
|
|
244
|
-
function _extractLocalMembers(session, parent, classMember, cache) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const d = typeDefinition.nodeId.isEmpty() ? null : yield extractClassDefinition(session, typeDefinition.nodeId, cache);
|
|
263
|
-
childType = (d === null || d === void 0 ? void 0 : d.interfaceName) || { name: "UAMethod", module: "BasicType", namespace: -1 };
|
|
264
|
-
}
|
|
265
|
-
// may be childType is already
|
|
266
|
-
const { suffix, suffixInstantiate, typeToReference, chevrons } = yield extractVariableExtra(session, child.nodeId, cache, classMember);
|
|
267
|
-
const c = {
|
|
268
|
-
childType,
|
|
269
|
-
description,
|
|
270
|
-
isOptional,
|
|
271
|
-
modellingRule,
|
|
272
|
-
name,
|
|
273
|
-
suffix,
|
|
274
|
-
suffixInstantiate,
|
|
275
|
-
typeToReference,
|
|
276
|
-
chevrons
|
|
277
|
-
};
|
|
278
|
-
children2.push(c);
|
|
225
|
+
async function _extractLocalMembers(session, parent, classMember, cache) {
|
|
226
|
+
const children2 = [];
|
|
227
|
+
for (const child of classMember.children) {
|
|
228
|
+
const nodeId = child.nodeId;
|
|
229
|
+
const browseName = await (0, utils_1.getBrowseName)(session, nodeId);
|
|
230
|
+
const name = (0, utils2_1.toJavascritPropertyName)(browseName.name, { ignoreConflictingName: true });
|
|
231
|
+
const description = await (0, utils_1.getDescription)(session, nodeId);
|
|
232
|
+
const modellingRule = await (0, utils_1.getModellingRule)(session, nodeId);
|
|
233
|
+
const isOptional = sameInBaseClassIsMandatory(parent, browseName) ? false : modellingRule === "Optional";
|
|
234
|
+
const typeDefinition = await (0, utils_1.getTypeDefOrBaseType)(session, nodeId);
|
|
235
|
+
const childInBase = classMember.classDef?.members.find((a) => a.browseName.toString() === browseName.toString());
|
|
236
|
+
let childType;
|
|
237
|
+
if (childInBase) {
|
|
238
|
+
childType = childInBase.childType;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
const d = typeDefinition.nodeId.isEmpty() ? null : await extractClassDefinition(session, typeDefinition.nodeId, cache);
|
|
242
|
+
childType = d?.interfaceName || { name: "UAMethod", module: "BasicType", namespace: -1 };
|
|
279
243
|
}
|
|
280
|
-
|
|
281
|
-
|
|
244
|
+
// may be childType is already
|
|
245
|
+
const { suffix, suffixInstantiate, typeToReference, chevrons } = await extractVariableExtra(session, child.nodeId, cache, classMember);
|
|
246
|
+
const c = {
|
|
247
|
+
childType,
|
|
248
|
+
description,
|
|
249
|
+
isOptional,
|
|
250
|
+
modellingRule,
|
|
251
|
+
name,
|
|
252
|
+
suffix,
|
|
253
|
+
suffixInstantiate,
|
|
254
|
+
typeToReference,
|
|
255
|
+
chevrons
|
|
256
|
+
};
|
|
257
|
+
children2.push(c);
|
|
258
|
+
}
|
|
259
|
+
return children2;
|
|
282
260
|
}
|
|
283
261
|
function isUnspecifiedDataType(dataType) {
|
|
284
262
|
return dataType === node_opcua_variant_1.DataType.Null || dataType === node_opcua_variant_1.DataType.Variant;
|
|
285
263
|
}
|
|
286
|
-
function extractVariableExtra(session, nodeId, cache, classMember) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
if (!isUnspecifiedDataType(typeDefCD.dataType)) {
|
|
316
|
-
suffixInstantiate = "<any>";
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
suffixInstantiate = "<any, any>";
|
|
320
|
-
}
|
|
264
|
+
async function extractVariableExtra(session, nodeId, cache, classMember) {
|
|
265
|
+
const typeToReference = [];
|
|
266
|
+
const importCollector = (i) => {
|
|
267
|
+
typeToReference.push(i);
|
|
268
|
+
cache.ensureImported(i);
|
|
269
|
+
};
|
|
270
|
+
const nodeClass = await (0, utils_1.getNodeClass)(session, nodeId);
|
|
271
|
+
if (nodeClass === node_opcua_data_model_1.NodeClass.Variable) {
|
|
272
|
+
const dataTypeNodeId = await (0, utils_1.getDataTypeNodeId)(session, nodeId);
|
|
273
|
+
const { dataType, jtype } = await (0, get_corresponding_data_type_1.getCorrespondingJavascriptType2)(session, nodeId, dataTypeNodeId, cache, importCollector);
|
|
274
|
+
cache && cache.referenceBasicType("DataType");
|
|
275
|
+
importCollector({ name: "DataType", namespace: -1, module: "BasicType" });
|
|
276
|
+
const t = isUnspecifiedDataType(classMember.classDef?.dataType);
|
|
277
|
+
const suffix = jtype === "undefined" || isUnspecifiedDataType(dataType)
|
|
278
|
+
? `<any, any>`
|
|
279
|
+
: `<${jtype}${t ? `, ${m0}DataType.${node_opcua_variant_1.DataType[dataType]}` : ""}>`;
|
|
280
|
+
// const suffix2 = `<T${t ? `, /DT extends DataType` : ""}>`;
|
|
281
|
+
const suffix3 = `<T${t ? `, ${m1}DT` : ""}>`;
|
|
282
|
+
const typeDef = await (0, utils_1.getTypeDefOrBaseType)(session, nodeId);
|
|
283
|
+
const typeDefCD = await extractClassDefinition(session, typeDef.nodeId, cache);
|
|
284
|
+
const chevrons = calculateChevrons(typeDefCD, { dataType });
|
|
285
|
+
const suffix2 = chevrons.chevronsDef;
|
|
286
|
+
/** Suffix for instantiation
|
|
287
|
+
* if typeDef.dataType is not null, then we need to add a type argument
|
|
288
|
+
*/
|
|
289
|
+
let suffixInstantiate = "";
|
|
290
|
+
if (isUnspecifiedDataType(dataType)) {
|
|
291
|
+
if (!isUnspecifiedDataType(typeDefCD.dataType)) {
|
|
292
|
+
suffixInstantiate = "<any>";
|
|
321
293
|
}
|
|
322
294
|
else {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
295
|
+
suffixInstantiate = "<any, any>";
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
if (!isUnspecifiedDataType(typeDefCD.dataType)) {
|
|
300
|
+
suffixInstantiate = `<${jtype}>`;
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
suffixInstantiate = `<${jtype}, DataType.${node_opcua_variant_1.DataType[dataType]}>`;
|
|
329
304
|
}
|
|
330
|
-
return { suffixInstantiate, suffix, suffix2, suffix3, dataTypeNodeId, dataType, jtype, typeToReference, chevrons };
|
|
331
305
|
}
|
|
332
|
-
return { suffix
|
|
333
|
-
}
|
|
306
|
+
return { suffixInstantiate, suffix, suffix2, suffix3, dataTypeNodeId, dataType, jtype, typeToReference, chevrons };
|
|
307
|
+
}
|
|
308
|
+
return { suffix: "", typeToReference };
|
|
334
309
|
}
|
|
335
310
|
// eslint-disable-next-line max-statements
|
|
336
|
-
function extractClassMemberDef(session, nodeId, parentDef, cache) {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
if (
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
childType = innerClass;
|
|
383
|
-
}
|
|
384
|
-
else {
|
|
385
|
-
innerClass = {
|
|
386
|
-
module: parentDef.interfaceName.module,
|
|
387
|
-
name: parentDef.interfaceName.name + "_" + name,
|
|
388
|
-
namespace: nodeId.namespace
|
|
389
|
-
};
|
|
390
|
-
childBase = childType;
|
|
391
|
-
childType = innerClass;
|
|
392
|
-
}
|
|
393
|
-
(0, node_opcua_assert_1.default)(innerClass);
|
|
394
|
-
(0, node_opcua_assert_1.default)(childBase);
|
|
311
|
+
async function extractClassMemberDef(session, nodeId, parentDef, cache) {
|
|
312
|
+
const nodeClass = await (0, utils_1.getNodeClass)(session, nodeId);
|
|
313
|
+
const browseName = await (0, utils_1.getBrowseName)(session, nodeId);
|
|
314
|
+
const name = (0, utils2_1.toJavascritPropertyName)(browseName.name, { ignoreConflictingName: true });
|
|
315
|
+
if (nodeClass !== node_opcua_data_model_1.NodeClass.Method && nodeClass !== node_opcua_data_model_1.NodeClass.Object && nodeClass !== node_opcua_data_model_1.NodeClass.Variable) {
|
|
316
|
+
throw new Error("Invalid property " + node_opcua_data_model_1.NodeClass[nodeClass] + " " + browseName?.toString() + " " + nodeId.toString());
|
|
317
|
+
}
|
|
318
|
+
const description = await (0, utils_1.getDescription)(session, nodeId);
|
|
319
|
+
const children = await (0, utils_1.getChildrenOrFolderElements)(session, nodeId);
|
|
320
|
+
const modellingRule = await (0, utils_1.getModellingRule)(session, nodeId);
|
|
321
|
+
const isOptional = sameInBaseClassIsMandatory(parentDef, browseName) ? false : modellingRule === "Optional";
|
|
322
|
+
const typeDefinition = await (0, utils_1.getTypeDefOrBaseType)(session, nodeId);
|
|
323
|
+
if (nodeClass !== node_opcua_data_model_1.NodeClass.Method && (!typeDefinition.browseName || !typeDefinition.browseName.name)) {
|
|
324
|
+
warningLog(typeDefinition.toString());
|
|
325
|
+
warningLog("cannot find typeDefinition for ", browseName.toString(), "( is the namespace loaded ?)");
|
|
326
|
+
}
|
|
327
|
+
let childType = makeTypeName2(nodeClass, typeDefinition.browseName);
|
|
328
|
+
const classDef = typeDefinition.nodeId.isEmpty() ? null : await extractClassDefinition(session, typeDefinition.nodeId, cache);
|
|
329
|
+
let innerClass = null;
|
|
330
|
+
let childBase = null;
|
|
331
|
+
let shouldExposeInnerDefinition = false;
|
|
332
|
+
// find member exposed by type definition
|
|
333
|
+
const baseParentDef = parentDef.superType && (await extractClassDefinition(session, parentDef.superType.nodeId, cache));
|
|
334
|
+
if (classDef && baseParentDef) {
|
|
335
|
+
const chevrons1 = calculateChevrons(classDef, baseParentDef);
|
|
336
|
+
(0, node_opcua_assert_1.default)(!innerClass);
|
|
337
|
+
// let's extract the member that are theorically defined in the member
|
|
338
|
+
const membersReference = await extractAllMembers(session, classDef, cache);
|
|
339
|
+
// find member exposed by this member
|
|
340
|
+
const membersInstance = await classify(session, children, classDef);
|
|
341
|
+
// if (name==="powerup") {
|
|
342
|
+
// dump1(membersReference);
|
|
343
|
+
// dump1(membersInstance);
|
|
344
|
+
// await extractAllMembers(session, classDef, cache);
|
|
345
|
+
// }
|
|
346
|
+
shouldExposeInnerDefinition = checkIfShouldExposeInnerDefinition(membersReference, membersInstance);
|
|
347
|
+
const sameMemberInBaseClass = baseParentDef && (await findClassMember(session, browseName, baseParentDef, cache));
|
|
348
|
+
if (shouldExposeInnerDefinition) {
|
|
349
|
+
if (sameMemberInBaseClass) {
|
|
350
|
+
innerClass = {
|
|
351
|
+
module: parentDef.interfaceName.module,
|
|
352
|
+
name: parentDef.interfaceName.name + "_" + name,
|
|
353
|
+
namespace: nodeId.namespace
|
|
354
|
+
};
|
|
355
|
+
childBase = sameMemberInBaseClass.childType;
|
|
356
|
+
childType = innerClass;
|
|
395
357
|
}
|
|
396
358
|
else {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
359
|
+
innerClass = {
|
|
360
|
+
module: parentDef.interfaceName.module,
|
|
361
|
+
name: parentDef.interfaceName.name + "_" + name,
|
|
362
|
+
namespace: nodeId.namespace
|
|
363
|
+
};
|
|
364
|
+
childBase = childType;
|
|
365
|
+
childType = innerClass;
|
|
402
366
|
}
|
|
367
|
+
(0, node_opcua_assert_1.default)(innerClass);
|
|
368
|
+
(0, node_opcua_assert_1.default)(childBase);
|
|
403
369
|
}
|
|
404
370
|
else {
|
|
405
|
-
// the
|
|
406
|
-
//
|
|
371
|
+
// may not expose definition but we may want to used the augment typescript class defined in the definition
|
|
372
|
+
// we don't need to create an inner class ...
|
|
373
|
+
childType = sameMemberInBaseClass ? sameMemberInBaseClass?.childType : childType;
|
|
407
374
|
(0, node_opcua_assert_1.default)(!innerClass);
|
|
408
375
|
(0, node_opcua_assert_1.default)(!childBase);
|
|
409
376
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
// the lass member has no HasTypeDefinition reference
|
|
380
|
+
// may be is a method
|
|
381
|
+
(0, node_opcua_assert_1.default)(!innerClass);
|
|
382
|
+
(0, node_opcua_assert_1.default)(!childBase);
|
|
383
|
+
}
|
|
384
|
+
let classMember = {
|
|
385
|
+
name,
|
|
386
|
+
nodeClass,
|
|
387
|
+
browseName,
|
|
388
|
+
modellingRule,
|
|
389
|
+
isOptional,
|
|
390
|
+
classDef,
|
|
391
|
+
description,
|
|
392
|
+
typeDefinition,
|
|
393
|
+
childType,
|
|
394
|
+
suffix2: "",
|
|
395
|
+
suffix: "",
|
|
396
|
+
suffix3: "",
|
|
397
|
+
suffixInstantiate: "",
|
|
398
|
+
children,
|
|
399
|
+
children2: [],
|
|
400
|
+
typeToReference: [],
|
|
401
|
+
//
|
|
402
|
+
innerClass,
|
|
403
|
+
childBase,
|
|
404
|
+
chevrons: null
|
|
405
|
+
};
|
|
406
|
+
classMember.children2 = await _extractLocalMembers(session, classDef, classMember, cache);
|
|
407
|
+
if (nodeClass === node_opcua_data_model_1.NodeClass.Variable) {
|
|
408
|
+
const extra = await extractVariableExtra(session, nodeId, cache, classMember);
|
|
409
|
+
classMember = {
|
|
410
|
+
...classMember,
|
|
411
|
+
...extra
|
|
431
412
|
};
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
const extra = yield extractVariableExtra(session, nodeId, cache, classMember);
|
|
435
|
-
classMember = Object.assign(Object.assign({}, classMember), extra);
|
|
436
|
-
}
|
|
437
|
-
return classMember;
|
|
438
|
-
});
|
|
413
|
+
}
|
|
414
|
+
return classMember;
|
|
439
415
|
}
|
|
440
416
|
exports.extractClassMemberDef = extractClassMemberDef;
|
|
441
|
-
function preDumpChildren(padding, classDef, f, cache) {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
}
|
|
459
|
-
});
|
|
417
|
+
async function preDumpChildren(padding, classDef, f, cache) {
|
|
418
|
+
f = f || new node_opcua_utils_1.LineFile();
|
|
419
|
+
for (const memberDef of classDef.members) {
|
|
420
|
+
const { innerClass, suffix2, suffix3, nodeClass, childBase, chevrons } = memberDef;
|
|
421
|
+
if (!innerClass || !childBase) {
|
|
422
|
+
continue; // no need to expose inner class
|
|
423
|
+
}
|
|
424
|
+
cache.ensureImported(childBase);
|
|
425
|
+
if (innerClass.name === "UAPubSubDiagnostics_counters" || innerClass.name === "UAProgramStateMachine_currentState") {
|
|
426
|
+
// debugger;
|
|
427
|
+
}
|
|
428
|
+
const baseStuff = getBaseClassWithOmit2(memberDef);
|
|
429
|
+
//f.write(`export interface ${innerClass.name}${suffix2} extends ${childBase.name}${suffix3} { // ${NodeClass[nodeClass]}`);
|
|
430
|
+
f.write(`export interface ${innerClass.name}${suffix2} extends ${baseStuff} { // ${node_opcua_data_model_1.NodeClass[nodeClass]}`);
|
|
431
|
+
await dumpChildren(padding + " ", memberDef.children2, f, cache);
|
|
432
|
+
f.write("}");
|
|
433
|
+
}
|
|
460
434
|
}
|
|
461
435
|
const isPlaceHolder = (def) => {
|
|
462
436
|
const { modellingRule } = def;
|
|
@@ -607,7 +581,7 @@ function getBaseClassWithOmit(classDef) {
|
|
|
607
581
|
// console.log("conflictingMembers = ", conflictingMembers.map((a) => a.name).join(" "));
|
|
608
582
|
}
|
|
609
583
|
const chBase = calculateChevrons(classDef.baseClassDef, classDef);
|
|
610
|
-
let baseStuff = `${baseInterfaceName
|
|
584
|
+
let baseStuff = `${baseInterfaceName?.name}${chBase.chevronsUse}`;
|
|
611
585
|
if (conflictingMembers.length) {
|
|
612
586
|
baseStuff = `Omit<${baseStuff}, ${conflictingMembers.map((a) => `"${a.name}"`).join("|")}>`;
|
|
613
587
|
}
|
|
@@ -622,7 +596,7 @@ function getBaseClassWithOmit2(classMember) {
|
|
|
622
596
|
doDebug && console.log("conflictingMembers = ", conflictingMembers.map((a) => a.name).join(" "));
|
|
623
597
|
}
|
|
624
598
|
const childBase = classMember.childBase;
|
|
625
|
-
let baseStuff = `${childBase
|
|
599
|
+
let baseStuff = `${childBase?.name}${classMember.suffix3}`;
|
|
626
600
|
if (conflictingMembers.length) {
|
|
627
601
|
baseStuff = `Omit<${baseStuff}, ${conflictingMembers.map((a) => `"${a.name}"`).join("|")}>`;
|
|
628
602
|
}
|
|
@@ -632,129 +606,125 @@ function getBaseClassWithOmit2(classMember) {
|
|
|
632
606
|
* nodeId : a DataType, ReferenceType,AObjectType, VariableType node
|
|
633
607
|
*/
|
|
634
608
|
// eslint-disable-next-line max-statements
|
|
635
|
-
function _convertTypeToTypescript(session, nodeId, cache, f) {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
609
|
+
async function _convertTypeToTypescript(session, nodeId, cache, f) {
|
|
610
|
+
f = f || new node_opcua_utils_1.LineFile();
|
|
611
|
+
const nodeClass = await (0, utils_1.getNodeClass)(session, nodeId);
|
|
612
|
+
if (nodeClass === node_opcua_data_model_1.NodeClass.DataType) {
|
|
613
|
+
return await (0, _dataType_1._exportDataTypeToTypescript)(session, nodeId, cache, f);
|
|
614
|
+
}
|
|
615
|
+
const classDef = await extractClassDefinition(session, nodeId, cache);
|
|
616
|
+
// if (classDef.browseName.toString().match(/PubSubDiagnosticsWriterGroupType/)) {
|
|
617
|
+
// debugger;
|
|
618
|
+
// }
|
|
619
|
+
const { dataTypeName, dataType, dataTypeNodeId, interfaceName, baseInterfaceName, browseName, description, isAbstract, members } = classDef;
|
|
620
|
+
await preDumpChildren(" ", classDef, f, cache);
|
|
621
|
+
const n = (n) => n?.toString().replace(/ns=([0-9]+);/, "");
|
|
622
|
+
// f.write(superType.toString());
|
|
623
|
+
f.write(`/**`);
|
|
624
|
+
if (description.text) {
|
|
625
|
+
f.write((0, utils2_1.toComment)(" * ", description.text || ""));
|
|
626
|
+
f.write(` *`);
|
|
627
|
+
}
|
|
628
|
+
f.write(` * | |${(0, utils2_1.f1)(" ")}|`);
|
|
629
|
+
f.write(` * |----------------|${(0, utils2_1.f2)("-")}|`);
|
|
630
|
+
f.write(` * |namespace |${(0, utils2_1.f1)(cache.namespace[nodeId.namespace].namespaceUri)}|`);
|
|
631
|
+
f.write(` * |nodeClass |${(0, utils2_1.f1)(node_opcua_data_model_1.NodeClass[nodeClass])}|`);
|
|
632
|
+
f.write(` * |typedDefinition |${(0, utils2_1.f1)(browseName.name.toString() + " " + n(nodeId))}|`);
|
|
633
|
+
if (nodeClass === node_opcua_data_model_1.NodeClass.VariableType) {
|
|
634
|
+
f.write(` * |dataType |${(0, utils2_1.f1)(node_opcua_variant_1.DataType[dataType])}|`);
|
|
635
|
+
f.write(` * |dataType Name |${(0, utils2_1.f1)(dataTypeName + " " + n(dataTypeNodeId))}|`);
|
|
636
|
+
}
|
|
637
|
+
f.write(` * |isAbstract |${(0, utils2_1.f1)(isAbstract.toString())}|`);
|
|
638
|
+
f.write(` */`);
|
|
639
|
+
// if (interfaceName.name === "UAOperationLimits") {
|
|
640
|
+
// debugger;
|
|
641
|
+
// }
|
|
642
|
+
cache.ensureImported(baseInterfaceName);
|
|
643
|
+
cache.ensureImported({ ...baseInterfaceName, name: baseInterfaceName.name + `${baseExtension}` });
|
|
644
|
+
const ch = calculateChevrons(classDef);
|
|
645
|
+
{
|
|
660
646
|
if (nodeClass === node_opcua_data_model_1.NodeClass.VariableType) {
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
// }
|
|
669
|
-
cache.ensureImported(baseInterfaceName);
|
|
670
|
-
cache.ensureImported(Object.assign(Object.assign({}, baseInterfaceName), { name: baseInterfaceName.name + `${baseExtension}` }));
|
|
671
|
-
const ch = calculateChevrons(classDef);
|
|
672
|
-
{
|
|
673
|
-
if (nodeClass === node_opcua_data_model_1.NodeClass.VariableType) {
|
|
674
|
-
if (classDef.dataTypeImport) {
|
|
675
|
-
// istanbul ignore next
|
|
676
|
-
if (doDebug) {
|
|
677
|
-
debugLog(chalk_1.default.red(" ----------------> ", classDef.browseName));
|
|
678
|
-
classDef.dataTypeImport.forEach((a) => {
|
|
679
|
-
debugLog(chalk_1.default.red(" ------------------------> ", a.module, a.name, a.namespace));
|
|
680
|
-
});
|
|
681
|
-
}
|
|
682
|
-
classDef.dataTypeImport.forEach(cache.ensureImported.bind(cache));
|
|
683
|
-
}
|
|
684
|
-
cache.referenceBasicType("DataType");
|
|
685
|
-
const chevrons = calculateChevrons(classDef);
|
|
686
|
-
const chevronsBase = calculateChevrons(classDef.baseClassDef, classDef);
|
|
687
|
-
// Shall we cache.ensureImported({ ...baseInterfaceName!, module: dataTypeName, name: dataTypeName });
|
|
688
|
-
const classBaseName = `${interfaceName.name}${baseExtension}${chevrons.chevronsDef}`;
|
|
689
|
-
if (countExposedChildren(members) === 0 && (baseInterfaceName === null || baseInterfaceName === void 0 ? void 0 : baseInterfaceName.name) !== "UAVariableT") {
|
|
690
|
-
//
|
|
691
|
-
const baseName = `${baseInterfaceName === null || baseInterfaceName === void 0 ? void 0 : baseInterfaceName.name}${baseExtension}${chevronsBase.chevronsExtend}`;
|
|
692
|
-
f.write(`export type ${classBaseName} = ${baseName};`);
|
|
693
|
-
}
|
|
694
|
-
else {
|
|
695
|
-
if ((baseInterfaceName === null || baseInterfaceName === void 0 ? void 0 : baseInterfaceName.name) === "UAVariableT") {
|
|
696
|
-
f.write(`export interface ${classBaseName} {`);
|
|
697
|
-
}
|
|
698
|
-
else {
|
|
699
|
-
const baseName = `${baseInterfaceName === null || baseInterfaceName === void 0 ? void 0 : baseInterfaceName.name}${baseExtension}${chevronsBase.chevronsExtend}`;
|
|
700
|
-
f.write(`export interface ${classBaseName} extends ${baseName} {`);
|
|
701
|
-
}
|
|
702
|
-
yield dumpChildren(" ", members, f, cache);
|
|
703
|
-
f.write(`}`);
|
|
647
|
+
if (classDef.dataTypeImport) {
|
|
648
|
+
// istanbul ignore next
|
|
649
|
+
if (doDebug) {
|
|
650
|
+
debugLog(chalk_1.default.red(" ----------------> ", classDef.browseName));
|
|
651
|
+
classDef.dataTypeImport.forEach((a) => {
|
|
652
|
+
debugLog(chalk_1.default.red(" ------------------------> ", a.module, a.name, a.namespace));
|
|
653
|
+
});
|
|
704
654
|
}
|
|
655
|
+
classDef.dataTypeImport.forEach(cache.ensureImported.bind(cache));
|
|
656
|
+
}
|
|
657
|
+
cache.referenceBasicType("DataType");
|
|
658
|
+
const chevrons = calculateChevrons(classDef);
|
|
659
|
+
const chevronsBase = calculateChevrons(classDef.baseClassDef, classDef);
|
|
660
|
+
// Shall we cache.ensureImported({ ...baseInterfaceName!, module: dataTypeName, name: dataTypeName });
|
|
661
|
+
const classBaseName = `${interfaceName.name}${baseExtension}${chevrons.chevronsDef}`;
|
|
662
|
+
if (countExposedChildren(members) === 0 && baseInterfaceName?.name !== "UAVariableT") {
|
|
663
|
+
//
|
|
664
|
+
const baseName = `${baseInterfaceName?.name}${baseExtension}${chevronsBase.chevronsExtend}`;
|
|
665
|
+
f.write(`export type ${classBaseName} = ${baseName};`);
|
|
705
666
|
}
|
|
706
667
|
else {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
const baseName = `${baseInterfaceName === null || baseInterfaceName === void 0 ? void 0 : baseInterfaceName.name}${baseExtension}`;
|
|
710
|
-
f.write(`export type ${classBaseName} = ${baseName};`);
|
|
668
|
+
if (baseInterfaceName?.name === "UAVariableT") {
|
|
669
|
+
f.write(`export interface ${classBaseName} {`);
|
|
711
670
|
}
|
|
712
671
|
else {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
}
|
|
716
|
-
else {
|
|
717
|
-
const baseName = `${baseInterfaceName === null || baseInterfaceName === void 0 ? void 0 : baseInterfaceName.name}${baseExtension}`;
|
|
718
|
-
f.write(`export interface ${classBaseName} extends ${baseName} {`);
|
|
719
|
-
}
|
|
720
|
-
yield dumpChildren(" ", members, f, cache);
|
|
721
|
-
f.write(`}`);
|
|
672
|
+
const baseName = `${baseInterfaceName?.name}${baseExtension}${chevronsBase.chevronsExtend}`;
|
|
673
|
+
f.write(`export interface ${classBaseName} extends ${baseName} {`);
|
|
722
674
|
}
|
|
675
|
+
await dumpChildren(" ", members, f, cache);
|
|
676
|
+
f.write(`}`);
|
|
723
677
|
}
|
|
724
678
|
}
|
|
725
|
-
const baseStuff = getBaseClassWithOmit(classDef);
|
|
726
|
-
if (nodeClass === node_opcua_data_model_1.NodeClass.VariableType) {
|
|
727
|
-
cache.referenceBasicType("DataType");
|
|
728
|
-
// if dataType is a extension object we can simpligy by forcing DT
|
|
729
|
-
const className = `${interfaceName.name}${ch.chevronsDef}`;
|
|
730
|
-
const c = isUnspecifiedDataType(dataType) ? `<T, DT${mB}>` : `<T${mC}>`;
|
|
731
|
-
const classBaseName = `${interfaceName.name}${baseExtension}${c}`;
|
|
732
|
-
f.write(`export interface ${className} extends ${baseStuff}, ${classBaseName} {`);
|
|
733
|
-
}
|
|
734
679
|
else {
|
|
735
|
-
const className = `${interfaceName.name}`;
|
|
736
680
|
const classBaseName = `${interfaceName.name}${baseExtension}`;
|
|
737
|
-
|
|
681
|
+
if (countExposedChildren(members) === 0 && baseInterfaceName?.name !== "UAObject") {
|
|
682
|
+
const baseName = `${baseInterfaceName?.name}${baseExtension}`;
|
|
683
|
+
f.write(`export type ${classBaseName} = ${baseName};`);
|
|
684
|
+
}
|
|
685
|
+
else {
|
|
686
|
+
if (baseInterfaceName?.name === "UAObject") {
|
|
687
|
+
f.write(`export interface ${classBaseName} {`);
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
const baseName = `${baseInterfaceName?.name}${baseExtension}`;
|
|
691
|
+
f.write(`export interface ${classBaseName} extends ${baseName} {`);
|
|
692
|
+
}
|
|
693
|
+
await dumpChildren(" ", members, f, cache);
|
|
694
|
+
f.write(`}`);
|
|
695
|
+
}
|
|
738
696
|
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
697
|
+
}
|
|
698
|
+
const baseStuff = getBaseClassWithOmit(classDef);
|
|
699
|
+
if (nodeClass === node_opcua_data_model_1.NodeClass.VariableType) {
|
|
700
|
+
cache.referenceBasicType("DataType");
|
|
701
|
+
// if dataType is a extension object we can simpligy by forcing DT
|
|
702
|
+
const className = `${interfaceName.name}${ch.chevronsDef}`;
|
|
703
|
+
const c = isUnspecifiedDataType(dataType) ? `<T, DT${mB}>` : `<T${mC}>`;
|
|
704
|
+
const classBaseName = `${interfaceName.name}${baseExtension}${c}`;
|
|
705
|
+
f.write(`export interface ${className} extends ${baseStuff}, ${classBaseName} {`);
|
|
706
|
+
}
|
|
707
|
+
else {
|
|
708
|
+
const className = `${interfaceName.name}`;
|
|
709
|
+
const classBaseName = `${interfaceName.name}${baseExtension}`;
|
|
710
|
+
f.write(`export interface ${className} extends ${baseStuff}, ${classBaseName} {`);
|
|
711
|
+
}
|
|
712
|
+
f.write(`}`);
|
|
713
|
+
return { type: "ua", content: f.toString(), typeName: interfaceName.name };
|
|
742
714
|
}
|
|
743
715
|
exports._convertTypeToTypescript = _convertTypeToTypescript;
|
|
744
|
-
function convertTypeToTypescript(session, nodeId, options, cache, f) {
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
return { type, content: f.toString(), folder, module, filename, dependencies };
|
|
757
|
-
});
|
|
716
|
+
async function convertTypeToTypescript(session, nodeId, options, cache, f) {
|
|
717
|
+
f = new node_opcua_utils_1.LineFile();
|
|
718
|
+
cache = cache || (await (0, cache_1.constructCache)(session, options));
|
|
719
|
+
const { type, content, typeName } = await _convertTypeToTypescript(session, nodeId, cache);
|
|
720
|
+
f.write(`// ----- this file has been automatically generated - do not edit`);
|
|
721
|
+
f.write(dumpUsedExport(typeName, nodeId.namespace, cache));
|
|
722
|
+
f.write(content);
|
|
723
|
+
const folder = cache.namespace[nodeId.namespace].sourceFolder;
|
|
724
|
+
const module = cache.namespace[nodeId.namespace].module;
|
|
725
|
+
const filename = (0, to_filename_1.toFilename)(typeName);
|
|
726
|
+
const dependencies = findUsedImport(nodeId.namespace, cache);
|
|
727
|
+
return { type, content: f.toString(), folder, module, filename, dependencies };
|
|
758
728
|
}
|
|
759
729
|
exports.convertTypeToTypescript = convertTypeToTypescript;
|
|
760
730
|
//# sourceMappingURL=convert_to_typescript.js.map
|