node-opcua-convert-nodeset-to-javascript 2.178.0 → 2.179.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.
Files changed (47) hide show
  1. package/dist/_dataType.d.ts +4 -4
  2. package/dist/_dataType.js +33 -14
  3. package/dist/_dataType.js.map +1 -1
  4. package/dist/convert_namespace_to_typescript.d.ts +2 -2
  5. package/dist/convert_namespace_to_typescript.js +50 -52
  6. package/dist/convert_namespace_to_typescript.js.map +1 -1
  7. package/dist/convert_to_typescript.d.ts +16 -8
  8. package/dist/convert_to_typescript.js +122 -90
  9. package/dist/convert_to_typescript.js.map +1 -1
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.js +1 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/main.js +4 -3
  14. package/dist/main.js.map +1 -1
  15. package/dist/private/cache.d.ts +4 -4
  16. package/dist/private/cache.js +16 -11
  17. package/dist/private/cache.js.map +1 -1
  18. package/dist/private/fs_retry.js +3 -1
  19. package/dist/private/fs_retry.js.map +1 -1
  20. package/dist/private/get_corresponding_data_type.d.ts +4 -4
  21. package/dist/private/get_corresponding_data_type.js +9 -10
  22. package/dist/private/get_corresponding_data_type.js.map +1 -1
  23. package/dist/private/to_filename.js.map +1 -1
  24. package/dist/private/utils.d.ts +5 -5
  25. package/dist/private/utils.js +28 -10
  26. package/dist/private/utils.js.map +1 -1
  27. package/dist/remove_unused.js +36 -7
  28. package/dist/remove_unused.js.map +1 -1
  29. package/dist/update_parent_tsconfig.js +14 -17
  30. package/dist/update_parent_tsconfig.js.map +1 -1
  31. package/dist/walk_through.d.ts +1 -1
  32. package/dist/walk_through.js.map +1 -1
  33. package/package.json +17 -17
  34. package/source/_dataType.ts +47 -27
  35. package/source/convert_namespace_to_typescript.ts +20 -25
  36. package/source/convert_to_typescript.ts +166 -138
  37. package/source/index.ts +2 -2
  38. package/source/main.ts +4 -3
  39. package/source/private/cache.ts +23 -16
  40. package/source/private/fs_retry.ts +3 -1
  41. package/source/private/get_corresponding_data_type.ts +29 -26
  42. package/source/private/to_filename.ts +1 -1
  43. package/source/private/utils.ts +41 -19
  44. package/source/private-stuff.ts +0 -2
  45. package/source/remove_unused.ts +38 -8
  46. package/source/update_parent_tsconfig.ts +27 -16
  47. package/source/walk_through.ts +3 -3
@@ -1,44 +1,34 @@
1
- /* eslint-disable max-depth */
2
1
  import chalk from "chalk";
3
- import { LocalizedText, NodeClass, QualifiedName } from "node-opcua-data-model";
4
- import { NodeId, resolveNodeId } from "node-opcua-nodeid";
5
- import { IBasicSessionBrowseAsyncSimple, IBasicSessionReadAsyncSimple } from "node-opcua-pseudo-session";
6
- import {
7
- ReferenceDescription,
8
- StructureDefinition,
9
- _enumerationDataChangeTrigger
10
- } from "node-opcua-types";
2
+ import type { ModellingRuleType } from "node-opcua-address-space-base";
3
+ import assert from "node-opcua-assert";
4
+ import { type LocalizedText, NodeClass, type QualifiedName } from "node-opcua-data-model";
5
+ import { make_debugLog, make_warningLog } from "node-opcua-debug";
6
+ import type { NodeId } from "node-opcua-nodeid";
7
+ import type { IBasicSessionBrowseAsyncSimple, IBasicSessionReadAsyncSimple } from "node-opcua-pseudo-session";
8
+ import { type ReferenceDescription, StructureDefinition } from "node-opcua-types";
11
9
  import { LineFile } from "node-opcua-utils";
12
10
  import { DataType } from "node-opcua-variant";
13
- import assert from "node-opcua-assert";
14
- import { ModellingRuleType } from "node-opcua-address-space-base";
15
- import { make_warningLog, make_debugLog } from "node-opcua-debug";
11
+ import { _exportDataTypeToTypescript } from "./_dataType";
12
+ import type { Options } from "./options";
13
+ import { type Cache, constructCache, type Import, makeTypeNameNew, type RequestedSubSymbol } from "./private/cache";
14
+ import { getCorrespondingJavascriptType2 } from "./private/get_corresponding_data_type";
15
+ import { toFilename } from "./private/to_filename";
16
16
  import {
17
+ extractBasicDataType,
17
18
  getBrowseName,
18
- getIsAbstract,
19
+ getChildrenOrFolderElements,
20
+ getDataTypeNodeId,
19
21
  getDefinition,
20
22
  getDescription,
23
+ getIsAbstract,
21
24
  getModellingRule,
22
25
  getNodeClass,
23
26
  getSubtypeNodeIdIfAny,
24
27
  getTypeDefOrBaseType,
25
- getChildrenOrFolderElements,
26
- getDataTypeNodeId,
27
- extractBasicDataType,
28
- getValueRank} from "./private/utils";
29
-
30
- import {
31
- Cache,
32
- constructCache,
33
- Import,
34
- makeTypeNameNew,
35
- RequestedSubSymbol
36
- } from "./private/cache";
37
- import { Options } from "./options";
38
- import { toFilename } from "./private/to_filename";
28
+ getValueRank
29
+ } from "./private/utils";
39
30
  import { f1, f2, quotifyIfNecessary, toComment, toJavascritPropertyName } from "./utils2";
