dbgate-plugin-csv
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -1,1 +0,1 @@ | ||
module.exports=function(t){var e={};function i(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,o){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(i.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(o,r,function(e){return t[e]}.bind(null,r));return o},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=7)}([function(t,e){t.exports=require("stream")},function(t,e,i){t.exports={generate:i(9),parse:i(10),transform:i(12),stringify:i(14)}},function(t,e){t.exports=require("util")},function(t,e){t.exports=require("fs")},function(t,e,i){var o=i(5).Symbol;t.exports=o},function(t,e,i){var o=i(24),r="object"==typeof self&&self&&self.Object===Object&&self,n=o||r||Function("return this")();t.exports=n},function(t,e){t.exports=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}},function(t,e,i){const o=i(8),r=i(15);t.exports={shellApi:{csvWriter:o,csvReader:r}}},function(t,e,i){const o=i(1),r=i(3),n=i(0);class s extends n.Transform{constructor({header:t}){super({objectMode:!0}),this.structure=null,this.header=t}_transform(t,e,i){this.structure?(this.push(this.structure.columns.map(e=>t[e.columnName])),i()):(this.structure=t,this.header&&this.push(t.columns.map(t=>t.columnName)),i())}}t.exports=async function({fileName:t,encoding:e="utf-8",header:i=!0,delimiter:n,quoted:l}){console.log("Writing file "+t);const a=new s({header:i}),u=o.stringify({delimiter:n,quoted:l}),c=r.createWriteStream(t,e);return a.pipe(u),u.pipe(c),a.finisher=c,a}},function(t,e,i){var o,r,n,s=[].indexOf;r=i(0),n=i(2),t.exports=function(){var t,e,i,r;return 2===arguments.length?(r=arguments[0],t=arguments[1]):1===arguments.length?"function"==typeof arguments[0]?(r={},t=arguments[0]):r=arguments[0]:0===arguments.length&&(r={}),i=new o(r),t&&(e=[],i.on("readable",(function(){var t,o;for(o=[];t=i.read();)o.push(e.push(t));return o})),i.on("error",t),i.on("end",(function(){return i.options.objectMode||(e=i.options.encoding?e.join(""):Buffer.concat(e)),t(null,e)}))),i},o=function(t={}){var e,i,n,l,a,u,c,f,h,d,_,m,p,g,y,b,v,w,O;for(b in t.high_water_mark&&(t.highWaterMark=t.high_water_mark),t.object_mode&&(t.objectMode=t.object_mode),r.Readable.call(this,t),this.options={},t)O=t[b],this.options[o.camelize(b)]=O;for(null==(i=this.options).columns&&(i.columns=8),null==(n=this.options).delimiter&&(n.delimiter=","),null==(u=this.options).duration&&(u.duration=null),null==(c=this.options).encoding&&(c.encoding=null),null==(f=this.options).end&&(f.end=null),null==(h=this.options).eof&&(h.eof=!1),null==(d=this.options).fixedSize&&(d.fixedSize=!1),null==(_=this.options).length&&(_.length=-1),null==(m=this.options).maxWordLength&&(m.maxWordLength=16),null==(p=this.options).rowDelimiter&&(p.rowDelimiter="\n"),null==(l=this.options).seed&&(l.seed=!1),null==(a=this.options).sleep&&(a.sleep=0),!0===this.options.eof&&(this.options.eof=this.options.rowDelimiter),this._={start_time:this.options.duration?Date.now():null,fixed_size_buffer:"",count_written:0,count_created:0},"number"==typeof this.options.columns&&(this.options.columns=new Array(this.options.columns)),e=Object.keys(o).filter((function(t){return"super_"!==t&&"camelize"!==t})),g=y=0,v=(w=this.options.columns).length;y<v;g=++y)if(null==(O=w[g])&&(O="ascii"),"string"==typeof O){if(s.call(e,O)<0)throw Error(`Invalid column type: got "${O}", default values are ${JSON.stringify(e)}`);this.options.columns[g]=o[O]}return this},n.inherits(o,r.Readable),t.exports.Generator=o,o.prototype.random=function(){return this.options.seed?this.options.seed=this.options.seed*Math.PI*100%100/100:Math.random()},o.prototype.end=function(){return this.push(null)},o.prototype._read=function(t){var e,i,o,r,n,s,l,a,u,c,f,h,d,_;for(e=[],(u=this._.fixed_size_buffer.length)&&e.push(this._.fixed_size_buffer);;){if(this._.count_created===this.options.length||this.options.end&&Date.now()>this.options.end||this.options.duration&&Date.now()>this._.start_time+this.options.duration){if(e.length)if(this.options.objectMode)for(o=0,n=e.length;o<n;o++)c=e[o],this.__push(c);else this.__push(e.join("")+(this.options.eof?this.options.eof:""));return this.push(null)}for(c=[],r=0,s=(_=this.options.columns).length;r<s;r++)i=_[r],c.push(""+i(this));if(this.options.objectMode)for(f=0,h=0,l=c.length;h<l;h++)f+=c[h].length;else f=(c=`${0===this._.count_created?"":this.options.rowDelimiter}${c.join(this.options.delimiter)}`).length;if(this._.count_created++,u+f>t){if(this.options.objectMode)for(e.push(c),d=0,a=e.length;d<a;d++)c=e[d],this.__push(c);else this.options.fixedSize?(this._.fixed_size_buffer=c.substr(t-u),e.push(c.substr(0,t-u))):e.push(c),this.__push(e.join(""));break}u+=f,e.push(c)}},o.prototype.__push=function(t){return this._.count_written++,this.options.sleep>0?setTimeout(()=>this.push(t),this.options.sleep):this.push(t)},o.ascii=function(t){var e,i,o,r;for(i=[],o=0,r=Math.ceil(t.random()*t.options.maxWordLength);0<=r?o<r:o>r;0<=r?++o:--o)e=Math.floor(32*t.random()),i.push(String.fromCharCode(e+(e<16?65:81)));return i.join("")},o.int=function(t){return Math.floor(t.random()*Math.pow(2,52))},o.bool=function(t){return Math.floor(2*t.random())},o.camelize=function(t){return t.replace(/_([a-z])/gi,(function(t,e,i){return e.toUpperCase()}))}},function(t,e,i){const{Transform:o}=i(0),r=i(11),n={utf8:Buffer.from([239,187,191]),utf16le:Buffer.from([255,254])};class s extends o{constructor(t={}){super({readableObjectMode:!0,...t,encoding:null}),this.__originalOptions=t,this.__normalizeOptions(t)}__normalizeOptions(t){const e={};for(let i in t)e[u(i)]=t[i];if(void 0===e.encoding||!0===e.encoding)e.encoding="utf8";else if(null===e.encoding||!1===e.encoding)e.encoding=null;else if("string"!=typeof e.encoding&&null!==e.encoding)throw new a("CSV_INVALID_OPTION_ENCODING",["Invalid option encoding:","encoding must be a string or null to return a buffer,","got "+JSON.stringify(e.encoding)],e);if(void 0===e.bom||null===e.bom||!1===e.bom)e.bom=!1;else if(!0!==e.bom)throw new a("CSV_INVALID_OPTION_BOM",["Invalid option bom:","bom must be true,","got "+JSON.stringify(e.bom)],e);let i=null;if(void 0===e.cast||null===e.cast||!1===e.cast||""===e.cast)e.cast=void 0;else if("function"==typeof e.cast)i=e.cast,e.cast=!0;else if(!0!==e.cast)throw new a("CSV_INVALID_OPTION_CAST",["Invalid option cast:","cast must be true or a function,","got "+JSON.stringify(e.cast)],e);if(void 0===e.cast_date||null===e.cast_date||!1===e.cast_date||""===e.cast_date)e.cast_date=!1;else if(!0===e.cast_date)e.cast_date=function(t){const e=Date.parse(t);return isNaN(e)?t:new Date(e)};else if("function"!=typeof e.cast_date)throw new a("CSV_INVALID_OPTION_CAST_DATE",["Invalid option cast_date:","cast_date must be true or a function,","got "+JSON.stringify(e.cast_date)],e);let o=null;if(!0===e.columns)o=void 0;else if("function"==typeof e.columns)o=e.columns,e.columns=!0;else if(Array.isArray(e.columns))e.columns=h(e.columns);else{if(void 0!==e.columns&&null!==e.columns&&!1!==e.columns)throw new a("CSV_INVALID_OPTION_COLUMNS",["Invalid option columns:","expect an object, a function or true,","got "+JSON.stringify(e.columns)],e);e.columns=!1}if(void 0===e.columns_duplicates_to_array||null===e.columns_duplicates_to_array||!1===e.columns_duplicates_to_array)e.columns_duplicates_to_array=!1;else if(!0!==e.columns_duplicates_to_array)throw new a("CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY",["Invalid option columns_duplicates_to_array:","expect an boolean,","got "+JSON.stringify(e.columns_duplicates_to_array)],e);if(void 0===e.comment||null===e.comment||!1===e.comment||""===e.comment)e.comment=null;else if("string"==typeof e.comment&&(e.comment=Buffer.from(e.comment,e.encoding)),!Buffer.isBuffer(e.comment))throw new a("CSV_INVALID_OPTION_COMMENT",["Invalid option comment:","comment must be a buffer or a string,","got "+JSON.stringify(e.comment)],e);const n=JSON.stringify(e.delimiter);if(Array.isArray(e.delimiter)||(e.delimiter=[e.delimiter]),0===e.delimiter.length)throw new a("CSV_INVALID_OPTION_DELIMITER",["Invalid option delimiter:","delimiter must be a non empty string or buffer or array of string|buffer,","got "+n],e);if(e.delimiter=e.delimiter.map((function(t){if(null==t||!1===t)return Buffer.from(",",e.encoding);if("string"==typeof t&&(t=Buffer.from(t,e.encoding)),!Buffer.isBuffer(t)||0===t.length)throw new a("CSV_INVALID_OPTION_DELIMITER",["Invalid option delimiter:","delimiter must be a non empty string or buffer or array of string|buffer,","got "+n],e);return t})),void 0===e.escape||!0===e.escape?e.escape=Buffer.from('"',e.encoding):"string"==typeof e.escape?e.escape=Buffer.from(e.escape,e.encoding):null!==e.escape&&!1!==e.escape||(e.escape=null),null!==e.escape&&!Buffer.isBuffer(e.escape))throw new Error("Invalid Option: escape must be a buffer, a string or a boolean, got "+JSON.stringify(e.escape));if(void 0===e.from||null===e.from)e.from=1;else{if("string"==typeof e.from&&/\d+/.test(e.from)&&(e.from=parseInt(e.from)),!Number.isInteger(e.from))throw new Error("Invalid Option: from must be an integer, got "+JSON.stringify(e.from));if(e.from<0)throw new Error("Invalid Option: from must be a positive integer, got "+JSON.stringify(t.from))}if(void 0===e.from_line||null===e.from_line)e.from_line=1;else{if("string"==typeof e.from_line&&/\d+/.test(e.from_line)&&(e.from_line=parseInt(e.from_line)),!Number.isInteger(e.from_line))throw new Error("Invalid Option: from_line must be an integer, got "+JSON.stringify(t.from_line));if(e.from_line<=0)throw new Error("Invalid Option: from_line must be a positive integer greater than 0, got "+JSON.stringify(t.from_line))}if(void 0===e.info||null===e.info||!1===e.info)e.info=!1;else if(!0!==e.info)throw new Error("Invalid Option: info must be true, got "+JSON.stringify(e.info));if(void 0===e.max_record_size||null===e.max_record_size||!1===e.max_record_size)e.max_record_size=0;else if(Number.isInteger(e.max_record_size)&&e.max_record_size>=0);else{if("string"!=typeof e.max_record_size||!/\d+/.test(e.max_record_size))throw new Error("Invalid Option: max_record_size must be a positive integer, got "+JSON.stringify(e.max_record_size));e.max_record_size=parseInt(e.max_record_size)}if(void 0===e.objname||null===e.objname||!1===e.objname)e.objname=void 0;else if(Buffer.isBuffer(e.objname)){if(0===e.objname.length)throw new Error("Invalid Option: objname must be a non empty buffer");null===e.encoding||(e.objname=e.objname.toString(e.encoding))}else{if("string"!=typeof e.objname)throw new Error("Invalid Option: objname must be a string or a buffer, got "+e.objname);if(0===e.objname.length)throw new Error("Invalid Option: objname must be a non empty string")}if(void 0===e.on_record||null===e.on_record)e.on_record=void 0;else if("function"!=typeof e.on_record)throw new a("CSV_INVALID_OPTION_ON_RECORD",["Invalid option `on_record`:","expect a function,","got "+JSON.stringify(e.on_record)],e);if(null===e.quote||!1===e.quote||""===e.quote)e.quote=null;else if(void 0===e.quote||!0===e.quote?e.quote=Buffer.from('"',e.encoding):"string"==typeof e.quote&&(e.quote=Buffer.from(e.quote,e.encoding)),!Buffer.isBuffer(e.quote))throw new Error("Invalid Option: quote must be a buffer or a string, got "+JSON.stringify(e.quote));if(void 0===e.raw||null===e.raw||!1===e.raw)e.raw=!1;else if(!0!==e.raw)throw new Error("Invalid Option: raw must be true, got "+JSON.stringify(e.raw));if(e.record_delimiter?Array.isArray(e.record_delimiter)||(e.record_delimiter=[e.record_delimiter]):e.record_delimiter=[],e.record_delimiter=e.record_delimiter.map((function(t){return"string"==typeof t&&(t=Buffer.from(t,e.encoding)),t})),"boolean"==typeof e.relax);else{if(void 0!==e.relax&&null!==e.relax)throw new Error("Invalid Option: relax must be a boolean, got "+JSON.stringify(e.relax));e.relax=!1}if("boolean"==typeof e.relax_column_count);else{if(void 0!==e.relax_column_count&&null!==e.relax_column_count)throw new Error("Invalid Option: relax_column_count must be a boolean, got "+JSON.stringify(e.relax_column_count));e.relax_column_count=!1}if("boolean"==typeof e.relax_column_count_less);else{if(void 0!==e.relax_column_count_less&&null!==e.relax_column_count_less)throw new Error("Invalid Option: relax_column_count_less must be a boolean, got "+JSON.stringify(e.relax_column_count_less));e.relax_column_count_less=!1}if("boolean"==typeof e.relax_column_count_more);else{if(void 0!==e.relax_column_count_more&&null!==e.relax_column_count_more)throw new Error("Invalid Option: relax_column_count_more must be a boolean, got "+JSON.stringify(e.relax_column_count_more));e.relax_column_count_more=!1}if("boolean"==typeof e.skip_empty_lines);else{if(void 0!==e.skip_empty_lines&&null!==e.skip_empty_lines)throw new Error("Invalid Option: skip_empty_lines must be a boolean, got "+JSON.stringify(e.skip_empty_lines));e.skip_empty_lines=!1}if("boolean"==typeof e.skip_lines_with_empty_values);else{if(void 0!==e.skip_lines_with_empty_values&&null!==e.skip_lines_with_empty_values)throw new Error("Invalid Option: skip_lines_with_empty_values must be a boolean, got "+JSON.stringify(e.skip_lines_with_empty_values));e.skip_lines_with_empty_values=!1}if("boolean"==typeof e.skip_lines_with_error);else{if(void 0!==e.skip_lines_with_error&&null!==e.skip_lines_with_error)throw new Error("Invalid Option: skip_lines_with_error must be a boolean, got "+JSON.stringify(e.skip_lines_with_error));e.skip_lines_with_error=!1}if(void 0===e.rtrim||null===e.rtrim||!1===e.rtrim)e.rtrim=!1;else if(!0!==e.rtrim)throw new Error("Invalid Option: rtrim must be a boolean, got "+JSON.stringify(e.rtrim));if(void 0===e.ltrim||null===e.ltrim||!1===e.ltrim)e.ltrim=!1;else if(!0!==e.ltrim)throw new Error("Invalid Option: ltrim must be a boolean, got "+JSON.stringify(e.ltrim));if(void 0===e.trim||null===e.trim||!1===e.trim)e.trim=!1;else if(!0!==e.trim)throw new Error("Invalid Option: trim must be a boolean, got "+JSON.stringify(e.trim));if(!0===e.trim&&!1!==t.ltrim?e.ltrim=!0:!0!==e.ltrim&&(e.ltrim=!1),!0===e.trim&&!1!==t.rtrim?e.rtrim=!0:!0!==e.rtrim&&(e.rtrim=!1),void 0===e.to||null===e.to)e.to=-1;else{if("string"==typeof e.to&&/\d+/.test(e.to)&&(e.to=parseInt(e.to)),!Number.isInteger(e.to))throw new Error("Invalid Option: to must be an integer, got "+JSON.stringify(t.to));if(e.to<=0)throw new Error("Invalid Option: to must be a positive integer greater than 0, got "+JSON.stringify(t.to))}if(void 0===e.to_line||null===e.to_line)e.to_line=-1;else{if("string"==typeof e.to_line&&/\d+/.test(e.to_line)&&(e.to_line=parseInt(e.to_line)),!Number.isInteger(e.to_line))throw new Error("Invalid Option: to_line must be an integer, got "+JSON.stringify(t.to_line));if(e.to_line<=0)throw new Error("Invalid Option: to_line must be a positive integer greater than 0, got "+JSON.stringify(t.to_line))}this.info={comment_lines:0,empty_lines:0,invalid_field_length:0,lines:1,records:0},this.options=e,this.state={bomSkipped:!1,castField:i,commenting:!1,error:void 0,enabled:1===e.from_line,escaping:!1,escapeIsQuote:Buffer.isBuffer(e.escape)&&Buffer.isBuffer(e.quote)&&0===Buffer.compare(e.escape,e.quote),expectedRecordLength:null===e.columns?0:e.columns.length,field:new r(20),firstLineToHeaders:o,info:Object.assign({},this.info),needMoreDataSize:Math.max(null!==e.comment?e.comment.length:0,...e.delimiter.map(t=>t.length),null!==e.quote?e.quote.length:0),previousBuf:void 0,quoting:!1,stop:!1,rawBuffer:new r(100),record:[],recordHasError:!1,record_length:0,recordDelimiterMaxLength:0===e.record_delimiter.length?2:Math.max(...e.record_delimiter.map(t=>t.length)),trimChars:[Buffer.from(" ",e.encoding)[0],Buffer.from("\t",e.encoding)[0]],wasQuoting:!1,wasRowDelimiter:!1}}_transform(t,e,i){if(!0===this.state.stop)return;const o=this.__parse(t,!1);void 0!==o&&(this.state.stop=!0),i(o)}_flush(t){if(!0===this.state.stop)return;t(this.__parse(void 0,!0))}__parse(t,e){const{bom:i,comment:o,escape:r,from_line:s,info:l,ltrim:u,max_record_size:c,quote:f,raw:h,relax:d,rtrim:_,skip_empty_lines:m,to:p,to_line:g}=this.options;let{record_delimiter:y}=this.options;const{bomSkipped:b,previousBuf:v,rawBuffer:w,escapeIsQuote:O}=this.state;let x;if(void 0===v){if(void 0===t)return void this.push(null);x=t}else x=void 0!==v&&void 0===t?v:Buffer.concat([v,t]);if(!1===b)if(!1===i)this.state.bomSkipped=!0;else if(x.length<3){if(!1===e)return void(this.state.previousBuf=x)}else{for(let t in n)if(0===n[t].compare(x,0,n[t].length)){x=x.slice(n[t].length),this.__normalizeOptions({...this.__originalOptions,encoding:t});break}this.state.bomSkipped=!0}const I=x.length;let S;for(S=0;S<I&&!this.__needMoreData(S,I,e);S++){if(!0===this.state.wasRowDelimiter&&(this.info.lines++,!0===l&&0===this.state.record.length&&0===this.state.field.length&&!1===this.state.wasQuoting&&(this.state.info=Object.assign({},this.info)),this.state.wasRowDelimiter=!1),-1!==g&&this.info.lines>g)return this.state.stop=!0,void this.push(null);if(!1===this.state.quoting&&0===y.length){this.__autoDiscoverRowDelimiter(x,S)&&(y=this.options.record_delimiter)}const t=x[S];if(!0===h&&w.append(t),13!==t&&10!==t||!1!==this.state.wasRowDelimiter||(this.state.wasRowDelimiter=!0),!0===this.state.escaping)this.state.escaping=!1;else{if(null!==r&&!0===this.state.quoting&&this.__isEscape(x,S,t)&&S+r.length<I){if(!O){this.state.escaping=!0,S+=r.length-1;continue}if(this.__isQuote(x,S+r.length)){this.state.escaping=!0,S+=r.length-1;continue}}if(!1===this.state.commenting&&this.__isQuote(x,S))if(!0===this.state.quoting){const e=x[S+f.length],i=_&&this.__isCharTrimable(e),n=null!==o&&this.__compareBytes(o,x,S+f.length,e),s=this.__isDelimiter(x,S+f.length,e),l=0===y.length?this.__autoDiscoverRowDelimiter(x,S+f.length):this.__isRecordDelimiter(e,x,S+f.length);if(null!==r&&this.__isEscape(x,S,t)&&this.__isQuote(x,S+r.length))S+=r.length-1;else{if(!e||s||l||n||i){this.state.quoting=!1,this.state.wasQuoting=!0,S+=f.length-1;continue}if(!1===d){const t=this.__error(new a("CSV_INVALID_CLOSING_QUOTE",["Invalid Closing Quote:",`got "${String.fromCharCode(e)}"`,"at line "+this.info.lines,"instead of delimiter, row delimiter, trimable character","(if activated) or comment"],this.options,this.__context()));if(void 0!==t)return t}else this.state.quoting=!1,this.state.wasQuoting=!0,this.state.field.prepend(f),S+=f.length-1}}else{if(0===this.state.field.length){this.state.quoting=!0,S+=f.length-1;continue}if(!1===d){const t=this.__error(new a("INVALID_OPENING_QUOTE",["Invalid Opening Quote:","a quote is found inside a field at line "+this.info.lines],this.options,this.__context(),{field:this.state.field}));if(void 0!==t)return t}}if(!1===this.state.quoting){let e=this.__isRecordDelimiter(t,x,S);if(0!==e){if(this.state.commenting&&!1===this.state.wasQuoting&&0===this.state.record.length&&0===this.state.field.length)this.info.comment_lines++;else{if(!0===m&&!1===this.state.wasQuoting&&0===this.state.record.length&&0===this.state.field.length){this.info.empty_lines++,S+=e-1;continue}if(!1===this.state.enabled&&this.info.lines+(!0===this.state.wasRowDelimiter?1:0)>=s){this.state.enabled=!0,this.__resetField(),this.__resetRow(),S+=e-1;continue}{const t=this.__onField();if(void 0!==t)return t;const e=this.__onRow();if(void 0!==e)return e}if(-1!==p&&this.info.records>=p)return this.state.stop=!0,void this.push(null)}this.state.commenting=!1,S+=e-1;continue}if(this.state.commenting)continue;if(0!==(null===o?0:this.__compareBytes(o,x,S,t))){this.state.commenting=!0;continue}let i=this.__isDelimiter(x,S,t);if(0!==i){const t=this.__onField();if(void 0!==t)return t;S+=i-1;continue}}}if(!1===this.state.commenting&&0!==c&&this.state.record_length+this.state.field.length>c){const t=this.__error(new a("CSV_MAX_RECORD_SIZE",["Max Record Size:","record exceed the maximum number of tolerated bytes","of "+c,"at line "+this.info.lines],this.options,this.__context()));if(void 0!==t)return t}const e=!1===u||!0===this.state.quoting||0!==this.state.field.length||!this.__isCharTrimable(t),i=!1===_||!1===this.state.wasQuoting;if(!0===e&&!0===i)this.state.field.append(t);else if(!0===_&&!this.__isCharTrimable(t)){const t=this.__error(new a("CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE",["Invalid Closing Quote:","found non trimable byte after quote","at line "+this.info.lines],this.options,this.__context()));if(void 0!==t)return t}}if(!0===e)if(!0===this.state.quoting){const t=this.__error(new a("CSV_QUOTE_NOT_CLOSED",["Quote Not Closed:","the parsing is finished with an opening quote at line "+this.info.lines],this.options,this.__context()));if(void 0!==t)return t}else if(!0===this.state.wasQuoting||0!==this.state.record.length||0!==this.state.field.length){const t=this.__onField();if(void 0!==t)return t;const e=this.__onRow();if(void 0!==e)return e}else!0===this.state.wasRowDelimiter?this.info.empty_lines++:!0===this.state.commenting&&this.info.comment_lines++;else this.state.previousBuf=x.slice(S);!0===this.state.wasRowDelimiter&&(this.info.lines++,this.state.wasRowDelimiter=!1)}__isCharTrimable(t){return 32===t||9===t||13===t||10===t||12===t}__onRow(){const{columns:t,columns_duplicates_to_array:e,encoding:i,info:o,from:r,relax_column_count:n,relax_column_count_less:s,relax_column_count_more:l,raw:u,skip_lines_with_empty_values:c}=this.options,{enabled:h,record:d}=this.state;if(!1===h)return this.__resetRow();const _=d.length;if(!0===t)return f(d)?void this.__resetRow():this.__firstLineToColumns(d);if(!1===t&&0===this.info.records&&(this.state.expectedRecordLength=_),_!==this.state.expectedRecordLength){const e=!1===t?this.__error(new a("CSV_INCONSISTENT_RECORD_LENGTH",["Invalid Record Length:",`expect ${this.state.expectedRecordLength},`,`got ${_} on line ${this.info.lines}`],this.options,this.__context(),{record:d})):this.__error(new a("CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH",["Invalid Record Length:",`columns length is ${t.length},`,`got ${_} on line ${this.info.lines}`],this.options,this.__context(),{record:d}));if(!0===n||!0===s&&_<this.state.expectedRecordLength||!0===l&&_>this.state.expectedRecordLength)this.info.invalid_field_length++,this.state.error=e;else if(void 0!==e)return e}if(!0===c&&f(d))this.__resetRow();else{if(!0===this.state.recordHasError)return this.__resetRow(),void(this.state.recordHasError=!1);if(this.info.records++,1===r||this.info.records>=r)if(!1!==t){const r={};for(let i=0,o=d.length;i<o;i++)void 0===t[i]||t[i].disabled||(!0===e&&r[t[i].name]?Array.isArray(r[t[i].name])?r[t[i].name]=r[t[i].name].concat(d[i]):r[t[i].name]=[r[t[i].name],d[i]]:r[t[i].name]=d[i]);const{objname:n}=this.options;if(void 0===n)if(!0===u||!0===o){const t=this.__push(Object.assign({record:r},!0===u?{raw:this.state.rawBuffer.toString(i)}:{},!0===o?{info:this.state.info}:{}));if(t)return t}else{const t=this.__push(r);if(t)return t}else if(!0===u||!0===o){const t=this.__push(Object.assign({record:[r[n],r]},!0===u?{raw:this.state.rawBuffer.toString(i)}:{},!0===o?{info:this.state.info}:{}));if(t)return t}else{const t=this.__push([r[n],r]);if(t)return t}}else if(!0===u||!0===o){const t=this.__push(Object.assign({record:d},!0===u?{raw:this.state.rawBuffer.toString(i)}:{},!0===o?{info:this.state.info}:{}));if(t)return t}else{const t=this.__push(d);if(t)return t}this.__resetRow()}}__firstLineToColumns(t){const{firstLineToHeaders:e}=this.state;try{const i=void 0===e?t:e.call(null,t);if(!Array.isArray(i))return this.__error(new a("CSV_INVALID_COLUMN_MAPPING",["Invalid Column Mapping:","expect an array from column function,","got "+JSON.stringify(i)],this.options,this.__context(),{headers:i}));const o=h(i);return this.state.expectedRecordLength=o.length,this.options.columns=o,void this.__resetRow()}catch(t){return t}}__resetRow(){!0===this.options.raw&&this.state.rawBuffer.reset(),this.state.error=void 0,this.state.record=[],this.state.record_length=0}__onField(){const{cast:t,encoding:e,rtrim:i,max_record_size:o}=this.options,{enabled:r,wasQuoting:n}=this.state;if(!1===r)return this.__resetField();let s=this.state.field.toString(e);if(!0===i&&!1===n&&(s=s.trimRight()),!0===t){const[t,e]=this.__cast(s);if(void 0!==t)return t;s=e}this.state.record.push(s),0!==o&&"string"==typeof s&&(this.state.record_length+=s.length),this.__resetField()}__resetField(){this.state.field.reset(),this.state.wasQuoting=!1}__push(t){const{on_record:e}=this.options;if(void 0!==e){const i=this.__context();try{t=e.call(null,t,i)}catch(t){return t}if(null==t)return}this.push(t)}__cast(t){const{columns:e,relax_column_count:i}=this.options;if(!0===Array.isArray(e)&&i&&this.options.columns.length<=this.state.record.length)return[void 0,void 0];const o=this.__context();if(null!==this.state.castField)try{return[void 0,this.state.castField.call(null,t,o)]}catch(t){return[t]}return this.__isFloat(t)?[void 0,parseFloat(t)]:!1!==this.options.cast_date?[void 0,this.options.cast_date.call(null,t,o)]:[void 0,t]}__isFloat(t){return t-parseFloat(t)+1>=0}__compareBytes(t,e,i,o){if(t[0]!==o)return 0;const r=t.length;for(let o=1;o<r;o++)if(t[o]!==e[i+o])return 0;return r}__needMoreData(t,e,i){if(i)return!1;const{quote:o}=this.options,{quoting:r,needMoreDataSize:n,recordDelimiterMaxLength:s}=this.state;return e-t-1<Math.max(n,s,r?o.length+s:0)}__isDelimiter(t,e,i){const{delimiter:o}=this.options;t:for(let r=0;r<o.length;r++){const n=o[r];if(n[0]===i){for(let i=1;i<n.length;i++)if(n[i]!==t[e+i])continue t;return n.length}}return 0}__isRecordDelimiter(t,e,i){const{record_delimiter:o}=this.options,r=o.length;t:for(let n=0;n<r;n++){const r=o[n],s=r.length;if(r[0]===t){for(let t=1;t<s;t++)if(r[t]!==e[i+t])continue t;return r.length}}return 0}__isEscape(t,e,i){const{escape:o}=this.options;if(null===o)return!1;const r=o.length;if(o[0]===i){for(let i=0;i<r;i++)if(o[i]!==t[e+i])return!1;return!0}return!1}__isQuote(t,e){const{quote:i}=this.options;if(null===i)return!1;const o=i.length;for(let r=0;r<o;r++)if(i[r]!==t[e+r])return!1;return!0}__autoDiscoverRowDelimiter(t,e){const{encoding:i}=this.options,o=t[e];return 13===o?10===t[e+1]?(this.options.record_delimiter.push(Buffer.from("\r\n",i)),this.state.recordDelimiterMaxLength=2,2):(this.options.record_delimiter.push(Buffer.from("\r",i)),this.state.recordDelimiterMaxLength=1,1):10===o?(this.options.record_delimiter.push(Buffer.from("\n",i)),this.state.recordDelimiterMaxLength=1,1):0}__error(t){const{skip_lines_with_error:e}=this.options,i="string"==typeof t?new Error(t):t;return e?(this.state.recordHasError=!0,void this.emit("skip",i)):i}__context(){const{columns:t}=this.options;return{column:!0===Array.isArray(t)?t.length>this.state.record.length?t[this.state.record.length].name:null:this.state.record.length,empty_lines:this.info.empty_lines,error:this.state.error,header:!0===t,index:this.state.record.length,invalid_field_length:this.info.invalid_field_length,quoting:this.state.wasQuoting,lines:this.info.lines,records:this.info.records}}}const l=function(){let t,e,i;for(let o in arguments){const r=arguments[o],n=typeof r;if(void 0!==t||"string"!=typeof r&&!Buffer.isBuffer(r))if(void 0===e&&c(r))e=r;else{if(void 0!==i||"function"!==n)throw new a("CSV_INVALID_ARGUMENT",["Invalid argument:",`got ${JSON.stringify(r)} at index ${o}`],this.options);i=r}else t=r}const o=new s(e);if(i){const t=void 0===e||void 0===e.objname?[]:{};o.on("readable",(function(){let i;for(;null!==(i=this.read());)void 0===e||void 0===e.objname?t.push(i):t[i[0]]=i[1]})),o.on("error",(function(t){i(t,void 0,o.info)})),o.on("end",(function(){i(void 0,t,o.info)}))}return void 0!==t&&("function"==typeof setImmediate?setImmediate((function(){o.write(t),o.end()})):(o.write(t),o.end())),o};class a extends Error{constructor(t,e,i,...o){Array.isArray(e)&&(e=e.join(" ")),super(e),void 0!==Error.captureStackTrace&&Error.captureStackTrace(this,a),this.code=t;for(const t of o)for(const e in t){const o=t[e];this[e]=Buffer.isBuffer(o)?o.toString(i.encoding):null==o?o:JSON.parse(JSON.stringify(o))}}}l.Parser=s,l.CsvError=a,t.exports=l;const u=function(t){return t.replace(/([A-Z])/g,(function(t,e){return"_"+e.toLowerCase()}))},c=function(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)},f=function(t){return t.every(t=>null==t||t.toString&&""===t.toString().trim())},h=function(t){const e=[];for(let i=0,o=t.length;i<o;i++){const o=t[i];if(null==o||!1===o)e[i]={disabled:!0};else if("string"==typeof o)e[i]={name:o};else{if(!c(o))throw new a("CSV_INVALID_COLUMN_DEFINITION",["Invalid column definition:","expect a string or a literal object,",`got ${JSON.stringify(o)} at position ${i}`]);if("string"!=typeof o.name)throw new a("CSV_OPTION_COLUMNS_MISSING_NAME",["Option columns missing name:",'property "name" is required at position '+i,"when column is an object literal"]);e[i]=o}}return e}},function(t,e){t.exports=class{constructor(t=100){this.size=t,this.length=0,this.buf=Buffer.alloc(t)}prepend(t){if(Buffer.isBuffer(t)){const e=this.length+t.length;if(e>=this.size&&(this.resize(),e>=this.size))throw Error("INVALID_BUFFER_STATE");const i=this.buf;this.buf=Buffer.alloc(this.size),t.copy(this.buf,0),i.copy(this.buf,t.length),this.length+=t.length}else{const e=this.length++;e===this.size&&this.resize();const i=this.clone();this.buf[0]=t,i.copy(this.buf,1,0,e)}}append(t){const e=this.length++;e===this.size&&this.resize(),this.buf[e]=t}clone(){return Buffer.from(this.buf.slice(0,this.length))}resize(){const t=this.length;this.size=2*this.size;const e=Buffer.alloc(this.size);this.buf.copy(e,0,0,t),this.buf=e}toString(t){return t?this.buf.slice(0,this.length).toString(t):Uint8Array.prototype.slice.call(this.buf.slice(0,this.length))}toJSON(){return this.toString("utf8")}reset(){this.length=0}}},function(t,e,i){var o,r,n,s;n=i(0),s=i(2),({clone:r}=i(13)),t.exports=function(){var t,e,i,n,s,l,a,u,c,f,h,d;for(u={},s=l=0,a=arguments.length;l<a;s=++l)if(d=typeof(t=arguments[s]),null===t?d="null":"object"===d&&Array.isArray(t)&&(d="array"),"array"===d)c=t;else if("object"===d)u=r(t);else if("function"===d)n&&s===arguments.length-1?e=t:n=t;else if("null"!==d)throw new Error(`Invalid Arguments: got ${JSON.stringify(t)} at position ${s}`);return h=new o(u,n),i=!1,c&&setImmediate((function(){var t,e,o;for(t=0,e=c.length;t<e&&(o=c[t],!i);t++)h.write(o);return h.end()})),(e||u.consume)&&(f=[],h.on("readable",(function(){var t,i;for(i=[];t=h.read();)e?i.push(f.push(t)):i.push(void 0);return i})),h.on("error",(function(t){if(i=!0,e)return e(t)})),h.on("end",(function(){if(e&&!i)return e(null,f)}))),h},o=function(t={},e){var i,o;return this.options=t,this.handler=e,null==(i=this.options).consume&&(i.consume=!1),this.options.objectMode=!0,null==(o=this.options).parallel&&(o.parallel=100),n.Transform.call(this,this.options),this.state={running:0,started:0,finished:0},this},s.inherits(o,n.Transform),t.exports.Transformer=o,o.prototype._transform=function(t,e,i){var o,r,n;this.state.started++,this.state.running++,this.state.running<this.options.parallel&&(i(),i=null);try{if(n=this.handler.length,null!=this.options.params&&n--,1===n)this.__done(null,[this.handler.call(this,t,this.options.params)],i);else{if(2!==n)throw Error("Invalid handler arguments");o=(t,...e)=>this.__done(t,e,i),this.handler.call(this,t,o,this.options.params)}return!1}catch(t){return r=t,this.__done(r)}},o.prototype._flush=function(t){return this._ending=function(){if(0===this.state.running)return t()},this._ending()},o.prototype.__done=function(t,e,i){var o,r,n;if(this.state.running--,t)return this.emit("error",t);for(this.state.finished++,r=0,n=e.length;r<n;r++)"number"==typeof(o=e[r])&&(o=""+o),null!=o&&""!==o&&this.push(o);return i&&i(),this._ending?this._ending():void 0}},function(t,e,i){"use strict";function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var r,n,s,l,a,u,c,f;i.r(e),i.d(e,"clone",(function(){return n})),i.d(e,"compare",(function(){return s})),i.d(e,"is_object",(function(){return l})),i.d(e,"is_object_literal",(function(){return a})),i.d(e,"merge",(function(){return u})),i.d(e,"mutate",(function(){return c})),i.d(e,"snake_case",(function(){return f})),u=function(){return c.apply(void 0,[{}].concat(Array.prototype.slice.call(arguments)))},n=function(t){return Array.isArray(t)?t.map((function(t){return n(t)})):t&&"object"===o(t)?c({},t):t},c=function(){var t,e,i,o,r,n,s;for(n=arguments[0],t=e=1,o=arguments.length;1<=o?e<o:e>o;t=1<=o?++e:--e)if(a(r=arguments[t]))for(i in a(n)||(n={}),r)n[i]=c(n[i],r[i]);else Array.isArray(r)?n=function(){var t,e,i;for(i=[],t=0,e=r.length;t<e;t++)s=r[t],i.push(c(void 0,s));return i}():void 0!==r&&(n=r);return n},f=function(t){var e,i,o,n,s=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(o={},a(t))for(e in n="number"==typeof s&&s>0?s-1:s,t)i=t[e],s&&(e=r(e)),o[e]=f(i,n);else o=t;return o},s=function(t,e){var i,o,r,n,l,u,c,f;if(a(t)){if(!a(e))return!1;if(l=Object.keys(t).sort(),u=Object.keys(e).sort(),l.length!==u.length)return!1;for(i=o=0,c=l.length;o<c;i=++o){if((n=l[i])!==u[i])return!1;if(!s(t[n],e[n]))return!1}}else if(Array.isArray(t)){if(!Array.isArray(e))return!1;if(t.length!==e.length)return!1;for(i=r=0,f=t.length;0<=f?r<f:r>f;i=0<=f?++r:--r)if(!s(t[i],e[i]))return!1}else if(t!==e)return!1;return!0},r=function(t){return t.replace(/([A-Z])/g,(function(t,e,i){return"_"+e.toLowerCase()}))},l=function(t){return t&&"object"===o(t)&&!Array.isArray(t)},a=function(t){var e;if(e=t,"object"!==o(t)||null===t)return!1;for(;null!==Object.getPrototypeOf(e=Object.getPrototypeOf(e)););return Object.getPrototypeOf(t)===e}},function(t,e,o){const{Transform:r}=o(0),n=Buffer.from([239,187,191]);class s extends r{constructor(t={}){super({writableObjectMode:!0,...t});const e={};let i;for(let i in t)e[c(i)]=t[i];if(i=this.normalize(e))throw i;switch(e.record_delimiter){case"auto":e.record_delimiter=null;break;case"unix":e.record_delimiter="\n";break;case"mac":e.record_delimiter="\r";break;case"windows":e.record_delimiter="\r\n";break;case"ascii":e.record_delimiter="";break;case"unicode":e.record_delimiter="\u2028"}this.options=e,this.state={stop:!1},this.info={records:0}}normalize(t){if(void 0===t.bom||null===t.bom||!1===t.bom)t.bom=!1;else if(!0!==t.bom)return new a("CSV_OPTION_BOOLEAN_INVALID_TYPE",["option `bom` is optional and must be a boolean value,","got "+JSON.stringify(t.bom)]);if(void 0===t.delimiter||null===t.delimiter)t.delimiter=",";else if(Buffer.isBuffer(t.delimiter))t.delimiter=t.delimiter.toString();else if("string"!=typeof t.delimiter)return new a("CSV_OPTION_DELIMITER_INVALID_TYPE",["option `delimiter` must be a buffer or a string,","got "+JSON.stringify(t.delimiter)]);if(void 0===t.quote||null===t.quote)t.quote='"';else if(!0===t.quote)t.quote='"';else if(!1===t.quote)t.quote="";else if(Buffer.isBuffer(t.quote))t.quote=t.quote.toString();else if("string"!=typeof t.quote)return new a("CSV_OPTION_QUOTE_INVALID_TYPE",["option `quote` must be a boolean, a buffer or a string,","got "+JSON.stringify(t.quote)]);if(void 0!==t.quoted&&null!==t.quoted||(t.quoted=!1),void 0!==t.quoted_empty&&null!==t.quoted_empty||(t.quoted_empty=void 0),void 0===t.quoted_match||null===t.quoted_match||!1===t.quoted_match?t.quoted_match=null:Array.isArray(t.quoted_match)||(t.quoted_match=[t.quoted_match]),t.quoted_match)for(let e of t.quoted_match){const t=e instanceof RegExp;if(!("string"==typeof e)&&!t)return Error("Invalid Option: quoted_match must be a string or a regex, got "+JSON.stringify(e))}if(void 0!==t.quoted_string&&null!==t.quoted_string||(t.quoted_string=!1),void 0!==t.eof&&null!==t.eof||(t.eof=!0),void 0===t.escape||null===t.escape)t.escape='"';else if(Buffer.isBuffer(t.escape))t.escape=t.escape.toString();else if("string"!=typeof t.escape)return Error("Invalid Option: escape must be a buffer or a string, got "+JSON.stringify(t.escape));if(t.escape.length>1)return Error(`Invalid Option: escape must be one character, got ${t.escape.length} characters`);if(void 0!==t.header&&null!==t.header||(t.header=!1),t.columns=this.normalize_columns(t.columns),void 0!==t.quoted&&null!==t.quoted||(t.quoted=!1),void 0!==t.cast&&null!==t.cast||(t.cast={}),void 0!==t.cast.bigint&&null!==t.cast.bigint||(t.cast.bigint=t=>""+t),void 0!==t.cast.boolean&&null!==t.cast.boolean||(t.cast.boolean=t=>t?"1":""),void 0!==t.cast.date&&null!==t.cast.date||(t.cast.date=t=>""+t.getTime()),void 0!==t.cast.number&&null!==t.cast.number||(t.cast.number=t=>""+t),void 0!==t.cast.object&&null!==t.cast.object||(t.cast.object=t=>JSON.stringify(t)),void 0!==t.cast.string&&null!==t.cast.string||(t.cast.string=function(t){return t}),void 0===t.record_delimiter||null===t.record_delimiter)t.record_delimiter="\n";else if(Buffer.isBuffer(t.record_delimiter))t.record_delimiter=t.record_delimiter.toString();else if("string"!=typeof t.record_delimiter)return Error("Invalid Option: record_delimiter must be a buffer or a string, got "+JSON.stringify(t.record_delimiter))}_transform(t,e,i){if(!0!==this.state.stop){if(!Array.isArray(t)&&"object"!=typeof t)return this.state.stop=!0,i(Error("Invalid Record: expect an array or an object, got "+JSON.stringify(t)));if(0===this.info.records)if(Array.isArray(t)){if(!0===this.options.header&&!this.options.columns)return this.state.stop=!0,i(Error("Undiscoverable Columns: header option requires column option or object records"))}else void 0!==this.options.columns&&null!==this.options.columns||(this.options.columns=this.normalize_columns(Object.keys(t)));0===this.info.records&&(this.bom(),this.headers());try{this.emit("record",t,this.info.records)}catch(t){return this.state.stop=!0,this.emit("error",t)}if(this.options.eof){if(void 0===(t=this.stringify(t)))return;t+=this.options.record_delimiter}else{if(void 0===(t=this.stringify(t)))return;(this.options.header||this.info.records)&&(t=this.options.record_delimiter+t)}this.info.records++,this.push(t),i()}}_flush(t){0===this.info.records&&(this.bom(),this.headers()),t()}stringify(t,e=!1){if("object"!=typeof t)return t;const{columns:o,header:r}=this.options,n=[];if(Array.isArray(t)){o&&t.splice(o.length);for(let i=0;i<t.length;i++){const o=t[i],[r,s]=this.__cast(o,{index:i,column:i,records:this.info.records,header:e});if(r)return void this.emit("error",r);n[i]=[s,o]}}else if(o)for(let i=0;i<o.length;i++){const r=b(t,o[i].key),[s,l]=this.__cast(r,{index:i,column:o[i].key,records:this.info.records,header:e});if(s)return void this.emit("error",s);n[i]=[l,r]}else for(let r of t){const s=t[r],[l,a]=this.__cast(s,{index:i,column:o[i].key,records:this.info.records,header:e});if(l)return void this.emit("error",l);n.push([a,s])}let s="";for(let t=0;t<n.length;t++){let e,i,[o,r]=n[t];if("string"==typeof o)e=this.options;else if(u(o)){if(e=o,o=e.value,delete e.value,"string"!=typeof o&&null!=o)return void this.emit("error",Error("Invalid Casting Value: returned value must return a string, null or undefined, got "+JSON.stringify(o)));if(e={...this.options,...e},i=this.normalize(e))return void this.emit("error",i)}else{if(null!=o)return void this.emit("error",Error("Invalid Casting Value: returned value must return a string, an object, null or undefined, got "+JSON.stringify(o)));e=this.options}const{delimiter:l,escape:a,quote:c,quoted:f,quoted_empty:h,quoted_string:d,quoted_match:_,record_delimiter:m}=e;if(o){if("string"!=typeof o)return this.emit("error",Error("Formatter must return a string, null or undefined, got "+JSON.stringify(o))),null;const t=l.length&&o.indexOf(l)>=0,e=""!==c&&o.indexOf(c)>=0,i=o.indexOf(a)>=0&&a!==c,n=o.indexOf(m)>=0,u=d&&"string"==typeof r;let h=_&&_.filter(t=>"string"==typeof t?-1!==o.indexOf(t):t.test(o));h=h&&h.length>0;const p=!0===e||t||n||f||u||h;if(!0===p&&!0===i){const t="\\"===a?new RegExp(a+a,"g"):new RegExp(a,"g");o=o.replace(t,a+a)}if(!0===e){const t=new RegExp(c,"g");o=o.replace(t,a+c)}!0===p&&(o=c+o+c),s+=o}else(!0===h||""===r&&!0===d&&!1!==h)&&(s+=c+c);t!==n.length-1&&(s+=l)}return s}bom(){!0===this.options.bom&&this.push(n)}headers(){if(!1===this.options.header)return;if(void 0===this.options.columns)return;let t=this.options.columns.map(t=>t.header);t=this.options.eof?this.stringify(t,!0)+this.options.record_delimiter:this.stringify(t),this.push(t)}__cast(t,e){const i=typeof t;try{return"string"===i?[void 0,this.options.cast.string(t,e)]:"bigint"===i?[void 0,this.options.cast.bigint(t,e)]:"number"===i?[void 0,this.options.cast.number(t,e)]:"boolean"===i?[void 0,this.options.cast.boolean(t,e)]:t instanceof Date?[void 0,this.options.cast.date(t,e)]:"object"===i&&null!==t?[void 0,this.options.cast.object(t,e)]:[void 0,t,t]}catch(t){return[t]}}normalize_columns(t){if(null!=t){if("object"!=typeof t)throw Error('Invalid option "columns": expect an array or an object');if(Array.isArray(t)){const e=[];for(let i of t)if("string"==typeof i)e.push({key:i,header:i});else{if("object"!=typeof i||void 0===i||Array.isArray(i))throw Error("Invalid column definition: expect a string or an object");if(!i.key)throw Error('Invalid column definition: property "key" is required');void 0===i.header&&(i.header=i.key),e.push(i)}t=e}else{const e=[];for(let i in t)e.push({key:i,header:t[i]});t=e}return t}}}const l=function(){let t,e,i;for(let o in arguments){const r=arguments[o],n=typeof r;if(void 0===t&&Array.isArray(r))t=r;else if(void 0===e&&u(r))e=r;else{if(void 0!==i||"function"!==n)throw new a("CSV_INVALID_ARGUMENT",["Invalid argument:",`got ${JSON.stringify(r)} at index ${o}`]);i=r}}const o=new s(e);if(i){const t=[];o.on("readable",(function(){let e;for(;null!==(e=this.read());)t.push(e)})),o.on("error",(function(t){i(t)})),o.on("end",(function(){i(void 0,t.join(""))}))}if(void 0!==t)if("function"==typeof setImmediate)setImmediate((function(){for(let e of t)o.write(e);o.end()}));else{for(let e of t)o.write(e);o.end()}return o};class a extends Error{constructor(t,e,...i){Array.isArray(e)&&(e=e.join(" ")),super(e),void 0!==Error.captureStackTrace&&Error.captureStackTrace(this,a),this.code=t;for(const t of i)for(const e in t){const i=t[e];this[e]=Buffer.isBuffer(i)?i.toString():null==i?i:JSON.parse(JSON.stringify(i))}}}l.Stringifier=s,l.CsvError=a,t.exports=l;const u=function(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)},c=function(t){return t.replace(/([A-Z])/g,(function(t,e){return"_"+e.toLowerCase()}))},f=".".charCodeAt(0),h=/\\(\\)?/g,d=RegExp("[^.[\\]]+|\\[(?:([^\"'][^[]*)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))","g"),_=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,m=/^\w*$/,p=function(t){const e=typeof t;return"symbol"===e||"object"===e&&t&&"[object Symbol]"===function(t){return Object.prototype.toString.call(t)}(t)},g=function(t,e){return Array.isArray(t)?t:function(t,e){if(Array.isArray(t))return!1;const i=typeof t;return!("number"!==i&&"symbol"!==i&&"boolean"!==i&&t&&!p(t))||(m.test(t)||!_.test(t)||null!=e&&t in Object(e))}(t,e)?[t]:function(t){const e=[];return t.charCodeAt(0)===f&&e.push(""),t.replace(d,(function(t,i,o,r){let n=t;o?n=r.replace(h,"$1"):i&&(n=i.trim()),e.push(n)})),e}(t)},y=function(t){if("string"==typeof t||p(t))return t;const e=""+t;return"0"==e&&1/t==-INFINITY?"-0":e},b=function(t,e){let i=0;const o=(e=g(e,t)).length;for(;null!=t&&i<o;)t=t[y(e[i++])];return i&&i===o?t:void 0}},function(t,e,i){const o=i(16),r=i(1),n=i(3),s=i(0);class l extends s.Transform{constructor({header:t}){super({objectMode:!0}),this.structure=null,this.header=t}_transform(t,e,i){this.structure?(this.push(o(this.structure.columns.map(t=>t.columnName),t)),i()):(this.header?(this.structure={columns:t.map(t=>({columnName:t}))},this.push(this.structure)):(this.structure={columns:t.map((t,e)=>({columnName:"col"+(e+1)}))},this.push(this.structure),this.push(o(this.structure.columns.map(t=>t.columnName),t))),i())}}t.exports=async function({fileName:t,encoding:e="utf-8",header:i=!0,delimiter:o,limitRows:s}){console.log("Reading file "+t);const a=r.parse({delimiter:o,skip_lines_with_error:!0,to_line:s?s+1:-1}),u=n.createReadStream(t,e),c=new l({header:i});return u.pipe(a),a.pipe(c),c}},function(t,e,i){var o=i(17),r=i(32);t.exports=function(t,e){return r(t||[],e||[],o)}},function(t,e,i){var o=i(18),r=i(31),n=Object.prototype.hasOwnProperty;t.exports=function(t,e,i){var s=t[e];n.call(t,e)&&r(s,i)&&(void 0!==i||e in t)||o(t,e,i)}},function(t,e,i){var o=i(19);t.exports=function(t,e,i){"__proto__"==e&&o?o(t,e,{configurable:!0,enumerable:!0,value:i,writable:!0}):t[e]=i}},function(t,e,i){var o=i(20),r=function(){try{var t=o(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();t.exports=r},function(t,e,i){var o=i(21),r=i(30);t.exports=function(t,e){var i=r(t,e);return o(i)?i:void 0}},function(t,e,i){var o=i(22),r=i(27),n=i(6),s=i(29),l=/^\[object .+?Constructor\]$/,a=Function.prototype,u=Object.prototype,c=a.toString,f=u.hasOwnProperty,h=RegExp("^"+c.call(f).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");t.exports=function(t){return!(!n(t)||r(t))&&(o(t)?h:l).test(s(t))}},function(t,e,i){var o=i(23),r=i(6);t.exports=function(t){if(!r(t))return!1;var e=o(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}},function(t,e,i){var o=i(4),r=i(25),n=i(26),s=o?o.toStringTag:void 0;t.exports=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":s&&s in Object(t)?r(t):n(t)}},function(t,e){var i="object"==typeof global&&global&&global.Object===Object&&global;t.exports=i},function(t,e,i){var o=i(4),r=Object.prototype,n=r.hasOwnProperty,s=r.toString,l=o?o.toStringTag:void 0;t.exports=function(t){var e=n.call(t,l),i=t[l];try{t[l]=void 0;var o=!0}catch(t){}var r=s.call(t);return o&&(e?t[l]=i:delete t[l]),r}},function(t,e){var i=Object.prototype.toString;t.exports=function(t){return i.call(t)}},function(t,e,i){var o,r=i(28),n=(o=/[^.]+$/.exec(r&&r.keys&&r.keys.IE_PROTO||""))?"Symbol(src)_1."+o:"";t.exports=function(t){return!!n&&n in t}},function(t,e,i){var o=i(5)["__core-js_shared__"];t.exports=o},function(t,e){var i=Function.prototype.toString;t.exports=function(t){if(null!=t){try{return i.call(t)}catch(t){}try{return t+""}catch(t){}}return""}},function(t,e){t.exports=function(t,e){return null==t?void 0:t[e]}},function(t,e){t.exports=function(t,e){return t===e||t!=t&&e!=e}},function(t,e){t.exports=function(t,e,i){for(var o=-1,r=t.length,n=e.length,s={};++o<r;){var l=o<n?e[o]:void 0;i(s,t[o],l)}return s}}]); | ||
module.exports=function(t){var e={};function i(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,o){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(i.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(o,r,function(e){return t[e]}.bind(null,r));return o},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=7)}([function(t,e){t.exports=require("stream")},function(t,e,i){t.exports={generate:i(9),parse:i(10),transform:i(12),stringify:i(14)}},function(t,e){t.exports=require("util")},function(t,e){t.exports=require("fs")},function(t,e,i){var o=i(5).Symbol;t.exports=o},function(t,e,i){var o=i(24),r="object"==typeof self&&self&&self.Object===Object&&self,n=o||r||Function("return this")();t.exports=n},function(t,e){t.exports=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}},function(t,e,i){const o=i(8),r=i(15);t.exports={shellApi:{csvWriter:o,csvReader:r}}},function(t,e,i){const o=i(1),r=i(3),n=i(0);class s extends n.Transform{constructor({header:t}){super({objectMode:!0}),this.structure=null,this.header=t}_transform(t,e,i){this.structure?(this.push(this.structure.columns.map(e=>t[e.columnName])),i()):(this.structure=t,this.header&&this.push(t.columns.map(t=>t.columnName)),i())}}t.exports=async function({fileName:t,encoding:e="utf-8",header:i=!0,delimiter:n,quoted:l}){console.log("Writing file "+t);const a=new s({header:i}),u=o.stringify({delimiter:n,quoted:l}),c=r.createWriteStream(t,e);return a.pipe(u),u.pipe(c),a.finisher=c,a}},function(t,e,i){var o,r,n,s=[].indexOf;r=i(0),n=i(2),t.exports=function(){var t,e,i,r;return 2===arguments.length?(r=arguments[0],t=arguments[1]):1===arguments.length?"function"==typeof arguments[0]?(r={},t=arguments[0]):r=arguments[0]:0===arguments.length&&(r={}),i=new o(r),t&&(e=[],i.on("readable",(function(){var t,o;for(o=[];t=i.read();)o.push(e.push(t));return o})),i.on("error",t),i.on("end",(function(){return i.options.objectMode||(e=i.options.encoding?e.join(""):Buffer.concat(e)),t(null,e)}))),i},o=function(t={}){var e,i,n,l,a,u,c,f,h,d,_,m,p,g,y,b,v,w,O;for(b in t.high_water_mark&&(t.highWaterMark=t.high_water_mark),t.object_mode&&(t.objectMode=t.object_mode),r.Readable.call(this,t),this.options={},t)O=t[b],this.options[o.camelize(b)]=O;for(null==(i=this.options).columns&&(i.columns=8),null==(n=this.options).delimiter&&(n.delimiter=","),null==(u=this.options).duration&&(u.duration=null),null==(c=this.options).encoding&&(c.encoding=null),null==(f=this.options).end&&(f.end=null),null==(h=this.options).eof&&(h.eof=!1),null==(d=this.options).fixedSize&&(d.fixedSize=!1),null==(_=this.options).length&&(_.length=-1),null==(m=this.options).maxWordLength&&(m.maxWordLength=16),null==(p=this.options).rowDelimiter&&(p.rowDelimiter="\n"),null==(l=this.options).seed&&(l.seed=!1),null==(a=this.options).sleep&&(a.sleep=0),!0===this.options.eof&&(this.options.eof=this.options.rowDelimiter),this._={start_time:this.options.duration?Date.now():null,fixed_size_buffer:"",count_written:0,count_created:0},"number"==typeof this.options.columns&&(this.options.columns=new Array(this.options.columns)),e=Object.keys(o).filter((function(t){return"super_"!==t&&"camelize"!==t})),g=y=0,v=(w=this.options.columns).length;y<v;g=++y)if(null==(O=w[g])&&(O="ascii"),"string"==typeof O){if(s.call(e,O)<0)throw Error(`Invalid column type: got "${O}", default values are ${JSON.stringify(e)}`);this.options.columns[g]=o[O]}return this},n.inherits(o,r.Readable),t.exports.Generator=o,o.prototype.random=function(){return this.options.seed?this.options.seed=this.options.seed*Math.PI*100%100/100:Math.random()},o.prototype.end=function(){return this.push(null)},o.prototype._read=function(t){var e,i,o,r,n,s,l,a,u,c,f,h,d,_;for(e=[],(u=this._.fixed_size_buffer.length)&&e.push(this._.fixed_size_buffer);;){if(this._.count_created===this.options.length||this.options.end&&Date.now()>this.options.end||this.options.duration&&Date.now()>this._.start_time+this.options.duration){if(e.length)if(this.options.objectMode)for(o=0,n=e.length;o<n;o++)c=e[o],this.__push(c);else this.__push(e.join("")+(this.options.eof?this.options.eof:""));return this.push(null)}for(c=[],r=0,s=(_=this.options.columns).length;r<s;r++)i=_[r],c.push(""+i(this));if(this.options.objectMode)for(f=0,h=0,l=c.length;h<l;h++)f+=c[h].length;else f=(c=`${0===this._.count_created?"":this.options.rowDelimiter}${c.join(this.options.delimiter)}`).length;if(this._.count_created++,u+f>t){if(this.options.objectMode)for(e.push(c),d=0,a=e.length;d<a;d++)c=e[d],this.__push(c);else this.options.fixedSize?(this._.fixed_size_buffer=c.substr(t-u),e.push(c.substr(0,t-u))):e.push(c),this.__push(e.join(""));break}u+=f,e.push(c)}},o.prototype.__push=function(t){return this._.count_written++,this.options.sleep>0?setTimeout(()=>this.push(t),this.options.sleep):this.push(t)},o.ascii=function(t){var e,i,o,r;for(i=[],o=0,r=Math.ceil(t.random()*t.options.maxWordLength);0<=r?o<r:o>r;0<=r?++o:--o)e=Math.floor(32*t.random()),i.push(String.fromCharCode(e+(e<16?65:81)));return i.join("")},o.int=function(t){return Math.floor(t.random()*Math.pow(2,52))},o.bool=function(t){return Math.floor(2*t.random())},o.camelize=function(t){return t.replace(/_([a-z])/gi,(function(t,e,i){return e.toUpperCase()}))}},function(t,e,i){const{Transform:o}=i(0),r=i(11),n={utf8:Buffer.from([239,187,191]),utf16le:Buffer.from([255,254])};class s extends o{constructor(t={}){super({readableObjectMode:!0,...t,encoding:null}),this.__originalOptions=t,this.__normalizeOptions(t)}__normalizeOptions(t){const e={};for(let i in t)e[u(i)]=t[i];if(void 0===e.encoding||!0===e.encoding)e.encoding="utf8";else if(null===e.encoding||!1===e.encoding)e.encoding=null;else if("string"!=typeof e.encoding&&null!==e.encoding)throw new a("CSV_INVALID_OPTION_ENCODING",["Invalid option encoding:","encoding must be a string or null to return a buffer,","got "+JSON.stringify(e.encoding)],e);if(void 0===e.bom||null===e.bom||!1===e.bom)e.bom=!1;else if(!0!==e.bom)throw new a("CSV_INVALID_OPTION_BOM",["Invalid option bom:","bom must be true,","got "+JSON.stringify(e.bom)],e);let i=null;if(void 0===e.cast||null===e.cast||!1===e.cast||""===e.cast)e.cast=void 0;else if("function"==typeof e.cast)i=e.cast,e.cast=!0;else if(!0!==e.cast)throw new a("CSV_INVALID_OPTION_CAST",["Invalid option cast:","cast must be true or a function,","got "+JSON.stringify(e.cast)],e);if(void 0===e.cast_date||null===e.cast_date||!1===e.cast_date||""===e.cast_date)e.cast_date=!1;else if(!0===e.cast_date)e.cast_date=function(t){const e=Date.parse(t);return isNaN(e)?t:new Date(e)};else if("function"!=typeof e.cast_date)throw new a("CSV_INVALID_OPTION_CAST_DATE",["Invalid option cast_date:","cast_date must be true or a function,","got "+JSON.stringify(e.cast_date)],e);let o=null;if(!0===e.columns)o=void 0;else if("function"==typeof e.columns)o=e.columns,e.columns=!0;else if(Array.isArray(e.columns))e.columns=h(e.columns);else{if(void 0!==e.columns&&null!==e.columns&&!1!==e.columns)throw new a("CSV_INVALID_OPTION_COLUMNS",["Invalid option columns:","expect an object, a function or true,","got "+JSON.stringify(e.columns)],e);e.columns=!1}if(void 0===e.columns_duplicates_to_array||null===e.columns_duplicates_to_array||!1===e.columns_duplicates_to_array)e.columns_duplicates_to_array=!1;else if(!0!==e.columns_duplicates_to_array)throw new a("CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY",["Invalid option columns_duplicates_to_array:","expect an boolean,","got "+JSON.stringify(e.columns_duplicates_to_array)],e);if(void 0===e.comment||null===e.comment||!1===e.comment||""===e.comment)e.comment=null;else if("string"==typeof e.comment&&(e.comment=Buffer.from(e.comment,e.encoding)),!Buffer.isBuffer(e.comment))throw new a("CSV_INVALID_OPTION_COMMENT",["Invalid option comment:","comment must be a buffer or a string,","got "+JSON.stringify(e.comment)],e);const n=JSON.stringify(e.delimiter);if(Array.isArray(e.delimiter)||(e.delimiter=[e.delimiter]),0===e.delimiter.length)throw new a("CSV_INVALID_OPTION_DELIMITER",["Invalid option delimiter:","delimiter must be a non empty string or buffer or array of string|buffer,","got "+n],e);if(e.delimiter=e.delimiter.map((function(t){if(null==t||!1===t)return Buffer.from(",",e.encoding);if("string"==typeof t&&(t=Buffer.from(t,e.encoding)),!Buffer.isBuffer(t)||0===t.length)throw new a("CSV_INVALID_OPTION_DELIMITER",["Invalid option delimiter:","delimiter must be a non empty string or buffer or array of string|buffer,","got "+n],e);return t})),void 0===e.escape||!0===e.escape?e.escape=Buffer.from('"',e.encoding):"string"==typeof e.escape?e.escape=Buffer.from(e.escape,e.encoding):null!==e.escape&&!1!==e.escape||(e.escape=null),null!==e.escape&&!Buffer.isBuffer(e.escape))throw new Error("Invalid Option: escape must be a buffer, a string or a boolean, got "+JSON.stringify(e.escape));if(void 0===e.from||null===e.from)e.from=1;else{if("string"==typeof e.from&&/\d+/.test(e.from)&&(e.from=parseInt(e.from)),!Number.isInteger(e.from))throw new Error("Invalid Option: from must be an integer, got "+JSON.stringify(e.from));if(e.from<0)throw new Error("Invalid Option: from must be a positive integer, got "+JSON.stringify(t.from))}if(void 0===e.from_line||null===e.from_line)e.from_line=1;else{if("string"==typeof e.from_line&&/\d+/.test(e.from_line)&&(e.from_line=parseInt(e.from_line)),!Number.isInteger(e.from_line))throw new Error("Invalid Option: from_line must be an integer, got "+JSON.stringify(t.from_line));if(e.from_line<=0)throw new Error("Invalid Option: from_line must be a positive integer greater than 0, got "+JSON.stringify(t.from_line))}if(void 0===e.info||null===e.info||!1===e.info)e.info=!1;else if(!0!==e.info)throw new Error("Invalid Option: info must be true, got "+JSON.stringify(e.info));if(void 0===e.max_record_size||null===e.max_record_size||!1===e.max_record_size)e.max_record_size=0;else if(Number.isInteger(e.max_record_size)&&e.max_record_size>=0);else{if("string"!=typeof e.max_record_size||!/\d+/.test(e.max_record_size))throw new Error("Invalid Option: max_record_size must be a positive integer, got "+JSON.stringify(e.max_record_size));e.max_record_size=parseInt(e.max_record_size)}if(void 0===e.objname||null===e.objname||!1===e.objname)e.objname=void 0;else if(Buffer.isBuffer(e.objname)){if(0===e.objname.length)throw new Error("Invalid Option: objname must be a non empty buffer");null===e.encoding||(e.objname=e.objname.toString(e.encoding))}else{if("string"!=typeof e.objname)throw new Error("Invalid Option: objname must be a string or a buffer, got "+e.objname);if(0===e.objname.length)throw new Error("Invalid Option: objname must be a non empty string")}if(void 0===e.on_record||null===e.on_record)e.on_record=void 0;else if("function"!=typeof e.on_record)throw new a("CSV_INVALID_OPTION_ON_RECORD",["Invalid option `on_record`:","expect a function,","got "+JSON.stringify(e.on_record)],e);if(null===e.quote||!1===e.quote||""===e.quote)e.quote=null;else if(void 0===e.quote||!0===e.quote?e.quote=Buffer.from('"',e.encoding):"string"==typeof e.quote&&(e.quote=Buffer.from(e.quote,e.encoding)),!Buffer.isBuffer(e.quote))throw new Error("Invalid Option: quote must be a buffer or a string, got "+JSON.stringify(e.quote));if(void 0===e.raw||null===e.raw||!1===e.raw)e.raw=!1;else if(!0!==e.raw)throw new Error("Invalid Option: raw must be true, got "+JSON.stringify(e.raw));if(e.record_delimiter?Array.isArray(e.record_delimiter)||(e.record_delimiter=[e.record_delimiter]):e.record_delimiter=[],e.record_delimiter=e.record_delimiter.map((function(t){return"string"==typeof t&&(t=Buffer.from(t,e.encoding)),t})),"boolean"==typeof e.relax);else{if(void 0!==e.relax&&null!==e.relax)throw new Error("Invalid Option: relax must be a boolean, got "+JSON.stringify(e.relax));e.relax=!1}if("boolean"==typeof e.relax_column_count);else{if(void 0!==e.relax_column_count&&null!==e.relax_column_count)throw new Error("Invalid Option: relax_column_count must be a boolean, got "+JSON.stringify(e.relax_column_count));e.relax_column_count=!1}if("boolean"==typeof e.relax_column_count_less);else{if(void 0!==e.relax_column_count_less&&null!==e.relax_column_count_less)throw new Error("Invalid Option: relax_column_count_less must be a boolean, got "+JSON.stringify(e.relax_column_count_less));e.relax_column_count_less=!1}if("boolean"==typeof e.relax_column_count_more);else{if(void 0!==e.relax_column_count_more&&null!==e.relax_column_count_more)throw new Error("Invalid Option: relax_column_count_more must be a boolean, got "+JSON.stringify(e.relax_column_count_more));e.relax_column_count_more=!1}if("boolean"==typeof e.skip_empty_lines);else{if(void 0!==e.skip_empty_lines&&null!==e.skip_empty_lines)throw new Error("Invalid Option: skip_empty_lines must be a boolean, got "+JSON.stringify(e.skip_empty_lines));e.skip_empty_lines=!1}if("boolean"==typeof e.skip_lines_with_empty_values);else{if(void 0!==e.skip_lines_with_empty_values&&null!==e.skip_lines_with_empty_values)throw new Error("Invalid Option: skip_lines_with_empty_values must be a boolean, got "+JSON.stringify(e.skip_lines_with_empty_values));e.skip_lines_with_empty_values=!1}if("boolean"==typeof e.skip_lines_with_error);else{if(void 0!==e.skip_lines_with_error&&null!==e.skip_lines_with_error)throw new Error("Invalid Option: skip_lines_with_error must be a boolean, got "+JSON.stringify(e.skip_lines_with_error));e.skip_lines_with_error=!1}if(void 0===e.rtrim||null===e.rtrim||!1===e.rtrim)e.rtrim=!1;else if(!0!==e.rtrim)throw new Error("Invalid Option: rtrim must be a boolean, got "+JSON.stringify(e.rtrim));if(void 0===e.ltrim||null===e.ltrim||!1===e.ltrim)e.ltrim=!1;else if(!0!==e.ltrim)throw new Error("Invalid Option: ltrim must be a boolean, got "+JSON.stringify(e.ltrim));if(void 0===e.trim||null===e.trim||!1===e.trim)e.trim=!1;else if(!0!==e.trim)throw new Error("Invalid Option: trim must be a boolean, got "+JSON.stringify(e.trim));if(!0===e.trim&&!1!==t.ltrim?e.ltrim=!0:!0!==e.ltrim&&(e.ltrim=!1),!0===e.trim&&!1!==t.rtrim?e.rtrim=!0:!0!==e.rtrim&&(e.rtrim=!1),void 0===e.to||null===e.to)e.to=-1;else{if("string"==typeof e.to&&/\d+/.test(e.to)&&(e.to=parseInt(e.to)),!Number.isInteger(e.to))throw new Error("Invalid Option: to must be an integer, got "+JSON.stringify(t.to));if(e.to<=0)throw new Error("Invalid Option: to must be a positive integer greater than 0, got "+JSON.stringify(t.to))}if(void 0===e.to_line||null===e.to_line)e.to_line=-1;else{if("string"==typeof e.to_line&&/\d+/.test(e.to_line)&&(e.to_line=parseInt(e.to_line)),!Number.isInteger(e.to_line))throw new Error("Invalid Option: to_line must be an integer, got "+JSON.stringify(t.to_line));if(e.to_line<=0)throw new Error("Invalid Option: to_line must be a positive integer greater than 0, got "+JSON.stringify(t.to_line))}this.info={comment_lines:0,empty_lines:0,invalid_field_length:0,lines:1,records:0},this.options=e,this.state={bomSkipped:!1,castField:i,commenting:!1,error:void 0,enabled:1===e.from_line,escaping:!1,escapeIsQuote:Buffer.isBuffer(e.escape)&&Buffer.isBuffer(e.quote)&&0===Buffer.compare(e.escape,e.quote),expectedRecordLength:null===e.columns?0:e.columns.length,field:new r(20),firstLineToHeaders:o,info:Object.assign({},this.info),needMoreDataSize:Math.max(null!==e.comment?e.comment.length:0,...e.delimiter.map(t=>t.length),null!==e.quote?e.quote.length:0),previousBuf:void 0,quoting:!1,stop:!1,rawBuffer:new r(100),record:[],recordHasError:!1,record_length:0,recordDelimiterMaxLength:0===e.record_delimiter.length?2:Math.max(...e.record_delimiter.map(t=>t.length)),trimChars:[Buffer.from(" ",e.encoding)[0],Buffer.from("\t",e.encoding)[0]],wasQuoting:!1,wasRowDelimiter:!1}}_transform(t,e,i){if(!0===this.state.stop)return;const o=this.__parse(t,!1);void 0!==o&&(this.state.stop=!0),i(o)}_flush(t){if(!0===this.state.stop)return;t(this.__parse(void 0,!0))}__parse(t,e){const{bom:i,comment:o,escape:r,from_line:s,info:l,ltrim:u,max_record_size:c,quote:f,raw:h,relax:d,rtrim:_,skip_empty_lines:m,to:p,to_line:g}=this.options;let{record_delimiter:y}=this.options;const{bomSkipped:b,previousBuf:v,rawBuffer:w,escapeIsQuote:O}=this.state;let x;if(void 0===v){if(void 0===t)return void this.push(null);x=t}else x=void 0!==v&&void 0===t?v:Buffer.concat([v,t]);if(!1===b)if(!1===i)this.state.bomSkipped=!0;else if(x.length<3){if(!1===e)return void(this.state.previousBuf=x)}else{for(let t in n)if(0===n[t].compare(x,0,n[t].length)){x=x.slice(n[t].length),this.__normalizeOptions({...this.__originalOptions,encoding:t});break}this.state.bomSkipped=!0}const I=x.length;let S;for(S=0;S<I&&!this.__needMoreData(S,I,e);S++){if(!0===this.state.wasRowDelimiter&&(this.info.lines++,!0===l&&0===this.state.record.length&&0===this.state.field.length&&!1===this.state.wasQuoting&&(this.state.info=Object.assign({},this.info)),this.state.wasRowDelimiter=!1),-1!==g&&this.info.lines>g)return this.state.stop=!0,void this.push(null);if(!1===this.state.quoting&&0===y.length){this.__autoDiscoverRowDelimiter(x,S)&&(y=this.options.record_delimiter)}const t=x[S];if(!0===h&&w.append(t),13!==t&&10!==t||!1!==this.state.wasRowDelimiter||(this.state.wasRowDelimiter=!0),!0===this.state.escaping)this.state.escaping=!1;else{if(null!==r&&!0===this.state.quoting&&this.__isEscape(x,S,t)&&S+r.length<I){if(!O){this.state.escaping=!0,S+=r.length-1;continue}if(this.__isQuote(x,S+r.length)){this.state.escaping=!0,S+=r.length-1;continue}}if(!1===this.state.commenting&&this.__isQuote(x,S))if(!0===this.state.quoting){const e=x[S+f.length],i=_&&this.__isCharTrimable(e),n=null!==o&&this.__compareBytes(o,x,S+f.length,e),s=this.__isDelimiter(x,S+f.length,e),l=0===y.length?this.__autoDiscoverRowDelimiter(x,S+f.length):this.__isRecordDelimiter(e,x,S+f.length);if(null!==r&&this.__isEscape(x,S,t)&&this.__isQuote(x,S+r.length))S+=r.length-1;else{if(!e||s||l||n||i){this.state.quoting=!1,this.state.wasQuoting=!0,S+=f.length-1;continue}if(!1===d){const t=this.__error(new a("CSV_INVALID_CLOSING_QUOTE",["Invalid Closing Quote:",`got "${String.fromCharCode(e)}"`,"at line "+this.info.lines,"instead of delimiter, row delimiter, trimable character","(if activated) or comment"],this.options,this.__context()));if(void 0!==t)return t}else this.state.quoting=!1,this.state.wasQuoting=!0,this.state.field.prepend(f),S+=f.length-1}}else{if(0===this.state.field.length){this.state.quoting=!0,S+=f.length-1;continue}if(!1===d){const t=this.__error(new a("INVALID_OPENING_QUOTE",["Invalid Opening Quote:","a quote is found inside a field at line "+this.info.lines],this.options,this.__context(),{field:this.state.field}));if(void 0!==t)return t}}if(!1===this.state.quoting){let e=this.__isRecordDelimiter(t,x,S);if(0!==e){if(this.state.commenting&&!1===this.state.wasQuoting&&0===this.state.record.length&&0===this.state.field.length)this.info.comment_lines++;else{if(!0===m&&!1===this.state.wasQuoting&&0===this.state.record.length&&0===this.state.field.length){this.info.empty_lines++,S+=e-1;continue}if(!1===this.state.enabled&&this.info.lines+(!0===this.state.wasRowDelimiter?1:0)>=s){this.state.enabled=!0,this.__resetField(),this.__resetRow(),S+=e-1;continue}{const t=this.__onField();if(void 0!==t)return t;const e=this.__onRow();if(void 0!==e)return e}if(-1!==p&&this.info.records>=p)return this.state.stop=!0,void this.push(null)}this.state.commenting=!1,S+=e-1;continue}if(this.state.commenting)continue;if(0!==(null===o?0:this.__compareBytes(o,x,S,t))){this.state.commenting=!0;continue}let i=this.__isDelimiter(x,S,t);if(0!==i){const t=this.__onField();if(void 0!==t)return t;S+=i-1;continue}}}if(!1===this.state.commenting&&0!==c&&this.state.record_length+this.state.field.length>c){const t=this.__error(new a("CSV_MAX_RECORD_SIZE",["Max Record Size:","record exceed the maximum number of tolerated bytes","of "+c,"at line "+this.info.lines],this.options,this.__context()));if(void 0!==t)return t}const e=!1===u||!0===this.state.quoting||0!==this.state.field.length||!this.__isCharTrimable(t),i=!1===_||!1===this.state.wasQuoting;if(!0===e&&!0===i)this.state.field.append(t);else if(!0===_&&!this.__isCharTrimable(t)){const t=this.__error(new a("CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE",["Invalid Closing Quote:","found non trimable byte after quote","at line "+this.info.lines],this.options,this.__context()));if(void 0!==t)return t}}if(!0===e)if(!0===this.state.quoting){const t=this.__error(new a("CSV_QUOTE_NOT_CLOSED",["Quote Not Closed:","the parsing is finished with an opening quote at line "+this.info.lines],this.options,this.__context()));if(void 0!==t)return t}else if(!0===this.state.wasQuoting||0!==this.state.record.length||0!==this.state.field.length){const t=this.__onField();if(void 0!==t)return t;const e=this.__onRow();if(void 0!==e)return e}else!0===this.state.wasRowDelimiter?this.info.empty_lines++:!0===this.state.commenting&&this.info.comment_lines++;else this.state.previousBuf=x.slice(S);!0===this.state.wasRowDelimiter&&(this.info.lines++,this.state.wasRowDelimiter=!1)}__isCharTrimable(t){return 32===t||9===t||13===t||10===t||12===t}__onRow(){const{columns:t,columns_duplicates_to_array:e,encoding:i,info:o,from:r,relax_column_count:n,relax_column_count_less:s,relax_column_count_more:l,raw:u,skip_lines_with_empty_values:c}=this.options,{enabled:h,record:d}=this.state;if(!1===h)return this.__resetRow();const _=d.length;if(!0===t)return f(d)?void this.__resetRow():this.__firstLineToColumns(d);if(!1===t&&0===this.info.records&&(this.state.expectedRecordLength=_),_!==this.state.expectedRecordLength){const e=!1===t?this.__error(new a("CSV_INCONSISTENT_RECORD_LENGTH",["Invalid Record Length:",`expect ${this.state.expectedRecordLength},`,`got ${_} on line ${this.info.lines}`],this.options,this.__context(),{record:d})):this.__error(new a("CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH",["Invalid Record Length:",`columns length is ${t.length},`,`got ${_} on line ${this.info.lines}`],this.options,this.__context(),{record:d}));if(!0===n||!0===s&&_<this.state.expectedRecordLength||!0===l&&_>this.state.expectedRecordLength)this.info.invalid_field_length++,this.state.error=e;else if(void 0!==e)return e}if(!0===c&&f(d))this.__resetRow();else{if(!0===this.state.recordHasError)return this.__resetRow(),void(this.state.recordHasError=!1);if(this.info.records++,1===r||this.info.records>=r)if(!1!==t){const r={};for(let i=0,o=d.length;i<o;i++)void 0===t[i]||t[i].disabled||(!0===e&&r[t[i].name]?Array.isArray(r[t[i].name])?r[t[i].name]=r[t[i].name].concat(d[i]):r[t[i].name]=[r[t[i].name],d[i]]:r[t[i].name]=d[i]);const{objname:n}=this.options;if(void 0===n)if(!0===u||!0===o){const t=this.__push(Object.assign({record:r},!0===u?{raw:this.state.rawBuffer.toString(i)}:{},!0===o?{info:this.state.info}:{}));if(t)return t}else{const t=this.__push(r);if(t)return t}else if(!0===u||!0===o){const t=this.__push(Object.assign({record:[r[n],r]},!0===u?{raw:this.state.rawBuffer.toString(i)}:{},!0===o?{info:this.state.info}:{}));if(t)return t}else{const t=this.__push([r[n],r]);if(t)return t}}else if(!0===u||!0===o){const t=this.__push(Object.assign({record:d},!0===u?{raw:this.state.rawBuffer.toString(i)}:{},!0===o?{info:this.state.info}:{}));if(t)return t}else{const t=this.__push(d);if(t)return t}this.__resetRow()}}__firstLineToColumns(t){const{firstLineToHeaders:e}=this.state;try{const i=void 0===e?t:e.call(null,t);if(!Array.isArray(i))return this.__error(new a("CSV_INVALID_COLUMN_MAPPING",["Invalid Column Mapping:","expect an array from column function,","got "+JSON.stringify(i)],this.options,this.__context(),{headers:i}));const o=h(i);return this.state.expectedRecordLength=o.length,this.options.columns=o,void this.__resetRow()}catch(t){return t}}__resetRow(){!0===this.options.raw&&this.state.rawBuffer.reset(),this.state.error=void 0,this.state.record=[],this.state.record_length=0}__onField(){const{cast:t,encoding:e,rtrim:i,max_record_size:o}=this.options,{enabled:r,wasQuoting:n}=this.state;if(!1===r)return this.__resetField();let s=this.state.field.toString(e);if(!0===i&&!1===n&&(s=s.trimRight()),!0===t){const[t,e]=this.__cast(s);if(void 0!==t)return t;s=e}this.state.record.push(s),0!==o&&"string"==typeof s&&(this.state.record_length+=s.length),this.__resetField()}__resetField(){this.state.field.reset(),this.state.wasQuoting=!1}__push(t){const{on_record:e}=this.options;if(void 0!==e){const i=this.__context();try{t=e.call(null,t,i)}catch(t){return t}if(null==t)return}this.push(t)}__cast(t){const{columns:e,relax_column_count:i}=this.options;if(!0===Array.isArray(e)&&i&&this.options.columns.length<=this.state.record.length)return[void 0,void 0];const o=this.__context();if(null!==this.state.castField)try{return[void 0,this.state.castField.call(null,t,o)]}catch(t){return[t]}return this.__isFloat(t)?[void 0,parseFloat(t)]:!1!==this.options.cast_date?[void 0,this.options.cast_date.call(null,t,o)]:[void 0,t]}__isFloat(t){return t-parseFloat(t)+1>=0}__compareBytes(t,e,i,o){if(t[0]!==o)return 0;const r=t.length;for(let o=1;o<r;o++)if(t[o]!==e[i+o])return 0;return r}__needMoreData(t,e,i){if(i)return!1;const{quote:o}=this.options,{quoting:r,needMoreDataSize:n,recordDelimiterMaxLength:s}=this.state;return e-t-1<Math.max(n,s,r?o.length+s:0)}__isDelimiter(t,e,i){const{delimiter:o}=this.options;t:for(let r=0;r<o.length;r++){const n=o[r];if(n[0]===i){for(let i=1;i<n.length;i++)if(n[i]!==t[e+i])continue t;return n.length}}return 0}__isRecordDelimiter(t,e,i){const{record_delimiter:o}=this.options,r=o.length;t:for(let n=0;n<r;n++){const r=o[n],s=r.length;if(r[0]===t){for(let t=1;t<s;t++)if(r[t]!==e[i+t])continue t;return r.length}}return 0}__isEscape(t,e,i){const{escape:o}=this.options;if(null===o)return!1;const r=o.length;if(o[0]===i){for(let i=0;i<r;i++)if(o[i]!==t[e+i])return!1;return!0}return!1}__isQuote(t,e){const{quote:i}=this.options;if(null===i)return!1;const o=i.length;for(let r=0;r<o;r++)if(i[r]!==t[e+r])return!1;return!0}__autoDiscoverRowDelimiter(t,e){const{encoding:i}=this.options,o=t[e];return 13===o?10===t[e+1]?(this.options.record_delimiter.push(Buffer.from("\r\n",i)),this.state.recordDelimiterMaxLength=2,2):(this.options.record_delimiter.push(Buffer.from("\r",i)),this.state.recordDelimiterMaxLength=1,1):10===o?(this.options.record_delimiter.push(Buffer.from("\n",i)),this.state.recordDelimiterMaxLength=1,1):0}__error(t){const{skip_lines_with_error:e}=this.options,i="string"==typeof t?new Error(t):t;return e?(this.state.recordHasError=!0,void this.emit("skip",i)):i}__context(){const{columns:t}=this.options;return{column:!0===Array.isArray(t)?t.length>this.state.record.length?t[this.state.record.length].name:null:this.state.record.length,empty_lines:this.info.empty_lines,error:this.state.error,header:!0===t,index:this.state.record.length,invalid_field_length:this.info.invalid_field_length,quoting:this.state.wasQuoting,lines:this.info.lines,records:this.info.records}}}const l=function(){let t,e,i;for(let o in arguments){const r=arguments[o],n=typeof r;if(void 0!==t||"string"!=typeof r&&!Buffer.isBuffer(r))if(void 0===e&&c(r))e=r;else{if(void 0!==i||"function"!==n)throw new a("CSV_INVALID_ARGUMENT",["Invalid argument:",`got ${JSON.stringify(r)} at index ${o}`],this.options);i=r}else t=r}const o=new s(e);if(i){const t=void 0===e||void 0===e.objname?[]:{};o.on("readable",(function(){let i;for(;null!==(i=this.read());)void 0===e||void 0===e.objname?t.push(i):t[i[0]]=i[1]})),o.on("error",(function(t){i(t,void 0,o.info)})),o.on("end",(function(){i(void 0,t,o.info)}))}return void 0!==t&&("function"==typeof setImmediate?setImmediate((function(){o.write(t),o.end()})):(o.write(t),o.end())),o};class a extends Error{constructor(t,e,i,...o){Array.isArray(e)&&(e=e.join(" ")),super(e),void 0!==Error.captureStackTrace&&Error.captureStackTrace(this,a),this.code=t;for(const t of o)for(const e in t){const o=t[e];this[e]=Buffer.isBuffer(o)?o.toString(i.encoding):null==o?o:JSON.parse(JSON.stringify(o))}}}l.Parser=s,l.CsvError=a,t.exports=l;const u=function(t){return t.replace(/([A-Z])/g,(function(t,e){return"_"+e.toLowerCase()}))},c=function(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)},f=function(t){return t.every(t=>null==t||t.toString&&""===t.toString().trim())},h=function(t){const e=[];for(let i=0,o=t.length;i<o;i++){const o=t[i];if(null==o||!1===o)e[i]={disabled:!0};else if("string"==typeof o)e[i]={name:o};else{if(!c(o))throw new a("CSV_INVALID_COLUMN_DEFINITION",["Invalid column definition:","expect a string or a literal object,",`got ${JSON.stringify(o)} at position ${i}`]);if("string"!=typeof o.name)throw new a("CSV_OPTION_COLUMNS_MISSING_NAME",["Option columns missing name:",'property "name" is required at position '+i,"when column is an object literal"]);e[i]=o}}return e}},function(t,e){t.exports=class{constructor(t=100){this.size=t,this.length=0,this.buf=Buffer.alloc(t)}prepend(t){if(Buffer.isBuffer(t)){const e=this.length+t.length;if(e>=this.size&&(this.resize(),e>=this.size))throw Error("INVALID_BUFFER_STATE");const i=this.buf;this.buf=Buffer.alloc(this.size),t.copy(this.buf,0),i.copy(this.buf,t.length),this.length+=t.length}else{const e=this.length++;e===this.size&&this.resize();const i=this.clone();this.buf[0]=t,i.copy(this.buf,1,0,e)}}append(t){const e=this.length++;e===this.size&&this.resize(),this.buf[e]=t}clone(){return Buffer.from(this.buf.slice(0,this.length))}resize(){const t=this.length;this.size=2*this.size;const e=Buffer.alloc(this.size);this.buf.copy(e,0,0,t),this.buf=e}toString(t){return t?this.buf.slice(0,this.length).toString(t):Uint8Array.prototype.slice.call(this.buf.slice(0,this.length))}toJSON(){return this.toString("utf8")}reset(){this.length=0}}},function(t,e,i){var o,r,n,s;n=i(0),s=i(2),({clone:r}=i(13)),t.exports=function(){var t,e,i,n,s,l,a,u,c,f,h,d;for(u={},s=l=0,a=arguments.length;l<a;s=++l)if(d=typeof(t=arguments[s]),null===t?d="null":"object"===d&&Array.isArray(t)&&(d="array"),"array"===d)c=t;else if("object"===d)u=r(t);else if("function"===d)n&&s===arguments.length-1?e=t:n=t;else if("null"!==d)throw new Error(`Invalid Arguments: got ${JSON.stringify(t)} at position ${s}`);return h=new o(u,n),i=!1,c&&setImmediate((function(){var t,e,o;for(t=0,e=c.length;t<e&&(o=c[t],!i);t++)h.write(o);return h.end()})),(e||u.consume)&&(f=[],h.on("readable",(function(){var t,i;for(i=[];t=h.read();)e?i.push(f.push(t)):i.push(void 0);return i})),h.on("error",(function(t){if(i=!0,e)return e(t)})),h.on("end",(function(){if(e&&!i)return e(null,f)}))),h},o=function(t={},e){var i,o;return this.options=t,this.handler=e,null==(i=this.options).consume&&(i.consume=!1),this.options.objectMode=!0,null==(o=this.options).parallel&&(o.parallel=100),n.Transform.call(this,this.options),this.state={running:0,started:0,finished:0},this},s.inherits(o,n.Transform),t.exports.Transformer=o,o.prototype._transform=function(t,e,i){var o,r,n;this.state.started++,this.state.running++,this.state.running<this.options.parallel&&(i(),i=null);try{if(n=this.handler.length,null!=this.options.params&&n--,1===n)this.__done(null,[this.handler.call(this,t,this.options.params)],i);else{if(2!==n)throw Error("Invalid handler arguments");o=(t,...e)=>this.__done(t,e,i),this.handler.call(this,t,o,this.options.params)}return!1}catch(t){return r=t,this.__done(r)}},o.prototype._flush=function(t){return this._ending=function(){if(0===this.state.running)return t()},this._ending()},o.prototype.__done=function(t,e,i){var o,r,n;if(this.state.running--,t)return this.emit("error",t);for(this.state.finished++,r=0,n=e.length;r<n;r++)"number"==typeof(o=e[r])&&(o=""+o),null!=o&&""!==o&&this.push(o);return i&&i(),this._ending?this._ending():void 0}},function(t,e,i){"use strict";function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var r,n,s,l,a,u,c,f;i.r(e),i.d(e,"clone",(function(){return n})),i.d(e,"compare",(function(){return s})),i.d(e,"is_object",(function(){return l})),i.d(e,"is_object_literal",(function(){return a})),i.d(e,"merge",(function(){return u})),i.d(e,"mutate",(function(){return c})),i.d(e,"snake_case",(function(){return f})),u=function(){return c.apply(void 0,[{}].concat(Array.prototype.slice.call(arguments)))},n=function(t){return Array.isArray(t)?t.map((function(t){return n(t)})):t&&"object"===o(t)?c({},t):t},c=function(){var t,e,i,o,r,n,s;for(n=arguments[0],t=e=1,o=arguments.length;1<=o?e<o:e>o;t=1<=o?++e:--e)if(a(r=arguments[t]))for(i in a(n)||(n={}),r)n[i]=c(n[i],r[i]);else Array.isArray(r)?n=function(){var t,e,i;for(i=[],t=0,e=r.length;t<e;t++)s=r[t],i.push(c(void 0,s));return i}():void 0!==r&&(n=r);return n},f=function(t){var e,i,o,n,s=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(o={},a(t))for(e in n="number"==typeof s&&s>0?s-1:s,t)i=t[e],s&&(e=r(e)),o[e]=f(i,n);else o=t;return o},s=function(t,e){var i,o,r,n,l,u,c,f;if(a(t)){if(!a(e))return!1;if(l=Object.keys(t).sort(),u=Object.keys(e).sort(),l.length!==u.length)return!1;for(i=o=0,c=l.length;o<c;i=++o){if((n=l[i])!==u[i])return!1;if(!s(t[n],e[n]))return!1}}else if(Array.isArray(t)){if(!Array.isArray(e))return!1;if(t.length!==e.length)return!1;for(i=r=0,f=t.length;0<=f?r<f:r>f;i=0<=f?++r:--r)if(!s(t[i],e[i]))return!1}else if(t!==e)return!1;return!0},r=function(t){return t.replace(/([A-Z])/g,(function(t,e,i){return"_"+e.toLowerCase()}))},l=function(t){return t&&"object"===o(t)&&!Array.isArray(t)},a=function(t){var e;if(e=t,"object"!==o(t)||null===t)return!1;for(;null!==Object.getPrototypeOf(e=Object.getPrototypeOf(e)););return Object.getPrototypeOf(t)===e}},function(t,e,o){const{Transform:r}=o(0),n=Buffer.from([239,187,191]);class s extends r{constructor(t={}){super({writableObjectMode:!0,...t});const e={};let i;for(let i in t)e[c(i)]=t[i];if(i=this.normalize(e))throw i;switch(e.record_delimiter){case"auto":e.record_delimiter=null;break;case"unix":e.record_delimiter="\n";break;case"mac":e.record_delimiter="\r";break;case"windows":e.record_delimiter="\r\n";break;case"ascii":e.record_delimiter="";break;case"unicode":e.record_delimiter="\u2028"}this.options=e,this.state={stop:!1},this.info={records:0}}normalize(t){if(void 0===t.bom||null===t.bom||!1===t.bom)t.bom=!1;else if(!0!==t.bom)return new a("CSV_OPTION_BOOLEAN_INVALID_TYPE",["option `bom` is optional and must be a boolean value,","got "+JSON.stringify(t.bom)]);if(void 0===t.delimiter||null===t.delimiter)t.delimiter=",";else if(Buffer.isBuffer(t.delimiter))t.delimiter=t.delimiter.toString();else if("string"!=typeof t.delimiter)return new a("CSV_OPTION_DELIMITER_INVALID_TYPE",["option `delimiter` must be a buffer or a string,","got "+JSON.stringify(t.delimiter)]);if(void 0===t.quote||null===t.quote)t.quote='"';else if(!0===t.quote)t.quote='"';else if(!1===t.quote)t.quote="";else if(Buffer.isBuffer(t.quote))t.quote=t.quote.toString();else if("string"!=typeof t.quote)return new a("CSV_OPTION_QUOTE_INVALID_TYPE",["option `quote` must be a boolean, a buffer or a string,","got "+JSON.stringify(t.quote)]);if(void 0!==t.quoted&&null!==t.quoted||(t.quoted=!1),void 0!==t.quoted_empty&&null!==t.quoted_empty||(t.quoted_empty=void 0),void 0===t.quoted_match||null===t.quoted_match||!1===t.quoted_match?t.quoted_match=null:Array.isArray(t.quoted_match)||(t.quoted_match=[t.quoted_match]),t.quoted_match)for(let e of t.quoted_match){const t=e instanceof RegExp;if(!("string"==typeof e)&&!t)return Error("Invalid Option: quoted_match must be a string or a regex, got "+JSON.stringify(e))}if(void 0!==t.quoted_string&&null!==t.quoted_string||(t.quoted_string=!1),void 0!==t.eof&&null!==t.eof||(t.eof=!0),void 0===t.escape||null===t.escape)t.escape='"';else if(Buffer.isBuffer(t.escape))t.escape=t.escape.toString();else if("string"!=typeof t.escape)return Error("Invalid Option: escape must be a buffer or a string, got "+JSON.stringify(t.escape));if(t.escape.length>1)return Error(`Invalid Option: escape must be one character, got ${t.escape.length} characters`);if(void 0!==t.header&&null!==t.header||(t.header=!1),t.columns=this.normalize_columns(t.columns),void 0!==t.quoted&&null!==t.quoted||(t.quoted=!1),void 0!==t.cast&&null!==t.cast||(t.cast={}),void 0!==t.cast.bigint&&null!==t.cast.bigint||(t.cast.bigint=t=>""+t),void 0!==t.cast.boolean&&null!==t.cast.boolean||(t.cast.boolean=t=>t?"1":""),void 0!==t.cast.date&&null!==t.cast.date||(t.cast.date=t=>""+t.getTime()),void 0!==t.cast.number&&null!==t.cast.number||(t.cast.number=t=>""+t),void 0!==t.cast.object&&null!==t.cast.object||(t.cast.object=t=>JSON.stringify(t)),void 0!==t.cast.string&&null!==t.cast.string||(t.cast.string=function(t){return t}),void 0===t.record_delimiter||null===t.record_delimiter)t.record_delimiter="\n";else if(Buffer.isBuffer(t.record_delimiter))t.record_delimiter=t.record_delimiter.toString();else if("string"!=typeof t.record_delimiter)return Error("Invalid Option: record_delimiter must be a buffer or a string, got "+JSON.stringify(t.record_delimiter))}_transform(t,e,i){if(!0!==this.state.stop){if(!Array.isArray(t)&&"object"!=typeof t)return this.state.stop=!0,i(Error("Invalid Record: expect an array or an object, got "+JSON.stringify(t)));if(0===this.info.records)if(Array.isArray(t)){if(!0===this.options.header&&!this.options.columns)return this.state.stop=!0,i(Error("Undiscoverable Columns: header option requires column option or object records"))}else void 0!==this.options.columns&&null!==this.options.columns||(this.options.columns=this.normalize_columns(Object.keys(t)));0===this.info.records&&(this.bom(),this.headers());try{this.emit("record",t,this.info.records)}catch(t){return this.state.stop=!0,this.emit("error",t)}if(this.options.eof){if(void 0===(t=this.stringify(t)))return;t+=this.options.record_delimiter}else{if(void 0===(t=this.stringify(t)))return;(this.options.header||this.info.records)&&(t=this.options.record_delimiter+t)}this.info.records++,this.push(t),i()}}_flush(t){0===this.info.records&&(this.bom(),this.headers()),t()}stringify(t,e=!1){if("object"!=typeof t)return t;const{columns:o,header:r}=this.options,n=[];if(Array.isArray(t)){o&&t.splice(o.length);for(let i=0;i<t.length;i++){const o=t[i],[r,s]=this.__cast(o,{index:i,column:i,records:this.info.records,header:e});if(r)return void this.emit("error",r);n[i]=[s,o]}}else if(o)for(let i=0;i<o.length;i++){const r=b(t,o[i].key),[s,l]=this.__cast(r,{index:i,column:o[i].key,records:this.info.records,header:e});if(s)return void this.emit("error",s);n[i]=[l,r]}else for(let r of t){const s=t[r],[l,a]=this.__cast(s,{index:i,column:o[i].key,records:this.info.records,header:e});if(l)return void this.emit("error",l);n.push([a,s])}let s="";for(let t=0;t<n.length;t++){let e,i,[o,r]=n[t];if("string"==typeof o)e=this.options;else if(u(o)){if(e=o,o=e.value,delete e.value,"string"!=typeof o&&null!=o)return void this.emit("error",Error("Invalid Casting Value: returned value must return a string, null or undefined, got "+JSON.stringify(o)));if(e={...this.options,...e},i=this.normalize(e))return void this.emit("error",i)}else{if(null!=o)return void this.emit("error",Error("Invalid Casting Value: returned value must return a string, an object, null or undefined, got "+JSON.stringify(o)));e=this.options}const{delimiter:l,escape:a,quote:c,quoted:f,quoted_empty:h,quoted_string:d,quoted_match:_,record_delimiter:m}=e;if(o){if("string"!=typeof o)return this.emit("error",Error("Formatter must return a string, null or undefined, got "+JSON.stringify(o))),null;const t=l.length&&o.indexOf(l)>=0,e=""!==c&&o.indexOf(c)>=0,i=o.indexOf(a)>=0&&a!==c,n=o.indexOf(m)>=0,u=d&&"string"==typeof r;let h=_&&_.filter(t=>"string"==typeof t?-1!==o.indexOf(t):t.test(o));h=h&&h.length>0;const p=!0===e||t||n||f||u||h;if(!0===p&&!0===i){const t="\\"===a?new RegExp(a+a,"g"):new RegExp(a,"g");o=o.replace(t,a+a)}if(!0===e){const t=new RegExp(c,"g");o=o.replace(t,a+c)}!0===p&&(o=c+o+c),s+=o}else(!0===h||""===r&&!0===d&&!1!==h)&&(s+=c+c);t!==n.length-1&&(s+=l)}return s}bom(){!0===this.options.bom&&this.push(n)}headers(){if(!1===this.options.header)return;if(void 0===this.options.columns)return;let t=this.options.columns.map(t=>t.header);t=this.options.eof?this.stringify(t,!0)+this.options.record_delimiter:this.stringify(t),this.push(t)}__cast(t,e){const i=typeof t;try{return"string"===i?[void 0,this.options.cast.string(t,e)]:"bigint"===i?[void 0,this.options.cast.bigint(t,e)]:"number"===i?[void 0,this.options.cast.number(t,e)]:"boolean"===i?[void 0,this.options.cast.boolean(t,e)]:t instanceof Date?[void 0,this.options.cast.date(t,e)]:"object"===i&&null!==t?[void 0,this.options.cast.object(t,e)]:[void 0,t,t]}catch(t){return[t]}}normalize_columns(t){if(null!=t){if("object"!=typeof t)throw Error('Invalid option "columns": expect an array or an object');if(Array.isArray(t)){const e=[];for(let i of t)if("string"==typeof i)e.push({key:i,header:i});else{if("object"!=typeof i||void 0===i||Array.isArray(i))throw Error("Invalid column definition: expect a string or an object");if(!i.key)throw Error('Invalid column definition: property "key" is required');void 0===i.header&&(i.header=i.key),e.push(i)}t=e}else{const e=[];for(let i in t)e.push({key:i,header:t[i]});t=e}return t}}}const l=function(){let t,e,i;for(let o in arguments){const r=arguments[o],n=typeof r;if(void 0===t&&Array.isArray(r))t=r;else if(void 0===e&&u(r))e=r;else{if(void 0!==i||"function"!==n)throw new a("CSV_INVALID_ARGUMENT",["Invalid argument:",`got ${JSON.stringify(r)} at index ${o}`]);i=r}}const o=new s(e);if(i){const t=[];o.on("readable",(function(){let e;for(;null!==(e=this.read());)t.push(e)})),o.on("error",(function(t){i(t)})),o.on("end",(function(){i(void 0,t.join(""))}))}if(void 0!==t)if("function"==typeof setImmediate)setImmediate((function(){for(let e of t)o.write(e);o.end()}));else{for(let e of t)o.write(e);o.end()}return o};class a extends Error{constructor(t,e,...i){Array.isArray(e)&&(e=e.join(" ")),super(e),void 0!==Error.captureStackTrace&&Error.captureStackTrace(this,a),this.code=t;for(const t of i)for(const e in t){const i=t[e];this[e]=Buffer.isBuffer(i)?i.toString():null==i?i:JSON.parse(JSON.stringify(i))}}}l.Stringifier=s,l.CsvError=a,t.exports=l;const u=function(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)},c=function(t){return t.replace(/([A-Z])/g,(function(t,e){return"_"+e.toLowerCase()}))},f=".".charCodeAt(0),h=/\\(\\)?/g,d=RegExp("[^.[\\]]+|\\[(?:([^\"'][^[]*)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))","g"),_=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,m=/^\w*$/,p=function(t){const e=typeof t;return"symbol"===e||"object"===e&&t&&"[object Symbol]"===function(t){return Object.prototype.toString.call(t)}(t)},g=function(t,e){return Array.isArray(t)?t:function(t,e){if(Array.isArray(t))return!1;const i=typeof t;return!("number"!==i&&"symbol"!==i&&"boolean"!==i&&t&&!p(t))||(m.test(t)||!_.test(t)||null!=e&&t in Object(e))}(t,e)?[t]:function(t){const e=[];return t.charCodeAt(0)===f&&e.push(""),t.replace(d,(function(t,i,o,r){let n=t;o?n=r.replace(h,"$1"):i&&(n=i.trim()),e.push(n)})),e}(t)},y=function(t){if("string"==typeof t||p(t))return t;const e=""+t;return"0"==e&&1/t==-INFINITY?"-0":e},b=function(t,e){let i=0;const o=(e=g(e,t)).length;for(;null!=t&&i<o;)t=t[y(e[i++])];return i&&i===o?t:void 0}},function(t,e,i){const o=i(16),r=i(1),n=i(3),s=i(0);class l extends s.Transform{constructor({header:t}){super({objectMode:!0}),this.structure=null,this.header=t}_transform(t,e,i){this.structure?(this.push(o(this.structure.columns.map(t=>t.columnName),t)),i()):(this.header?(this.structure={columns:t.map(t=>({columnName:t}))},this.push(this.structure)):(this.structure={columns:t.map((t,e)=>({columnName:"col"+(e+1)}))},this.push(this.structure),this.push(o(this.structure.columns.map(t=>t.columnName),t))),i())}}t.exports=async function({fileName:t,encoding:e="utf-8",header:i=!0,delimiter:o,limitRows:s}){console.log("Reading file "+t);const a=r.parse({delimiter:o,skip_lines_with_error:!0,to_line:s?s+1:void 0}),u=n.createReadStream(t,e),c=new l({header:i});return u.pipe(a),a.pipe(c),c}},function(t,e,i){var o=i(17),r=i(32);t.exports=function(t,e){return r(t||[],e||[],o)}},function(t,e,i){var o=i(18),r=i(31),n=Object.prototype.hasOwnProperty;t.exports=function(t,e,i){var s=t[e];n.call(t,e)&&r(s,i)&&(void 0!==i||e in t)||o(t,e,i)}},function(t,e,i){var o=i(19);t.exports=function(t,e,i){"__proto__"==e&&o?o(t,e,{configurable:!0,enumerable:!0,value:i,writable:!0}):t[e]=i}},function(t,e,i){var o=i(20),r=function(){try{var t=o(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();t.exports=r},function(t,e,i){var o=i(21),r=i(30);t.exports=function(t,e){var i=r(t,e);return o(i)?i:void 0}},function(t,e,i){var o=i(22),r=i(27),n=i(6),s=i(29),l=/^\[object .+?Constructor\]$/,a=Function.prototype,u=Object.prototype,c=a.toString,f=u.hasOwnProperty,h=RegExp("^"+c.call(f).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");t.exports=function(t){return!(!n(t)||r(t))&&(o(t)?h:l).test(s(t))}},function(t,e,i){var o=i(23),r=i(6);t.exports=function(t){if(!r(t))return!1;var e=o(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}},function(t,e,i){var o=i(4),r=i(25),n=i(26),s=o?o.toStringTag:void 0;t.exports=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":s&&s in Object(t)?r(t):n(t)}},function(t,e){var i="object"==typeof global&&global&&global.Object===Object&&global;t.exports=i},function(t,e,i){var o=i(4),r=Object.prototype,n=r.hasOwnProperty,s=r.toString,l=o?o.toStringTag:void 0;t.exports=function(t){var e=n.call(t,l),i=t[l];try{t[l]=void 0;var o=!0}catch(t){}var r=s.call(t);return o&&(e?t[l]=i:delete t[l]),r}},function(t,e){var i=Object.prototype.toString;t.exports=function(t){return i.call(t)}},function(t,e,i){var o,r=i(28),n=(o=/[^.]+$/.exec(r&&r.keys&&r.keys.IE_PROTO||""))?"Symbol(src)_1."+o:"";t.exports=function(t){return!!n&&n in t}},function(t,e,i){var o=i(5)["__core-js_shared__"];t.exports=o},function(t,e){var i=Function.prototype.toString;t.exports=function(t){if(null!=t){try{return i.call(t)}catch(t){}try{return t+""}catch(t){}}return""}},function(t,e){t.exports=function(t,e){return null==t?void 0:t[e]}},function(t,e){t.exports=function(t,e){return t===e||t!=t&&e!=e}},function(t,e){t.exports=function(t,e,i){for(var o=-1,r=t.length,n=e.length,s={};++o<r;){var l=o<n?e[o]:void 0;i(s,t[o],l)}return s}}]); |
@@ -1,1 +0,135 @@ | ||
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)r.d(n,a,function(t){return e[t]}.bind(null,a));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t);t.default={fileFormats:[{storageType:"csv",extension:"csv",name:"CSV",readerFunc:"csvReader",writerFunc:"csvWriter",args:[{type:"select",name:"delimiter",label:"Delimiter",options:[{name:"Comma (,)",value:","},{name:"Semicolon (;)",value:";"},{name:"Tab",value:"\t"},{name:"Pipe (|)",value:"|"}],apiName:"delimiter"},{type:"checkbox",name:"quoted",label:"Quoted",apiName:"quoted",direction:"target"},{type:"checkbox",name:"header",label:"Has header row",apiName:"header",default:!0}]}]}}]); | ||
/******/ (function(modules) { // webpackBootstrap | ||
/******/ // The module cache | ||
/******/ var installedModules = {}; | ||
/******/ | ||
/******/ // The require function | ||
/******/ function __webpack_require__(moduleId) { | ||
/******/ | ||
/******/ // Check if module is in cache | ||
/******/ if(installedModules[moduleId]) { | ||
/******/ return installedModules[moduleId].exports; | ||
/******/ } | ||
/******/ // Create a new module (and put it into the cache) | ||
/******/ var module = installedModules[moduleId] = { | ||
/******/ i: moduleId, | ||
/******/ l: false, | ||
/******/ exports: {} | ||
/******/ }; | ||
/******/ | ||
/******/ // Execute the module function | ||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | ||
/******/ | ||
/******/ // Flag the module as loaded | ||
/******/ module.l = true; | ||
/******/ | ||
/******/ // Return the exports of the module | ||
/******/ return module.exports; | ||
/******/ } | ||
/******/ | ||
/******/ | ||
/******/ // expose the modules object (__webpack_modules__) | ||
/******/ __webpack_require__.m = modules; | ||
/******/ | ||
/******/ // expose the module cache | ||
/******/ __webpack_require__.c = installedModules; | ||
/******/ | ||
/******/ // define getter function for harmony exports | ||
/******/ __webpack_require__.d = function(exports, name, getter) { | ||
/******/ if(!__webpack_require__.o(exports, name)) { | ||
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); | ||
/******/ } | ||
/******/ }; | ||
/******/ | ||
/******/ // define __esModule on exports | ||
/******/ __webpack_require__.r = function(exports) { | ||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
/******/ } | ||
/******/ Object.defineProperty(exports, '__esModule', { value: true }); | ||
/******/ }; | ||
/******/ | ||
/******/ // create a fake namespace object | ||
/******/ // mode & 1: value is a module id, require it | ||
/******/ // mode & 2: merge all properties of value into the ns | ||
/******/ // mode & 4: return value when already ns object | ||
/******/ // mode & 8|1: behave like require | ||
/******/ __webpack_require__.t = function(value, mode) { | ||
/******/ if(mode & 1) value = __webpack_require__(value); | ||
/******/ if(mode & 8) return value; | ||
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; | ||
/******/ var ns = Object.create(null); | ||
/******/ __webpack_require__.r(ns); | ||
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); | ||
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); | ||
/******/ return ns; | ||
/******/ }; | ||
/******/ | ||
/******/ // getDefaultExport function for compatibility with non-harmony modules | ||
/******/ __webpack_require__.n = function(module) { | ||
/******/ var getter = module && module.__esModule ? | ||
/******/ function getDefault() { return module['default']; } : | ||
/******/ function getModuleExports() { return module; }; | ||
/******/ __webpack_require__.d(getter, 'a', getter); | ||
/******/ return getter; | ||
/******/ }; | ||
/******/ | ||
/******/ // Object.prototype.hasOwnProperty.call | ||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; | ||
/******/ | ||
/******/ // __webpack_public_path__ | ||
/******/ __webpack_require__.p = ""; | ||
/******/ | ||
/******/ | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 0); | ||
/******/ }) | ||
/************************************************************************/ | ||
/******/ ([ | ||
/* 0 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
const csvFormat = { | ||
storageType: 'csv', | ||
extension: 'csv', | ||
name: 'CSV', | ||
readerFunc: 'csvReader@dbgate-plugin-csv', | ||
writerFunc: 'csvWriter@dbgate-plugin-csv', | ||
args: [ | ||
{ | ||
type: 'select', | ||
name: 'delimiter', | ||
label: 'Delimiter', | ||
options: [ | ||
{ name: 'Comma (,)', value: ',' }, | ||
{ name: 'Semicolon (;)', value: ';' }, | ||
{ name: 'Tab', value: '\t' }, | ||
{ name: 'Pipe (|)', value: '|' }, | ||
], | ||
apiName: 'delimiter', | ||
}, | ||
{ | ||
type: 'checkbox', | ||
name: 'quoted', | ||
label: 'Quoted', | ||
apiName: 'quoted', | ||
direction: 'target', | ||
}, | ||
{ | ||
type: 'checkbox', | ||
name: 'header', | ||
label: 'Has header row', | ||
apiName: 'header', | ||
default: true, | ||
}, | ||
], | ||
}; | ||
/* harmony default export */ __webpack_exports__["default"] = ({ | ||
fileFormats: [csvFormat], | ||
}); | ||
/***/ }) | ||
/******/ ]); |
{ | ||
"name": "dbgate-plugin-csv", | ||
"main": "lib/backend.js", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"homepage": "https://github.com/dbshell/dbgate-plugin-csv", | ||
"descripton": "CSV import/export plugin for DbGate", | ||
"description": "CSV import/export plugin for DbGate", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
87872
130