node-red-contrib-prib-functions
Advanced tools
Comparing version 0.11.1 to 0.12.0
{ | ||
"name": "node-red-contrib-prib-functions", | ||
"version": "0.11.1", | ||
"version": "0.12.0", | ||
"description": "Node-RED added node functions.", | ||
@@ -8,3 +8,3 @@ "dependencies": { | ||
"avsc": "*", | ||
"snappy": "*" | ||
"fast-xml-parser": "*" | ||
}, | ||
@@ -91,2 +91,4 @@ "devDependencies": { | ||
"WMA", | ||
"xml", | ||
"XML", | ||
"Z-score" | ||
@@ -93,0 +95,0 @@ ], |
@@ -77,3 +77,3 @@ # [node-red-contrib-prib-functions][2] | ||
* Array to Messages | ||
* AVRO to JSON | ||
* AVRO to JSON (uses [avsc][6]) | ||
* CSV to Array | ||
@@ -89,6 +89,7 @@ * CSV to HTML | ||
* JSON to CSV | ||
* JSON to AVRO | ||
* JSON to AVRO (uses [avsc][6]) | ||
* JSON to ISO8385 | ||
* JSON to Messages | ||
* JSON to String | ||
* JSON to XML (uses [fast-xml-parser][4]) | ||
* String to JSON | ||
@@ -104,5 +105,8 @@ * path to Basename | ||
* path to Resolve | ||
* snappy compress | ||
* snappy uncompress | ||
* snappy compress (uses [snappy][5], must install separately) | ||
* snappy uncompress (uses [snappy][5], must install separately) | ||
* XML to JSON (uses [fast-xml-parser][4]) | ||
Note, snappy needs to be installed separately as can have issues with auto install as build binaries. | ||
Example AVRO with schema | ||
@@ -235,2 +239,3 @@ | ||
0.12.0 added xml to json and json to xml. Make snappy installed separately as can cause install issues | ||
@@ -293,1 +298,7 @@ 0.11.1 Fix spelling of AVRO. | ||
[3]: https://github.com/peterprib "base github" | ||
[4]: https://github.com/NaturalIntelligence/fast-xml-parser "fast-xml-parser" | ||
[5]: https://www.npmjs.com/package/snappy "snappy" | ||
[6]: https://www.npmjs.com/package/avsc "avsc" |
@@ -8,7 +8,23 @@ const logger = new (require("node-red-contrib-logger"))("transform"); | ||
process=require('process'); | ||
const avsc = require('avsc'); | ||
const snappy = require('snappy'); | ||
let avsc,snappy,xmlParser,json2xmlParser; | ||
const {ISO8583BitMapId,ISO8583BitMapName}=require("./ISO8583BitMap"); | ||
let ISO8583,ISO8583message; | ||
const XMLoptions = { | ||
// attributeNamePrefix : "@_", | ||
// attrNodeName: "attr", //default is 'false' | ||
// textNodeName : "#text", | ||
ignoreAttributes : false, | ||
ignoreNameSpace : false, | ||
allowBooleanAttributes : true, | ||
parseNodeValue : true, | ||
parseAttributeValue : false, | ||
// cdataTagName: "__cdata", //default is 'false' | ||
// cdataPositionChar: "\\c", | ||
// parseTrueNumberOnly: false, | ||
// arrayMode: false, //"strict" | ||
// attrValueProcessor: (val, attrName) => he.decode(val, {isAttributeValue: true}),//default is a=>a | ||
// tagValueProcessor : (val, tagName) => he.decode(val), //default is a=>a | ||
// stopNodes: ["parse-me-as-string"] | ||
trimValues: false | ||
}; | ||
function error(node,ex,shortMessage){ | ||
@@ -194,2 +210,3 @@ if(logger.active) logger.send({label:"transformNode catch",shortMessage:shortMessage,error:ex.message,stack:ex.stack}); | ||
JSONToString: (RED,node,msg,data)=>JSON.stringify(data), | ||
JSONToXML: (RED,node,msg,data)=>json2xmlParser.parse(data), | ||
StringToJSON: (RED,node,msg,data)=>JSON.parse(data), | ||
@@ -229,2 +246,3 @@ pathToBasename: (RED,node,msg,data)=>path.basename(data), | ||
}, | ||
XMLToJSON: (RED,node,msg,data)=>xmlParser.parse(data,XMLoptions,true), | ||
invalidArray:(v=>!Array.isArray(v)) | ||
@@ -240,2 +258,5 @@ }; | ||
} | ||
function is(node,value){ | ||
return node.actionSource==value||node.actionTarget==value; | ||
} | ||
module.exports = function (RED) { | ||
@@ -246,2 +267,14 @@ function transformNode(n) { | ||
let node=Object.assign(this,{maxMessages:1000,SendArray:SendArray},n,{RED:RED}); | ||
if(is(node,"AVRO")) { | ||
if(avsc==null) avsc=require('avsc'); | ||
} else if(is(node,"snappy")) { | ||
if(snappy==null) snappy=require('snappy'); | ||
} else if(is(node,"XML")) { | ||
if(xmlParser==null) xmlParser=require('fast-xml-parser'); | ||
if(json2xmlParser==null) { | ||
const j2xParser=xmlParser.j2xParser; | ||
json2xmlParser=new j2xParser(XMLoptions); | ||
} | ||
if(logger.active) logger.send({label:"load xml",xmlParserKeys:Object.keys(xmlParser),json2xmlParser:Object.keys(json2xmlParser)}); | ||
} | ||
node.sendInFunction=["snappy"].includes(node.actionSource)||["Messages"].includes(node.actionTarget); | ||
@@ -285,3 +318,3 @@ node.hasNewTopic=![null,""].includes(node.topicProperty); | ||
node.transform=functions[node.actionSource+"To"+node.actionTarget]; | ||
if(!node.transform) throw Error("transform routine not found"); | ||
if(!node.transform) throw Error("transform routine not found for "+node.actionSource+" to "+node.actionTarget); | ||
} catch (ex) { | ||
@@ -288,0 +321,0 @@ error(node,ex,node.actionSource+"\nto "+node.actionTarget + " not implemented") |
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
1203510
59
2096
300
+ Addedfast-xml-parser@*
+ Addedfast-xml-parser@4.5.0(transitive)
+ Addedstrnum@1.0.5(transitive)
- Removedsnappy@*
- Removed@napi-rs/snappy-android-arm-eabi@7.2.2(transitive)
- Removed@napi-rs/snappy-android-arm64@7.2.2(transitive)
- Removed@napi-rs/snappy-darwin-arm64@7.2.2(transitive)
- Removed@napi-rs/snappy-darwin-x64@7.2.2(transitive)
- Removed@napi-rs/snappy-freebsd-x64@7.2.2(transitive)
- Removed@napi-rs/snappy-linux-arm-gnueabihf@7.2.2(transitive)
- Removed@napi-rs/snappy-linux-arm64-gnu@7.2.2(transitive)
- Removed@napi-rs/snappy-linux-arm64-musl@7.2.2(transitive)
- Removed@napi-rs/snappy-linux-x64-gnu@7.2.2(transitive)
- Removed@napi-rs/snappy-linux-x64-musl@7.2.2(transitive)
- Removed@napi-rs/snappy-win32-arm64-msvc@7.2.2(transitive)
- Removed@napi-rs/snappy-win32-ia32-msvc@7.2.2(transitive)
- Removed@napi-rs/snappy-win32-x64-msvc@7.2.2(transitive)
- Removedsnappy@7.2.2(transitive)