dobo-extra 1.2.2 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  async function factory (pkgName) {
2
2
  const me = this
3
3
 
4
- return class DoboExtra extends this.lib.BajoPlugin {
4
+ return class DoboExtra extends this.lib.Plugin {
5
5
  constructor () {
6
6
  super(pkgName, me.app)
7
7
  this.alias = 'dbx'
@@ -36,11 +36,32 @@ async function getFile (dest, ensureDir) {
36
36
 
37
37
  async function getData ({ source, filter, count, stream, progressFn, fields }) {
38
38
  let cnt = count ?? 0
39
- const { recordFind } = this.app.dobo
39
+ const { find } = this.lib._
40
+ const { recordFind, getSchema } = this.app.dobo
41
+ const { maxLimit, hardLimit } = this.app.dobo.config.default.filter
42
+ filter.limit = maxLimit
43
+ let sort
44
+ const schema = getSchema(source)
45
+ const idField = find(schema.properties, { name: 'id' })
46
+ for (const name of ['createdAt', 'updatedAt', 'ts', 'dt']) {
47
+ const field = find(schema.properties, { name })
48
+ if (field) {
49
+ sort = field.name
50
+ break
51
+ }
52
+ }
53
+ filter.sort = `${sort ?? idField}:1`
40
54
  for (;;) {
41
55
  const batchStart = new Date()
42
56
  const { data, page } = await recordFind(source, filter, { dataOnly: false, fields })
43
57
  if (data.length === 0) break
58
+ if (cnt + data.length > hardLimit) {
59
+ const sliced = data.slice(0, hardLimit - cnt)
60
+ await stream.pull(sliced)
61
+ cnt += sliced.length
62
+ if (progressFn) await progressFn.call(this, { batchNo: page, data: sliced, batchStart, batchEnd: new Date() })
63
+ break
64
+ }
44
65
  cnt += data.length
45
66
  await stream.pull(data)
46
67
  if (progressFn) await progressFn.call(this, { batchNo: page, data, batchStart, batchEnd: new Date() })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo-extra",
3
- "version": "1.2.2",
3
+ "version": "2.0.0",
4
4
  "description": "Bajo DB Extra Tools/Utility",
5
5
  "main": "index.js",
6
6
  "scripts": {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes