node-opcua-convert-nodeset-to-javascript 2.112.0 → 2.114.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 +419 -447
- 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
- package/source/convert_to_typescript.ts +5 -3
|
@@ -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
|
};
|
|
@@ -28,6 +19,7 @@ const utils2_1 = require("./utils2");
|
|
|
28
19
|
const _dataType_1 = require("./_dataType");
|
|
29
20
|
const get_corresponding_data_type_1 = require("./private/get_corresponding_data_type");
|
|
30
21
|
const warningLog = (0, node_opcua_debug_1.make_warningLog)("typescript");
|
|
22
|
+
const debugLog = (0, node_opcua_debug_1.make_debugLog)("typescript");
|
|
31
23
|
const doDebug = false;
|
|
32
24
|
const baseExtension = "_Base";
|
|
33
25
|
const m0 = !doDebug ? "" : `/* 0 */`;
|
|
@@ -43,20 +35,18 @@ const m9 = !doDebug ? "" : `/* 9 */`;
|
|
|
43
35
|
const mA = !doDebug ? "" : `/* a */`;
|
|
44
36
|
const mB = !doDebug ? "" : `/* b */`;
|
|
45
37
|
const mC = !doDebug ? "" : `/* c */`;
|
|
46
|
-
function convertDataTypeToTypescript(session, dataTypeId) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
/** */
|
|
56
|
-
}
|
|
57
|
-
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
|
+
/** */
|
|
58
47
|
}
|
|
59
|
-
|
|
48
|
+
f.write(`}`);
|
|
49
|
+
}
|
|
60
50
|
}
|
|
61
51
|
exports.convertDataTypeToTypescript = convertDataTypeToTypescript;
|
|
62
52
|
function makeTypeName2(nodeClass, browseName, suffix) {
|
|
@@ -67,139 +57,131 @@ function makeTypeName2(nodeClass, browseName, suffix) {
|
|
|
67
57
|
return (0, cache_1.makeTypeNameNew)(nodeClass, null, browseName, suffix);
|
|
68
58
|
}
|
|
69
59
|
exports.makeTypeName2 = makeTypeName2;
|
|
70
|
-
function extractClassDefinition(session, nodeId, cache) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
cache.ensureImported(i);
|
|
95
|
-
};
|
|
96
|
-
const { jtype } = yield (0, get_corresponding_data_type_1.getCorrespondingJavascriptType2)(session, nodeId, dataTypeNodeId, cache, importCollector);
|
|
97
|
-
dataTypeName = jtype; // with decoration
|
|
98
|
-
if (!(dataTypeNodeId === null || dataTypeNodeId === void 0 ? void 0 : dataTypeNodeId.isEmpty())) {
|
|
99
|
-
// "DT" + (await getBrowseName(session, dataTypeNodeId!))?.name! || "";
|
|
100
|
-
// const bn = await getBrowseName(session, dataTypeNodeId!);
|
|
101
|
-
dataTypeImport = extraImports; // makeTypeName2(NodeClass.DataType, bn);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
const baseClassDef = !superType ? null : yield extractClassDefinition(session, superType.nodeId, cache);
|
|
105
|
-
const description = yield (0, utils_1.getDescription)(session, nodeId);
|
|
106
|
-
// const definition = await getDefinition(session, nodeId);
|
|
107
|
-
const interfaceName = makeTypeName2(nodeClass, browseName);
|
|
108
|
-
const baseInterfaceName = !superType ? null : makeTypeName2(nodeClass, superType.browseName);
|
|
109
|
-
// extract member
|
|
110
|
-
const children = yield (0, utils_1.getChildrenOrFolderElements)(session, nodeId);
|
|
111
|
-
const members = [];
|
|
112
|
-
classDef = {
|
|
113
|
-
nodeClass,
|
|
114
|
-
browseName,
|
|
115
|
-
isAbstract,
|
|
116
|
-
dataType,
|
|
117
|
-
dataTypeNodeId,
|
|
118
|
-
dataTypeName,
|
|
119
|
-
dataTypeImport,
|
|
120
|
-
superType,
|
|
121
|
-
baseClassDef,
|
|
122
|
-
description,
|
|
123
|
-
// definition,
|
|
124
|
-
children,
|
|
125
|
-
members,
|
|
126
|
-
interfaceName,
|
|
127
|
-
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);
|
|
128
84
|
};
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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);
|
|
133
91
|
}
|
|
134
|
-
|
|
135
|
-
|
|
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;
|
|
136
124
|
}
|
|
137
125
|
exports.extractClassDefinition = extractClassDefinition;
|
|
138
|
-
function classify(session, refs, classDef) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if (sameMember) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
modellingRule = "Mandatory";
|
|
159
|
-
}
|
|
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";
|
|
160
146
|
}
|
|
161
147
|
}
|
|
162
|
-
r[modellingRule] = r[modellingRule] || [];
|
|
163
|
-
r[modellingRule].push(mm);
|
|
164
148
|
}
|
|
149
|
+
r[modellingRule] = r[modellingRule] || [];
|
|
150
|
+
r[modellingRule].push(mm);
|
|
165
151
|
}
|
|
166
|
-
|
|
167
|
-
|
|
152
|
+
}
|
|
153
|
+
return r;
|
|
168
154
|
}
|
|
169
|
-
function extractAllMembers(session, classDef, cache) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
m.push(mm);
|
|
181
|
-
}
|
|
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);
|
|
182
166
|
}
|
|
183
167
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
168
|
+
}
|
|
169
|
+
// now separate mandatory and optionals
|
|
170
|
+
const members = await classify(session, m, classDef);
|
|
171
|
+
return members;
|
|
188
172
|
}
|
|
189
|
-
function findClassMember(session, browseName, baseParentDef, cache) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
return yield findClassMember(session, browseName, baseBaseParentDef, cache);
|
|
202
|
-
});
|
|
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);
|
|
203
185
|
}
|
|
204
186
|
exports.findClassMember = findClassMember;
|
|
205
187
|
function hasNewMaterial(referenceMembers, instanceMembers) {
|
|
@@ -240,222 +222,215 @@ function sameInBaseClassIsMandatory(parent, browseName) {
|
|
|
240
222
|
return false;
|
|
241
223
|
return !originalClassMember.isOptional;
|
|
242
224
|
}
|
|
243
|
-
function _extractLocalMembers(session, parent, classMember, cache) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
const d = typeDefinition.nodeId.isEmpty() ? null : yield extractClassDefinition(session, typeDefinition.nodeId, cache);
|
|
262
|
-
childType = (d === null || d === void 0 ? void 0 : d.interfaceName) || { name: "UAMethod", module: "BasicType", namespace: -1 };
|
|
263
|
-
}
|
|
264
|
-
// may be childType is already
|
|
265
|
-
const { suffix, suffixInstantiate, typeToReference, chevrons } = yield extractVariableExtra(session, child.nodeId, cache, classMember);
|
|
266
|
-
const c = {
|
|
267
|
-
childType,
|
|
268
|
-
description,
|
|
269
|
-
isOptional,
|
|
270
|
-
modellingRule,
|
|
271
|
-
name,
|
|
272
|
-
suffix,
|
|
273
|
-
suffixInstantiate,
|
|
274
|
-
typeToReference,
|
|
275
|
-
chevrons
|
|
276
|
-
};
|
|
277
|
-
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 };
|
|
278
243
|
}
|
|
279
|
-
|
|
280
|
-
|
|
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;
|
|
281
260
|
}
|
|
282
261
|
function isUnspecifiedDataType(dataType) {
|
|
283
262
|
return dataType === node_opcua_variant_1.DataType.Null || dataType === node_opcua_variant_1.DataType.Variant;
|
|
284
263
|
}
|
|
285
|
-
function extractVariableExtra(session, nodeId, cache, classMember) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
if (!isUnspecifiedDataType(typeDefCD.dataType)) {
|
|
315
|
-
suffixInstantiate = "<any>";
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
suffixInstantiate = "<any, any>";
|
|
319
|
-
}
|
|
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>";
|
|
320
293
|
}
|
|
321
294
|
else {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
}
|
|
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]}>`;
|
|
328
304
|
}
|
|
329
|
-
return { suffixInstantiate, suffix, suffix2, suffix3, dataTypeNodeId, dataType, jtype, typeToReference, chevrons };
|
|
330
305
|
}
|
|
331
|
-
return { suffix
|
|
332
|
-
}
|
|
306
|
+
return { suffixInstantiate, suffix, suffix2, suffix3, dataTypeNodeId, dataType, jtype, typeToReference, chevrons };
|
|
307
|
+
}
|
|
308
|
+
return { suffix: "", typeToReference };
|
|
333
309
|
}
|
|
334
310
|
// eslint-disable-next-line max-statements
|
|
335
|
-
function extractClassMemberDef(session, nodeId, parentDef, cache) {
|
|
336
|
-
|
|
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
|
-
if (
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
childType = innerClass;
|
|
382
|
-
}
|
|
383
|
-
else {
|
|
384
|
-
innerClass = {
|
|
385
|
-
module: parentDef.interfaceName.module,
|
|
386
|
-
name: parentDef.interfaceName.name + "_" + name,
|
|
387
|
-
namespace: nodeId.namespace
|
|
388
|
-
};
|
|
389
|
-
childBase = childType;
|
|
390
|
-
childType = innerClass;
|
|
391
|
-
}
|
|
392
|
-
(0, node_opcua_assert_1.default)(innerClass);
|
|
393
|
-
(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;
|
|
394
357
|
}
|
|
395
358
|
else {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
359
|
+
innerClass = {
|
|
360
|
+
module: parentDef.interfaceName.module,
|
|
361
|
+
name: parentDef.interfaceName.name + "_" + name,
|
|
362
|
+
namespace: nodeId.namespace
|
|
363
|
+
};
|
|
364
|
+
childBase = childType;
|
|
365
|
+
childType = innerClass;
|
|
401
366
|
}
|
|
367
|
+
(0, node_opcua_assert_1.default)(innerClass);
|
|
368
|
+
(0, node_opcua_assert_1.default)(childBase);
|
|
402
369
|
}
|
|
403
370
|
else {
|
|
404
|
-
// the
|
|
405
|
-
//
|
|
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;
|
|
406
374
|
(0, node_opcua_assert_1.default)(!innerClass);
|
|
407
375
|
(0, node_opcua_assert_1.default)(!childBase);
|
|
408
376
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
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
|
|
430
412
|
};
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
const extra = yield extractVariableExtra(session, nodeId, cache, classMember);
|
|
434
|
-
classMember = Object.assign(Object.assign({}, classMember), extra);
|
|
435
|
-
}
|
|
436
|
-
return classMember;
|
|
437
|
-
});
|
|
413
|
+
}
|
|
414
|
+
return classMember;
|
|
438
415
|
}
|
|
439
416
|
exports.extractClassMemberDef = extractClassMemberDef;
|
|
440
|
-
function preDumpChildren(padding, classDef, f, cache) {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
}
|
|
458
|
-
});
|
|
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
|
+
}
|
|
459
434
|
}
|
|
460
435
|
const isPlaceHolder = (def) => {
|
|
461
436
|
const { modellingRule } = def;
|
|
@@ -606,7 +581,7 @@ function getBaseClassWithOmit(classDef) {
|
|
|
606
581
|
// console.log("conflictingMembers = ", conflictingMembers.map((a) => a.name).join(" "));
|
|
607
582
|
}
|
|
608
583
|
const chBase = calculateChevrons(classDef.baseClassDef, classDef);
|
|
609
|
-
let baseStuff = `${baseInterfaceName
|
|
584
|
+
let baseStuff = `${baseInterfaceName?.name}${chBase.chevronsUse}`;
|
|
610
585
|
if (conflictingMembers.length) {
|
|
611
586
|
baseStuff = `Omit<${baseStuff}, ${conflictingMembers.map((a) => `"${a.name}"`).join("|")}>`;
|
|
612
587
|
}
|
|
@@ -621,7 +596,7 @@ function getBaseClassWithOmit2(classMember) {
|
|
|
621
596
|
doDebug && console.log("conflictingMembers = ", conflictingMembers.map((a) => a.name).join(" "));
|
|
622
597
|
}
|
|
623
598
|
const childBase = classMember.childBase;
|
|
624
|
-
let baseStuff = `${childBase
|
|
599
|
+
let baseStuff = `${childBase?.name}${classMember.suffix3}`;
|
|
625
600
|
if (conflictingMembers.length) {
|
|
626
601
|
baseStuff = `Omit<${baseStuff}, ${conflictingMembers.map((a) => `"${a.name}"`).join("|")}>`;
|
|
627
602
|
}
|
|
@@ -631,128 +606,125 @@ function getBaseClassWithOmit2(classMember) {
|
|
|
631
606
|
* nodeId : a DataType, ReferenceType,AObjectType, VariableType node
|
|
632
607
|
*/
|
|
633
608
|
// eslint-disable-next-line max-statements
|
|
634
|
-
function _convertTypeToTypescript(session, nodeId, cache, f) {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
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
|
+
{
|
|
659
646
|
if (nodeClass === node_opcua_data_model_1.NodeClass.VariableType) {
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
// }
|
|
668
|
-
cache.ensureImported(baseInterfaceName);
|
|
669
|
-
cache.ensureImported(Object.assign(Object.assign({}, baseInterfaceName), { name: baseInterfaceName.name + `${baseExtension}` }));
|
|
670
|
-
const ch = calculateChevrons(classDef);
|
|
671
|
-
{
|
|
672
|
-
if (nodeClass === node_opcua_data_model_1.NodeClass.VariableType) {
|
|
673
|
-
if (classDef.dataTypeImport) {
|
|
674
|
-
if (doDebug) {
|
|
675
|
-
console.log(chalk_1.default.red(" ----------------> ", classDef.browseName));
|
|
676
|
-
classDef.dataTypeImport.forEach((a) => {
|
|
677
|
-
console.log(chalk_1.default.red(" ------------------------> ", a.module, a.name, a.namespace));
|
|
678
|
-
});
|
|
679
|
-
}
|
|
680
|
-
classDef.dataTypeImport.forEach(cache.ensureImported.bind(cache));
|
|
681
|
-
}
|
|
682
|
-
cache.referenceBasicType("DataType");
|
|
683
|
-
const chevrons = calculateChevrons(classDef);
|
|
684
|
-
const chevronsBase = calculateChevrons(classDef.baseClassDef, classDef);
|
|
685
|
-
// Shall we cache.ensureImported({ ...baseInterfaceName!, module: dataTypeName, name: dataTypeName });
|
|
686
|
-
const classBaseName = `${interfaceName.name}${baseExtension}${chevrons.chevronsDef}`;
|
|
687
|
-
if (countExposedChildren(members) === 0 && (baseInterfaceName === null || baseInterfaceName === void 0 ? void 0 : baseInterfaceName.name) !== "UAVariableT") {
|
|
688
|
-
//
|
|
689
|
-
const baseName = `${baseInterfaceName === null || baseInterfaceName === void 0 ? void 0 : baseInterfaceName.name}${baseExtension}${chevronsBase.chevronsExtend}`;
|
|
690
|
-
f.write(`export type ${classBaseName} = ${baseName};`);
|
|
691
|
-
}
|
|
692
|
-
else {
|
|
693
|
-
if ((baseInterfaceName === null || baseInterfaceName === void 0 ? void 0 : baseInterfaceName.name) === "UAVariableT") {
|
|
694
|
-
f.write(`export interface ${classBaseName} {`);
|
|
695
|
-
}
|
|
696
|
-
else {
|
|
697
|
-
const baseName = `${baseInterfaceName === null || baseInterfaceName === void 0 ? void 0 : baseInterfaceName.name}${baseExtension}${chevronsBase.chevronsExtend}`;
|
|
698
|
-
f.write(`export interface ${classBaseName} extends ${baseName} {`);
|
|
699
|
-
}
|
|
700
|
-
yield dumpChildren(" ", members, f, cache);
|
|
701
|
-
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
|
+
});
|
|
702
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};`);
|
|
703
666
|
}
|
|
704
667
|
else {
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
const baseName = `${baseInterfaceName === null || baseInterfaceName === void 0 ? void 0 : baseInterfaceName.name}${baseExtension}`;
|
|
708
|
-
f.write(`export type ${classBaseName} = ${baseName};`);
|
|
668
|
+
if (baseInterfaceName?.name === "UAVariableT") {
|
|
669
|
+
f.write(`export interface ${classBaseName} {`);
|
|
709
670
|
}
|
|
710
671
|
else {
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
}
|
|
714
|
-
else {
|
|
715
|
-
const baseName = `${baseInterfaceName === null || baseInterfaceName === void 0 ? void 0 : baseInterfaceName.name}${baseExtension}`;
|
|
716
|
-
f.write(`export interface ${classBaseName} extends ${baseName} {`);
|
|
717
|
-
}
|
|
718
|
-
yield dumpChildren(" ", members, f, cache);
|
|
719
|
-
f.write(`}`);
|
|
672
|
+
const baseName = `${baseInterfaceName?.name}${baseExtension}${chevronsBase.chevronsExtend}`;
|
|
673
|
+
f.write(`export interface ${classBaseName} extends ${baseName} {`);
|
|
720
674
|
}
|
|
675
|
+
await dumpChildren(" ", members, f, cache);
|
|
676
|
+
f.write(`}`);
|
|
721
677
|
}
|
|
722
678
|
}
|
|
723
|
-
const baseStuff = getBaseClassWithOmit(classDef);
|
|
724
|
-
if (nodeClass === node_opcua_data_model_1.NodeClass.VariableType) {
|
|
725
|
-
cache.referenceBasicType("DataType");
|
|
726
|
-
// if dataType is a extension object we can simpligy by forcing DT
|
|
727
|
-
const className = `${interfaceName.name}${ch.chevronsDef}`;
|
|
728
|
-
const c = isUnspecifiedDataType(dataType) ? `<T, DT${mB}>` : `<T${mC}>`;
|
|
729
|
-
const classBaseName = `${interfaceName.name}${baseExtension}${c}`;
|
|
730
|
-
f.write(`export interface ${className} extends ${baseStuff}, ${classBaseName} {`);
|
|
731
|
-
}
|
|
732
679
|
else {
|
|
733
|
-
const className = `${interfaceName.name}`;
|
|
734
680
|
const classBaseName = `${interfaceName.name}${baseExtension}`;
|
|
735
|
-
|
|
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
|
+
}
|
|
736
696
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
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 };
|
|
740
714
|
}
|
|
741
715
|
exports._convertTypeToTypescript = _convertTypeToTypescript;
|
|
742
|
-
function convertTypeToTypescript(session, nodeId, options, cache, f) {
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
return { type, content: f.toString(), folder, module, filename, dependencies };
|
|
755
|
-
});
|
|
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 };
|
|
756
728
|
}
|
|
757
729
|
exports.convertTypeToTypescript = convertTypeToTypescript;
|
|
758
730
|
//# sourceMappingURL=convert_to_typescript.js.map
|