node-opcua-convert-nodeset-to-javascript 2.183.1 → 2.184.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_dataType.d.ts +1 -0
- package/dist/_dataType.d.ts.map +1 -0
- package/dist/_dataType.js +36 -39
- package/dist/_dataType.js.map +1 -1
- package/dist/convert_namespace_to_typescript.d.ts +1 -0
- package/dist/convert_namespace_to_typescript.d.ts.map +1 -0
- package/dist/convert_namespace_to_typescript.js +72 -67
- package/dist/convert_namespace_to_typescript.js.map +1 -1
- package/dist/convert_to_typescript.d.ts +1 -0
- package/dist/convert_to_typescript.d.ts.map +1 -0
- package/dist/convert_to_typescript.js +124 -138
- package/dist/convert_to_typescript.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -19
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +2 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +31 -35
- package/dist/main.js.map +1 -1
- package/dist/options.d.ts +1 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +1 -2
- package/dist/package_root.d.ts +1 -0
- package/dist/package_root.d.ts.map +1 -0
- package/dist/package_root.js +4 -10
- package/dist/package_root.js.map +1 -1
- package/dist/private/cache.d.ts +1 -0
- package/dist/private/cache.d.ts.map +1 -0
- package/dist/private/cache.js +35 -48
- package/dist/private/cache.js.map +1 -1
- package/dist/private/fs_retry.d.ts +1 -0
- package/dist/private/fs_retry.d.ts.map +1 -0
- package/dist/private/fs_retry.js +4 -11
- package/dist/private/fs_retry.js.map +1 -1
- package/dist/private/get_corresponding_data_type.d.ts +1 -0
- package/dist/private/get_corresponding_data_type.d.ts.map +1 -0
- package/dist/private/get_corresponding_data_type.js +38 -42
- package/dist/private/get_corresponding_data_type.js.map +1 -1
- package/dist/private/to_filename.d.ts +1 -0
- package/dist/private/to_filename.d.ts.map +1 -0
- package/dist/private/to_filename.js +3 -6
- package/dist/private/to_filename.js.map +1 -1
- package/dist/private/utils.d.ts +1 -0
- package/dist/private/utils.d.ts.map +1 -0
- package/dist/private/utils.js +69 -90
- package/dist/private/utils.js.map +1 -1
- package/dist/private-stuff.d.ts +1 -0
- package/dist/private-stuff.d.ts.map +1 -0
- package/dist/private-stuff.js +4 -20
- package/dist/private-stuff.js.map +1 -1
- package/dist/remove_unused.d.ts +1 -0
- package/dist/remove_unused.d.ts.map +1 -0
- package/dist/remove_unused.js +22 -28
- package/dist/remove_unused.js.map +1 -1
- package/dist/update_parent_tsconfig.d.ts +1 -0
- package/dist/update_parent_tsconfig.d.ts.map +1 -0
- package/dist/update_parent_tsconfig.js +10 -16
- package/dist/update_parent_tsconfig.js.map +1 -1
- package/dist/utils2.d.ts +1 -0
- package/dist/utils2.d.ts.map +1 -0
- package/dist/utils2.js +10 -22
- package/dist/utils2.js.map +1 -1
- package/dist/walk_through.d.ts +1 -0
- package/dist/walk_through.d.ts.map +1 -0
- package/dist/walk_through.js +19 -26
- package/dist/walk_through.js.map +1 -1
- package/package.json +19 -19
- package/source/convert_namespace_to_typescript.ts +15 -2
- package/source/main.ts +1 -0
- package/source/package_root.ts +1 -1
|
@@ -1,32 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const node_opcua_assert_1 = __importDefault(require("node-opcua-assert"));
|
|
17
|
-
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
18
|
-
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
19
|
-
const node_opcua_types_1 = require("node-opcua-types");
|
|
20
|
-
const node_opcua_utils_1 = require("node-opcua-utils");
|
|
21
|
-
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
22
|
-
const _dataType_js_1 = require("./_dataType.js");
|
|
23
|
-
const cache_js_1 = require("./private/cache.js");
|
|
24
|
-
const get_corresponding_data_type_js_1 = require("./private/get_corresponding_data_type.js");
|
|
25
|
-
const to_filename_js_1 = require("./private/to_filename.js");
|
|
26
|
-
const utils_js_1 = require("./private/utils.js");
|
|
27
|
-
const utils2_js_1 = require("./utils2.js");
|
|
28
|
-
const warningLog = (0, node_opcua_debug_1.make_warningLog)("typescript");
|
|
29
|
-
const debugLog = (0, node_opcua_debug_1.make_debugLog)("typescript");
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import assert from "node-opcua-assert";
|
|
3
|
+
import { NodeClass } from "node-opcua-data-model";
|
|
4
|
+
import { make_debugLog, make_warningLog } from "node-opcua-debug";
|
|
5
|
+
import { StructureDefinition } from "node-opcua-types";
|
|
6
|
+
import { LineFile } from "node-opcua-utils";
|
|
7
|
+
import { DataType } from "node-opcua-variant";
|
|
8
|
+
import { _exportDataTypeToTypescript } from "./_dataType.js";
|
|
9
|
+
import { constructCache, makeTypeNameNew } from "./private/cache.js";
|
|
10
|
+
import { getCorrespondingJavascriptType2 } from "./private/get_corresponding_data_type.js";
|
|
11
|
+
import { toFilename } from "./private/to_filename.js";
|
|
12
|
+
import { extractBasicDataType, getBrowseName, getChildrenOrFolderElements, getDataTypeNodeId, getDefinition, getDescription, getIsAbstract, getModellingRule, getNodeClass, getSubtypeNodeIdIfAny, getTypeDefOrBaseType, getValueRank } from "./private/utils.js";
|
|
13
|
+
import { f1, f2, quotifyIfNecessary, toComment, toJavascritPropertyName } from "./utils2.js";
|
|
14
|
+
const warningLog = make_warningLog("typescript");
|
|
15
|
+
const debugLog = make_debugLog("typescript");
|
|
30
16
|
const doDebug = false;
|
|
31
17
|
const baseExtension = "_Base";
|
|
32
18
|
const m0 = !doDebug ? "" : `/* 0 */`;
|
|
@@ -45,12 +31,12 @@ const mC = !doDebug ? "" : `/* c */`;
|
|
|
45
31
|
const mD = !doDebug ? "" : `/* d */`;
|
|
46
32
|
const mE = !doDebug ? "" : `/* e */`;
|
|
47
33
|
const mF = !doDebug ? "" : `/* f */`;
|
|
48
|
-
async function convertDataTypeToTypescript(session, dataTypeId) {
|
|
49
|
-
const definition = await
|
|
50
|
-
const browseName = await
|
|
34
|
+
export async function convertDataTypeToTypescript(session, dataTypeId) {
|
|
35
|
+
const definition = await getDefinition(session, dataTypeId);
|
|
36
|
+
const browseName = await getBrowseName(session, dataTypeId);
|
|
51
37
|
const dataTypeTypescriptName = `UA${browseName.name?.toString()}`;
|
|
52
|
-
const f = new
|
|
53
|
-
if (definition && definition instanceof
|
|
38
|
+
const f = new LineFile();
|
|
39
|
+
if (definition && definition instanceof StructureDefinition) {
|
|
54
40
|
f.write(`interface ${dataTypeTypescriptName} {`);
|
|
55
41
|
for (const _field of definition.fields || []) {
|
|
56
42
|
/** */
|
|
@@ -58,14 +44,14 @@ async function convertDataTypeToTypescript(session, dataTypeId) {
|
|
|
58
44
|
f.write(`}`);
|
|
59
45
|
}
|
|
60
46
|
}
|
|
61
|
-
function makeTypeName2(nodeClass, browseName, suffix) {
|
|
62
|
-
(
|
|
63
|
-
if (nodeClass ===
|
|
47
|
+
export function makeTypeName2(nodeClass, browseName, suffix) {
|
|
48
|
+
assert(browseName);
|
|
49
|
+
if (nodeClass === NodeClass.Method) {
|
|
64
50
|
return { name: "UAMethod", namespace: 0, module: "UAMethod" };
|
|
65
51
|
}
|
|
66
|
-
return
|
|
52
|
+
return makeTypeNameNew(nodeClass, null, browseName, suffix);
|
|
67
53
|
}
|
|
68
|
-
async function extractClassDefinition(session, nodeId, cache) {
|
|
54
|
+
export async function extractClassDefinition(session, nodeId, cache) {
|
|
69
55
|
const extraImports = [];
|
|
70
56
|
const cacheWithClassDefCache = cache;
|
|
71
57
|
const _c = cacheWithClassDefCache.classDefCache || {};
|
|
@@ -74,29 +60,29 @@ async function extractClassDefinition(session, nodeId, cache) {
|
|
|
74
60
|
if (classDef) {
|
|
75
61
|
return classDef;
|
|
76
62
|
}
|
|
77
|
-
const nodeClass = await
|
|
78
|
-
if (nodeClass !==
|
|
79
|
-
throw new Error(`Invalid nodeClass ${
|
|
63
|
+
const nodeClass = await getNodeClass(session, nodeId);
|
|
64
|
+
if (nodeClass !== NodeClass.VariableType && nodeClass !== NodeClass.ObjectType) {
|
|
65
|
+
throw new Error(`Invalid nodeClass ${NodeClass[nodeClass]} nodeId ${nodeId.toString()}`);
|
|
80
66
|
}
|
|
81
|
-
const browseName = await
|
|
82
|
-
const isAbstract = await
|
|
83
|
-
const superType = (await
|
|
84
|
-
const dataTypeNodeId = await
|
|
67
|
+
const browseName = await getBrowseName(session, nodeId);
|
|
68
|
+
const isAbstract = await getIsAbstract(session, nodeId);
|
|
69
|
+
const superType = (await getSubtypeNodeIdIfAny(session, nodeId)) || undefined;
|
|
70
|
+
const dataTypeNodeId = await getDataTypeNodeId(session, nodeId);
|
|
85
71
|
let dataTypeName = "";
|
|
86
|
-
let dataType =
|
|
72
|
+
let dataType = DataType.Null;
|
|
87
73
|
let dataTypeImport;
|
|
88
74
|
let valueRank;
|
|
89
75
|
let dataTypeCombination;
|
|
90
|
-
if (nodeClass ===
|
|
76
|
+
if (nodeClass === NodeClass.VariableType) {
|
|
91
77
|
if (!dataTypeNodeId) {
|
|
92
78
|
throw new Error(`VariableType ${nodeId.toString()} is expected to have a DataType attribute`);
|
|
93
79
|
}
|
|
94
|
-
dataType = await
|
|
80
|
+
dataType = await extractBasicDataType(session, dataTypeNodeId);
|
|
95
81
|
const importCollector = (i) => {
|
|
96
82
|
extraImports.push(i);
|
|
97
83
|
cache.ensureImported(i);
|
|
98
84
|
};
|
|
99
|
-
const info = await
|
|
85
|
+
const info = await getCorrespondingJavascriptType2(session, nodeId, dataTypeNodeId, cache, importCollector);
|
|
100
86
|
const jtype = info.jtype;
|
|
101
87
|
dataTypeCombination = info.dataTypeCombination;
|
|
102
88
|
dataTypeName = jtype; // with decoration
|
|
@@ -105,15 +91,15 @@ async function extractClassDefinition(session, nodeId, cache) {
|
|
|
105
91
|
// const bn = await getBrowseName(session, dataTypeNodeId!);
|
|
106
92
|
dataTypeImport = extraImports; // makeTypeName2(NodeClass.DataType, bn);
|
|
107
93
|
}
|
|
108
|
-
valueRank = await
|
|
94
|
+
valueRank = await getValueRank(session, nodeId);
|
|
109
95
|
}
|
|
110
96
|
const baseClassDef = !superType ? null : await extractClassDefinition(session, superType.nodeId, cache);
|
|
111
|
-
const description = await
|
|
97
|
+
const description = await getDescription(session, nodeId);
|
|
112
98
|
// const definition = await getDefinition(session, nodeId);
|
|
113
99
|
const interfaceName = makeTypeName2(nodeClass, browseName);
|
|
114
100
|
const baseInterfaceName = !superType ? null : makeTypeName2(nodeClass, superType.browseName);
|
|
115
101
|
// extract member
|
|
116
|
-
const children = await
|
|
102
|
+
const children = await getChildrenOrFolderElements(session, nodeId);
|
|
117
103
|
const members = [];
|
|
118
104
|
classDef = {
|
|
119
105
|
nodeClass,
|
|
@@ -150,15 +136,15 @@ async function classify(session, refs, classDef) {
|
|
|
150
136
|
ExposesItsArray: []
|
|
151
137
|
};
|
|
152
138
|
for (const mm of refs) {
|
|
153
|
-
let modellingRule = await
|
|
139
|
+
let modellingRule = await getModellingRule(session, mm.nodeId);
|
|
154
140
|
if (modellingRule) {
|
|
155
141
|
// if Optional, check that base class member is also Optional or force to Mandatory
|
|
156
142
|
if (modellingRule === "Optional" && classDef.baseClassDef) {
|
|
157
143
|
const sameMember = classDef.baseClassDef.members.find((m) => m.browseName.name === mm.browseName.name);
|
|
158
144
|
if (sameMember) {
|
|
159
145
|
if (!sameMember.isOptional) {
|
|
160
|
-
console.log(
|
|
161
|
-
|
|
146
|
+
console.log(chalk.cyan("Warning: ") +
|
|
147
|
+
chalk.yellow(classDef.browseName.toString()) +
|
|
162
148
|
" ModellingRule is Optional but base class member is Mandatory");
|
|
163
149
|
modellingRule = "Mandatory";
|
|
164
150
|
}
|
|
@@ -188,7 +174,7 @@ async function extractAllMembers(session, classDef, _cache) {
|
|
|
188
174
|
const members = await classify(session, m, classDef);
|
|
189
175
|
return members;
|
|
190
176
|
}
|
|
191
|
-
async function findClassMember(session, browseName, baseParentDef, cache) {
|
|
177
|
+
export async function findClassMember(session, browseName, baseParentDef, cache) {
|
|
192
178
|
const childBrowseName = browseName.toString();
|
|
193
179
|
const r = baseParentDef.children.find((a) => a.browseName.toString() === childBrowseName);
|
|
194
180
|
if (r) {
|
|
@@ -214,7 +200,7 @@ function hasNewMaterial(referenceMembers, instanceMembers) {
|
|
|
214
200
|
// we should expose an inner definition if
|
|
215
201
|
// - at least one mandatory in instnace doesn't exist in main.Mandatory
|
|
216
202
|
// - at least one optional in instnace doesn't exist in main.Mandatory
|
|
217
|
-
function checkIfShouldExposeInnerDefinition(main, instance) {
|
|
203
|
+
export function checkIfShouldExposeInnerDefinition(main, instance) {
|
|
218
204
|
const hasNewStuff = hasNewMaterial(main.Mandatory, instance.Mandatory) || hasNewMaterial(main.Optional, instance.Optional);
|
|
219
205
|
return hasNewStuff;
|
|
220
206
|
}
|
|
@@ -243,18 +229,18 @@ async function _extractLocalMembers(session, parent, classMember, cache) {
|
|
|
243
229
|
const children2 = [];
|
|
244
230
|
for (const child of classMember.children) {
|
|
245
231
|
const nodeId = child.nodeId;
|
|
246
|
-
const browseName = await
|
|
232
|
+
const browseName = await getBrowseName(session, nodeId);
|
|
247
233
|
if (!browseName.name) {
|
|
248
234
|
throw new Error(`Expecting a browseName.name for node ${nodeId.toString()}`);
|
|
249
235
|
}
|
|
250
|
-
const name =
|
|
236
|
+
const name = toJavascritPropertyName(browseName.name, {
|
|
251
237
|
ignoreConflictingName: true,
|
|
252
238
|
parentNodeClass: classMember.nodeClass
|
|
253
239
|
});
|
|
254
|
-
const description = await
|
|
255
|
-
const modellingRule = await
|
|
240
|
+
const description = await getDescription(session, nodeId);
|
|
241
|
+
const modellingRule = await getModellingRule(session, nodeId);
|
|
256
242
|
const isOptional = sameInBaseClassIsMandatory(parent, browseName) ? false : modellingRule === "Optional";
|
|
257
|
-
const typeDefinition = await
|
|
243
|
+
const typeDefinition = await getTypeDefOrBaseType(session, nodeId);
|
|
258
244
|
const childInBase = classMember.classDef?.members.find((a) => a.browseName.toString() === browseName.toString());
|
|
259
245
|
let childType;
|
|
260
246
|
if (childInBase) {
|
|
@@ -282,7 +268,7 @@ async function _extractLocalMembers(session, parent, classMember, cache) {
|
|
|
282
268
|
return children2;
|
|
283
269
|
}
|
|
284
270
|
function isUnspecifiedDataType(dataType) {
|
|
285
|
-
return dataType ===
|
|
271
|
+
return dataType === DataType.Null || dataType === DataType.Variant;
|
|
286
272
|
}
|
|
287
273
|
async function extractVariableExtra(session, nodeId, cache, classMember) {
|
|
288
274
|
const typeToReference = [];
|
|
@@ -290,24 +276,24 @@ async function extractVariableExtra(session, nodeId, cache, classMember) {
|
|
|
290
276
|
typeToReference.push(i);
|
|
291
277
|
cache.ensureImported(i);
|
|
292
278
|
};
|
|
293
|
-
const nodeClass = await
|
|
294
|
-
if (nodeClass ===
|
|
295
|
-
const dataTypeNodeId = await
|
|
279
|
+
const nodeClass = await getNodeClass(session, nodeId);
|
|
280
|
+
if (nodeClass === NodeClass.Variable) {
|
|
281
|
+
const dataTypeNodeId = await getDataTypeNodeId(session, nodeId);
|
|
296
282
|
if (!dataTypeNodeId) {
|
|
297
283
|
throw new Error(`Variable ${nodeId.toString()} is expected to have a DataType attribute`);
|
|
298
284
|
}
|
|
299
|
-
const _valueRank = await
|
|
285
|
+
const _valueRank = await getValueRank(session, nodeId);
|
|
300
286
|
_valueRank;
|
|
301
|
-
const { dataType, jtype, dataTypeCombination } = await
|
|
287
|
+
const { dataType, jtype, dataTypeCombination } = await getCorrespondingJavascriptType2(session, nodeId, dataTypeNodeId, cache, importCollector);
|
|
302
288
|
cache?.referenceBasicType("DataType");
|
|
303
289
|
importCollector({ name: "DataType", namespace: -1, module: "BasicType" });
|
|
304
290
|
const t = isUnspecifiedDataType(classMember.classDef?.dataType);
|
|
305
291
|
const suffix = jtype === "undefined" || isUnspecifiedDataType(dataType)
|
|
306
292
|
? `<any, any>`
|
|
307
|
-
: `<${jtype}${t ? `, ${m0}DataType.${
|
|
293
|
+
: `<${jtype}${t ? `, ${m0}DataType.${DataType[dataType]}` : ""}>`;
|
|
308
294
|
// const suffix2 = `<T${t ? `, /DT extends DataType` : ""}>`;
|
|
309
295
|
const suffix3 = `<T${t ? `, ${m1}DT` : ""}>`;
|
|
310
|
-
const typeDef = await
|
|
296
|
+
const typeDef = await getTypeDefOrBaseType(session, nodeId);
|
|
311
297
|
const typeDefCD = await extractClassDefinition(session, typeDef.nodeId, cache);
|
|
312
298
|
const chevrons = calculateChevrons(typeDefCD, { dataType });
|
|
313
299
|
const suffix2 = chevrons.chevronsDef;
|
|
@@ -336,7 +322,7 @@ async function extractVariableExtra(session, nodeId, cache, classMember) {
|
|
|
336
322
|
}
|
|
337
323
|
}
|
|
338
324
|
else {
|
|
339
|
-
suffixInstantiate = `<${jtype}, DataType.${
|
|
325
|
+
suffixInstantiate = `<${jtype}, DataType.${DataType[dataType]}${mF}>`;
|
|
340
326
|
}
|
|
341
327
|
}
|
|
342
328
|
return {
|
|
@@ -357,33 +343,33 @@ async function extractVariableExtra(session, nodeId, cache, classMember) {
|
|
|
357
343
|
/** the class of the instances of a type: what a generated interface describes */
|
|
358
344
|
function instanceNodeClass(typeNodeClass) {
|
|
359
345
|
switch (typeNodeClass) {
|
|
360
|
-
case
|
|
361
|
-
return
|
|
362
|
-
case
|
|
363
|
-
return
|
|
346
|
+
case NodeClass.ObjectType:
|
|
347
|
+
return NodeClass.Object;
|
|
348
|
+
case NodeClass.VariableType:
|
|
349
|
+
return NodeClass.Variable;
|
|
364
350
|
default:
|
|
365
351
|
return typeNodeClass;
|
|
366
352
|
}
|
|
367
353
|
}
|
|
368
|
-
async function extractClassMemberDef(session, nodeId, parentDef, cache) {
|
|
369
|
-
const nodeClass = await
|
|
370
|
-
const browseName = await
|
|
354
|
+
export async function extractClassMemberDef(session, nodeId, parentDef, cache) {
|
|
355
|
+
const nodeClass = await getNodeClass(session, nodeId);
|
|
356
|
+
const browseName = await getBrowseName(session, nodeId);
|
|
371
357
|
if (!browseName.name) {
|
|
372
358
|
throw new Error(`Expecting a browseName.name for node ${nodeId.toString()}`);
|
|
373
359
|
}
|
|
374
|
-
const name =
|
|
360
|
+
const name = toJavascritPropertyName(browseName.name, {
|
|
375
361
|
ignoreConflictingName: true,
|
|
376
362
|
parentNodeClass: instanceNodeClass(parentDef.nodeClass)
|
|
377
363
|
});
|
|
378
|
-
if (nodeClass !==
|
|
379
|
-
throw new Error(`Invalid property ${
|
|
364
|
+
if (nodeClass !== NodeClass.Method && nodeClass !== NodeClass.Object && nodeClass !== NodeClass.Variable) {
|
|
365
|
+
throw new Error(`Invalid property ${NodeClass[nodeClass]} ${browseName?.toString()} ${nodeId.toString()}`);
|
|
380
366
|
}
|
|
381
|
-
const description = await
|
|
382
|
-
const children = await
|
|
383
|
-
const modellingRule = await
|
|
367
|
+
const description = await getDescription(session, nodeId);
|
|
368
|
+
const children = await getChildrenOrFolderElements(session, nodeId);
|
|
369
|
+
const modellingRule = await getModellingRule(session, nodeId);
|
|
384
370
|
const isOptional = sameInBaseClassIsMandatory(parentDef, browseName) ? false : modellingRule === "Optional";
|
|
385
|
-
const typeDefinition = await
|
|
386
|
-
if (nodeClass !==
|
|
371
|
+
const typeDefinition = await getTypeDefOrBaseType(session, nodeId);
|
|
372
|
+
if (nodeClass !== NodeClass.Method && !typeDefinition.browseName?.name) {
|
|
387
373
|
warningLog(typeDefinition.toString());
|
|
388
374
|
warningLog("cannot find typeDefinition for ", browseName.toString(), "( is the namespace loaded ?)");
|
|
389
375
|
}
|
|
@@ -396,7 +382,7 @@ async function extractClassMemberDef(session, nodeId, parentDef, cache) {
|
|
|
396
382
|
const baseParentDef = parentDef.superType && (await extractClassDefinition(session, parentDef.superType?.nodeId, cache));
|
|
397
383
|
if (classDef && baseParentDef) {
|
|
398
384
|
const _chevrons1 = calculateChevrons(classDef, baseParentDef);
|
|
399
|
-
(
|
|
385
|
+
assert(!innerClass);
|
|
400
386
|
// let's extract the member that are theorically defined in the member
|
|
401
387
|
const membersReference = await extractAllMembers(session, classDef, cache);
|
|
402
388
|
// find member exposed by this member
|
|
@@ -427,22 +413,22 @@ async function extractClassMemberDef(session, nodeId, parentDef, cache) {
|
|
|
427
413
|
childBase = childType;
|
|
428
414
|
childType = innerClass;
|
|
429
415
|
}
|
|
430
|
-
(
|
|
431
|
-
(
|
|
416
|
+
assert(innerClass);
|
|
417
|
+
assert(childBase);
|
|
432
418
|
}
|
|
433
419
|
else {
|
|
434
420
|
if (sameMemberInBaseClass && sameMemberInBaseClass.childType.name !== childType.name) {
|
|
435
421
|
childType = sameMemberInBaseClass.childType;
|
|
436
422
|
}
|
|
437
|
-
(
|
|
438
|
-
(
|
|
423
|
+
assert(!innerClass);
|
|
424
|
+
assert(!childBase);
|
|
439
425
|
}
|
|
440
426
|
}
|
|
441
427
|
else {
|
|
442
428
|
// the lass member has no HasTypeDefinition reference
|
|
443
429
|
// may be is a method
|
|
444
|
-
(
|
|
445
|
-
(
|
|
430
|
+
assert(!innerClass);
|
|
431
|
+
assert(!childBase);
|
|
446
432
|
}
|
|
447
433
|
let classMember = {
|
|
448
434
|
name,
|
|
@@ -467,7 +453,7 @@ async function extractClassMemberDef(session, nodeId, parentDef, cache) {
|
|
|
467
453
|
chevrons: null
|
|
468
454
|
};
|
|
469
455
|
classMember.children2 = await _extractLocalMembers(session, classDef, classMember, cache);
|
|
470
|
-
if (nodeClass ===
|
|
456
|
+
if (nodeClass === NodeClass.Variable) {
|
|
471
457
|
const extra = await extractVariableExtra(session, nodeId, cache, classMember);
|
|
472
458
|
classMember = {
|
|
473
459
|
...classMember,
|
|
@@ -482,14 +468,14 @@ async function extractClassMemberDef(session, nodeId, parentDef, cache) {
|
|
|
482
468
|
// childType was inherited from base (e.g., UADiscreteItem instead of UATwoStateDiscrete)
|
|
483
469
|
// Recalculate suffix based on base class's classDef
|
|
484
470
|
if (sameMemberInBase.classDef && classMember.dataType !== undefined) {
|
|
485
|
-
const baseTypeHasUnspecifiedDataType = sameMemberInBase.classDef.dataType ===
|
|
486
|
-
sameMemberInBase.classDef.dataType ===
|
|
471
|
+
const baseTypeHasUnspecifiedDataType = sameMemberInBase.classDef.dataType === DataType.Null ||
|
|
472
|
+
sameMemberInBase.classDef.dataType === DataType.Variant;
|
|
487
473
|
if (baseTypeHasUnspecifiedDataType &&
|
|
488
|
-
classMember.dataType !==
|
|
489
|
-
classMember.dataType !==
|
|
474
|
+
classMember.dataType !== DataType.Null &&
|
|
475
|
+
classMember.dataType !== DataType.Variant) {
|
|
490
476
|
// Base type is generic (2 params), current has specific dataType
|
|
491
477
|
// Generate: <specificType, DataType.SpecificType>
|
|
492
|
-
classMember.suffixInstantiate = `<${classMember.jtype}, DataType.${
|
|
478
|
+
classMember.suffixInstantiate = `<${classMember.jtype}, DataType.${DataType[classMember.dataType]}>`;
|
|
493
479
|
}
|
|
494
480
|
}
|
|
495
481
|
}
|
|
@@ -498,7 +484,7 @@ async function extractClassMemberDef(session, nodeId, parentDef, cache) {
|
|
|
498
484
|
return classMember;
|
|
499
485
|
}
|
|
500
486
|
async function preDumpChildren(padding, classDef, f, cache) {
|
|
501
|
-
f = f || new
|
|
487
|
+
f = f || new LineFile();
|
|
502
488
|
for (const memberDef of classDef.members) {
|
|
503
489
|
const { innerClass, suffix2, nodeClass, childBase } = memberDef;
|
|
504
490
|
if (!innerClass || !childBase) {
|
|
@@ -510,7 +496,7 @@ async function preDumpChildren(padding, classDef, f, cache) {
|
|
|
510
496
|
}
|
|
511
497
|
const baseStuff = getBaseClassWithOmit2(memberDef);
|
|
512
498
|
//f.write(`export interface ${innerClass.name}${suffix2} extends ${childBase.name}${suffix3} { // ${NodeClass[nodeClass]}`);
|
|
513
|
-
f.write(`export interface ${innerClass.name}${suffix2} extends ${baseStuff} { // ${
|
|
499
|
+
f.write(`export interface ${innerClass.name}${suffix2} extends ${baseStuff} { // ${NodeClass[nodeClass]}`);
|
|
514
500
|
await dumpChildren(`${padding} `, memberDef.children2, f, cache);
|
|
515
501
|
f.write("}");
|
|
516
502
|
}
|
|
@@ -523,7 +509,7 @@ function countExposedChildren(children) {
|
|
|
523
509
|
return children.reduce((p, def) => p + (isPlaceHolder(def) ? 0 : 1), 0);
|
|
524
510
|
}
|
|
525
511
|
function dumpChildren(padding, children, f, cache) {
|
|
526
|
-
f = f || new
|
|
512
|
+
f = f || new LineFile();
|
|
527
513
|
for (const def of children) {
|
|
528
514
|
const { suffixInstantiate, name, childType, isOptional, description } = def;
|
|
529
515
|
def.typeToReference.forEach((t) => {
|
|
@@ -536,14 +522,14 @@ function dumpChildren(padding, children, f, cache) {
|
|
|
536
522
|
cache.ensureImported(childType);
|
|
537
523
|
// name went through the rule already, with its parent class known; this is the same
|
|
538
524
|
// transformation applied to an already adjusted name, hence no parent class here
|
|
539
|
-
const adjustedName =
|
|
525
|
+
const adjustedName = toJavascritPropertyName(name, { ignoreConflictingName: true });
|
|
540
526
|
if (description.text) {
|
|
541
527
|
f.write(`${padding}/**`);
|
|
542
528
|
f.write(`${padding} * ${name || ""}`);
|
|
543
|
-
f.write(
|
|
529
|
+
f.write(toComment(`${padding} * `, description.text || ""));
|
|
544
530
|
f.write(`${padding} */`);
|
|
545
531
|
}
|
|
546
|
-
f.write(`${padding}${
|
|
532
|
+
f.write(`${padding}${quotifyIfNecessary(adjustedName)}${isOptional ? "?" : ""}: ${childType.name}${suffixInstantiate || ""};`);
|
|
547
533
|
}
|
|
548
534
|
}
|
|
549
535
|
// now from other namespace
|
|
@@ -554,7 +540,7 @@ const getSubSymbolList = (s) => {
|
|
|
554
540
|
}
|
|
555
541
|
return subSymbolList;
|
|
556
542
|
};
|
|
557
|
-
function findUsedImport(namespaceIndex, cache) {
|
|
543
|
+
export function findUsedImport(namespaceIndex, cache) {
|
|
558
544
|
const usedImport = [];
|
|
559
545
|
// from standard types
|
|
560
546
|
for (const imp of Object.keys(cache.imports)) {
|
|
@@ -577,7 +563,7 @@ function findUsedImport(namespaceIndex, cache) {
|
|
|
577
563
|
return usedImport;
|
|
578
564
|
}
|
|
579
565
|
function dumpUsedExport(currentType, namespaceIndex, cache, f) {
|
|
580
|
-
f = f || new
|
|
566
|
+
f = f || new LineFile();
|
|
581
567
|
for (const imp of Object.keys(cache.imports)) {
|
|
582
568
|
const symbolToImport = Object.keys(cache.imports[imp]).filter((f) => f !== currentType && Object.hasOwn(cache.requestedBasicTypes, f));
|
|
583
569
|
if (symbolToImport.length === 0) {
|
|
@@ -591,7 +577,7 @@ function dumpUsedExport(currentType, namespaceIndex, cache, f) {
|
|
|
591
577
|
if (ns === namespaceIndex) {
|
|
592
578
|
// include individuals stuff
|
|
593
579
|
for (const [symbol, s] of Object.entries(cache.requestedSymbols.namespace[ns].symbols).filter((a) => a[0] !== currentType)) {
|
|
594
|
-
const filename =
|
|
580
|
+
const filename = toFilename(symbol);
|
|
595
581
|
const subSymbolList = getSubSymbolList(s);
|
|
596
582
|
// ".js": ESM has no extension search, and the generated files are shipped
|
|
597
583
|
// source. Without it every regeneration would undo the extensions across
|
|
@@ -603,7 +589,7 @@ function dumpUsedExport(currentType, namespaceIndex, cache, f) {
|
|
|
603
589
|
if (cache.requestedSymbols.namespace[ns]) {
|
|
604
590
|
for (const [symbol, s] of Object.entries(cache.requestedSymbols.namespace[ns].symbols)) {
|
|
605
591
|
const subSymbolList = getSubSymbolList(s);
|
|
606
|
-
const filename =
|
|
592
|
+
const filename = toFilename(symbol);
|
|
607
593
|
f.write(`import { ${subSymbolList.join(", ")} } from "${module}/dist/${filename}.js"`);
|
|
608
594
|
}
|
|
609
595
|
}
|
|
@@ -616,7 +602,7 @@ function calculateChevrons(classDef, classDefDerived) {
|
|
|
616
602
|
let chevronsDef = "";
|
|
617
603
|
let chevronsUse = "";
|
|
618
604
|
let chevronsExtend = "";
|
|
619
|
-
if (nodeClass !==
|
|
605
|
+
if (nodeClass !== NodeClass.VariableType) {
|
|
620
606
|
return { chevronsDef, chevronsUse, chevronsExtend };
|
|
621
607
|
}
|
|
622
608
|
if (!isUnspecifiedDataType(dataType)) {
|
|
@@ -624,7 +610,7 @@ function calculateChevrons(classDef, classDefDerived) {
|
|
|
624
610
|
chevronsUse = `<T${m4}>`;
|
|
625
611
|
if (classDefDerived) {
|
|
626
612
|
if (isUnspecifiedDataType(classDefDerived.dataType)) {
|
|
627
|
-
chevronsExtend = `<T, ${m5}DataType.${
|
|
613
|
+
chevronsExtend = `<T, ${m5}DataType.${DataType[dataType]}>`;
|
|
628
614
|
}
|
|
629
615
|
else {
|
|
630
616
|
chevronsExtend = `<T${m6}>`;
|
|
@@ -640,8 +626,8 @@ function calculateChevrons(classDef, classDefDerived) {
|
|
|
640
626
|
chevronsExtend = `<T${m8}, DT>`;
|
|
641
627
|
}
|
|
642
628
|
else {
|
|
643
|
-
chevronsUse = `<T, ${m9}DataType.${
|
|
644
|
-
chevronsExtend = `<T, ${mA}DataType.${
|
|
629
|
+
chevronsUse = `<T, ${m9}DataType.${DataType[classDefDerived.dataType]}>`;
|
|
630
|
+
chevronsExtend = `<T, ${mA}DataType.${DataType[classDefDerived.dataType]}>`;
|
|
645
631
|
}
|
|
646
632
|
}
|
|
647
633
|
}
|
|
@@ -696,11 +682,11 @@ function getBaseClassWithOmit2(classMember) {
|
|
|
696
682
|
/**
|
|
697
683
|
* nodeId : a DataType, ReferenceType,AObjectType, VariableType node
|
|
698
684
|
*/
|
|
699
|
-
async function _convertTypeToTypescript(session, nodeId, cache, f) {
|
|
700
|
-
f = f || new
|
|
701
|
-
const nodeClass = await
|
|
702
|
-
if (nodeClass ===
|
|
703
|
-
return await
|
|
685
|
+
export async function _convertTypeToTypescript(session, nodeId, cache, f) {
|
|
686
|
+
f = f || new LineFile();
|
|
687
|
+
const nodeClass = await getNodeClass(session, nodeId);
|
|
688
|
+
if (nodeClass === NodeClass.DataType) {
|
|
689
|
+
return await _exportDataTypeToTypescript(session, nodeId, cache, f);
|
|
704
690
|
}
|
|
705
691
|
const classDef = await extractClassDefinition(session, nodeId, cache);
|
|
706
692
|
// if (classDef.browseName.toString().match(/PubSubDiagnosticsWriterGroupType/)) {
|
|
@@ -712,21 +698,21 @@ async function _convertTypeToTypescript(session, nodeId, cache, f) {
|
|
|
712
698
|
// f.write(superType.toString());
|
|
713
699
|
f.write(`/**`);
|
|
714
700
|
if (description.text) {
|
|
715
|
-
f.write(
|
|
701
|
+
f.write(toComment(" * ", description.text || ""));
|
|
716
702
|
f.write(` *`);
|
|
717
703
|
}
|
|
718
|
-
f.write(` * | |${
|
|
719
|
-
f.write(` * |----------------|${
|
|
720
|
-
f.write(` * |namespace |${
|
|
721
|
-
f.write(` * |nodeClass |${
|
|
722
|
-
f.write(` * |typedDefinition |${
|
|
723
|
-
if (nodeClass ===
|
|
704
|
+
f.write(` * | |${f1(" ")}|`);
|
|
705
|
+
f.write(` * |----------------|${f2("-")}|`);
|
|
706
|
+
f.write(` * |namespace |${f1(cache.namespace[nodeId.namespace].namespaceUri)}|`);
|
|
707
|
+
f.write(` * |nodeClass |${f1(NodeClass[nodeClass])}|`);
|
|
708
|
+
f.write(` * |typedDefinition |${f1(`${browseName.name?.toString()} ${n(nodeId)}`)}|`);
|
|
709
|
+
if (nodeClass === NodeClass.VariableType) {
|
|
724
710
|
const { valueRank } = classDef;
|
|
725
|
-
f.write(` * |dataType |${
|
|
726
|
-
f.write(` * |dataType Name |${
|
|
727
|
-
valueRank && f.write(` * |value rank |${
|
|
711
|
+
f.write(` * |dataType |${f1(DataType[dataType])}|`);
|
|
712
|
+
f.write(` * |dataType Name |${f1(`${dataTypeName} ${n(dataTypeNodeId)}`)}|`);
|
|
713
|
+
valueRank && f.write(` * |value rank |${f1(valueRank.toString())}|`);
|
|
728
714
|
}
|
|
729
|
-
f.write(` * |isAbstract |${
|
|
715
|
+
f.write(` * |isAbstract |${f1(isAbstract.toString())}|`);
|
|
730
716
|
f.write(` */`);
|
|
731
717
|
// if (interfaceName.name === "UAOperationLimits") {
|
|
732
718
|
// debugger;
|
|
@@ -737,13 +723,13 @@ async function _convertTypeToTypescript(session, nodeId, cache, f) {
|
|
|
737
723
|
cache.ensureImported(baseInterfaceName);
|
|
738
724
|
cache.ensureImported({ ...baseInterfaceName, name: `${baseInterfaceName.name}${baseExtension}` });
|
|
739
725
|
const ch = calculateChevrons(classDef);
|
|
740
|
-
if (nodeClass ===
|
|
726
|
+
if (nodeClass === NodeClass.VariableType) {
|
|
741
727
|
if (classDef.dataTypeImport) {
|
|
742
728
|
// c8 ignore next
|
|
743
729
|
if (doDebug) {
|
|
744
|
-
debugLog(
|
|
730
|
+
debugLog(chalk.red(" ----------------> ", classDef.browseName));
|
|
745
731
|
classDef.dataTypeImport.forEach((a) => {
|
|
746
|
-
debugLog(
|
|
732
|
+
debugLog(chalk.red(" ------------------------> ", a.module, a.name, a.namespace));
|
|
747
733
|
});
|
|
748
734
|
}
|
|
749
735
|
classDef.dataTypeImport.forEach(cache.ensureImported.bind(cache));
|
|
@@ -792,7 +778,7 @@ async function _convertTypeToTypescript(session, nodeId, cache, f) {
|
|
|
792
778
|
}
|
|
793
779
|
}
|
|
794
780
|
const baseStuff = getBaseClassWithOmit(classDef);
|
|
795
|
-
if (nodeClass ===
|
|
781
|
+
if (nodeClass === NodeClass.VariableType) {
|
|
796
782
|
cache.referenceBasicType("DataType");
|
|
797
783
|
// if dataType is a extension object we can simpligy by forcing DT
|
|
798
784
|
const className = `${interfaceName.name}${ch.chevronsDef}`;
|
|
@@ -808,16 +794,16 @@ async function _convertTypeToTypescript(session, nodeId, cache, f) {
|
|
|
808
794
|
f.write(`}`);
|
|
809
795
|
return { type: "ua", content: f.toString(), typeName: interfaceName.name };
|
|
810
796
|
}
|
|
811
|
-
async function convertTypeToTypescript(session, nodeId, options, cache, f) {
|
|
812
|
-
f = new
|
|
813
|
-
cache = cache || (await
|
|
797
|
+
export async function convertTypeToTypescript(session, nodeId, options, cache, f) {
|
|
798
|
+
f = new LineFile();
|
|
799
|
+
cache = cache || (await constructCache(session, options));
|
|
814
800
|
const { type, content, typeName } = await _convertTypeToTypescript(session, nodeId, cache);
|
|
815
801
|
f.write(`// ----- this file has been automatically generated - do not edit`);
|
|
816
802
|
f.write(dumpUsedExport(typeName, nodeId.namespace, cache));
|
|
817
803
|
f.write(content);
|
|
818
804
|
const folder = cache.namespace[nodeId.namespace].sourceFolder;
|
|
819
805
|
const module = cache.namespace[nodeId.namespace].module;
|
|
820
|
-
const filename =
|
|
806
|
+
const filename = toFilename(typeName);
|
|
821
807
|
const dependencies = findUsedImport(nodeId.namespace, cache);
|
|
822
808
|
return { type, content: f.toString(), folder, module, filename, dependencies };
|
|
823
809
|
}
|