node-opcua-convert-nodeset-to-javascript 2.76.0 → 2.77.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 (44) hide show
  1. package/dist/_dataType.d.ts +10 -0
  2. package/dist/_dataType.js +153 -0
  3. package/dist/_dataType.js.map +1 -0
  4. package/dist/convert_namespace_to_typescript.d.ts +3 -3
  5. package/dist/convert_namespace_to_typescript.js +182 -182
  6. package/dist/convert_to_typescript.d.ts +105 -110
  7. package/dist/convert_to_typescript.js +753 -987
  8. package/dist/convert_to_typescript.js.map +1 -1
  9. package/dist/index.d.ts +3 -3
  10. package/dist/index.js +19 -19
  11. package/dist/main.d.ts +1 -1
  12. package/dist/main.js +77 -74
  13. package/dist/main.js.map +1 -1
  14. package/dist/official_namespaces.d.ts +23 -23
  15. package/dist/official_namespaces.js +35 -35
  16. package/dist/official_namespaces.js.map +1 -1
  17. package/dist/options.d.ts +5 -5
  18. package/dist/options.js +2 -2
  19. package/dist/private/cache.d.ts +61 -59
  20. package/dist/private/cache.js +236 -221
  21. package/dist/private/cache.js.map +1 -1
  22. package/dist/private/get_corresponding_data_type.d.ts +14 -0
  23. package/dist/private/get_corresponding_data_type.js +104 -0
  24. package/dist/private/get_corresponding_data_type.js.map +1 -0
  25. package/dist/private/to_filename.d.ts +1 -1
  26. package/dist/private/to_filename.js +9 -9
  27. package/dist/private/utils.d.ts +31 -31
  28. package/dist/private/utils.js +289 -289
  29. package/dist/private-stuff.d.ts +4 -4
  30. package/dist/private-stuff.js +20 -20
  31. package/dist/utils2.d.ts +7 -0
  32. package/dist/utils2.js +58 -0
  33. package/dist/utils2.js.map +1 -0
  34. package/dist/walk_through.d.ts +13 -13
  35. package/dist/walk_through.js +86 -86
  36. package/package.json +19 -18
  37. package/source/_dataType.ts +164 -0
  38. package/source/convert_to_typescript.ts +4 -252
  39. package/source/main.ts +5 -2
  40. package/source/official_namespaces.ts +0 -1
  41. package/source/private/cache.ts +24 -7
  42. package/source/private/get_corresponding_data_type.ts +104 -0
  43. package/source/utils2.ts +55 -0
  44. package/tsconfig-generated.json +4 -1
@@ -1,6 +1,5 @@
1
1
  /* eslint-disable max-depth */
2
2
  import * as chalk from "chalk";
3
- import * as wrap from "wordwrap";
4
3
  import { LocalizedText, NodeClass, QualifiedName } from "node-opcua-data-model";
5
4
  import { NodeId } from "node-opcua-nodeid";
6
5
  import { IBasicSession } from "node-opcua-pseudo-session";
@@ -45,11 +44,11 @@ import {
45
44
  } from "./private/cache";
46
45
  import { Options } from "./options";
47
46
  import { toFilename } from "./private/to_filename";
47
+ import { f1, f2, quotifyIfNecessary, toComment, toJavascritPropertyName } from "./utils2";
48
+ import { _exportDataTypeToTypescript } from "./_dataType";
49
+ import { getCorrepondingJavascriptType2 } from "./private/get_corresponding_data_type";
48
50
  const warningLog = make_warningLog("typescript");
49
51
  const doDebug = false;
50
- const wrapText = wrap(0, 50);
51
- const f2 = (str: string) => str.padEnd(50, "-");
52
- const f1 = (str: string) => str.padEnd(50, " ");
53
52
  const baseExtension = "_Base";
54
53
 
55
54
  const m0 = !doDebug ? "" : `/* 0 */`;
@@ -81,137 +80,6 @@ export async function convertDataTypeToTypescript(session: IBasicSession, dataTy
81
80
  }
82
81
  }
83
82
 
