dobo-extra 2.5.1 → 2.5.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.
- package/index.js +18 -20
- package/package.json +1 -1
- package/wiki/CHANGES.md +4 -0
package/index.js
CHANGED
|
@@ -126,7 +126,6 @@ async function factory (pkgName) {
|
|
|
126
126
|
* @param {string} dest - Destination file path (absolute or relative to plugin data dir)
|
|
127
127
|
* @param {object} options - Export options
|
|
128
128
|
* @param {object} [options.filter={}] - Filter object to select records to export
|
|
129
|
-
* @param {boolean} [options.ensureDir] - Whether to create the destination directory if it doesn't exist
|
|
130
129
|
* @param {boolean} [options.useHeader=true] - Whether to include the header row (for CSV/TSV/XLSX)
|
|
131
130
|
* @param {number} [options.batch=500] - Number of records to export in a single batch
|
|
132
131
|
* @param {function} [options.progressFn] - Callback function to report progress
|
|
@@ -136,33 +135,22 @@ async function factory (pkgName) {
|
|
|
136
135
|
*/
|
|
137
136
|
exportTo = (source, dest, options = {}) => {
|
|
138
137
|
let {
|
|
139
|
-
filter = {},
|
|
140
|
-
progressFn, fields, parserOpts = {}
|
|
138
|
+
filter = {}, useHeader = true, batch = 500, opts = {},
|
|
139
|
+
progressFn, fields, parserOpts = {}, exportOpts = {}
|
|
141
140
|
} = options
|
|
142
|
-
const {
|
|
141
|
+
const { getDownloadDir } = this.app.bajo
|
|
143
142
|
const { fs } = this.app.lib
|
|
144
143
|
const { merge, omit } = this.app.lib._
|
|
145
144
|
const { getModel } = this.app.dobo
|
|
145
|
+
const { generateId } = this.app.lib.aneka
|
|
146
146
|
|
|
147
147
|
const getFile = async () => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (path.isAbsolute(dest)) file = dest
|
|
151
|
-
else {
|
|
152
|
-
file = `${this.app.getPluginDataDir(this.ns)}/export/${dest}`
|
|
153
|
-
fs.ensureDirSync(path.dirname(file))
|
|
154
|
-
}
|
|
155
|
-
file = increment(file, { fs: true, platform: 'win32' })
|
|
156
|
-
const dir = path.dirname(file)
|
|
157
|
-
if (!fs.existsSync(dir)) {
|
|
158
|
-
if (ensureDir) fs.ensureDirSync(dir)
|
|
159
|
-
else throw this.error('dirNotExists%s', dir)
|
|
160
|
-
}
|
|
148
|
+
let ext = path.extname(dest)
|
|
149
|
+
const file = `${getDownloadDir()}/${generateId()}${ext}`
|
|
161
150
|
let compress = false
|
|
162
|
-
let ext = path.extname(file)
|
|
163
151
|
if (ext === '.gz') {
|
|
164
152
|
compress = true
|
|
165
|
-
ext = path.extname(
|
|
153
|
+
ext = path.extname(dest.slice(0, -3))
|
|
166
154
|
// file = file.slice(0, file.length - 3)
|
|
167
155
|
}
|
|
168
156
|
if (!exts.includes(ext)) throw this.error('unsupportedFormat%s', ext.slice(1))
|
|
@@ -190,7 +178,17 @@ async function factory (pkgName) {
|
|
|
190
178
|
for (;;) {
|
|
191
179
|
const batchStart = new Date()
|
|
192
180
|
const { data: rows, page } = await model.findRecord(filter, { dataOnly: false, fields, fmt: true, refs: '*', noCache: true })
|
|
193
|
-
const data = rows.map(item =>
|
|
181
|
+
const data = rows.map(item => {
|
|
182
|
+
let _item = exportOpts.includes('fvalue') ? item._fmt : omit(item, ['_immutable', '_fmt', '_ref'])
|
|
183
|
+
if (exportOpts.includes('fkey')) {
|
|
184
|
+
const newItem = {}
|
|
185
|
+
for (const key in _item) {
|
|
186
|
+
newItem[opts.lang ? this.t(`field.${key}`, { lang: opts.lang }) : key] = _item[key]
|
|
187
|
+
}
|
|
188
|
+
_item = newItem
|
|
189
|
+
}
|
|
190
|
+
return _item
|
|
191
|
+
})
|
|
194
192
|
if (data.length === 0) break
|
|
195
193
|
if (cnt + data.length > hardCap) {
|
|
196
194
|
const sliced = data.slice(0, hardCap - cnt)
|
package/package.json
CHANGED