dbgate-plugin-csv
Advanced tools
Comparing version 5.0.9 to 5.1.0
@@ -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){var r,o,n,s=[].indexOf;o=i(0),n=i(5),t.exports=function(){var t,e,i,o;return 2===arguments.length?(o=arguments[0],t=arguments[1]):1===arguments.length?"function"==typeof arguments[0]?(o={},t=arguments[0]):o=arguments[0]:0===arguments.length&&(o={}),i=new r(o),t&&(e=[],i.on("readable",(function(){var t,r;for(r=[];t=i.read();)r.push(e.push(t));return r})),i.on("error",t),i.on("end",(function(){return i.options.objectMode||(e=i.options.encoding?e.join(""):Buffer.concat(e)),t(null,e)}))),i},r=function(t={}){var e,i,n,l,a,u,c,f,h,d,_,m,p,g,y,b,v,w,O;for(b in t.high_water_mark&&(t.highWaterMark=t.high_water_mark),t.object_mode&&(t.objectMode=t.object_mode),o.Readable.call(this,t),this.options={},t)O=t[b],this.options[r.camelize(b)]=O;for(null==(i=this.options).columns&&(i.columns=8),null==(n=this.options).delimiter&&(n.delimiter=","),null==(u=this.options).duration&&(u.duration=null),null==(c=this.options).encoding&&(c.encoding=null),null==(f=this.options).end&&(f.end=null),null==(h=this.options).eof&&(h.eof=!1),null==(d=this.options).fixedSize&&(d.fixedSize=!1),null==(_=this.options).length&&(_.length=-1),null==(m=this.options).maxWordLength&&(m.maxWordLength=16),null==(p=this.options).rowDelimiter&&(p.rowDelimiter="\n"),null==(l=this.options).seed&&(l.seed=!1),null==(a=this.options).sleep&&(a.sleep=0),!0===this.options.eof&&(this.options.eof=this.options.rowDelimiter),this._={start_time:this.options.duration?Date.now():null,fixed_size_buffer:"",count_written:0,count_created:0},"number"==typeof this.options.columns&&(this.options.columns=new Array(this.options.columns)),e=Object.keys(r).filter((function(t){return"super_"!==t&&"camelize"!==t})),g=y=0,v=(w=this.options.columns).length;y<v;g=++y)if(null==(O=w[g])&&(O="ascii"),"string"==typeof O){if(s.call(e,O)<0)throw Error(`Invalid column type: got "${O}", default values are ${JSON.stringify(e)}`);this.options.columns[g]=r[O]}return this},n.inherits(r,o.Readable),t.exports.Generator=r,r.prototype.random=function(){return this.options.seed?this.options.seed=this.options.seed*Math.PI*100%100/100:Math.random()},r.prototype.end=function(){return this.push(null)},r.prototype._read=function(t){var e,i,r,o,n,s,l,a,u,c,f,h,d,_;for(e=[],(u=this._.fixed_size_buffer.length)&&e.push(this._.fixed_size_buffer);;){if(this._.count_created===this.options.length||this.options.end&&Date.now()>this.options.end||this.options.duration&&Date.now()>this._.start_time+this.options.duration){if(e.length)if(this.options.objectMode)for(r=0,n=e.length;r<n;r++)c=e[r],this.__push(c);else this.__push(e.join("")+(this.options.eof?this.options.eof:""));return this.push(null)}for(c=[],o=0,s=(_=this.options.columns).length;o<s;o++)i=_[o],c.push(`${i(this)}`);if(this.options.objectMode)for(f=0,h=0,l=c.length;h<l;h++)f+=c[h].length;else f=(c=`${0===this._.count_created?"":this.options.rowDelimiter}${c.join(this.options.delimiter)}`).length;if(this._.count_created++,u+f>t){if(this.options.objectMode)for(e.push(c),d=0,a=e.length;d<a;d++)c=e[d],this.__push(c);else this.options.fixedSize?(this._.fixed_size_buffer=c.substr(t-u),e.push(c.substr(0,t-u))):e.push(c),this.__push(e.join(""));break}u+=f,e.push(c)}},r.prototype.__push=function(t){return this._.count_written++,this.options.sleep>0?setTimeout(()=>this.push(t),this.options.sleep):this.push(t)},r.ascii=function(t){var e,i,r,o;for(i=[],r=0,o=Math.ceil(t.random()*t.options.maxWordLength);0<=o?r<o:r>o;0<=o?++r:--r)e=Math.floor(32*t.random()),i.push(String.fromCharCode(e+(e<16?65:81)));return i.join("")},r.int=function(t){return Math.floor(t.random()*Math.pow(2,52))},r.bool=function(t){return Math.floor(2*t.random())},r.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)e.cast_date=function(t){const e=Date.parse(t);return isNaN(e)?t:new Date(e)};else if("function"!=typeof e.cast_date)throw new a("CSV_INVALID_OPTION_CAST_DATE",["Invalid option cast_date:","cast_date must be true or a function,",`got ${JSON.stringify(e.cast_date)}`],e);let 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 object, a function or true,",`got ${JSON.stringify(e.columns)}`],e);e.columns=!1}if(void 0===e.columns_duplicates_to_array||null===e.columns_duplicates_to_array||!1===e.columns_duplicates_to_array)e.columns_duplicates_to_array=!1;else if(!0!==e.columns_duplicates_to_array)throw new a("CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY",["Invalid option columns_duplicates_to_array:","expect an boolean,",`got ${JSON.stringify(e.columns_duplicates_to_array)}`],e);if(void 0===e.comment||null===e.comment||!1===e.comment||""===e.comment)e.comment=null;else if("string"==typeof e.comment&&(e.comment=Buffer.from(e.comment,e.encoding)),!Buffer.isBuffer(e.comment))throw new a("CSV_INVALID_OPTION_COMMENT",["Invalid option comment:","comment must be a buffer or a string,",`got ${JSON.stringify(e.comment)}`],e);const n=JSON.stringify(e.delimiter);if(Array.isArray(e.delimiter)||(e.delimiter=[e.delimiter]),0===e.delimiter.length)throw new a("CSV_INVALID_OPTION_DELIMITER",["Invalid option delimiter:","delimiter must be a non empty string or buffer or array of string|buffer,",`got ${n}`],e);if(e.delimiter=e.delimiter.map((function(t){if(null==t||!1===t)return Buffer.from(",",e.encoding);if("string"==typeof t&&(t=Buffer.from(t,e.encoding)),!Buffer.isBuffer(t)||0===t.length)throw new a("CSV_INVALID_OPTION_DELIMITER",["Invalid option delimiter:","delimiter must be a non empty string or buffer or array of string|buffer,",`got ${n}`],e);return t})),void 0===e.escape||!0===e.escape?e.escape=Buffer.from('"',e.encoding):"string"==typeof e.escape?e.escape=Buffer.from(e.escape,e.encoding):null!==e.escape&&!1!==e.escape||(e.escape=null),null!==e.escape&&!Buffer.isBuffer(e.escape))throw new Error(`Invalid Option: escape must be a buffer, a string or a boolean, got ${JSON.stringify(e.escape)}`);if(void 0===e.from||null===e.from)e.from=1;else{if("string"==typeof e.from&&/\d+/.test(e.from)&&(e.from=parseInt(e.from)),!Number.isInteger(e.from))throw new Error(`Invalid Option: from must be an integer, got ${JSON.stringify(e.from)}`);if(e.from<0)throw new Error(`Invalid Option: from must be a positive integer, got ${JSON.stringify(t.from)}`)}if(void 0===e.from_line||null===e.from_line)e.from_line=1;else{if("string"==typeof e.from_line&&/\d+/.test(e.from_line)&&(e.from_line=parseInt(e.from_line)),!Number.isInteger(e.from_line))throw new Error(`Invalid Option: from_line must be an integer, got ${JSON.stringify(t.from_line)}`);if(e.from_line<=0)throw new Error(`Invalid Option: from_line must be a positive integer greater than 0, got ${JSON.stringify(t.from_line)}`)}if(void 0===e.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={comment_lines:0,empty_lines:0,invalid_field_length:0,lines:1,records:0},this.options=e,this.state={bomSkipped:!1,castField:i,commenting:!1,error:void 0,enabled:1===e.from_line,escaping:!1,escapeIsQuote:Buffer.isBuffer(e.escape)&&Buffer.isBuffer(e.quote)&&0===Buffer.compare(e.escape,e.quote),expectedRecordLength:null===e.columns?0:e.columns.length,field:new o(20),firstLineToHeaders:r,info:Object.assign({},this.info),needMoreDataSize:Math.max(null!==e.comment?e.comment.length:0,...e.delimiter.map(t=>t.length),null!==e.quote?e.quote.length:0),previousBuf:void 0,quoting:!1,stop:!1,rawBuffer:new 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,info:l,ltrim:u,max_record_size:c,quote:f,raw:h,relax:d,rtrim:_,skip_empty_lines:m,to:p,to_line:g}=this.options;let{record_delimiter:y}=this.options;const{bomSkipped:b,previousBuf:v,rawBuffer:w,escapeIsQuote:O}=this.state;let I;if(void 0===v){if(void 0===t)return void this.push(null);I=t}else I=void 0!==v&&void 0===t?v:Buffer.concat([v,t]);if(!1===b)if(!1===i)this.state.bomSkipped=!0;else if(I.length<3){if(!1===e)return void(this.state.previousBuf=I)}else{for(let t in n)if(0===n[t].compare(I,0,n[t].length)){I=I.slice(n[t].length),this.__normalizeOptions({...this.__originalOptions,encoding:t});break}this.state.bomSkipped=!0}const S=I.length;let x;for(x=0;x<S&&!this.__needMoreData(x,S,e);x++){if(!0===this.state.wasRowDelimiter&&(this.info.lines++,!0===l&&0===this.state.record.length&&0===this.state.field.length&&!1===this.state.wasQuoting&&(this.state.info=Object.assign({},this.info)),this.state.wasRowDelimiter=!1),-1!==g&&this.info.lines>g)return this.state.stop=!0,void this.push(null);if(!1===this.state.quoting&&0===y.length){this.__autoDiscoverRecordDelimiter(I,x)&&(y=this.options.record_delimiter)}const t=I[x];if(!0===h&&w.append(t),13!==t&&10!==t||!1!==this.state.wasRowDelimiter||(this.state.wasRowDelimiter=!0),!0===this.state.escaping)this.state.escaping=!1;else{if(null!==o&&!0===this.state.quoting&&this.__isEscape(I,x,t)&&x+o.length<S){if(!O){this.state.escaping=!0,x+=o.length-1;continue}if(this.__isQuote(I,x+o.length)){this.state.escaping=!0,x+=o.length-1;continue}}if(!1===this.state.commenting&&this.__isQuote(I,x))if(!0===this.state.quoting){const e=I[x+f.length],i=_&&this.__isCharTrimable(e),n=null!==r&&this.__compareBytes(r,I,x+f.length,e),s=this.__isDelimiter(I,x+f.length,e),l=0===y.length?this.__autoDiscoverRecordDelimiter(I,x+f.length):this.__isRecordDelimiter(e,I,x+f.length);if(null!==o&&this.__isEscape(I,x,t)&&this.__isQuote(I,x+o.length))x+=o.length-1;else{if(!e||s||l||n||i){this.state.quoting=!1,this.state.wasQuoting=!0,x+=f.length-1;continue}if(!1===d){const t=this.__error(new a("CSV_INVALID_CLOSING_QUOTE",["Invalid Closing Quote:",`got "${String.fromCharCode(e)}"`,`at line ${this.info.lines}`,"instead of delimiter, record delimiter, trimable character","(if activated) or comment"],this.options,this.__context()));if(void 0!==t)return t}else this.state.quoting=!1,this.state.wasQuoting=!0,this.state.field.prepend(f),x+=f.length-1}}else{if(0===this.state.field.length){this.state.quoting=!0,x+=f.length-1;continue}if(!1===d){const t=this.__error(new a("INVALID_OPENING_QUOTE",["Invalid Opening Quote:",`a quote is found inside a field at line ${this.info.lines}`],this.options,this.__context(),{field:this.state.field}));if(void 0!==t)return t}}if(!1===this.state.quoting){let e=this.__isRecordDelimiter(t,I,x);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(),x+=e-1;continue}if(!0===m&&!1===this.state.wasQuoting&&0===this.state.record.length&&0===this.state.field.length){this.info.empty_lines++,x+=e-1;continue}const t=this.__onField();if(void 0!==t)return t;const i=this.__onRecord();if(void 0!==i)return i;if(-1!==p&&this.info.records>=p)return this.state.stop=!0,void this.push(null)}this.state.commenting=!1,x+=e-1;continue}if(this.state.commenting)continue;if(0!==(null===r?0:this.__compareBytes(r,I,x,t))){this.state.commenting=!0;continue}let i=this.__isDelimiter(I,x,t);if(0!==i){const t=this.__onField();if(void 0!==t)return t;x+=i-1;continue}}}if(!1===this.state.commenting&&0!==c&&this.state.record_length+this.state.field.length>c){const t=this.__error(new a("CSV_MAX_RECORD_SIZE",["Max Record Size:","record exceed the maximum number of tolerated bytes",`of ${c}`,`at line ${this.info.lines}`],this.options,this.__context()));if(void 0!==t)return t}const e=!1===u||!0===this.state.quoting||0!==this.state.field.length||!this.__isCharTrimable(t),i=!1===_||!1===this.state.wasQuoting;if(!0===e&&!0===i)this.state.field.append(t);else if(!0===_&&!this.__isCharTrimable(t)){const t=this.__error(new a("CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE",["Invalid Closing Quote:","found non trimable byte after quote",`at line ${this.info.lines}`],this.options,this.__context()));if(void 0!==t)return t}}if(!0===e)if(!0===this.state.quoting){const t=this.__error(new a("CSV_QUOTE_NOT_CLOSED",["Quote Not Closed:",`the parsing is finished with an opening quote at line ${this.info.lines}`],this.options,this.__context()));if(void 0!==t)return t}else if(!0===this.state.wasQuoting||0!==this.state.record.length||0!==this.state.field.length){const t=this.__onField();if(void 0!==t)return t;const e=this.__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.previousBuf=I.slice(x);!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 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.__context(),{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.__context(),{record:d});if(!0===n||!0===s&&_<this.state.expectedRecordLength||!0===l&&_>this.state.expectedRecordLength)this.info.invalid_field_length++,this.state.error=e;else{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&&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.state.info}:{}));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.state.info}:{}));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.state.info}:{}));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.__context(),{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.__context();try{t=e.call(null,t,i)}catch(t){return t}if(null==t)return}this.push(t)}__cast(t){const{columns:e,relax_column_count:i}=this.options;if(!0===Array.isArray(e)&&i&&this.options.columns.length<=this.state.record.length)return[void 0,void 0];const r=this.__context();if(null!==this.state.castField)try{return[void 0,this.state.castField.call(null,t,r)]}catch(t){return[t]}return this.__isFloat(t)?[void 0,parseFloat(t)]:!1!==this.options.cast_date?[void 0,this.options.cast_date.call(null,t,r)]:[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}__context(){const{columns:t}=this.options;return{column:!0===Array.isArray(t)?t.length>this.state.record.length?t[this.state.record.length].name:null:this.state.record.length,empty_lines:this.info.empty_lines,error:this.state.error,header:!0===t,index:this.state.record.length,invalid_field_length:this.info.invalid_field_length,quoting:this.state.wasQuoting,lines:this.info.lines,records:this.info.records}}}const l=function(){let t,e,i;for(let 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}`],this.options);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.info)})),r.on("end",(function(){i(void 0,t,r.info)}))}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 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(o=arguments[t],a(o))for(i in a(n)||(n={}),o)"__proto__"!==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);class s extends n.Transform{constructor({header:t}){super({objectMode:!0}),this.structure=null,this.header=t}_transform(t,e,i){this.structure?(this.push(this.structure.columns.map(e=>t[e.columnName])),i()):(this.structure=t,this.header&&this.push(t.columns.map(t=>t.columnName)),i())}}t.exports=async function({fileName:t,encoding:e="utf-8",header:i=!0,delimiter:n,quoted:l}){console.log(`Writing file ${t}`);const a=new s({header:i}),u=r.stringify({delimiter:n,quoted:l}),c=o.createWriteStream(t,e);return a.pipe(u),u.pipe(c),a.finisher=c,a.requireFixedStructure=!0,a}}]); | ||
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);class s extends n.Transform{constructor({header:t}){super({objectMode:!0}),this.structure=null,this.header=t}_transform(t,e,i){this.structure?(this.push(this.structure.columns.map(e=>t[e.columnName])),i()):(this.structure=t,this.header&&this.push(t.columns.map(t=>t.columnName)),i())}}t.exports=async function({fileName:t,encoding:e="utf-8",header:i=!0,delimiter:n,quoted:l}){console.log("Writing file "+t);const a=new s({header:i}),u=r.stringify({delimiter:n,quoted:l}),c=o.createWriteStream(t,e);return a.pipe(u),u.pipe(c),a.finisher=c,a.requireFixedStructure=!0,a}}]); |
{ | ||
"name": "dbgate-plugin-csv", | ||
"main": "dist/backend.js", | ||
"version": "5.0.9", | ||
"version": "5.1.0", | ||
"homepage": "https://dbgate.org", | ||
@@ -6,0 +6,0 @@ "description": "CSV import/export plugin for DbGate", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56959
3