node-opcua-generator
Advanced tools
Comparing version 2.6.0-alpha.7 to 2.6.1
@@ -0,1 +1,4 @@ | ||
/** | ||
* @module node-opcua-generator | ||
*/ | ||
import { StructuredTypeSchema } from "node-opcua-factory"; | ||
@@ -2,0 +5,0 @@ export declare function get_class_tscript_filename(schemaName: string, optionalFolder?: string): string; |
"use strict"; | ||
/* istanbul ignore file */ | ||
/** | ||
* @module node-opcua-generator | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.produce_tscript_code = exports.writeStructuredType = exports.get_class_jscript_filename = exports.get_class_tscript_filename = void 0; | ||
// tslint:disable:max-line-length | ||
// tslint:disable:max-depth | ||
const fs = require("fs"); | ||
@@ -39,2 +45,3 @@ const node_opcua_assert_1 = require("node-opcua-assert"); | ||
lines.push("]"); | ||
// tslint:disable:no-empty | ||
} | ||
@@ -86,3 +93,3 @@ else if (typeof (obj) === "function") { | ||
if (!generateTypeScriptSource) { | ||
const folder = "."; | ||
const folder = "."; // exports.folder_for_generated_file; | ||
generateTypeScriptSource = path.join(folder, "_" + schemaName + ".ts"); | ||
@@ -105,3 +112,3 @@ } | ||
function write_enumeration(write, schema, field, member, i) { | ||
node_opcua_assert_1.assert(!field.isArray); | ||
node_opcua_assert_1.assert(!field.isArray); // would not work in this case | ||
const capMember = node_opcua_utils_1.capitalizeFirstLetter(member); | ||
@@ -118,5 +125,6 @@ write(` this.${field.name} = this.set${capMember}(initialize_field(schema.fields[${i}], options.${field.name}));`); | ||
} | ||
function write_complex(write, schema, field, member) { | ||
function write_complex(write, schema, field, member /*, i*/) { | ||
if (field.isArray) { | ||
if (field.hasOwnProperty("defaultValue")) { | ||
// todo: fix me => should call field defaultValue in the live version | ||
write(` this.${member} = []; // should default`); | ||
@@ -130,2 +138,3 @@ } | ||
write(` this.${member} = options.${member}.map((e: any) => new ${field.fieldType}(e));`); | ||
// write(` self.${member} = options.${member}.map(function(e){ return construct${field.fieldType}(e); } );`); | ||
write(" }"); | ||
@@ -136,5 +145,7 @@ } | ||
write(` this.${member} = (options.${member}) ? new ${field.fieldType}( options.${member}) : null;`); | ||
// xx write(` self.${member} = (options.${member}) ? construct${field.fieldType}( options.${member}) : null;`); | ||
} | ||
else { | ||
write(` this.${member} = new ${field.fieldType}(options.${member});`); | ||
// xx write(` self.${member} = construct${field.fieldType}(options.${member});`); | ||
} | ||
@@ -146,2 +157,7 @@ } | ||
if (field.isArray) { | ||
// write(`this.${member} = [];`); | ||
// write(`if (options.${member}) {`); | ||
// write(` assert(_.isArray(options.${member}));`); | ||
// write(` this.${member} = options.browsePath.map(e => field.coerce(e) );`); | ||
// write(`}`); | ||
write(` this.${member} = initialize_field_array(schema.fields[${i}], options.${field.name});`); | ||
@@ -178,2 +194,3 @@ } | ||
const ft = makeFieldType(field); | ||
// xx write(" * @param [options." + field.name + def + "] " + ft + " " + documentation); | ||
} | ||
@@ -200,2 +217,3 @@ write(" */"); | ||
} | ||
// write(" options = options || {};"); | ||
write(" if (options === undefined || options === null) { options = {}; }"); | ||
@@ -206,2 +224,5 @@ write(" /* istanbul ignore next */"); | ||
write(" }"); | ||
// ----------------------------------------------------------------------------------------------------------------- | ||
// Special case when options === null => fast constructor for deserialization | ||
// ----------------------------------------------------------------------------------------------------------------- | ||
if (hasComplex(schema)) { | ||
@@ -211,2 +232,4 @@ write(" if (options === null) {"); | ||
if (baseClass) { | ||
// write(" " + baseclass + ".call(this,options);"); | ||
// write(" " + baseclass + ".call(this,options);"); | ||
} | ||
@@ -228,2 +251,3 @@ for (let i = 0; i < n; i++) { | ||
} | ||
// ----------------------------------------------------------------------------------------------------------------- | ||
for (let i = 0; i < n; i++) { | ||
@@ -241,2 +265,3 @@ const field = schema.fields[i]; | ||
write(" * @property ", field.name); | ||
// write(" * @type {", (field.isArray ? "Array[" : "") + field.fieldType + (field.isArray ? " ]" : "")+"}"); | ||
write(" * @type " + makeFieldType(field)); | ||
@@ -269,2 +294,3 @@ } | ||
function write_isValid(write, schema) { | ||
// --------------------------------------- | ||
if (_.isFunction(schema.isValid)) { | ||
@@ -327,2 +353,4 @@ if (produceComment) { | ||
function write_decode(write, schema) { | ||
// -------------------------------------------------------------- | ||
// implement decode | ||
function write_field(field, member, i) { | ||
@@ -358,5 +386,7 @@ if (field.category === node_opcua_factory_1.FieldCategory.enumeration || field.category === node_opcua_factory_1.FieldCategory.basic) { | ||
write(" this." + member + ".decode(stream);"); | ||
// xx write(" this." + member + ".decode(stream);"); | ||
} | ||
} | ||
} | ||
// --------------------------------------------------------------- | ||
if (_.isFunction(schema.decode)) { | ||
@@ -530,2 +560,3 @@ if (produceComment) { | ||
const needRegistration = encodingBinaryNodeId.value !== 0; | ||
// ----------------------------------------------- Options | ||
if (baseClass === "BaseUAObject" || baseClass === "ExtensionObject" || baseClass === "DataTypeDefinition") { | ||
@@ -546,2 +577,5 @@ write(`export interface ${className}Options {`); | ||
write_possible_fields(write, className, possibleFields); | ||
// ------------------------------------------------------------------------- | ||
// - encodingDefaultBinary | ||
// ------------------------------------------------------------------------- | ||
write(` public static dataTypeNodeId = makeExpandedNodeId(${dataTypeNodeId.value}, ${dataTypeNodeId.namespace});`); | ||
@@ -563,2 +597,3 @@ if (encodingBinaryNodeId) { | ||
} | ||
// xx write(` static schema = schema${className};`); | ||
write_declare_class_member(write, schema); | ||
@@ -610,2 +645,3 @@ write_constructor(write, schema); | ||
} | ||
/* eslint complexity:[0,50], max-statements: [1, 254]*/ | ||
function produce_tscript_code(schema, localSchemaFile, generatedTypescriptFilename) { | ||
@@ -621,4 +657,8 @@ const className = schema.name; | ||
} | ||
// Xx resolve_schema_field_types(schema, generatedObjectSchema); | ||
const complexTypes = schema.fields.filter((field) => field.category === node_opcua_factory_1.FieldCategory.complex && field.fieldType !== schema.name); | ||
const folderForSourceFile = path.dirname(generatedTypescriptFilename); | ||
// ------------------------------------------------------------------------- | ||
// - insert common require's | ||
// ------------------------------------------------------------------------- | ||
write("/**"); | ||
@@ -646,2 +686,3 @@ write(" * @module node-opcua-address-space.types"); | ||
write("import { encodeArray, decodeArray } from \"node-opcua-basic-types\";"); | ||
// xx write('import { BaseUAObject } from "node-opcua-factory";'); | ||
write("/* tslint:disable:no-this-assignment */"); | ||
@@ -652,2 +693,5 @@ write("/* tslint:disable:max-classes-per-file */"); | ||
write("const schema = " + schemaObjName + ";"); | ||
// ------------------------------------------------------------------------- | ||
// - insert definition of complex type used by this class | ||
// ------------------------------------------------------------------------- | ||
const tmpMap = {}; | ||
@@ -662,2 +706,3 @@ for (const field of complexTypes) { | ||
if (fs.existsSync(filename)) { | ||
// xx write("const " + field.fieldType + ' = require("' + local_filename + '").' + field.fieldType + ";"); | ||
write(`import { ${field.fieldType} } from "${localFilename}";`); | ||
@@ -669,5 +714,9 @@ } | ||
} | ||
// ------------------------------------------------------------------------- | ||
// - insert definition of base class | ||
// ------------------------------------------------------------------------- | ||
if (baseClass !== "BaseUAObject") { | ||
const filename = get_class_tscript_filename_local(baseClass); | ||
const localFilename = node_opcua_utils_1.normalize_require_file(folderForSourceFile, filename); | ||
// xx console.log(" ===> filename", filename, localFilename, fs.existsSync(filename)); | ||
if (fs.existsSync(filename)) { | ||
@@ -674,0 +723,0 @@ node_opcua_assert_1.assert(!localFilename.match(/\\/)); |
@@ -13,2 +13,9 @@ "use strict"; | ||
exports.generate = void 0; | ||
/* istanbul ignore file */ | ||
/** | ||
* @module node-opcua-generator | ||
*/ | ||
// tslint:disable:max-line-length | ||
// tslint:disable:no-inner-declarations | ||
// | ||
const chalk = require("chalk"); | ||
@@ -26,2 +33,3 @@ const fs = require("fs"); | ||
const debugLog = node_opcua_debug_1.make_debugLog(__filename); | ||
// Xx import * as prettier from "prettier"; | ||
const readFile = util_1.promisify(fs.readFile); | ||
@@ -33,2 +41,3 @@ const f = new node_opcua_utils_1.LineFile(); | ||
function writeEnumeratedType(enumerationSchema) { | ||
// make sure there is a Invalid key in the enum => else insert one | ||
const hasInvalid = enumerationSchema.enumValues.hasOwnProperty("Invalid"); | ||
@@ -43,5 +52,7 @@ if (!hasInvalid) { | ||
.sort((a, b) => a - b); | ||
// determining if enum is of type FLAGS | ||
const isFlaggable = arrayValues.length > 2 | ||
&& arrayValues[2] === arrayValues[1] * 2 | ||
&& arrayValues[3] === arrayValues[2] * 2; | ||
// find min and max values (excluding | ||
const minEnumValue = Math.min.apply(null, arrayValues); | ||
@@ -60,2 +71,3 @@ const maxEnumValue = Math.max.apply(null, arrayValues); | ||
write(`const schema${enumerationSchema.name} = {`); | ||
// xx write(` documentation: "${enumerationSchema.documentation}",`); | ||
write(` enumValues: ${enumerationSchema.name},`); | ||
@@ -99,2 +111,3 @@ write(` flaggable: ${isFlaggable},`); | ||
} | ||
// write(` /* cat = ${field.category} */`); | ||
write(` },`); | ||
@@ -227,2 +240,3 @@ } | ||
const alreadyDone = {}; | ||
/* tslint:disable:no-string-literal */ | ||
alreadyDone["ExtensionObject"] = true; | ||
@@ -259,2 +273,3 @@ alreadyDone["NodeId"] = true; | ||
alreadyDone[structuredType.name] = structuredType; | ||
// make sure | ||
if (dataTypeFactory.hasStructuredType(structuredType.baseType)) { | ||
@@ -277,2 +292,3 @@ processStructuredType(dataTypeFactory.getStructuredTypeSchema(structuredType.baseType)); | ||
processStructuredType(dataTypeFactory.getStructuredTypeSchema("AxisInformation")); | ||
// processStructuredType(dataTypeFactory.getStructuredTypeSchema("DiagnosticInfo")); | ||
processStructuredType(dataTypeFactory.getStructuredTypeSchema("SimpleAttributeOperand")); | ||
@@ -284,6 +300,14 @@ for (const structureType of dataTypeFactory.structuredTypesNames().sort()) { | ||
processStructuredType(dataTypeFactory.getStructuredTypeSchema(structureType)); | ||
// if (++i > 250) { break; } | ||
} | ||
write(``); | ||
f.saveFormat(generatedTypescriptFilename, (code) => { | ||
// const options: prettier.Options = { | ||
// printWidth: 120, | ||
// parser: "typescript", | ||
// insertPragma: true, | ||
// bracketSpacing: true | ||
// }; | ||
return code; | ||
// return prettier.format(code, options).replace("\n",os.EOL); | ||
}); | ||
@@ -290,0 +314,0 @@ } |
@@ -13,2 +13,8 @@ "use strict"; | ||
exports.unregisterObject = exports.registerObject = exports.generateTypeScriptCodeFromSchema = exports.generateCode = exports.verbose = void 0; | ||
/* istanbul ignore file */ | ||
/** | ||
* @module node-opcua-generator | ||
*/ | ||
// tslint:disable:max-line-length | ||
// tslint:disable:no-console | ||
const fs = require("fs"); | ||
@@ -25,2 +31,7 @@ const path = require("path"); | ||
const mkdir = util_1.promisify(fs.mkdir); | ||
/** | ||
* @module opcua.miscellaneous | ||
* @class Factory | ||
* @static | ||
*/ | ||
function compileTscriptCode(typescriptFilename) { | ||
@@ -47,2 +58,6 @@ const content = fs.readFileSync(typescriptFilename, "ascii"); | ||
function get_caller_source_filename() { | ||
// let's find source code where schema file is described | ||
// to do make change this | ||
// the line has the following shape: | ||
// 'at blah (/home/toto/myfile.js:53:34)' | ||
const err = new Error(""); | ||
@@ -61,2 +76,3 @@ const re = /.*\((.*):[0-9]*:[0-9]*\)/g; | ||
return "../"; | ||
// throw new Error("Invalid: cannot find caller_source_filename : " + err.stack + "\n ============="); | ||
} | ||
@@ -70,2 +86,3 @@ const schemaFile = m[1]; | ||
const currentFolder = process.cwd(); | ||
// | ||
const localSchemaFileExists = yield fileExists(localSchemaFile); | ||
@@ -128,5 +145,8 @@ if (!localSchemaFileExists) { | ||
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(); | ||
@@ -133,0 +153,0 @@ const defaultHint = path.join(path.dirname(callerFolder), "schemas"); |
@@ -0,2 +1,5 @@ | ||
/** | ||
* @module node-opcua-generator | ||
*/ | ||
export { generateTypeScriptCodeFromSchema, registerObject, unregisterObject } from "./generator"; | ||
export { generate } from "./generate_extension_object_code"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* istanbul ignore file */ | ||
/** | ||
* @module node-opcua-generator | ||
*/ | ||
var generator_1 = require("./generator"); | ||
@@ -4,0 +8,0 @@ Object.defineProperty(exports, "generateTypeScriptCodeFromSchema", { enumerable: true, get: function () { return generator_1.generateTypeScriptCodeFromSchema; } }); |
@@ -12,2 +12,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* istanbul ignore file */ | ||
/** | ||
* @module node-opcua-generator | ||
*/ | ||
// tslint:disable:no-console | ||
const generator_1 = require("./generator"); | ||
@@ -14,0 +19,0 @@ console.log(process.argv); |
{ | ||
"name": "node-opcua-generator", | ||
"version": "2.6.0-alpha.7", | ||
"version": "2.6.1", | ||
"description": "pure nodejs OPCUA SDK - module -generator", | ||
@@ -14,17 +14,17 @@ "main": "./dist/index.js", | ||
"chalk": "^4.0.0", | ||
"node-opcua-assert": "^2.6.0-alpha.1", | ||
"node-opcua-basic-types": "^2.6.0-alpha.1", | ||
"node-opcua-buffer-utils": "^2.6.0-alpha.1", | ||
"node-opcua-constants": "^2.6.0-alpha.1", | ||
"node-opcua-date-time": "^2.6.0-alpha.1", | ||
"node-opcua-debug": "^2.6.0-alpha.1", | ||
"node-opcua-enum": "^2.6.0-alpha.1", | ||
"node-opcua-factory": "^2.6.0-alpha.7", | ||
"node-opcua-guid": "^2.6.0-alpha.1", | ||
"node-opcua-nodeid": "^2.6.0-alpha.1", | ||
"node-opcua-numeric-range": "^2.6.0-alpha.7", | ||
"node-opcua-schemas": "^2.6.0-alpha.7", | ||
"node-opcua-status-code": "^2.6.0-alpha.1", | ||
"node-opcua-utils": "^2.6.0-alpha.1", | ||
"node-opcua-xml2json": "^2.6.0-alpha.7", | ||
"node-opcua-assert": "^2.6.1", | ||
"node-opcua-basic-types": "^2.6.1", | ||
"node-opcua-buffer-utils": "^2.6.1", | ||
"node-opcua-constants": "^2.6.1", | ||
"node-opcua-date-time": "^2.6.1", | ||
"node-opcua-debug": "^2.6.1", | ||
"node-opcua-enum": "^2.6.1", | ||
"node-opcua-factory": "^2.6.1", | ||
"node-opcua-guid": "^2.6.1", | ||
"node-opcua-nodeid": "^2.6.1", | ||
"node-opcua-numeric-range": "^2.6.1", | ||
"node-opcua-schemas": "^2.6.1", | ||
"node-opcua-status-code": "^2.6.1", | ||
"node-opcua-utils": "^2.6.1", | ||
"node-opcua-xml2json": "^2.6.1", | ||
"prettier": "^2.0.5", | ||
@@ -36,5 +36,5 @@ "typescript": "^3.9.2", | ||
"@types/prettier": "^2.0.0", | ||
"node-opcua-binary-stream": "^2.6.0-alpha.1", | ||
"node-opcua-extension-object": "^2.6.0-alpha.7", | ||
"node-opcua-packet-analyzer": "^2.6.0-alpha.7", | ||
"node-opcua-binary-stream": "^2.6.1", | ||
"node-opcua-extension-object": "^2.6.1", | ||
"node-opcua-packet-analyzer": "^2.6.1", | ||
"should": "^13.2.3", | ||
@@ -58,3 +58,3 @@ "source-map-support": "^0.5.19" | ||
"homepage": "http://node-opcua.github.io/", | ||
"gitHead": "6af0c6f183dcb96ddc5a2befc98851d0960c5fd0" | ||
"gitHead": "15f0c0f83232fc63310dc04fea187048c7a01e4b" | ||
} |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
152750
2469
0
Updatednode-opcua-assert@^2.6.1
Updatednode-opcua-constants@^2.6.1
Updatednode-opcua-date-time@^2.6.1
Updatednode-opcua-debug@^2.6.1
Updatednode-opcua-enum@^2.6.1
Updatednode-opcua-factory@^2.6.1
Updatednode-opcua-guid@^2.6.1
Updatednode-opcua-nodeid@^2.6.1
Updatednode-opcua-schemas@^2.6.1
Updatednode-opcua-utils@^2.6.1
Updatednode-opcua-xml2json@^2.6.1