dobo 1.2.5 → 1.2.7

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.
@@ -187,7 +187,7 @@
187
187
  "type": "Type",
188
188
  "schema": "Schema"
189
189
  },
190
- "validationError": "Kesalahan Validasi",
190
+ "validationError": "Validation Error",
191
191
  "validation": {
192
192
  "any": {
193
193
  "required": "Required",
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
@@ -265,13 +265,27 @@ async function factory (pkgName) {
265
265
  }
266
266
 
267
267
  buildQuery = async ({ filter, schema, options = {} } = {}) => {
268
- const { trim, isString, isPlainObject } = this.lib._
268
+ const { trim, find, isString, isPlainObject } = this.lib._
269
269
  let query = {}
270
270
  if (isString(filter.query)) {
271
271
  try {
272
- filter.oquery = filter.query
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "description": "Database ORM/ODM for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {