UNPKG

node-red-contrib-prib-functions

Version:
477 lines (470 loc) 19.2 kB
<script type="text/javascript"> const setInput=(t,types=['str','json','env'])=>{ $("#node-input-"+t+"Type").val(this[t+"Type"]); $("#node-input-"+t).typedInput({ default: types[0], typeField: $("#node-input-"+t+"Type"), types:types, validate: ()=>{ } }); $("#node-input-"+t).typedInput('type',this[t+"Type"]); } const schemaExample='{"type":"record","fields":[{"name":"name","type":"string"}]}'; /*globals RED */ RED.nodes.registerType('transform', { category: 'function', color: '#fdeea2', defaults: { name: {value: ""}, actionSource: {value:"csv",required:true}, deleteSource: {value:true,validate: RED.validators.typedInput("deleteSourceType")}, deleteSourceType:{value:"bool"}, actionTarget: {value:"JSON",required:true}, sourceProperty:{value:"msg.payload"}, targetProperty:{value:"msg.payload"}, topicProperty:{value:"msg.topic"}, JSONataSource:{value:null,validate:v=>v==null||RED.validators.typedInput("JSONataSourceType")}, JSONataSourceType:{value:"jsonata"}, JSONataTarget:{value:null,validate:v=>v==null||RED.validators.typedInput("JSONataTargetType")}, JSONataTargetType:{value:"jsonata"}, index: {value:0}, maxMessages: {value:1000}, maxDate: {value:null}, minDate: {value:null}, maxNumber: {value:0}, minNumber: {value:0}, maxString: {value:""}, minString: {value:""}, radix: {value:10}, schema: {value:schemaExample, validate: RED.validators.typedInput("schemaType")}, schemaType: {value:"json"}, skipLeading: {value:0}, skipTrailing: {value:0}, radix: {value:10}, string: {value:"", validate: RED.validators.typedInput("stringType")}, stringType: {value:"str"}, delimiter: {value:",",required:true}, compressionType: {value:"gzip"} }, inputs: 1, outputs: 2, icon: "icons8-one-way-transition-80.png", align: 'left', paletteLabel: "transform", inputLabels: "Message In", outputLabels: ["Message Out","Error"], label: function () { return this.name ||this.actionSource+"=>"+this.actionTarget|| "Transform"; }, oneditprepare: function() { const actionTarget=this.actionTarget; $("#node-input-actionSource").typedInput({type:"actionSource", types:[{ value: "actionSource", options: [ { value: "Array", label: "Array"}, { value: "AVRO", label: "AVRO"}, { value: "Buffer", label: "Buffer"}, { value: "Compressed", label: "Compressed"}, { value: "Confluence", label: "Confluence"}, { value: "CSVWithHeader", label: "CSV with header"}, { value: "CSV", label: "CSV"}, { value: "Date", label: "Date"}, { value: "ISO8385", label: "ISO 8583"}, { value: "JSON", label: "JSON"}, { value: "npy", label: "npy"}, { value: "Number", label: "Number"}, { value: "NumPyObject", label: "NumPy Obect"}, { value: "String", label: "String"}, { value: "snappy", label: "Snappy"}, { value: "path", label: "Path"}, { value: "XLSX", label: "XLSX (excel)"}, { value: "XLSXObject", label: "XLSX object (excel)"}, { value: "XML", label: "XML"} ] }]}); $("#node-input-compressionType").typedInput({type:"compression", types:[{ value: "compression", options: [ { value: "setGzip", label: "gzip"}, { value: "setGzipSpeed", label: "gzip speed"}, { value: "setGzipCompression", label: "gzip compression"}, { value: "setZlib", label: "zip"}, { value: "setZlibSpeed", label: "zip speed"}, { value: "setZlibCompression", label: "zip compression"}, { value: "setLzma", label: "Lempel-Ziv-Markov speed"}, { value: "setLzmaCompression", label: "Lempel-Ziv-Markov compression"}, { value: "setBrotli", label: "Brotli"}, { value: "setSnappy", label: "Snappy"}, { value: "setFlate", label: "Deflate/Inflate"} ] }]}); $("#node-input-actionSource").change(function() { const actionSource=$(this).val(); $(".form-row-http-in-skip").hide(); $(".form-row-http-in-schema").hide(); $(".form-row-http-in-compressionType").hide(); $(".form-row-http-in-JSONataSource").hide(); if(!['CSV','CSVWithHeader'].includes(actionSource)) { $(".form-row-http-in-csv").hide(); } let options={}; switch (actionSource) { case 'Array': options["CSV"]="CSV"; options["HTML"]="HMTL"; options["ISO8385"]="ISO8385"; options["Messages"]="Messages"; options["XLSX"]="XLSX (excel)"; options["XLSXObject"]="XLSX object (excel)"; break; case 'AVRO': case 'Buffer': options["Compressed"]="Compressed"; break; case 'Confluence': options["JSON"]="JSON"; $(".form-row-http-in-schema").show(); break; case 'Compressed': options["JSON"]="JSON"; options["String"]="String"; options["Buffer"]="Buffer"; $(".form-row-http-in-compressionType").show(); break; case 'CSVWithHeader': options["JSON"]="JSON"; case 'CSV': $(".form-row-http-in-csv").show(); $(".form-row-http-in-skip").show(); options["Array"]="Array"; options["HTML"]="HTML"; options["Messages"]="Messages"; break; case 'Date': options["isBetween"]="is between"; options["RangeLimit"]="Range Limit"; options["ISODate"]="YYYY-MM-DD"; options["LocalDate"]="Local String"; break; case 'ISO8385': options["JSON"]="JSON"; options["Array"]="Array"; break; case 'JSON': $(".form-row-http-in-JSONataSource").show(); options["Array"]="Array"; options["AVRO"]="AVRO"; options["Compressed"]="Compressed"; options["Confluence"]="Confluence"; options["CSV"]="CSV"; options["ISO8385"]="ISO 8583"; options["HTML"]="HTML"; options["JSON"]="JSON"; options["Messages"]="Messages"; options["npy"]="npy"; options["NumPyObject"]="NumPy Object"; options["String"]="String"; options["XLSX"]="XLSX"; options["XLSXObject"]="XLSX Object"; options["XML"]="XML"; break; case 'npy': options["JSON"]="JSON"; options["NumPyObject"]="NumPy Object"; break; case 'Number': options["Abbreviated"]="Abbreviated"; options["RangeLimit"]="Range Limit"; options["isBetween"]="is Between"; break; case 'NumPyObject': options["JSON"]="JSON"; break; case 'Object': options["Coalesce"]="Coalesce"; options["Nullif"]="Nullif"; break; case 'path': options["Basename"]="basename"; options["Dirname"]="dirname"; options["Extname"]="extname"; options["IsAbsolute"]="isAbsolute"; options["Join"]="join"; options["Normalize"]="normalize"; options["Resolve"]="resolve"; break; case 'snappy': options["Uncompress"]="Uncompress"; options["Compress"]="Compress"; break; case 'String': options["Append"]="Append"; options["ArrayusingDelimiter"]="Array By Delimiter"; options["At"]="At"; options["Camelize"]="Camelize"; options["Capitalize"]="Capitalize"; options["Compressed"]="Compressed"; options["CharAt"]="Char At"; options["CharCodeAt"]="Char Code At"; options["CodePointAt"]="Code Point At"; options["Concat"]="Concat"; options["Date"]="Date"; options["DateLocal"]="Date Local"; options["DelimiterOnCase"]="Delimiter On Case"; options["Deunderscore"]="_ to space"; options["DeunderscoreCapitilize"]="_ to space Capitilize"; options["DropSquareBracketPrefix"]="Drop square bracket prefix"; options["EndsWith"]="Ends With"; options["Float"]="Float"; options["GetWord"]="Get Word"; options["Integer"]="Integer"; options["isBetween"]="is Between"; options["LowerCase"]="Lower Case"; options["Number"]="Number"; options["Prepend"]="Prepend"; options["JSON"]="JSON"; options["RangeLimit"]="Range Limit"; options["Split"]="Split"; options["StartsWith"]="Starts With"; options["Timestamp"]="Timestamp"; options["Title"]="Title"; options["TitleGrammatical"]="Title Grammatical"; options["Trim"]="Trim"; options["TrimEnd"]="Trim End"; options["TrimStart"]="Trim Start"; options["UpperCase"]="Upper Case"; options["XmlStringEncode"]="Xml String Encode"; break; case 'XLSX': options["XLSXObject"]="XLSX Object"; case 'XLSXObject': options["Array"]="Array"; options["JSON"]="JSON"; break; case 'XML': options["JSON"]="JSON"; break; default: options["Array"]="Array"; options["CSVWithHeader"]="CSV with header"; options["CSV"]="CSV"; options["ISO8385"]="ISO 8583"; options["HTML"]="HTML"; options["JSON"]="JSON"; options["String"]="String"; } const selectElement = $("#node-input-actionTarget"); selectElement.empty(); // remove old options $.each(options, function(key,value) { selectElement.append($("<option></option>").attr("value", key).text(value)); }); selectElement.val(actionTarget); }).change(); $("#node-input-actionTarget").change(function() { const actionTarget=$(this).val(); const actionSource=$("#node-input-actionSource").val(); $(".form-row-http-in-compressionType").hide(); $(".form-row-http-in-csv").hide(); $(".form-row-http-in-delimiter").hide(); $(".form-row-http-in-index").hide(); $(".form-row-http-in-length").hide(); $(".form-row-http-in-maxMessages").hide(); $(".form-row-http-in-maxDate").hide(); $(".form-row-http-in-maxNumber").hide(); $(".form-row-http-in-maxString").hide(); $(".form-row-http-in-minDate").hide(); $(".form-row-http-in-minNumber").hide(); $(".form-row-http-in-minString").hide(); $(".form-row-http-in-radix").hide(); $(".form-row-http-in-schema").hide(); $(".form-row-http-in-string").hide(); $(".form-row-http-in-JSONataTarget").hide(); switch (actionTarget) { case 'AVRO': case 'Confluence': $(".form-row-http-in-schema").show(); break; case 'Compressed': $(".form-row-http-in-compressionType").show(); break; case 'Messages': $(".form-row-http-in-maxMessages").show(); break; case 'Integer': $(".form-row-http-in-radix").show(); break; case 'At': case 'CharAt': case 'CharCodeAt': case 'CodePointAt': case 'GetWord': $(".form-row-http-in-index").show(); break; case 'EndsWith': case 'StartsWith': case 'Append': case 'Prepend': case 'Concat': case 'Split': $(".form-row-http-in-string").show(); break; case 'CSV': case 'DelimiterOnCase': case 'ArrayByDelimiter': $(".form-row-http-in-delimiter").show(); break; case 'RangeLimit': case 'isBetween': $(".form-row-http-in-max"+actionSource).show(); $(".form-row-http-in-min"+actionSource).show(); break; case 'JSON': $(".form-row-http-in-max"+actionSource).show(); $(".form-row-http-in-JSONataTarget").show(); break; } }).change(); setInput.apply(this,["JSONataSource",["jsonata"]]); setInput.apply(this,["JSONataTarget",["jsonata"]]); setInput.apply(this,["deleteSource",["bool"]]); setInput.apply(this,["schema"]); setInput.apply(this,["string",["str","msg","flow","global","env","node"]]); }, oneditsave: function() { }, resizeRule : function(file,newWidth) { } }); </script> <script type="text/x-red" data-template-name="transform"> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name </label> <input type="text" id="node-input-name" placeholder="Name"> </div> <div class="form-row form-row-http-in-sourceProperty show"> <label for="node-input-sourceProperty" style="white-space: nowrap"> Source Property </label> <input type="text" id="node-input-sourceProperty" placeholder="msg.payload"> </div> <div class="form-row form-row-http-in-deleteSource show"> <label for="node-input-deleteSource"><span data-i18n="common.label.string"> Delete?</span></label> <input type="text" id="node-input-deleteSource" style="width:70%"> <input type="hidden" id="node-input-deleteSourceType"> </div> <div class="form-row form-row-http-in-targetProperty show"> <label for="node-input-targetProperty" style="white-space: nowrap"> Target Property </label> <input type="text" id="node-input-targetProperty" placeholder="msg.payload"> </div> <div class="form-row form-row-http-in-topicProperty show"> <label for="node-input-topicProperty" style="white-space: nowrap"><i class="icon-bookmark"></i> Topic Property </label> <input type="text" id="node-input-topicProperty" placeholder="msg.topic"> </div> <div class="form-row"> <label for="node-input-actionSource"><i class="fa fa-list-ul"></i> Source Type </label> <input type="text" id="node-input-actionSource"> </div> <div class="form-row form-row-http-in-JSONataSource hide"> <label for="node-input-JSONataSource"><i class="fa fa-bookmark"></i> <span data-i18n="common.label.string"> JSONata Source</span></label> <input type="text" id="node-input-JSONataSource" style="width:70%"> <input type="hidden" id="node-input-JSONataSourceType"> </div> <div class="form-row"> <label for="node-input-actionTarget"><i class="fa fa-list-ul"></i> Target Type </label> <select id="node-input-actionTarget" placeholder="actionTarget"> </select> </div> <div class="form-row form-row-http-in-JSONataTarget hide"> <label for="node-input-JSONataTarget"><i class="fa fa-bookmark"></i> <span data-i18n="common.label.string"> JSONata Target</span></label> <input type="text" id="node-input-JSONataTarget" style="width:70%"> <input type="hidden" id="node-input-JSONataTargetType"> </div> <div class="form-row form-row-http-in-delimiter hide"> <label for="node-input-delimiter"><i class="icon-bookmark"></i> Delimiter</label> <input type="text" id="node-input-delimiter" placeholder="delimiter" size="1" minlength="1"> </div> <div class="form-row form-row-http-in-index hide"> <label for="node-input-index"><i class="icon-bookmark"></i> Index</label> <input type="number" id="node-input-index" placeholder="index" min="-10000" max="10000" step="1"> </div> <div class="form-row form-row-http-in-skip hide"> <label for="node-input-skipLeading"><i class="icon-bookmark"></i> Skip Leading</label> <input type="number" id="node-input-skipLeading" placeholder="skipLeading" min="0" max="10000" step="1"> <label for="node-input-skipTrailing"><i class="icon-bookmark"></i> Skip Trailing</label> <input type="number" id="node-input-skipTrailing" placeholder="skipTrailing" min="0" max="10000" step="1"> </div> <div class="form-row form-row-http-in-maxMessages hide"> <label for="node-input-maxMessages"><i class="icon-bookmark"></i> Max Messages</label> <input type="number" id="node-input-maxMessages" placeholder="maxMessages" min="1" max="36" step="1"> </div> <div class="form-row form-row-http-in-minNumber hide"> <label for="node-input-minNumber"><i class="icon-bookmark"></i> Min</label> <input type="number" id="node-input-minNumber" placeholder="min"> </div> <div class="form-row form-row-http-in-maxNumber hide"> <label for="node-input-maxNumber"><i class="icon-bookmark"></i> Max</label> <input type="number" id="node-input-maxNumber" placeholder="max"> </div> <div class="form-row form-row-http-in-minString hide"> <label for="node-input-minString"><i class="icon-bookmark"></i> Min</label> <input type="text" id="node-input-minString" placeholder="min"> </div> <div class="form-row form-row-http-in-maxString hide"> <label for="node-input-maxString"><i class="icon-bookmark"></i> Max</label> <input type="text" id="node-input-maxString" placeholder="max"> </div> <div class="form-row form-row-http-in-minDate hide"> <label for="node-input-minDate"><i class="icon-bookmark"></i> Min</label> <input type="date" id="node-input-minDate" placeholder="min"> </div> <div class="form-row form-row-http-in-maxDate hide"> <label for="node-input-maxDate"><i class="icon-bookmark"></i> Max</label> <input type="date" id="node-input-maxDate" placeholder="max"> </div> <div class="form-row form-row-http-in-length hide"> <label for="node-input-length"><i class="icon-bookmark"></i> Length</label> <input type="number" id="node-input-length" placeholder="length" min="1" max="1000" step="1"> </div> <div class="form-row form-row-http-in-radix hide"> <label for="node-input-radix"><i class="icon-bookmark"></i> Radix</label> <input type="number" id="node-input-radix" placeholder="radix" min="2" max="10000" step="100"> </div> <div class="form-row form-row-http-in-schema hide"> <label for="node-input-schema"><i class="fa fa-envelope"></i> <span data-i18n="common.label.schema"> Schema </span></label> <input type="text" id="node-input-schema" style="width:70%"> <input type="hidden" id="node-input-schemaType"> </div> <div class="form-row form-row-http-in-compressionType hide"> <label for="node-input-compressionType"><i class="fa fa-envelope"></i> <span data-i18n="common.label.compressionType"> Type </span></label> <input type="text" id="node-input-compressionType"> </div> <div class="form-row form-row-http-in-string hide"> <label for="node-input-string"><i class="fa fa-bookmark"></i> <span data-i18n="common.label.string"> String</span></label> <input type="text" id="node-input-string" style="width:70%"> <input type="hidden" id="node-input-stringType"> </div> </script> <script type="text/x-red" data-help-name="transform"> <p>translates msg payload from one form to another</p> <p> Source/Target/Topic allows the override of the property to an expression which can reference RED, node or msg variables. Target and Topic have extra one called "data" which is the transformed data and if to messages "index" which is the sequence number of message cloned. </p> <p> If AVRO or Confluence then schema appears. Schema must be detailed and for confluence it is an array of schemas with id. If confluence the value has form {schema:<id>,data:<data>} where id must be a number as per confluence requirements. </p> <h3>Inputs</h3> <dl class="message-properties"> <dt>msg <span class="property-type">topic</span></dt> <dd>incoming message with topic</dd> <dt>msg <span class="property-type">payload</span></dt> <dd></dd> </dl> <h3>Ports</h3> <dl class="message-properties"> <dt><span class="property-type">message out</span></dt> <dd>a message with payload which has be transformed</dd> <dt><span class="property-type">error</span></dt> <dd>a message where msg.error details error during transformation</dd> </dl> </script>