Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-opcua-generator

Package Overview
Dependencies
Maintainers
1
Versions
216
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-opcua-generator - npm Package Compare versions

Comparing version 2.113.0 to 2.114.0

221

dist/generate_extension_object_code.js

@@ -25,11 +25,2 @@ "use strict";

};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -153,34 +144,33 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

}
function generate(filename, generatedTypescriptFilename) {
return __awaiter(this, void 0, void 0, function* () {
const content = yield readFile(filename, "utf-8");
const idProvider = {
getDataTypeAndEncodingId(name) {
const dataType = node_opcua_constants_1.DataTypeIds[name] || 0;
const binEncoding = node_opcua_constants_1.ObjectIds[name + "_Encoding_DefaultBinary"] || 0;
const xmlEncoding = node_opcua_constants_1.ObjectIds[name + "_Encoding_DefaultXml"] || 0;
const jsonEncoding = node_opcua_constants_1.ObjectIds[name + "_Encoding_DefaultJson"] || 0;
if (dataType === undefined) {
return null;
}
const dataTypeNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, dataType, 0);
const binaryEncodingNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, binEncoding, 0);
const xmlEncodingNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, xmlEncoding, 0);
const jsonEncodingNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, jsonEncoding, 0);
const data = {
binaryEncodingNodeId,
dataTypeNodeId,
jsonEncodingNodeId,
xmlEncodingNodeId
};
// istanbul ignore next
if (doDebug) {
debugLog(" data=", chalk_1.default.cyan(name.padEnd(43, " ")), data.dataTypeNodeId.toString().padEnd(43, " "), data.binaryEncodingNodeId.toString().padEnd(43, " "));
}
return data;
async function generate(filename, generatedTypescriptFilename) {
const content = await readFile(filename, "utf-8");
const idProvider = {
getDataTypeAndEncodingId(name) {
const dataType = node_opcua_constants_1.DataTypeIds[name] || 0;
const binEncoding = node_opcua_constants_1.ObjectIds[name + "_Encoding_DefaultBinary"] || 0;
const xmlEncoding = node_opcua_constants_1.ObjectIds[name + "_Encoding_DefaultXml"] || 0;
const jsonEncoding = node_opcua_constants_1.ObjectIds[name + "_Encoding_DefaultJson"] || 0;
if (dataType === undefined) {
return null;
}
};
const dataTypeFactory = new node_opcua_factory_1.DataTypeFactory([(0, node_opcua_factory_1.getStandardDataTypeFactory)()]);
yield (0, node_opcua_schemas_1.parseBinaryXSDAsync)(content, idProvider, dataTypeFactory);
write(`// tslint:disable:no-this-assignment
const dataTypeNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, dataType, 0);
const binaryEncodingNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, binEncoding, 0);
const xmlEncodingNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, xmlEncoding, 0);
const jsonEncodingNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, jsonEncoding, 0);
const data = {
binaryEncodingNodeId,
dataTypeNodeId,
jsonEncodingNodeId,
xmlEncodingNodeId
};
// istanbul ignore next
if (doDebug) {
debugLog(" data=", chalk_1.default.cyan(name.padEnd(43, " ")), data.dataTypeNodeId.toString().padEnd(43, " "), data.binaryEncodingNodeId.toString().padEnd(43, " "));
}
return data;
}
};
const dataTypeFactory = new node_opcua_factory_1.DataTypeFactory([(0, node_opcua_factory_1.getStandardDataTypeFactory)()]);
await (0, node_opcua_schemas_1.parseBinaryXSDAsync)(content, idProvider, dataTypeFactory);
write(`// tslint:disable:no-this-assignment
// tslint:disable:max-classes-per-file

@@ -265,83 +255,82 @@ // tslint:disable:no-empty-interface

} from "node-opcua-variant";`);
write(``);
// write(`export class DataTypeDefinition extends BaseUAObject {`);
// write(` constructor(options: any) {`);
// write(` options = options; // do not remove`);
// write(` super();`);
// write(` }`);
// write(`}`);
// write(``);
const alreadyDone = {};
/* tslint:disable:no-string-literal */
alreadyDone["ExtensionObject"] = true;
alreadyDone["NodeId"] = true;
alreadyDone["ExpandedNodeId"] = true;
alreadyDone["Variant"] = true;
alreadyDone["XmlElement"] = true;
alreadyDone["NodeIdType"] = true;
alreadyDone["TwoByteNodeId"] = true;
alreadyDone["FourByteNodeId"] = true;
alreadyDone["NumericNodeId"] = true;
alreadyDone["StringNodeId"] = true;
alreadyDone["GuidNodeId"] = true;
alreadyDone["ByteStringNodeId"] = true;
alreadyDone["DiagnosticInfo"] = true;
alreadyDone["Variant"] = true;
alreadyDone["DataValue"] = true;
alreadyDone["LocalizedText"] = true;
alreadyDone["QualifiedName"] = true;
alreadyDone["BrowseDirection"] = true;
alreadyDone["TimestampsToReturn"] = true;
function processEnumeratedType(enumerationSchema) {
if (alreadyDone[enumerationSchema.name]) {
return;
}
alreadyDone[enumerationSchema.name] = enumerationSchema;
writeEnumeratedType(enumerationSchema);
write(``);
// write(`export class DataTypeDefinition extends BaseUAObject {`);
// write(` constructor(options: any) {`);
// write(` options = options; // do not remove`);
// write(` super();`);
// write(` }`);
// write(`}`);
// write(``);
const alreadyDone = {};
/* tslint:disable:no-string-literal */
alreadyDone["ExtensionObject"] = true;
alreadyDone["NodeId"] = true;
alreadyDone["ExpandedNodeId"] = true;
alreadyDone["Variant"] = true;
alreadyDone["XmlElement"] = true;
alreadyDone["NodeIdType"] = true;
alreadyDone["TwoByteNodeId"] = true;
alreadyDone["FourByteNodeId"] = true;
alreadyDone["NumericNodeId"] = true;
alreadyDone["StringNodeId"] = true;
alreadyDone["GuidNodeId"] = true;
alreadyDone["ByteStringNodeId"] = true;
alreadyDone["DiagnosticInfo"] = true;
alreadyDone["Variant"] = true;
alreadyDone["DataValue"] = true;
alreadyDone["LocalizedText"] = true;
alreadyDone["QualifiedName"] = true;
alreadyDone["BrowseDirection"] = true;
alreadyDone["TimestampsToReturn"] = true;
function processEnumeratedType(enumerationSchema) {
if (alreadyDone[enumerationSchema.name]) {
return;
}
function processStructuredType(structuredType) {
if (alreadyDone[structuredType.name]) {
return;
alreadyDone[enumerationSchema.name] = enumerationSchema;
writeEnumeratedType(enumerationSchema);
}
function processStructuredType(structuredType) {
if (alreadyDone[structuredType.name]) {
return;
}
alreadyDone[structuredType.name] = structuredType;
// make sure
if (dataTypeFactory.hasStructureByTypeName(structuredType.baseType)) {
processStructuredType(dataTypeFactory.getStructuredTypeSchema(structuredType.baseType));
}
for (const field of structuredType.fields) {
if (field.category === node_opcua_factory_1.FieldCategory.complex) {
const fieldSchema = dataTypeFactory.getStructuredTypeSchema(field.fieldType);
processStructuredType(fieldSchema);
}
alreadyDone[structuredType.name] = structuredType;
// make sure
if (dataTypeFactory.hasStructureByTypeName(structuredType.baseType)) {
processStructuredType(dataTypeFactory.getStructuredTypeSchema(structuredType.baseType));
if (field.category === node_opcua_factory_1.FieldCategory.enumeration) {
const fieldSchema = dataTypeFactory.getEnumeration(field.fieldType);
processEnumeratedType(fieldSchema);
}
for (const field of structuredType.fields) {
if (field.category === node_opcua_factory_1.FieldCategory.complex) {
const fieldSchema = dataTypeFactory.getStructuredTypeSchema(field.fieldType);
processStructuredType(fieldSchema);
}
if (field.category === node_opcua_factory_1.FieldCategory.enumeration) {
const fieldSchema = dataTypeFactory.getEnumeration(field.fieldType);
processEnumeratedType(fieldSchema);
}
}
writeStructuredTypeWithSchema(structuredType);
}
//xx processStructuredType(dataTypeFactory.getStructuredTypeSchema("LocalizedText"));
processStructuredType(dataTypeFactory.getStructuredTypeSchema("AxisInformation"));
// processStructuredType(dataTypeFactory.getStructuredTypeSchema("DiagnosticInfo"));
processStructuredType(dataTypeFactory.getStructuredTypeSchema("SimpleAttributeOperand"));
for (const structureType of [...dataTypeFactory.structuredTypesNames()].sort()) {
if (!dataTypeFactory.hasStructureByTypeName(structureType)) {
continue;
}
processStructuredType(dataTypeFactory.getStructuredTypeSchema(structureType));
// if (++i > 250) { break; }
writeStructuredTypeWithSchema(structuredType);
}
//xx processStructuredType(dataTypeFactory.getStructuredTypeSchema("LocalizedText"));
processStructuredType(dataTypeFactory.getStructuredTypeSchema("AxisInformation"));
// processStructuredType(dataTypeFactory.getStructuredTypeSchema("DiagnosticInfo"));
processStructuredType(dataTypeFactory.getStructuredTypeSchema("SimpleAttributeOperand"));
for (const structureType of [...dataTypeFactory.structuredTypesNames()].sort()) {
if (!dataTypeFactory.hasStructureByTypeName(structureType)) {
continue;
}
write(``);
f.saveFormat(generatedTypescriptFilename, (code) => {
return code;
/*
const options: prettier.Options = {
bracketSpacing: true,
insertPragma: true,
parser: "typescript",
printWidth: 120
};
return prettier.format(code, options).replace("\n", os.EOL);
*/
});
processStructuredType(dataTypeFactory.getStructuredTypeSchema(structureType));
// if (++i > 250) { break; }
}
write(``);
f.saveFormat(generatedTypescriptFilename, (code) => {
return code;
/*
const options: prettier.Options = {
bracketSpacing: true,
insertPragma: true,
parser: "typescript",
printWidth: 120
};
return prettier.format(code, options).replace("\n", os.EOL);
*/
});

@@ -348,0 +337,0 @@ }

@@ -25,11 +25,2 @@ "use strict";

};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -101,87 +92,81 @@ exports.unregisterObject = exports.registerObject = exports.generateTypeScriptCodeFromSchema = exports.generateCode = exports.verbose = void 0;

}
function generateCode(schemaName, localSchemaFile, generatedCodeFolder) {
return __awaiter(this, void 0, void 0, function* () {
const schemaTypescriptFile = schemaName + "_Schema.ts";
const currentFolder = process.cwd();
//
const localSchemaFileExists = fs.existsSync(localSchemaFile);
if (!localSchemaFileExists) {
throw new Error(`Cannot find source file for schema ${schemaTypescriptFile}`);
async function generateCode(schemaName, localSchemaFile, generatedCodeFolder) {
const schemaTypescriptFile = schemaName + "_Schema.ts";
const currentFolder = process.cwd();
//
const localSchemaFileExists = fs.existsSync(localSchemaFile);
if (!localSchemaFileExists) {
throw new Error(`Cannot find source file for schema ${schemaTypescriptFile}`);
}
if (!generatedCodeFolder) {
generatedCodeFolder = path.join(currentFolder, "_generated_");
}
const generatedCodeFolderExists = fs.existsSync(generatedCodeFolder);
if (!generatedCodeFolderExists) {
await mkdir(generatedCodeFolder);
}
const generatedTypescriptSource = path.join(generatedCodeFolder, "_" + schemaName + ".ts");
const generatedSourceExists = fs.existsSync(generatedTypescriptSource);
let schemaFileIsNewer = false;
let codeGeneratorIsNewer = true;
if (generatedSourceExists) {
const generatedSourceMtime = new Date(fs.statSync(generatedTypescriptSource).mtime).getTime();
const schemaFileMtime = new Date(fs.statSync(localSchemaFile).mtime).getTime();
schemaFileIsNewer = generatedSourceMtime <= schemaFileMtime;
let codeGeneratorScript = path.join(__dirname, "factory_code_generator.ts");
if (!fs.existsSync(codeGeneratorScript)) {
codeGeneratorScript = path.join(__dirname, "factory_code_generator.js");
}
if (!generatedCodeFolder) {
generatedCodeFolder = path.join(currentFolder, "_generated_");
(0, node_opcua_assert_1.assert)(fs.existsSync(codeGeneratorScript), "cannot get code factory_code_generator" + codeGeneratorScript);
const codeGeneratorScriptMtime = new Date(fs.statSync(codeGeneratorScript).mtime).getTime();
codeGeneratorIsNewer = generatedSourceMtime <= codeGeneratorScriptMtime;
}
const generatedSourceIsOutdated = !generatedSourceExists || codeGeneratorIsNewer || schemaFileIsNewer;
if (generatedSourceIsOutdated) {
const module = await Promise.resolve(`${localSchemaFile}`).then(s => __importStar(require(s)));
const schema = module[schemaName + "_Schema"];
if (!schema) {
throw new Error(`module must export a Schema with name ${schemaName}_Schema in ${generatedTypescriptSource}`);
}
const generatedCodeFolderExists = fs.existsSync(generatedCodeFolder);
if (!generatedCodeFolderExists) {
yield mkdir(generatedCodeFolder);
debugLog(" generated_source_is_outdated ", schemaName, " to ", generatedTypescriptSource);
if (exports.verbose) {
console.log(" generating ", schemaName, " in ", generatedTypescriptSource);
}
const generatedTypescriptSource = path.join(generatedCodeFolder, "_" + schemaName + ".ts");
const generatedSourceExists = fs.existsSync(generatedTypescriptSource);
let schemaFileIsNewer = false;
let codeGeneratorIsNewer = true;
if (generatedSourceExists) {
const generatedSourceMtime = new Date(fs.statSync(generatedTypescriptSource).mtime).getTime();
const schemaFileMtime = new Date(fs.statSync(localSchemaFile).mtime).getTime();
schemaFileIsNewer = generatedSourceMtime <= schemaFileMtime;
let codeGeneratorScript = path.join(__dirname, "factory_code_generator.ts");
if (!fs.existsSync(codeGeneratorScript)) {
codeGeneratorScript = path.join(__dirname, "factory_code_generator.js");
}
(0, node_opcua_assert_1.assert)(fs.existsSync(codeGeneratorScript), "cannot get code factory_code_generator" + codeGeneratorScript);
const codeGeneratorScriptMtime = new Date(fs.statSync(codeGeneratorScript).mtime).getTime();
codeGeneratorIsNewer = generatedSourceMtime <= codeGeneratorScriptMtime;
}
const generatedSourceIsOutdated = !generatedSourceExists || codeGeneratorIsNewer || schemaFileIsNewer;
if (generatedSourceIsOutdated) {
const module = yield Promise.resolve(`${localSchemaFile}`).then(s => __importStar(require(s)));
const schema = module[schemaName + "_Schema"];
if (!schema) {
throw new Error(`module must export a Schema with name ${schemaName}_Schema in ${generatedTypescriptSource}`);
}
debugLog(" generated_source_is_outdated ", schemaName, " to ", generatedTypescriptSource);
if (exports.verbose) {
console.log(" generating ", schemaName, " in ", generatedTypescriptSource);
}
const localSchemaFile1 = path.join("../schemas", schemaName + "_schema");
(0, factory_code_generator_1.produce_TScript_code)(schema, localSchemaFile1, generatedTypescriptSource);
}
});
const localSchemaFile1 = path.join("../schemas", schemaName + "_schema");
(0, factory_code_generator_1.produce_TScript_code)(schema, localSchemaFile1, generatedTypescriptSource);
}
}
exports.generateCode = generateCode;
function generateTypeScriptCodeFromSchema(schemaName) {
return __awaiter(this, void 0, void 0, function* () {
const currentFolder = process.cwd();
const schemaFilename = path.join(currentFolder, "schemas", schemaName + "_schema.ts");
const generatedCodeFolder = path.join(process.cwd(), "_generated_");
yield generateCode(schemaName, schemaFilename, generatedCodeFolder);
});
async function generateTypeScriptCodeFromSchema(schemaName) {
const currentFolder = process.cwd();
const schemaFilename = path.join(currentFolder, "schemas", schemaName + "_schema.ts");
const generatedCodeFolder = path.join(process.cwd(), "_generated_");
await generateCode(schemaName, schemaFilename, generatedCodeFolder);
}
exports.generateTypeScriptCodeFromSchema = generateTypeScriptCodeFromSchema;
function registerObject(schema, generateCodeFolder) {
return __awaiter(this, void 0, void 0, function* () {
if (!schema.split) {
console.log("error !", schema);
// xx process.exit(1);
}
// we expect <schema>|<hint>
const hintSchema = schema.split("|");
if (hintSchema.length === 1) {
// no hint provided
const callerFolder = get_caller_source_filename();
const defaultHint = path.join(path.dirname(callerFolder), "schemas");
hintSchema.unshift(defaultHint);
generateCodeFolder = generateCodeFolder ? generateCodeFolder : path.join(path.dirname(callerFolder), "_generated_");
}
const folderHint = hintSchema[0];
schema = hintSchema[1];
const schemaName = schema + "_Schema";
const schemaFile = path.join(folderHint, schema + "_schema.ts");
const module = yield Promise.resolve(`${schemaFile}`).then(s => __importStar(require(s)));
if (!module) {
throw new Error("cannot find " + schemaFile);
}
const schemaObj = module[schemaName];
yield generateCode(schemaName, schemaFile, generateCodeFolder);
return null;
});
async function registerObject(schema, generateCodeFolder) {
if (!schema.split) {
console.log("error !", schema);
// xx process.exit(1);
}
// we expect <schema>|<hint>
const hintSchema = schema.split("|");
if (hintSchema.length === 1) {
// no hint provided
const callerFolder = get_caller_source_filename();
const defaultHint = path.join(path.dirname(callerFolder), "schemas");
hintSchema.unshift(defaultHint);
generateCodeFolder = generateCodeFolder ? generateCodeFolder : path.join(path.dirname(callerFolder), "_generated_");
}
const folderHint = hintSchema[0];
schema = hintSchema[1];
const schemaName = schema + "_Schema";
const schemaFile = path.join(folderHint, schema + "_schema.ts");
const module = await Promise.resolve(`${schemaFile}`).then(s => __importStar(require(s)));
if (!module) {
throw new Error("cannot find " + schemaFile);
}
const schemaObj = module[schemaName];
await generateCode(schemaName, schemaFile, generateCodeFolder);
return null;
}

@@ -188,0 +173,0 @@ exports.registerObject = registerObject;

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -19,9 +10,7 @@ /* istanbul ignore file */

console.log(process.argv);
function main() {
return __awaiter(this, void 0, void 0, function* () {
const className = "LocalizedText";
(0, generator_1.generateTypeScriptCodeFromSchema)(className);
});
async function main() {
const className = "LocalizedText";
(0, generator_1.generateTypeScriptCodeFromSchema)(className);
}
main().then().catch();
//# sourceMappingURL=opcua_code_generator.js.map
{
"name": "node-opcua-generator",
"version": "2.113.0",
"version": "2.114.0",
"description": "pure nodejs OPCUA SDK - module generator",

@@ -17,15 +17,15 @@ "main": "./dist/index.js",

"node-opcua-assert": "2.105.0",
"node-opcua-constants": "2.98.1",
"node-opcua-debug": "2.113.0",
"node-opcua-factory": "2.113.0",
"node-opcua-nodeid": "2.113.0",
"node-opcua-schemas": "2.113.0",
"node-opcua-utils": "2.110.0"
"node-opcua-constants": "2.114.0",
"node-opcua-debug": "2.114.0",
"node-opcua-factory": "2.114.0",
"node-opcua-nodeid": "2.114.0",
"node-opcua-schemas": "2.114.0",
"node-opcua-utils": "2.114.0"
},
"devDependencies": {
"node-opcua-basic-types": "2.113.0",
"node-opcua-binary-stream": "2.110.0",
"node-opcua-extension-object": "2.113.0",
"node-opcua-packet-analyzer": "2.113.0",
"node-opcua-status-code": "2.110.0",
"node-opcua-basic-types": "2.114.0",
"node-opcua-binary-stream": "2.114.0",
"node-opcua-extension-object": "2.114.0",
"node-opcua-packet-analyzer": "2.114.0",
"node-opcua-status-code": "2.114.0",
"prettier": "^3.0.3",

@@ -50,3 +50,3 @@ "should": "^13.2.3",

"homepage": "http://node-opcua.github.io/",
"gitHead": "36db335391fedd39726990a1b37f7768da16466a",
"gitHead": "358d284a696c88e383eedac1ab75d950fb28ec35",
"files": [

@@ -53,0 +53,0 @@ "dist",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc