dobo 1.2.6 → 1.2.8
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
|
@@ -233,6 +233,7 @@ async function factory (pkgName) {
|
|
|
233
233
|
|
|
234
234
|
buildMatch = ({ input = '', schema, options }) => {
|
|
235
235
|
const { isPlainObject, trim } = this.lib._
|
|
236
|
+
if (isPlainObject(input)) return input
|
|
236
237
|
const split = (value, schema) => {
|
|
237
238
|
let [field, val] = value.split(':').map(i => i.trim())
|
|
238
239
|
if (!val) {
|
|
@@ -241,7 +242,6 @@ async function factory (pkgName) {
|
|
|
241
242
|
}
|
|
242
243
|
return { field, value: val }
|
|
243
244
|
}
|
|
244
|
-
|
|
245
245
|
input = trim(input)
|
|
246
246
|
let items = {}
|
|
247
247
|
if (isPlainObject(input)) items = input
|
|
@@ -264,14 +264,28 @@ async function factory (pkgName) {
|
|
|
264
264
|
return matcher
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
-
buildQuery =
|
|
268
|
-
const { trim, isString, isPlainObject } = this.lib._
|
|
267
|
+
buildQuery = ({ filter, schema, options = {} } = {}) => {
|
|
268
|
+
const { trim, find, isString, isPlainObject } = this.lib._
|
|
269
269
|
let query = {}
|
|
270
270
|
if (isString(filter.query)) {
|
|
271
271
|
try {
|
|
272
|
-
filter.
|
|
272
|
+
filter.query = trim(filter.query)
|
|
273
|
+
filter.orgQuery = filter.query
|
|
273
274
|
if (trim(filter.query).startsWith('{')) query = JSON.parse(filter.query)
|
|
274
|
-
else query = nql(filter.query).parse()
|
|
275
|
+
else if (filter.query.includes(':')) query = nql(filter.query).parse()
|
|
276
|
+
else {
|
|
277
|
+
const fields = schema.sortables.filter(f => {
|
|
278
|
+
const field = find(schema.properties, { name: f, type: 'string' })
|
|
279
|
+
return !!field
|
|
280
|
+
})
|
|
281
|
+
const parts = fields.map(f => {
|
|
282
|
+
if (filter.query[0] === '*') return `${f}:~$'${filter.query.replaceAll('*', '')}'`
|
|
283
|
+
if (filter.query[filter.length - 1] === '*') return `${f}:~^'${filter.query.replaceAll('*', '')}'`
|
|
284
|
+
return `${f}:~'${filter.query.replaceAll('*', '')}'`
|
|
285
|
+
})
|
|
286
|
+
if (parts.length === 1) query = nql(parts[0]).parse()
|
|
287
|
+
else if (parts.length > 1) query = nql(parts.join(',')).parse()
|
|
288
|
+
}
|
|
275
289
|
} catch (err) {
|
|
276
290
|
this.error('invalidQuery', { orgMessage: err.message })
|
|
277
291
|
}
|
package/package.json
CHANGED
|
@@ -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 =
|
|
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) {
|
|
@@ -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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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)
|