dobo-extra 1.2.1 → 1.2.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.
@@ -5,10 +5,12 @@ import csv from 'fast-csv'
5
5
  import xlsxparse from 'xlsx-parse-stream'
6
6
  import XLSXWriteStream from '@atomictech/xlsx-write-stream'
7
7
  import StreamArray from 'stream-json/streamers/StreamArray.js'
8
- import stringer from 'stream-json/Stringer.js'
9
- import disassembler from 'stream-json/Disassembler.js'
8
+ import Stringer from 'stream-json/Stringer.js'
9
+ import Disassembler from 'stream-json/Disassembler.js'
10
10
  import chain from 'stream-chain'
11
11
 
12
+ const XLSXStreamer = XLSXWriteStream.default
13
+
12
14
  export default {
13
15
  ndjson: {
14
16
  parse: (...args) => ndjson.parse(...args),
@@ -20,7 +22,7 @@ export default {
20
22
  },
21
23
  xlsx: {
22
24
  parse: (...args) => xlsxparse(...args),
23
- stringify: (...args) => new XLSXWriteStream(...args)
25
+ stringify: (...args) => new XLSXStreamer(...args)
24
26
  },
25
27
  json: {
26
28
  parse: (...args) => chain([
@@ -28,8 +30,8 @@ export default {
28
30
  data => data.value
29
31
  ]),
30
32
  stringify: (options, ...args) => chain([
31
- disassembler(),
32
- stringer({ ...options, makeArray: true })
33
+ new Disassembler(),
34
+ new Stringer({ ...options, makeArray: true })
33
35
  ])
34
36
  }
35
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo-extra",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Bajo DB Extra Tools/Utility",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -27,19 +27,19 @@ async function getFile (dest, ensureDir) {
27
27
  let ext = path.extname(file)
28
28
  if (ext === '.gz') {
29
29
  compress = true
30
- ext = path.extname(path.basename(file).replace('.gz', ''))
30
+ ext = path.extname(file.slice(0, -3))
31
31
  // file = file.slice(0, file.length - 3)
32
32
  }
33
33
  if (!supportedExt.includes(ext)) throw this.error('unsupportedFormat%s', ext.slice(1))
34
34
  return { file, ext, compress }
35
35
  }
36
36
 
37
- async function getData ({ source, filter, count, stream, progressFn }) {
37
+ async function getData ({ source, filter, count, stream, progressFn, fields }) {
38
38
  let cnt = count ?? 0
39
39
  const { recordFind } = this.app.dobo
40
40
  for (;;) {
41
41
  const batchStart = new Date()
42
- const { data, page } = await recordFind(source, filter, { dataOnly: false })
42
+ const { data, page } = await recordFind(source, filter, { dataOnly: false, fields })
43
43
  if (data.length === 0) break
44
44
  cnt += data.length
45
45
  await stream.pull(data)
@@ -50,9 +50,10 @@ async function getData ({ source, filter, count, stream, progressFn }) {
50
50
  return cnt
51
51
  }
52
52
 
53
- function exportTo (source, dest, { filter = {}, ensureDir, useHeader = true, batch = 500, progressFn } = {}, opts = {}) {
53
+ function exportTo (source, dest, { filter = {}, ensureDir, useHeader = true, batch = 500, progressFn, fields } = {}, opts = {}) {
54
54
  const { fs } = this.lib
55
55
  const { merge } = this.lib._
56
+ const { getInfo } = this.app.dobo
56
57
 
57
58
  filter.page = 1
58
59
  batch = parseInt(batch) ?? 500
@@ -61,7 +62,6 @@ function exportTo (source, dest, { filter = {}, ensureDir, useHeader = true, bat
61
62
  filter.limit = batch
62
63
 
63
64
  return new Promise((resolve, reject) => {
64
- const { getInfo } = this.app.dobo
65
65
  let count = 0
66
66
  let file
67
67
  let ext
@@ -69,9 +69,7 @@ function exportTo (source, dest, { filter = {}, ensureDir, useHeader = true, bat
69
69
  let compress
70
70
  let writer
71
71
  getInfo(source)
72
- .then(res => {
73
- return getFile.call(this, dest, ensureDir)
74
- })
72
+ getFile.call(this, dest, ensureDir)
75
73
  .then(res => {
76
74
  file = res.file
77
75
  ext = res.ext
@@ -93,7 +91,7 @@ function exportTo (source, dest, { filter = {}, ensureDir, useHeader = true, bat
93
91
  else if (ext === '.xlsx') pipes.push(xlsx.stringify(merge({}, { header: useHeader }, opts)))
94
92
  if (compress) pipes.push(createGzip())
95
93
  DataStream.pipeline(stream, ...pipes).pipe(writer)
96
- return getData.call(this, { source, filter, count, stream, progressFn })
94
+ return getData.call(this, { source, filter, count, stream, fields, progressFn })
97
95
  })
98
96
  .then(cnt => {
99
97
  count = cnt