Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function generateEnumerationCode(dataType, filename) {
assert(typeof filename === "string");
const dataTypeName = dataType.browseName.name.toString();
assert(!hasEnumeration(dataTypeName));
// create the enumeration file
const f = new LineFile();
f.write("// namespace " + dataType.namespaceUri.toString());
f.write('const factories = require("node-opcua-factory");');
f.write('const makeNodeId = require("node-opcua-nodeid").makeNodeId;');
f.write("const " + dataTypeName + "_Schema = {");
f.write(" id: makeNodeId(" + dataType.nodeId.value + "," + dataType.nodeId.namespace + "),");
f.write(" name: '" + dataTypeName + "',");
f.write(" namespace: '" + dataType.nodeId.namespace + "',");
f.write(" enumValues: {");
dataType.definition.forEach(function(pair) {
f.write(" " + pair.name + ": " + pair.value + ",");
});
function makeEnumeration(dataType, bForce) {
assert(dataType);
assert(dataType.hasOwnProperty("browseName"));
assert(dataType.browseName instanceof QualifiedName);
assert(_.isArray(dataType.definition));
const dataTypeName = dataType.browseName.name.toString();
if (hasEnumeration(dataTypeName)) {
return getEnumeration(dataTypeName).typedEnum;
}
//const Enumeration_Schema = {
// id: dataType.nodeId,
// name: dataType.browseName.toString(),
// enumValues: {}
//};
//
//dataType.definition.forEach(function (pair) {
// Enumeration_Schema.enumValues[pair.name] = parseInt(pair.value, 10);
//});
const namespace = dataType.namespaceUri;
const filename = getSchemaSourceFile(namespace, dataType.browseName.toString(), "enum");
generateEnumerationCode(dataType, filename);