node-opcua-factory
Advanced tools
Comparing version 2.5.1 to 2.5.2
@@ -11,2 +11,3 @@ "use strict"; | ||
const node_opcua_debug_1 = require("node-opcua-debug"); | ||
const node_opcua_nodeid_1 = require("node-opcua-nodeid"); | ||
const utils = require("node-opcua-utils"); | ||
@@ -20,2 +21,3 @@ const _ = require("underscore"); | ||
const types_1 = require("./types"); | ||
const node_opcua_basic_types_1 = require("node-opcua-basic-types"); | ||
function r(str, length = 30) { | ||
@@ -67,3 +69,3 @@ return (str + " ").substr(0, length); | ||
const _nbElements = process.env.ARRAYLENGTH ? parseInt(process.env.ARRAYLENGTH, 10) : 10; | ||
function _arrayEllipsis(value) { | ||
function _arrayEllipsis(value, data) { | ||
if (!value) { | ||
@@ -79,2 +81,5 @@ return "null []"; | ||
const m = Math.min(_nbElements, value.length); | ||
const ellipsis = (value.length > _nbElements ? " ... " : ""); | ||
const pad = data.padding + " "; | ||
let isMultiLine = true; | ||
for (let i = 0; i < m; i++) { | ||
@@ -85,5 +90,29 @@ let element = value[i]; | ||
} | ||
v.push(!utils.isNullOrUndefined(element) ? element.toString() : null); | ||
else if (utils.isNullOrUndefined(element)) { | ||
element = "null"; | ||
} | ||
else { | ||
element = element.toString(); | ||
const s = element.split("\n"); | ||
if (s.length > 1) { | ||
element = "\n" + pad + s.join("\n" + pad); | ||
isMultiLine = true; | ||
} | ||
} | ||
if (element.length > 80) { | ||
isMultiLine = true; | ||
} | ||
v.push(element); | ||
} | ||
return "[ " + v.join(",") + (value.length > 10 ? " ... " : "") + "] (l=" + value.length + ")"; | ||
const length = "/* length =" + value.length + "*/"; | ||
if (isMultiLine) { | ||
return "[ " + length + | ||
"\n" + pad | ||
+ v.join(",\n" + pad + " ") | ||
+ ellipsis + "\n" + data.padding | ||
+ "]"; | ||
} | ||
else { | ||
return "[ " + length + v.join(",") + ellipsis + "]"; | ||
} | ||
} | ||
@@ -137,2 +166,8 @@ } | ||
} | ||
if (fieldType === "DataValue" && !field.isArray && value) { | ||
value = value.toString(data); | ||
str = fieldNameF + " " + fieldTypeF + ": " + chalk.green(value.toString(data)); | ||
data.lines.push(str); | ||
return; | ||
} | ||
function _dump_simple_value(self, field, data, value, fieldType) { | ||
@@ -147,8 +182,17 @@ let str = ""; | ||
if (field.isArray) { | ||
str = fieldNameF + " " + fieldTypeF + ": " + _arrayEllipsis(value); | ||
str = fieldNameF + " " + fieldTypeF + ": " + _arrayEllipsis(value, data); | ||
} | ||
else { | ||
if (fieldType === "IntegerId" || fieldType === "UInt32") { | ||
value = "" + value + " " + ((value !== undefined) ? "0x" + value.toString(16) : "undefined"); | ||
if (field.fieldType === "NodeId" && value instanceof node_opcua_nodeid_1.NodeId) { | ||
value = value.displayText(); | ||
} | ||
else if (fieldType === "IntegerId" || fieldType === "UInt32") { | ||
if (field.name === "attributeId") { | ||
value = "AttributeIds." + node_opcua_basic_types_1.AttributeIds[value] + "/* " + value + " */"; | ||
} | ||
else { | ||
const extra = ((value !== undefined) ? "0x" + value.toString(16) : "undefined"); | ||
value = "" + value + " " + extra; | ||
} | ||
} | ||
else if (fieldType === "DateTime" || fieldType === "UtcTime") { | ||
@@ -174,3 +218,5 @@ value = (value && value.toISOString) ? value.toISOString() : value; | ||
const typeDictionary = self.schema.$$factory; | ||
// istanbul ignore next | ||
if (!typeDictionary) { | ||
// tslint:disable-next-line: no-console | ||
console.log(" No typeDictionary for ", self.schema); | ||
@@ -195,3 +241,6 @@ } | ||
data.lines.push(padding + chalk.cyan(" { " + ("/*" + i + "*/"))); | ||
const data1 = { padding: padding + " ", lines: [] }; | ||
const data1 = { | ||
lines: [], | ||
padding: padding + " " | ||
}; | ||
applyOnAllSchemaFields(element, _newFieldSchema, data1, _exploreObject, args); | ||
@@ -219,2 +268,3 @@ data.lines = data.lines.concat(data1.lines); | ||
const s = field.schema; | ||
// istanbul ignore next | ||
if (!s.typedEnum) { | ||
@@ -224,3 +274,3 @@ // tslint:disable:no-console | ||
} | ||
str = fieldNameF + " " + fieldTypeF + ": " + s.typedEnum.get(value) + " ( " + value + ")"; | ||
str = fieldNameF + " " + fieldTypeF + ": " + s.name + "." + s.typedEnum.get(value).key + " ( " + value + ")"; | ||
data.lines.push(str); | ||
@@ -252,3 +302,3 @@ break; | ||
} | ||
function _JSONify(self, schema, options) { | ||
function _JSONify(self, schema, pojo) { | ||
/* jshint validthis: true */ | ||
@@ -264,6 +314,6 @@ for (const field of schema.fields) { | ||
if (field.isArray) { | ||
options[field.name] = f.map((value) => enumeration.enumValues[value.toString()]); | ||
pojo[field.name] = f.map((value) => enumeration.enumValues[value.toString()]); | ||
} | ||
else { | ||
options[field.name] = enumeration.enumValues[f.toString()]; | ||
pojo[field.name] = enumeration.enumValues[f.toString()]; | ||
} | ||
@@ -274,6 +324,6 @@ continue; | ||
if (field.isArray) { | ||
options[field.name] = f.map((value) => json_ify(t, value, field, value)); | ||
pojo[field.name] = f.map((value) => json_ify(t, value, field, value)); | ||
} | ||
else { | ||
options[field.name] = json_ify(t, f, field, f); | ||
pojo[field.name] = json_ify(t, f, field, f); | ||
} | ||
@@ -400,5 +450,5 @@ } | ||
const schema = this.schema; | ||
const options = {}; | ||
_visitSchemaChain(this, schema, options, _JSONify, null); | ||
return options; | ||
const pojo = {}; | ||
_visitSchemaChain(this, schema, pojo, _JSONify, null); | ||
return pojo; | ||
} | ||
@@ -428,3 +478,3 @@ } | ||
exports.BaseUAObject = BaseUAObject; | ||
function _visitSchemaChain(self, schema, options, func, extraData) { | ||
function _visitSchemaChain(self, schema, pojo, func, extraData) { | ||
node_opcua_assert_1.assert(_.isFunction(func)); | ||
@@ -434,6 +484,6 @@ // apply also construct to baseType schema first | ||
if (baseSchema) { | ||
_visitSchemaChain(self, baseSchema, options, func, extraData); | ||
_visitSchemaChain(self, baseSchema, pojo, func, extraData); | ||
} | ||
func.call(null, self, schema, options); | ||
func.call(null, self, schema, pojo); | ||
} | ||
//# sourceMappingURL=factories_baseobject.js.map |
{ | ||
"name": "node-opcua-factory", | ||
"version": "2.5.1", | ||
"version": "2.5.2", | ||
"description": "pure nodejs OPCUA SDK - module -factory", | ||
@@ -15,8 +15,8 @@ "main": "./dist/index.js", | ||
"node-opcua-assert": "^2.5.1", | ||
"node-opcua-basic-types": "^2.5.1", | ||
"node-opcua-basic-types": "^2.5.2", | ||
"node-opcua-binary-stream": "^2.5.1", | ||
"node-opcua-debug": "^2.5.1", | ||
"node-opcua-enum": "^2.5.1", | ||
"node-opcua-enum": "^2.5.2", | ||
"node-opcua-guid": "^2.5.1", | ||
"node-opcua-nodeid": "^2.5.1", | ||
"node-opcua-nodeid": "^2.5.2", | ||
"node-opcua-status-code": "^2.5.1", | ||
@@ -41,3 +41,3 @@ "node-opcua-utils": "^2.5.1", | ||
"homepage": "http://node-opcua.github.io/", | ||
"gitHead": "4cc18f384bbdf33c5cdd2a7857e810425aa67c8b" | ||
"gitHead": "923fb4060b27a91f5f8cebeb1294c48a8e8e8ff9" | ||
} |
@@ -9,2 +9,3 @@ /** | ||
import { hexDump } from "node-opcua-debug"; | ||
import { NodeId } from "node-opcua-nodeid"; | ||
import * as utils from "node-opcua-utils"; | ||
@@ -19,2 +20,3 @@ import * as _ from "underscore"; | ||
import { EnumerationDefinition, FieldCategory, StructuredTypeField } from "./types"; | ||
import { AttributeIds } from "node-opcua-basic-types"; | ||
@@ -63,3 +65,3 @@ function r(str: string, length = 30) { | ||
type Func1 = (a: any, field: StructuredTypeField, data: any, args: any) => void; | ||
type Func1 = (a: any, field: StructuredTypeField, data: ExploreParams, args: any) => void; | ||
@@ -69,3 +71,3 @@ function applyOnAllSchemaFields( | ||
schema: StructuredTypeSchema, | ||
data: any, | ||
data: ExploreParams, | ||
functor: Func1, | ||
@@ -87,3 +89,3 @@ args: any | ||
function _arrayEllipsis(value: any[] | null) { | ||
function _arrayEllipsis(value: any[] | null, data: ExploreParams): string { | ||
@@ -97,4 +99,10 @@ if (!value) { | ||
assert(_.isArray(value)); | ||
const v = []; | ||
const m = Math.min(_nbElements, value.length); | ||
const ellipsis = (value.length > _nbElements ? " ... " : ""); | ||
const pad = data.padding + " "; | ||
let isMultiLine = true; | ||
for (let i = 0; i < m; i++) { | ||
@@ -104,10 +112,36 @@ let element = value[i]; | ||
element = hexDump(element, 32, 16); | ||
} else if (utils.isNullOrUndefined(element)) { | ||
element = "null"; | ||
} else { | ||
element = element.toString(); | ||
const s = element.split("\n"); | ||
if (s.length > 1) { | ||
element = "\n" + pad + s.join("\n" + pad); | ||
isMultiLine = true; | ||
} | ||
} | ||
v.push(!utils.isNullOrUndefined(element) ? element.toString() : null); | ||
if (element.length > 80) { | ||
isMultiLine = true; | ||
} | ||
v.push(element); | ||
} | ||
return "[ " + v.join(",") + (value.length > 10 ? " ... " : "") + "] (l=" + value.length + ")"; | ||
const length = "/* length =" + value.length + "*/"; | ||
if (isMultiLine) { | ||
return "[ " + length + | ||
"\n" + pad | ||
+ v.join(",\n" + pad + " ") | ||
+ ellipsis + "\n" + data.padding | ||
+ "]"; | ||
} else { | ||
return "[ " + length + v.join(",") + ellipsis + "]"; | ||
} | ||
} | ||
} | ||
function _exploreObject(self: BaseUAObject, field: StructuredTypeField, data: any, args: any) { | ||
interface ExploreParams { | ||
padding: string; | ||
lines: string[]; | ||
} | ||
function _exploreObject(self: BaseUAObject, field: StructuredTypeField, data: ExploreParams, args: any) { | ||
@@ -170,4 +204,16 @@ if (!self) { | ||
} | ||
if (fieldType === "DataValue" && !field.isArray && value) { | ||
value = value.toString(data); | ||
str = fieldNameF + " " + fieldTypeF + ": " + chalk.green(value.toString(data)); | ||
data.lines.push(str); | ||
return; | ||
} | ||
function _dump_simple_value(self: BaseUAObject, field: StructuredTypeField, data: any, value: any, fieldType: string) { | ||
function _dump_simple_value( | ||
self: BaseUAObject, | ||
field: StructuredTypeField, | ||
data: ExploreParams, | ||
value: any, | ||
fieldType: string | ||
) { | ||
@@ -183,6 +229,16 @@ let str = ""; | ||
if (field.isArray) { | ||
str = fieldNameF + " " + fieldTypeF + ": " + _arrayEllipsis(value); | ||
str = fieldNameF + " " + fieldTypeF + ": " + _arrayEllipsis(value, data); | ||
} else { | ||
if (fieldType === "IntegerId" || fieldType === "UInt32") { | ||
value = "" + value + " " + ((value !== undefined) ? "0x" + value.toString(16) : "undefined"); | ||
if (field.fieldType === "NodeId" && value instanceof NodeId) { | ||
value = value.displayText(); | ||
} else if (fieldType === "IntegerId" || fieldType === "UInt32") { | ||
if (field.name === "attributeId") { | ||
value = "AttributeIds." + AttributeIds[value] + "/* " + value + " */"; | ||
} else { | ||
const extra = ((value !== undefined) ? "0x" + value.toString(16) : "undefined"); | ||
value = "" + value + " " + extra; | ||
} | ||
} else if (fieldType === "DateTime" || fieldType === "UtcTime") { | ||
@@ -200,3 +256,10 @@ value = (value && value.toISOString) ? value.toISOString() : value; | ||
function _dump_complex_value(self: BaseUAObject, field: StructuredTypeField, data: any, value: any, fieldType: string) { | ||
function _dump_complex_value( | ||
self: BaseUAObject, | ||
field: StructuredTypeField, | ||
data: ExploreParams, | ||
value: any, | ||
fieldType: string | ||
) { | ||
if (field.subType) { | ||
@@ -210,3 +273,5 @@ // this is a synonymous | ||
const typeDictionary = (self.schema as any).$$factory as DataTypeFactory; | ||
// istanbul ignore next | ||
if (!typeDictionary) { | ||
// tslint:disable-next-line: no-console | ||
console.log(" No typeDictionary for ", self.schema); | ||
@@ -227,3 +292,2 @@ } | ||
data.lines.push(fieldNameF + " " + fieldTypeF + ": ["); | ||
const m = Math.min(_nbElements, value.length); | ||
@@ -235,4 +299,8 @@ | ||
const data1 = { padding: padding + " ", lines: [] }; | ||
const data1 = { | ||
lines: [], | ||
padding: padding + " " | ||
}; | ||
applyOnAllSchemaFields(element, _newFieldSchema, data1, _exploreObject, args); | ||
data.lines = data.lines.concat(data1.lines); | ||
@@ -264,2 +332,4 @@ | ||
const s = field.schema as EnumerationDefinition; | ||
// istanbul ignore next | ||
if (!s.typedEnum) { | ||
@@ -269,3 +339,3 @@ // tslint:disable:no-console | ||
} | ||
str = fieldNameF + " " + fieldTypeF + ": " + s.typedEnum.get(value) + " ( " + value + ")"; | ||
str = fieldNameF + " " + fieldTypeF + ": " + s.name + "." + s.typedEnum.get(value)!.key + " ( " + value + ")"; | ||
data.lines.push(str); | ||
@@ -298,3 +368,3 @@ break; | ||
function _JSONify(self: BaseUAObject, schema: StructuredTypeSchema, options: any) { | ||
function _JSONify(self: BaseUAObject, schema: StructuredTypeSchema, pojo: any) { | ||
@@ -312,5 +382,5 @@ /* jshint validthis: true */ | ||
if (field.isArray) { | ||
options[field.name] = f.map((value: any) => enumeration.enumValues[value.toString()]); | ||
pojo[field.name] = f.map((value: any) => enumeration.enumValues[value.toString()]); | ||
} else { | ||
options[field.name] = enumeration.enumValues[f.toString()]; | ||
pojo[field.name] = enumeration.enumValues[f.toString()]; | ||
} | ||
@@ -324,5 +394,5 @@ | ||
if (field.isArray) { | ||
options[field.name] = f.map((value: any) => json_ify(t, value, field, value)); | ||
pojo[field.name] = f.map((value: any) => json_ify(t, value, field, value)); | ||
} else { | ||
options[field.name] = json_ify(t, f, field, f); | ||
pojo[field.name] = json_ify(t, f, field, f); | ||
} | ||
@@ -484,5 +554,5 @@ } | ||
const schema = this.schema; | ||
const options = {}; | ||
_visitSchemaChain(this, schema, options, _JSONify, null); | ||
return options; | ||
const pojo = {}; | ||
_visitSchemaChain(this, schema, pojo, _JSONify, null); | ||
return pojo; | ||
} | ||
@@ -520,4 +590,4 @@ } | ||
schema: StructuredTypeSchema, | ||
options: any, | ||
func: (self: BaseUAObject, schema: StructuredTypeSchema, options: any) => void, | ||
pojo: any, | ||
func: (self: BaseUAObject, schema: StructuredTypeSchema, pojo: any) => void, | ||
extraData: any | ||
@@ -530,5 +600,5 @@ ) { | ||
if (baseSchema) { | ||
_visitSchemaChain(self, baseSchema, options, func, extraData); | ||
_visitSchemaChain(self, baseSchema, pojo, func, extraData); | ||
} | ||
func.call(null, self, schema, options); | ||
func.call(null, self, schema, pojo); | ||
} |
Sorry, the diff of this file is not supported yet
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
224132
4161
Updatednode-opcua-enum@^2.5.2
Updatednode-opcua-nodeid@^2.5.2