dbgate-plugin-csv 7.0.3 → 7.0.4

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 e={237:(e,t,s)=>{const r=s(514),i=s(370);e.exports={packageName:"dbgate-plugin-csv",shellApi:{reader:r,writer:i},initialize(e){r.initialize(e)}}},514:(e,t,s)=>{const r=s(825),i=s(464),o=s(896),c=s(203),n=s(994);let u;class a extends c.Transform{constructor(e){super(e),this._checkedBOM=!1,this._pending=Buffer.alloc(0)}_transform(e,t,s){if(this._checkedBOM)return this.push(e),s();if(this._pending=Buffer.concat([this._pending,e]),this._pending.length<3)return s();const r=[239,187,191];this._pending[0]===r[0]&&this._pending[1]===r[1]&&this._pending[2]===r[2]?this.push(this._pending.slice(3)):this.push(this._pending),this._pending=Buffer.alloc(0),this._checkedBOM=!0,s()}_flush(e){!this._checkedBOM&&this._pending.length>0&&this.push(this._pending),this._pending=Buffer.alloc(0),e()}}class h extends c.Transform{constructor({header:e}){super({objectMode:!0}),this.structure=null,this.header=e}_transform(e,t,s){this.structure?(this.push(r.zipObject(this.structure.columns.map((e=>e.columnName)),e)),s()):(this.header?(this.structure={__isStreamHeader:!0,columns:e.map((e=>({columnName:e})))},this.push(this.structure)):(this.structure={__isStreamHeader:!0,columns:e.map(((e,t)=>({columnName:`col${t+1}`})))},this.push(this.structure),this.push(r.zipObject(this.structure.columns.map((e=>e.columnName)),e))),s())}}async function l({fileName:e,encoding:t="utf-8",header:s=!0,delimiter:r,limitRows:c}){console.log(`Reading file ${e}`);const l=await u.download(e);if(!r){const e=await(f=l,new Promise(((e,t)=>{n.open(f,((s,r)=>{s?t(s):r.hasNextLine()?r.nextLine(((s,i)=>{s?r.close((()=>t(s))):r.close((()=>e(i)))})):r.close((()=>e(null)))}))})));if(e){const t={",":e.replace(/[^,]/g,"").length,";":e.replace(/[^;]/g,"").length,"|":e.replace(/[^|]/g,"").length};r=Object.keys(t).reduce(((e,s)=>t[e]>t[s]?e:s),",")}}var f;const d=i.parse({delimiter:r,skip_lines_with_error:!0,to_line:c?c+1:void 0,ltrim:!0}),m=o.createReadStream(l,t),p=new h({header:s});return[m,new a,d,p]}l.initialize=e=>{u=e.dbgateApi},e.exports=l},370:(e,t,s)=>{const r=s(464),i=s(896),o=s(203),{getLogger:c}=global.DBGATE_PACKAGES["dbgate-tools"],n=c("csvWriter");class u extends o.Transform{constructor(e="utf8"){super({readableObjectMode:!1,writableObjectMode:!1}),this.to=String(e).toLowerCase(),this.decoder=new(global.TextDecoder||s(23).TextDecoder)("utf-8",{fatal:!1})}_encodeString(e){if("utf8"===this.to||"utf-8"===this.to)return Buffer.from(e,"utf8");if("utf16le"===this.to||"ucs2"===this.to||"utf-16le"===this.to)return Buffer.from(e,"utf16le");if("utf16be"===this.to||"utf-16be"===this.to){const t=Buffer.from(e,"utf16le");for(let e=0;e+1<t.length;e+=2){const s=t[e];t[e]=t[e+1],t[e+1]=s}return t}throw new Error(`Unsupported target encoding: ${this.to}`)}_transform(e,t,s){try{Buffer.isBuffer(e)||(e=Buffer.from(e,t));const r=this.decoder.decode(e,{stream:!0});r.length&&this.push(this._encodeString(r)),s()}catch(e){s(e)}}_flush(e){try{const t=this.decoder.decode();t.length&&this.push(this._encodeString(t)),e()}catch(t){e(t)}}}class a extends o.Transform{constructor({header:e,booleanFormat:t}){super({objectMode:!0}),this.columns=null,this.header=e,this.cachedRows=null,this.booleanFormat=t||"true_false"}_extractValue(e){return e&&"object"==typeof e&&void 0!==e.$decimal?e.$decimal:e&&"object"==typeof e&&void 0!==e.$bigint?e.$bigint:e&&"object"==typeof e&&e.$binary&&e.$binary.base64?e.$binary.base64:e&&"boolean"==typeof e?"true_false"===this.booleanFormat?e?"true":"false":"true_false_upper"===this.booleanFormat?e?"TRUE":"FALSE":e?1:0:e}_transform(e,t,s){if(this.columns)this.push(this.columns.map((t=>this._extractValue(e[t])))),s();else{if(e.__isStreamHeader&&e.columns?.length>0)return this.columns=e.columns.map((e=>e.columnName)),this.header&&this.push(this.columns),void s();if(this.cachedRows||(this.cachedRows=[]),this.cachedRows.push(e),this.cachedRows.length<100)return void s();this.inferStructureFromCachedRows(),s()}}inferStructureFromCachedRows(){const e={};for(const t of this.cachedRows)for(const s of Object.keys(t))e[s]=!0;this.columns=Object.keys(e),this.header&&this.push(this.columns);for(const e of this.cachedRows)this.push(this.columns.map((t=>this._extractValue(e[t]))));this.cachedRows=null}_final(e){this.cachedRows&&this.inferStructureFromCachedRows(),e()}}e.exports=async function({fileName:e,encoding:t="utf-8",header:s=!0,delimiter:o,quoted:c,writeBom:h,writeSepHeader:l,recordDelimiter:f,booleanFormat:d}){n.info(`DBGM-00133 Writing file ${e}`);const m=new a({header:s,booleanFormat:d}),p=r.stringify({delimiter:o,quoted:c,record_delimiter:f||void 0}),g=i.createWriteStream(e,t);if(h)switch(t.toLowerCase()){case"utf-8":case"utf8":g.write(Buffer.from([239,187,191]));break;case"utf-16":case"utf16":case"utf-16le":case"utf16le":g.write(Buffer.from([255,254]));break;case"utf-16be":case"utf16be":g.write(Buffer.from([254,255]));break;case"utf-32le":case"utf32le":g.write(Buffer.from([255,254,0,0]));break;case"utf-32be":case"utf32be":g.write(Buffer.from([0,0,254,255]))}return l&&g.write(`sep=${o}${f||"\n"}`),m.requireFixedStructure=!0,"utf8"===t.toLowerCase()||"utf-8"===t.toLowerCase()?[m,p,g]:[m,p,new u(t),g]}},464:e=>{"use strict";e.exports=require("csv")},994:e=>{"use strict";e.exports=require("line-reader")},825:e=>{"use strict";e.exports=require("lodash")},896:e=>{"use strict";e.exports=require("fs")},203:e=>{"use strict";e.exports=require("stream")},23:e=>{"use strict";e.exports=require("util")}},t={},s=function s(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,s),o.exports}(237);module.exports=s})();
1
+ (()=>{var e={237:(e,t,s)=>{const r=s(514),i=s(370);e.exports={packageName:"dbgate-plugin-csv",shellApi:{reader:r,writer:i},initialize(e){r.initialize(e)}}},514:(e,t,s)=>{const r=s(825),i=s(464),o=s(896),c=s(203),n=s(994);let u;class a extends c.Transform{constructor(e){super(e),this._checkedBOM=!1,this._pending=Buffer.alloc(0)}_transform(e,t,s){if(this._checkedBOM)return this.push(e),s();if(this._pending=Buffer.concat([this._pending,e]),this._pending.length<3)return s();const r=[239,187,191];this._pending[0]===r[0]&&this._pending[1]===r[1]&&this._pending[2]===r[2]?this.push(this._pending.slice(3)):this.push(this._pending),this._pending=Buffer.alloc(0),this._checkedBOM=!0,s()}_flush(e){!this._checkedBOM&&this._pending.length>0&&this.push(this._pending),this._pending=Buffer.alloc(0),e()}}class h extends c.Transform{constructor({header:e}){super({objectMode:!0}),this.structure=null,this.header=e}_transform(e,t,s){this.structure?(this.push(r.zipObject(this.structure.columns.map((e=>e.columnName)),e)),s()):(this.header?(this.structure={__isStreamHeader:!0,columns:e.map((e=>({columnName:e})))},this.push(this.structure)):(this.structure={__isStreamHeader:!0,columns:e.map(((e,t)=>({columnName:`col${t+1}`})))},this.push(this.structure),this.push(r.zipObject(this.structure.columns.map((e=>e.columnName)),e))),s())}}async function l({fileName:e,encoding:t="utf-8",header:s=!0,delimiter:r,limitRows:c}){console.log(`Reading file ${e}`);const l=await u.download(e);if(!r){const e=await(f=l,new Promise(((e,t)=>{n.open(f,((s,r)=>{s?t(s):r.hasNextLine()?r.nextLine(((s,i)=>{s?r.close((()=>t(s))):r.close((()=>e(i)))})):r.close((()=>e(null)))}))})));if(e){const t={",":e.replace(/[^,]/g,"").length,";":e.replace(/[^;]/g,"").length,"|":e.replace(/[^|]/g,"").length};r=Object.keys(t).reduce(((e,s)=>t[e]>t[s]?e:s),",")}}var f;const d=i.parse({delimiter:r,skip_lines_with_error:!0,to_line:c?c+1:void 0,ltrim:!0}),m=o.createReadStream(l,t),p=new h({header:s});return[m,new a,d,p]}l.initialize=e=>{u=e.dbgateApi},e.exports=l},370:(e,t,s)=>{const r=s(464),i=s(896),o=s(203),{getLogger:c}=global.DBGATE_PACKAGES["dbgate-tools"],n=c("csvWriter");class u extends o.Transform{constructor(e="utf8"){super({readableObjectMode:!1,writableObjectMode:!1}),this.to=String(e).toLowerCase(),this.decoder=new(global.TextDecoder||s(23).TextDecoder)("utf-8",{fatal:!1})}_encodeString(e){if("utf8"===this.to||"utf-8"===this.to)return Buffer.from(e,"utf8");if("utf16le"===this.to||"ucs2"===this.to||"utf-16le"===this.to)return Buffer.from(e,"utf16le");if("utf16be"===this.to||"utf-16be"===this.to){const t=Buffer.from(e,"utf16le");for(let e=0;e+1<t.length;e+=2){const s=t[e];t[e]=t[e+1],t[e+1]=s}return t}throw new Error(`Unsupported target encoding: ${this.to}`)}_transform(e,t,s){try{Buffer.isBuffer(e)||(e=Buffer.from(e,t));const r=this.decoder.decode(e,{stream:!0});r.length&&this.push(this._encodeString(r)),s()}catch(e){s(e)}}_flush(e){try{const t=this.decoder.decode();t.length&&this.push(this._encodeString(t)),e()}catch(t){e(t)}}}class a extends o.Transform{constructor({header:e,booleanFormat:t}){super({objectMode:!0}),this.columns=null,this.header=e,this.cachedRows=null,this.booleanFormat=t||"true_false"}_extractValue(e){return void 0!==e?.$decimal?e.$decimal:void 0!==e?.$bigint?e.$bigint:e?.$binary?.base64?e.$binary.base64:"boolean"==typeof e?"1_0"===this.booleanFormat?e?1:0:"true_false_upper"===this.booleanFormat?e?"TRUE":"FALSE":e?"true":"false":e}_transform(e,t,s){if(this.columns)this.push(this.columns.map((t=>this._extractValue(e[t])))),s();else{if(e.__isStreamHeader&&e.columns?.length>0)return this.columns=e.columns.map((e=>e.columnName)),this.header&&this.push(this.columns),void s();if(this.cachedRows||(this.cachedRows=[]),this.cachedRows.push(e),this.cachedRows.length<100)return void s();this.inferStructureFromCachedRows(),s()}}inferStructureFromCachedRows(){const e={};for(const t of this.cachedRows)for(const s of Object.keys(t))e[s]=!0;this.columns=Object.keys(e),this.header&&this.push(this.columns);for(const e of this.cachedRows)this.push(this.columns.map((t=>this._extractValue(e[t]))));this.cachedRows=null}_final(e){this.cachedRows&&this.inferStructureFromCachedRows(),e()}}e.exports=async function({fileName:e,encoding:t="utf-8",header:s=!0,delimiter:o,quoted:c,writeBom:h,writeSepHeader:l,recordDelimiter:f,booleanFormat:d}){n.info(`DBGM-00133 Writing file ${e}`);const m=new a({header:s,booleanFormat:d}),p=r.stringify({delimiter:o,quoted:c,record_delimiter:f||void 0}),g=i.createWriteStream(e,t);if(h)switch(t.toLowerCase()){case"utf-8":case"utf8":g.write(Buffer.from([239,187,191]));break;case"utf-16":case"utf16":case"utf-16le":case"utf16le":g.write(Buffer.from([255,254]));break;case"utf-16be":case"utf16be":g.write(Buffer.from([254,255]));break;case"utf-32le":case"utf32le":g.write(Buffer.from([255,254,0,0]));break;case"utf-32be":case"utf32be":g.write(Buffer.from([0,0,254,255]))}return l&&g.write(`sep=${o}${f||"\n"}`),m.requireFixedStructure=!0,"utf8"===t.toLowerCase()||"utf-8"===t.toLowerCase()?[m,p,g]:[m,p,new u(t),g]}},464:e=>{"use strict";e.exports=require("csv")},994:e=>{"use strict";e.exports=require("line-reader")},825:e=>{"use strict";e.exports=require("lodash")},896:e=>{"use strict";e.exports=require("fs")},203:e=>{"use strict";e.exports=require("stream")},23:e=>{"use strict";e.exports=require("util")}},t={},s=function s(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,s),o.exports}(237);module.exports=s})();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dbgate-plugin-csv",
3
3
  "main": "dist/backend.js",
4
- "version": "7.0.3",
4
+ "version": "7.0.4",
5
5
  "homepage": "https://dbgate.org",
6
6
  "description": "CSV import/export plugin for DbGate",
7
7
  "repository": {