84
- // to avoid clashes
85
- function toJavascritPropertyName(childName: string, { ignoreConflictingName }: { ignoreConflictingName: boolean }): string {
86
- childName = lowerFirstLetter(childName);
87
-
88
- if (ignoreConflictingName) {
89
- if (childName === "namespaceUri") {
90
- childName = "$namespaceUri";
91
- }
92
- if (childName === "rolePermissions") {
93
- childName = "$rolePermissions";
94
- }
95
- if (childName === "displayName") {
96
- childName = "$displayName";
97
- }
98
- if (childName === "eventNotifier") {
99
- childName = "$eventNotifier";
100
- }
101
- if (childName === "description") {
102
- childName = "$description";
103
- }
104
- }
105
- return childName.replace(/</g, "$").replace(/>/g, "$").replace(/ |\./g, "_").replace(/#/g, "_");
106
- }
107
-
108
- function quotifyIfNecessary(s: string): string {
109
- if (s.match(/(^[^a-zA-Z])|([^a-zA-Z_0-9])/)) {
110
- return `"${s}"`;
111
- }
112
- if (s === "nodeClass") {
113
- return `["$nodeClass"]`;
114
- }
115
- return s;
116
- }
117
-
118
- async function getCorrepondingJavascriptType2(
119
- session: IBasicSession,
120
- nodeId: NodeId,
121
- dataTypeNodeId: NodeId,
122
- cache: Cache,
123
- importCollect?: (t: Import) => void
124
- ): Promise<{ dataType: DataType; jtype: string }> {
125
- const q = await getCorrepondingJavascriptType(session, dataTypeNodeId, cache, importCollect);
126
- const valueRank = await getValueRank(session, nodeId);
127
- return { dataType: q.dataType, jtype: q.jtype + (valueRank >= 1 ? "[]" : "") };
128
- }
129
-
130
- // eslint-disable-next-line complexity
131
- async function getCorrepondingJavascriptType(
132
- session: IBasicSession,
133
- dataTypeNodeId: NodeId,
134
- cache: Cache,
135
- importCollect?: (t: Import) => void
136
- ): Promise<{ enumerationType?: string; dataType: DataType; jtype: string }> {
137
- const { dataType, enumerationType } = await _convertNodeIdToDataTypeAsync(session, dataTypeNodeId);
138
-
139
- if (enumerationType) {
140
- // we have a enmeration name here
141
- const jtypeImport = await referenceEnumeration(session, dataTypeNodeId);
142
- const jtype = jtypeImport.name;
143
- importCollect && importCollect(jtypeImport);
144
- return { dataType, jtype };
145
- }
146
-
147
- if (dataType === DataType.ExtensionObject) {
148
- const jtypeImport = await referenceExtensionObject(session, dataTypeNodeId);
149
- const jtype = jtypeImport.name;
150
- importCollect && importCollect(jtypeImport);
151
- return { dataType, jtype };
152
- }
153
- const referenceBasicType = (name: string): string => {
154
- const t = { name, namespace: -1, module: "BasicType" };
155
- importCollect && importCollect(t);
156
- cache.ensureImported(t);
157
- return t.name;
158
- };
159
- switch (dataType) {
160
- case DataType.Null:
161
- return { dataType, jtype: "undefined" };
162
- case DataType.Boolean:
163
- return { dataType, jtype: "boolean" };
164
- case DataType.Byte:
165
- return { dataType, jtype: referenceBasicType("Byte") };
166
- case DataType.ByteString:
167
- return { dataType, jtype: "Buffer" };
168
- case DataType.DataValue:
169
- return { dataType, jtype: referenceBasicType("DataValue") };
170
- case DataType.DateTime:
171
- return { dataType, jtype: "Date" };
172
- case DataType.DiagnosticInfo:
173
- return { dataType, jtype: referenceBasicType("DiagnosticInfo") };
174
- case DataType.Double:
175
- return { dataType, jtype: "number" };
176
- case DataType.Float:
177
- return { dataType, jtype: "number" };
178
- case DataType.Guid:
179
- return { dataType, jtype: referenceBasicType("Guid") };
180
- case DataType.Int16:
181
- return { dataType, jtype: referenceBasicType("Int16") };
182
- case DataType.Int32:
183
- return { dataType, jtype: referenceBasicType("Int32") };
184
- case DataType.UInt16:
185
- return { dataType, jtype: referenceBasicType("UInt16") };
186
- case DataType.UInt32:
187
- return { dataType, jtype: referenceBasicType("UInt32") };
188
- case DataType.UInt64:
189
- return { dataType, jtype: referenceBasicType("UInt64") };
190
- case DataType.Int64:
191
- return { dataType, jtype: referenceBasicType("Int64") };
192
- case DataType.LocalizedText:
193
- return { dataType, jtype: referenceBasicType("LocalizedText") };
194
- case DataType.NodeId:
195
- return { dataType, jtype: referenceBasicType("NodeId") };
196
- case DataType.ExpandedNodeId:
197
- return { dataType, jtype: referenceBasicType("ExpandedNodeId") };
198
- case DataType.QualifiedName:
199
- return { dataType, jtype: referenceBasicType("QualifiedName") };
200
- case DataType.SByte:
201
- return { dataType, jtype: referenceBasicType("SByte") };
202
- case DataType.StatusCode:
203
- return { dataType, jtype: referenceBasicType("StatusCode") };
204
- case DataType.String:
205
- return { dataType, jtype: referenceBasicType("UAString") };
206
- case DataType.Variant:
207
- return { dataType, jtype: referenceBasicType("Variant") };
208
- case DataType.XmlElement:
209
- return { dataType, jtype: referenceBasicType("String") };
210
- default:
211
- throw new Error("Unsupported " + dataType + " " + DataType[dataType]);
212
- }
213
- }
214
-
215
83
  interface ClassDefinition {
216
84
  nodeClass: NodeClass.VariableType | NodeClass.ObjectType;
217
85
  browseName: QualifiedName;
@@ -881,124 +749,8 @@ function dumpUsedExport(currentType: string, namespaceIndex: number, cache: Cach
881
749
  return f.toString();
882
750
  }
883
751
 
884
- function toComment(prefix: string, description: string) {
885
- const d = wrapText(description);
886
- return d
887
- .split("\n")
888
- .map((x) => prefix + x)
889
- .join("\n");
890
- }
891
- export type Type = "enum" | "basic" | "structure" | "ua";
892
- // eslint-disable-next-line max-statements, complexity
893
- export async function _exportDataTypeToTypescript(
894
- session: IBasicSession,
895
- nodeId: NodeId,
896
- cache: Cache,
897
- f?: LineFile
898
- ): Promise<{ type: Type; content: string; typeName: string }> {
899
- f = f || new LineFile();
900
-
901
- const importCollector = (i: Import) => {
902
- cache.ensureImported(i);
903
- };
904
- const nodeClass = NodeClass.DataType;
905
- const description = await getDescription(session, nodeId);
906
- const definition = await getDefinition(session, nodeId);
907
- const browseName = await getBrowseName(session, nodeId);
908
- const isAbstract = await getIsAbstract(session, nodeId);
909
-
910
- const interfaceImport: Import = makeTypeNameNew(nodeClass, definition, browseName);
911
- const interfaceName = interfaceImport.name;
912
-
913
- const superType = await getSubtypeNodeId(session, nodeId);
914
- const baseInterfaceImport: Import = makeTypeNameNew(nodeClass, definition, superType.browseName);
915
-
916
- cache.ensureImported(baseInterfaceImport);
917
-
918
- const baseInterfaceName = baseInterfaceImport.name;
919
- // f.write(superType.toString());
920
- f.write(`/**`);
921
- if (description.text) {
922
- f.write(toComment(" * ", description.text || ""));
923
- f.write(` *`);
924
- }
925
- f.write(` * | |${f1(" ")}|`);
926
- f.write(` * |-----------|${f2("-")}|`);
927
- f.write(` * | namespace |${f1(cache.namespace[nodeId.namespace].namespaceUri)}|`);
928
- f.write(` * | nodeClass |${f1(NodeClass[nodeClass])}|`);
929
- f.write(` * | name |${f1(browseName.toString())}|`);
930
- f.write(` * | isAbstract|${f1(isAbstract.toString())}|`);
931
- f.write(` */`);
932
-
933
- let type: "basic" | "structure" | "enum" | "ua" = "basic";
934
- if (definition instanceof EnumDefinition) {
935
- type = "enum";
936
- f.write(`export enum ${interfaceName} {`);
937
- for (const field of definition.fields!) {
938
- if (field.description.text) {
939
- f.write(` /**`);
940
- f.write(toComment(" * ", field.description.text || ""));
941
- f.write(` */`);
942
- }
943
- f.write(` ${quotifyIfNecessary(field.name!)} = ${field.value[1]},`);
944
- }
945
- f.write(`}`);
946
- } else if (definition instanceof StructureDefinition) {
947
- if (baseInterfaceName === "DTUnion") {
948
- type = "structure";
949
- for (let i = 0; i < definition.fields!.length; i++) {
950
- f.write(`export interface ${interfaceName}_${i} extends ${baseInterfaceName} {`);
951
- for (let j = 0; j < definition.fields!.length; j++) {
952
- const field = definition.fields![j];
953
- const fieldName = toJavascritPropertyName(field.name!, { ignoreConflictingName: false });
954
- if (j === i) {
955
- await outputStructureField(f, field);
956
- } else {
957
- f.write(` ${quotifyIfNecessary(fieldName)}?: never`);
958
- }
959
- }
960
- f.write(`}`);
961
- }
962
- f.write(`export type ${interfaceName} = `);
963
- for (let i = 0; i < definition.fields!.length; i++) {
964
- f.write(` | ${interfaceName}_${i}`);
965
- }
966
- f.write(` ;`);
967
- } else {
968
- type = "structure";
969
- if (!definition.fields!.length && interfaceName !== "DTStructure") {
970
- f.write(`export type ${interfaceName} = ${baseInterfaceName};`);
971
- } else {
972
- if (interfaceName === "DTStructure") {
973
- f.write(`export interface ${interfaceName} {`);
974
- } else {
975
- f.write(`export interface ${interfaceName} extends ${baseInterfaceName} {`);
976
- }
977
- for (const field of definition.fields!) {
978
- await outputStructureField(f, field);
979
- }
980
- f.write(`}`);
981
- }
982
- }
983
- } else {
984
- type = "basic";
985
- f.write(`// NO DEFINITION`);
986
- f.write(`export type ${interfaceName} = ${baseInterfaceName};`);
987
- // throw new Error("Invalid " + definition?.constructor.name);
988
- }
989
- return { type, content: f.toString(), typeName: interfaceName };
990
752
 
991
- async function outputStructureField(f: LineFile, field: StructureField) {
992
- const fieldName = toJavascritPropertyName(field.name!, { ignoreConflictingName: false });
993
- // special case ! fieldName=
994
- if (field.description.text) {
995
- f.write(`/** ${field.description.text}*/`);
996
- }
997
- const ar = field.valueRank >= 1 ? "[]" : "";
998
- const { dataType, jtype } = await getCorrepondingJavascriptType(session, field.dataType, cache, importCollector);
999
- f.write(` ${quotifyIfNecessary(fieldName)}: ${jtype}${ar}; // ${DataType[dataType]} ${field.dataType.toString()}`);
1000
- }
1001
- }
753
+ export type Type = "enum" | "basic" | "structure" | "ua";
1002
754
 
1003
755
  function calculateChevrons(classDef: ClassDefinition, classDefDerived?: { dataType: DataType }) {
1004
756
  const { nodeClass, dataType, dataTypeName } = classDef;
package/source/main.ts CHANGED
@@ -20,7 +20,8 @@ async function main() {
20
20
  nodesets.machineTool,
21
21
  nodesets.cnc,
22
22
  nodesets.woodWorking,
23
- nodesets.glass
23
+ nodesets.glass,
24
+ nodesets.tightening
24
25
  ]);
25
26
 
26
27
  const nsUA = 0;
@@ -37,6 +38,7 @@ async function main() {
37
38
  const nsCommercialKitchenEquipment = addressSpace.getNamespaceIndex("http://opcfoundation.org/UA/CommercialKitchenEquipment/");
38
39
  const nsWW = addressSpace.getNamespaceIndex("http://opcfoundation.org/UA/Woodworking/");
39
40
  const nsGlass = addressSpace.getNamespaceIndex("http://opcfoundation.org/UA/Glass/Flat/");
41
+ const nsThightening = addressSpace.getNamespaceIndex("http://opcfoundation.org/UA/IJT/");
40
42
 
41
43
  const session = new PseudoSession(addressSpace);
42
44
  const options = {
@@ -58,7 +60,8 @@ async function main() {
58
60
  convertNamespaceTypeToTypescript(session, ncCNC, options),
59
61
  convertNamespaceTypeToTypescript(session, nsCommercialKitchenEquipment, options),
60
62
  convertNamespaceTypeToTypescript(session, nsWW, options),
61
- convertNamespaceTypeToTypescript(session, nsGlass, options)
63
+ convertNamespaceTypeToTypescript(session, nsGlass, options),
64
+ convertNamespaceTypeToTypescript(session, nsThightening, options)
62
65
  ];
63
66
  await Promise.all(promises);
64
67
  }
@@ -18,7 +18,6 @@ export const officialNamespaces = {
18
18
  },
19
19
  "commercialKitchenEquipment": {
20
20
  location: "node-opcua-nodeset-commercial-kitchen-equipment"
21
-
22
21
  },
23
22
  "gds": {
24
23
  location: "node-opcua-types-gds"
@@ -12,6 +12,7 @@ export interface Import {
12
12
  name: string;
13
13
  module: string;
14
14
  namespace: number;
15
+ name2?: string;
15
16
  }
16
17
  interface CacheInterfaceNamespace {
17
18
  namespaceUri: string;
@@ -31,7 +32,13 @@ interface RequestedSymbol {
31
32
  symbols: { [key: string]: RequestedSubSymbol };
32
33
  }[];
33
34
  }
34
-
35
+ export function makeName2(name: string) {
36
+ return "U" + name;
37
+ // if (name === "EUInformation") {
38
+ // return "EUInformation2";
39
+ // }
40
+ // return name.replace(/^DT/, "").replace(/^3/, "Three").replace(/^2/, "Two");
41
+ }
35
42
  export class Cache implements CacheInterface {
36
43
  namespace: CacheInterfaceNamespace[] = [];
37
44
  requestedSymbols: RequestedSymbol = { namespace: [] };
@@ -45,11 +52,12 @@ export class Cache implements CacheInterface {
45
52
  UAVariableT: 1,
46
53
  UAMethod: 1,
47
54
  UADataType: 1,
48
- UAProperty: 1,
55
+ UAProperty: 1
49
56
  },
50
57
  "node-opcua-variant": {
51
58
  DataType: 1,
52
- Variant: 1
59
+ Variant: 1,
60
+ VariantOptions: 1,
53
61
  },
54
62
  "node-opcua-data-model": {
55
63
  LocalizedText: 1,
@@ -85,7 +93,13 @@ export class Cache implements CacheInterface {
85
93
  },
86
94
  "node-opcua-types": {
87
95
  EnumValueType: 1
96
+ },
97
+ "node-opcua-extension-object": {
98
+ ExtensionObject: 1
88
99
  }
100
+ // "node-opcua-schemas": {
101
+ // ExtensionObject: 1
102
+ // }
89
103
  };
90
104
  }
91
105
  resetRequire(): void {
@@ -133,11 +147,10 @@ export class Cache implements CacheInterface {
133
147
  }
134
148
  }
135
149
 
136
-
137
150
  function getSourceFolderForNamespace(browseName: QualifiedName, options: Options, cache: Cache2) {
138
151
  const ns = browseName.namespaceIndex;
139
152
  const n = cache.namespaceArray[ns].split("/").filter((s: string) => s.length !== 0);
140
- const nn = (n[n.length - 1] !== "UA" && n[n.length - 2] !== "UA" ? n[n.length - 2] : "") + n[n.length - 1];
153
+ const nn = (n[n.length - 1] !== "UA" && n[n.length - 2] !== "UA" ? n[n.length - 2] : "") + n[n.length - 1];
141
154
  const module = options.prefix + kebabCase(nn);
142
155
  const namespaceFolder = path.join(options.baseFolder, module);
143
156
  const sourceFolder = path.join(namespaceFolder);
@@ -158,7 +171,6 @@ export async function referenceEnumeration(session: IBasicSession, enumerationDa
158
171
  return dataTypeNameImport;
159
172
  }
160
173
 
161
-
162
174
  export class Cache2 extends Cache {
163
175
  public namespaceArray: string[] = [];
164
176
  }
@@ -195,7 +207,12 @@ export async function constructCache(session: IBasicSession, options: Options):
195
207
  function makeBasicTypeImport(name: string): Import {
196
208
  return { name, module: "BasicType", namespace: -1 };
197
209
  }
198
- export function makeTypeNameNew(nodeClass: NodeClass, definition: DataTypeDefinition | null, browseName: QualifiedName, suffix?: string): Import {
210
+ export function makeTypeNameNew(
211
+ nodeClass: NodeClass,
212
+ definition: DataTypeDefinition | null,
213
+ browseName: QualifiedName,
214
+ suffix?: string
215
+ ): Import {
199
216
  assert(browseName && !!browseName.name, "expecting a class name here");
200
217
 
201
218
  const typeName = browseName.name!.toString();
@@ -0,0 +1,104 @@
1
+ import { NodeId } from "node-opcua-nodeid";
2
+ import { IBasicSession } from "node-opcua-pseudo-session";
3
+ import { DataType } from "node-opcua-variant";
4
+ import { Import, referenceEnumeration, referenceExtensionObject } from "./cache";
5
+ import { getValueRank, _convertNodeIdToDataTypeAsync } from "./utils";
6
+ import { Cache } from "./cache";
7
+
8
+ export async function getCorrepondingJavascriptType2(
9
+ session: IBasicSession,
10
+ nodeId: NodeId,
11
+ dataTypeNodeId: NodeId,
12
+ cache: Cache,
13
+ importCollect?: (t: Import) => void
14
+ ): Promise<{ dataType: DataType; jtype: string }> {
15
+ const q = await getCorrepondingJavascriptType(session, dataTypeNodeId, cache, importCollect);
16
+ const valueRank = await getValueRank(session, nodeId);
17
+ return { dataType: q.dataType, jtype: q.jtype + (valueRank >= 1 ? "[]" : "") };
18
+ }
19
+
20
+ // eslint-disable-next-line complexity
21
+ export async function getCorrepondingJavascriptType(
22
+ session: IBasicSession,
23
+ dataTypeNodeId: NodeId,
24
+ cache: Cache,
25
+ importCollect?: (t: Import) => void
26
+ ): Promise<{ enumerationType?: string; dataType: DataType; jtype: string }> {
27
+ const { dataType, enumerationType } = await _convertNodeIdToDataTypeAsync(session, dataTypeNodeId);
28
+
29
+ if (enumerationType) {
30
+ // we have a enmeration name here
31
+ const jtypeImport = await referenceEnumeration(session, dataTypeNodeId);
32
+ const jtype = jtypeImport.name;
33
+ importCollect && importCollect(jtypeImport);
34
+ return { dataType, jtype };
35
+ }
36
+
37
+ if (dataType === DataType.ExtensionObject) {
38
+ const jtypeImport = await referenceExtensionObject(session, dataTypeNodeId);
39
+ const jtype = jtypeImport.name;
40
+ importCollect && importCollect(jtypeImport);
41
+ return { dataType, jtype };
42
+ }
43
+ const referenceBasicType = (name: string): string => {
44
+ const t = { name, namespace: -1, module: "BasicType" };
45
+ importCollect && importCollect(t);
46
+ cache.ensureImported(t);
47
+ return t.name;
48
+ };
49
+
50
+ switch (dataType) {
51
+ case DataType.Null:
52
+ return { dataType: DataType.Variant, jtype: referenceBasicType("VariantOptions") };
53
+ case DataType.Boolean:
54
+ return { dataType, jtype: "boolean" };
55
+ case DataType.Byte:
56
+ return { dataType, jtype: referenceBasicType("Byte") };
57
+ case DataType.ByteString:
58
+ return { dataType, jtype: "Buffer" };
59
+ case DataType.DataValue:
60
+ return { dataType, jtype: referenceBasicType("DataValue") };
61
+ case DataType.DateTime:
62
+ return { dataType, jtype: "Date" };
63
+ case DataType.DiagnosticInfo:
64
+ return { dataType, jtype: referenceBasicType("DiagnosticInfo") };
65
+ case DataType.Double:
66
+ return { dataType, jtype: "number" };
67
+ case DataType.Float:
68
+ return { dataType, jtype: "number" };
69
+ case DataType.Guid:
70
+ return { dataType, jtype: referenceBasicType("Guid") };
71
+ case DataType.Int16:
72
+ return { dataType, jtype: referenceBasicType("Int16") };
73
+ case DataType.Int32:
74
+ return { dataType, jtype: referenceBasicType("Int32") };
75
+ case DataType.UInt16:
76
+ return { dataType, jtype: referenceBasicType("UInt16") };
77
+ case DataType.UInt32:
78
+ return { dataType, jtype: referenceBasicType("UInt32") };
79
+ case DataType.UInt64:
80
+ return { dataType, jtype: referenceBasicType("UInt64") };
81
+ case DataType.Int64:
82
+ return { dataType, jtype: referenceBasicType("Int64") };
83
+ case DataType.LocalizedText:
84
+ return { dataType, jtype: referenceBasicType("LocalizedText") };
85
+ case DataType.NodeId:
86
+ return { dataType, jtype: referenceBasicType("NodeId") };
87
+ case DataType.ExpandedNodeId:
88
+ return { dataType, jtype: referenceBasicType("ExpandedNodeId") };
89
+ case DataType.QualifiedName:
90
+ return { dataType, jtype: referenceBasicType("QualifiedName") };
91
+ case DataType.SByte:
92
+ return { dataType, jtype: referenceBasicType("SByte") };
93
+ case DataType.StatusCode:
94
+ return { dataType, jtype: referenceBasicType("StatusCode") };
95
+ case DataType.String:
96
+ return { dataType, jtype: referenceBasicType("UAString") };
97
+ case DataType.Variant:
98
+ return { dataType, jtype: referenceBasicType("Variant") };
99
+ case DataType.XmlElement:
100
+ return { dataType, jtype: referenceBasicType("String") };
101
+ default:
102
+ throw new Error("Unsupported " + dataType + " " + DataType[dataType]);
103
+ }
104
+ }
@@ -0,0 +1,55 @@
1
+ import { lowerFirstLetter } from "node-opcua-utils";
2
+ import * as wrap from "wordwrap";
3
+
4
+ const wrapText = wrap(0, 50);
5
+
6
+ export function toComment(prefix: string, description: string) {
7
+ const d = wrapText(description);
8
+ return d
9
+ .split("\n")
10
+ .map((x) => prefix + x)
11
+ .join("\n");
12
+ }
13
+
14
+ // to avoid clashes
15
+ export function toJavascritPropertyName(childName: string, { ignoreConflictingName }: { ignoreConflictingName: boolean }): string {
16
+ childName = lowerFirstLetter(childName);
17
+
18
+ if (ignoreConflictingName) {
19
+ if (childName === "namespaceUri") {
20
+ childName = "$namespaceUri";
21
+ }
22
+ if (childName === "rolePermissions") {
23
+ childName = "$rolePermissions";
24
+ }
25
+ if (childName === "displayName") {
26
+ childName = "$displayName";
27
+ }
28
+ if (childName === "eventNotifier") {
29
+ childName = "$eventNotifier";
30
+ }
31
+ if (childName === "description") {
32
+ childName = "$description";
33
+ }
34
+ if (childName === "decode") {
35
+ childName = "$decode";
36
+ }
37
+ if (childName === "encode") {
38
+ childName = "$encode";
39
+ }
40
+ }
41
+ return childName.replace(/</g, "$").replace(/>/g, "$").replace(/ |\./g, "_").replace(/#/g, "_");
42
+ }
43
+
44
+ export function quotifyIfNecessary(s: string): string {
45
+ if (s.match(/(^[^a-zA-Z])|([^a-zA-Z_0-9])/)) {
46
+ return `"${s}"`;
47
+ }
48
+ if (s === "nodeClass") {
49
+ return `["$nodeClass"]`;
50
+ }
51
+ return s;
52
+ }
53
+
54
+ export const f2 = (str: string) => str.padEnd(50, "-");
55
+ export const f1 = (str: string) => str.padEnd(50, " ");
@@ -7,7 +7,10 @@
7
7
  "incremental": true
8
8
  },
9
9
  "references": [
10
- ],
10
+ {
11
+ "path": "../node-opcua-debug"
12
+ }
13
+ ],
11
14
  "exclude": ["node_modules", "dist", "test", "source/*"],
12
15
  "include": ["./tmp/node-opcua-nodeset*/index.d.ts"]
13
16
  }