Socket
Socket
Sign inDemoInstall

dbgate-plugin-csv

Package Overview
Dependencies
Maintainers
1
Versions
127
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dbgate-plugin-csv - npm Package Compare versions

Comparing version 5.2.7 to 5.2.8

2

dist/backend.js

@@ -1,1 +0,1 @@

module.exports=function(t){var e={};function i(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,i),o.l=!0,o.exports}return i.m=t,i.c=e,i.d=function(t,e,r){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},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 r=Object.create(null);if(i.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)i.d(r,o,function(e){return t[e]}.bind(null,o));return r},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){var r=i(2).Symbol;t.exports=r},function(t,e,i){var r=i(17),o="object"==typeof self&&self&&self.Object===Object&&self,n=r||o||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){t.exports={generate:i(26),parse:i(27),transform:i(29),stringify:i(31)}},function(t,e){t.exports=require("util")},function(t,e){t.exports=require("fs")},function(t,e,i){const r=i(8),o=i(32);t.exports={packageName:"dbgate-plugin-csv",shellApi:{reader:r,writer:o},initialize(t){r.initialize(t)}}},function(t,e,i){const r=i(9),o=i(4),n=i(6),s=i(0);let l;class a extends s.Transform{constructor({header:t}){super({objectMode:!0}),this.structure=null,this.header=t}_transform(t,e,i){this.structure?(this.push(r(this.structure.columns.map(t=>t.columnName),t)),i()):(this.header?(this.structure={__isStreamHeader:!0,columns:t.map(t=>({columnName:t}))},this.push(this.structure)):(this.structure={__isStreamHeader:!0,columns:t.map((t,e)=>({columnName:"col"+(e+1)}))},this.push(this.structure),this.push(r(this.structure.columns.map(t=>t.columnName),t))),i())}}async function u({fileName:t,encoding:e="utf-8",header:i=!0,delimiter:r,limitRows:s}){console.log("Reading file "+t);const u=o.parse({delimiter:r,skip_lines_with_error:!0,to_line:s?s+1:void 0}),c=await l.download(t),f=n.createReadStream(c,e),h=new a({header:i});return f.pipe(u),u.pipe(h),h}u.initialize=t=>{l=t.dbgateApi},t.exports=u},function(t,e,i){var r=i(10),o=i(25);t.exports=function(t,e){return o(t||[],e||[],r)}},function(t,e,i){var r=i(11),o=i(24),n=Object.prototype.hasOwnProperty;t.exports=function(t,e,i){var s=t[e];n.call(t,e)&&o(s,i)&&(void 0!==i||e in t)||r(t,e,i)}},function(t,e,i){var r=i(12);t.exports=function(t,e,i){"__proto__"==e&&r?r(t,e,{configurable:!0,enumerable:!0,value:i,writable:!0}):t[e]=i}},function(t,e,i){var r=i(13),o=function(){try{var t=r(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();t.exports=o},function(t,e,i){var r=i(14),o=i(23);t.exports=function(t,e){var i=o(t,e);return r(i)?i:void 0}},function(t,e,i){var r=i(15),o=i(20),n=i(3),s=i(22),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)||o(t))&&(r(t)?h:l).test(s(t))}},function(t,e,i){var r=i(16),o=i(3);t.exports=function(t){if(!o(t))return!1;var e=r(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}},function(t,e,i){var r=i(1),o=i(18),n=i(19),s=r?r.toStringTag:void 0;t.exports=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":s&&s in Object(t)?o(t):n(t)}},function(t,e){var i="object"==typeof global&&global&&global.Object===Object&&global;t.exports=i},function(t,e,i){var r=i(1),o=Object.prototype,n=o.hasOwnProperty,s=o.toString,l=r?r.toStringTag:void 0;t.exports=function(t){var e=n.call(t,l),i=t[l];try{t[l]=void 0;var r=!0}catch(t){}var o=s.call(t);return r&&(e?t[l]=i:delete t[l]),o}},function(t,e){var i=Object.prototype.toString;t.exports=function(t){return i.call(t)}},function(t,e,i){var r,o=i(21),n=(r=/[^.]+$/.exec(o&&o.keys&&o.keys.IE_PROTO||""))?"Symbol(src)_1."+r:"";t.exports=function(t){return!!n&&n in t}},function(t,e,i){var r=i(2)["__core-js_shared__"];t.exports=r},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 r=-1,o=t.length,n=e.length,s={};++r<o;){var l=r<n?e[r]:void 0;i(s,t[r],l)}return s}},function(t,e,i){const r=i(0),o=i(5);t.exports=function(){let t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):1===arguments.length?"function"==typeof arguments[0]?(t={},e=arguments[0]):t=arguments[0]:0===arguments.length&&(t={});const i=new Generator(t);if(e){const t=[];i.on("readable",(function(){let e;for(;e=i.read();)t.push(e)})),i.on("error",e),i.on("end",(function(){i.options.objectMode?e(null,t):i.options.encoding?e(null,t.join("")):e(null,Buffer.concat(t))}))}return i},Generator=function(t={}){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={};for(let e in t)this.options[Generator.camelize(e)]=t[e];const e={columns:8,delimiter:",",duration:null,encoding:null,end:null,eof:!1,fixedSize:!1,length:-1,maxWordLength:16,rowDelimiter:"\n",seed:!1,sleep:0};for(const t in e)void 0===this.options[t]&&(this.options[t]=e[t]);!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));const i=Object.keys(Generator).filter(t=>!["super_","camelize"].includes(t));for(let t=0;t<this.options.columns.length;t++){const e=this.options.columns[t]||"ascii";if("string"==typeof e){if(!i.includes(e))throw Error(`Invalid column type: got "${e}", default values are ${JSON.stringify(i)}`);this.options.columns[t]=Generator[e]}}return this},o.inherits(Generator,r.Readable),t.exports.Generator=Generator,Generator.prototype.random=function(){return this.options.seed?this.options.seed=this.options.seed*Math.PI*100%100/100:Math.random()},Generator.prototype.end=function(){this.push(null)},Generator.prototype._read=function(t){const e=[];let i=this._.fixed_size_buffer.length;for(0!==i&&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(const t of e)this.__push(t);else this.__push(e.join("")+(this.options.eof?this.options.eof:""));return this.push(null)}let r,o=[];if(this.options.columns.forEach(t=>{o.push(t(this))}),this.options.objectMode){r=0;for(const t of o)r+=t.length}else o=(0===this._.count_created?"":this.options.rowDelimiter)+o.join(this.options.delimiter),r=o.length;if(this._.count_created++,i+r>t){if(this.options.objectMode){e.push(o);for(const t of e)this.__push(t)}else this.options.fixedSize?(this._.fixed_size_buffer=o.substr(t-i),e.push(o.substr(0,t-i))):e.push(o),this.__push(e.join(""));return}i+=r,e.push(o)}},Generator.prototype.__push=function(t){this._.count_written++,this.options.sleep>0?setTimeout(()=>{this.push(t)},this.options.sleep):this.push(t)},Generator.ascii=function(t){const e=[],i=Math.ceil(t.random()*t.options.maxWordLength);for(let r=0;r<i;r++){const i=Math.floor(32*t.random());e.push(String.fromCharCode(i+(i<16?65:81)))}return e.join("")},Generator.int=function(t){return Math.floor(t.random()*Math.pow(2,52))},Generator.bool=function(t){return Math.floor(2*t.random())},Generator.camelize=function(t){return t.replace(/_([a-z])/gi,(function(t,e,i){return e.toUpperCase()}))}},function(t,e,i){const{Transform:r}=i(0),o=i(28),n={utf8:Buffer.from([239,187,191]),utf16le:Buffer.from([255,254])};class s extends r{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)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);e.cast_date=function(t){const e=Date.parse(t);return isNaN(e)?t:new Date(e)}}let r=null;if(!0===e.columns)r=void 0;else if("function"==typeof e.columns)r=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 array, 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(!1===e.columns)throw new a("CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY",["Invalid option columns_duplicates_to_array:","the `columns` mode must be activated."],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.ignore_last_delimiters||null===e.ignore_last_delimiters)e.ignore_last_delimiters=!1;else if("number"==typeof e.ignore_last_delimiters)e.ignore_last_delimiters=Math.floor(e.ignore_last_delimiters),0===e.ignore_last_delimiters&&(e.ignore_last_delimiters=!1);else if("boolean"!=typeof e.ignore_last_delimiters)throw new a("CSV_INVALID_OPTION_IGNORE_LAST_DELIMITERS",["Invalid option `ignore_last_delimiters`:","the value must be a boolean value or an integer,","got "+JSON.stringify(e.ignore_last_delimiters)],e);if(!0===e.ignore_last_delimiters&&!1===e.columns)throw new a("CSV_IGNORE_LAST_DELIMITERS_REQUIRES_COLUMNS",["The option `ignore_last_delimiters`","requires the activation of the `columns` option"],e);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={bytes:0,comment_lines:0,empty_lines:0,invalid_field_length:0,lines:1,records:0},this.options=e,this.state={bomSkipped:!1,bufBytesStart:0,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:Array.isArray(e.columns)?e.columns.length:void 0,field:new o(20),firstLineToHeaders:r,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 o(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 r=this.__parse(t,!1);void 0!==r&&(this.state.stop=!0),i(r)}_flush(t){if(!0===this.state.stop)return;t(this.__parse(void 0,!0))}__parse(t,e){const{bom:i,comment:r,escape:o,from_line:s,ltrim:l,max_record_size:u,quote:c,raw:f,relax:h,rtrim:d,skip_empty_lines:_,to:m,to_line:p}=this.options;let{record_delimiter:g}=this.options;const{bomSkipped:y,previousBuf:b,rawBuffer:v,escapeIsQuote:w}=this.state;let O;if(void 0===b){if(void 0===t)return void this.push(null);O=t}else O=void 0!==b&&void 0===t?b:Buffer.concat([b,t]);if(!1===y)if(!1===i)this.state.bomSkipped=!0;else if(O.length<3){if(!1===e)return void(this.state.previousBuf=O)}else{for(let t in n)if(0===n[t].compare(O,0,n[t].length)){let e=n[t].length;this.state.bufBytesStart+=e,O=O.slice(e),this.__normalizeOptions({...this.__originalOptions,encoding:t});break}this.state.bomSkipped=!0}const S=O.length;let I;for(I=0;I<S&&!this.__needMoreData(I,S,e);I++){if(!0===this.state.wasRowDelimiter&&(this.info.lines++,this.state.wasRowDelimiter=!1),-1!==p&&this.info.lines>p)return this.state.stop=!0,void this.push(null);if(!1===this.state.quoting&&0===g.length){this.__autoDiscoverRecordDelimiter(O,I)&&(g=this.options.record_delimiter)}const t=O[I];if(!0===f&&v.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!==o&&!0===this.state.quoting&&this.__isEscape(O,I,t)&&I+o.length<S){if(!w){this.state.escaping=!0,I+=o.length-1;continue}if(this.__isQuote(O,I+o.length)){this.state.escaping=!0,I+=o.length-1;continue}}if(!1===this.state.commenting&&this.__isQuote(O,I))if(!0===this.state.quoting){const e=O[I+c.length],i=d&&this.__isCharTrimable(e),n=null!==r&&this.__compareBytes(r,O,I+c.length,e),s=this.__isDelimiter(O,I+c.length,e),l=0===g.length?this.__autoDiscoverRecordDelimiter(O,I+c.length):this.__isRecordDelimiter(e,O,I+c.length);if(null!==o&&this.__isEscape(O,I,t)&&this.__isQuote(O,I+o.length))I+=o.length-1;else{if(!e||s||l||n||i){this.state.quoting=!1,this.state.wasQuoting=!0,I+=c.length-1;continue}if(!1===h){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, record delimiter, trimable character","(if activated) or comment"],this.options,this.__infoField()));if(void 0!==t)return t}else this.state.quoting=!1,this.state.wasQuoting=!0,this.state.field.prepend(c),I+=c.length-1}}else{if(0===this.state.field.length){this.state.quoting=!0,I+=c.length-1;continue}if(!1===h){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.__infoField(),{field:this.state.field}));if(void 0!==t)return t}}if(!1===this.state.quoting){let e=this.__isRecordDelimiter(t,O,I);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(!1===this.state.enabled&&this.info.lines+(!0===this.state.wasRowDelimiter?1:0)>=s){this.state.enabled=!0,this.__resetField(),this.__resetRecord(),I+=e-1;continue}if(!0===_&&!1===this.state.wasQuoting&&0===this.state.record.length&&0===this.state.field.length){this.info.empty_lines++,I+=e-1;continue}this.info.bytes=this.state.bufBytesStart+I;const t=this.__onField();if(void 0!==t)return t;this.info.bytes=this.state.bufBytesStart+I+e;const i=this.__onRecord();if(void 0!==i)return i;if(-1!==m&&this.info.records>=m)return this.state.stop=!0,void this.push(null)}this.state.commenting=!1,I+=e-1;continue}if(this.state.commenting)continue;if(0!==(null===r?0:this.__compareBytes(r,O,I,t))){this.state.commenting=!0;continue}let i=this.__isDelimiter(O,I,t);if(0!==i){this.info.bytes=this.state.bufBytesStart+I;const t=this.__onField();if(void 0!==t)return t;I+=i-1;continue}}}if(!1===this.state.commenting&&0!==u&&this.state.record_length+this.state.field.length>u){const t=this.__error(new a("CSV_MAX_RECORD_SIZE",["Max Record Size:","record exceed the maximum number of tolerated bytes","of "+u,"at line "+this.info.lines],this.options,this.__infoField()));if(void 0!==t)return t}const e=!1===l||!0===this.state.quoting||0!==this.state.field.length||!this.__isCharTrimable(t),i=!1===d||!1===this.state.wasQuoting;if(!0===e&&!0===i)this.state.field.append(t);else if(!0===d&&!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.__infoField()));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.__infoField()));if(void 0!==t)return t}else if(!0===this.state.wasQuoting||0!==this.state.record.length||0!==this.state.field.length){this.info.bytes=this.state.bufBytesStart+I;const t=this.__onField();if(void 0!==t)return t;const e=this.__onRecord();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.bufBytesStart+=I,this.state.previousBuf=O.slice(I);!0===this.state.wasRowDelimiter&&(this.info.lines++,this.state.wasRowDelimiter=!1)}__onRecord(){const{columns:t,columns_duplicates_to_array:e,encoding:i,info:r,from:o,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.__resetRecord();const _=d.length;if(!0===t)return!0===c&&f(d)?void this.__resetRecord():this.__firstLineToColumns(d);if(!1===t&&0===this.info.records&&(this.state.expectedRecordLength=_),_!==this.state.expectedRecordLength){const e=!1===t?new a("CSV_INCONSISTENT_RECORD_LENGTH",["Invalid Record Length:",`expect ${this.state.expectedRecordLength},`,`got ${_} on line ${this.info.lines}`],this.options,this.__infoField(),{record:d}):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.__infoField(),{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{const t=this.__error(e);if(t)return t}}if(!0===c&&f(d))this.__resetRecord();else{if(!0===this.state.recordHasError)return this.__resetRecord(),void(this.state.recordHasError=!1);if(this.info.records++,1===o||this.info.records>=o)if(!1!==t){const o={};for(let i=0,r=d.length;i<r;i++)void 0===t[i]||t[i].disabled||(!0===e&&void 0!==o[t[i].name]?Array.isArray(o[t[i].name])?o[t[i].name]=o[t[i].name].concat(d[i]):o[t[i].name]=[o[t[i].name],d[i]]:o[t[i].name]=d[i]);const{objname:n}=this.options;if(void 0===n)if(!0===u||!0===r){const t=this.__push(Object.assign({record:o},!0===u?{raw:this.state.rawBuffer.toString(i)}:{},!0===r?{info:this.__infoRecord()}:{}));if(t)return t}else{const t=this.__push(o);if(t)return t}else if(!0===u||!0===r){const t=this.__push(Object.assign({record:[o[n],o]},!0===u?{raw:this.state.rawBuffer.toString(i)}:{},!0===r?{info:this.__infoRecord()}:{}));if(t)return t}else{const t=this.__push([o[n],o]);if(t)return t}}else if(!0===u||!0===r){const t=this.__push(Object.assign({record:d},!0===u?{raw:this.state.rawBuffer.toString(i)}:{},!0===r?{info:this.__infoRecord()}:{}));if(t)return t}else{const t=this.__push(d);if(t)return t}this.__resetRecord()}}__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.__infoField(),{headers:i}));const r=h(i);return this.state.expectedRecordLength=r.length,this.options.columns=r,void this.__resetRecord()}catch(t){return t}}__resetRecord(){!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:r}=this.options,{enabled:o,wasQuoting:n}=this.state;if(!1===o)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!==r&&"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.__infoRecord();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];if(null!==this.state.castField)try{const e=this.__infoField();return[void 0,this.state.castField.call(null,t,e)]}catch(t){return[t]}if(this.__isFloat(t))return[void 0,parseFloat(t)];if(!1!==this.options.cast_date){const e=this.__infoField();return[void 0,this.options.cast_date.call(null,t,e)]}return[void 0,t]}__isCharTrimable(t){return 32===t||9===t||13===t||10===t||12===t}__isFloat(t){return t-parseFloat(t)+1>=0}__compareBytes(t,e,i,r){if(t[0]!==r)return 0;const o=t.length;for(let r=1;r<o;r++)if(t[r]!==e[i+r])return 0;return o}__needMoreData(t,e,i){if(i)return!1;const{quote:r}=this.options,{quoting:o,needMoreDataSize:n,recordDelimiterMaxLength:s}=this.state;return e-t-1<Math.max(n,s,o?r.length+s:0)}__isDelimiter(t,e,i){const{delimiter:r,ignore_last_delimiters:o}=this.options;if(!0===o&&this.state.record.length===this.options.columns.length-1)return 0;if(!1!==o&&"number"==typeof o&&this.state.record.length===o-1)return 0;t:for(let o=0;o<r.length;o++){const n=r[o];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:r}=this.options,o=r.length;t:for(let n=0;n<o;n++){const o=r[n],s=o.length;if(o[0]===t){for(let t=1;t<s;t++)if(o[t]!==e[i+t])continue t;return o.length}}return 0}__isEscape(t,e,i){const{escape:r}=this.options;if(null===r)return!1;const o=r.length;if(r[0]===i){for(let i=0;i<o;i++)if(r[i]!==t[e+i])return!1;return!0}return!1}__isQuote(t,e){const{quote:i}=this.options;if(null===i)return!1;const r=i.length;for(let o=0;o<r;o++)if(i[o]!==t[e+o])return!1;return!0}__autoDiscoverRecordDelimiter(t,e){const{encoding:i}=this.options,r=t[e];return 13===r?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===r?(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}__infoDataSet(){return{...this.info,columns:this.options.columns}}__infoRecord(){const{columns:t}=this.options;return{...this.__infoDataSet(),error:this.state.error,header:!0===t,index:this.state.record.length}}__infoField(){const{columns:t}=this.options,e=Array.isArray(t);return{...this.__infoRecord(),column:!0===e?t.length>this.state.record.length?t[this.state.record.length].name:null:this.state.record.length,quoting:this.state.wasQuoting}}}const l=function(){let t,e,i;for(let r in arguments){const o=arguments[r],n=typeof o;if(void 0!==t||"string"!=typeof o&&!Buffer.isBuffer(o))if(void 0===e&&c(o))e=o;else{if(void 0!==i||"function"!==n)throw new a("CSV_INVALID_ARGUMENT",["Invalid argument:",`got ${JSON.stringify(o)} at index ${r}`],e||{});i=o}else t=o}const r=new s(e);if(i){const t=void 0===e||void 0===e.objname?[]:{};r.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]})),r.on("error",(function(t){i(t,void 0,r.__infoDataSet())})),r.on("end",(function(){i(void 0,t,r.__infoDataSet())}))}return void 0!==t&&("function"==typeof setImmediate?setImmediate((function(){r.write(t),r.end()})):(r.write(t),r.end())),r};class a extends Error{constructor(t,e,i,...r){Array.isArray(e)&&(e=e.join(" ")),super(e),void 0!==Error.captureStackTrace&&Error.captureStackTrace(this,a),this.code=t;for(const t of r)for(const e in t){const r=t[e];this[e]=Buffer.isBuffer(r)?r.toString(i.encoding):null==r?r:JSON.parse(JSON.stringify(r))}}}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,r=t.length;i<r;i++){const r=t[i];if(null==r||!1===r)e[i]={disabled:!0};else if("string"==typeof r)e[i]={name:r};else{if(!c(r))throw new a("CSV_INVALID_COLUMN_DEFINITION",["Invalid column definition:","expect a string or a literal object,",`got ${JSON.stringify(r)} at position ${i}`]);if("string"!=typeof r.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]=r}}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 r,o,n,s;n=i(0),s=i(5),({clone:o}=i(30)),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=o(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 r(u,n),i=!1,c&&setImmediate((function(){var t,e,r;for(t=0,e=c.length;t<e&&(r=c[t],!i);t++)h.write(r);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},r=function(t={},e){var i,r;return this.options=t,this.handler=e,null==(i=this.options).consume&&(i.consume=!1),this.options.objectMode=!0,null==(r=this.options).parallel&&(r.parallel=100),n.Transform.call(this,this.options),this.state={running:0,started:0,finished:0},this},s.inherits(r,n.Transform),t.exports.Transformer=r,r.prototype._transform=function(t,e,i){var r,o,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");r=(t,...e)=>this.__done(t,e,i),this.handler.call(this,t,r,this.options.params)}return!1}catch(t){return o=t,this.__done(o)}},r.prototype._flush=function(t){return this._ending=function(){if(0===this.state.running)return this._ending=void 0,t()},this._ending()},r.prototype.__done=function(t,e,i){var r,o,n;if(this.state.running--,t)return this.emit("error",t);for(this.state.finished++,o=0,n=e.length;o<n;o++)"number"==typeof(r=e[o])&&(r=""+r),null!=r&&""!==r&&this.push(r);return i&&i(),this._ending?this._ending():void 0}},function(t,e,i){"use strict";function r(t){return(r="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 o,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"===r(t)?c({},t):t},c=function(){var t,e,i,r,o,n,s;for(n=arguments[0],t=e=1,r=arguments.length;1<=r?e<r:e>r;t=1<=r?++e:--e)if(a(o=arguments[t]))for(i in a(n)||(n={}),o)/__proto__|prototype/.test(i)||(n[i]=c(n[i],o[i]));else Array.isArray(o)?n=function(){var t,e,i;for(i=[],t=0,e=o.length;t<e;t++)s=o[t],i.push(c(void 0,s));return i}():void 0!==o&&(n=o);return n},f=function(t){var e,i,r,n,s=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(r={},a(t))for(e in n="number"==typeof s&&s>0?s-1:s,t)i=t[e],s&&(e=o(e)),r[e]=f(i,n);else r=t;return r},s=function(t,e){var i,r,o,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=r=0,c=l.length;r<c;i=++r){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=o=0,f=t.length;0<=f?o<f:o>f;i=0<=f?++o:--o)if(!s(t[i],e[i]))return!1}else if(t!==e)return!1;return!0},o=function(t){return t.replace(/([A-Z])/g,(function(t,e,i){return"_"+e.toLowerCase()}))},l=function(t){return t&&"object"===r(t)&&!Array.isArray(t)},a=function(t){var e;if(e=t,"object"!==r(t)||null===t)return!1;if(null===Object.getPrototypeOf(e))return!0;for(;null!==Object.getPrototypeOf(e=Object.getPrototypeOf(e)););return Object.getPrototypeOf(t)===e}},function(t,e,r){const{Transform:o}=r(0),n=Buffer.from([239,187,191]);class s extends o{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)return;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)}let r;if(this.options.eof){if(r=this.stringify(t),void 0===r)return;r+=this.options.record_delimiter}else{if(r=this.stringify(t),void 0===r)return;(this.options.header||this.info.records)&&(r=this.options.record_delimiter+r)}this.info.records++,this.push(r),i()}_flush(t){0===this.info.records&&(this.bom(),this.headers()),t()}stringify(t,e=!1){if("object"!=typeof t)return t;const{columns:r,header:o}=this.options,n=[];if(Array.isArray(t)){r&&t.splice(r.length);for(let i=0;i<t.length;i++){const r=t[i],[o,s]=this.__cast(r,{index:i,column:i,records:this.info.records,header:e});if(o)return void this.emit("error",o);n[i]=[s,r]}}else if(r)for(let i=0;i<r.length;i++){const o=b(t,r[i].key),[s,l]=this.__cast(o,{index:i,column:r[i].key,records:this.info.records,header:e});if(s)return void this.emit("error",s);n[i]=[l,o]}else for(let o of t){const s=t[o],[l,a]=this.__cast(s,{index:i,column:r[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,[r,o]=n[t];if("string"==typeof r)e=this.options;else if(u(r)){if(e=r,r=e.value,delete e.value,"string"!=typeof r&&null!=r)return void this.emit("error",Error("Invalid Casting Value: returned value must return a string, null or undefined, got "+JSON.stringify(r)));if(e={...this.options,...e},i=this.normalize(e))return void this.emit("error",i)}else{if(null!=r)return void this.emit("error",Error("Invalid Casting Value: returned value must return a string, an object, null or undefined, got "+JSON.stringify(r)));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(r){if("string"!=typeof r)return this.emit("error",Error("Formatter must return a string, null or undefined, got "+JSON.stringify(r))),null;const t=l.length&&r.indexOf(l)>=0,e=""!==c&&r.indexOf(c)>=0,i=r.indexOf(a)>=0&&a!==c,n=r.indexOf(m)>=0,u=d&&"string"==typeof o;let h=_&&_.filter(t=>"string"==typeof t?-1!==r.indexOf(t):t.test(r));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");r=r.replace(t,a+a)}if(!0===e){const t=new RegExp(c,"g");r=r.replace(t,a+c)}!0===p&&(r=c+r+c),s+=r}else(!0===h||""===o&&!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 r in arguments){const o=arguments[r],n=typeof o;if(void 0===t&&Array.isArray(o))t=o;else if(void 0===e&&u(o))e=o;else{if(void 0!==i||"function"!==n)throw new a("CSV_INVALID_ARGUMENT",["Invalid argument:",`got ${JSON.stringify(o)} at index ${r}`]);i=o}}const r=new s(e);if(i){const t=[];r.on("readable",(function(){let e;for(;null!==(e=this.read());)t.push(e)})),r.on("error",(function(t){i(t)})),r.on("end",(function(){i(void 0,t.join(""))}))}if(void 0!==t)if("function"==typeof setImmediate)setImmediate((function(){for(let e of t)r.write(e);r.end()}));else{for(let e of t)r.write(e);r.end()}return r};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,r,o){let n=t;r?n=o.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 r=(e=g(e,t)).length;for(;null!=t&&i<r;)t=t[y(e[i++])];return i&&i===r?t:void 0}},function(t,e,i){const r=i(4),o=i(6),n=i(0),{getLogger:s}=global.DBGATE_TOOLS,l=s("csvWriter");class a 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:s}){l.info("Writing file "+t);const u=new a({header:i}),c=r.stringify({delimiter:n,quoted:s}),f=o.createWriteStream(t,e);return u.pipe(c),c.pipe(f),u.finisher=f,u.requireFixedStructure=!0,u}}]);
(()=>{var t={608:(t,e,i)=>{const r=i(203),o=i(23);t.exports=function(){let t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):1===arguments.length?"function"==typeof arguments[0]?(t={},e=arguments[0]):t=arguments[0]:0===arguments.length&&(t={});const i=new Generator(t);if(e){const t=[];i.on("readable",(function(){let e;for(;e=i.read();)t.push(e)})),i.on("error",e),i.on("end",(function(){i.options.objectMode?e(null,t):i.options.encoding?e(null,t.join("")):e(null,Buffer.concat(t))}))}return i},Generator=function(t={}){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={};for(let e in t)this.options[Generator.camelize(e)]=t[e];const e={columns:8,delimiter:",",duration:null,encoding:null,end:null,eof:!1,fixedSize:!1,length:-1,maxWordLength:16,rowDelimiter:"\n",seed:!1,sleep:0};for(const t in e)void 0===this.options[t]&&(this.options[t]=e[t]);!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));const i=Object.keys(Generator).filter((t=>!["super_","camelize"].includes(t)));for(let t=0;t<this.options.columns.length;t++){const e=this.options.columns[t]||"ascii";if("string"==typeof e){if(!i.includes(e))throw Error(`Invalid column type: got "${e}", default values are ${JSON.stringify(i)}`);this.options.columns[t]=Generator[e]}}return this},o.inherits(Generator,r.Readable),t.exports.Generator=Generator,Generator.prototype.random=function(){return this.options.seed?this.options.seed=this.options.seed*Math.PI*100%100/100:Math.random()},Generator.prototype.end=function(){this.push(null)},Generator.prototype._read=function(t){const e=[];let i=this._.fixed_size_buffer.length;for(0!==i&&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(const t of e)this.__push(t);else this.__push(e.join("")+(this.options.eof?this.options.eof:""));return this.push(null)}let r,o=[];if(this.options.columns.forEach((t=>{o.push(t(this))})),this.options.objectMode){r=0;for(const t of o)r+=t.length}else o=(0===this._.count_created?"":this.options.rowDelimiter)+o.join(this.options.delimiter),r=o.length;if(this._.count_created++,i+r>t){if(this.options.objectMode){e.push(o);for(const t of e)this.__push(t)}else this.options.fixedSize?(this._.fixed_size_buffer=o.substr(t-i),e.push(o.substr(0,t-i))):e.push(o),this.__push(e.join(""));return}i+=r,e.push(o)}},Generator.prototype.__push=function(t){this._.count_written++,this.options.sleep>0?setTimeout((()=>{this.push(t)}),this.options.sleep):this.push(t)},Generator.ascii=function(t){const e=[],i=Math.ceil(t.random()*t.options.maxWordLength);for(let r=0;r<i;r++){const i=Math.floor(32*t.random());e.push(String.fromCharCode(i+(i<16?65:81)))}return e.join("")},Generator.int=function(t){return Math.floor(t.random()*Math.pow(2,52))},Generator.bool=function(t){return Math.floor(2*t.random())},Generator.camelize=function(t){return t.replace(/_([a-z])/gi,(function(t,e,i){return e.toUpperCase()}))}},610:t=>{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}}},438:(t,e,i)=>{const{Transform:r}=i(203),o=i(610),n={utf8:Buffer.from([239,187,191]),utf16le:Buffer.from([255,254])};class s extends r{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)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);e.cast_date=function(t){const e=Date.parse(t);return isNaN(e)?t:new Date(e)}}let r=null;if(!0===e.columns)r=void 0;else if("function"==typeof e.columns)r=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 array, 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(!1===e.columns)throw new a("CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY",["Invalid option columns_duplicates_to_array:","the `columns` mode must be activated."],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.ignore_last_delimiters||null===e.ignore_last_delimiters)e.ignore_last_delimiters=!1;else if("number"==typeof e.ignore_last_delimiters)e.ignore_last_delimiters=Math.floor(e.ignore_last_delimiters),0===e.ignore_last_delimiters&&(e.ignore_last_delimiters=!1);else if("boolean"!=typeof e.ignore_last_delimiters)throw new a("CSV_INVALID_OPTION_IGNORE_LAST_DELIMITERS",["Invalid option `ignore_last_delimiters`:","the value must be a boolean value or an integer,",`got ${JSON.stringify(e.ignore_last_delimiters)}`],e);if(!0===e.ignore_last_delimiters&&!1===e.columns)throw new a("CSV_IGNORE_LAST_DELIMITERS_REQUIRES_COLUMNS",["The option `ignore_last_delimiters`","requires the activation of the `columns` option"],e);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={bytes:0,comment_lines:0,empty_lines:0,invalid_field_length:0,lines:1,records:0},this.options=e,this.state={bomSkipped:!1,bufBytesStart:0,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:Array.isArray(e.columns)?e.columns.length:void 0,field:new o(20),firstLineToHeaders:r,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 o(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 r=this.__parse(t,!1);void 0!==r&&(this.state.stop=!0),i(r)}_flush(t){!0!==this.state.stop&&t(this.__parse(void 0,!0))}__parse(t,e){const{bom:i,comment:r,escape:o,from_line:s,ltrim:l,max_record_size:u,quote:c,raw:f,relax:h,rtrim:d,skip_empty_lines:_,to:m,to_line:p}=this.options;let{record_delimiter:g}=this.options;const{bomSkipped:y,previousBuf:b,rawBuffer:v,escapeIsQuote:w}=this.state;let O;if(void 0===b){if(void 0===t)return void this.push(null);O=t}else O=void 0!==b&&void 0===t?b:Buffer.concat([b,t]);if(!1===y)if(!1===i)this.state.bomSkipped=!0;else if(O.length<3){if(!1===e)return void(this.state.previousBuf=O)}else{for(let t in n)if(0===n[t].compare(O,0,n[t].length)){let e=n[t].length;this.state.bufBytesStart+=e,O=O.slice(e),this.__normalizeOptions({...this.__originalOptions,encoding:t});break}this.state.bomSkipped=!0}const I=O.length;let S;for(S=0;S<I&&!this.__needMoreData(S,I,e);S++){if(!0===this.state.wasRowDelimiter&&(this.info.lines++,this.state.wasRowDelimiter=!1),-1!==p&&this.info.lines>p)return this.state.stop=!0,void this.push(null);!1===this.state.quoting&&0===g.length&&this.__autoDiscoverRecordDelimiter(O,S)&&(g=this.options.record_delimiter);const t=O[S];if(!0===f&&v.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!==o&&!0===this.state.quoting&&this.__isEscape(O,S,t)&&S+o.length<I){if(!w){this.state.escaping=!0,S+=o.length-1;continue}if(this.__isQuote(O,S+o.length)){this.state.escaping=!0,S+=o.length-1;continue}}if(!1===this.state.commenting&&this.__isQuote(O,S))if(!0===this.state.quoting){const e=O[S+c.length],i=d&&this.__isCharTrimable(e),n=null!==r&&this.__compareBytes(r,O,S+c.length,e),s=this.__isDelimiter(O,S+c.length,e),l=0===g.length?this.__autoDiscoverRecordDelimiter(O,S+c.length):this.__isRecordDelimiter(e,O,S+c.length);if(null!==o&&this.__isEscape(O,S,t)&&this.__isQuote(O,S+o.length))S+=o.length-1;else{if(!e||s||l||n||i){this.state.quoting=!1,this.state.wasQuoting=!0,S+=c.length-1;continue}if(!1===h){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, record delimiter, trimable character","(if activated) or comment"],this.options,this.__infoField()));if(void 0!==t)return t}else this.state.quoting=!1,this.state.wasQuoting=!0,this.state.field.prepend(c),S+=c.length-1}}else{if(0===this.state.field.length){this.state.quoting=!0,S+=c.length-1;continue}if(!1===h){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.__infoField(),{field:this.state.field}));if(void 0!==t)return t}}if(!1===this.state.quoting){let e=this.__isRecordDelimiter(t,O,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(!1===this.state.enabled&&this.info.lines+(!0===this.state.wasRowDelimiter?1:0)>=s){this.state.enabled=!0,this.__resetField(),this.__resetRecord(),S+=e-1;continue}if(!0===_&&!1===this.state.wasQuoting&&0===this.state.record.length&&0===this.state.field.length){this.info.empty_lines++,S+=e-1;continue}this.info.bytes=this.state.bufBytesStart+S;const t=this.__onField();if(void 0!==t)return t;this.info.bytes=this.state.bufBytesStart+S+e;const i=this.__onRecord();if(void 0!==i)return i;if(-1!==m&&this.info.records>=m)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===r?0:this.__compareBytes(r,O,S,t))){this.state.commenting=!0;continue}let i=this.__isDelimiter(O,S,t);if(0!==i){this.info.bytes=this.state.bufBytesStart+S;const t=this.__onField();if(void 0!==t)return t;S+=i-1;continue}}}if(!1===this.state.commenting&&0!==u&&this.state.record_length+this.state.field.length>u){const t=this.__error(new a("CSV_MAX_RECORD_SIZE",["Max Record Size:","record exceed the maximum number of tolerated bytes",`of ${u}`,`at line ${this.info.lines}`],this.options,this.__infoField()));if(void 0!==t)return t}const e=!1===l||!0===this.state.quoting||0!==this.state.field.length||!this.__isCharTrimable(t),i=!1===d||!1===this.state.wasQuoting;if(!0===e&&!0===i)this.state.field.append(t);else if(!0===d&&!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.__infoField()));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.__infoField()));if(void 0!==t)return t}else if(!0===this.state.wasQuoting||0!==this.state.record.length||0!==this.state.field.length){this.info.bytes=this.state.bufBytesStart+S;const t=this.__onField();if(void 0!==t)return t;const e=this.__onRecord();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.bufBytesStart+=S,this.state.previousBuf=O.slice(S);!0===this.state.wasRowDelimiter&&(this.info.lines++,this.state.wasRowDelimiter=!1)}__onRecord(){const{columns:t,columns_duplicates_to_array:e,encoding:i,info:r,from:o,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.__resetRecord();const _=d.length;if(!0===t)return!0===c&&f(d)?void this.__resetRecord():this.__firstLineToColumns(d);if(!1===t&&0===this.info.records&&(this.state.expectedRecordLength=_),_!==this.state.expectedRecordLength){const e=!1===t?new a("CSV_INCONSISTENT_RECORD_LENGTH",["Invalid Record Length:",`expect ${this.state.expectedRecordLength},`,`got ${_} on line ${this.info.lines}`],this.options,this.__infoField(),{record:d}):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.__infoField(),{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{const t=this.__error(e);if(t)return t}}if(!0===c&&f(d))this.__resetRecord();else{if(!0===this.state.recordHasError)return this.__resetRecord(),void(this.state.recordHasError=!1);if(this.info.records++,1===o||this.info.records>=o)if(!1!==t){const o={};for(let i=0,r=d.length;i<r;i++)void 0===t[i]||t[i].disabled||(!0===e&&void 0!==o[t[i].name]?Array.isArray(o[t[i].name])?o[t[i].name]=o[t[i].name].concat(d[i]):o[t[i].name]=[o[t[i].name],d[i]]:o[t[i].name]=d[i]);const{objname:n}=this.options;if(void 0===n)if(!0===u||!0===r){const t=this.__push(Object.assign({record:o},!0===u?{raw:this.state.rawBuffer.toString(i)}:{},!0===r?{info:this.__infoRecord()}:{}));if(t)return t}else{const t=this.__push(o);if(t)return t}else if(!0===u||!0===r){const t=this.__push(Object.assign({record:[o[n],o]},!0===u?{raw:this.state.rawBuffer.toString(i)}:{},!0===r?{info:this.__infoRecord()}:{}));if(t)return t}else{const t=this.__push([o[n],o]);if(t)return t}}else if(!0===u||!0===r){const t=this.__push(Object.assign({record:d},!0===u?{raw:this.state.rawBuffer.toString(i)}:{},!0===r?{info:this.__infoRecord()}:{}));if(t)return t}else{const t=this.__push(d);if(t)return t}this.__resetRecord()}}__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.__infoField(),{headers:i}));const r=h(i);return this.state.expectedRecordLength=r.length,this.options.columns=r,void this.__resetRecord()}catch(t){return t}}__resetRecord(){!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:r}=this.options,{enabled:o,wasQuoting:n}=this.state;if(!1===o)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!==r&&"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.__infoRecord();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];if(null!==this.state.castField)try{const e=this.__infoField();return[void 0,this.state.castField.call(null,t,e)]}catch(t){return[t]}if(this.__isFloat(t))return[void 0,parseFloat(t)];if(!1!==this.options.cast_date){const e=this.__infoField();return[void 0,this.options.cast_date.call(null,t,e)]}return[void 0,t]}__isCharTrimable(t){return 32===t||9===t||13===t||10===t||12===t}__isFloat(t){return t-parseFloat(t)+1>=0}__compareBytes(t,e,i,r){if(t[0]!==r)return 0;const o=t.length;for(let r=1;r<o;r++)if(t[r]!==e[i+r])return 0;return o}__needMoreData(t,e,i){if(i)return!1;const{quote:r}=this.options,{quoting:o,needMoreDataSize:n,recordDelimiterMaxLength:s}=this.state;return e-t-1<Math.max(n,s,o?r.length+s:0)}__isDelimiter(t,e,i){const{delimiter:r,ignore_last_delimiters:o}=this.options;if(!0===o&&this.state.record.length===this.options.columns.length-1)return 0;if(!1!==o&&"number"==typeof o&&this.state.record.length===o-1)return 0;t:for(let o=0;o<r.length;o++){const n=r[o];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:r}=this.options,o=r.length;t:for(let n=0;n<o;n++){const o=r[n],s=o.length;if(o[0]===t){for(let t=1;t<s;t++)if(o[t]!==e[i+t])continue t;return o.length}}return 0}__isEscape(t,e,i){const{escape:r}=this.options;if(null===r)return!1;const o=r.length;if(r[0]===i){for(let i=0;i<o;i++)if(r[i]!==t[e+i])return!1;return!0}return!1}__isQuote(t,e){const{quote:i}=this.options;if(null===i)return!1;const r=i.length;for(let o=0;o<r;o++)if(i[o]!==t[e+o])return!1;return!0}__autoDiscoverRecordDelimiter(t,e){const{encoding:i}=this.options,r=t[e];return 13===r?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===r?(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}__infoDataSet(){return{...this.info,columns:this.options.columns}}__infoRecord(){const{columns:t}=this.options;return{...this.__infoDataSet(),error:this.state.error,header:!0===t,index:this.state.record.length}}__infoField(){const{columns:t}=this.options,e=Array.isArray(t);return{...this.__infoRecord(),column:!0===e?t.length>this.state.record.length?t[this.state.record.length].name:null:this.state.record.length,quoting:this.state.wasQuoting}}}const l=function(){let t,e,i;for(let r in arguments){const o=arguments[r],n=typeof o;if(void 0!==t||"string"!=typeof o&&!Buffer.isBuffer(o))if(void 0===e&&c(o))e=o;else{if(void 0!==i||"function"!==n)throw new a("CSV_INVALID_ARGUMENT",["Invalid argument:",`got ${JSON.stringify(o)} at index ${r}`],e||{});i=o}else t=o}const r=new s(e);if(i){const t=void 0===e||void 0===e.objname?[]:{};r.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]})),r.on("error",(function(t){i(t,void 0,r.__infoDataSet())})),r.on("end",(function(){i(void 0,t,r.__infoDataSet())}))}return void 0!==t&&("function"==typeof setImmediate?setImmediate((function(){r.write(t),r.end()})):(r.write(t),r.end())),r};class a extends Error{constructor(t,e,i,...r){Array.isArray(e)&&(e=e.join(" ")),super(e),void 0!==Error.captureStackTrace&&Error.captureStackTrace(this,a),this.code=t;for(const t of r)for(const e in t){const r=t[e];this[e]=Buffer.isBuffer(r)?r.toString(i.encoding):null==r?r:JSON.parse(JSON.stringify(r))}}}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,r=t.length;i<r;i++){const r=t[i];if(null==r||!1===r)e[i]={disabled:!0};else if("string"==typeof r)e[i]={name:r};else{if(!c(r))throw new a("CSV_INVALID_COLUMN_DEFINITION",["Invalid column definition:","expect a string or a literal object,",`got ${JSON.stringify(r)} at position ${i}`]);if("string"!=typeof r.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]=r}}return e}},164:(t,e,r)=>{const{Transform:o}=r(203),n=Buffer.from([239,187,191]);class s extends o{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)return;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)}let r;if(this.options.eof){if(r=this.stringify(t),void 0===r)return;r+=this.options.record_delimiter}else{if(r=this.stringify(t),void 0===r)return;(this.options.header||this.info.records)&&(r=this.options.record_delimiter+r)}this.info.records++,this.push(r),i()}_flush(t){0===this.info.records&&(this.bom(),this.headers()),t()}stringify(t,e=!1){if("object"!=typeof t)return t;const{columns:r,header:o}=this.options,n=[];if(Array.isArray(t)){r&&t.splice(r.length);for(let i=0;i<t.length;i++){const r=t[i],[o,s]=this.__cast(r,{index:i,column:i,records:this.info.records,header:e});if(o)return void this.emit("error",o);n[i]=[s,r]}}else if(r)for(let i=0;i<r.length;i++){const o=y(t,r[i].key),[s,l]=this.__cast(o,{index:i,column:r[i].key,records:this.info.records,header:e});if(s)return void this.emit("error",s);n[i]=[l,o]}else for(let o of t){const s=t[o],[l,a]=this.__cast(s,{index:i,column:r[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,[r,o]=n[t];if("string"==typeof r)e=this.options;else if(u(r)){if(e=r,r=e.value,delete e.value,"string"!=typeof r&&null!=r)return void this.emit("error",Error(`Invalid Casting Value: returned value must return a string, null or undefined, got ${JSON.stringify(r)}`));if(e={...this.options,...e},i=this.normalize(e))return void this.emit("error",i)}else{if(null!=r)return void this.emit("error",Error(`Invalid Casting Value: returned value must return a string, an object, null or undefined, got ${JSON.stringify(r)}`));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(r){if("string"!=typeof r)return this.emit("error",Error(`Formatter must return a string, null or undefined, got ${JSON.stringify(r)}`)),null;const t=l.length&&r.indexOf(l)>=0,e=""!==c&&r.indexOf(c)>=0,i=r.indexOf(a)>=0&&a!==c,n=r.indexOf(m)>=0,u=d&&"string"==typeof o;let h=_&&_.filter((t=>"string"==typeof t?-1!==r.indexOf(t):t.test(r)));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");r=r.replace(t,a+a)}if(!0===e){const t=new RegExp(c,"g");r=r.replace(t,a+c)}!0===p&&(r=c+r+c),s+=r}else(!0===h||""===o&&!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 r in arguments){const o=arguments[r],n=typeof o;if(void 0===t&&Array.isArray(o))t=o;else if(void 0===e&&u(o))e=o;else{if(void 0!==i||"function"!==n)throw new a("CSV_INVALID_ARGUMENT",["Invalid argument:",`got ${JSON.stringify(o)} at index ${r}`]);i=o}}const r=new s(e);if(i){const t=[];r.on("readable",(function(){let e;for(;null!==(e=this.read());)t.push(e)})),r.on("error",(function(t){i(t)})),r.on("end",(function(){i(void 0,t.join(""))}))}if(void 0!==t)if("function"==typeof setImmediate)setImmediate((function(){for(let e of t)r.write(e);r.end()}));else{for(let e of t)r.write(e);r.end()}return r};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){if("string"==typeof t||p(t))return t;const e=`${t}`;return"0"==e&&1/t==-INFINITY?"-0":e},y=function(t,e){let i=0;const r=(e=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,r,o){let n=t;r?n=o.replace(h,"$1"):i&&(n=i.trim()),e.push(n)})),e}(t)}(e,t)).length;for(;null!=t&&i<r;)t=t[g(e[i++])];return i&&i===r?t:void 0}},888:(t,e,i)=>{t.exports={generate:i(608),parse:i(438),transform:i(485),stringify:i(164)}},432:(t,e,i)=>{var r=i(36).Symbol;t.exports=r},312:(t,e,i)=>{var r=i(571),o=i(679),n=Object.prototype.hasOwnProperty;t.exports=function(t,e,i){var s=t[e];n.call(t,e)&&o(s,i)&&(void 0!==i||e in t)||r(t,e,i)}},571:(t,e,i)=>{var r=i(133);t.exports=function(t,e,i){"__proto__"==e&&r?r(t,e,{configurable:!0,enumerable:!0,value:i,writable:!0}):t[e]=i}},77:(t,e,i)=>{var r=i(432),o=i(444),n=i(371),s=r?r.toStringTag:void 0;t.exports=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":s&&s in Object(t)?o(t):n(t)}},950:(t,e,i)=>{var r=i(553),o=i(909),n=i(130),s=i(760),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)||o(t))&&(r(t)?h:l).test(s(t))}},141:t=>{t.exports=function(t,e,i){for(var r=-1,o=t.length,n=e.length,s={};++r<o;){var l=r<n?e[r]:void 0;i(s,t[r],l)}return s}},780:(t,e,i)=>{var r=i(36)["__core-js_shared__"];t.exports=r},133:(t,e,i)=>{var r=i(789),o=function(){try{var t=r(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();t.exports=o},565:t=>{var e="object"==typeof global&&global&&global.Object===Object&&global;t.exports=e},789:(t,e,i)=>{var r=i(950),o=i(869);t.exports=function(t,e){var i=o(t,e);return r(i)?i:void 0}},444:(t,e,i)=>{var r=i(432),o=Object.prototype,n=o.hasOwnProperty,s=o.toString,l=r?r.toStringTag:void 0;t.exports=function(t){var e=n.call(t,l),i=t[l];try{t[l]=void 0;var r=!0}catch(t){}var o=s.call(t);return r&&(e?t[l]=i:delete t[l]),o}},869:t=>{t.exports=function(t,e){return null==t?void 0:t[e]}},909:(t,e,i)=>{var r,o=i(780),n=(r=/[^.]+$/.exec(o&&o.keys&&o.keys.IE_PROTO||""))?"Symbol(src)_1."+r:"";t.exports=function(t){return!!n&&n in t}},371:t=>{var e=Object.prototype.toString;t.exports=function(t){return e.call(t)}},36:(t,e,i)=>{var r=i(565),o="object"==typeof self&&self&&self.Object===Object&&self,n=r||o||Function("return this")();t.exports=n},760:t=>{var e=Function.prototype.toString;t.exports=function(t){if(null!=t){try{return e.call(t)}catch(t){}try{return t+""}catch(t){}}return""}},679:t=>{t.exports=function(t,e){return t===e||t!=t&&e!=e}},553:(t,e,i)=>{var r=i(77),o=i(130);t.exports=function(t){if(!o(t))return!1;var e=r(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}},130:t=>{t.exports=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}},613:(t,e,i)=>{var r=i(312),o=i(141);t.exports=function(t,e){return o(t||[],e||[],r)}},485:(t,e,i)=>{var r,o,n,s;n=i(203),s=i(23),({clone:o}=i(268)),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=o(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 r(u,n),i=!1,c&&setImmediate((function(){var t,e,r;for(t=0,e=c.length;t<e&&(r=c[t],!i);t++)h.write(r);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},r=function(t={},e){var i,r;return this.options=t,this.handler=e,null==(i=this.options).consume&&(i.consume=!1),this.options.objectMode=!0,null==(r=this.options).parallel&&(r.parallel=100),n.Transform.call(this,this.options),this.state={running:0,started:0,finished:0},this},s.inherits(r,n.Transform),t.exports.Transformer=r,r.prototype._transform=function(t,e,i){var r,o,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");r=(t,...e)=>this.__done(t,e,i),this.handler.call(this,t,r,this.options.params)}return!1}catch(t){return o=t,this.__done(o)}},r.prototype._flush=function(t){return this._ending=function(){if(0===this.state.running)return this._ending=void 0,t()},this._ending()},r.prototype.__done=function(t,e,i){var r,o,n;if(this.state.running--,t)return this.emit("error",t);for(this.state.finished++,o=0,n=e.length;o<n;o++)"number"==typeof(r=e[o])&&(r=`${r}`),null!=r&&""!==r&&this.push(r);return i&&i(),this._ending?this._ending():void 0}},237:(t,e,i)=>{const r=i(514),o=i(370);t.exports={packageName:"dbgate-plugin-csv",shellApi:{reader:r,writer:o},initialize(t){r.initialize(t)}}},514:(t,e,i)=>{const r=i(613),o=i(888),n=i(896),s=i(203);let l;class a extends s.Transform{constructor({header:t}){super({objectMode:!0}),this.structure=null,this.header=t}_transform(t,e,i){this.structure?(this.push(r(this.structure.columns.map((t=>t.columnName)),t)),i()):(this.header?(this.structure={__isStreamHeader:!0,columns:t.map((t=>({columnName:t})))},this.push(this.structure)):(this.structure={__isStreamHeader:!0,columns:t.map(((t,e)=>({columnName:`col${e+1}`})))},this.push(this.structure),this.push(r(this.structure.columns.map((t=>t.columnName)),t))),i())}}async function u({fileName:t,encoding:e="utf-8",header:i=!0,delimiter:r,limitRows:s}){console.log(`Reading file ${t}`);const u=o.parse({delimiter:r,skip_lines_with_error:!0,to_line:s?s+1:void 0}),c=await l.download(t),f=n.createReadStream(c,e),h=new a({header:i});return f.pipe(u),u.pipe(h),h}u.initialize=t=>{l=t.dbgateApi},t.exports=u},370:(t,e,i)=>{const r=i(888),o=i(896),n=i(203),{getLogger:s}=global.DBGATE_TOOLS,l=s("csvWriter");class a 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:s}){l.info(`Writing file ${t}`);const u=new a({header:i}),c=r.stringify({delimiter:n,quoted:s}),f=o.createWriteStream(t,e);return u.pipe(c),c.pipe(f),u.finisher=f,u.requireFixedStructure=!0,u}},896:t=>{"use strict";t.exports=require("fs")},203:t=>{"use strict";t.exports=require("stream")},23:t=>{"use strict";t.exports=require("util")},268:(t,e)=>{"use strict";function i(t){return i="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},i(t)}function r(t){return Array.isArray(t)?t.map((function(t){return r(t)})):t&&"object"===i(t)?o({},t):t}function o(){for(var t=arguments[0],e=1;e<arguments.length;e++){var i=arguments[e];if(s(i)){s(t)||(t={});for(var n=0,l=Object.keys(i);n<l.length;n++){var a=l[n];/__proto__|prototype/.test(a)||(t[a]=o(t[a],i[a]))}}else Array.isArray(i)?t=i.map((function(t){return r(t)})):void 0!==i&&(t=i)}return t}function n(t){return t.replace(/([a-z\d])([A-Z]+)/g,"$1_$2").replace(/[-\s]+/g,"_").toLowerCase()}function s(t){var e=t;if("object"!==i(t)||null===t)return!1;if(null===Object.getPrototypeOf(e))return!0;for(;null!==Object.getPrototypeOf(e=Object.getPrototypeOf(e)););return Object.getPrototypeOf(t)===e}e.clone=r,e.compare=function t(e,i){if(s(e)){if(!s(i))return!1;var r=Object.keys(e).sort(),o=Object.keys(i).sort();if(r.length!==o.length)return!1;for(var n=0;n<r.length;n++){var l=r[n];if(l!==o[n])return!1;if(!t(e[l],i[l]))return!1}}else if(Array.isArray(e)){if(!Array.isArray(i))return!1;if(e.length!==i.length)return!1;for(var a=0;a<e.length;a++)if(!t(e[a],i[a]))return!1}else if(e!==i)return!1;return!0},e.is_object=function(t){return t&&"object"===i(t)&&!Array.isArray(t)},e.is_object_literal=s,e.merge=function(){return o.apply(void 0,[{}].concat(Array.prototype.slice.call(arguments)))},e.mutate=o,e.snake_case=function t(e){var i=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r={};if(s(e))for(var o="number"==typeof i&&i>0?i-1:i,l=0,a=Object.keys(e);l<a.length;l++){var u=a[l],c=e[u];i&&(u=n(u)),r[u]=t(c,o)}else r=e;return r},e.snake_case_str=n}},e={},r=function i(r){var o=e[r];if(void 0!==o)return o.exports;var n=e[r]={exports:{}};return t[r](n,n.exports,i),n.exports}(237);module.exports=r})();

@@ -1,1 +0,1 @@

var plugin=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}return 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:[{packageName:"dbgate-plugin-csv",storageType:"csv",extension:"csv",name:"CSV",readerFunc:"reader@dbgate-plugin-csv",writerFunc:"writer@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:!0}]}],quickExports:[{label:"CSV file",extension:"csv",createWriter:e=>({functionName:"writer@dbgate-plugin-csv",props:{fileName:e,delimiter:","}})},{label:"CSV file (semicolon separated)",extension:"csv",createWriter:e=>({functionName:"writer@dbgate-plugin-csv",props:{fileName:e,delimiter:";"}})}]}}]);
var plugin;(()=>{"use strict";var e={d:(a,t)=>{for(var r in t)e.o(t,r)&&!e.o(a,r)&&Object.defineProperty(a,r,{enumerable:!0,get:t[r]})},o:(e,a)=>Object.prototype.hasOwnProperty.call(e,a),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},a={};e.r(a),e.d(a,{default:()=>t});const t={fileFormats:[{packageName:"dbgate-plugin-csv",storageType:"csv",extension:"csv",name:"CSV",readerFunc:"reader@dbgate-plugin-csv",writerFunc:"writer@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:!0}]}],quickExports:[{label:"CSV file",extension:"csv",createWriter:e=>({functionName:"writer@dbgate-plugin-csv",props:{fileName:e,delimiter:","}})},{label:"CSV file (semicolon separated)",extension:"csv",createWriter:e=>({functionName:"writer@dbgate-plugin-csv",props:{fileName:e,delimiter:";"}})}]};plugin=a})();
{
"name": "dbgate-plugin-csv",
"main": "dist/backend.js",
"version": "5.2.7",
"version": "5.2.8",
"homepage": "https://dbgate.org",

@@ -38,5 +38,5 @@ "description": "CSV import/export plugin for DbGate",

"lodash": "^4.17.21",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11"
"webpack": "^5.91.0",
"webpack-cli": "^5.1.4"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc