node-opcua-convert-nodeset-to-javascript 2.76.2 → 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.
- package/dist/_dataType.d.ts +10 -0
- package/dist/_dataType.js +153 -0
- package/dist/_dataType.js.map +1 -0
- package/dist/convert_to_typescript.d.ts +0 -5
- package/dist/convert_to_typescript.js +21 -255
- package/dist/convert_to_typescript.js.map +1 -1
- package/dist/main.js +5 -2
- package/dist/main.js.map +1 -1
- package/dist/official_namespaces.js.map +1 -1
- package/dist/private/cache.d.ts +2 -0
- package/dist/private/cache.js +18 -3
- package/dist/private/cache.js.map +1 -1
- package/dist/private/get_corresponding_data_type.d.ts +14 -0
- package/dist/private/get_corresponding_data_type.js +104 -0
- package/dist/private/get_corresponding_data_type.js.map +1 -0
- package/dist/utils2.d.ts +7 -0
- package/dist/utils2.js +58 -0
- package/dist/utils2.js.map +1 -0
- package/package.json +19 -18
- package/source/_dataType.ts +164 -0
- package/source/convert_to_typescript.ts +4 -252
- package/source/main.ts +5 -2
- package/source/official_namespaces.ts +0 -1
- package/source/private/cache.ts +24 -7
- package/source/private/get_corresponding_data_type.ts +104 -0
- package/source/utils2.ts +55 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NodeId } from "node-opcua-nodeid";
|
|
2
|
+
import { IBasicSession } from "node-opcua-pseudo-session";
|
|
3
|
+
import { LineFile } from "node-opcua-utils";
|
|
4
|
+
import { Type } from "./convert_to_typescript";
|
|
5
|
+
import { Cache } from "./private/cache";
|
|
6
|
+
export declare function _exportDataTypeToTypescript(session: IBasicSession, nodeId: NodeId, cache: Cache, f?: LineFile): Promise<{
|
|
7
|
+
type: Type;
|
|
8
|
+
content: string;
|
|
9
|
+
typeName: string;
|
|
10
|
+
}>;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports._exportDataTypeToTypescript = void 0;
|
|
13
|
+
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
14
|
+
const node_opcua_types_1 = require("node-opcua-types");
|
|
15
|
+
const node_opcua_utils_1 = require("node-opcua-utils");
|
|
16
|
+
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
17
|
+
const private_stuff_1 = require("./private-stuff");
|
|
18
|
+
const cache_1 = require("./private/cache");
|
|
19
|
+
const get_corresponding_data_type_1 = require("./private/get_corresponding_data_type");
|
|
20
|
+
const utils2_1 = require("./utils2");
|
|
21
|
+
// eslint-disable-next-line max-statements, complexity
|
|
22
|
+
function _exportDataTypeToTypescript(session, nodeId, cache, f) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const importCollect = undefined;
|
|
25
|
+
const referenceBasicType = (name) => {
|
|
26
|
+
const t = { name, namespace: -1, module: "BasicType" };
|
|
27
|
+
importCollect && importCollect(t);
|
|
28
|
+
cache.ensureImported(t);
|
|
29
|
+
return t.name;
|
|
30
|
+
};
|
|
31
|
+
f = f || new node_opcua_utils_1.LineFile();
|
|
32
|
+
const importCollector = (i) => {
|
|
33
|
+
cache.ensureImported(i);
|
|
34
|
+
};
|
|
35
|
+
const nodeClass = node_opcua_data_model_1.NodeClass.DataType;
|
|
36
|
+
const description = yield (0, private_stuff_1.getDescription)(session, nodeId);
|
|
37
|
+
const definition = yield (0, private_stuff_1.getDefinition)(session, nodeId);
|
|
38
|
+
const browseName = yield (0, private_stuff_1.getBrowseName)(session, nodeId);
|
|
39
|
+
const isAbstract = yield (0, private_stuff_1.getIsAbstract)(session, nodeId);
|
|
40
|
+
const interfaceImport = (0, private_stuff_1.makeTypeNameNew)(nodeClass, definition, browseName);
|
|
41
|
+
const interfaceName = interfaceImport.name;
|
|
42
|
+
const superType = yield (0, private_stuff_1.getSubtypeNodeId)(session, nodeId);
|
|
43
|
+
const baseInterfaceImport = (0, private_stuff_1.makeTypeNameNew)(nodeClass, definition, superType.browseName);
|
|
44
|
+
cache.ensureImported(baseInterfaceImport);
|
|
45
|
+
const baseInterfaceName = baseInterfaceImport.name;
|
|
46
|
+
// f.write(superType.toString());
|
|
47
|
+
f.write(`/**`);
|
|
48
|
+
if (description.text) {
|
|
49
|
+
f.write((0, utils2_1.toComment)(" * ", description.text || ""));
|
|
50
|
+
f.write(` *`);
|
|
51
|
+
}
|
|
52
|
+
f.write(` * | |${(0, utils2_1.f1)(" ")}|`);
|
|
53
|
+
f.write(` * |-----------|${(0, utils2_1.f2)("-")}|`);
|
|
54
|
+
f.write(` * | namespace |${(0, utils2_1.f1)(cache.namespace[nodeId.namespace].namespaceUri)}|`);
|
|
55
|
+
f.write(` * | nodeClass |${(0, utils2_1.f1)(node_opcua_data_model_1.NodeClass[nodeClass])}|`);
|
|
56
|
+
f.write(` * | name |${(0, utils2_1.f1)(browseName.toString())}|`);
|
|
57
|
+
f.write(` * | isAbstract|${(0, utils2_1.f1)(isAbstract.toString())}|`);
|
|
58
|
+
f.write(` */`);
|
|
59
|
+
let type = "basic";
|
|
60
|
+
if (definition instanceof node_opcua_types_1.EnumDefinition) {
|
|
61
|
+
type = "enum";
|
|
62
|
+
f.write(`export enum ${interfaceName} {`);
|
|
63
|
+
for (const field of definition.fields) {
|
|
64
|
+
if (field.description.text) {
|
|
65
|
+
f.write(` /**`);
|
|
66
|
+
f.write((0, utils2_1.toComment)(" * ", field.description.text || ""));
|
|
67
|
+
f.write(` */`);
|
|
68
|
+
}
|
|
69
|
+
f.write(` ${(0, utils2_1.quotifyIfNecessary)(field.name)} = ${field.value[1]},`);
|
|
70
|
+
}
|
|
71
|
+
f.write(`}`);
|
|
72
|
+
}
|
|
73
|
+
else if (definition instanceof node_opcua_types_1.StructureDefinition) {
|
|
74
|
+
if (baseInterfaceName === "DTUnion") {
|
|
75
|
+
type = "structure";
|
|
76
|
+
for (let i = 0; i < definition.fields.length; i++) {
|
|
77
|
+
f.write(`export interface ${interfaceName}_${i} extends ${baseInterfaceName} {`);
|
|
78
|
+
for (let j = 0; j < definition.fields.length; j++) {
|
|
79
|
+
const field = definition.fields[j];
|
|
80
|
+
const fieldName = (0, utils2_1.toJavascritPropertyName)(field.name, { ignoreConflictingName: false });
|
|
81
|
+
if (j === i) {
|
|
82
|
+
yield outputStructureField(f, field);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
f.write(` ${(0, utils2_1.quotifyIfNecessary)(fieldName)}?: never`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
f.write(`}`);
|
|
89
|
+
}
|
|
90
|
+
f.write(`export type ${interfaceName} = `);
|
|
91
|
+
for (let i = 0; i < definition.fields.length; i++) {
|
|
92
|
+
f.write(` | ${interfaceName}_${i}`);
|
|
93
|
+
}
|
|
94
|
+
f.write(` ;`);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
type = "structure";
|
|
98
|
+
if (!definition.fields.length && interfaceName !== "DTStructure") {
|
|
99
|
+
f.write(`export type ${interfaceName} = ${baseInterfaceName};`);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
if (interfaceName === "DTStructure") {
|
|
103
|
+
f.write(`export interface ${interfaceName} {`);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
f.write(`export interface ${interfaceName} extends ${baseInterfaceName} {`);
|
|
107
|
+
}
|
|
108
|
+
for (const field of definition.fields) {
|
|
109
|
+
yield outputStructureField(f, field);
|
|
110
|
+
}
|
|
111
|
+
f.write(`}`);
|
|
112
|
+
//
|
|
113
|
+
referenceBasicType("ExtensionObject");
|
|
114
|
+
// ache.ensureImported({ module: "BasicType", name: "ExtensionObject", namespace: 0 });
|
|
115
|
+
// interface TighteningResultOptions extends Partial<DTTighteningResult> {}
|
|
116
|
+
// interface TighteningResult extends ExtensionObject, DTTighteningResult {}
|
|
117
|
+
const full = (0, cache_1.makeName2)(interfaceName);
|
|
118
|
+
// filter issue with UDTOpticalVerifierScanResult that has a decode:Uint32 conflicting with the ExtensionObject decode method
|
|
119
|
+
const toAvoid = ["decode", "encode"];
|
|
120
|
+
const collidingNames = definition
|
|
121
|
+
.fields.map((a) => (0, utils2_1.toJavascritPropertyName)(a.name, { ignoreConflictingName: false }))
|
|
122
|
+
.filter((d) => toAvoid.indexOf(d.toLowerCase()) !== -1);
|
|
123
|
+
const adpatedIntefaceName = collidingNames.length === 0
|
|
124
|
+
? interfaceName
|
|
125
|
+
: `Omit<${interfaceName},${collidingNames.map((a) => `"${a}"`).join(",")}>`;
|
|
126
|
+
f.write(`export interface ${full} extends ExtensionObject, ${adpatedIntefaceName} {};`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
type = "basic";
|
|
132
|
+
f.write(`// NO DEFINITION`);
|
|
133
|
+
f.write(`export type ${interfaceName} = ${baseInterfaceName};`);
|
|
134
|
+
// throw new Error("Invalid " + definition?.constructor.name);
|
|
135
|
+
}
|
|
136
|
+
return { type, content: f.toString(), typeName: interfaceName };
|
|
137
|
+
function outputStructureField(f, field) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
const fieldName = (0, utils2_1.toJavascritPropertyName)(field.name, { ignoreConflictingName: false });
|
|
140
|
+
// special case ! fieldName=
|
|
141
|
+
if (field.description.text) {
|
|
142
|
+
f.write(` /** ${field.description.text}*/`);
|
|
143
|
+
}
|
|
144
|
+
const opt = field.isOptional ? "?" : "";
|
|
145
|
+
const arrayMarker = field.valueRank >= 1 ? "[]" : "";
|
|
146
|
+
const { dataType, jtype } = yield (0, get_corresponding_data_type_1.getCorrepondingJavascriptType)(session, field.dataType, cache, importCollector);
|
|
147
|
+
f.write(` ${(0, utils2_1.quotifyIfNecessary)(fieldName)}${opt}: ${jtype}${arrayMarker}; // ${node_opcua_variant_1.DataType[dataType]} ${field.dataType.toString()}`);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
exports._exportDataTypeToTypescript = _exportDataTypeToTypescript;
|
|
153
|
+
//# sourceMappingURL=_dataType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dataType.js","sourceRoot":"","sources":["../source/_dataType.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAAkD;AAGlD,uDAAuF;AACvF,uDAA4C;AAC5C,2DAA8C;AAE9C,mDAQyB;AACzB,2CAAmD;AACnD,uFAAsF;AACtF,qCAA0F;AAE1F,sDAAsD;AACtD,SAAsB,2BAA2B,CAC7C,OAAsB,EACtB,MAAc,EACd,KAAY,EACZ,CAAY;;QAEZ,MAAM,aAAa,GAAQ,SAAS,CAAC;QACrC,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAAU,EAAE;YAChD,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;YACvD,aAAa,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC;YAClC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;YACxB,OAAO,CAAC,CAAC,IAAI,CAAC;QAClB,CAAC,CAAC;QAEF,CAAC,GAAG,CAAC,IAAI,IAAI,2BAAQ,EAAE,CAAC;QAExB,MAAM,eAAe,GAAG,CAAC,CAAS,EAAE,EAAE;YAClC,KAAK,C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GAAG,GAAG,KAAK,KAAK,GAAG,WAAW,QAC5D,6BAAQ,CAAC,QAAQ,CACrB,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAClC,CAAC;YACN,CAAC;SAAA;IACL,CAAC;CAAA;AA9ID,kEA8IC"}
|
|
@@ -86,11 +86,6 @@ interface ClassDefinitionB {
|
|
|
86
86
|
export declare function extractClassMemberDef(session: IBasicSession, nodeId: NodeId, parentDef: ClassDefinitionB, cache: Cache): Promise<ClassMember>;
|
|
87
87
|
export declare function findUsedImport(namespaceIndex: number, cache: Cache): string[];
|
|
88
88
|
export declare type Type = "enum" | "basic" | "structure" | "ua";
|
|
89
|
-
export declare function _exportDataTypeToTypescript(session: IBasicSession, nodeId: NodeId, cache: Cache, f?: LineFile): Promise<{
|
|
90
|
-
type: Type;
|
|
91
|
-
content: string;
|
|
92
|
-
typeName: string;
|
|
93
|
-
}>;
|
|
94
89
|
/**
|
|
95
90
|
* nodeId : a DataType, ReferenceType,AObjectType, VariableType node
|
|
96
91
|
*/
|
|
@@ -9,10 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.convertTypeToTypescript = exports._convertTypeToTypescript = exports.
|
|
12
|
+
exports.convertTypeToTypescript = exports._convertTypeToTypescript = exports.findUsedImport = exports.extractClassMemberDef = exports.checkIfShouldExposeInnerDefinition = exports.findClassMember = exports.extractClassDefinition = exports.makeTypeName2 = exports.convertDataTypeToTypescript = void 0;
|
|
13
13
|
/* eslint-disable max-depth */
|
|
14
14
|
const chalk = require("chalk");
|
|
15
|
-
const wrap = require("wordwrap");
|
|
16
15
|
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
17
16
|
const node_opcua_types_1 = require("node-opcua-types");
|
|
18
17
|
const node_opcua_utils_1 = require("node-opcua-utils");
|
|
@@ -22,11 +21,11 @@ const node_opcua_debug_1 = require("node-opcua-debug");
|
|
|
22
21
|
const utils_1 = require("./private/utils");
|
|
23
22
|
const cache_1 = require("./private/cache");
|
|
24
23
|
const to_filename_1 = require("./private/to_filename");
|
|
24
|
+
const utils2_1 = require("./utils2");
|
|
25
|
+
const _dataType_1 = require("./_dataType");
|
|
26
|
+
const get_corresponding_data_type_1 = require("./private/get_corresponding_data_type");
|
|
25
27
|
const warningLog = (0, node_opcua_debug_1.make_warningLog)("typescript");
|
|
26
28
|
const doDebug = false;
|
|
27
|
-
const wrapText = wrap(0, 50);
|
|
28
|
-
const f2 = (str) => str.padEnd(50, "-");
|
|
29
|
-
const f1 = (str) => str.padEnd(50, " ");
|
|
30
29
|
const baseExtension = "_Base";
|
|
31
30
|
const m0 = !doDebug ? "" : `/* 0 */`;
|
|
32
31
|
const m1 = !doDebug ? "" : `/* 1 */`;
|
|
@@ -57,123 +56,6 @@ function convertDataTypeToTypescript(session, dataTypeId) {
|
|
|
57
56
|
});
|
|
58
57
|
}
|
|
59
58
|
exports.convertDataTypeToTypescript = convertDataTypeToTypescript;
|
|
60
|
-
// to avoid clashes
|
|
61
|
-
function toJavascritPropertyName(childName, { ignoreConflictingName }) {
|
|
62
|
-
childName = (0, node_opcua_utils_1.lowerFirstLetter)(childName);
|
|
63
|
-
if (ignoreConflictingName) {
|
|
64
|
-
if (childName === "namespaceUri") {
|
|
65
|
-
childName = "$namespaceUri";
|
|
66
|
-
}
|
|
67
|
-
if (childName === "rolePermissions") {
|
|
68
|
-
childName = "$rolePermissions";
|
|
69
|
-
}
|
|
70
|
-
if (childName === "displayName") {
|
|
71
|
-
childName = "$displayName";
|
|
72
|
-
}
|
|
73
|
-
if (childName === "eventNotifier") {
|
|
74
|
-
childName = "$eventNotifier";
|
|
75
|
-
}
|
|
76
|
-
if (childName === "description") {
|
|
77
|
-
childName = "$description";
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return childName.replace(/</g, "$").replace(/>/g, "$").replace(/ |\./g, "_").replace(/#/g, "_");
|
|
81
|
-
}
|
|
82
|
-
function quotifyIfNecessary(s) {
|
|
83
|
-
if (s.match(/(^[^a-zA-Z])|([^a-zA-Z_0-9])/)) {
|
|
84
|
-
return `"${s}"`;
|
|
85
|
-
}
|
|
86
|
-
if (s === "nodeClass") {
|
|
87
|
-
return `["$nodeClass"]`;
|
|
88
|
-
}
|
|
89
|
-
return s;
|
|
90
|
-
}
|
|
91
|
-
function getCorrepondingJavascriptType2(session, nodeId, dataTypeNodeId, cache, importCollect) {
|
|
92
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
const q = yield getCorrepondingJavascriptType(session, dataTypeNodeId, cache, importCollect);
|
|
94
|
-
const valueRank = yield (0, utils_1.getValueRank)(session, nodeId);
|
|
95
|
-
return { dataType: q.dataType, jtype: q.jtype + (valueRank >= 1 ? "[]" : "") };
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
// eslint-disable-next-line complexity
|
|
99
|
-
function getCorrepondingJavascriptType(session, dataTypeNodeId, cache, importCollect) {
|
|
100
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
const { dataType, enumerationType } = yield (0, utils_1._convertNodeIdToDataTypeAsync)(session, dataTypeNodeId);
|
|
102
|
-
if (enumerationType) {
|
|
103
|
-
// we have a enmeration name here
|
|
104
|
-
const jtypeImport = yield (0, cache_1.referenceEnumeration)(session, dataTypeNodeId);
|
|
105
|
-
const jtype = jtypeImport.name;
|
|
106
|
-
importCollect && importCollect(jtypeImport);
|
|
107
|
-
return { dataType, jtype };
|
|
108
|
-
}
|
|
109
|
-
if (dataType === node_opcua_variant_1.DataType.ExtensionObject) {
|
|
110
|
-
const jtypeImport = yield (0, cache_1.referenceExtensionObject)(session, dataTypeNodeId);
|
|
111
|
-
const jtype = jtypeImport.name;
|
|
112
|
-
importCollect && importCollect(jtypeImport);
|
|
113
|
-
return { dataType, jtype };
|
|
114
|
-
}
|
|
115
|
-
const referenceBasicType = (name) => {
|
|
116
|
-
const t = { name, namespace: -1, module: "BasicType" };
|
|
117
|
-
importCollect && importCollect(t);
|
|
118
|
-
cache.ensureImported(t);
|
|
119
|
-
return t.name;
|
|
120
|
-
};
|
|
121
|
-
switch (dataType) {
|
|
122
|
-
case node_opcua_variant_1.DataType.Null:
|
|
123
|
-
return { dataType, jtype: "undefined" };
|
|
124
|
-
case node_opcua_variant_1.DataType.Boolean:
|
|
125
|
-
return { dataType, jtype: "boolean" };
|
|
126
|
-
case node_opcua_variant_1.DataType.Byte:
|
|
127
|
-
return { dataType, jtype: referenceBasicType("Byte") };
|
|
128
|
-
case node_opcua_variant_1.DataType.ByteString:
|
|
129
|
-
return { dataType, jtype: "Buffer" };
|
|
130
|
-
case node_opcua_variant_1.DataType.DataValue:
|
|
131
|
-
return { dataType, jtype: referenceBasicType("DataValue") };
|
|
132
|
-
case node_opcua_variant_1.DataType.DateTime:
|
|
133
|
-
return { dataType, jtype: "Date" };
|
|
134
|
-
case node_opcua_variant_1.DataType.DiagnosticInfo:
|
|
135
|
-
return { dataType, jtype: referenceBasicType("DiagnosticInfo") };
|
|
136
|
-
case node_opcua_variant_1.DataType.Double:
|
|
137
|
-
return { dataType, jtype: "number" };
|
|
138
|
-
case node_opcua_variant_1.DataType.Float:
|
|
139
|
-
return { dataType, jtype: "number" };
|
|
140
|
-
case node_opcua_variant_1.DataType.Guid:
|
|
141
|
-
return { dataType, jtype: referenceBasicType("Guid") };
|
|
142
|
-
case node_opcua_variant_1.DataType.Int16:
|
|
143
|
-
return { dataType, jtype: referenceBasicType("Int16") };
|
|
144
|
-
case node_opcua_variant_1.DataType.Int32:
|
|
145
|
-
return { dataType, jtype: referenceBasicType("Int32") };
|
|
146
|
-
case node_opcua_variant_1.DataType.UInt16:
|
|
147
|
-
return { dataType, jtype: referenceBasicType("UInt16") };
|
|
148
|
-
case node_opcua_variant_1.DataType.UInt32:
|
|
149
|
-
return { dataType, jtype: referenceBasicType("UInt32") };
|
|
150
|
-
case node_opcua_variant_1.DataType.UInt64:
|
|
151
|
-
return { dataType, jtype: referenceBasicType("UInt64") };
|
|
152
|
-
case node_opcua_variant_1.DataType.Int64:
|
|
153
|
-
return { dataType, jtype: referenceBasicType("Int64") };
|
|
154
|
-
case node_opcua_variant_1.DataType.LocalizedText:
|
|
155
|
-
return { dataType, jtype: referenceBasicType("LocalizedText") };
|
|
156
|
-
case node_opcua_variant_1.DataType.NodeId:
|
|
157
|
-
return { dataType, jtype: referenceBasicType("NodeId") };
|
|
158
|
-
case node_opcua_variant_1.DataType.ExpandedNodeId:
|
|
159
|
-
return { dataType, jtype: referenceBasicType("ExpandedNodeId") };
|
|
160
|
-
case node_opcua_variant_1.DataType.QualifiedName:
|
|
161
|
-
return { dataType, jtype: referenceBasicType("QualifiedName") };
|
|
162
|
-
case node_opcua_variant_1.DataType.SByte:
|
|
163
|
-
return { dataType, jtype: referenceBasicType("SByte") };
|
|
164
|
-
case node_opcua_variant_1.DataType.StatusCode:
|
|
165
|
-
return { dataType, jtype: referenceBasicType("StatusCode") };
|
|
166
|
-
case node_opcua_variant_1.DataType.String:
|
|
167
|
-
return { dataType, jtype: referenceBasicType("UAString") };
|
|
168
|
-
case node_opcua_variant_1.DataType.Variant:
|
|
169
|
-
return { dataType, jtype: referenceBasicType("Variant") };
|
|
170
|
-
case node_opcua_variant_1.DataType.XmlElement:
|
|
171
|
-
return { dataType, jtype: referenceBasicType("String") };
|
|
172
|
-
default:
|
|
173
|
-
throw new Error("Unsupported " + dataType + " " + node_opcua_variant_1.DataType[dataType]);
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
59
|
function makeTypeName2(nodeClass, browseName, suffix) {
|
|
178
60
|
(0, node_opcua_assert_1.default)(browseName);
|
|
179
61
|
if (nodeClass === node_opcua_data_model_1.NodeClass.Method) {
|
|
@@ -208,7 +90,7 @@ function extractClassDefinition(session, nodeId, cache) {
|
|
|
208
90
|
extraImports.push(i);
|
|
209
91
|
cache.ensureImported(i);
|
|
210
92
|
};
|
|
211
|
-
const { jtype } = yield getCorrepondingJavascriptType2(session, nodeId, dataTypeNodeId, cache, importCollector);
|
|
93
|
+
const { jtype } = yield (0, get_corresponding_data_type_1.getCorrepondingJavascriptType2)(session, nodeId, dataTypeNodeId, cache, importCollector);
|
|
212
94
|
dataTypeName = jtype; // with decoration
|
|
213
95
|
if (!(dataTypeNodeId === null || dataTypeNodeId === void 0 ? void 0 : dataTypeNodeId.isEmpty())) {
|
|
214
96
|
// "DT" + (await getBrowseName(session, dataTypeNodeId!))?.name! || "";
|
|
@@ -362,7 +244,7 @@ function _extractLocalMembers(session, parent, classMember, cache) {
|
|
|
362
244
|
for (const child of classMember.children) {
|
|
363
245
|
const nodeId = child.nodeId;
|
|
364
246
|
const browseName = yield (0, utils_1.getBrowseName)(session, nodeId);
|
|
365
|
-
const name = toJavascritPropertyName(browseName.name, { ignoreConflictingName: true });
|
|
247
|
+
const name = (0, utils2_1.toJavascritPropertyName)(browseName.name, { ignoreConflictingName: true });
|
|
366
248
|
const description = yield (0, utils_1.getDescription)(session, nodeId);
|
|
367
249
|
const modellingRule = yield (0, utils_1.getModellingRule)(session, nodeId);
|
|
368
250
|
const isOptional = sameInBaseClassIsMandatory(parent, browseName) ? false : modellingRule === "Optional";
|
|
@@ -408,7 +290,7 @@ function extractVariableExtra(session, nodeId, cache, classMember) {
|
|
|
408
290
|
const nodeClass = yield (0, utils_1.getNodeClass)(session, nodeId);
|
|
409
291
|
if (nodeClass === node_opcua_data_model_1.NodeClass.Variable) {
|
|
410
292
|
const dataTypeNodeId = yield (0, utils_1.getDataTypeNodeId)(session, nodeId);
|
|
411
|
-
const { dataType, jtype } = yield getCorrepondingJavascriptType2(session, nodeId, dataTypeNodeId, cache, importCollector);
|
|
293
|
+
const { dataType, jtype } = yield (0, get_corresponding_data_type_1.getCorrepondingJavascriptType2)(session, nodeId, dataTypeNodeId, cache, importCollector);
|
|
412
294
|
cache && cache.referenceBasicType("DataType");
|
|
413
295
|
importCollector({ name: "DataType", namespace: -1, module: "BasicType" });
|
|
414
296
|
const t = isUnspecifiedDataType((_a = classMember.classDef) === null || _a === void 0 ? void 0 : _a.dataType);
|
|
@@ -451,7 +333,7 @@ function extractClassMemberDef(session, nodeId, parentDef, cache) {
|
|
|
451
333
|
return __awaiter(this, void 0, void 0, function* () {
|
|
452
334
|
const nodeClass = yield (0, utils_1.getNodeClass)(session, nodeId);
|
|
453
335
|
const browseName = yield (0, utils_1.getBrowseName)(session, nodeId);
|
|
454
|
-
const name = toJavascritPropertyName(browseName.name, { ignoreConflictingName: true });
|
|
336
|
+
const name = (0, utils2_1.toJavascritPropertyName)(browseName.name, { ignoreConflictingName: true });
|
|
455
337
|
if (nodeClass !== node_opcua_data_model_1.NodeClass.Method && nodeClass !== node_opcua_data_model_1.NodeClass.Object && nodeClass !== node_opcua_data_model_1.NodeClass.Variable) {
|
|
456
338
|
throw new Error("Invalid property " + node_opcua_data_model_1.NodeClass[nodeClass] + " " + (browseName === null || browseName === void 0 ? void 0 : browseName.toString()) + " " + nodeId.toString());
|
|
457
339
|
}
|
|
@@ -589,14 +471,14 @@ function dumpChildren(padding, children, f, cache) {
|
|
|
589
471
|
continue;
|
|
590
472
|
}
|
|
591
473
|
cache.ensureImported(childType);
|
|
592
|
-
const adjustedName = toJavascritPropertyName(name, { ignoreConflictingName: true });
|
|
474
|
+
const adjustedName = (0, utils2_1.toJavascritPropertyName)(name, { ignoreConflictingName: true });
|
|
593
475
|
if (description.text) {
|
|
594
476
|
f.write(`${padding}/**`);
|
|
595
477
|
f.write(`${padding} * ${name || ""}`);
|
|
596
|
-
f.write(toComment(`${padding} * `, description.text || ""));
|
|
478
|
+
f.write((0, utils2_1.toComment)(`${padding} * `, description.text || ""));
|
|
597
479
|
f.write(`${padding} */`);
|
|
598
480
|
}
|
|
599
|
-
f.write(`${padding}${quotifyIfNecessary(adjustedName)}${isOptional ? "?" : ""}: ${childType.name}${suffixInstantiate || ""};`);
|
|
481
|
+
f.write(`${padding}${(0, utils2_1.quotifyIfNecessary)(adjustedName)}${isOptional ? "?" : ""}: ${childType.name}${suffixInstantiate || ""};`);
|
|
600
482
|
}
|
|
601
483
|
}
|
|
602
484
|
// now from other namespace
|
|
@@ -663,122 +545,6 @@ function dumpUsedExport(currentType, namespaceIndex, cache, f) {
|
|
|
663
545
|
}
|
|
664
546
|
return f.toString();
|
|
665
547
|
}
|
|
666
|
-
function toComment(prefix, description) {
|
|
667
|
-
const d = wrapText(description);
|
|
668
|
-
return d
|
|
669
|
-
.split("\n")
|
|
670
|
-
.map((x) => prefix + x)
|
|
671
|
-
.join("\n");
|
|
672
|
-
}
|
|
673
|
-
// eslint-disable-next-line max-statements, complexity
|
|
674
|
-
function _exportDataTypeToTypescript(session, nodeId, cache, f) {
|
|
675
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
676
|
-
f = f || new node_opcua_utils_1.LineFile();
|
|
677
|
-
const importCollector = (i) => {
|
|
678
|
-
cache.ensureImported(i);
|
|
679
|
-
};
|
|
680
|
-
const nodeClass = node_opcua_data_model_1.NodeClass.DataType;
|
|
681
|
-
const description = yield (0, utils_1.getDescription)(session, nodeId);
|
|
682
|
-
const definition = yield (0, utils_1.getDefinition)(session, nodeId);
|
|
683
|
-
const browseName = yield (0, utils_1.getBrowseName)(session, nodeId);
|
|
684
|
-
const isAbstract = yield (0, utils_1.getIsAbstract)(session, nodeId);
|
|
685
|
-
const interfaceImport = (0, cache_1.makeTypeNameNew)(nodeClass, definition, browseName);
|
|
686
|
-
const interfaceName = interfaceImport.name;
|
|
687
|
-
const superType = yield (0, utils_1.getSubtypeNodeId)(session, nodeId);
|
|
688
|
-
const baseInterfaceImport = (0, cache_1.makeTypeNameNew)(nodeClass, definition, superType.browseName);
|
|
689
|
-
cache.ensureImported(baseInterfaceImport);
|
|
690
|
-
const baseInterfaceName = baseInterfaceImport.name;
|
|
691
|
-
// f.write(superType.toString());
|
|
692
|
-
f.write(`/**`);
|
|
693
|
-
if (description.text) {
|
|
694
|
-
f.write(toComment(" * ", description.text || ""));
|
|
695
|
-
f.write(` *`);
|
|
696
|
-
}
|
|
697
|
-
f.write(` * | |${f1(" ")}|`);
|
|
698
|
-
f.write(` * |-----------|${f2("-")}|`);
|
|
699
|
-
f.write(` * | namespace |${f1(cache.namespace[nodeId.namespace].namespaceUri)}|`);
|
|
700
|
-
f.write(` * | nodeClass |${f1(node_opcua_data_model_1.NodeClass[nodeClass])}|`);
|
|
701
|
-
f.write(` * | name |${f1(browseName.toString())}|`);
|
|
702
|
-
f.write(` * | isAbstract|${f1(isAbstract.toString())}|`);
|
|
703
|
-
f.write(` */`);
|
|
704
|
-
let type = "basic";
|
|
705
|
-
if (definition instanceof node_opcua_types_1.EnumDefinition) {
|
|
706
|
-
type = "enum";
|
|
707
|
-
f.write(`export enum ${interfaceName} {`);
|
|
708
|
-
for (const field of definition.fields) {
|
|
709
|
-
if (field.description.text) {
|
|
710
|
-
f.write(` /**`);
|
|
711
|
-
f.write(toComment(" * ", field.description.text || ""));
|
|
712
|
-
f.write(` */`);
|
|
713
|
-
}
|
|
714
|
-
f.write(` ${quotifyIfNecessary(field.name)} = ${field.value[1]},`);
|
|
715
|
-
}
|
|
716
|
-
f.write(`}`);
|
|
717
|
-
}
|
|
718
|
-
else if (definition instanceof node_opcua_types_1.StructureDefinition) {
|
|
719
|
-
if (baseInterfaceName === "DTUnion") {
|
|
720
|
-
type = "structure";
|
|
721
|
-
for (let i = 0; i < definition.fields.length; i++) {
|
|
722
|
-
f.write(`export interface ${interfaceName}_${i} extends ${baseInterfaceName} {`);
|
|
723
|
-
for (let j = 0; j < definition.fields.length; j++) {
|
|
724
|
-
const field = definition.fields[j];
|
|
725
|
-
const fieldName = toJavascritPropertyName(field.name, { ignoreConflictingName: false });
|
|
726
|
-
if (j === i) {
|
|
727
|
-
yield outputStructureField(f, field);
|
|
728
|
-
}
|
|
729
|
-
else {
|
|
730
|
-
f.write(` ${quotifyIfNecessary(fieldName)}?: never`);
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
f.write(`}`);
|
|
734
|
-
}
|
|
735
|
-
f.write(`export type ${interfaceName} = `);
|
|
736
|
-
for (let i = 0; i < definition.fields.length; i++) {
|
|
737
|
-
f.write(` | ${interfaceName}_${i}`);
|
|
738
|
-
}
|
|
739
|
-
f.write(` ;`);
|
|
740
|
-
}
|
|
741
|
-
else {
|
|
742
|
-
type = "structure";
|
|
743
|
-
if (!definition.fields.length && interfaceName !== "DTStructure") {
|
|
744
|
-
f.write(`export type ${interfaceName} = ${baseInterfaceName};`);
|
|
745
|
-
}
|
|
746
|
-
else {
|
|
747
|
-
if (interfaceName === "DTStructure") {
|
|
748
|
-
f.write(`export interface ${interfaceName} {`);
|
|
749
|
-
}
|
|
750
|
-
else {
|
|
751
|
-
f.write(`export interface ${interfaceName} extends ${baseInterfaceName} {`);
|
|
752
|
-
}
|
|
753
|
-
for (const field of definition.fields) {
|
|
754
|
-
yield outputStructureField(f, field);
|
|
755
|
-
}
|
|
756
|
-
f.write(`}`);
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
else {
|
|
761
|
-
type = "basic";
|
|
762
|
-
f.write(`// NO DEFINITION`);
|
|
763
|
-
f.write(`export type ${interfaceName} = ${baseInterfaceName};`);
|
|
764
|
-
// throw new Error("Invalid " + definition?.constructor.name);
|
|
765
|
-
}
|
|
766
|
-
return { type, content: f.toString(), typeName: interfaceName };
|
|
767
|
-
function outputStructureField(f, field) {
|
|
768
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
769
|
-
const fieldName = toJavascritPropertyName(field.name, { ignoreConflictingName: false });
|
|
770
|
-
// special case ! fieldName=
|
|
771
|
-
if (field.description.text) {
|
|
772
|
-
f.write(`/** ${field.description.text}*/`);
|
|
773
|
-
}
|
|
774
|
-
const ar = field.valueRank >= 1 ? "[]" : "";
|
|
775
|
-
const { dataType, jtype } = yield getCorrepondingJavascriptType(session, field.dataType, cache, importCollector);
|
|
776
|
-
f.write(` ${quotifyIfNecessary(fieldName)}: ${jtype}${ar}; // ${node_opcua_variant_1.DataType[dataType]} ${field.dataType.toString()}`);
|
|
777
|
-
});
|
|
778
|
-
}
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
exports._exportDataTypeToTypescript = _exportDataTypeToTypescript;
|
|
782
548
|
function calculateChevrons(classDef, classDefDerived) {
|
|
783
549
|
const { nodeClass, dataType, dataTypeName } = classDef;
|
|
784
550
|
let chevronsDef = "";
|
|
@@ -867,7 +633,7 @@ function _convertTypeToTypescript(session, nodeId, cache, f) {
|
|
|
867
633
|
f = f || new node_opcua_utils_1.LineFile();
|
|
868
634
|
const nodeClass = yield (0, utils_1.getNodeClass)(session, nodeId);
|
|
869
635
|
if (nodeClass === node_opcua_data_model_1.NodeClass.DataType) {
|
|
870
|
-
return yield _exportDataTypeToTypescript(session, nodeId, cache, f);
|
|
636
|
+
return yield (0, _dataType_1._exportDataTypeToTypescript)(session, nodeId, cache, f);
|
|
871
637
|
}
|
|
872
638
|
const classDef = yield extractClassDefinition(session, nodeId, cache);
|
|
873
639
|
// if (classDef.browseName.toString().match(/PubSubDiagnosticsWriterGroupType/)) {
|
|
@@ -878,19 +644,19 @@ function _convertTypeToTypescript(session, nodeId, cache, f) {
|
|
|
878
644
|
// f.write(superType.toString());
|
|
879
645
|
f.write(`/**`);
|
|
880
646
|
if (description.text) {
|
|
881
|
-
f.write(toComment(" * ", description.text || ""));
|
|
647
|
+
f.write((0, utils2_1.toComment)(" * ", description.text || ""));
|
|
882
648
|
f.write(` *`);
|
|
883
649
|
}
|
|
884
|
-
f.write(` * | |${f1(" ")}|`);
|
|
885
|
-
f.write(` * |----------------|${f2("-")}|`);
|
|
886
|
-
f.write(` * |namespace |${f1(cache.namespace[nodeId.namespace].namespaceUri)}|`);
|
|
887
|
-
f.write(` * |nodeClass |${f1(node_opcua_data_model_1.NodeClass[nodeClass])}|`);
|
|
888
|
-
f.write(` * |typedDefinition |${f1(browseName.toString() + " " + nodeId.toString())}|`);
|
|
650
|
+
f.write(` * | |${(0, utils2_1.f1)(" ")}|`);
|
|
651
|
+
f.write(` * |----------------|${(0, utils2_1.f2)("-")}|`);
|
|
652
|
+
f.write(` * |namespace |${(0, utils2_1.f1)(cache.namespace[nodeId.namespace].namespaceUri)}|`);
|
|
653
|
+
f.write(` * |nodeClass |${(0, utils2_1.f1)(node_opcua_data_model_1.NodeClass[nodeClass])}|`);
|
|
654
|
+
f.write(` * |typedDefinition |${(0, utils2_1.f1)(browseName.toString() + " " + nodeId.toString())}|`);
|
|
889
655
|
if (nodeClass === node_opcua_data_model_1.NodeClass.VariableType) {
|
|
890
|
-
f.write(` * |dataType |${f1(node_opcua_variant_1.DataType[dataType])}|`);
|
|
891
|
-
f.write(` * |dataType Name |${f1(dataTypeName + " " + (dataTypeNodeId === null || dataTypeNodeId === void 0 ? void 0 : dataTypeNodeId.toString()))}|`);
|
|
656
|
+
f.write(` * |dataType |${(0, utils2_1.f1)(node_opcua_variant_1.DataType[dataType])}|`);
|
|
657
|
+
f.write(` * |dataType Name |${(0, utils2_1.f1)(dataTypeName + " " + (dataTypeNodeId === null || dataTypeNodeId === void 0 ? void 0 : dataTypeNodeId.toString()))}|`);
|
|
892
658
|
}
|
|
893
|
-
f.write(` * |isAbstract |${f1(isAbstract.toString())}|`);
|
|
659
|
+
f.write(` * |isAbstract |${(0, utils2_1.f1)(isAbstract.toString())}|`);
|
|
894
660
|
f.write(` */`);
|
|
895
661
|
// if (interfaceName.name === "UAOperationLimits") {
|
|
896
662
|
// debugger;
|