node-opcua-generator 2.70.0 → 2.71.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/factory_code_generator.d.ts +9 -9
- package/dist/factory_code_generator.js +807 -807
- package/dist/generate_extension_object_code.d.ts +1 -1
- package/dist/generate_extension_object_code.js +240 -240
- package/dist/generator.d.ts +8 -8
- package/dist/generator.js +171 -171
- package/dist/index.d.ts +5 -5
- package/dist/index.js +13 -13
- package/dist/opcua_code_generator.d.ts +1 -1
- package/dist/opcua_code_generator.js +25 -25
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +18 -18
- package/dist/utils/line_file.d.ts +6 -6
- package/dist/utils/line_file.js +25 -25
- package/dist/utils/normalize_require_file.d.ts +10 -10
- package/dist/utils/normalize_require_file.js +25 -25
- package/dist/utils/write_func.d.ts +7 -7
- package/dist/utils/write_func.js +14 -14
- package/package.json +22 -22
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function generate(filename: string, generatedTypescriptFilename: string): Promise<void>;
|
|
1
|
+
export declare function generate(filename: string, generatedTypescriptFilename: string): Promise<void>;
|
|
@@ -1,158 +1,158 @@
|
|
|
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.generate = void 0;
|
|
13
|
-
/* eslint-disable max-statements */
|
|
14
|
-
/* istanbul ignore file */
|
|
15
|
-
/**
|
|
16
|
-
* @module node-opcua-generator
|
|
17
|
-
*/
|
|
18
|
-
// tslint:disable:max-line-length
|
|
19
|
-
// tslint:disable:no-inner-declarations
|
|
20
|
-
//
|
|
21
|
-
const fs = require("fs");
|
|
22
|
-
const chalk = require("chalk");
|
|
23
|
-
// node 14 onward : import { readFile } from "fs/promises";
|
|
24
|
-
const { readFile } = fs.promises;
|
|
25
|
-
// import * as prettier from "prettier";
|
|
26
|
-
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
27
|
-
const node_opcua_constants_1 = require("node-opcua-constants");
|
|
28
|
-
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
29
|
-
const node_opcua_factory_1 = require("node-opcua-factory");
|
|
30
|
-
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
31
|
-
const node_opcua_schemas_1 = require("node-opcua-schemas");
|
|
32
|
-
const factory_code_generator_1 = require("./factory_code_generator");
|
|
33
|
-
const line_file_1 = require("./utils/line_file");
|
|
34
|
-
const write_func_1 = require("./utils/write_func");
|
|
35
|
-
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
|
|
36
|
-
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
37
|
-
const f = new line_file_1.LineFile1();
|
|
38
|
-
const write = (0, write_func_1.makeWrite)(f);
|
|
39
|
-
// eslint-disable-next-line max-statements
|
|
40
|
-
function writeEnumeratedType(enumerationSchema) {
|
|
41
|
-
const arrayValues = Object.keys(enumerationSchema.enumValues)
|
|
42
|
-
.filter((a) => a.match("[0-9]+"))
|
|
43
|
-
.map((a) => parseInt(a, 10))
|
|
44
|
-
.filter((a) => a !== 0xffffffff)
|
|
45
|
-
.sort((a, b) => a - b);
|
|
46
|
-
// determining if enum is of type FLAGS
|
|
47
|
-
const isFlaggable = arrayValues.length > 2 && arrayValues[2] === arrayValues[1] * 2 && arrayValues[3] === arrayValues[2] * 2;
|
|
48
|
-
// find min and max values (excluding
|
|
49
|
-
const minEnumValue = Math.min.apply(null, arrayValues);
|
|
50
|
-
const maxEnumValue = Math.max.apply(null, arrayValues);
|
|
51
|
-
// make sure there is a Invalid key in the enum => else insert one (but only if not flaggable)
|
|
52
|
-
const hasInvalid = Object.prototype.hasOwnProperty.call(enumerationSchema.enumValues, "Invalid");
|
|
53
|
-
if (!hasInvalid && !isFlaggable) {
|
|
54
|
-
enumerationSchema.enumValues[(enumerationSchema.enumValues.Invalid = 0xffffffff)] = "Invalid";
|
|
55
|
-
}
|
|
56
|
-
write("");
|
|
57
|
-
write(`// --------------------------------------------------------------------------------------------`);
|
|
58
|
-
write(`export enum ${enumerationSchema.name} {`);
|
|
59
|
-
const str = [];
|
|
60
|
-
const values = Object.keys(enumerationSchema.enumValues).filter((a) => a.match("[0-9]+"));
|
|
61
|
-
for (const value of values) {
|
|
62
|
-
str.push(` ${enumerationSchema.enumValues[value]} = ${value}`);
|
|
63
|
-
}
|
|
64
|
-
write(str.join(",\n"));
|
|
65
|
-
write(`}`);
|
|
66
|
-
write(`const schema${enumerationSchema.name} = {`);
|
|
67
|
-
// xx write(` documentation: "${enumerationSchema.documentation}",`);
|
|
68
|
-
write(` enumValues: ${enumerationSchema.name},`);
|
|
69
|
-
write(` flaggable: ${isFlaggable},`);
|
|
70
|
-
if (!isFlaggable) {
|
|
71
|
-
write(` minValue: ${minEnumValue},`);
|
|
72
|
-
write(` maxValue: ${maxEnumValue},`);
|
|
73
|
-
}
|
|
74
|
-
write(` name: "${enumerationSchema.name}"`);
|
|
75
|
-
write(`};`);
|
|
76
|
-
write(`function decode${enumerationSchema.name}(stream: BinaryStream, _value?: ${enumerationSchema.name}): ${enumerationSchema.name} {`);
|
|
77
|
-
if (!isFlaggable) {
|
|
78
|
-
if (enumerationSchema.lengthInBits === 16) {
|
|
79
|
-
write(` let value = stream.readUInt16() as ${enumerationSchema.name};`);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
(0, node_opcua_assert_1.assert)(enumerationSchema.lengthInBits === 32);
|
|
83
|
-
write(` let value = stream.readUInt32() as ${enumerationSchema.name};`);
|
|
84
|
-
}
|
|
85
|
-
write(` value = (value < schema${enumerationSchema.name}.minValue || value > schema${enumerationSchema.name}.maxValue) ? ${enumerationSchema.name}.Invalid : value; `);
|
|
86
|
-
write(` return value;`);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
write(` return stream.readUInt32() as ${enumerationSchema.name};`);
|
|
90
|
-
}
|
|
91
|
-
write(`}`);
|
|
92
|
-
write(`function encode${enumerationSchema.name}(value: ${enumerationSchema.name}, stream: OutputBinaryStream): void {`);
|
|
93
|
-
if (enumerationSchema.lengthInBits === 16) {
|
|
94
|
-
write(` stream.writeUInt16(value);`);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
(0, node_opcua_assert_1.assert)(enumerationSchema.lengthInBits === 32);
|
|
98
|
-
write(` stream.writeUInt32(value);`);
|
|
99
|
-
}
|
|
100
|
-
write(`}`);
|
|
101
|
-
write(`export const _enumeration${enumerationSchema.name} = registerEnumeration(schema${enumerationSchema.name});`);
|
|
102
|
-
write(`assert(_enumeration${enumerationSchema.name}.isFlaggable === ${isFlaggable});`);
|
|
103
|
-
}
|
|
104
|
-
function writeStructuredTypeWithSchema(structuredType) {
|
|
105
|
-
write(`// --------------------------------------------------------------------------------------------`);
|
|
106
|
-
write(`const schema${structuredType.name} = buildStructuredType({`);
|
|
107
|
-
write(` name: "${structuredType.name}",`);
|
|
108
|
-
write(``);
|
|
109
|
-
write(` baseType: "${structuredType.baseType}",`);
|
|
110
|
-
write(` fields: [`);
|
|
111
|
-
for (const field of structuredType.fields) {
|
|
112
|
-
write(` {`);
|
|
113
|
-
write(` name: "${field.name}",`);
|
|
114
|
-
write(``);
|
|
115
|
-
write(` fieldType: "${field.fieldType}",`);
|
|
116
|
-
if (field.isArray) {
|
|
117
|
-
write(` isArray: ${field.isArray}`);
|
|
118
|
-
}
|
|
119
|
-
// write(` /* cat = ${field.category} */`);
|
|
120
|
-
write(` },`);
|
|
121
|
-
}
|
|
122
|
-
write(` ]`);
|
|
123
|
-
write(`});`);
|
|
124
|
-
(0, factory_code_generator_1.writeStructuredType)(write, structuredType);
|
|
125
|
-
}
|
|
126
|
-
function generate(filename, generatedTypescriptFilename) {
|
|
127
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
const content = yield readFile(filename, "utf-8");
|
|
129
|
-
const idProvider = {
|
|
130
|
-
getDataTypeAndEncodingId(name) {
|
|
131
|
-
const dataType = node_opcua_constants_1.DataTypeIds[name] || 0;
|
|
132
|
-
const binEncoding = node_opcua_constants_1.ObjectIds[name + "_Encoding_DefaultBinary"] || 0;
|
|
133
|
-
const xmlEncoding = node_opcua_constants_1.ObjectIds[name + "_Encoding_DefaultXml"] || 0;
|
|
134
|
-
const jsonEncoding = node_opcua_constants_1.ObjectIds[name + "_Encoding_DefaultJson"] || 0;
|
|
135
|
-
if (dataType === undefined) {
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
const dataTypeNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, dataType, 0);
|
|
139
|
-
const binaryEncodingNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, binEncoding, 0);
|
|
140
|
-
const xmlEncodingNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, xmlEncoding, 0);
|
|
141
|
-
const jsonEncodingNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, jsonEncoding, 0);
|
|
142
|
-
const data = {
|
|
143
|
-
binaryEncodingNodeId,
|
|
144
|
-
dataTypeNodeId,
|
|
145
|
-
jsonEncodingNodeId,
|
|
146
|
-
xmlEncodingNodeId
|
|
147
|
-
};
|
|
148
|
-
if (doDebug) {
|
|
149
|
-
debugLog(" data=", chalk.cyan(name.padEnd(43, " ")), data.dataTypeNodeId.toString().padEnd(43, " "), data.binaryEncodingNodeId.toString().padEnd(43, " "));
|
|
150
|
-
}
|
|
151
|
-
return data;
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
const dataTypeFactory = new node_opcua_factory_1.DataTypeFactory([(0, node_opcua_factory_1.getStandardDataTypeFactory)()]);
|
|
155
|
-
yield (0, node_opcua_schemas_1.parseBinaryXSDAsync)(content, idProvider, dataTypeFactory);
|
|
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.generate = void 0;
|
|
13
|
+
/* eslint-disable max-statements */
|
|
14
|
+
/* istanbul ignore file */
|
|
15
|
+
/**
|
|
16
|
+
* @module node-opcua-generator
|
|
17
|
+
*/
|
|
18
|
+
// tslint:disable:max-line-length
|
|
19
|
+
// tslint:disable:no-inner-declarations
|
|
20
|
+
//
|
|
21
|
+
const fs = require("fs");
|
|
22
|
+
const chalk = require("chalk");
|
|
23
|
+
// node 14 onward : import { readFile } from "fs/promises";
|
|
24
|
+
const { readFile } = fs.promises;
|
|
25
|
+
// import * as prettier from "prettier";
|
|
26
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
27
|
+
const node_opcua_constants_1 = require("node-opcua-constants");
|
|
28
|
+
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
29
|
+
const node_opcua_factory_1 = require("node-opcua-factory");
|
|
30
|
+
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
31
|
+
const node_opcua_schemas_1 = require("node-opcua-schemas");
|
|
32
|
+
const factory_code_generator_1 = require("./factory_code_generator");
|
|
33
|
+
const line_file_1 = require("./utils/line_file");
|
|
34
|
+
const write_func_1 = require("./utils/write_func");
|
|
35
|
+
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
|
|
36
|
+
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
37
|
+
const f = new line_file_1.LineFile1();
|
|
38
|
+
const write = (0, write_func_1.makeWrite)(f);
|
|
39
|
+
// eslint-disable-next-line max-statements
|
|
40
|
+
function writeEnumeratedType(enumerationSchema) {
|
|
41
|
+
const arrayValues = Object.keys(enumerationSchema.enumValues)
|
|
42
|
+
.filter((a) => a.match("[0-9]+"))
|
|
43
|
+
.map((a) => parseInt(a, 10))
|
|
44
|
+
.filter((a) => a !== 0xffffffff)
|
|
45
|
+
.sort((a, b) => a - b);
|
|
46
|
+
// determining if enum is of type FLAGS
|
|
47
|
+
const isFlaggable = arrayValues.length > 2 && arrayValues[2] === arrayValues[1] * 2 && arrayValues[3] === arrayValues[2] * 2;
|
|
48
|
+
// find min and max values (excluding
|
|
49
|
+
const minEnumValue = Math.min.apply(null, arrayValues);
|
|
50
|
+
const maxEnumValue = Math.max.apply(null, arrayValues);
|
|
51
|
+
// make sure there is a Invalid key in the enum => else insert one (but only if not flaggable)
|
|
52
|
+
const hasInvalid = Object.prototype.hasOwnProperty.call(enumerationSchema.enumValues, "Invalid");
|
|
53
|
+
if (!hasInvalid && !isFlaggable) {
|
|
54
|
+
enumerationSchema.enumValues[(enumerationSchema.enumValues.Invalid = 0xffffffff)] = "Invalid";
|
|
55
|
+
}
|
|
56
|
+
write("");
|
|
57
|
+
write(`// --------------------------------------------------------------------------------------------`);
|
|
58
|
+
write(`export enum ${enumerationSchema.name} {`);
|
|
59
|
+
const str = [];
|
|
60
|
+
const values = Object.keys(enumerationSchema.enumValues).filter((a) => a.match("[0-9]+"));
|
|
61
|
+
for (const value of values) {
|
|
62
|
+
str.push(` ${enumerationSchema.enumValues[value]} = ${value}`);
|
|
63
|
+
}
|
|
64
|
+
write(str.join(",\n"));
|
|
65
|
+
write(`}`);
|
|
66
|
+
write(`const schema${enumerationSchema.name} = {`);
|
|
67
|
+
// xx write(` documentation: "${enumerationSchema.documentation}",`);
|
|
68
|
+
write(` enumValues: ${enumerationSchema.name},`);
|
|
69
|
+
write(` flaggable: ${isFlaggable},`);
|
|
70
|
+
if (!isFlaggable) {
|
|
71
|
+
write(` minValue: ${minEnumValue},`);
|
|
72
|
+
write(` maxValue: ${maxEnumValue},`);
|
|
73
|
+
}
|
|
74
|
+
write(` name: "${enumerationSchema.name}"`);
|
|
75
|
+
write(`};`);
|
|
76
|
+
write(`function decode${enumerationSchema.name}(stream: BinaryStream, _value?: ${enumerationSchema.name}): ${enumerationSchema.name} {`);
|
|
77
|
+
if (!isFlaggable) {
|
|
78
|
+
if (enumerationSchema.lengthInBits === 16) {
|
|
79
|
+
write(` let value = stream.readUInt16() as ${enumerationSchema.name};`);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
(0, node_opcua_assert_1.assert)(enumerationSchema.lengthInBits === 32);
|
|
83
|
+
write(` let value = stream.readUInt32() as ${enumerationSchema.name};`);
|
|
84
|
+
}
|
|
85
|
+
write(` value = (value < schema${enumerationSchema.name}.minValue || value > schema${enumerationSchema.name}.maxValue) ? ${enumerationSchema.name}.Invalid : value; `);
|
|
86
|
+
write(` return value;`);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
write(` return stream.readUInt32() as ${enumerationSchema.name};`);
|
|
90
|
+
}
|
|
91
|
+
write(`}`);
|
|
92
|
+
write(`function encode${enumerationSchema.name}(value: ${enumerationSchema.name}, stream: OutputBinaryStream): void {`);
|
|
93
|
+
if (enumerationSchema.lengthInBits === 16) {
|
|
94
|
+
write(` stream.writeUInt16(value);`);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
(0, node_opcua_assert_1.assert)(enumerationSchema.lengthInBits === 32);
|
|
98
|
+
write(` stream.writeUInt32(value);`);
|
|
99
|
+
}
|
|
100
|
+
write(`}`);
|
|
101
|
+
write(`export const _enumeration${enumerationSchema.name} = registerEnumeration(schema${enumerationSchema.name});`);
|
|
102
|
+
write(`assert(_enumeration${enumerationSchema.name}.isFlaggable === ${isFlaggable});`);
|
|
103
|
+
}
|
|
104
|
+
function writeStructuredTypeWithSchema(structuredType) {
|
|
105
|
+
write(`// --------------------------------------------------------------------------------------------`);
|
|
106
|
+
write(`const schema${structuredType.name} = buildStructuredType({`);
|
|
107
|
+
write(` name: "${structuredType.name}",`);
|
|
108
|
+
write(``);
|
|
109
|
+
write(` baseType: "${structuredType.baseType}",`);
|
|
110
|
+
write(` fields: [`);
|
|
111
|
+
for (const field of structuredType.fields) {
|
|
112
|
+
write(` {`);
|
|
113
|
+
write(` name: "${field.name}",`);
|
|
114
|
+
write(``);
|
|
115
|
+
write(` fieldType: "${field.fieldType}",`);
|
|
116
|
+
if (field.isArray) {
|
|
117
|
+
write(` isArray: ${field.isArray}`);
|
|
118
|
+
}
|
|
119
|
+
// write(` /* cat = ${field.category} */`);
|
|
120
|
+
write(` },`);
|
|
121
|
+
}
|
|
122
|
+
write(` ]`);
|
|
123
|
+
write(`});`);
|
|
124
|
+
(0, factory_code_generator_1.writeStructuredType)(write, structuredType);
|
|
125
|
+
}
|
|
126
|
+
function generate(filename, generatedTypescriptFilename) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
const content = yield readFile(filename, "utf-8");
|
|
129
|
+
const idProvider = {
|
|
130
|
+
getDataTypeAndEncodingId(name) {
|
|
131
|
+
const dataType = node_opcua_constants_1.DataTypeIds[name] || 0;
|
|
132
|
+
const binEncoding = node_opcua_constants_1.ObjectIds[name + "_Encoding_DefaultBinary"] || 0;
|
|
133
|
+
const xmlEncoding = node_opcua_constants_1.ObjectIds[name + "_Encoding_DefaultXml"] || 0;
|
|
134
|
+
const jsonEncoding = node_opcua_constants_1.ObjectIds[name + "_Encoding_DefaultJson"] || 0;
|
|
135
|
+
if (dataType === undefined) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
const dataTypeNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, dataType, 0);
|
|
139
|
+
const binaryEncodingNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, binEncoding, 0);
|
|
140
|
+
const xmlEncodingNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, xmlEncoding, 0);
|
|
141
|
+
const jsonEncodingNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, jsonEncoding, 0);
|
|
142
|
+
const data = {
|
|
143
|
+
binaryEncodingNodeId,
|
|
144
|
+
dataTypeNodeId,
|
|
145
|
+
jsonEncodingNodeId,
|
|
146
|
+
xmlEncodingNodeId
|
|
147
|
+
};
|
|
148
|
+
if (doDebug) {
|
|
149
|
+
debugLog(" data=", chalk.cyan(name.padEnd(43, " ")), data.dataTypeNodeId.toString().padEnd(43, " "), data.binaryEncodingNodeId.toString().padEnd(43, " "));
|
|
150
|
+
}
|
|
151
|
+
return data;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const dataTypeFactory = new node_opcua_factory_1.DataTypeFactory([(0, node_opcua_factory_1.getStandardDataTypeFactory)()]);
|
|
155
|
+
yield (0, node_opcua_schemas_1.parseBinaryXSDAsync)(content, idProvider, dataTypeFactory);
|
|
156
156
|
write(`// tslint:disable:no-this-assignment
|
|
157
157
|
// tslint:disable:max-classes-per-file
|
|
158
158
|
// tslint:disable:no-empty-interface
|
|
@@ -232,89 +232,89 @@ import {
|
|
|
232
232
|
import {
|
|
233
233
|
decodeVariant, encodeVariant, Variant, VariantLike,
|
|
234
234
|
VariantOptions
|
|
235
|
-
} from "node-opcua-variant";`);
|
|
236
|
-
write(``);
|
|
237
|
-
write(`export class DataTypeDefinition extends BaseUAObject {`);
|
|
238
|
-
write(` constructor(options: any) {`);
|
|
239
|
-
write(` options = options; // do not remove`);
|
|
240
|
-
write(` super();`);
|
|
241
|
-
write(` }`);
|
|
242
|
-
write(`}`);
|
|
243
|
-
write(``);
|
|
244
|
-
const alreadyDone = {};
|
|
245
|
-
/* tslint:disable:no-string-literal */
|
|
246
|
-
alreadyDone["ExtensionObject"] = true;
|
|
247
|
-
alreadyDone["NodeId"] = true;
|
|
248
|
-
alreadyDone["ExpandedNodeId"] = true;
|
|
249
|
-
alreadyDone["Variant"] = true;
|
|
250
|
-
alreadyDone["XmlElement"] = true;
|
|
251
|
-
alreadyDone["NodeIdType"] = true;
|
|
252
|
-
alreadyDone["TwoByteNodeId"] = true;
|
|
253
|
-
alreadyDone["FourByteNodeId"] = true;
|
|
254
|
-
alreadyDone["NumericNodeId"] = true;
|
|
255
|
-
alreadyDone["StringNodeId"] = true;
|
|
256
|
-
alreadyDone["GuidNodeId"] = true;
|
|
257
|
-
alreadyDone["ByteStringNodeId"] = true;
|
|
258
|
-
alreadyDone["DiagnosticInfo"] = true;
|
|
259
|
-
alreadyDone["Variant"] = true;
|
|
260
|
-
alreadyDone["DataValue"] = true;
|
|
261
|
-
alreadyDone["LocalizedText"] = true;
|
|
262
|
-
alreadyDone["QualifiedName"] = true;
|
|
263
|
-
alreadyDone["BrowseDirection"] = true;
|
|
264
|
-
alreadyDone["TimestampsToReturn"] = true;
|
|
265
|
-
function processEnumeratedType(enumerationSchema) {
|
|
266
|
-
if (alreadyDone[enumerationSchema.name]) {
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
alreadyDone[enumerationSchema.name] = enumerationSchema;
|
|
270
|
-
writeEnumeratedType(enumerationSchema);
|
|
271
|
-
}
|
|
272
|
-
function processStructuredType(structuredType) {
|
|
273
|
-
if (alreadyDone[structuredType.name]) {
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
alreadyDone[structuredType.name] = structuredType;
|
|
277
|
-
// make sure
|
|
278
|
-
if (dataTypeFactory.hasStructuredType(structuredType.baseType)) {
|
|
279
|
-
processStructuredType(dataTypeFactory.getStructuredTypeSchema(structuredType.baseType));
|
|
280
|
-
}
|
|
281
|
-
for (const field of structuredType.fields) {
|
|
282
|
-
if (field.category === node_opcua_factory_1.FieldCategory.complex) {
|
|
283
|
-
const fieldSchema = dataTypeFactory.getStructuredTypeSchema(field.fieldType);
|
|
284
|
-
processStructuredType(fieldSchema);
|
|
285
|
-
}
|
|
286
|
-
if (field.category === node_opcua_factory_1.FieldCategory.enumeration) {
|
|
287
|
-
const fieldSchema = dataTypeFactory.getEnumeration(field.fieldType);
|
|
288
|
-
processEnumeratedType(fieldSchema);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
writeStructuredTypeWithSchema(structuredType);
|
|
292
|
-
}
|
|
293
|
-
processStructuredType(dataTypeFactory.getStructuredTypeSchema("LocalizedText"));
|
|
294
|
-
processStructuredType(dataTypeFactory.getStructuredTypeSchema("AxisInformation"));
|
|
295
|
-
// processStructuredType(dataTypeFactory.getStructuredTypeSchema("DiagnosticInfo"));
|
|
296
|
-
processStructuredType(dataTypeFactory.getStructuredTypeSchema("SimpleAttributeOperand"));
|
|
297
|
-
for (const structureType of [...dataTypeFactory.structuredTypesNames()].sort()) {
|
|
298
|
-
if (!dataTypeFactory.hasStructuredType(structureType)) {
|
|
299
|
-
continue;
|
|
300
|
-
}
|
|
301
|
-
processStructuredType(dataTypeFactory.getStructuredTypeSchema(structureType));
|
|
302
|
-
// if (++i > 250) { break; }
|
|
303
|
-
}
|
|
304
|
-
write(``);
|
|
305
|
-
f.saveFormat(generatedTypescriptFilename, (code) => {
|
|
306
|
-
return code;
|
|
307
|
-
/*
|
|
308
|
-
const options: prettier.Options = {
|
|
309
|
-
bracketSpacing: true,
|
|
310
|
-
insertPragma: true,
|
|
311
|
-
parser: "typescript",
|
|
312
|
-
printWidth: 120
|
|
313
|
-
};
|
|
314
|
-
return prettier.format(code, options).replace("\n", os.EOL);
|
|
315
|
-
*/
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
exports.generate = generate;
|
|
235
|
+
} from "node-opcua-variant";`);
|
|
236
|
+
write(``);
|
|
237
|
+
write(`export class DataTypeDefinition extends BaseUAObject {`);
|
|
238
|
+
write(` constructor(options: any) {`);
|
|
239
|
+
write(` options = options; // do not remove`);
|
|
240
|
+
write(` super();`);
|
|
241
|
+
write(` }`);
|
|
242
|
+
write(`}`);
|
|
243
|
+
write(``);
|
|
244
|
+
const alreadyDone = {};
|
|
245
|
+
/* tslint:disable:no-string-literal */
|
|
246
|
+
alreadyDone["ExtensionObject"] = true;
|
|
247
|
+
alreadyDone["NodeId"] = true;
|
|
248
|
+
alreadyDone["ExpandedNodeId"] = true;
|
|
249
|
+
alreadyDone["Variant"] = true;
|
|
250
|
+
alreadyDone["XmlElement"] = true;
|
|
251
|
+
alreadyDone["NodeIdType"] = true;
|
|
252
|
+
alreadyDone["TwoByteNodeId"] = true;
|
|
253
|
+
alreadyDone["FourByteNodeId"] = true;
|
|
254
|
+
alreadyDone["NumericNodeId"] = true;
|
|
255
|
+
alreadyDone["StringNodeId"] = true;
|
|
256
|
+
alreadyDone["GuidNodeId"] = true;
|
|
257
|
+
alreadyDone["ByteStringNodeId"] = true;
|
|
258
|
+
alreadyDone["DiagnosticInfo"] = true;
|
|
259
|
+
alreadyDone["Variant"] = true;
|
|
260
|
+
alreadyDone["DataValue"] = true;
|
|
261
|
+
alreadyDone["LocalizedText"] = true;
|
|
262
|
+
alreadyDone["QualifiedName"] = true;
|
|
263
|
+
alreadyDone["BrowseDirection"] = true;
|
|
264
|
+
alreadyDone["TimestampsToReturn"] = true;
|
|
265
|
+
function processEnumeratedType(enumerationSchema) {
|
|
266
|
+
if (alreadyDone[enumerationSchema.name]) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
alreadyDone[enumerationSchema.name] = enumerationSchema;
|
|
270
|
+
writeEnumeratedType(enumerationSchema);
|
|
271
|
+
}
|
|
272
|
+
function processStructuredType(structuredType) {
|
|
273
|
+
if (alreadyDone[structuredType.name]) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
alreadyDone[structuredType.name] = structuredType;
|
|
277
|
+
// make sure
|
|
278
|
+
if (dataTypeFactory.hasStructuredType(structuredType.baseType)) {
|
|
279
|
+
processStructuredType(dataTypeFactory.getStructuredTypeSchema(structuredType.baseType));
|
|
280
|
+
}
|
|
281
|
+
for (const field of structuredType.fields) {
|
|
282
|
+
if (field.category === node_opcua_factory_1.FieldCategory.complex) {
|
|
283
|
+
const fieldSchema = dataTypeFactory.getStructuredTypeSchema(field.fieldType);
|
|
284
|
+
processStructuredType(fieldSchema);
|
|
285
|
+
}
|
|
286
|
+
if (field.category === node_opcua_factory_1.FieldCategory.enumeration) {
|
|
287
|
+
const fieldSchema = dataTypeFactory.getEnumeration(field.fieldType);
|
|
288
|
+
processEnumeratedType(fieldSchema);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
writeStructuredTypeWithSchema(structuredType);
|
|
292
|
+
}
|
|
293
|
+
processStructuredType(dataTypeFactory.getStructuredTypeSchema("LocalizedText"));
|
|
294
|
+
processStructuredType(dataTypeFactory.getStructuredTypeSchema("AxisInformation"));
|
|
295
|
+
// processStructuredType(dataTypeFactory.getStructuredTypeSchema("DiagnosticInfo"));
|
|
296
|
+
processStructuredType(dataTypeFactory.getStructuredTypeSchema("SimpleAttributeOperand"));
|
|
297
|
+
for (const structureType of [...dataTypeFactory.structuredTypesNames()].sort()) {
|
|
298
|
+
if (!dataTypeFactory.hasStructuredType(structureType)) {
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
processStructuredType(dataTypeFactory.getStructuredTypeSchema(structureType));
|
|
302
|
+
// if (++i > 250) { break; }
|
|
303
|
+
}
|
|
304
|
+
write(``);
|
|
305
|
+
f.saveFormat(generatedTypescriptFilename, (code) => {
|
|
306
|
+
return code;
|
|
307
|
+
/*
|
|
308
|
+
const options: prettier.Options = {
|
|
309
|
+
bracketSpacing: true,
|
|
310
|
+
insertPragma: true,
|
|
311
|
+
parser: "typescript",
|
|
312
|
+
printWidth: 120
|
|
313
|
+
};
|
|
314
|
+
return prettier.format(code, options).replace("\n", os.EOL);
|
|
315
|
+
*/
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
exports.generate = generate;
|
|
320
320
|
//# sourceMappingURL=generate_extension_object_code.js.map
|
package/dist/generator.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ConstructorFunc } from "node-opcua-factory";
|
|
2
|
-
export declare const verbose = false;
|
|
3
|
-
export declare function generateCode(schemaName: string, localSchemaFile: string, generatedCodeFolder?: string): Promise<void>;
|
|
4
|
-
export declare function generateTypeScriptCodeFromSchema(schemaName: string): Promise<void>;
|
|
5
|
-
export declare function registerObject(schema: string, generateCodeFolder?: string): Promise<ConstructorFunc | null>;
|
|
6
|
-
export declare function unregisterObject(schema: {
|
|
7
|
-
name: string;
|
|
8
|
-
}, folder: string): void;
|
|
1
|
+
import { ConstructorFunc } from "node-opcua-factory";
|
|
2
|
+
export declare const verbose = false;
|
|
3
|
+
export declare function generateCode(schemaName: string, localSchemaFile: string, generatedCodeFolder?: string): Promise<void>;
|
|
4
|
+
export declare function generateTypeScriptCodeFromSchema(schemaName: string): Promise<void>;
|
|
5
|
+
export declare function registerObject(schema: string, generateCodeFolder?: string): Promise<ConstructorFunc | null>;
|
|
6
|
+
export declare function unregisterObject(schema: {
|
|
7
|
+
name: string;
|
|
8
|
+
}, folder: string): void;
|