dobo 1.2.7 → 1.2.9

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
@@ -34,6 +34,7 @@ async function factory (pkgName) {
34
34
  filter: {
35
35
  limit: 25,
36
36
  maxLimit: 200,
37
+ hardLimit: 10000,
37
38
  sort: ['dt:-1', 'updatedAt:-1', 'updated_at:-1', 'createdAt:-1', 'createdAt:-1', 'ts:-1', 'username', 'name']
38
39
  },
39
40
  idField: {
@@ -264,7 +265,7 @@ async function factory (pkgName) {
264
265
  return matcher
265
266
  }
266
267
 
267
- buildQuery = async ({ filter, schema, options = {} } = {}) => {
268
+ buildQuery = ({ filter, schema, options = {} } = {}) => {
268
269
  const { trim, find, isString, isPlainObject } = this.lib._
269
270
  let query = {}
270
271
  if (isString(filter.query)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "description": "Database ORM/ODM for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -15,7 +15,7 @@ async function count (name, filter = {}, opts = {}) {
15
15
  await this.modelExists(name, true)
16
16
  const { handler, schema, driver } = await resolveMethod.call(this, name, 'record-count', options)
17
17
  if (!schema.cacheable) noCache = true
18
- filter.query = await this.buildQuery({ filter, schema, options }) ?? {}
18
+ filter.query = this.buildQuery({ filter, schema, options }) ?? {}
19
19
  if (options.queryHandler) filter.query = await options.queryHandler.call(opts.req ? this.app[opts.req.ns] : this, filter.query, opts.req)
20
20
  filter.match = this.buildMatch({ input: filter.match, schema, options }) ?? {}
21
21
  if (!noHook) {
@@ -1,14 +1,22 @@
1
1
  async function findAll (name, filter = {}, options = {}) {
2
+ const { maxLimit, hardLimit } = this.config.default.filter
2
3
  filter.page = 1
3
- filter.limit = 100
4
+ filter.limit = maxLimit
4
5
  options.dataOnly = true
5
6
  const match = filter.match
6
7
  const all = []
8
+ let count = 0
7
9
  for (;;) {
8
10
  filter.match = match
9
11
  const results = await this.recordFind(name, filter, options)
10
12
  if (results.length === 0) break
13
+ if (count + results.length > hardLimit) {
14
+ const sliced = results.slice(0, hardLimit - count)
15
+ all.push(...sliced)
16
+ break
17
+ }
11
18
  all.push(...results)
19
+ count = count + results.length
12
20
  filter.page++
13
21
  }
14
22
  return all
@@ -20,7 +20,7 @@ async function findOne (name, filter = {}, opts = {}) {
20
20
  filter.page = 1
21
21
  const { handler, schema, driver } = await resolveMethod.call(this, name, 'record-find', options)
22
22
  if (!schema.cacheable) noCache = true
23
- filter.query = await this.buildQuery({ filter, schema, options }) ?? {}
23
+ filter.query = this.buildQuery({ filter, schema, options }) ?? {}
24
24
  if (options.queryHandler) filter.query = await options.queryHandler.call(opts.req ? this.app[opts.req.ns] : this, filter.query, opts.req)
25
25
  filter.match = this.buildMatch({ input: filter.match, schema, options }) ?? {}
26
26
  if (!noHook) {
@@ -18,7 +18,7 @@ async function find (name, filter = {}, opts = {}) {
18
18
  await this.modelExists(name, true)
19
19
  const { handler, schema, driver } = await resolveMethod.call(this, name, 'record-find', options)
20
20
  if (!schema.cacheable) noCache = true
21
- filter.query = await this.buildQuery({ filter, schema, options }) ?? {}
21
+ filter.query = this.buildQuery({ filter, schema, options }) ?? {}
22
22
  if (options.queryHandler) filter.query = await options.queryHandler.call(opts.req ? this.app[opts.req.ns] : this, filter.query, opts.req)
23
23
  filter.match = this.buildMatch({ input: filter.match, schema, options }) ?? {}
24
24
  if (!noHook) {
@@ -10,7 +10,7 @@ async function aggregate (name, filter = {}, options = {}) {
10
10
  await runHook(`${this.name}:beforeStatAggregate`, name, aggregate, filter, options)
11
11
  await runHook(`${this.name}.${name}:beforeStatAggregate`, aggregate, filter, options)
12
12
  }
13
- filter.query = await this.buildQuery({ filter, schema, options }) ?? {}
13
+ filter.query = this.buildQuery({ filter, schema, options }) ?? {}
14
14
  filter.match = this.buildMatch({ input: filter.match, schema, options }) ?? {}
15
15
  const rec = await handler.call(this.app[driver.ns], { schema, filter, options })
16
16
  if (!noHook) {
@@ -9,7 +9,7 @@ async function histogram (name, filter = {}, options = {}) {
9
9
  if (!types.includes(type)) throw this.error('histogramTypeMusBe%s', join(types))
10
10
  await this.modelExists(name, true)
11
11
  const { handler, schema, driver } = await resolveMethod.call(this, name, 'stat-histogram', options)
12
- filter.query = await this.buildQuery({ filter, schema, options }) ?? {}
12
+ filter.query = this.buildQuery({ filter, schema, options }) ?? {}
13
13
  filter.match = this.buildMatch({ input: filter.match, schema, options }) ?? {}
14
14
  if (!noHook) {
15
15
  await runHook(`${this.name}:beforeStatHistogram`, name, type, filter, options)