dobo-extra 1.1.2 → 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/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,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo-extra",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "Bajo DB Extra Tools/Utility",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,8 +1,8 @@
1
1
  import path from 'path'
2
- import format from '../../lib/ndjson-csv-xlsx.js'
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 '../../lib/io-exts.js'
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 '../../lib/ndjson-csv-xlsx.js'
2
+ import format from '../lib/ndjson-csv-xlsx.js'
3
3
  import { createGunzip } from 'zlib'
4
- import supportedExt from '../../lib/io-exts.js'
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
@@ -1,2 +0,0 @@
1
- dobo
2
- bajo-extra
@@ -1,18 +0,0 @@
1
- {
2
- "export": {
3
- "maxBatch": 1000,
4
- "stringify": {
5
- "open": "[\n",
6
- "sep": ",\n",
7
- "close": "\n]\n"
8
- }
9
- },
10
- "import": {
11
- "maxBatch": 1000
12
- },
13
- "archive": {
14
- "tasks": [],
15
- "checkInterval": false,
16
- "runEarly": true
17
- }
18
- }
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