node-opcua-generator
Advanced tools
Comparing version 0.2.3 to 0.3.0
{ | ||
"name": "node-opcua-generator", | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"description": "pure nodejs OPCUA SDK - module -generator", | ||
@@ -10,16 +10,16 @@ "main": "index.js", | ||
"dependencies": { | ||
"node-opcua-assert": "^0.2.0", | ||
"node-opcua-basic-types": "^0.2.3", | ||
"node-opcua-assert": "^0.3.0", | ||
"node-opcua-basic-types": "^0.3.0", | ||
"node-opcua-constants": "^0.2.0", | ||
"node-opcua-debug": "^0.2.2", | ||
"node-opcua-factory": "^0.2.3", | ||
"node-opcua-nodeid": "^0.2.3", | ||
"node-opcua-utils": "^0.2.3", | ||
"node-opcua-debug": "^0.3.0", | ||
"node-opcua-factory": "^0.3.0", | ||
"node-opcua-nodeid": "^0.3.0", | ||
"node-opcua-utils": "^0.3.0", | ||
"underscore": "^1.8.3" | ||
}, | ||
"devDependencies": { | ||
"node-opcua-binary-stream": "^0.2.3", | ||
"node-opcua-extension-object": "^0.2.3", | ||
"node-opcua-packet-analyzer": "^0.2.3", | ||
"node-opcua-status-code": "^0.2.3", | ||
"node-opcua-binary-stream": "^0.3.0", | ||
"node-opcua-extension-object": "^0.3.0", | ||
"node-opcua-packet-analyzer": "^0.3.0", | ||
"node-opcua-status-code": "^0.3.0", | ||
"should": "13.2.1" | ||
@@ -26,0 +26,0 @@ }, |
@@ -7,28 +7,27 @@ "use strict"; | ||
var assert = require("node-opcua-assert"); | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
var _ = require("underscore"); | ||
const assert = require("node-opcua-assert").assert; | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const _ = require("underscore"); | ||
var getFactory = require("node-opcua-factory/src/factories_factories").getFactory; | ||
const getFactory = require("node-opcua-factory/src/factories_factories").getFactory; | ||
var schema_helpers = require("node-opcua-factory/src/factories_schema_helpers"); | ||
var extract_all_fields = schema_helpers.extract_all_fields; | ||
var resolve_schema_field_types = schema_helpers.resolve_schema_field_types; | ||
var check_schema_correctness = schema_helpers.check_schema_correctness; | ||
var coerceNodeId = require("node-opcua-nodeid").coerceNodeId; | ||
const schema_helpers = require("node-opcua-factory/src/factories_schema_helpers"); | ||
const extract_all_fields = schema_helpers.extract_all_fields; | ||
const resolve_schema_field_types = schema_helpers.resolve_schema_field_types; | ||
const check_schema_correctness = schema_helpers.check_schema_correctness; | ||
const coerceNodeId = require("node-opcua-nodeid").coerceNodeId; | ||
var objectNodeIds = require("node-opcua-constants").ObjectIds; | ||
var ec = require("node-opcua-basic-types"); | ||
const objectNodeIds = require("node-opcua-constants").ObjectIds; | ||
const ec = require("node-opcua-basic-types"); | ||
var makeExpandedNodeId = require("node-opcua-nodeid/src/expanded_nodeid").makeExpandedNodeId; | ||
const makeExpandedNodeId = require("node-opcua-nodeid/src/expanded_nodeid").makeExpandedNodeId; | ||
var debugLog = require("node-opcua-debug").make_debugLog(__filename); | ||
const debugLog = require("node-opcua-debug").make_debugLog(__filename); | ||
//xx var doDebug = require("node-opcua-debug").checkDebugFlag(__filename); | ||
var utils = require("node-opcua-utils"); | ||
var normalize_require_file = utils.normalize_require_file; | ||
var LineFile = require("node-opcua-utils/src/linefile").LineFile; | ||
const utils = require("node-opcua-utils"); | ||
const normalize_require_file = utils.normalize_require_file; | ||
const LineFile = require("node-opcua-utils").LineFile; | ||
//xx exports.folder_for_generated_file = path.normalize(path.join(__dirname,"../../node-opcua/generated")); | ||
@@ -40,9 +39,8 @@ //xx if (fs.existsSync && !fs.existsSync(exports.folder_for_generated_file)) { | ||
function get_class_javascript_filename(schema_name, optional_folder) { | ||
var folder; | ||
let folder; | ||
if (optional_folder) { | ||
if(!(fs.existsSync(optional_folder))) { | ||
if (!fs.existsSync(optional_folder)) { | ||
fs.mkdirSync(optional_folder); | ||
if(!(fs.existsSync(optional_folder))) { | ||
throw new Error("get_class_javascript_filename: Cannot find folder " +optional_folder); | ||
if (!fs.existsSync(optional_folder)) { | ||
throw new Error("get_class_javascript_filename: Cannot find folder " + optional_folder); | ||
} | ||
@@ -63,17 +61,13 @@ } | ||
function get_class_javascript_filename_local(schema_name) { | ||
var generate_source = getFactory(schema_name).prototype._schema.generate_source; | ||
let generate_source = getFactory(schema_name).prototype._schema.generate_source; | ||
if (!generate_source) { | ||
var folder =".";// exports.folder_for_generated_file; | ||
const folder = "."; // exports.folder_for_generated_file; | ||
generate_source = path.join(folder, "_auto_generated_" + schema_name + ".js"); | ||
} | ||
return generate_source; | ||
} | ||
var RUNTIME_GENERATED_ID =+ -1; | ||
const RUNTIME_GENERATED_ID = +-1; | ||
function write_enumeration_setter(f, schema, field, member, i) { | ||
@@ -84,9 +78,9 @@ assert(f instanceof LineFile); | ||
} | ||
var className = schema.name; | ||
var capMember = utils.capitalizeFirstLetter(member); | ||
write(className + ".prototype.set"+capMember +" = function(value) {"); | ||
write(" var coercedValue = _enumerations." + field.fieldType + ".typedEnum.get(value);"); | ||
const className = schema.name; | ||
const capMember = utils.capitalizeFirstLetter(member); | ||
write(className + ".prototype.set" + capMember + " = function(value) {"); | ||
write(" const coercedValue = _enumerations." + field.fieldType + ".typedEnum.get(value);"); | ||
write(" /* istanbul ignore next */"); | ||
write(" if (coercedValue === undefined || coercedValue === null) {"); | ||
write(" throw new Error(\"value cannot be coerced to " + field.fieldType + ": \" + value);"); | ||
write(' throw new Error("value cannot be coerced to ' + field.fieldType + ': " + value);'); | ||
write(" }"); | ||
@@ -97,3 +91,2 @@ write(" this." + member + " = coercedValue;"); | ||
function write_enumeration(f, schema, field, member, i) { | ||
assert(f instanceof LineFile); | ||
@@ -104,12 +97,13 @@ function write() { | ||
//xx var __member = "$" + member; | ||
//xx const __member = "$" + member; | ||
assert(!field.isArray); // would not work in this case | ||
var capMember = utils.capitalizeFirstLetter(member); | ||
write(" self.set" + capMember + "(initialize_field(schema.fields[" + i + "]" + ", options." + field.name + "));"); | ||
const capMember = utils.capitalizeFirstLetter(member); | ||
write( | ||
" self.set" + capMember + "(initialize_field(schema.fields[" + i + "]" + ", options." + field.name + "));" | ||
); | ||
} | ||
function write_complex_fast_construct(f, schema, field, member/*, i*/) { | ||
function write_complex_fast_construct(f, schema, field, member /*, i*/) { | ||
assert(f instanceof LineFile); | ||
@@ -124,7 +118,5 @@ function write() { | ||
} | ||
} | ||
function write_complex(f, schema, field, member/*, i*/) { | ||
function write_complex(f, schema, field, member /*, i*/) { | ||
assert(f instanceof LineFile); | ||
@@ -144,7 +136,25 @@ function write() { | ||
write(" assert(_.isArray(options." + member + "));"); | ||
write(" self." + member + " = options." + member + ".map(function(e){ return new " + field.fieldType + "(e); } );"); | ||
write( | ||
" self." + | ||
member + | ||
" = options." + | ||
member + | ||
".map(function(e){ return new " + | ||
field.fieldType + | ||
"(e); } );" | ||
); | ||
write(" }"); | ||
} else { | ||
if (field.defaultValue === null || field.fieldType === schema.name) { | ||
write(" self." + member + " = (options." + member + ") ? new " + field.fieldType + "( options." + member + ") : null;"); | ||
write( | ||
" self." + | ||
member + | ||
" = (options." + | ||
member + | ||
") ? new " + | ||
field.fieldType + | ||
"( options." + | ||
member + | ||
") : null;" | ||
); | ||
} else { | ||
@@ -154,3 +164,2 @@ write(" self." + member + " = new " + field.fieldType + "( options." + member + ");"); | ||
} | ||
} | ||
@@ -167,21 +176,27 @@ | ||
if (field.isArray) { | ||
write(" self." + member + " = initialize_field_array(schema.fields[" + i + "]" + ", options." + field.name + ");"); | ||
write( | ||
" self." + | ||
member + | ||
" = initialize_field_array(schema.fields[" + | ||
i + | ||
"]" + | ||
", options." + | ||
field.name + | ||
");" | ||
); | ||
} else { | ||
write(" self." + member + " = initialize_field(schema.fields[" + i + "]" + ", options." + field.name + ");"); | ||
} | ||
} | ||
/* eslint complexity:[0,50], max-statements: [1, 254]*/ | ||
function produce_code(schema_file, schema_name, source_file) { | ||
let is_complex_type; | ||
let i, field, fieldType, member, __member; | ||
var is_complex_type; | ||
var i, field, fieldType, member, __member; | ||
schema_file = schema_file.replace(/\\/g, "/"); | ||
var full_path_to_schema ; | ||
let full_path_to_schema; | ||
if (schema_file.match(/^\$node-opcua/)) { | ||
full_path_to_schema = path.resolve(path.join(__dirname,"../../../node_modules",schema_file)); | ||
full_path_to_schema = path.resolve(path.join(__dirname, "../../../node_modules", schema_file)); | ||
} else { | ||
@@ -193,9 +208,9 @@ full_path_to_schema = path.resolve(schema_file); | ||
var relative_path_to_schema = normalize_require_file(__dirname, full_path_to_schema); | ||
const relative_path_to_schema = normalize_require_file(__dirname, full_path_to_schema); | ||
debugLog("relative_path_to_schema".red, relative_path_to_schema); | ||
var local_schema_file = normalize_require_file(path.dirname(source_file), full_path_to_schema); | ||
const local_schema_file = normalize_require_file(path.dirname(source_file), full_path_to_schema); | ||
debugLog("local_schema_file ".red, local_schema_file); | ||
var schema = require(relative_path_to_schema)[schema_name]; | ||
const schema = require(relative_path_to_schema)[schema_name]; | ||
@@ -207,7 +222,7 @@ check_schema_correctness(schema); | ||
} | ||
var name = schema.name; | ||
const name = schema.name; | ||
// check the id of the object binary encoding | ||
var encoding_BinaryId = schema.id; | ||
var encoding_XmlId; | ||
let encoding_BinaryId = schema.id; | ||
let encoding_XmlId; | ||
if (encoding_BinaryId === undefined) { | ||
@@ -221,3 +236,5 @@ encoding_BinaryId = objectNodeIds[name + "_Encoding_DefaultBinary"]; | ||
if (!encoding_BinaryId) { | ||
throw new Error("" + name + " has no _Encoding_DefaultBinary id\nplease add a Id field in the structure definition"); | ||
throw new Error( | ||
"" + name + " has no _Encoding_DefaultBinary id\nplease add a Id field in the structure definition" | ||
); | ||
} | ||
@@ -231,17 +248,14 @@ if (typeof encoding_XmlId === "string") { | ||
const encodingBinaryNodeId = | ||
encoding_BinaryId === RUNTIME_GENERATED_ID ? encoding_BinaryId : makeExpandedNodeId(encoding_BinaryId); | ||
const encodingXmlNodeId = encoding_XmlId ? makeExpandedNodeId(encoding_XmlId) : null; | ||
var encodingBinaryNodeId = (encoding_BinaryId === RUNTIME_GENERATED_ID ) ? encoding_BinaryId : makeExpandedNodeId(encoding_BinaryId); | ||
var encodingXmlNodeId = (encoding_XmlId ) ? makeExpandedNodeId(encoding_XmlId) : null; | ||
schema.baseType = schema.baseType || "BaseUAObject"; | ||
var baseclass = schema.baseType; | ||
const baseclass = schema.baseType; | ||
const classname = schema.name; | ||
var classname = schema.name; | ||
const f = new LineFile(); | ||
var f = new LineFile(); | ||
function write() { | ||
@@ -252,81 +266,75 @@ f.write.apply(f, arguments); | ||
resolve_schema_field_types(schema); | ||
var complexTypes = schema.fields.filter(function (field) { | ||
const complexTypes = schema.fields.filter(function(field) { | ||
return field.category === "complex" && field.fieldType !== schema.name; | ||
}); | ||
var folder_for_source_file = path.dirname(source_file); | ||
const folder_for_source_file = path.dirname(source_file); | ||
// ------------------------------------------------------------------------- | ||
// - insert common require's | ||
// ------------------------------------------------------------------------- | ||
write("\"use strict\";"); | ||
// ------------------------------------------------------------------------- | ||
// - insert common require's | ||
// ------------------------------------------------------------------------- | ||
write('"use strict";'); | ||
write("/**"); | ||
write(" * @module opcua.address_space.types"); | ||
write(" */"); | ||
write("var assert = require(\"node-opcua-assert\");"); | ||
write("var util = require(\"util\");"); | ||
write("var _ = require(\"underscore\");"); | ||
write("var makeNodeId = require(\"node-opcua-nodeid\").makeNodeId;"); | ||
write("var schema_helpers = require(\"node-opcua-factory/src/factories_schema_helpers\");"); | ||
write('const assert = require("node-opcua-assert").assert;'); | ||
write('const util = require("util");'); | ||
write('const _ = require("underscore");'); | ||
write('const makeNodeId = require("node-opcua-nodeid").makeNodeId;'); | ||
write('const schema_helpers = require("node-opcua-factory/src/factories_schema_helpers");'); | ||
write("var extract_all_fields = schema_helpers.extract_all_fields;"); | ||
write("var resolve_schema_field_types = schema_helpers.resolve_schema_field_types;"); | ||
write("var initialize_field = schema_helpers.initialize_field;"); | ||
write("var initialize_field_array = schema_helpers.initialize_field_array;"); | ||
write("var check_options_correctness_against_schema = schema_helpers.check_options_correctness_against_schema;"); | ||
write("var _defaultTypeMap = require(\"node-opcua-factory/src/factories_builtin_types\")._defaultTypeMap;"); | ||
write("const extract_all_fields = schema_helpers.extract_all_fields;"); | ||
write("const resolve_schema_field_types = schema_helpers.resolve_schema_field_types;"); | ||
write("const initialize_field = schema_helpers.initialize_field;"); | ||
write("const initialize_field_array = schema_helpers.initialize_field_array;"); | ||
write("const check_options_correctness_against_schema = schema_helpers.check_options_correctness_against_schema;"); | ||
write('const _defaultTypeMap = require("node-opcua-factory/src/factories_builtin_types")._defaultTypeMap;'); | ||
write("var ec = require(\"node-opcua-basic-types\");"); | ||
write("var encodeArray = ec.encodeArray;"); | ||
write("var decodeArray = ec.decodeArray;"); | ||
write("var makeExpandedNodeId = require(\"node-opcua-nodeid/src/expanded_nodeid\").makeExpandedNodeId;"); | ||
write('const ec = require("node-opcua-basic-types");'); | ||
write("const encodeArray = ec.encodeArray;"); | ||
write("const decodeArray = ec.decodeArray;"); | ||
write('const makeExpandedNodeId = require("node-opcua-nodeid/src/expanded_nodeid").makeExpandedNodeId;'); | ||
write("var generate_new_id = require(\"node-opcua-factory\").generate_new_id;"); | ||
write("var _enumerations = require(\"node-opcua-factory/src/factories_enumerations\")._private._enumerations;"); | ||
// ------------------------------------------------------------------------- | ||
// - insert schema | ||
// ------------------------------------------------------------------------- | ||
write('const generate_new_id = require("node-opcua-factory").generate_new_id;'); | ||
write('const _enumerations = require("node-opcua-factory/src/factories_enumerations")._private._enumerations;'); | ||
// ------------------------------------------------------------------------- | ||
// - insert schema | ||
// ------------------------------------------------------------------------- | ||
write("var schema = require(\"" + local_schema_file + "\")." + classname + "_Schema;"); | ||
write('const schema = require("' + local_schema_file + '").' + classname + "_Schema;"); | ||
// ------------------------------------------------------------------------- | ||
// - insert definition of complex type used by this class | ||
// ------------------------------------------------------------------------- | ||
// ------------------------------------------------------------------------- | ||
// - insert definition of complex type used by this class | ||
// ------------------------------------------------------------------------- | ||
write("var getFactory = require(\"node-opcua-factory/src/factories_factories\").getFactory;"); | ||
var tmp_map = {}; | ||
complexTypes.forEach(function (field) { | ||
if (tmp_map.hasOwnProperty( field.fieldType )) { | ||
write('const getFactory = require("node-opcua-factory/src/factories_factories").getFactory;'); | ||
const tmp_map = {}; | ||
complexTypes.forEach(function(field) { | ||
if (tmp_map.hasOwnProperty(field.fieldType)) { | ||
return; | ||
} | ||
tmp_map[ field.fieldType ] = 1; | ||
tmp_map[field.fieldType] = 1; | ||
var filename = get_class_javascript_filename_local(field.fieldType); | ||
var local_filename = normalize_require_file(folder_for_source_file, filename); | ||
const filename = get_class_javascript_filename_local(field.fieldType); | ||
const local_filename = normalize_require_file(folder_for_source_file, filename); | ||
if( fs.existsSync(filename)) { | ||
write("var " + field.fieldType + " = require(\"" + local_filename + "\")." + field.fieldType + ";"); | ||
if (fs.existsSync(filename)) { | ||
write("const " + field.fieldType + ' = require("' + local_filename + '").' + field.fieldType + ";"); | ||
} else { | ||
write("var " + field.fieldType + " = getFactory(\"" + field.fieldType + "\");"); | ||
write("const " + field.fieldType + ' = getFactory("' + field.fieldType + '");'); | ||
} | ||
}); | ||
// ------------------------------------------------------------------------- | ||
// - insert definition of base class | ||
// ------------------------------------------------------------------------- | ||
write("var BaseUAObject = require(\"node-opcua-factory/src/factories_baseobject\").BaseUAObject;"); | ||
// ------------------------------------------------------------------------- | ||
// - insert definition of base class | ||
// ------------------------------------------------------------------------- | ||
write('const BaseUAObject = require("node-opcua-factory/src/factories_baseobject").BaseUAObject;'); | ||
if (baseclass !== "BaseUAObject") { | ||
const filename = get_class_javascript_filename_local(baseclass); | ||
const local_filename = normalize_require_file(folder_for_source_file, filename); | ||
var filename = get_class_javascript_filename_local(baseclass); | ||
var local_filename = normalize_require_file(folder_for_source_file, filename); | ||
if( fs.existsSync(filename)) { | ||
write("var " + baseclass + " = require(\"" + local_filename + "\")." + baseclass + ";"); | ||
if (fs.existsSync(filename)) { | ||
write("const " + baseclass + ' = require("' + local_filename + '").' + baseclass + ";"); | ||
} else { | ||
write("var " + baseclass+ " = getFactory(\"" + baseclass + "\");"); | ||
write("const " + baseclass + ' = getFactory("' + baseclass + '");'); | ||
} | ||
@@ -339,7 +347,7 @@ } | ||
// ------------------------------------------------------------------------- | ||
// - insert class enumeration properties | ||
// ------------------------------------------------------------------------- | ||
var has_enumeration = false; | ||
var n = schema.fields.length; | ||
// ------------------------------------------------------------------------- | ||
// - insert class enumeration properties | ||
// ------------------------------------------------------------------------- | ||
let has_enumeration = false; | ||
let n = schema.fields.length; | ||
for (i = 0; i < n; i++) { | ||
@@ -352,7 +360,6 @@ if (schema.fields[i].category === "enumeration") { | ||
// ------------------------------------------------------------------------- | ||
// - insert class constructor | ||
// ------------------------------------------------------------------------- | ||
// ------------------------------------------------------------------------- | ||
// - insert class constructor | ||
// ------------------------------------------------------------------------- | ||
write(""); | ||
@@ -370,7 +377,7 @@ write("/**"); | ||
write(" * @param options {Object}"); | ||
var def = ""; | ||
let def = ""; | ||
for (i = 0; i < n; i++) { | ||
field = schema.fields[i]; | ||
fieldType = field.fieldType; | ||
var documentation = field.documentation ? field.documentation : ""; | ||
const documentation = field.documentation ? field.documentation : ""; | ||
def = ""; | ||
@@ -384,4 +391,4 @@ if (field.defaultValue !== undefined) { | ||
} | ||
var ft = makeFieldType(field); | ||
write(" * @param [options." + field.name + def + "] " + ft + " " + documentation); | ||
const ft = makeFieldType(field); | ||
//xx write(" * @param [options." + field.name + def + "] " + ft + " " + documentation); | ||
} | ||
@@ -393,7 +400,7 @@ | ||
write("{"); | ||
// write(" var value;"); | ||
// write(" const value;"); | ||
write(" options = options || {};"); | ||
write(" /* istanbul ignore next */"); | ||
write(" if (schema_helpers.doDebug) { check_options_correctness_against_schema(this,schema,options); }"); | ||
write(" var self = this;"); | ||
write(" const self = this;"); | ||
write(" assert(this instanceof BaseUAObject); // ' keyword \"new\" is required for constructor call')"); | ||
@@ -438,3 +445,2 @@ write(" resolve_schema_field_types(schema);"); | ||
for (i = 0; i < n; i++) { | ||
field = schema.fields[i]; | ||
@@ -449,3 +455,3 @@ | ||
write(" /**"); | ||
documentation = field.documentation ? field.documentation : ""; | ||
let documentation = field.documentation ? field.documentation : ""; | ||
write(" * ", documentation); | ||
@@ -462,13 +468,7 @@ write(" * @property ", field.name); | ||
if (field.category === "enumeration") { | ||
write_enumeration(f, schema, field, member, i); | ||
} else if (field.category === "complex") { | ||
write_complex(f, schema, field, member, i); | ||
} else { | ||
write_basic(f, schema, field, member, i); | ||
@@ -482,14 +482,11 @@ } | ||
// ------------------------------------------------------------------------- | ||
// - inheritance chain | ||
// ------------------------------------------------------------------------- | ||
// ------------------------------------------------------------------------- | ||
// - inheritance chain | ||
// ------------------------------------------------------------------------- | ||
write("util.inherits(" + classname + "," + baseclass + ");"); | ||
// ------------------------------------------------------------------------- | ||
// - Enumeration | ||
// ------------------------------------------------------------------------- | ||
// ------------------------------------------------------------------------- | ||
// - Enumeration | ||
// ------------------------------------------------------------------------- | ||
if (has_enumeration) { | ||
@@ -508,27 +505,32 @@ write(""); | ||
// ------------------------------------------------------------------------- | ||
// - encodingDefaultBinary | ||
// ------------------------------------------------------------------------- | ||
// ------------------------------------------------------------------------- | ||
// - encodingDefaultBinary | ||
// ------------------------------------------------------------------------- | ||
if (RUNTIME_GENERATED_ID === encodingBinaryNodeId) { | ||
write("schema.id = generate_new_id();"); | ||
write(classname + ".prototype.encodingDefaultBinary = makeExpandedNodeId(schema.id);"); | ||
} else { | ||
write(classname + ".prototype.encodingDefaultBinary = makeExpandedNodeId(" + encodingBinaryNodeId.value + ",", encodingBinaryNodeId.namespace, ");"); | ||
write( | ||
classname + ".prototype.encodingDefaultBinary = makeExpandedNodeId(" + encodingBinaryNodeId.value + ",", | ||
encodingBinaryNodeId.namespace, | ||
");" | ||
); | ||
} | ||
if (encodingXmlNodeId) { | ||
write(classname + ".prototype.encodingDefaultXml = makeExpandedNodeId(" + encodingXmlNodeId.value + ",", encodingXmlNodeId.namespace, ");"); | ||
write( | ||
classname + ".prototype.encodingDefaultXml = makeExpandedNodeId(" + encodingXmlNodeId.value + ",", | ||
encodingXmlNodeId.namespace, | ||
");" | ||
); | ||
} | ||
write(classname + ".prototype._schema = schema;"); | ||
// -------------------------------------------------------------- | ||
// expose encoder and decoder func for basic type that we need | ||
// -------------------------------------------------------------- | ||
// -------------------------------------------------------------- | ||
// expose encoder and decoder func for basic type that we need | ||
// -------------------------------------------------------------- | ||
write(""); | ||
n = schema.fields.length; | ||
var done = {}; | ||
const done = {}; | ||
for (i = 0; i < n; i++) { | ||
@@ -540,25 +542,21 @@ field = schema.fields[i]; | ||
if (field.category === "enumeration") { | ||
write("var encode_" + field.fieldType + " = _enumerations." + field.fieldType + ".encode;"); | ||
write("var decode_" + field.fieldType + " = _enumerations." + field.fieldType + ".decode;"); | ||
write("const encode_" + field.fieldType + " = _enumerations." + field.fieldType + ".encode;"); | ||
write("const decode_" + field.fieldType + " = _enumerations." + field.fieldType + ".decode;"); | ||
} else if (field.category === "complex") { | ||
// | ||
} else { | ||
write("var encode_" + field.fieldType + " = _defaultTypeMap." + field.fieldType + ".encode;"); | ||
write("var decode_" + field.fieldType + " = _defaultTypeMap." + field.fieldType + ".decode;"); | ||
write("const encode_" + field.fieldType + " = _defaultTypeMap." + field.fieldType + ".encode;"); | ||
write("const decode_" + field.fieldType + " = _defaultTypeMap." + field.fieldType + ".decode;"); | ||
} | ||
} | ||
} | ||
// -------------------------------------------------------------- | ||
// implement encode | ||
// --------------------------------------------------------------- | ||
// -------------------------------------------------------------- | ||
// implement encode | ||
// --------------------------------------------------------------- | ||
if (_.isFunction(schema.encode)) { | ||
write(classname + ".prototype.encode = function(stream,options) {"); | ||
write(" schema.encode(this,stream,options); "); | ||
write("};"); | ||
} else { | ||
write("/**"); | ||
@@ -582,3 +580,2 @@ write(" * encode the object into a binary stream"); | ||
if (field.category === "enumeration" || field.category === "basic") { | ||
if (field.isArray) { | ||
@@ -589,7 +586,9 @@ write(" encodeArray(this." + member + ", stream, encode_" + field.fieldType + ");"); | ||
} | ||
} else if (field.category === "complex") { | ||
if (field.isArray) { | ||
write(" encodeArray(this." + member + ",stream,function(obj,stream){ obj.encode(stream,options); }); "); | ||
write( | ||
" encodeArray(this." + | ||
member + | ||
",stream,function(obj,stream){ obj.encode(stream,options); }); " | ||
); | ||
} else { | ||
@@ -601,10 +600,8 @@ write(" this." + member + ".encode(stream,options);"); | ||
write("};"); | ||
} | ||
// -------------------------------------------------------------- | ||
// implement decode | ||
// --------------------------------------------------------------- | ||
// -------------------------------------------------------------- | ||
// implement decode | ||
// --------------------------------------------------------------- | ||
if (_.isFunction(schema.decode)) { | ||
write("/**"); | ||
@@ -615,7 +612,6 @@ write(" * decode the object from a binary stream"); | ||
write(" * @param stream {BinaryStream} "); | ||
write(" * @param [option] {object} "); | ||
write(" */"); | ||
write(classname + ".prototype.decode = function(stream,options) {"); | ||
write(" schema.decode(this,stream,options); "); | ||
write(classname + ".prototype.decode = function(stream) {"); | ||
write(" schema.decode(this,stream); "); | ||
write("};"); | ||
@@ -629,3 +625,2 @@ | ||
write("};"); | ||
} else { | ||
@@ -637,7 +632,6 @@ write("/**"); | ||
write(" * @param stream {BinaryStream} "); | ||
write(" * @param [option] {object} "); | ||
write(" */"); | ||
write(classname + ".prototype.decode = function(stream,options) {"); | ||
write(classname + ".prototype.decode = function(stream) {"); | ||
write(" // call base class implementation first"); | ||
write(" " + baseclass + ".prototype.decode.call(this,stream,options);"); | ||
write(" " + baseclass + ".prototype.decode.call(this,stream);"); | ||
@@ -650,14 +644,12 @@ n = schema.fields.length; | ||
if (field.category === "enumeration" || field.category === "basic") { | ||
if (field.isArray) { | ||
write(" this." + member + " = decodeArray(stream, decode_" + field.fieldType + ");"); | ||
} else { | ||
if (is_complex_type) { | ||
write(" this." + member + ".decode(stream,options);"); | ||
write(" this." + member + ".decode(stream);"); | ||
} else { | ||
if (_.isFunction(field.decode)) { | ||
write(" this." + member + " = schema.fields[" + i + "].decode(stream,options);"); | ||
write(" this." + member + " = schema.fields[" + i + "].decode(stream);"); | ||
} else { | ||
write(" this." + member + " = decode_" + field.fieldType + "(stream,options);"); | ||
write(" this." + member + " = decode_" + field.fieldType + "(stream);"); | ||
} | ||
@@ -667,32 +659,29 @@ } | ||
} else { | ||
assert(field.category === "complex"); | ||
if (field.isArray) { | ||
write(" this." + member + " = decodeArray(stream, function(stream) { "); | ||
write(" var obj = new " + field.fieldType + "(null);"); | ||
write(" obj.decode(stream,options);"); | ||
write(" const obj = new " + field.fieldType + "(null);"); | ||
write(" obj.decode(stream);"); | ||
write(" return obj; "); | ||
write(" });"); | ||
} else { | ||
write(" this." + member + ".decode(stream,options);"); | ||
// xx write(" this." + member + ".decode(stream,options);"); | ||
write(" this." + member + ".decode(stream);"); | ||
// xx write(" this." + member + ".decode(stream);"); | ||
} | ||
} | ||
} | ||
write("};"); | ||
} | ||
// -------------------------------------------------------------- | ||
// implement explore | ||
// --------------------------------------------------------------- | ||
// write("/**"); | ||
// write(" *"); | ||
// write(" * pretty print the object"); | ||
// write(" * @method explore"); | ||
// write(" *"); | ||
// write(" */"); | ||
// write(classname + ".prototype.explore = function() {"); | ||
// write("};"); | ||
// -------------------------------------------------------------- | ||
// implement explore | ||
// --------------------------------------------------------------- | ||
// write("/**"); | ||
// write(" *"); | ||
// write(" * pretty print the object"); | ||
// write(" * @method explore"); | ||
// write(" *"); | ||
// write(" */"); | ||
// write(classname + ".prototype.explore = function() {"); | ||
// write("};"); | ||
@@ -710,8 +699,7 @@ // --------------------------------------- | ||
function quotify(str) { | ||
return "\"" + str + "\""; | ||
return '"' + str + '"'; | ||
} | ||
var possible_fields = extract_all_fields(schema); | ||
const possible_fields = extract_all_fields(schema); | ||
@@ -723,13 +711,12 @@ write(classname + ".possibleFields = ["); | ||
write("exports." + classname + " = " + classname + ";"); | ||
write("var register_class_definition = require(\"node-opcua-factory/src/factories_factories\").register_class_definition;"); | ||
write("register_class_definition(\"" + classname + "\"," + classname + ");"); | ||
write( | ||
'const register_class_definition = require("node-opcua-factory/src/factories_factories").register_class_definition;' | ||
); | ||
write('register_class_definition("' + classname + '",' + classname + ");"); | ||
write(""); | ||
f.save(source_file); | ||
} | ||
exports.produce_code = produce_code; |
"use strict"; | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
var assert = require("node-opcua-assert"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const assert = require("node-opcua-assert").assert; | ||
var normalize_require_file = require("node-opcua-utils").normalize_require_file; | ||
const normalize_require_file = require("node-opcua-utils").normalize_require_file; | ||
var debugLog = require("node-opcua-debug").make_debugLog(__filename); | ||
var doDebug = require("node-opcua-debug").checkDebugFlag(__filename); | ||
const debugLog = require("node-opcua-debug").make_debugLog(__filename); | ||
const doDebug = require("node-opcua-debug").checkDebugFlag(__filename); | ||
@@ -22,5 +22,5 @@ /** | ||
var produce_code = require("./factory_code_generator").produce_code; | ||
const produce_code = require("./factory_code_generator").produce_code; | ||
var get_class_javascript_filename = require("./factory_code_generator").get_class_javascript_filename; | ||
const get_class_javascript_filename = require("./factory_code_generator").get_class_javascript_filename; | ||
@@ -34,5 +34,5 @@ exports.verbose = false; | ||
// 'at blah (/home/toto/myfile.js:53:34)' | ||
var err = new Error(); | ||
var re = /.*\((.*):[0-9]*:[0-9]*\)/g; | ||
var schema_file = re.exec(err.stack.split("\n")[3])[1]; | ||
const err = new Error(); | ||
const re = /.*\((.*):[0-9]*:[0-9]*\)/g; | ||
const schema_file = re.exec(err.stack.split("\n")[3])[1]; | ||
return schema_file; | ||
@@ -49,14 +49,16 @@ } | ||
function registerObject(schema, optional_folder) { | ||
let schema_file; | ||
let schema_name; | ||
let code; | ||
let local_schema_file; | ||
var schema_file,schema_name,code,local_schema_file; | ||
if (typeof schema === "string") { | ||
// we expect <schema>|<hint> | ||
var hint_schema = schema.split("|"); | ||
const hint_schema = schema.split("|"); | ||
if (hint_schema.length === 1) { | ||
// no hint provided | ||
var caller_folder = get_caller_source_filename(); | ||
const caller_folder = get_caller_source_filename(); | ||
var default_hint = path.join(path.dirname(caller_folder),"schemas"); | ||
const default_hint = path.join(path.dirname(caller_folder),"schemas"); | ||
hint_schema.unshift(default_hint); | ||
@@ -68,3 +70,3 @@ | ||
var folder_hint = hint_schema[0]; | ||
const folder_hint = hint_schema[0]; | ||
schema = hint_schema[1]; | ||
@@ -92,19 +94,19 @@ | ||
var generated_source = get_class_javascript_filename(schema.name, optional_folder); | ||
const generated_source = get_class_javascript_filename(schema.name, optional_folder); | ||
var generated_source_exists = fs.existsSync(generated_source); | ||
const generated_source_exists = fs.existsSync(generated_source); | ||
var schema_file_is_newer = false; | ||
var code_generator_is_newer = false; | ||
let schema_file_is_newer = false; | ||
let code_generator_is_newer = false; | ||
if (generated_source_exists) { | ||
var generated_source_mtime = new Date(fs.statSync(generated_source).mtime).getTime(); | ||
var schema_file_mtime = new Date(fs.statSync(local_schema_file).mtime).getTime(); | ||
const generated_source_mtime = new Date(fs.statSync(generated_source).mtime).getTime(); | ||
const schema_file_mtime = new Date(fs.statSync(local_schema_file).mtime).getTime(); | ||
schema_file_is_newer = (generated_source_mtime <= schema_file_mtime ); | ||
var code_generator_script = path.join(__dirname,"factory_code_generator.js"); | ||
const code_generator_script = path.join(__dirname,"factory_code_generator.js"); | ||
assert(fs.existsSync(code_generator_script), "cannot get code generator"); | ||
var code_generator_script_mtime = new Date(fs.statSync(code_generator_script).mtime).getTime(); | ||
const code_generator_script_mtime = new Date(fs.statSync(code_generator_script).mtime).getTime(); | ||
code_generator_is_newer = (generated_source_mtime <= code_generator_script_mtime ); | ||
} | ||
var generated_source_is_outdated = (!generated_source_exists || code_generator_is_newer || schema_file_is_newer); | ||
const generated_source_is_outdated = (!generated_source_exists || code_generator_is_newer || schema_file_is_newer); | ||
@@ -116,7 +118,7 @@ if (generated_source_is_outdated) { | ||
} | ||
var code = produce_code(schema_file, schema_name, generated_source); | ||
code = produce_code(schema_file, schema_name, generated_source); | ||
} | ||
schema.generate_source = generated_source; | ||
var local_generated_source = normalize_require_file(__dirname, generated_source); | ||
const local_generated_source = normalize_require_file(__dirname, generated_source); | ||
return require(local_generated_source)[schema.name]; | ||
@@ -130,3 +132,3 @@ } | ||
assert(folder,"#unregisterObject: a folder must be provided"); | ||
var generate_source = get_class_javascript_filename(schema.name,folder); | ||
const generate_source = get_class_javascript_filename(schema.name,folder); | ||
if (fs.existsSync(generate_source)) { | ||
@@ -133,0 +135,0 @@ fs.unlinkSync(generate_source); |
/*global describe, require, it*/ | ||
var should = require("should"); | ||
const should = require("should"); | ||
var factories = require("node-opcua-factory"); | ||
var generator = require("../.."); | ||
const factories = require("node-opcua-factory"); | ||
const generator = require("../.."); | ||
var BinaryStream = require("node-opcua-binary-stream").BinaryStream; | ||
var makeExpandedNodeId = require("node-opcua-nodeid/src/expanded_nodeid").makeExpandedNodeId; | ||
const BinaryStream = require("node-opcua-binary-stream").BinaryStream; | ||
const makeExpandedNodeId = require("node-opcua-nodeid/src/expanded_nodeid").makeExpandedNodeId; | ||
var encode_decode_round_trip_test = require("node-opcua-packet-analyzer/test_helpers/encode_decode_round_trip_test").encode_decode_round_trip_test | ||
const encode_decode_round_trip_test = require("node-opcua-packet-analyzer/test_helpers/encode_decode_round_trip_test").encode_decode_round_trip_test; | ||
var path = require("path"); | ||
var temporary_folder = path.join(__dirname,"../..","_test_generated"); | ||
const path = require("path"); | ||
const temporary_folder = path.join(__dirname,"../..","_test_generated"); | ||
var ExtensionObject = require("node-opcua-extension-object").ExtensionObject; | ||
const ExtensionObject = require("node-opcua-extension-object").ExtensionObject; | ||
@@ -30,6 +30,6 @@ describe("ExtensionObject", function () { | ||
var MetaShape = generator.registerObject(exports.MetaShapeForUnitTest_Schema, temporary_folder); | ||
const MetaShape = generator.registerObject(exports.MetaShapeForUnitTest_Schema, temporary_folder); | ||
var Potato_Schema_Id = 0xF00001; | ||
const Potato_Schema_Id = 0xF00001; | ||
exports.Potato_Schema = { | ||
@@ -44,7 +44,7 @@ name: "Potato", | ||
}; | ||
var Potato = generator.registerObject(exports.Potato_Schema, temporary_folder); | ||
const Potato = generator.registerObject(exports.Potato_Schema, temporary_folder); | ||
it("should encode an object with an embedded ExtensionObject set to null ", function () { | ||
var shape = new MetaShape({ | ||
const shape = new MetaShape({ | ||
name: "MyPotato", | ||
@@ -56,3 +56,3 @@ shape: null, | ||
var stream = new BinaryStream(shape.binaryStoreSize()); | ||
const stream = new BinaryStream(shape.binaryStoreSize()); | ||
shape.encode(stream); | ||
@@ -64,3 +64,3 @@ encode_decode_round_trip_test(shape); | ||
var shape = new MetaShape({ | ||
const shape = new MetaShape({ | ||
name: "Potato", | ||
@@ -72,3 +72,3 @@ shape: new Potato({length: 10.0, radius: 5.0}), | ||
var stream = new BinaryStream(shape.binaryStoreSize()); | ||
const stream = new BinaryStream(shape.binaryStoreSize()); | ||
shape.encode(stream); | ||
@@ -75,0 +75,0 @@ |
require("node-opcua-basic-types"); | ||
var registerObject = require("../..").registerObject; | ||
var registerEnumeration = require("node-opcua-factory").registerEnumeration; | ||
var next_available_id = require("node-opcua-factory").next_available_id; | ||
const registerObject = require("../..").registerObject; | ||
const registerEnumeration = require("node-opcua-factory").registerEnumeration; | ||
const next_available_id = require("node-opcua-factory").next_available_id; | ||
var SomeEnumeration = registerEnumeration({ | ||
const SomeEnumeration = registerEnumeration({ | ||
name: "SomeEnumeration", | ||
@@ -19,3 +19,3 @@ enumValues: { | ||
// ----------------------------------------------------- | ||
var FooBar_Schema = { | ||
const FooBar_Schema = { | ||
name: "FooBar", | ||
@@ -30,4 +30,4 @@ documentation: "A FOOBAR Object.", | ||
var path = require("path"); | ||
var temporary_folder = path.join(__dirname,"../..","_test_generated"); | ||
const path = require("path"); | ||
const temporary_folder = path.join(__dirname,"../..","_test_generated"); | ||
@@ -37,3 +37,3 @@ exports.FooBar_Schema = FooBar_Schema; | ||
var FooBarDerived_Schema = { | ||
const FooBarDerived_Schema = { | ||
name: "FooBarDerived", | ||
@@ -51,3 +51,3 @@ documentation: "A FOOBAR Derived Object.", | ||
var DummyObject_Schema = { | ||
const DummyObject_Schema = { | ||
name: "DummyObject", | ||
@@ -54,0 +54,0 @@ documentation: "A dummy Object.", |
var generator = require("../.."); | ||
var factories = require("node-opcua-factory"); | ||
var path = require("path"); | ||
var temporary_folder = path.join(__dirname,"../..","_test_generated"); | ||
const generator = require("../.."); | ||
const factories = require("node-opcua-factory"); | ||
const path = require("path"); | ||
const temporary_folder = path.join(__dirname,"../..","_test_generated"); | ||
var FooWithRecursion_Schema = { | ||
const FooWithRecursion_Schema = { | ||
name: "FooWithRecursion", | ||
@@ -10,0 +10,0 @@ documentation: "A dummy Object.", |
@@ -1,18 +0,18 @@ | ||
var should = require("should"); | ||
const should = require("should"); | ||
var BinaryStream = require("node-opcua-binary-stream").BinaryStream; | ||
var ec = require("node-opcua-basic-types"); | ||
var makeExpandedNodeId = require("node-opcua-nodeid/src/expanded_nodeid").makeExpandedNodeId; | ||
const BinaryStream = require("node-opcua-binary-stream").BinaryStream; | ||
const ec = require("node-opcua-basic-types"); | ||
const makeExpandedNodeId = require("node-opcua-nodeid/src/expanded_nodeid").makeExpandedNodeId; | ||
var generator = require("../.."); | ||
var factories = require("node-opcua-factory"); | ||
const generator = require("../.."); | ||
const factories = require("node-opcua-factory"); | ||
var packet_analyzer = require("node-opcua-packet-analyzer").packet_analyzer; | ||
const packet_analyzer = require("node-opcua-packet-analyzer").packet_analyzer; | ||
var path = require("path"); | ||
var temporary_folder = path.join(__dirname,"../..","_test_generated"); | ||
const path = require("path"); | ||
const temporary_folder = path.join(__dirname,"../..","_test_generated"); | ||
var Person2_Schema = { | ||
const Person2_Schema = { | ||
id: factories.next_available_id(), | ||
@@ -27,3 +27,3 @@ name: "Person2", | ||
exports.Person2_Schema = Person2_Schema; | ||
var Person2 = generator.registerObject(Person2_Schema, temporary_folder); | ||
const Person2 = generator.registerObject(Person2_Schema, temporary_folder); | ||
@@ -34,3 +34,3 @@ describe("testing package_analyser", function () { | ||
var obj = new Person2({ | ||
const obj = new Person2({ | ||
lastName: "John", | ||
@@ -40,5 +40,5 @@ address: "Miami" | ||
var stream = new BinaryStream(); | ||
const stream = new BinaryStream(); | ||
var expandedNodeId = makeExpandedNodeId(Person2_Schema.id); | ||
const expandedNodeId = makeExpandedNodeId(Person2_Schema.id); | ||
ec.encodeExpandedNodeId(expandedNodeId, stream); | ||
@@ -45,0 +45,0 @@ obj.encode(stream); |
var factories = require("node-opcua-factory"); | ||
const factories = require("node-opcua-factory"); | ||
var ObjWithIntegerId_Schema = { | ||
const ObjWithIntegerId_Schema = { | ||
@@ -6,0 +6,0 @@ id: factories.next_available_id(), |
var factories = require("node-opcua-factory"); | ||
const factories = require("node-opcua-factory"); | ||
var SampleBase_Schema = { | ||
const SampleBase_Schema = { | ||
name: "SampleBase", | ||
@@ -6,0 +6,0 @@ documentation: "A FOOBAR Object.", |
var factories = require("node-opcua-factory"); | ||
const factories = require("node-opcua-factory"); | ||
var SampleDerived_Schema = { | ||
const SampleDerived_Schema = { | ||
name: "SampleDerived", | ||
@@ -6,0 +6,0 @@ baseType: "SampleBase", |
"use strict"; | ||
var should = require("should"); | ||
var _ = require("underscore"); | ||
const should = require("should"); | ||
const _ = require("underscore"); | ||
var generator = require("../src/generator"); | ||
const generator = require("../src/generator"); | ||
var factories = require("node-opcua-factory"); | ||
const factories = require("node-opcua-factory"); | ||
var compare_obj_by_encoding = require("node-opcua-packet-analyzer/test_helpers/compare_obj_by_encoding").compare_obj_by_encoding; | ||
const compare_obj_by_encoding = require("node-opcua-packet-analyzer/test_helpers/compare_obj_by_encoding").compare_obj_by_encoding; | ||
var ec = require("node-opcua-basic-types"); | ||
const ec = require("node-opcua-basic-types"); | ||
var encode_decode_round_trip_test = require("node-opcua-packet-analyzer/test_helpers/encode_decode_round_trip_test").encode_decode_round_trip_test; | ||
const encode_decode_round_trip_test = require("node-opcua-packet-analyzer/test_helpers/encode_decode_round_trip_test").encode_decode_round_trip_test; | ||
var ShapeType = factories.registerEnumeration({ | ||
const ShapeType = factories.registerEnumeration({ | ||
name: "EnumShapeType", | ||
@@ -26,3 +26,3 @@ enumValues: { | ||
var Color = factories.registerEnumeration({ | ||
const Color = factories.registerEnumeration({ | ||
name: "EnumColor", | ||
@@ -55,6 +55,6 @@ enumValues: { | ||
var path = require("path"); | ||
var temporary_folder = path.join(__dirname,"..","_test_generated"); | ||
const path = require("path"); | ||
const temporary_folder = path.join(__dirname,"..","_test_generated"); | ||
var Shape = generator.registerObject(exports.Shape_Schema, temporary_folder); | ||
const Shape = generator.registerObject(exports.Shape_Schema, temporary_folder); | ||
@@ -98,5 +98,5 @@ factories.registerBasicType({ | ||
generator.unregisterObject(exports.MyStruct_Schema, temporary_folder); | ||
var MyStruct = generator.registerObject(exports.MyStruct_Schema, temporary_folder); | ||
const MyStruct = generator.registerObject(exports.MyStruct_Schema, temporary_folder); | ||
var s = new MyStruct(); | ||
const s = new MyStruct(); | ||
s.should.have.property("value"); | ||
@@ -111,3 +111,3 @@ s.value.should.equal(0); | ||
var StatusCodes = require("node-opcua-status-code").StatusCodes; | ||
const StatusCodes = require("node-opcua-status-code").StatusCodes; | ||
@@ -124,5 +124,5 @@ exports.MyStruct2_Schema = { | ||
var MyStruct2 = generator.registerObject(exports.MyStruct2_Schema, temporary_folder); | ||
const MyStruct2 = generator.registerObject(exports.MyStruct2_Schema, temporary_folder); | ||
var s = new MyStruct2(); | ||
const s = new MyStruct2(); | ||
s.should.have.property("value"); | ||
@@ -140,3 +140,3 @@ s.should.have.property("statusCode"); | ||
var shape = new Shape(); | ||
const shape = new Shape(); | ||
@@ -160,6 +160,6 @@ shape.shapeType.should.eql(ShapeType.CIRCLE); | ||
var shape1 = new Shape({shapeType: ShapeType.HEXAGON}); | ||
const shape1 = new Shape({shapeType: ShapeType.HEXAGON}); | ||
shape1.shapeType.should.eql(ShapeType.HEXAGON); | ||
var shape2 = new Shape({shapeType: ShapeType.RECTANGLE}); | ||
const shape2 = new Shape({shapeType: ShapeType.RECTANGLE}); | ||
shape2.shapeType.should.eql(ShapeType.RECTANGLE); | ||
@@ -170,3 +170,3 @@ }); | ||
var shape = new Shape({name: "yo", shapeType: ShapeType.HEXAGON, color: Color.BLUE}); | ||
const shape = new Shape({name: "yo", shapeType: ShapeType.HEXAGON, color: Color.BLUE}); | ||
encode_decode_round_trip_test(shape); | ||
@@ -178,11 +178,11 @@ | ||
var schema_helpers = require("node-opcua-factory/src/factories_schema_helpers"); | ||
const schema_helpers = require("node-opcua-factory/src/factories_schema_helpers"); | ||
var old_schema_helpers_doDebug = schema_helpers.doDebug; | ||
const old_schema_helpers_doDebug = schema_helpers.doDebug; | ||
schema_helpers.doDebug = true; | ||
// redirect stdout to null as test will be noisy | ||
var old_process_stdout_write = process.stdout.write; | ||
const old_process_stdout_write = process.stdout.write; | ||
(function test_constructor_with_invalid_args() { | ||
var a = new Shape({ | ||
const a = new Shape({ | ||
@@ -209,6 +209,6 @@ this_invalid_field_should_cause_Shape_Constructor_to_raise_an_exception: "**bingo**", | ||
ShapeType.CIRCLE.key.should.equal("CIRCLE"); | ||
var value = ShapeType.CIRCLE; | ||
const value = ShapeType.CIRCLE; | ||
value.should.equal(ShapeType.CIRCLE); | ||
var shape = new Shape({name: "yo", shapeType: ShapeType.HEXAGON, inner_color: Color.RED, color: Color.BLUE}); | ||
const shape = new Shape({name: "yo", shapeType: ShapeType.HEXAGON, inner_color: Color.RED, color: Color.BLUE}); | ||
@@ -224,4 +224,4 @@ (function () { | ||
var shape = new Shape({name: "yo", shapeType: ShapeType.HEXAGON, inner_color: Color.RED, color: Color.BLUE}); | ||
var shape2 = new Shape({name: "yo", shapeType: "HEXAGON", inner_color: "RED", color: "BLUE"}); | ||
const shape = new Shape({name: "yo", shapeType: ShapeType.HEXAGON, inner_color: Color.RED, color: Color.BLUE}); | ||
const shape2 = new Shape({name: "yo", shapeType: "HEXAGON", inner_color: "RED", color: "BLUE"}); | ||
@@ -234,4 +234,4 @@ shape.should.eql(shape2); | ||
var shape = new Shape({name: "yo", shapeType: ShapeType.HEXAGON, inner_color: Color.RED, color: Color.BLUE}); | ||
var shape2 = new Shape({name: "yo", shapeType: 6, inner_color: 100, color: 200}); | ||
const shape = new Shape({name: "yo", shapeType: ShapeType.HEXAGON, inner_color: Color.RED, color: Color.BLUE}); | ||
const shape2 = new Shape({name: "yo", shapeType: 6, inner_color: 100, color: 200}); | ||
@@ -248,3 +248,3 @@ shape.should.eql(shape2); | ||
var shape = new Shape(); | ||
const shape = new Shape(); | ||
@@ -263,7 +263,7 @@ shape.binaryStoreSize().should.be.greaterThan(10); | ||
var shape = new Shape({name: "yo", shapeType: ShapeType.HEXAGON, inner_color: Color.RED, color: Color.BLUE}); | ||
const shape = new Shape({name: "yo", shapeType: ShapeType.HEXAGON, inner_color: Color.RED, color: Color.BLUE}); | ||
var str = JSON.stringify(shape); | ||
const str = JSON.stringify(shape); | ||
var obj = new Shape(JSON.parse(str)); | ||
const obj = new Shape(JSON.parse(str)); | ||
@@ -287,5 +287,5 @@ obj.should.eql(shape); | ||
generator.unregisterObject(exports.FakeBlob2_Schema, temporary_folder); | ||
var Blob = generator.registerObject(exports.FakeBlob2_Schema, temporary_folder); | ||
const Blob = generator.registerObject(exports.FakeBlob2_Schema, temporary_folder); | ||
var blob = new Blob({ | ||
const blob = new Blob({ | ||
buffer0: new Buffer("00FF00AA", "hex"), | ||
@@ -314,5 +314,5 @@ nodeId: "ns=1;s=toto" | ||
generator.unregisterObject(exports.FakeBlob3_Schema, temporary_folder); | ||
var Blob = generator.registerObject(exports.FakeBlob3_Schema, temporary_folder); | ||
const Blob = generator.registerObject(exports.FakeBlob3_Schema, temporary_folder); | ||
var blob = new Blob({ | ||
const blob = new Blob({ | ||
buffer0: [new Buffer("01020304", "hex"), [0, 1, 2, 3, 4]], | ||
@@ -325,7 +325,7 @@ nodeId: ["ns=1;s=toto", "ns=2;i=1234"] | ||
var str = JSON.stringify(blob); | ||
const str = JSON.stringify(blob); | ||
console.log("JSON string".yellow, str.cyan); | ||
var obj = new Blob(JSON.parse(str)); | ||
const obj = new Blob(JSON.parse(str)); | ||
@@ -361,6 +361,6 @@ obj.buffer0[0].should.eql(blob.buffer0[0]); | ||
var QualifiedName = generator.registerObject(exports.FakeQualifiedName_Schema, temporary_folder); | ||
const QualifiedName = generator.registerObject(exports.FakeQualifiedName_Schema, temporary_folder); | ||
var qname = new QualifiedName({ | ||
const qname = new QualifiedName({ | ||
namespaceIndex: 0 | ||
@@ -374,6 +374,6 @@ }); | ||
var str = JSON.stringify(qname); | ||
const str = JSON.stringify(qname); | ||
str.should.eql("{\"namespaceIndex\":0}"); | ||
var obj = new QualifiedName(JSON.parse(str)); | ||
const obj = new QualifiedName(JSON.parse(str)); | ||
obj.namespaceIndex.should.equal(0); | ||
@@ -401,5 +401,5 @@ should(_.isFinite(obj.namespaceIndex)).be.equal(true); | ||
generator.unregisterObject(exports.Blob4_Schema, temporary_folder); | ||
var Blob4 = generator.registerObject(exports.Blob4_Schema, temporary_folder); | ||
const Blob4 = generator.registerObject(exports.Blob4_Schema, temporary_folder); | ||
var blob4 = new Blob4({ | ||
const blob4 = new Blob4({ | ||
createdOn: null | ||
@@ -414,4 +414,4 @@ }); | ||
var utils = require("node-opcua-utils"); | ||
var fs = require("fs"); | ||
const utils = require("node-opcua-utils"); | ||
const fs = require("fs"); | ||
// delete existing file if any | ||
@@ -424,3 +424,3 @@ | ||
var ExtensionObject = require("node-opcua-status-code").ExtensionObject; | ||
const ExtensionObject = require("node-opcua-status-code").ExtensionObject; | ||
@@ -433,4 +433,4 @@ exports.Blob6_Schema = { | ||
var _defaultTypeMap = require("node-opcua-factory/src/factories_builtin_types")._defaultTypeMap; | ||
var findBuiltInType = require("node-opcua-factory/src/factories_builtin_types").findBuiltInType; | ||
const _defaultTypeMap = require("node-opcua-factory/src/factories_builtin_types")._defaultTypeMap; | ||
const findBuiltInType = require("node-opcua-factory/src/factories_builtin_types").findBuiltInType; | ||
@@ -444,8 +444,8 @@ Object.keys(_defaultTypeMap).forEach(function (key) { | ||
var options = {}; | ||
const options = {}; | ||
Object.keys(_defaultTypeMap).forEach(function (key) { | ||
if (key === "Any" || key === "Null" || key === "AccessLevelFlag") { return; } | ||
var type = _defaultTypeMap[key]; | ||
const type = _defaultTypeMap[key]; | ||
var random = type.random || ec["random" + type.name]; | ||
const random = type.random || ec["random" + type.name]; | ||
@@ -462,5 +462,5 @@ if (_.isFunction(random)) { | ||
var Blob6 = generator.registerObject(exports.Blob6_Schema, temporary_folder); | ||
const Blob6 = generator.registerObject(exports.Blob6_Schema, temporary_folder); | ||
var blob = new Blob6(options); | ||
const blob = new Blob6(options); | ||
//xx console.log(blob); | ||
@@ -479,4 +479,4 @@ encode_decode_round_trip_test(blob); | ||
it("should clone a Shape",function() { | ||
var shape = new Shape({name: "yo", shapeType: ShapeType.HEXAGON, inner_color: Color.RED, color: Color.BLUE}); | ||
var shape_clone = shape.clone(); | ||
const shape = new Shape({name: "yo", shapeType: ShapeType.HEXAGON, inner_color: Color.RED, color: Color.BLUE}); | ||
const shape_clone = shape.clone(); | ||
compare_obj_by_encoding(shape,shape_clone); | ||
@@ -483,0 +483,0 @@ }); |
"use strict"; | ||
var should = require("should"); | ||
var path = require("path"); | ||
const should = require("should"); | ||
const path = require("path"); | ||
var encode_decode_round_trip_test = require("node-opcua-packet-analyzer/test_helpers/encode_decode_round_trip_test").encode_decode_round_trip_test; | ||
const encode_decode_round_trip_test = require("node-opcua-packet-analyzer/test_helpers/encode_decode_round_trip_test").encode_decode_round_trip_test; | ||
@@ -10,3 +10,3 @@ | ||
var schema_file = path.join(__dirname,"./fixture/fixture_dummy_object_schema.js"); | ||
const schema_file = path.join(__dirname,"./fixture/fixture_dummy_object_schema.js"); | ||
@@ -16,6 +16,6 @@ it("should produce the javascript for new complex type using template ", function () { | ||
// code should compile | ||
var DummyObject = require(schema_file).DummyObject; | ||
var SomeEnumeration = require(schema_file).SomeEnumeration; | ||
const DummyObject = require(schema_file).DummyObject; | ||
const SomeEnumeration = require(schema_file).SomeEnumeration; | ||
var dummy = new DummyObject({ | ||
const dummy = new DummyObject({ | ||
viewVersion: 50, | ||
@@ -31,3 +31,3 @@ name: "Paris", | ||
var dummy_reloaded = encode_decode_round_trip_test(dummy); | ||
const dummy_reloaded = encode_decode_round_trip_test(dummy); | ||
@@ -46,6 +46,6 @@ dummy_reloaded.viewVersion.should.eql(dummy.viewVersion); | ||
var FooBarDerived = require(schema_file).FooBarDerived; | ||
var FooBar = require(schema_file).FooBar; | ||
const FooBarDerived = require(schema_file).FooBarDerived; | ||
const FooBar = require(schema_file).FooBar; | ||
var fb = new FooBarDerived({name: "toto", name2: "titi"}); | ||
const fb = new FooBarDerived({name: "toto", name2: "titi"}); | ||
fb.name.should.eql("toto"); | ||
@@ -57,3 +57,3 @@ fb.name2.should.eql("titi"); | ||
var fb_reloaded = encode_decode_round_trip_test(fb); | ||
const fb_reloaded = encode_decode_round_trip_test(fb); | ||
fb_reloaded.name.should.eql(fb.name); | ||
@@ -67,7 +67,7 @@ fb_reloaded.name2.should.eql(fb.name2); | ||
//xx should(function(){ | ||
var schema_file2 = path.join(__dirname,"./fixture/fixture_foo_object_with_recursion_schema.js"); | ||
var FooWithRecursion = require(schema_file2).FooWithRecursion; | ||
const schema_file2 = path.join(__dirname,"./fixture/fixture_foo_object_with_recursion_schema.js"); | ||
const FooWithRecursion = require(schema_file2).FooWithRecursion; | ||
//xx }).not.throwError(); | ||
var foo = new FooWithRecursion({}); | ||
let foo = new FooWithRecursion({}); | ||
@@ -74,0 +74,0 @@ should(foo.inner).be.eql(null); |
"use strict"; | ||
var should = require("should"); | ||
var _ = require("underscore"); | ||
const should = require("should"); | ||
const _ = require("underscore"); | ||
var generator = require("../src/generator"); | ||
var factories = require("node-opcua-factory"); | ||
const generator = require("../src/generator"); | ||
const factories = require("node-opcua-factory"); | ||
var redirectToFile = require("node-opcua-debug").redirectToFile; | ||
var makeExpandedNodeId = require("node-opcua-nodeid/src/expanded_nodeid").makeExpandedNodeId; | ||
const redirectToFile = require("node-opcua-debug").redirectToFile; | ||
const makeExpandedNodeId = require("node-opcua-nodeid/src/expanded_nodeid").makeExpandedNodeId; | ||
var BinaryStream = require("node-opcua-binary-stream").BinaryStream; | ||
var encode_decode_round_trip_test = require("node-opcua-packet-analyzer/test_helpers/encode_decode_round_trip_test").encode_decode_round_trip_test; | ||
var analyze_object_binary_encoding = require("node-opcua-packet-analyzer").analyze_object_binary_encoding; | ||
var compare_obj_by_encoding = require("node-opcua-packet-analyzer/test_helpers/compare_obj_by_encoding").compare_obj_by_encoding; | ||
const BinaryStream = require("node-opcua-binary-stream").BinaryStream; | ||
const encode_decode_round_trip_test = require("node-opcua-packet-analyzer/test_helpers/encode_decode_round_trip_test").encode_decode_round_trip_test; | ||
const analyze_object_binary_encoding = require("node-opcua-packet-analyzer").analyze_object_binary_encoding; | ||
const compare_obj_by_encoding = require("node-opcua-packet-analyzer/test_helpers/compare_obj_by_encoding").compare_obj_by_encoding; | ||
var Person_Schema = { | ||
const Person_Schema = { | ||
id: factories.next_available_id(), | ||
@@ -26,3 +26,3 @@ name: "Person", | ||
exports.Person_Schema = Person_Schema; | ||
var Role_Schema = { | ||
const Role_Schema = { | ||
id: factories.next_available_id(), | ||
@@ -37,3 +37,3 @@ name: "Role", | ||
var Employee_Schema = { | ||
const Employee_Schema = { | ||
id: factories.next_available_id(), | ||
@@ -50,3 +50,3 @@ name: "Employee", | ||
var Company_Schema = { | ||
const Company_Schema = { | ||
id: factories.next_available_id(), | ||
@@ -62,9 +62,9 @@ name: "Company", | ||
var path = require("path"); | ||
var temporary_folder = path.join(__dirname,"..","_test_generated"); | ||
const path = require("path"); | ||
const temporary_folder = path.join(__dirname,"..","_test_generated"); | ||
var Person = generator.registerObject(Person_Schema, temporary_folder); | ||
var Role = generator.registerObject(Role_Schema, temporary_folder); | ||
var Employee = generator.registerObject(Employee_Schema, temporary_folder); | ||
var Company = generator.registerObject(Company_Schema, temporary_folder); | ||
const Person = generator.registerObject(Person_Schema, temporary_folder); | ||
const Role = generator.registerObject(Role_Schema, temporary_folder); | ||
const Employee = generator.registerObject(Employee_Schema, temporary_folder); | ||
const Company = generator.registerObject(Company_Schema, temporary_folder); | ||
@@ -85,3 +85,3 @@ | ||
var person = new Person(); | ||
const person = new Person(); | ||
@@ -99,3 +99,3 @@ person.should.have.property("lastName"); | ||
var person = new Person({lastName: "Joe"}); | ||
const person = new Person({lastName: "Joe"}); | ||
@@ -109,3 +109,3 @@ person.lastName.should.equal("Joe"); | ||
var employee = new Employee({ | ||
const employee = new Employee({ | ||
lastName: "John", | ||
@@ -143,7 +143,7 @@ service: "R&D", | ||
var person = new Person({lastName: "Joe"}); | ||
const person = new Person({lastName: "Joe"}); | ||
person.age = 50; | ||
person.address = "Paris"; | ||
var person_reloaded = encode_decode_round_trip_test(person); | ||
const person_reloaded = encode_decode_round_trip_test(person); | ||
@@ -158,3 +158,3 @@ person.lastName.should.equal(person_reloaded.lastName); | ||
var employee = new Employee({lastName: "John", service: "R&D"}); | ||
const employee = new Employee({lastName: "John", service: "R&D"}); | ||
encode_decode_round_trip_test(employee); | ||
@@ -167,7 +167,7 @@ | ||
var company = new Company({name: "ACME"}); | ||
const company = new Company({name: "ACME"}); | ||
company.employees.length.should.equal(0); | ||
var employee = new Employee({lastName: "John", service: "R&D"}); | ||
const employee = new Employee({lastName: "John", service: "R&D"}); | ||
@@ -185,3 +185,3 @@ company.employees.push(employee); | ||
var company = new Company({ | ||
const company = new Company({ | ||
name: "ACME", | ||
@@ -203,3 +203,3 @@ employees: [ | ||
var company = new Company({ | ||
const company = new Company({ | ||
name: "ACME", | ||
@@ -226,3 +226,3 @@ company_values: [ | ||
var company = new Company({name: "ACME"}); | ||
const company = new Company({name: "ACME"}); | ||
company.encodingDefaultBinary.should.eql(makeExpandedNodeId(Company_Schema.id)); | ||
@@ -234,5 +234,5 @@ | ||
var getObjectClassName = require("node-opcua-utils").getObjectClassName; | ||
const getObjectClassName = require("node-opcua-utils").getObjectClassName; | ||
var obj = factories.constructObject(makeExpandedNodeId(Company_Schema.id)); | ||
const obj = factories.constructObject(makeExpandedNodeId(Company_Schema.id)); | ||
@@ -260,5 +260,5 @@ should(obj).have.property("_schema"); | ||
var Blob = generator.registerObject(exports.FakeBlob_Schema, temporary_folder); | ||
const Blob = generator.registerObject(exports.FakeBlob_Schema, temporary_folder); | ||
var blob = new Blob({buffer0: new Buffer(0), buffer1: new Buffer(1024)}); | ||
const blob = new Blob({buffer0: new Buffer(0), buffer1: new Buffer(1024)}); | ||
@@ -276,8 +276,8 @@ encode_decode_round_trip_test(blob); | ||
redirectToFile("pretty_print.log", function () { | ||
var company = new Company({name: "ACME"}); | ||
var employee = new Employee({lastName: "John", service: "R&D"}); | ||
const company = new Company({name: "ACME"}); | ||
const employee = new Employee({lastName: "John", service: "R&D"}); | ||
company.employees.push(employee); | ||
company.employees.push(new Employee({lastName: "Peter", service: "R&D"})); | ||
var str = company.explore(); | ||
const str = company.explore(); | ||
@@ -292,5 +292,5 @@ console.log(str); | ||
var someArray = [new Person({})]; | ||
const someArray = [new Person({})]; | ||
var str = JSON.stringify({stuff: someArray}, null, " "); | ||
const str = JSON.stringify({stuff: someArray}, null, " "); | ||
//xx console.log("xxxx str =",str); | ||
@@ -301,8 +301,8 @@ | ||
it("should clone an object ", function () { | ||
var company = new Company({name: "ACME"}); | ||
var employee = new Employee({lastName: "John", service: "R&D"}); | ||
const company = new Company({name: "ACME"}); | ||
const employee = new Employee({lastName: "John", service: "R&D"}); | ||
company.employees.push(employee); | ||
company.employees.push(new Employee({lastName: "Peter", service: "R&D"})); | ||
var company_copy = company.clone(); | ||
const company_copy = company.clone(); | ||
@@ -327,3 +327,3 @@ company_copy.constructor.name.should.eql("Company"); | ||
var company = new Company({ | ||
const company = new Company({ | ||
name: "ACME", | ||
@@ -335,3 +335,3 @@ employees: [ | ||
}); | ||
var stream = new BinaryStream(company.binaryStoreSize()); | ||
const stream = new BinaryStream(company.binaryStoreSize()); | ||
company.encode(stream); | ||
@@ -338,0 +338,0 @@ |
"use strict"; | ||
var should = require("should"); | ||
const should = require("should"); | ||
var generator = require(".."); | ||
var encode_decode_round_trip_test = require("node-opcua-packet-analyzer/test_helpers/encode_decode_round_trip_test").encode_decode_round_trip_test | ||
var _ = require("underscore"); | ||
const generator = require(".."); | ||
const encode_decode_round_trip_test = require("node-opcua-packet-analyzer/test_helpers/encode_decode_round_trip_test").encode_decode_round_trip_test; | ||
const _ = require("underscore"); | ||
var path = require("path"); | ||
var tmpfolder = path.join(__dirname,"../_test_generated"); | ||
var ObjWithIntegerId = generator.registerObject(path.join(__dirname,"./schemas")+"|ObjWithIntegerId", tmpfolder); | ||
const path = require("path"); | ||
const tmpfolder = path.join(__dirname,"../_test_generated"); | ||
const ObjWithIntegerId = generator.registerObject(path.join(__dirname,"./schemas")+"|ObjWithIntegerId", tmpfolder); | ||
@@ -18,3 +18,3 @@ | ||
var o = new ObjWithIntegerId({ | ||
const o = new ObjWithIntegerId({ | ||
requestHandle: 0 | ||
@@ -24,3 +24,3 @@ }); | ||
var obj_reloaded = encode_decode_round_trip_test(o); | ||
const obj_reloaded = encode_decode_round_trip_test(o); | ||
obj_reloaded.requestHandle.should.eql(0); | ||
@@ -31,3 +31,3 @@ | ||
var o = new ObjWithIntegerId({ | ||
const o = new ObjWithIntegerId({ | ||
requestHandle: 1 | ||
@@ -38,3 +38,3 @@ }); | ||
var obj_reloaded = encode_decode_round_trip_test(o); | ||
const obj_reloaded = encode_decode_round_trip_test(o); | ||
@@ -41,0 +41,0 @@ obj_reloaded.requestHandle.should.eql(1); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73187
1533
+ Addedansi-styles@3.2.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addednode-opcua-assert@0.3.0(transitive)
+ Addednode-opcua-basic-types@0.3.0(transitive)
+ Addednode-opcua-binary-stream@0.3.0(transitive)
+ Addednode-opcua-buffer-utils@0.3.0(transitive)
+ Addednode-opcua-date-time@0.3.0(transitive)
+ Addednode-opcua-debug@0.3.0(transitive)
+ Addednode-opcua-enum@0.3.0(transitive)
+ Addednode-opcua-factory@0.3.0(transitive)
+ Addednode-opcua-guid@0.3.0(transitive)
+ Addednode-opcua-nodeid@0.3.0(transitive)
+ Addednode-opcua-status-code@0.3.0(transitive)
+ Addednode-opcua-utils@0.3.0(transitive)
+ Addedsupports-color@5.5.0(transitive)
- Removednode-opcua-assert@0.2.0(transitive)
- Removednode-opcua-basic-types@0.2.3(transitive)
- Removednode-opcua-binary-stream@0.2.3(transitive)
- Removednode-opcua-buffer-utils@0.2.0(transitive)
- Removednode-opcua-date-time@0.2.3(transitive)
- Removednode-opcua-debug@0.2.2(transitive)
- Removednode-opcua-enum@0.2.3(transitive)
- Removednode-opcua-factory@0.2.3(transitive)
- Removednode-opcua-guid@0.2.0(transitive)
- Removednode-opcua-nodeid@0.2.3(transitive)
- Removednode-opcua-status-code@0.2.3(transitive)
- Removednode-opcua-utils@0.2.3(transitive)
Updatednode-opcua-assert@^0.3.0
Updatednode-opcua-debug@^0.3.0
Updatednode-opcua-factory@^0.3.0
Updatednode-opcua-nodeid@^0.3.0
Updatednode-opcua-utils@^0.3.0