dbgate-plugin-dbf 6.6.0 → 6.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/backend.js +1 -1
  2. package/package.json +1 -1
package/dist/backend.js CHANGED
@@ -1 +1 @@
1
- (()=>{var t={237:(t,e,i)=>{const o=i(514);t.exports={packageName:"dbgate-plugin-dbf",shellApi:{reader:o},initialize(t){o.initialize(t)}}},514:(t,e,i)=>{i(825),i(836),i(896);const o=i(203),{DBFFile:n}=i(726),{getLogger:r,extractErrorLogData:s}=global.DBGATE_PACKAGES["dbgate-tools"],l=r("dbfReader");let a;function f(t){const{type:e,size:i}=t;switch(e){case"C":return`varchar(${i})`;case"N":return"numeric";case"F":return"float";case"Y":return"money";case"I":return"int";case"L":return"boolean";case"D":return"date";case"T":return"datetime";case"B":return"duouble";case"M":return"varchar(max)";default:return"string"}}async function u({fileName:t,encoding:e="ISO-8859-1",includeDeletedRecords:i=!1,limitRows:r}){console.log(`Reading file ${t}`);const u=await a.download(t),c=new o.PassThrough({objectMode:!0});return(async()=>{try{const t=await n.open(u,{encoding:e,includeDeletedRecords:i}),o=t.fields.map((t=>({columnName:t.name,dataType:f(t)})));c.write({__isStreamHeader:!0,columns:o});let s=0;for await(const e of t)if(c.write(e),s++,r&&s>=r)break;c.end()}catch(t){l.error(s(t),"Error reading DBF file"),c.end()}})(),c}u.initialize=t=>{a=t.dbgateApi},t.exports=u},726:t=>{"use strict";t.exports=require("dbffile")},825:t=>{"use strict";t.exports=require("lodash")},896:t=>{"use strict";t.exports=require("fs")},203:t=>{"use strict";t.exports=require("stream")},23:t=>{"use strict";t.exports=require("util")},836:(t,e,i)=>{"use strict";var o=i(203),n=i(23);const r=function(t={}){return t.seed?t.seed=t.seed*Math.PI*100%100/100:Math.random()},s={ascii:function({options:t}){const e=[],i=Math.ceil(r(t)*t.maxWordLength);for(let o=0;o<i;o++){const i=Math.floor(32*r(t));e.push(String.fromCharCode(i+(i<16?65:81)))}return e.join("")},int:function({options:t}){return Math.floor(r(t)*Math.pow(2,52))},bool:function({options:t}){return Math.floor(2*r(t))}},l=function(t={}){return this.options=(t=>{t.object_mode&&(t.objectMode=t.object_mode),t.high_water_mark&&(t.highWaterMark=t.high_water_mark);const e={};for(const o in t)e[(i=o,i.replace(/_([a-z])/gi,(function(t,e){return e.toUpperCase()})))]=t[o];var i;const o={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 o)void 0===e[t]&&(e[t]=o[t]);!0===e.eof&&(e.eof=e.rowDelimiter),"number"==typeof e.columns&&(e.columns=new Array(e.columns));const n=Object.keys(s).filter((t=>!["super_","camelize"].includes(t)));for(let t=0;t<e.columns.length;t++){const i=e.columns[t]||"ascii";if("string"==typeof i){if(!n.includes(i))throw Error(`Invalid column type: got "${i}", default values are ${JSON.stringify(n)}`);e.columns[t]=s[i]}}return e})(t),o.Readable.call(this,this.options),this.state=(t=>({start_time:this.options.duration?Date.now():null,fixed_size_buffer:"",count_written:0,count_created:0}))(),this};n.inherits(l,o.Readable),l.prototype.end=function(){this.push(null)},l.prototype._read=function(t){setImmediate((()=>{this.__read(t)}))},l.prototype.__read=function(t){((t,e,i,o,n)=>{const r=[];let s=0;for(t.fixedSize&&(s=e.fixed_size_buffer.length,0!==s&&r.push(e.fixed_size_buffer));;){if(e.count_created===t.length||t.end&&Date.now()>t.end||t.duration&&Date.now()>e.start_time+t.duration){if(r.length){if(t.objectMode)for(const t of r)o(t);else o(r.join("")+(t.eof?t.eof:""));e.end=!0}else n();return}let l,a=[];for(const i of t.columns){const o=i({options:t,state:e}),r=typeof o;if(null!==o&&"string"!==r&&"number"!==r)return void n(Error(["INVALID_VALUE:","values returned by column function must be","a string, a number or null,",`got ${JSON.stringify(o)}`].join(" ")));a.push(o)}if(t.objectMode){l=0;for(const t of a)l+=t.length}else a=(0===e.count_created?"":t.rowDelimiter)+a.join(t.delimiter),l=a.length;if(e.count_created++,s+l>i){if(t.objectMode){r.push(a);for(const t of r)o(t)}else t.fixedSize?(e.fixed_size_buffer=a.substr(i-s),r.push(a.substr(0,i-s))):r.push(a),o(r.join(""));return}s+=l,r.push(a)}})(this.options,this.state,t,(t=>{this.__push(t)}),(t=>{t?this.destroy(t):this.push(null)}))},l.prototype.__push=function(t){const e=()=>{if(this.state.count_written++,this.push(t),!0===this.state.end)return this.push(null)};this.options.sleep>0?setTimeout(e,this.options.sleep):e()};const a=function(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)};let f=class t extends Error{constructor(e,i,o,...n){Array.isArray(i)&&(i=i.join(" ").trim()),super(i),void 0!==Error.captureStackTrace&&Error.captureStackTrace(this,t),this.code=e;for(const t of n)for(const e in t){const i=t[e];this[e]=Buffer.isBuffer(i)?i.toString(o.encoding):null==i?i:JSON.parse(JSON.stringify(i))}}};const u=function(t){const e=[];for(let i=0,o=t.length;i<o;i++){const o=t[i];if(null==o||!1===o)e[i]={disabled:!0};else if("string"==typeof o)e[i]={name:o};else{if(!a(o))throw new f("CSV_INVALID_COLUMN_DEFINITION",["Invalid column definition:","expect a string or a literal object,",`got ${JSON.stringify(o)} at position ${i}`]);if("string"!=typeof o.name)throw new f("CSV_OPTION_COLUMNS_MISSING_NAME",["Option columns missing name:",`property "name" is required at position ${i}`,"when column is an object literal"]);e[i]=o}}return e};class c{constructor(t=100){this.size=t,this.length=0,this.buf=Buffer.allocUnsafe(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.allocUnsafe(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.allocUnsafe(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}}const d=function(t){return{bomSkipped:!1,bufBytesStart:0,castField:t.cast_function,commenting:!1,error:void 0,enabled:1===t.from_line,escaping:!1,escapeIsQuote:Buffer.isBuffer(t.escape)&&Buffer.isBuffer(t.quote)&&0===Buffer.compare(t.escape,t.quote),expectedRecordLength:Array.isArray(t.columns)?t.columns.length:void 0,field:new c(20),firstLineToHeaders:t.cast_first_line_to_header,needMoreDataSize:Math.max(null!==t.comment?t.comment.length:0,...t.delimiter.map((t=>t.length)),null!==t.quote?t.quote.length:0),previousBuf:void 0,quoting:!1,stop:!1,rawBuffer:new c(100),record:[],recordHasError:!1,record_length:0,recordDelimiterMaxLength:0===t.record_delimiter.length?0:Math.max(...t.record_delimiter.map((t=>t.length))),trimChars:[Buffer.from(" ",t.encoding)[0],Buffer.from("\t",t.encoding)[0]],wasQuoting:!1,wasRowDelimiter:!1,timchars:[Buffer.from(Buffer.from([13],"utf8").toString(),t.encoding),Buffer.from(Buffer.from([10],"utf8").toString(),t.encoding),Buffer.from(Buffer.from([12],"utf8").toString(),t.encoding),Buffer.from(Buffer.from([32],"utf8").toString(),t.encoding),Buffer.from(Buffer.from([9],"utf8").toString(),t.encoding)]}},h=function(t){const e={};for(const o in t)e[(i=o,i.replace(/([A-Z])/g,(function(t,e){return"_"+e.toLowerCase()})))]=t[o];var 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 f("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 f("CSV_INVALID_OPTION_BOM",["Invalid option bom:","bom must be true,",`got ${JSON.stringify(e.bom)}`],e);if(e.cast_function=null,void 0===e.cast||null===e.cast||!1===e.cast||""===e.cast)e.cast=void 0;else if("function"==typeof e.cast)e.cast_function=e.cast,e.cast=!0;else if(!0!==e.cast)throw new f("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 f("CSV_INVALID_OPTION_CAST_DATE",["Invalid option cast_date:","cast_date must be true or a function,",`got ${JSON.stringify(e.cast_date)}`],e);if(e.cast_first_line_to_header=null,!0===e.columns)e.cast_first_line_to_header=void 0;else if("function"==typeof e.columns)e.cast_first_line_to_header=e.columns,e.columns=!0;else if(Array.isArray(e.columns))e.columns=u(e.columns);else{if(void 0!==e.columns&&null!==e.columns&&!1!==e.columns)throw new f("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.group_columns_by_name||null===e.group_columns_by_name||!1===e.group_columns_by_name)e.group_columns_by_name=!1;else{if(!0!==e.group_columns_by_name)throw new f("CSV_INVALID_OPTION_GROUP_COLUMNS_BY_NAME",["Invalid option group_columns_by_name:","expect an boolean,",`got ${JSON.stringify(e.group_columns_by_name)}`],e);if(!1===e.columns)throw new f("CSV_INVALID_OPTION_GROUP_COLUMNS_BY_NAME",["Invalid option group_columns_by_name:","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 f("CSV_INVALID_OPTION_COMMENT",["Invalid option comment:","comment must be a buffer or a string,",`got ${JSON.stringify(e.comment)}`],e);if(void 0===e.comment_no_infix||null===e.comment_no_infix||!1===e.comment_no_infix)e.comment_no_infix=!1;else if(!0!==e.comment_no_infix)throw new f("CSV_INVALID_OPTION_COMMENT",["Invalid option comment_no_infix:","value must be a boolean,",`got ${JSON.stringify(e.comment_no_infix)}`],e);const o=JSON.stringify(e.delimiter);if(Array.isArray(e.delimiter)||(e.delimiter=[e.delimiter]),0===e.delimiter.length)throw new f("CSV_INVALID_OPTION_DELIMITER",["Invalid option delimiter:","delimiter must be a non empty string or buffer or array of string|buffer,",`got ${o}`],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 f("CSV_INVALID_OPTION_DELIMITER",["Invalid option delimiter:","delimiter must be a non empty string or buffer or array of string|buffer,",`got ${o}`],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 f("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 f("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){if(0===e.objname.length)throw new Error("Invalid Option: objname must be a non empty string")}else if("number"!=typeof e.objname)throw new Error(`Invalid Option: objname must be a string or a buffer, got ${e.objname}`);if(void 0!==e.objname)if("number"==typeof e.objname){if(!1!==e.columns)throw Error("Invalid Option: objname index cannot be combined with columns or be defined as a field")}else if(!1===e.columns)throw Error("Invalid Option: objname field must be combined with columns or be defined as an index");if(void 0===e.on_record||null===e.on_record)e.on_record=void 0;else if("function"!=typeof e.on_record)throw new f("CSV_INVALID_OPTION_ON_RECORD",["Invalid option `on_record`:","expect a function,",`got ${JSON.stringify(e.on_record)}`],e);if(void 0!==e.on_skip&&null!==e.on_skip&&"function"!=typeof e.on_skip)throw new Error(`Invalid Option: on_skip must be a function, got ${JSON.stringify(e.on_skip)}`);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(void 0===e.record_delimiter)e.record_delimiter=[];else if("string"==typeof e.record_delimiter||Buffer.isBuffer(e.record_delimiter)){if(0===e.record_delimiter.length)throw new f("CSV_INVALID_OPTION_RECORD_DELIMITER",["Invalid option `record_delimiter`:","value must be a non empty string or buffer,",`got ${JSON.stringify(e.record_delimiter)}`],e);e.record_delimiter=[e.record_delimiter]}else if(!Array.isArray(e.record_delimiter))throw new f("CSV_INVALID_OPTION_RECORD_DELIMITER",["Invalid option `record_delimiter`:","value must be a string, a buffer or array of string|buffer,",`got ${JSON.stringify(e.record_delimiter)}`],e);if(e.record_delimiter=e.record_delimiter.map((function(t,i){if("string"!=typeof t&&!Buffer.isBuffer(t))throw new f("CSV_INVALID_OPTION_RECORD_DELIMITER",["Invalid option `record_delimiter`:","value must be a string, a buffer or array of string|buffer",`at index ${i},`,`got ${JSON.stringify(t)}`],e);if(0===t.length)throw new f("CSV_INVALID_OPTION_RECORD_DELIMITER",["Invalid option `record_delimiter`:","value must be a non empty string or buffer",`at index ${i},`,`got ${JSON.stringify(t)}`],e);return"string"==typeof t&&(t=Buffer.from(t,e.encoding)),t})),"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.relax_quotes);else{if(void 0!==e.relax_quotes&&null!==e.relax_quotes)throw new Error(`Invalid Option: relax_quotes must be a boolean, got ${JSON.stringify(e.relax_quotes)}`);e.relax_quotes=!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_records_with_empty_values);else{if(void 0!==e.skip_records_with_empty_values&&null!==e.skip_records_with_empty_values)throw new Error(`Invalid Option: skip_records_with_empty_values must be a boolean, got ${JSON.stringify(e.skip_records_with_empty_values)}`);e.skip_records_with_empty_values=!1}if("boolean"==typeof e.skip_records_with_error);else{if(void 0!==e.skip_records_with_error&&null!==e.skip_records_with_error)throw new Error(`Invalid Option: skip_records_with_error must be a boolean, got ${JSON.stringify(e.skip_records_with_error)}`);e.skip_records_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)}`)}return e},_=function(t){return t.every((t=>null==t||t.toString&&""===t.toString().trim()))},m={utf8:Buffer.from([239,187,191]),utf16le:Buffer.from([255,254])};class p extends o.Transform{constructor(t={}){super({readableObjectMode:!0,...t,encoding:null}),this.api=function(t={}){const e=h(t);return{info:{bytes:0,comment_lines:0,empty_lines:0,invalid_field_length:0,lines:1,records:0},original_options:t,options:e,state:d(e),__needMoreData:function(t,e,i){if(i)return!1;const{encoding:o,escape:n,quote:r}=this.options,{quoting:s,needMoreDataSize:l,recordDelimiterMaxLength:a}=this.state;return e-t-1<Math.max(l,0===a?Buffer.from("\r\n",o).length:a,s?(null===n?0:n.length)+r.length:0,s?r.length+a:0)},parse:function(t,e,i,o){const{bom:n,comment_no_infix:r,encoding:s,from_line:l,ltrim:a,max_record_size:u,raw:c,relax_quotes:d,rtrim:_,skip_empty_lines:p,to:g,to_line:b}=this.options;let{comment:y,escape:v,quote:w,record_delimiter:I}=this.options;const{bomSkipped:O,previousBuf:S,rawBuffer:N,escapeIsQuote:E}=this.state;let x;if(void 0===S){if(void 0===t)return void o();x=t}else x=void 0!==S&&void 0===t?S:Buffer.concat([S,t]);if(!1===O)if(!1===n)this.state.bomSkipped=!0;else if(x.length<3){if(!1===e)return void(this.state.previousBuf=x)}else{for(const t in m)if(0===m[t].compare(x,0,m[t].length)){const e=m[t].length;this.state.bufBytesStart+=e,x=x.slice(e),this.options=h({...this.original_options,encoding:t}),({comment:y,escape:v,quote:w}=this.options);break}this.state.bomSkipped=!0}const A=x.length;let B;for(B=0;B<A&&!this.__needMoreData(B,A,e);B++){if(!0===this.state.wasRowDelimiter&&(this.info.lines++,this.state.wasRowDelimiter=!1),-1!==b&&this.info.lines>b)return this.state.stop=!0,void o();!1===this.state.quoting&&0===I.length&&this.__autoDiscoverRecordDelimiter(x,B)&&(I=this.options.record_delimiter);const t=x[B];if(!0===c&&N.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!==v&&!0===this.state.quoting&&this.__isEscape(x,B,t)&&B+v.length<A){if(!E){this.state.escaping=!0,B+=v.length-1;continue}if(this.__isQuote(x,B+v.length)){this.state.escaping=!0,B+=v.length-1;continue}}if(!1===this.state.commenting&&this.__isQuote(x,B))if(!0===this.state.quoting){const e=x[B+w.length],i=_&&this.__isCharTrimable(x,B+w.length),o=null!==y&&this.__compareBytes(y,x,B+w.length,e),n=this.__isDelimiter(x,B+w.length,e),r=0===I.length?this.__autoDiscoverRecordDelimiter(x,B+w.length):this.__isRecordDelimiter(e,x,B+w.length);if(null!==v&&this.__isEscape(x,B,t)&&this.__isQuote(x,B+v.length))B+=v.length-1;else{if(!e||n||r||o||i){this.state.quoting=!1,this.state.wasQuoting=!0,B+=w.length-1;continue}if(!1===d){const t=this.__error(new f("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(w),B+=w.length-1}}else{if(0===this.state.field.length){this.state.quoting=!0,B+=w.length-1;continue}if(!1===d){const t=this.__infoField(),e=Object.keys(m).map((t=>!!m[t].equals(this.state.field.toString())&&t)).filter(Boolean)[0],i=this.__error(new f("INVALID_OPENING_QUOTE",["Invalid Opening Quote:",`a quote is found on field ${JSON.stringify(t.column)} at line ${t.lines}, value is ${JSON.stringify(this.state.field.toString(s))}`,e?`(${e} bom)`:void 0],this.options,t,{field:this.state.field}));if(void 0!==i)return i}}if(!1===this.state.quoting){const e=this.__isRecordDelimiter(t,x,B);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)>=l){this.state.enabled=!0,this.__resetField(),this.__resetRecord(),B+=e-1;continue}if(!0===p&&!1===this.state.wasQuoting&&0===this.state.record.length&&0===this.state.field.length){this.info.empty_lines++,B+=e-1;continue}this.info.bytes=this.state.bufBytesStart+B;const t=this.__onField();if(void 0!==t)return t;this.info.bytes=this.state.bufBytesStart+B+e;const n=this.__onRecord(i);if(void 0!==n)return n;if(-1!==g&&this.info.records>=g)return this.state.stop=!0,void o()}this.state.commenting=!1,B+=e-1;continue}if(this.state.commenting)continue;if(null!==y&&(!1===r||0===this.state.record.length&&0===this.state.field.length)&&0!==this.__compareBytes(y,x,B,t)){this.state.commenting=!0;continue}const n=this.__isDelimiter(x,B,t);if(0!==n){this.info.bytes=this.state.bufBytesStart+B;const t=this.__onField();if(void 0!==t)return t;B+=n-1;continue}}}if(!1===this.state.commenting&&0!==u&&this.state.record_length+this.state.field.length>u)return this.__error(new f("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()));const e=!1===a||!0===this.state.quoting||0!==this.state.field.length||!this.__isCharTrimable(x,B),n=!1===_||!1===this.state.wasQuoting;if(!0!==e||!0!==n){if(!0!==_||this.__isCharTrimable(x,B)){!1===e&&(B+=this.__isCharTrimable(x,B)-1);continue}return this.__error(new f("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()))}this.state.field.append(t)}if(!0===e)if(!0===this.state.quoting){const t=this.__error(new f("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+B;const t=this.__onField();if(void 0!==t)return t;const e=this.__onRecord(i);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+=B,this.state.previousBuf=x.slice(B);!0===this.state.wasRowDelimiter&&(this.info.lines++,this.state.wasRowDelimiter=!1)},__onRecord:function(t){const{columns:e,group_columns_by_name:i,encoding:o,info:n,from:r,relax_column_count:s,relax_column_count_less:l,relax_column_count_more:a,raw:u,skip_records_with_empty_values:c}=this.options,{enabled:d,record:h}=this.state;if(!1===d)return this.__resetRecord();const m=h.length;if(!0===e)return!0===c&&_(h)?void this.__resetRecord():this.__firstLineToColumns(h);if(!1===e&&0===this.info.records&&(this.state.expectedRecordLength=m),m!==this.state.expectedRecordLength){const t=!1===e?new f("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH",["Invalid Record Length:",`expect ${this.state.expectedRecordLength},`,`got ${m} on line ${this.info.lines}`],this.options,this.__infoField(),{record:h}):new f("CSV_RECORD_INCONSISTENT_COLUMNS",["Invalid Record Length:",`columns length is ${e.length},`,`got ${m} on line ${this.info.lines}`],this.options,this.__infoField(),{record:h});if(!0===s||!0===l&&m<this.state.expectedRecordLength||!0===a&&m>this.state.expectedRecordLength)this.info.invalid_field_length++,this.state.error=t;else{const e=this.__error(t);if(e)return e}}if(!0===c&&_(h))this.__resetRecord();else{if(!0===this.state.recordHasError)return this.__resetRecord(),void(this.state.recordHasError=!1);if(this.info.records++,1===r||this.info.records>=r){const{objname:r}=this.options;if(!1!==e){const s={};for(let t=0,o=h.length;t<o;t++)void 0===e[t]||e[t].disabled||(!0===i&&void 0!==s[e[t].name]?Array.isArray(s[e[t].name])?s[e[t].name]=s[e[t].name].concat(h[t]):s[e[t].name]=[s[e[t].name],h[t]]:s[e[t].name]=h[t]);if(!0===u||!0===n){const e=Object.assign({record:s},!0===u?{raw:this.state.rawBuffer.toString(o)}:{},!0===n?{info:this.__infoRecord()}:{}),i=this.__push(void 0===r?e:[s[r],e],t);if(i)return i}else{const e=this.__push(void 0===r?s:[s[r],s],t);if(e)return e}}else if(!0===u||!0===n){const e=Object.assign({record:h},!0===u?{raw:this.state.rawBuffer.toString(o)}:{},!0===n?{info:this.__infoRecord()}:{}),i=this.__push(void 0===r?e:[h[r],e],t);if(i)return i}else{const e=this.__push(void 0===r?h:[h[r],h],t);if(e)return e}}this.__resetRecord()}},__firstLineToColumns:function(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 f("CSV_INVALID_COLUMN_MAPPING",["Invalid Column Mapping:","expect an array from column function,",`got ${JSON.stringify(i)}`],this.options,this.__infoField(),{headers:i}));const o=u(i);return this.state.expectedRecordLength=o.length,this.options.columns=o,void this.__resetRecord()}catch(t){return t}},__resetRecord:function(){!0===this.options.raw&&this.state.rawBuffer.reset(),this.state.error=void 0,this.state.record=[],this.state.record_length=0},__onField:function(){const{cast:t,encoding:e,rtrim:i,max_record_size:o}=this.options,{enabled:n,wasQuoting:r}=this.state;if(!1===n)return this.__resetField();let s=this.state.field.toString(e);if(!0===i&&!1===r&&(s=s.trimRight()),!0===t){const[t,e]=this.__cast(s);if(void 0!==t)return t;s=e}this.state.record.push(s),0!==o&&"string"==typeof s&&(this.state.record_length+=s.length),this.__resetField()},__resetField:function(){this.state.field.reset(),this.state.wasQuoting=!1},__push:function(t,e){const{on_record:i}=this.options;if(void 0!==i){const e=this.__infoRecord();try{t=i.call(null,t,e)}catch(t){return t}if(null==t)return}e(t)},__cast:function(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:function(t,e){return((t,e)=>{const{timchars:i}=this.state;t:for(let o=0;o<i.length;o++){const n=i[o];for(let i=0;i<n.length;i++)if(n[i]!==t[e+i])continue t;return n.length}return 0})(t,e)},__isFloat:function(t){return t-parseFloat(t)+1>=0},__compareBytes:function(t,e,i,o){if(t[0]!==o)return 0;const n=t.length;for(let o=1;o<n;o++)if(t[o]!==e[i+o])return 0;return n},__isDelimiter:function(t,e,i){const{delimiter:o,ignore_last_delimiters:n}=this.options;if(!0===n&&this.state.record.length===this.options.columns.length-1)return 0;if(!1!==n&&"number"==typeof n&&this.state.record.length===n-1)return 0;t:for(let n=0;n<o.length;n++){const r=o[n];if(r[0]===i){for(let i=1;i<r.length;i++)if(r[i]!==t[e+i])continue t;return r.length}}return 0},__isRecordDelimiter:function(t,e,i){const{record_delimiter:o}=this.options,n=o.length;t:for(let r=0;r<n;r++){const n=o[r],s=n.length;if(n[0]===t){for(let t=1;t<s;t++)if(n[t]!==e[i+t])continue t;return n.length}}return 0},__isEscape:function(t,e,i){const{escape:o}=this.options;if(null===o)return!1;const n=o.length;if(o[0]===i){for(let i=0;i<n;i++)if(o[i]!==t[e+i])return!1;return!0}return!1},__isQuote:function(t,e){const{quote:i}=this.options;if(null===i)return!1;const o=i.length;for(let n=0;n<o;n++)if(i[n]!==t[e+n])return!1;return!0},__autoDiscoverRecordDelimiter:function(t,e){const{encoding:i}=this.options,o=[Buffer.from("\r\n",i),Buffer.from("\n",i),Buffer.from("\r",i)];t:for(let i=0;i<o.length;i++){const n=o[i].length;for(let r=0;r<n;r++)if(o[i][r]!==t[e+r])continue t;return this.options.record_delimiter.push(o[i]),this.state.recordDelimiterMaxLength=o[i].length,o[i].length}return 0},__error:function(t){const{encoding:e,raw:i,skip_records_with_error:o}=this.options,n="string"==typeof t?new Error(t):t;return o?(this.state.recordHasError=!0,void(void 0!==this.options.on_skip&&this.options.on_skip(n,i?this.state.rawBuffer.toString(e):void 0))):n},__infoDataSet:function(){return{...this.info,columns:this.options.columns}},__infoRecord:function(){const{columns:t,raw:e,encoding:i}=this.options;return{...this.__infoDataSet(),error:this.state.error,header:!0===t,index:this.state.record.length,raw:e?this.state.rawBuffer.toString(i):void 0}},__infoField:function(){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}}}}({on_skip:(t,e)=>{this.emit("skip",t,e)},...t}),this.state=this.api.state,this.options=this.api.options,this.info=this.api.info}_transform(t,e,i){if(!0===this.state.stop)return;const o=this.api.parse(t,!1,(t=>{this.push(t)}),(()=>{this.push(null),this.end(),this.on("end",this.destroy)}));void 0!==o&&(this.state.stop=!0),i(o)}_flush(t){!0!==this.state.stop&&t(this.api.parse(void 0,!0,(t=>{this.push(t)}),(()=>{this.push(null),this.on("end",this.destroy)})))}}const g=function(t={},e){return this.options=t,void 0!==t.consume&&null!==t.consume||(this.options.consume=!1),this.options.objectMode=!0,void 0!==t.parallel&&null!==t.parallel||(this.options.parallel=100),void 0!==t.params&&null!==t.params||(t.params=null),this.handler=e,o.Transform.call(this,this.options),this.state={running:0,started:0,finished:0,paused:!1},this};n.inherits(g,o.Transform),g.prototype._transform=function(t,e,i){this.state.started++,this.state.running++,!this.state.paused&&this.state.running<this.options.parallel&&(i(),i=null);try{let e=this.handler.length;if(null!==this.options.params&&e--,1===e){const e=this.handler.call(this,t,this.options.params);e&&e.then?(e.then((t=>{this.__done(null,[t],i)})),e.catch((t=>{this.__done(t)}))):this.__done(null,[e],i)}else{if(2!==e)throw Error("Invalid handler arguments");{const e=(t,...e)=>this.__done(t,e,i);this.handler.call(this,t,e,this.options.params)}}return!1}catch(t){this.__done(t)}},g.prototype._flush=function(t){0===this.state.running?t():this._ending=function(){t()}},g.prototype.__done=function(t,e,i){if(this.state.running--,t)return this.destroy(t);this.state.finished++;for(let t of e)"number"==typeof t&&(t=`${t}`),null!=t&&""!==t&&(this.state.paused=!this.push(t));i&&i(),this._ending&&0===this.state.running&&this._ending()};class b extends Error{constructor(t,e,...i){Array.isArray(e)&&(e=e.join(" ")),super(e),void 0!==Error.captureStackTrace&&Error.captureStackTrace(this,b),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))}}}const y=function(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)},v=".".charCodeAt(0),w=/\\(\\)?/g,I=RegExp("[^.[\\]]+|\\[(?:([^\"'][^[]*)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))","g"),O=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,S=/^\w*$/,N=function(t){const e=typeof t;return"symbol"===e||"object"===e&&t&&"[object Symbol]"===function(t){return Object.prototype.toString.call(t)}(t)},E=function(t){if("string"==typeof t||N(t))return t;const e=`${t}`;return"0"==e&&1/t==-INFINITY?"-0":e},x=function(t,e){let i=0;const o=(e=function(t,e){return Array.isArray(t)?t:function(t,e){if(Array.isArray(t))return!1;const i=typeof t;return!("number"!==i&&"symbol"!==i&&"boolean"!==i&&t&&!N(t))||S.test(t)||!O.test(t)||null!=e&&t in Object(e)}(t,e)?[t]:function(t){const e=[];return t.charCodeAt(0)===v&&e.push(""),t.replace(I,(function(t,i,o,n){let r=t;o?r=n.replace(w,"$1"):i&&(r=i.trim()),e.push(r)})),e}(t)}(e,t)).length;for(;null!=t&&i<o;)t=t[E(e[i++])];return i&&i===o?t:void 0},A=function(t){if(null==t)return[void 0,void 0];if("object"!=typeof t)return[Error('Invalid option "columns": expect an array or an object')];if(Array.isArray(t)){const e=[];for(const i of t)if("string"==typeof i)e.push({key:i,header:i});else{if("object"!=typeof i||null===i||Array.isArray(i))return[Error("Invalid column definition: expect a string or an object")];if(!i.key)return[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(const i in t)e.push({key:i,header:t[i]});t=e}return[void 0,t]},B=function(t){const e={};for(const o in t)e[(i=o,i.replace(/([A-Z])/g,(function(t,e){return"_"+e.toLowerCase()})))]=t[o];var i;if(void 0===e.bom||null===e.bom||!1===e.bom)e.bom=!1;else if(!0!==e.bom)return[new b("CSV_OPTION_BOOLEAN_INVALID_TYPE",["option `bom` is optional and must be a boolean value,",`got ${JSON.stringify(e.bom)}`])];if(void 0===e.delimiter||null===e.delimiter)e.delimiter=",";else if(Buffer.isBuffer(e.delimiter))e.delimiter=e.delimiter.toString();else if("string"!=typeof e.delimiter)return[new b("CSV_OPTION_DELIMITER_INVALID_TYPE",["option `delimiter` must be a buffer or a string,",`got ${JSON.stringify(e.delimiter)}`])];if(void 0===e.quote||null===e.quote)e.quote='"';else if(!0===e.quote)e.quote='"';else if(!1===e.quote)e.quote="";else if(Buffer.isBuffer(e.quote))e.quote=e.quote.toString();else if("string"!=typeof e.quote)return[new b("CSV_OPTION_QUOTE_INVALID_TYPE",["option `quote` must be a boolean, a buffer or a string,",`got ${JSON.stringify(e.quote)}`])];if(void 0!==e.quoted&&null!==e.quoted||(e.quoted=!1),void 0===e.escape_formulas||null===e.escape_formulas)e.escape_formulas=!1;else if("boolean"!=typeof e.escape_formulas)return[new b("CSV_OPTION_ESCAPE_FORMULAS_INVALID_TYPE",["option `escape_formulas` must be a boolean,",`got ${JSON.stringify(e.escape_formulas)}`])];if(void 0!==e.quoted_empty&&null!==e.quoted_empty||(e.quoted_empty=void 0),void 0===e.quoted_match||null===e.quoted_match||!1===e.quoted_match?e.quoted_match=null:Array.isArray(e.quoted_match)||(e.quoted_match=[e.quoted_match]),e.quoted_match)for(const t of e.quoted_match){const e=t instanceof RegExp;if("string"!=typeof t&&!e)return[Error(`Invalid Option: quoted_match must be a string or a regex, got ${JSON.stringify(t)}`)]}if(void 0!==e.quoted_string&&null!==e.quoted_string||(e.quoted_string=!1),void 0!==e.eof&&null!==e.eof||(e.eof=!0),void 0===e.escape||null===e.escape)e.escape='"';else if(Buffer.isBuffer(e.escape))e.escape=e.escape.toString();else if("string"!=typeof e.escape)return[Error(`Invalid Option: escape must be a buffer or a string, got ${JSON.stringify(e.escape)}`)];if(e.escape.length>1)return[Error(`Invalid Option: escape must be one character, got ${e.escape.length} characters`)];void 0!==e.header&&null!==e.header||(e.header=!1);const[o,n]=A(e.columns);if(void 0!==o)return[o];if(e.columns=n,void 0!==e.quoted&&null!==e.quoted||(e.quoted=!1),void 0!==e.cast&&null!==e.cast||(e.cast={}),void 0!==e.cast.bigint&&null!==e.cast.bigint||(e.cast.bigint=t=>""+t),void 0!==e.cast.boolean&&null!==e.cast.boolean||(e.cast.boolean=t=>t?"1":""),void 0!==e.cast.date&&null!==e.cast.date||(e.cast.date=t=>""+t.getTime()),void 0!==e.cast.number&&null!==e.cast.number||(e.cast.number=t=>""+t),void 0!==e.cast.object&&null!==e.cast.object||(e.cast.object=t=>JSON.stringify(t)),void 0!==e.cast.string&&null!==e.cast.string||(e.cast.string=function(t){return t}),void 0!==e.on_record&&"function"!=typeof e.on_record)return[Error('Invalid Option: "on_record" must be a function.')];if(void 0===e.record_delimiter||null===e.record_delimiter)e.record_delimiter="\n";else if(Buffer.isBuffer(e.record_delimiter))e.record_delimiter=e.record_delimiter.toString();else if("string"!=typeof e.record_delimiter)return[Error(`Invalid Option: record_delimiter must be a buffer or a string, got ${JSON.stringify(e.record_delimiter)}`)];switch(e.record_delimiter){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"}return[void 0,e]},D=Buffer.from([239,187,191]);class q extends o.Transform{constructor(t={}){super({writableObjectMode:!0,...t});const[e,i]=B(t);if(void 0!==e)throw e;this.options=i,this.state={stop:!1},this.info={records:0},this.api=function(t,e,i){return{options:t,state:e,info:i,__transform:function(t,e){if(!Array.isArray(t)&&"object"!=typeof t)return 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&&void 0===this.options.columns)return Error("Undiscoverable Columns: header option requires column option or object records")}else if(void 0===this.options.columns){const[e,i]=A(Object.keys(t));if(e)return;this.options.columns=i}if(0===this.info.records){this.bom(e);const t=this.headers(e);if(t)return t}try{this.options.on_record&&this.options.on_record(t,this.info.records)}catch(i){return i}let i,o;if(this.options.eof){if([i,o]=this.stringify(t),i)return i;if(void 0===o)return;o+=this.options.record_delimiter}else{if([i,o]=this.stringify(t),i)return i;if(void 0===o)return;(this.options.header||this.info.records)&&(o=this.options.record_delimiter+o)}this.info.records++,e(o)},stringify:function(t,e=!1){if("object"!=typeof t)return[void 0,t];const{columns:i}=this.options,o=[];if(Array.isArray(t)){i&&t.splice(i.length);for(let i=0;i<t.length;i++){const n=t[i],[r,s]=this.__cast(n,{index:i,column:i,records:this.info.records,header:e});if(r)return[r];o[i]=[s,n]}}else for(let n=0;n<i.length;n++){const r=x(t,i[n].key),[s,l]=this.__cast(r,{index:n,column:i[n].key,records:this.info.records,header:e});if(s)return[s];o[n]=[l,r]}let n="";for(let t=0;t<o.length;t++){let e,i,[r,s]=o[t];if("string"==typeof r)e=this.options;else if(y(r)){if(e=r,r=e.value,delete e.value,"string"!=typeof r&&null!=r&&i)return[Error(`Invalid Casting Value: returned value must return a string, null or undefined, got ${JSON.stringify(r)}`)];if(e={...this.options,...e},[i,e]=B(e),void 0!==i)return[i]}else{if(null!=r)return[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:f,quoted:u,quoted_empty:c,quoted_string:d,quoted_match:h,record_delimiter:_,escape_formulas:m}=e;if(""===r&&""===s){let t=h&&h.filter((t=>"string"==typeof t?-1!==r.indexOf(t):t.test(r)));t=t&&t.length>0,!0===(t||!0===c||!0===d&&!1!==c)&&(r=f+r+f),n+=r}else if(r){if("string"!=typeof r)return[Error(`Formatter must return a string, null or undefined, got ${JSON.stringify(r)}`)];const t=l.length&&r.indexOf(l)>=0,e=""!==f&&r.indexOf(f)>=0,i=r.indexOf(a)>=0&&a!==f,o=r.indexOf(_)>=0,c=d&&"string"==typeof s;let p=h&&h.filter((t=>"string"==typeof t?-1!==r.indexOf(t):t.test(r)));if(p=p&&p.length>0,m)switch(r[0]){case"=":case"+":case"-":case"@":case"\t":case"\r":case"=":case"+":case"-":case"@":r=`'${r}`}const g=!0===e||t||o||u||c||p;if(!0===g&&!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(f,"g");r=r.replace(t,a+f)}!0===g&&(r=f+r+f),n+=r}else(!0===c||""===s&&!0===d&&!1!==c)&&(n+=f+f);t!==o.length-1&&(n+=l)}return[void 0,n]},bom:function(t){!0===this.options.bom&&t(D)},headers:function(t){if(!1===this.options.header)return;if(void 0===this.options.columns)return;let e,i=this.options.columns.map((t=>t.header));if(this.options.eof?([e,i]=this.stringify(i,!0),i+=this.options.record_delimiter):[e,i]=this.stringify(i),e)return e;t(i)},__cast:function(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]}}}}(this.options,this.state,this.info),this.api.options.on_record=(...t)=>{this.emit("record",...t)}}_transform(t,e,i){if(!0===this.state.stop)return;const o=this.api.__transform(t,this.push.bind(this));void 0!==o&&(this.state.stop=!0),i(o)}_flush(t){if(!0!==this.state.stop){if(0===this.info.records){this.api.bom(this.push.bind(this));const e=this.api.headers(this.push.bind(this));e&&t(e)}t()}}}e.generate=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 l(t);if(e){const t=[];i.on("readable",(function(){let e;for(;null!==(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},e.parse=function(){let t,e,i;for(const o in arguments){const n=arguments[o],r=typeof n;if(void 0!==t||"string"!=typeof n&&!Buffer.isBuffer(n))if(void 0===e&&a(n))e=n;else{if(void 0!==i||"function"!==r)throw new f("CSV_INVALID_ARGUMENT",["Invalid argument:",`got ${JSON.stringify(n)} at index ${o}`],e||{});i=n}else t=n}const o=new p(e);if(i){const t=void 0===e||void 0===e.objname?[]:{};o.on("readable",(function(){let i;for(;null!==(i=this.read());)void 0===e||void 0===e.objname?t.push(i):t[i[0]]=i[1]})),o.on("error",(function(t){i(t,void 0,o.api.__infoDataSet())})),o.on("end",(function(){i(void 0,t,o.api.__infoDataSet())}))}if(void 0!==t){const e=function(){o.write(t),o.end()};"function"==typeof setImmediate?setImmediate(e):setTimeout(e,0)}return o},e.stringify=function(){let t,e,i;for(const o in arguments){const n=arguments[o],r=typeof n;if(void 0===t&&Array.isArray(n))t=n;else if(void 0===e&&y(n))e=n;else{if(void 0!==i||"function"!==r)throw new b("CSV_INVALID_ARGUMENT",["Invalid argument:",`got ${JSON.stringify(n)} at index ${o}`]);i=n}}const o=new q(e);if(i){const t=[];o.on("readable",(function(){let e;for(;null!==(e=this.read());)t.push(e)})),o.on("error",(function(t){i(t)})),o.on("end",(function(){try{i(void 0,t.join(""))}catch(t){return void i(t)}}))}if(void 0!==t){const e=function(){for(const e of t)o.write(e);o.end()};"function"==typeof setImmediate?setImmediate(e):setTimeout(e,0)}return o},e.transform=function(){let t,e,i,o={};for(let n=0;n<arguments.length;n++){const r=arguments[n];let s=typeof r;if(null===r?s="null":"object"===s&&Array.isArray(r)&&(s="array"),"array"===s)i=r;else if("object"===s)o={...r};else if("function"===s)e&&n===arguments.length-1?t=r:e=r;else if("null"!==s)throw new Error(`Invalid Arguments: got ${JSON.stringify(r)} at position ${n}`)}const n=new g(o,e);let r=!1;if(i){const t=function(){for(const t of i){if(r)break;n.write(t)}n.end()};"function"==typeof setImmediate?setImmediate(t):setTimeout(t,0)}if(t||o.consume){const e=[];n.on("readable",(function(){let i;for(;null!==(i=n.read());)t&&e.push(i)})),n.on("error",(function(e){r=!0,t&&t(e)})),n.on("end",(function(){t&&!r&&t(null,e)}))}return n}}},e={},i=function i(o){var n=e[o];if(void 0!==n)return n.exports;var r=e[o]={exports:{}};return t[o](r,r.exports,i),r.exports}(237);module.exports=i})();
1
+ (()=>{var t={237:(t,e,i)=>{const o=i(514);t.exports={packageName:"dbgate-plugin-dbf",shellApi:{reader:o},initialize(t){o.initialize(t)}}},514:(t,e,i)=>{i(825),i(836),i(896);const o=i(203),{DBFFile:n}=i(726),{getLogger:r,extractErrorLogData:s}=global.DBGATE_PACKAGES["dbgate-tools"],l=r("dbfReader");let a;function f(t){const{type:e,size:i}=t;switch(e){case"C":return`varchar(${i})`;case"N":return"numeric";case"F":return"float";case"Y":return"money";case"I":return"int";case"L":return"boolean";case"D":return"date";case"T":return"datetime";case"B":return"duouble";case"M":return"varchar(max)";default:return"string"}}async function u({fileName:t,encoding:e="ISO-8859-1",includeDeletedRecords:i=!1,limitRows:r}){console.log(`Reading file ${t}`);const u=await a.download(t),c=new o.PassThrough({objectMode:!0});return(async()=>{try{const t=await n.open(u,{encoding:e,includeDeletedRecords:i}),o=t.fields.map((t=>({columnName:t.name,dataType:f(t)})));c.write({__isStreamHeader:!0,columns:o});let s=0;for await(const e of t)if(c.write(e),s++,r&&s>=r)break;c.end()}catch(t){l.error(s(t),"DBGM-00187 Error reading DBF file"),c.end()}})(),c}u.initialize=t=>{a=t.dbgateApi},t.exports=u},726:t=>{"use strict";t.exports=require("dbffile")},825:t=>{"use strict";t.exports=require("lodash")},896:t=>{"use strict";t.exports=require("fs")},203:t=>{"use strict";t.exports=require("stream")},23:t=>{"use strict";t.exports=require("util")},836:(t,e,i)=>{"use strict";var o=i(203),n=i(23);const r=function(t={}){return t.seed?t.seed=t.seed*Math.PI*100%100/100:Math.random()},s={ascii:function({options:t}){const e=[],i=Math.ceil(r(t)*t.maxWordLength);for(let o=0;o<i;o++){const i=Math.floor(32*r(t));e.push(String.fromCharCode(i+(i<16?65:81)))}return e.join("")},int:function({options:t}){return Math.floor(r(t)*Math.pow(2,52))},bool:function({options:t}){return Math.floor(2*r(t))}},l=function(t={}){return this.options=(t=>{t.object_mode&&(t.objectMode=t.object_mode),t.high_water_mark&&(t.highWaterMark=t.high_water_mark);const e={};for(const o in t)e[(i=o,i.replace(/_([a-z])/gi,(function(t,e){return e.toUpperCase()})))]=t[o];var i;const o={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 o)void 0===e[t]&&(e[t]=o[t]);!0===e.eof&&(e.eof=e.rowDelimiter),"number"==typeof e.columns&&(e.columns=new Array(e.columns));const n=Object.keys(s).filter((t=>!["super_","camelize"].includes(t)));for(let t=0;t<e.columns.length;t++){const i=e.columns[t]||"ascii";if("string"==typeof i){if(!n.includes(i))throw Error(`Invalid column type: got "${i}", default values are ${JSON.stringify(n)}`);e.columns[t]=s[i]}}return e})(t),o.Readable.call(this,this.options),this.state=(t=>({start_time:this.options.duration?Date.now():null,fixed_size_buffer:"",count_written:0,count_created:0}))(),this};n.inherits(l,o.Readable),l.prototype.end=function(){this.push(null)},l.prototype._read=function(t){setImmediate((()=>{this.__read(t)}))},l.prototype.__read=function(t){((t,e,i,o,n)=>{const r=[];let s=0;for(t.fixedSize&&(s=e.fixed_size_buffer.length,0!==s&&r.push(e.fixed_size_buffer));;){if(e.count_created===t.length||t.end&&Date.now()>t.end||t.duration&&Date.now()>e.start_time+t.duration){if(r.length){if(t.objectMode)for(const t of r)o(t);else o(r.join("")+(t.eof?t.eof:""));e.end=!0}else n();return}let l,a=[];for(const i of t.columns){const o=i({options:t,state:e}),r=typeof o;if(null!==o&&"string"!==r&&"number"!==r)return void n(Error(["INVALID_VALUE:","values returned by column function must be","a string, a number or null,",`got ${JSON.stringify(o)}`].join(" ")));a.push(o)}if(t.objectMode){l=0;for(const t of a)l+=t.length}else a=(0===e.count_created?"":t.rowDelimiter)+a.join(t.delimiter),l=a.length;if(e.count_created++,s+l>i){if(t.objectMode){r.push(a);for(const t of r)o(t)}else t.fixedSize?(e.fixed_size_buffer=a.substr(i-s),r.push(a.substr(0,i-s))):r.push(a),o(r.join(""));return}s+=l,r.push(a)}})(this.options,this.state,t,(t=>{this.__push(t)}),(t=>{t?this.destroy(t):this.push(null)}))},l.prototype.__push=function(t){const e=()=>{if(this.state.count_written++,this.push(t),!0===this.state.end)return this.push(null)};this.options.sleep>0?setTimeout(e,this.options.sleep):e()};const a=function(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)};let f=class t extends Error{constructor(e,i,o,...n){Array.isArray(i)&&(i=i.join(" ").trim()),super(i),void 0!==Error.captureStackTrace&&Error.captureStackTrace(this,t),this.code=e;for(const t of n)for(const e in t){const i=t[e];this[e]=Buffer.isBuffer(i)?i.toString(o.encoding):null==i?i:JSON.parse(JSON.stringify(i))}}};const u=function(t){const e=[];for(let i=0,o=t.length;i<o;i++){const o=t[i];if(null==o||!1===o)e[i]={disabled:!0};else if("string"==typeof o)e[i]={name:o};else{if(!a(o))throw new f("CSV_INVALID_COLUMN_DEFINITION",["Invalid column definition:","expect a string or a literal object,",`got ${JSON.stringify(o)} at position ${i}`]);if("string"!=typeof o.name)throw new f("CSV_OPTION_COLUMNS_MISSING_NAME",["Option columns missing name:",`property "name" is required at position ${i}`,"when column is an object literal"]);e[i]=o}}return e};class c{constructor(t=100){this.size=t,this.length=0,this.buf=Buffer.allocUnsafe(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.allocUnsafe(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.allocUnsafe(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}}const d=function(t){return{bomSkipped:!1,bufBytesStart:0,castField:t.cast_function,commenting:!1,error:void 0,enabled:1===t.from_line,escaping:!1,escapeIsQuote:Buffer.isBuffer(t.escape)&&Buffer.isBuffer(t.quote)&&0===Buffer.compare(t.escape,t.quote),expectedRecordLength:Array.isArray(t.columns)?t.columns.length:void 0,field:new c(20),firstLineToHeaders:t.cast_first_line_to_header,needMoreDataSize:Math.max(null!==t.comment?t.comment.length:0,...t.delimiter.map((t=>t.length)),null!==t.quote?t.quote.length:0),previousBuf:void 0,quoting:!1,stop:!1,rawBuffer:new c(100),record:[],recordHasError:!1,record_length:0,recordDelimiterMaxLength:0===t.record_delimiter.length?0:Math.max(...t.record_delimiter.map((t=>t.length))),trimChars:[Buffer.from(" ",t.encoding)[0],Buffer.from("\t",t.encoding)[0]],wasQuoting:!1,wasRowDelimiter:!1,timchars:[Buffer.from(Buffer.from([13],"utf8").toString(),t.encoding),Buffer.from(Buffer.from([10],"utf8").toString(),t.encoding),Buffer.from(Buffer.from([12],"utf8").toString(),t.encoding),Buffer.from(Buffer.from([32],"utf8").toString(),t.encoding),Buffer.from(Buffer.from([9],"utf8").toString(),t.encoding)]}},h=function(t){const e={};for(const o in t)e[(i=o,i.replace(/([A-Z])/g,(function(t,e){return"_"+e.toLowerCase()})))]=t[o];var 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 f("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 f("CSV_INVALID_OPTION_BOM",["Invalid option bom:","bom must be true,",`got ${JSON.stringify(e.bom)}`],e);if(e.cast_function=null,void 0===e.cast||null===e.cast||!1===e.cast||""===e.cast)e.cast=void 0;else if("function"==typeof e.cast)e.cast_function=e.cast,e.cast=!0;else if(!0!==e.cast)throw new f("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 f("CSV_INVALID_OPTION_CAST_DATE",["Invalid option cast_date:","cast_date must be true or a function,",`got ${JSON.stringify(e.cast_date)}`],e);if(e.cast_first_line_to_header=null,!0===e.columns)e.cast_first_line_to_header=void 0;else if("function"==typeof e.columns)e.cast_first_line_to_header=e.columns,e.columns=!0;else if(Array.isArray(e.columns))e.columns=u(e.columns);else{if(void 0!==e.columns&&null!==e.columns&&!1!==e.columns)throw new f("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.group_columns_by_name||null===e.group_columns_by_name||!1===e.group_columns_by_name)e.group_columns_by_name=!1;else{if(!0!==e.group_columns_by_name)throw new f("CSV_INVALID_OPTION_GROUP_COLUMNS_BY_NAME",["Invalid option group_columns_by_name:","expect an boolean,",`got ${JSON.stringify(e.group_columns_by_name)}`],e);if(!1===e.columns)throw new f("CSV_INVALID_OPTION_GROUP_COLUMNS_BY_NAME",["Invalid option group_columns_by_name:","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 f("CSV_INVALID_OPTION_COMMENT",["Invalid option comment:","comment must be a buffer or a string,",`got ${JSON.stringify(e.comment)}`],e);if(void 0===e.comment_no_infix||null===e.comment_no_infix||!1===e.comment_no_infix)e.comment_no_infix=!1;else if(!0!==e.comment_no_infix)throw new f("CSV_INVALID_OPTION_COMMENT",["Invalid option comment_no_infix:","value must be a boolean,",`got ${JSON.stringify(e.comment_no_infix)}`],e);const o=JSON.stringify(e.delimiter);if(Array.isArray(e.delimiter)||(e.delimiter=[e.delimiter]),0===e.delimiter.length)throw new f("CSV_INVALID_OPTION_DELIMITER",["Invalid option delimiter:","delimiter must be a non empty string or buffer or array of string|buffer,",`got ${o}`],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 f("CSV_INVALID_OPTION_DELIMITER",["Invalid option delimiter:","delimiter must be a non empty string or buffer or array of string|buffer,",`got ${o}`],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 f("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 f("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){if(0===e.objname.length)throw new Error("Invalid Option: objname must be a non empty string")}else if("number"!=typeof e.objname)throw new Error(`Invalid Option: objname must be a string or a buffer, got ${e.objname}`);if(void 0!==e.objname)if("number"==typeof e.objname){if(!1!==e.columns)throw Error("Invalid Option: objname index cannot be combined with columns or be defined as a field")}else if(!1===e.columns)throw Error("Invalid Option: objname field must be combined with columns or be defined as an index");if(void 0===e.on_record||null===e.on_record)e.on_record=void 0;else if("function"!=typeof e.on_record)throw new f("CSV_INVALID_OPTION_ON_RECORD",["Invalid option `on_record`:","expect a function,",`got ${JSON.stringify(e.on_record)}`],e);if(void 0!==e.on_skip&&null!==e.on_skip&&"function"!=typeof e.on_skip)throw new Error(`Invalid Option: on_skip must be a function, got ${JSON.stringify(e.on_skip)}`);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(void 0===e.record_delimiter)e.record_delimiter=[];else if("string"==typeof e.record_delimiter||Buffer.isBuffer(e.record_delimiter)){if(0===e.record_delimiter.length)throw new f("CSV_INVALID_OPTION_RECORD_DELIMITER",["Invalid option `record_delimiter`:","value must be a non empty string or buffer,",`got ${JSON.stringify(e.record_delimiter)}`],e);e.record_delimiter=[e.record_delimiter]}else if(!Array.isArray(e.record_delimiter))throw new f("CSV_INVALID_OPTION_RECORD_DELIMITER",["Invalid option `record_delimiter`:","value must be a string, a buffer or array of string|buffer,",`got ${JSON.stringify(e.record_delimiter)}`],e);if(e.record_delimiter=e.record_delimiter.map((function(t,i){if("string"!=typeof t&&!Buffer.isBuffer(t))throw new f("CSV_INVALID_OPTION_RECORD_DELIMITER",["Invalid option `record_delimiter`:","value must be a string, a buffer or array of string|buffer",`at index ${i},`,`got ${JSON.stringify(t)}`],e);if(0===t.length)throw new f("CSV_INVALID_OPTION_RECORD_DELIMITER",["Invalid option `record_delimiter`:","value must be a non empty string or buffer",`at index ${i},`,`got ${JSON.stringify(t)}`],e);return"string"==typeof t&&(t=Buffer.from(t,e.encoding)),t})),"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.relax_quotes);else{if(void 0!==e.relax_quotes&&null!==e.relax_quotes)throw new Error(`Invalid Option: relax_quotes must be a boolean, got ${JSON.stringify(e.relax_quotes)}`);e.relax_quotes=!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_records_with_empty_values);else{if(void 0!==e.skip_records_with_empty_values&&null!==e.skip_records_with_empty_values)throw new Error(`Invalid Option: skip_records_with_empty_values must be a boolean, got ${JSON.stringify(e.skip_records_with_empty_values)}`);e.skip_records_with_empty_values=!1}if("boolean"==typeof e.skip_records_with_error);else{if(void 0!==e.skip_records_with_error&&null!==e.skip_records_with_error)throw new Error(`Invalid Option: skip_records_with_error must be a boolean, got ${JSON.stringify(e.skip_records_with_error)}`);e.skip_records_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)}`)}return e},_=function(t){return t.every((t=>null==t||t.toString&&""===t.toString().trim()))},m={utf8:Buffer.from([239,187,191]),utf16le:Buffer.from([255,254])};class p extends o.Transform{constructor(t={}){super({readableObjectMode:!0,...t,encoding:null}),this.api=function(t={}){const e=h(t);return{info:{bytes:0,comment_lines:0,empty_lines:0,invalid_field_length:0,lines:1,records:0},original_options:t,options:e,state:d(e),__needMoreData:function(t,e,i){if(i)return!1;const{encoding:o,escape:n,quote:r}=this.options,{quoting:s,needMoreDataSize:l,recordDelimiterMaxLength:a}=this.state;return e-t-1<Math.max(l,0===a?Buffer.from("\r\n",o).length:a,s?(null===n?0:n.length)+r.length:0,s?r.length+a:0)},parse:function(t,e,i,o){const{bom:n,comment_no_infix:r,encoding:s,from_line:l,ltrim:a,max_record_size:u,raw:c,relax_quotes:d,rtrim:_,skip_empty_lines:p,to:g,to_line:b}=this.options;let{comment:y,escape:v,quote:w,record_delimiter:I}=this.options;const{bomSkipped:O,previousBuf:S,rawBuffer:N,escapeIsQuote:E}=this.state;let x;if(void 0===S){if(void 0===t)return void o();x=t}else x=void 0!==S&&void 0===t?S:Buffer.concat([S,t]);if(!1===O)if(!1===n)this.state.bomSkipped=!0;else if(x.length<3){if(!1===e)return void(this.state.previousBuf=x)}else{for(const t in m)if(0===m[t].compare(x,0,m[t].length)){const e=m[t].length;this.state.bufBytesStart+=e,x=x.slice(e),this.options=h({...this.original_options,encoding:t}),({comment:y,escape:v,quote:w}=this.options);break}this.state.bomSkipped=!0}const A=x.length;let B;for(B=0;B<A&&!this.__needMoreData(B,A,e);B++){if(!0===this.state.wasRowDelimiter&&(this.info.lines++,this.state.wasRowDelimiter=!1),-1!==b&&this.info.lines>b)return this.state.stop=!0,void o();!1===this.state.quoting&&0===I.length&&this.__autoDiscoverRecordDelimiter(x,B)&&(I=this.options.record_delimiter);const t=x[B];if(!0===c&&N.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!==v&&!0===this.state.quoting&&this.__isEscape(x,B,t)&&B+v.length<A){if(!E){this.state.escaping=!0,B+=v.length-1;continue}if(this.__isQuote(x,B+v.length)){this.state.escaping=!0,B+=v.length-1;continue}}if(!1===this.state.commenting&&this.__isQuote(x,B))if(!0===this.state.quoting){const e=x[B+w.length],i=_&&this.__isCharTrimable(x,B+w.length),o=null!==y&&this.__compareBytes(y,x,B+w.length,e),n=this.__isDelimiter(x,B+w.length,e),r=0===I.length?this.__autoDiscoverRecordDelimiter(x,B+w.length):this.__isRecordDelimiter(e,x,B+w.length);if(null!==v&&this.__isEscape(x,B,t)&&this.__isQuote(x,B+v.length))B+=v.length-1;else{if(!e||n||r||o||i){this.state.quoting=!1,this.state.wasQuoting=!0,B+=w.length-1;continue}if(!1===d){const t=this.__error(new f("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(w),B+=w.length-1}}else{if(0===this.state.field.length){this.state.quoting=!0,B+=w.length-1;continue}if(!1===d){const t=this.__infoField(),e=Object.keys(m).map((t=>!!m[t].equals(this.state.field.toString())&&t)).filter(Boolean)[0],i=this.__error(new f("INVALID_OPENING_QUOTE",["Invalid Opening Quote:",`a quote is found on field ${JSON.stringify(t.column)} at line ${t.lines}, value is ${JSON.stringify(this.state.field.toString(s))}`,e?`(${e} bom)`:void 0],this.options,t,{field:this.state.field}));if(void 0!==i)return i}}if(!1===this.state.quoting){const e=this.__isRecordDelimiter(t,x,B);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)>=l){this.state.enabled=!0,this.__resetField(),this.__resetRecord(),B+=e-1;continue}if(!0===p&&!1===this.state.wasQuoting&&0===this.state.record.length&&0===this.state.field.length){this.info.empty_lines++,B+=e-1;continue}this.info.bytes=this.state.bufBytesStart+B;const t=this.__onField();if(void 0!==t)return t;this.info.bytes=this.state.bufBytesStart+B+e;const n=this.__onRecord(i);if(void 0!==n)return n;if(-1!==g&&this.info.records>=g)return this.state.stop=!0,void o()}this.state.commenting=!1,B+=e-1;continue}if(this.state.commenting)continue;if(null!==y&&(!1===r||0===this.state.record.length&&0===this.state.field.length)&&0!==this.__compareBytes(y,x,B,t)){this.state.commenting=!0;continue}const n=this.__isDelimiter(x,B,t);if(0!==n){this.info.bytes=this.state.bufBytesStart+B;const t=this.__onField();if(void 0!==t)return t;B+=n-1;continue}}}if(!1===this.state.commenting&&0!==u&&this.state.record_length+this.state.field.length>u)return this.__error(new f("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()));const e=!1===a||!0===this.state.quoting||0!==this.state.field.length||!this.__isCharTrimable(x,B),n=!1===_||!1===this.state.wasQuoting;if(!0!==e||!0!==n){if(!0!==_||this.__isCharTrimable(x,B)){!1===e&&(B+=this.__isCharTrimable(x,B)-1);continue}return this.__error(new f("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()))}this.state.field.append(t)}if(!0===e)if(!0===this.state.quoting){const t=this.__error(new f("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+B;const t=this.__onField();if(void 0!==t)return t;const e=this.__onRecord(i);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+=B,this.state.previousBuf=x.slice(B);!0===this.state.wasRowDelimiter&&(this.info.lines++,this.state.wasRowDelimiter=!1)},__onRecord:function(t){const{columns:e,group_columns_by_name:i,encoding:o,info:n,from:r,relax_column_count:s,relax_column_count_less:l,relax_column_count_more:a,raw:u,skip_records_with_empty_values:c}=this.options,{enabled:d,record:h}=this.state;if(!1===d)return this.__resetRecord();const m=h.length;if(!0===e)return!0===c&&_(h)?void this.__resetRecord():this.__firstLineToColumns(h);if(!1===e&&0===this.info.records&&(this.state.expectedRecordLength=m),m!==this.state.expectedRecordLength){const t=!1===e?new f("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH",["Invalid Record Length:",`expect ${this.state.expectedRecordLength},`,`got ${m} on line ${this.info.lines}`],this.options,this.__infoField(),{record:h}):new f("CSV_RECORD_INCONSISTENT_COLUMNS",["Invalid Record Length:",`columns length is ${e.length},`,`got ${m} on line ${this.info.lines}`],this.options,this.__infoField(),{record:h});if(!0===s||!0===l&&m<this.state.expectedRecordLength||!0===a&&m>this.state.expectedRecordLength)this.info.invalid_field_length++,this.state.error=t;else{const e=this.__error(t);if(e)return e}}if(!0===c&&_(h))this.__resetRecord();else{if(!0===this.state.recordHasError)return this.__resetRecord(),void(this.state.recordHasError=!1);if(this.info.records++,1===r||this.info.records>=r){const{objname:r}=this.options;if(!1!==e){const s={};for(let t=0,o=h.length;t<o;t++)void 0===e[t]||e[t].disabled||(!0===i&&void 0!==s[e[t].name]?Array.isArray(s[e[t].name])?s[e[t].name]=s[e[t].name].concat(h[t]):s[e[t].name]=[s[e[t].name],h[t]]:s[e[t].name]=h[t]);if(!0===u||!0===n){const e=Object.assign({record:s},!0===u?{raw:this.state.rawBuffer.toString(o)}:{},!0===n?{info:this.__infoRecord()}:{}),i=this.__push(void 0===r?e:[s[r],e],t);if(i)return i}else{const e=this.__push(void 0===r?s:[s[r],s],t);if(e)return e}}else if(!0===u||!0===n){const e=Object.assign({record:h},!0===u?{raw:this.state.rawBuffer.toString(o)}:{},!0===n?{info:this.__infoRecord()}:{}),i=this.__push(void 0===r?e:[h[r],e],t);if(i)return i}else{const e=this.__push(void 0===r?h:[h[r],h],t);if(e)return e}}this.__resetRecord()}},__firstLineToColumns:function(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 f("CSV_INVALID_COLUMN_MAPPING",["Invalid Column Mapping:","expect an array from column function,",`got ${JSON.stringify(i)}`],this.options,this.__infoField(),{headers:i}));const o=u(i);return this.state.expectedRecordLength=o.length,this.options.columns=o,void this.__resetRecord()}catch(t){return t}},__resetRecord:function(){!0===this.options.raw&&this.state.rawBuffer.reset(),this.state.error=void 0,this.state.record=[],this.state.record_length=0},__onField:function(){const{cast:t,encoding:e,rtrim:i,max_record_size:o}=this.options,{enabled:n,wasQuoting:r}=this.state;if(!1===n)return this.__resetField();let s=this.state.field.toString(e);if(!0===i&&!1===r&&(s=s.trimRight()),!0===t){const[t,e]=this.__cast(s);if(void 0!==t)return t;s=e}this.state.record.push(s),0!==o&&"string"==typeof s&&(this.state.record_length+=s.length),this.__resetField()},__resetField:function(){this.state.field.reset(),this.state.wasQuoting=!1},__push:function(t,e){const{on_record:i}=this.options;if(void 0!==i){const e=this.__infoRecord();try{t=i.call(null,t,e)}catch(t){return t}if(null==t)return}e(t)},__cast:function(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:function(t,e){return((t,e)=>{const{timchars:i}=this.state;t:for(let o=0;o<i.length;o++){const n=i[o];for(let i=0;i<n.length;i++)if(n[i]!==t[e+i])continue t;return n.length}return 0})(t,e)},__isFloat:function(t){return t-parseFloat(t)+1>=0},__compareBytes:function(t,e,i,o){if(t[0]!==o)return 0;const n=t.length;for(let o=1;o<n;o++)if(t[o]!==e[i+o])return 0;return n},__isDelimiter:function(t,e,i){const{delimiter:o,ignore_last_delimiters:n}=this.options;if(!0===n&&this.state.record.length===this.options.columns.length-1)return 0;if(!1!==n&&"number"==typeof n&&this.state.record.length===n-1)return 0;t:for(let n=0;n<o.length;n++){const r=o[n];if(r[0]===i){for(let i=1;i<r.length;i++)if(r[i]!==t[e+i])continue t;return r.length}}return 0},__isRecordDelimiter:function(t,e,i){const{record_delimiter:o}=this.options,n=o.length;t:for(let r=0;r<n;r++){const n=o[r],s=n.length;if(n[0]===t){for(let t=1;t<s;t++)if(n[t]!==e[i+t])continue t;return n.length}}return 0},__isEscape:function(t,e,i){const{escape:o}=this.options;if(null===o)return!1;const n=o.length;if(o[0]===i){for(let i=0;i<n;i++)if(o[i]!==t[e+i])return!1;return!0}return!1},__isQuote:function(t,e){const{quote:i}=this.options;if(null===i)return!1;const o=i.length;for(let n=0;n<o;n++)if(i[n]!==t[e+n])return!1;return!0},__autoDiscoverRecordDelimiter:function(t,e){const{encoding:i}=this.options,o=[Buffer.from("\r\n",i),Buffer.from("\n",i),Buffer.from("\r",i)];t:for(let i=0;i<o.length;i++){const n=o[i].length;for(let r=0;r<n;r++)if(o[i][r]!==t[e+r])continue t;return this.options.record_delimiter.push(o[i]),this.state.recordDelimiterMaxLength=o[i].length,o[i].length}return 0},__error:function(t){const{encoding:e,raw:i,skip_records_with_error:o}=this.options,n="string"==typeof t?new Error(t):t;return o?(this.state.recordHasError=!0,void(void 0!==this.options.on_skip&&this.options.on_skip(n,i?this.state.rawBuffer.toString(e):void 0))):n},__infoDataSet:function(){return{...this.info,columns:this.options.columns}},__infoRecord:function(){const{columns:t,raw:e,encoding:i}=this.options;return{...this.__infoDataSet(),error:this.state.error,header:!0===t,index:this.state.record.length,raw:e?this.state.rawBuffer.toString(i):void 0}},__infoField:function(){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}}}}({on_skip:(t,e)=>{this.emit("skip",t,e)},...t}),this.state=this.api.state,this.options=this.api.options,this.info=this.api.info}_transform(t,e,i){if(!0===this.state.stop)return;const o=this.api.parse(t,!1,(t=>{this.push(t)}),(()=>{this.push(null),this.end(),this.on("end",this.destroy)}));void 0!==o&&(this.state.stop=!0),i(o)}_flush(t){!0!==this.state.stop&&t(this.api.parse(void 0,!0,(t=>{this.push(t)}),(()=>{this.push(null),this.on("end",this.destroy)})))}}const g=function(t={},e){return this.options=t,void 0!==t.consume&&null!==t.consume||(this.options.consume=!1),this.options.objectMode=!0,void 0!==t.parallel&&null!==t.parallel||(this.options.parallel=100),void 0!==t.params&&null!==t.params||(t.params=null),this.handler=e,o.Transform.call(this,this.options),this.state={running:0,started:0,finished:0,paused:!1},this};n.inherits(g,o.Transform),g.prototype._transform=function(t,e,i){this.state.started++,this.state.running++,!this.state.paused&&this.state.running<this.options.parallel&&(i(),i=null);try{let e=this.handler.length;if(null!==this.options.params&&e--,1===e){const e=this.handler.call(this,t,this.options.params);e&&e.then?(e.then((t=>{this.__done(null,[t],i)})),e.catch((t=>{this.__done(t)}))):this.__done(null,[e],i)}else{if(2!==e)throw Error("Invalid handler arguments");{const e=(t,...e)=>this.__done(t,e,i);this.handler.call(this,t,e,this.options.params)}}return!1}catch(t){this.__done(t)}},g.prototype._flush=function(t){0===this.state.running?t():this._ending=function(){t()}},g.prototype.__done=function(t,e,i){if(this.state.running--,t)return this.destroy(t);this.state.finished++;for(let t of e)"number"==typeof t&&(t=`${t}`),null!=t&&""!==t&&(this.state.paused=!this.push(t));i&&i(),this._ending&&0===this.state.running&&this._ending()};class b extends Error{constructor(t,e,...i){Array.isArray(e)&&(e=e.join(" ")),super(e),void 0!==Error.captureStackTrace&&Error.captureStackTrace(this,b),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))}}}const y=function(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)},v=".".charCodeAt(0),w=/\\(\\)?/g,I=RegExp("[^.[\\]]+|\\[(?:([^\"'][^[]*)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))","g"),O=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,S=/^\w*$/,N=function(t){const e=typeof t;return"symbol"===e||"object"===e&&t&&"[object Symbol]"===function(t){return Object.prototype.toString.call(t)}(t)},E=function(t){if("string"==typeof t||N(t))return t;const e=`${t}`;return"0"==e&&1/t==-INFINITY?"-0":e},x=function(t,e){let i=0;const o=(e=function(t,e){return Array.isArray(t)?t:function(t,e){if(Array.isArray(t))return!1;const i=typeof t;return!("number"!==i&&"symbol"!==i&&"boolean"!==i&&t&&!N(t))||S.test(t)||!O.test(t)||null!=e&&t in Object(e)}(t,e)?[t]:function(t){const e=[];return t.charCodeAt(0)===v&&e.push(""),t.replace(I,(function(t,i,o,n){let r=t;o?r=n.replace(w,"$1"):i&&(r=i.trim()),e.push(r)})),e}(t)}(e,t)).length;for(;null!=t&&i<o;)t=t[E(e[i++])];return i&&i===o?t:void 0},A=function(t){if(null==t)return[void 0,void 0];if("object"!=typeof t)return[Error('Invalid option "columns": expect an array or an object')];if(Array.isArray(t)){const e=[];for(const i of t)if("string"==typeof i)e.push({key:i,header:i});else{if("object"!=typeof i||null===i||Array.isArray(i))return[Error("Invalid column definition: expect a string or an object")];if(!i.key)return[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(const i in t)e.push({key:i,header:t[i]});t=e}return[void 0,t]},B=function(t){const e={};for(const o in t)e[(i=o,i.replace(/([A-Z])/g,(function(t,e){return"_"+e.toLowerCase()})))]=t[o];var i;if(void 0===e.bom||null===e.bom||!1===e.bom)e.bom=!1;else if(!0!==e.bom)return[new b("CSV_OPTION_BOOLEAN_INVALID_TYPE",["option `bom` is optional and must be a boolean value,",`got ${JSON.stringify(e.bom)}`])];if(void 0===e.delimiter||null===e.delimiter)e.delimiter=",";else if(Buffer.isBuffer(e.delimiter))e.delimiter=e.delimiter.toString();else if("string"!=typeof e.delimiter)return[new b("CSV_OPTION_DELIMITER_INVALID_TYPE",["option `delimiter` must be a buffer or a string,",`got ${JSON.stringify(e.delimiter)}`])];if(void 0===e.quote||null===e.quote)e.quote='"';else if(!0===e.quote)e.quote='"';else if(!1===e.quote)e.quote="";else if(Buffer.isBuffer(e.quote))e.quote=e.quote.toString();else if("string"!=typeof e.quote)return[new b("CSV_OPTION_QUOTE_INVALID_TYPE",["option `quote` must be a boolean, a buffer or a string,",`got ${JSON.stringify(e.quote)}`])];if(void 0!==e.quoted&&null!==e.quoted||(e.quoted=!1),void 0===e.escape_formulas||null===e.escape_formulas)e.escape_formulas=!1;else if("boolean"!=typeof e.escape_formulas)return[new b("CSV_OPTION_ESCAPE_FORMULAS_INVALID_TYPE",["option `escape_formulas` must be a boolean,",`got ${JSON.stringify(e.escape_formulas)}`])];if(void 0!==e.quoted_empty&&null!==e.quoted_empty||(e.quoted_empty=void 0),void 0===e.quoted_match||null===e.quoted_match||!1===e.quoted_match?e.quoted_match=null:Array.isArray(e.quoted_match)||(e.quoted_match=[e.quoted_match]),e.quoted_match)for(const t of e.quoted_match){const e=t instanceof RegExp;if("string"!=typeof t&&!e)return[Error(`Invalid Option: quoted_match must be a string or a regex, got ${JSON.stringify(t)}`)]}if(void 0!==e.quoted_string&&null!==e.quoted_string||(e.quoted_string=!1),void 0!==e.eof&&null!==e.eof||(e.eof=!0),void 0===e.escape||null===e.escape)e.escape='"';else if(Buffer.isBuffer(e.escape))e.escape=e.escape.toString();else if("string"!=typeof e.escape)return[Error(`Invalid Option: escape must be a buffer or a string, got ${JSON.stringify(e.escape)}`)];if(e.escape.length>1)return[Error(`Invalid Option: escape must be one character, got ${e.escape.length} characters`)];void 0!==e.header&&null!==e.header||(e.header=!1);const[o,n]=A(e.columns);if(void 0!==o)return[o];if(e.columns=n,void 0!==e.quoted&&null!==e.quoted||(e.quoted=!1),void 0!==e.cast&&null!==e.cast||(e.cast={}),void 0!==e.cast.bigint&&null!==e.cast.bigint||(e.cast.bigint=t=>""+t),void 0!==e.cast.boolean&&null!==e.cast.boolean||(e.cast.boolean=t=>t?"1":""),void 0!==e.cast.date&&null!==e.cast.date||(e.cast.date=t=>""+t.getTime()),void 0!==e.cast.number&&null!==e.cast.number||(e.cast.number=t=>""+t),void 0!==e.cast.object&&null!==e.cast.object||(e.cast.object=t=>JSON.stringify(t)),void 0!==e.cast.string&&null!==e.cast.string||(e.cast.string=function(t){return t}),void 0!==e.on_record&&"function"!=typeof e.on_record)return[Error('Invalid Option: "on_record" must be a function.')];if(void 0===e.record_delimiter||null===e.record_delimiter)e.record_delimiter="\n";else if(Buffer.isBuffer(e.record_delimiter))e.record_delimiter=e.record_delimiter.toString();else if("string"!=typeof e.record_delimiter)return[Error(`Invalid Option: record_delimiter must be a buffer or a string, got ${JSON.stringify(e.record_delimiter)}`)];switch(e.record_delimiter){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"}return[void 0,e]},D=Buffer.from([239,187,191]);class q extends o.Transform{constructor(t={}){super({writableObjectMode:!0,...t});const[e,i]=B(t);if(void 0!==e)throw e;this.options=i,this.state={stop:!1},this.info={records:0},this.api=function(t,e,i){return{options:t,state:e,info:i,__transform:function(t,e){if(!Array.isArray(t)&&"object"!=typeof t)return 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&&void 0===this.options.columns)return Error("Undiscoverable Columns: header option requires column option or object records")}else if(void 0===this.options.columns){const[e,i]=A(Object.keys(t));if(e)return;this.options.columns=i}if(0===this.info.records){this.bom(e);const t=this.headers(e);if(t)return t}try{this.options.on_record&&this.options.on_record(t,this.info.records)}catch(i){return i}let i,o;if(this.options.eof){if([i,o]=this.stringify(t),i)return i;if(void 0===o)return;o+=this.options.record_delimiter}else{if([i,o]=this.stringify(t),i)return i;if(void 0===o)return;(this.options.header||this.info.records)&&(o=this.options.record_delimiter+o)}this.info.records++,e(o)},stringify:function(t,e=!1){if("object"!=typeof t)return[void 0,t];const{columns:i}=this.options,o=[];if(Array.isArray(t)){i&&t.splice(i.length);for(let i=0;i<t.length;i++){const n=t[i],[r,s]=this.__cast(n,{index:i,column:i,records:this.info.records,header:e});if(r)return[r];o[i]=[s,n]}}else for(let n=0;n<i.length;n++){const r=x(t,i[n].key),[s,l]=this.__cast(r,{index:n,column:i[n].key,records:this.info.records,header:e});if(s)return[s];o[n]=[l,r]}let n="";for(let t=0;t<o.length;t++){let e,i,[r,s]=o[t];if("string"==typeof r)e=this.options;else if(y(r)){if(e=r,r=e.value,delete e.value,"string"!=typeof r&&null!=r&&i)return[Error(`Invalid Casting Value: returned value must return a string, null or undefined, got ${JSON.stringify(r)}`)];if(e={...this.options,...e},[i,e]=B(e),void 0!==i)return[i]}else{if(null!=r)return[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:f,quoted:u,quoted_empty:c,quoted_string:d,quoted_match:h,record_delimiter:_,escape_formulas:m}=e;if(""===r&&""===s){let t=h&&h.filter((t=>"string"==typeof t?-1!==r.indexOf(t):t.test(r)));t=t&&t.length>0,!0===(t||!0===c||!0===d&&!1!==c)&&(r=f+r+f),n+=r}else if(r){if("string"!=typeof r)return[Error(`Formatter must return a string, null or undefined, got ${JSON.stringify(r)}`)];const t=l.length&&r.indexOf(l)>=0,e=""!==f&&r.indexOf(f)>=0,i=r.indexOf(a)>=0&&a!==f,o=r.indexOf(_)>=0,c=d&&"string"==typeof s;let p=h&&h.filter((t=>"string"==typeof t?-1!==r.indexOf(t):t.test(r)));if(p=p&&p.length>0,m)switch(r[0]){case"=":case"+":case"-":case"@":case"\t":case"\r":case"=":case"+":case"-":case"@":r=`'${r}`}const g=!0===e||t||o||u||c||p;if(!0===g&&!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(f,"g");r=r.replace(t,a+f)}!0===g&&(r=f+r+f),n+=r}else(!0===c||""===s&&!0===d&&!1!==c)&&(n+=f+f);t!==o.length-1&&(n+=l)}return[void 0,n]},bom:function(t){!0===this.options.bom&&t(D)},headers:function(t){if(!1===this.options.header)return;if(void 0===this.options.columns)return;let e,i=this.options.columns.map((t=>t.header));if(this.options.eof?([e,i]=this.stringify(i,!0),i+=this.options.record_delimiter):[e,i]=this.stringify(i),e)return e;t(i)},__cast:function(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]}}}}(this.options,this.state,this.info),this.api.options.on_record=(...t)=>{this.emit("record",...t)}}_transform(t,e,i){if(!0===this.state.stop)return;const o=this.api.__transform(t,this.push.bind(this));void 0!==o&&(this.state.stop=!0),i(o)}_flush(t){if(!0!==this.state.stop){if(0===this.info.records){this.api.bom(this.push.bind(this));const e=this.api.headers(this.push.bind(this));e&&t(e)}t()}}}e.generate=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 l(t);if(e){const t=[];i.on("readable",(function(){let e;for(;null!==(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},e.parse=function(){let t,e,i;for(const o in arguments){const n=arguments[o],r=typeof n;if(void 0!==t||"string"!=typeof n&&!Buffer.isBuffer(n))if(void 0===e&&a(n))e=n;else{if(void 0!==i||"function"!==r)throw new f("CSV_INVALID_ARGUMENT",["Invalid argument:",`got ${JSON.stringify(n)} at index ${o}`],e||{});i=n}else t=n}const o=new p(e);if(i){const t=void 0===e||void 0===e.objname?[]:{};o.on("readable",(function(){let i;for(;null!==(i=this.read());)void 0===e||void 0===e.objname?t.push(i):t[i[0]]=i[1]})),o.on("error",(function(t){i(t,void 0,o.api.__infoDataSet())})),o.on("end",(function(){i(void 0,t,o.api.__infoDataSet())}))}if(void 0!==t){const e=function(){o.write(t),o.end()};"function"==typeof setImmediate?setImmediate(e):setTimeout(e,0)}return o},e.stringify=function(){let t,e,i;for(const o in arguments){const n=arguments[o],r=typeof n;if(void 0===t&&Array.isArray(n))t=n;else if(void 0===e&&y(n))e=n;else{if(void 0!==i||"function"!==r)throw new b("CSV_INVALID_ARGUMENT",["Invalid argument:",`got ${JSON.stringify(n)} at index ${o}`]);i=n}}const o=new q(e);if(i){const t=[];o.on("readable",(function(){let e;for(;null!==(e=this.read());)t.push(e)})),o.on("error",(function(t){i(t)})),o.on("end",(function(){try{i(void 0,t.join(""))}catch(t){return void i(t)}}))}if(void 0!==t){const e=function(){for(const e of t)o.write(e);o.end()};"function"==typeof setImmediate?setImmediate(e):setTimeout(e,0)}return o},e.transform=function(){let t,e,i,o={};for(let n=0;n<arguments.length;n++){const r=arguments[n];let s=typeof r;if(null===r?s="null":"object"===s&&Array.isArray(r)&&(s="array"),"array"===s)i=r;else if("object"===s)o={...r};else if("function"===s)e&&n===arguments.length-1?t=r:e=r;else if("null"!==s)throw new Error(`Invalid Arguments: got ${JSON.stringify(r)} at position ${n}`)}const n=new g(o,e);let r=!1;if(i){const t=function(){for(const t of i){if(r)break;n.write(t)}n.end()};"function"==typeof setImmediate?setImmediate(t):setTimeout(t,0)}if(t||o.consume){const e=[];n.on("readable",(function(){let i;for(;null!==(i=n.read());)t&&e.push(i)})),n.on("error",(function(e){r=!0,t&&t(e)})),n.on("end",(function(){t&&!r&&t(null,e)}))}return n}}},e={},i=function i(o){var n=e[o];if(void 0!==n)return n.exports;var r=e[o]={exports:{}};return t[o](r,r.exports,i),r.exports}(237);module.exports=i})();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dbgate-plugin-dbf",
3
3
  "main": "dist/backend.js",
4
- "version": "6.6.0",
4
+ "version": "6.6.2",
5
5
  "homepage": "https://dbgate.org",
6
6
  "description": "DBF import/export plugin for DbGate",
7
7
  "repository": {