dobo-extra 1.1.1 → 1.2.0
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/bajoCli/applet/export-to.js +1 -1
- package/bajoCli/applet/import-from.js +1 -1
- package/index.js +68 -0
- package/package.json +1 -1
- package/{plugin/method → plugin-method}/export-to.js +2 -2
- package/{plugin/method → plugin-method}/import-from.js +2 -2
- package/plugin/.alias +0 -1
- package/plugin/.dependencies +0 -2
- package/plugin/config.json +0 -18
- package/plugin/init.js +0 -25
- package/plugin/start.js +0 -14
|
@@ -3,7 +3,7 @@ import _path from 'path'
|
|
|
3
3
|
const batch = 100
|
|
4
4
|
|
|
5
5
|
function makeProgress (spin) {
|
|
6
|
-
const { secToHms } = this.
|
|
6
|
+
const { secToHms } = this.lib.aneka
|
|
7
7
|
return async function ({ batchNo, data, batchStart, batchEnd } = {}) {
|
|
8
8
|
if (data.length === 0) return
|
|
9
9
|
spin.setText('batch%d%s', batchNo, secToHms(batchEnd.toTime() - batchStart.toTime(), true))
|
|
@@ -3,7 +3,7 @@ import _path from 'path'
|
|
|
3
3
|
const batch = 100
|
|
4
4
|
|
|
5
5
|
function makeProgress (spin) {
|
|
6
|
-
const { secToHms } = this.
|
|
6
|
+
const { secToHms } = this.lib.aneka
|
|
7
7
|
return async function ({ batchNo, data, batchStart, batchEnd } = {}) {
|
|
8
8
|
spin.setText('batch%d%s', batchNo, secToHms(batchEnd.toTime() - batchStart.toTime(), true))
|
|
9
9
|
}
|
package/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
async function factory (pkgName) {
|
|
2
|
+
const me = this
|
|
3
|
+
|
|
4
|
+
return class DoboExtra extends this.lib.BajoPlugin {
|
|
5
|
+
constructor () {
|
|
6
|
+
super(pkgName, me.app)
|
|
7
|
+
this.alias = 'dbx'
|
|
8
|
+
this.dependencies = ['dobo', 'bajo-extra']
|
|
9
|
+
this.config = {
|
|
10
|
+
export: {
|
|
11
|
+
maxBatch: 1000,
|
|
12
|
+
stringify: {
|
|
13
|
+
open: '[\n',
|
|
14
|
+
sep: ',\n',
|
|
15
|
+
close: '\n]\n'
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
import: {
|
|
19
|
+
maxBatch: 1000
|
|
20
|
+
},
|
|
21
|
+
archive: {
|
|
22
|
+
tasks: [],
|
|
23
|
+
checkInterval: false,
|
|
24
|
+
runEarly: true
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
init = async () => {
|
|
30
|
+
const { buildCollections } = this.app.bajo
|
|
31
|
+
const types = ['datetime', 'date', 'timestamp']
|
|
32
|
+
|
|
33
|
+
async function handler ({ item }) {
|
|
34
|
+
const { join } = this.app.bajo
|
|
35
|
+
const { getSchema } = this.app.dobo
|
|
36
|
+
const { has } = this.lib._
|
|
37
|
+
for (const f of ['source', 'destination']) {
|
|
38
|
+
if (!has(item, f)) throw this.error('taskMustHaveModel%s', f)
|
|
39
|
+
const key = `${f}Field`
|
|
40
|
+
item[key] = item[key] ?? 'createdAt'
|
|
41
|
+
const schema = getSchema(item[f])
|
|
42
|
+
const prop = schema.properties.find(p => p.name === item[key])
|
|
43
|
+
if (!prop) throw this.error('unknownField%s%s', item[key], item[f])
|
|
44
|
+
if (!types.includes(prop.type)) throw this.error('isNotSupported%s%s%s%s', item[key], item[f], prop.type, join(types))
|
|
45
|
+
}
|
|
46
|
+
if (item.source === item.destination) throw this.error('sourceDestMustBeDifferent')
|
|
47
|
+
item.maxAge = item.maxAge ?? 1 // in days, less then 1 is ignored
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this.archivers = await buildCollections({ ns: this.name, handler, container: 'archive.tasks', dupChecks: ['source'], useDefaultName: false })
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
start = async () => {
|
|
54
|
+
if (this.config.archive.checkInterval === false || this.config.archive.checkInterval <= 0) {
|
|
55
|
+
this.log.warn('autoArchiveDisabled')
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
if (this.config.archive.runEarly) await this.archive()
|
|
59
|
+
this.archiveIntv = setInterval(() => {
|
|
60
|
+
this.archive().then().catch(err => {
|
|
61
|
+
this.log.error('archiveError%s', err.message)
|
|
62
|
+
})
|
|
63
|
+
}, this.config.archive.checkInterval * 60 * 1000)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default factory
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
|
-
import format from '
|
|
2
|
+
import format from '../lib/ndjson-csv-xlsx.js'
|
|
3
3
|
import { createGzip } from 'node:zlib'
|
|
4
4
|
import scramjet from 'scramjet'
|
|
5
|
-
import supportedExt from '
|
|
5
|
+
import supportedExt from '../lib/io-exts.js'
|
|
6
6
|
|
|
7
7
|
const { DataStream } = scramjet
|
|
8
8
|
const { json, ndjson, csv, xlsx } = format
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
|
-
import format from '
|
|
2
|
+
import format from '../lib/ndjson-csv-xlsx.js'
|
|
3
3
|
import { createGunzip } from 'zlib'
|
|
4
|
-
import supportedExt from '
|
|
4
|
+
import supportedExt from '../lib/io-exts.js'
|
|
5
5
|
import scramjet from 'scramjet'
|
|
6
6
|
|
|
7
7
|
const { DataStream } = scramjet
|
package/plugin/.alias
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
dbx
|
package/plugin/.dependencies
DELETED
package/plugin/config.json
DELETED
package/plugin/init.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const types = ['datetime', 'date', 'timestamp']
|
|
2
|
-
|
|
3
|
-
async function handler ({ item }) {
|
|
4
|
-
const { join } = this.app.bajo
|
|
5
|
-
const { getSchema } = this.app.dobo
|
|
6
|
-
const { has } = this.lib._
|
|
7
|
-
for (const f of ['source', 'destination']) {
|
|
8
|
-
if (!has(item, f)) throw this.error('taskMustHaveModel%s', f)
|
|
9
|
-
const key = `${f}Field`
|
|
10
|
-
item[key] = item[key] ?? 'createdAt'
|
|
11
|
-
const schema = getSchema(item[f])
|
|
12
|
-
const prop = schema.properties.find(p => p.name === item[key])
|
|
13
|
-
if (!prop) throw this.error('unknownField%s%s', item[key], item[f])
|
|
14
|
-
if (!types.includes(prop.type)) throw this.error('isNotSupported%s%s%s%s', item[key], item[f], prop.type, join(types))
|
|
15
|
-
}
|
|
16
|
-
if (item.source === item.destination) throw this.error('sourceDestMustBeDifferent')
|
|
17
|
-
item.maxAge = item.maxAge ?? 1 // in days, less then 1 is ignored
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async function init () {
|
|
21
|
-
const { buildCollections } = this.app.bajo
|
|
22
|
-
this.archivers = await buildCollections({ ns: this.name, handler, container: 'archive.tasks', dupChecks: ['source'], useDefaultName: false })
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export default init
|
package/plugin/start.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
async function start () {
|
|
2
|
-
if (this.config.archive.checkInterval === false || this.config.archive.checkInterval <= 0) {
|
|
3
|
-
this.log.warn('autoArchiveDisabled')
|
|
4
|
-
return
|
|
5
|
-
}
|
|
6
|
-
if (this.config.archive.runEarly) await this.archive()
|
|
7
|
-
this.archiveIntv = setInterval(() => {
|
|
8
|
-
this.archive().then().catch(err => {
|
|
9
|
-
this.log.error('archiveError%s', err.message)
|
|
10
|
-
})
|
|
11
|
-
}, this.config.archive.checkInterval * 60 * 1000)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default start
|