40
- import { _exportDataTypeToTypescript } from "./_dataType";
41
- import { getCorrespondingJavascriptType2 } from "./private/get_corresponding_data_type";
31
+
42
32
  const warningLog = make_warningLog("typescript");
43
33
  const debugLog = make_debugLog("typescript");
44
34
  const doDebug = false;
@@ -46,7 +36,7 @@ const baseExtension = "_Base";
46
36
 
47
37
  const m0 = !doDebug ? "" : `/* 0 */`;
48
38
  const m1 = !doDebug ? "" : `/* 1 */`;
49
- const m2 = !doDebug ? "" : `/* 2 */`;
39
+ const _m2 = !doDebug ? "" : `/* 2 */`;
50
40
  const m3 = !doDebug ? "" : `/* 3 */`;
51
41
  const m4 = !doDebug ? "" : `/* 4 */`;
52
42
  const m5 = !doDebug ? "" : `/* 5 */`;
@@ -61,16 +51,15 @@ const mD = !doDebug ? "" : `/* d */`;
61
51
  const mE = !doDebug ? "" : `/* e */`;
62
52
  const mF = !doDebug ? "" : `/* f */`;
63
53
 
64
-
65
54
  export async function convertDataTypeToTypescript(session: IBasicSessionReadAsyncSimple, dataTypeId: NodeId): Promise<void> {
66
55
  const definition = await getDefinition(session, dataTypeId);
67
56
  const browseName = await getBrowseName(session, dataTypeId);
68
57
 
69
- const dataTypeTypescriptName = `UA${browseName.name!.toString()}`;
58
+ const dataTypeTypescriptName = `UA${browseName.name?.toString()}`;
70
59
  const f = new LineFile();
71
60
  if (definition && definition instanceof StructureDefinition) {
72
61
  f.write(`interface ${dataTypeTypescriptName} {`);
73
- for (const field of definition.fields || []) {
62
+ for (const _field of definition.fields || []) {
74
63
  /** */
75
64
  }
76
65
  f.write(`}`);
@@ -114,8 +103,12 @@ export async function extractClassDefinition(
114
103
  cache: Cache
115
104
  ): Promise<ClassDefinition> {
116
105
  const extraImports: Import[] = [];
117
- const _c = (cache as any).classDefCache || {};
118
- (cache as any).classDefCache = _c;
106
+ interface CacheWithClassDefCache {
107
+ classDefCache?: Record<string, ClassDefinition>;
108
+ }
109
+ const cacheWithClassDefCache = cache as unknown as CacheWithClassDefCache;
110
+ const _c = cacheWithClassDefCache.classDefCache || {};
111
+ cacheWithClassDefCache.classDefCache = _c;
119
112
 
120
113
  let classDef: ClassDefinition | null = _c[nodeId.toString()];
121
114
  if (classDef) {
@@ -123,7 +116,7 @@ export async function extractClassDefinition(
123
116
  }
124
117
  const nodeClass = await getNodeClass(session, nodeId);
125
118
  if (nodeClass !== NodeClass.VariableType && nodeClass !== NodeClass.ObjectType) {
126
- throw new Error("Invalid nodeClass " + NodeClass[nodeClass] + " nodeId " + nodeId.toString());
119
+ throw new Error(`Invalid nodeClass ${NodeClass[nodeClass]} nodeId ${nodeId.toString()}`);
127
120
  }
128
121
 
129
122
  const browseName = await getBrowseName(session, nodeId);
@@ -133,20 +126,23 @@ export async function extractClassDefinition(
133
126
  const dataTypeNodeId = await getDataTypeNodeId(session, nodeId);
134
127
  let dataTypeName = "";
135
128
  let dataType: DataType = DataType.Null;
136
- let dataTypeImport: Import[] | undefined = undefined;
137
- let valueRank: number| undefined;
138
- let dataTypeCombination: string| undefined;;
129
+ let dataTypeImport: Import[] | undefined;
130
+ let valueRank: number | undefined;
131
+ let dataTypeCombination: string | undefined;
139
132
  if (nodeClass === NodeClass.VariableType) {
140
- dataType = await extractBasicDataType(session, dataTypeNodeId!);
133
+ if (!dataTypeNodeId) {
134
+ throw new Error(`VariableType ${nodeId.toString()} is expected to have a DataType attribute`);
135
+ }
136
+ dataType = await extractBasicDataType(session, dataTypeNodeId);
141
137
  const importCollector = (i: Import) => {
142
138
  extraImports.push(i);
143
139
  cache.ensureImported(i);
144
140
  };
145
- const info = await getCorrespondingJavascriptType2(session, nodeId, dataTypeNodeId!, cache, importCollector);
141
+ const info = await getCorrespondingJavascriptType2(session, nodeId, dataTypeNodeId, cache, importCollector);
146
142
  const jtype = info.jtype;
147
143
  dataTypeCombination = info.dataTypeCombination;
148
144
  dataTypeName = jtype; // with decoration
149
- if (!dataTypeNodeId?.isEmpty()) {
145
+ if (!dataTypeNodeId.isEmpty()) {
150
146
  // "DT" + (await getBrowseName(session, dataTypeNodeId!))?.name! || "";
151
147
  // const bn = await getBrowseName(session, dataTypeNodeId!);
152
148
  dataTypeImport = extraImports; // makeTypeName2(NodeClass.DataType, bn);
@@ -191,7 +187,6 @@ export async function extractClassDefinition(
191
187
  baseInterfaceName,
192
188
  valueRank,
193
189
  dataTypeCombination
194
-
195
190
  };
196
191
  _c[nodeId.toString()] = classDef;
197
192
 
@@ -210,7 +205,7 @@ interface ClassMemberBasic {
210
205
  description: LocalizedText;
211
206
  suffix?: string;
212
207
  suffixInstantiate?: string;
213
- chevrons: any;
208
+ chevrons: ChevronsInfo | null | undefined;
214
209
  typeToReference: Import[];
215
210
  }
216
211
 
@@ -303,7 +298,7 @@ async function classify(
303
298
  async function extractAllMembers(
304
299
  session: IBasicSessionReadAsyncSimple & IBasicSessionBrowseAsyncSimple,
305
300
  classDef: ClassDefinition,
306
- cache: Cache
301
+ _cache: Cache
307
302
  ): Promise<ClassifiedReferenceDescriptions> {
308
303
  const m = [...classDef.children];
309
304
  let s = classDef;
@@ -331,11 +326,11 @@ export async function findClassMember(
331
326
  const childBrowseName = browseName.toString();
332
327
  const r = baseParentDef.children.find((a) => a.browseName.toString() === childBrowseName);
333
328
  if (r) {
334
- const d = await extractClassMemberDef(session, r!.nodeId, baseParentDef, cache);
329
+ const d = await extractClassMemberDef(session, r?.nodeId, baseParentDef, cache);
335
330
  return d;
336
331
  }
337
332
  const baseBaseParentDef =
338
- baseParentDef.superType && (await extractClassDefinition(session, baseParentDef.superType!.nodeId, cache));
333
+ baseParentDef.superType && (await extractClassDefinition(session, baseParentDef.superType?.nodeId, cache));
339
334
  if (!baseBaseParentDef) {
340
335
  return null;
341
336
  }
@@ -346,7 +341,7 @@ function hasNewMaterial(referenceMembers: ReferenceDescription[], instanceMember
346
341
  const ref = referenceMembers.map((x) => x.browseName.toString()).sort();
347
342
  const instance = instanceMembers.map((x) => x.browseName.toString()).sort();
348
343
  for (const n of instance) {
349
- if (ref.findIndex((x) => x === n) < 0) {
344
+ if (ref.indexOf(n) < 0) {
350
345
  return true;
351
346
  }
352
347
  }
@@ -364,7 +359,7 @@ export function checkIfShouldExposeInnerDefinition(
364
359
  return hasNewStuff;
365
360
  }
366
361
 
367
- function dump1(a: ClassifiedReferenceDescriptions): void {
362
+ function _dump1(a: ClassifiedReferenceDescriptions): void {
368
363
  console.log(
369
364
  "Mandatory = ",
370
365
  a.Mandatory.map((x) => x.browseName.toString())
@@ -378,10 +373,10 @@ function dump1(a: ClassifiedReferenceDescriptions): void {
378
373
  .join(" ")
379
374
  );
380
375
  }
381
- dump1;
376
+ _dump1;
382
377
 
383
378
  function getSameInBaseClass(parent: ClassDefinitionB | null, browseName: QualifiedName): ClassMember | null {
384
- if (!parent || !parent.baseClassDef) return null;
379
+ if (!parent?.baseClassDef) return null;
385
380
  const originalClassMember = parent.baseClassDef.members.find((m) => m.browseName.toString() === browseName.toString());
386
381
  return originalClassMember || null;
387
382
  }
@@ -397,12 +392,14 @@ async function _extractLocalMembers(
397
392
  classMember: ClassMember,
398
393
  cache: Cache
399
394
  ): Promise<ClassMemberBasic[]> {
400
-
401
395
  const children2: ClassMemberBasic[] = [];
402
396
  for (const child of classMember.children) {
403
397
  const nodeId = child.nodeId;
404
398
  const browseName = await getBrowseName(session, nodeId);
405
- const name = toJavascritPropertyName(browseName.name!, { ignoreConflictingName: true });
399
+ if (!browseName.name) {
400
+ throw new Error(`Expecting a browseName.name for node ${nodeId.toString()}`);
401
+ }
402
+ const name = toJavascritPropertyName(browseName.name, { ignoreConflictingName: true });
406
403
 
407
404
  const description = await getDescription(session, nodeId);
408
405
  const modellingRule = await getModellingRule(session, nodeId);
@@ -463,11 +460,20 @@ async function extractVariableExtra(
463
460
  const nodeClass = await getNodeClass(session, nodeId);
464
461
  if (nodeClass === NodeClass.Variable) {
465
462
  const dataTypeNodeId = await getDataTypeNodeId(session, nodeId);
466
- const valueRank = await getValueRank(session, nodeId);
467
- valueRank;
468
- const { dataType, jtype, dataTypeCombination } = await getCorrespondingJavascriptType2(session, nodeId, dataTypeNodeId!, cache, importCollector);
463
+ if (!dataTypeNodeId) {
464
+ throw new Error(`Variable ${nodeId.toString()} is expected to have a DataType attribute`);
465
+ }
466
+ const _valueRank = await getValueRank(session, nodeId);
467
+ _valueRank;
468
+ const { dataType, jtype, dataTypeCombination } = await getCorrespondingJavascriptType2(
469
+ session,
470
+ nodeId,
471
+ dataTypeNodeId,
472
+ cache,
473
+ importCollector
474
+ );
469
475
 
470
- cache && cache.referenceBasicType("DataType");
476
+ cache?.referenceBasicType("DataType");
471
477
  importCollector({ name: "DataType", namespace: -1, module: "BasicType" });
472
478
 
473
479
  const t = isUnspecifiedDataType(classMember.classDef?.dataType);
@@ -475,13 +481,13 @@ async function extractVariableExtra(
475
481
  const suffix =
476
482
  jtype === "undefined" || isUnspecifiedDataType(dataType)
477
483
  ? `<any, any>`
478
- : `<${jtype}${t ? `, ${m0}DataType.${DataType[dataType]}` :""}>`;
484
+ : `<${jtype}${t ? `, ${m0}DataType.${DataType[dataType]}` : ""}>`;
479
485
 
480
486
  // const suffix2 = `<T${t ? `, /DT extends DataType` : ""}>`;
481
487
  const suffix3 = `<T${t ? `, ${m1}DT` : ""}>`;
482
488
 
483
489
  const typeDef = await getTypeDefOrBaseType(session, nodeId);
484
- const typeDefCD = await extractClassDefinition(session, typeDef.nodeId!, cache);
490
+ const typeDefCD = await extractClassDefinition(session, typeDef.nodeId, cache);
485
491
  const chevrons = calculateChevrons(typeDefCD, { dataType });
486
492
  const suffix2 = chevrons.chevronsDef;
487
493
 
@@ -497,22 +503,31 @@ async function extractVariableExtra(
497
503
  }
498
504
  } else {
499
505
  if (!isUnspecifiedDataType(typeDefCD.dataType)) {
500
-
501
- if (jtype === "number" && (dataTypeNodeId!.value as number> 25)) {
502
- console.log("dataTypeNodeId", dataTypeNodeId?.toString()), dataTypeCombination;
506
+ if (jtype === "number" && (dataTypeNodeId?.value as number) > 25) {
507
+ console.log("dataTypeNodeId", dataTypeNodeId?.toString(), dataTypeCombination);
503
508
  }
504
509
  if (dataTypeCombination) {
505
510
  suffixInstantiate = `<${jtype}${mD},${dataTypeCombination}>`;
506
511
  } else {
507
512
  suffixInstantiate = `<${jtype}${mE}>`;
508
-
509
513
  }
510
514
  } else {
511
515
  suffixInstantiate = `<${jtype}, DataType.${DataType[dataType]}${mF}>`;
512
516
  }
513
517
  }
514
518
 
515
- return { suffixInstantiate, suffix, suffix2, suffix3, dataTypeNodeId, dataType, jtype, typeToReference, chevrons , dataTypeCombination};
519
+ return {
520
+ suffixInstantiate,
521
+ suffix,
522
+ suffix2,
523
+ suffix3,
524
+ dataTypeNodeId,
525
+ dataType,
526
+ jtype,
527
+ typeToReference,
528
+ chevrons,
529
+ dataTypeCombination
530
+ };
516
531
  }
517
532
  return { suffix: "", typeToReference };
518
533
  }
@@ -524,7 +539,6 @@ interface ClassDefinitionB {
524
539
  interfaceName: Import;
525
540
  baseClassDef?: ClassDefinition | null;
526
541
  }
527
- // eslint-disable-next-line max-statements
528
542
  export async function extractClassMemberDef(
529
543
  session: IBasicSessionReadAsyncSimple & IBasicSessionBrowseAsyncSimple,
530
544
  nodeId: NodeId,
@@ -534,10 +548,13 @@ export async function extractClassMemberDef(
534
548
  const nodeClass = await getNodeClass(session, nodeId);
535
549
  const browseName = await getBrowseName(session, nodeId);
536
550
 
537
- const name = toJavascritPropertyName(browseName.name!, { ignoreConflictingName: true });
551
+ if (!browseName.name) {
552
+ throw new Error(`Expecting a browseName.name for node ${nodeId.toString()}`);
553
+ }
554
+ const name = toJavascritPropertyName(browseName.name, { ignoreConflictingName: true });
538
555
 
539
556
  if (nodeClass !== NodeClass.Method && nodeClass !== NodeClass.Object && nodeClass !== NodeClass.Variable) {
540
- throw new Error("Invalid property " + NodeClass[nodeClass] + " " + browseName?.toString() + " " + nodeId.toString());
557
+ throw new Error(`Invalid property ${NodeClass[nodeClass]} ${browseName?.toString()} ${nodeId.toString()}`);
541
558
  }
542
559
 
543
560
  const description = await getDescription(session, nodeId);
@@ -548,7 +565,7 @@ export async function extractClassMemberDef(
548
565
 
549
566
  const typeDefinition = await getTypeDefOrBaseType(session, nodeId);
550
567
 
551
- if (nodeClass !== NodeClass.Method && (!typeDefinition.browseName || !typeDefinition.browseName.name)) {
568
+ if (nodeClass !== NodeClass.Method && !typeDefinition.browseName?.name) {
552
569
  warningLog(typeDefinition.toString());
553
570
  warningLog("cannot find typeDefinition for ", browseName.toString(), "( is the namespace loaded ?)");
554
571
  }
@@ -561,9 +578,9 @@ export async function extractClassMemberDef(
561
578
 
562
579
  let shouldExposeInnerDefinition = false;
563
580
  // find member exposed by type definition
564
- const baseParentDef = parentDef.superType && (await extractClassDefinition(session, parentDef.superType!.nodeId, cache));
581
+ const baseParentDef = parentDef.superType && (await extractClassDefinition(session, parentDef.superType?.nodeId, cache));
565
582
  if (classDef && baseParentDef) {
566
- const chevrons1 = calculateChevrons(classDef, baseParentDef);
583
+ const _chevrons1 = calculateChevrons(classDef, baseParentDef);
567
584
  assert(!innerClass);
568
585
 
569
586
  // let's extract the member that are theorically defined in the member
@@ -585,7 +602,7 @@ export async function extractClassMemberDef(
585
602
  if (sameMemberInBaseClass) {
586
603
  innerClass = {
587
604
  module: parentDef.interfaceName.module,
588
- name: parentDef.interfaceName.name + "_" + name,
605
+ name: `${parentDef.interfaceName.name}_${name}`,
589
606
  namespace: nodeId.namespace
590
607
  };
591
608
  childBase = sameMemberInBaseClass.childType;
@@ -593,7 +610,7 @@ export async function extractClassMemberDef(
593
610
  } else {
594
611
  innerClass = {
595
612
  module: parentDef.interfaceName.module,
596
- name: parentDef.interfaceName.name + "_" + name,
613
+ name: `${parentDef.interfaceName.name}_${name}`,
597
614
  namespace: nodeId.namespace
598
615
  };
599
616
  childBase = childType;
@@ -647,22 +664,27 @@ export async function extractClassMemberDef(
647
664
  ...classMember,
648
665
  ...extra
649
666
  };
650
-
667
+
651
668
  const baseParentDef2 = parentDef.superType && parentDef.baseClassDef;
652
669
  if (baseParentDef2) {
653
- const sameMemberInBase = baseParentDef2.members.find(
654
- (m) => m.browseName.toString() === browseName.toString()
655
- );
656
- if (sameMemberInBase && sameMemberInBase.childType.name === classMember.childType.name
657
- && sameMemberInBase.childType.name !== typeDefinition.browseName.name?.toString()) {
670
+ const sameMemberInBase = baseParentDef2.members.find((m) => m.browseName.toString() === browseName.toString());
671
+ if (
672
+ sameMemberInBase &&
673
+ sameMemberInBase.childType.name === classMember.childType.name &&
674
+ sameMemberInBase.childType.name !== typeDefinition.browseName.name?.toString()
675
+ ) {
658
676
  // childType was inherited from base (e.g., UADiscreteItem instead of UATwoStateDiscrete)
659
677
  // Recalculate suffix based on base class's classDef
660
678
  if (sameMemberInBase.classDef && classMember.dataType !== undefined) {
661
- const baseTypeHasUnspecifiedDataType =
662
- sameMemberInBase.classDef.dataType === DataType.Null ||
679
+ const baseTypeHasUnspecifiedDataType =
680
+ sameMemberInBase.classDef.dataType === DataType.Null ||
663
681
  sameMemberInBase.classDef.dataType === DataType.Variant;
664
-
665
- if (baseTypeHasUnspecifiedDataType && classMember.dataType !== DataType.Null && classMember.dataType !== DataType.Variant) {
682
+
683
+ if (
684
+ baseTypeHasUnspecifiedDataType &&
685
+ classMember.dataType !== DataType.Null &&
686
+ classMember.dataType !== DataType.Variant
687
+ ) {
666
688
  // Base type is generic (2 params), current has specific dataType
667
689
  // Generate: <specificType, DataType.SpecificType>
668
690
  classMember.suffixInstantiate = `<${classMember.jtype}, DataType.${DataType[classMember.dataType]}>`;
@@ -691,7 +713,7 @@ async function preDumpChildren(padding: string, classDef: ClassDefinition, f: Li
691
713
 
692
714
  //f.write(`export interface ${innerClass.name}${suffix2} extends ${childBase.name}${suffix3} { // ${NodeClass[nodeClass]}`);
693
715
  f.write(`export interface ${innerClass.name}${suffix2} extends ${baseStuff} { // ${NodeClass[nodeClass]}`);
694
- await dumpChildren(padding + " ", memberDef.children2, f, cache);
716
+ await dumpChildren(`${padding} `, memberDef.children2, f, cache);
695
717
  f.write("}");
696
718
  }
697
719
  }
@@ -709,7 +731,9 @@ function dumpChildren(padding: string, children: ClassMemberBasic[], f: LineFile
709
731
 
710
732
  for (const def of children) {
711
733
  const { suffixInstantiate, name, childType, isOptional, description } = def;
712
- def.typeToReference.forEach((t) => cache.ensureImported(t));
734
+ def.typeToReference.forEach((t) => {
735
+ cache.ensureImported(t);
736
+ });
713
737
 
714
738
  if (isPlaceHolder(def)) {
715
739
  f.write(" // PlaceHolder for ", name);
@@ -740,10 +764,8 @@ export function findUsedImport(namespaceIndex: number, cache: Cache): string[] {
740
764
  const usedImport: string[] = [];
741
765
  // from standard types
742
766
  for (const imp of Object.keys(cache.imports)) {
743
- const symbolToImport = Object.keys(cache.imports[imp]).filter((f) =>
744
- Object.prototype.hasOwnProperty.call(cache.requestedBasicTypes, f)
745
- );
746
- if (symbolToImport.length == 0) {
767
+ const symbolToImport = Object.keys(cache.imports[imp]).filter((f) => Object.hasOwn(cache.requestedBasicTypes, f));
768
+ if (symbolToImport.length === 0) {
747
769
  continue;
748
770
  }
749
771
  usedImport.push(imp);
@@ -768,9 +790,9 @@ function dumpUsedExport(currentType: string, namespaceIndex: number, cache: Cach
768
790
 
769
791
  for (const imp of Object.keys(cache.imports)) {
770
792
  const symbolToImport = Object.keys(cache.imports[imp]).filter(
771
- (f) => f !== currentType && Object.prototype.hasOwnProperty.call(cache.requestedBasicTypes, f)
793
+ (f) => f !== currentType && Object.hasOwn(cache.requestedBasicTypes, f)
772
794
  );
773
- if (symbolToImport.length == 0) {
795
+ if (symbolToImport.length === 0) {
774
796
  continue;
775
797
  }
776
798
  f.write(`import { ${symbolToImport.join(", ")} } from "${imp}"`);
@@ -802,6 +824,8 @@ function dumpUsedExport(currentType: string, namespaceIndex: number, cache: Cach
802
824
 
803
825
  export type Type = "enum" | "basic" | "structure" | "ua";
804
826
 
827
+ type ChevronsInfo = ReturnType<typeof calculateChevrons>;
828
+
805
829
  function calculateChevrons(classDef: ClassDefinition, classDefDerived?: { dataType: DataType }) {
806
830
  const { nodeClass, dataType, dataTypeName } = classDef;
807
831
  let chevronsDef = "";
@@ -853,13 +877,16 @@ function extractMembersRecursively(classDef?: ClassDefinition | null): string[]
853
877
  function getBaseClassWithOmit(classDef: ClassDefinition) {
854
878
  const { baseInterfaceName, members } = classDef;
855
879
 
880
+ if (!classDef.baseClassDef) {
881
+ throw new Error(`Expecting a baseClassDef for ${classDef.browseName.toString()}`);
882
+ }
856
883
  const allMembers = extractMembersRecursively(classDef.baseClassDef);
857
884
  const conflictingMembers = members.filter((m) => allMembers.indexOf(m.name) !== -1);
858
885
  //console.log(allMembers.join(" "));
859
886
  if (conflictingMembers.length) {
860
887
  // console.log("conflictingMembers = ", conflictingMembers.map((a) => a.name).join(" "));
861
888
  }
862
- const chBase = calculateChevrons(classDef.baseClassDef!, classDef);
889
+ const chBase = calculateChevrons(classDef.baseClassDef, classDef);
863
890
 
864
891
  let baseStuff = `${baseInterfaceName?.name}${chBase.chevronsUse}`;
865
892
  if (conflictingMembers.length) {
@@ -886,7 +913,6 @@ function getBaseClassWithOmit2(classMember: ClassMember) {
886
913
  /**
887
914
  * nodeId : a DataType, ReferenceType,AObjectType, VariableType node
888
915
  */
889
- // eslint-disable-next-line max-statements
890
916
  export async function _convertTypeToTypescript(
891
917
  session: IBasicSessionReadAsyncSimple & IBasicSessionBrowseAsyncSimple,
892
918
  nodeId: NodeId,
@@ -929,13 +955,12 @@ export async function _convertTypeToTypescript(
929
955
  f.write(` * |----------------|${f2("-")}|`);
930
956
  f.write(` * |namespace |${f1(cache.namespace[nodeId.namespace].namespaceUri)}|`);
931
957
  f.write(` * |nodeClass |${f1(NodeClass[nodeClass])}|`);
932
- f.write(` * |typedDefinition |${f1(browseName.name!.toString() + " " + n(nodeId))}|`);
958
+ f.write(` * |typedDefinition |${f1(`${browseName.name?.toString()} ${n(nodeId)}`)}|`);
933
959
  if (nodeClass === NodeClass.VariableType) {
934
960
  const { valueRank } = classDef;
935
961
  f.write(` * |dataType |${f1(DataType[dataType])}|`);
936
- f.write(` * |dataType Name |${f1(dataTypeName + " " + n(dataTypeNodeId))}|`);
962
+ f.write(` * |dataType Name |${f1(`${dataTypeName} ${n(dataTypeNodeId)}`)}|`);
937
963
  valueRank && f.write(` * |value rank |${f1(valueRank.toString())}|`);
938
-
939
964
  }
940
965
  f.write(` * |isAbstract |${f1(isAbstract.toString())}|`);
941
966
  f.write(` */`);
@@ -943,57 +968,60 @@ export async function _convertTypeToTypescript(
943
968
  // if (interfaceName.name === "UAOperationLimits") {
944
969
  // debugger;
945
970
  // }
946
- cache.ensureImported(baseInterfaceName!);
947
- cache.ensureImported({ ...baseInterfaceName!, name: baseInterfaceName!.name + `${baseExtension}` });
971
+ if (!baseInterfaceName) {
972
+ throw new Error(`Expecting a baseInterfaceName for ${interfaceName.name}`);
973
+ }
974
+ cache.ensureImported(baseInterfaceName);
975
+ cache.ensureImported({ ...baseInterfaceName, name: `${baseInterfaceName.name}${baseExtension}` });
948
976
 
949
977
  const ch = calculateChevrons(classDef);
950
-
951
- {
952
- if (nodeClass === NodeClass.VariableType) {
953
- if (classDef.dataTypeImport) {
954
- // c8 ignore next
955
- if (doDebug) {
956
- debugLog(chalk.red(" ----------------> ", classDef.browseName));
957
- classDef.dataTypeImport.forEach((a) => {
958
- debugLog(chalk.red(" ------------------------> ", a.module, a.name, a.namespace));
959
- });
960
- }
961
- classDef.dataTypeImport.forEach(cache.ensureImported.bind(cache));
978
+ if (nodeClass === NodeClass.VariableType) {
979
+ if (classDef.dataTypeImport) {
980
+ // c8 ignore next
981
+ if (doDebug) {
982
+ debugLog(chalk.red(" ----------------> ", classDef.browseName));
983
+ classDef.dataTypeImport.forEach((a) => {
984
+ debugLog(chalk.red(" ------------------------> ", a.module, a.name, a.namespace));
985
+ });
962
986
  }
963
- cache.referenceBasicType("DataType");
964
- const chevrons = calculateChevrons(classDef);
965
- const chevronsBase = calculateChevrons(classDef.baseClassDef!, classDef);
966
- // Shall we cache.ensureImported({ ...baseInterfaceName!, module: dataTypeName, name: dataTypeName });
967
- const classBaseName = `${interfaceName.name}${baseExtension}${chevrons.chevronsDef}`;
968
- if (countExposedChildren(members) === 0 && baseInterfaceName?.name !== "UAVariableT") {
969
- //
970
- const baseName = `${baseInterfaceName?.name}${baseExtension}${chevronsBase.chevronsExtend}`;
971
- f.write(`export type ${classBaseName} = ${baseName};`);
987
+ classDef.dataTypeImport.forEach(cache.ensureImported.bind(cache));
988
+ }
989
+ cache.referenceBasicType("DataType");
990
+ const chevrons = calculateChevrons(classDef);
991
+ if (!classDef.baseClassDef) {
992
+ throw new Error(`Expecting a baseClassDef for ${classDef.browseName.toString()}`);
993
+ }
994
+ const chevronsBase = calculateChevrons(classDef.baseClassDef, classDef);
995
+ // Shall we cache.ensureImported({ ...baseInterfaceName, module: dataTypeName, name: dataTypeName });
996
+ const classBaseName = `${interfaceName.name}${baseExtension}${chevrons.chevronsDef}`;
997
+ if (countExposedChildren(members) === 0 && baseInterfaceName?.name !== "UAVariableT") {
998
+ //
999
+ const baseName = `${baseInterfaceName?.name}${baseExtension}${chevronsBase.chevronsExtend}`;
1000
+ f.write(`export type ${classBaseName} = ${baseName};`);
1001
+ } else {
1002
+ if (baseInterfaceName?.name === "UAVariableT") {
1003
+ f.write(`export interface ${classBaseName} {`);
972
1004
  } else {
973
- if (baseInterfaceName?.name === "UAVariableT") {
974
- f.write(`export interface ${classBaseName} {`);
975
- } else {
976
- const baseName = `${baseInterfaceName?.name}${baseExtension}${chevronsBase.chevronsExtend}`;
977
- f.write(`export interface ${classBaseName} extends ${baseName} {`);
978
- }
979
- await dumpChildren(" ", members, f, cache);
980
- f.write(`}`);
1005
+ const baseName = `${baseInterfaceName?.name}${baseExtension}${chevronsBase.chevronsExtend}`;
1006
+ f.write(`export interface ${classBaseName} extends ${baseName} {`);
981
1007
  }
1008
+ await dumpChildren(" ", members, f, cache);
1009
+ f.write(`}`);
1010
+ }
1011
+ } else {
1012
+ const classBaseName = `${interfaceName.name}${baseExtension}`;
1013
+ if (countExposedChildren(members) === 0 && baseInterfaceName?.name !== "UAObject") {
1014
+ const baseName = `${baseInterfaceName?.name}${baseExtension}`;
1015
+ f.write(`export type ${classBaseName} = ${baseName};`);
982
1016
  } else {
983
- const classBaseName = `${interfaceName.name}${baseExtension}`;
984
- if (countExposedChildren(members) === 0 && baseInterfaceName?.name !== "UAObject") {
985
- const baseName = `${baseInterfaceName?.name}${baseExtension}`;
986
- f.write(`export type ${classBaseName} = ${baseName};`);
1017
+ if (baseInterfaceName?.name === "UAObject") {
1018
+ f.write(`export interface ${classBaseName} {`);
987
1019
  } else {
988
- if (baseInterfaceName?.name === "UAObject") {
989
- f.write(`export interface ${classBaseName} {`);
990
- } else {
991
- const baseName = `${baseInterfaceName?.name}${baseExtension}`;
992
- f.write(`export interface ${classBaseName} extends ${baseName} {`);
993
- }
994
- await dumpChildren(" ", members, f, cache);
995
- f.write(`}`);
1020
+ const baseName = `${baseInterfaceName?.name}${baseExtension}`;
1021
+ f.write(`export interface ${classBaseName} extends ${baseName} {`);
996
1022
  }
1023
+ await dumpChildren(" ", members, f, cache);
1024
+ f.write(`}`);
997
1025
  }
998
1026
  }
999
1027
  const baseStuff = getBaseClassWithOmit(classDef);
package/source/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./convert_to_typescript";
2
1
  export * from "./convert_namespace_to_typescript";
3
- export * from "./walk_through";
2
+ export * from "./convert_to_typescript";
3
+ export * from "./walk_through";
package/source/main.ts CHANGED
@@ -31,7 +31,7 @@ async function main() {
31
31
  const session = new PseudoSession(addressSpace);
32
32
  const options = {
33
33
  baseFolder: path.join(__dirname, "../../"),
34
- prefix: "node-opcua-nodeset-",
34
+ prefix: "node-opcua-nodeset-"
35
35
  };
36
36
  // const nodesetCatalog2 = nodesetCatalog.filter((meta) => meta.name == "scales");
37
37
 
@@ -48,7 +48,7 @@ async function main() {
48
48
  }
49
49
  await convertNamespaceTypeToTypescript(session, index, {
50
50
  ...options,
51
- nsName: meta.name,
51
+ nsName: meta.name
52
52
  });
53
53
  }
54
54
 
@@ -56,7 +56,8 @@ async function main() {
56
56
  // source/ folder on disk. This covers cases where a catalog entry name
57
57
  // doesn't line up with its package folder (e.g. catalog "standard" writes
58
58
  // into node-opcua-nodeset-ua).
59
- const folders = fs.readdirSync(options.baseFolder)
59
+ const folders = fs
60
+ .readdirSync(options.baseFolder)
60
61
  .filter((name) => name.startsWith(options.prefix))
61
62
  .map((name) => path.join(options.baseFolder, name))
62
63
  .filter((p) => fs.existsSync(path.join(p, "source")));