dobo 1.1.17 → 1.1.19

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.
@@ -122,6 +122,7 @@
122
122
  "errorAddingFixture%s%s": "Error adding fixture on model '%s': %s",
123
123
  "memoryDbSkipped%s": "'%s' is a memory DB, skipped",
124
124
  "db": "DB",
125
+ "invalidQuery": "Invalid Query",
125
126
  "field": {
126
127
  "id": "ID",
127
128
  "code": "Kode",
package/bajo/intl/id.json CHANGED
@@ -115,6 +115,7 @@
115
115
  "recordsAdded%s%d%d": "%s: %d of %d records added",
116
116
  "driverInstantiated%s%s": "- Driver '%s:%s' instantiated",
117
117
  "db": "DB",
118
+ "invalidQuery": "Kueri Tidak Valid",
118
119
  "field": {
119
120
  "id": "ID",
120
121
  "code": "Kode",
@@ -8,8 +8,9 @@ async function createdAt (opts = {}) {
8
8
  },
9
9
  hook: {
10
10
  beforeCreate: async function ({ body }) {
11
+ const { isSet } = this.lib.aneka
11
12
  const now = new Date()
12
- if (opts.overwrite || !this.app.bajo.isSet(body[opts.fieldName])) body[opts.fieldName] = now
13
+ if (opts.overwrite || !isSet(body[opts.fieldName])) body[opts.fieldName] = now
13
14
  }
14
15
  }
15
16
  }
@@ -9,12 +9,14 @@ async function updatedAt (opts = {}) {
9
9
  },
10
10
  hook: {
11
11
  beforeCreate: async function ({ body }) {
12
+ const { isSet } = this.lib.aneka
12
13
  const now = new Date()
13
- if (opts.overwrite || !this.app.bajo.isSet(body[opts.fieldName])) body[opts.fieldName] = now
14
+ if (opts.overwrite || !isSet(body[opts.fieldName])) body[opts.fieldName] = now
14
15
  },
15
16
  beforeUpdate: async function ({ body }) {
17
+ const { isSet } = this.lib.aneka
16
18
  const now = new Date()
17
- if (opts.overwrite || !this.app.bajo.isSet(body[opts.fieldName])) body[opts.fieldName] = now
19
+ if (opts.overwrite || !isSet(body[opts.fieldName])) body[opts.fieldName] = now
18
20
  }
19
21
  }
20
22
  }
@@ -1,5 +1,5 @@
1
1
  async function checkUnique ({ schema, body, id }) {
2
- const { isSet } = this.app.bajo
2
+ const { isSet } = this.lib.aneka
3
3
  const { filter, map, set } = this.lib._
4
4
  const singles = map(filter(schema.properties, p => (p.index ?? {}).type === 'unique'), 'name')
5
5
  const opts = { noHook: true, noCache: true, thrownNotFound: false, forceNoHidden: true }
@@ -2,7 +2,8 @@ import path from 'path'
2
2
  import sanitizeSchema from './sanitize-schema.js'
3
3
 
4
4
  async function handler ({ file, alias, ns }) {
5
- const { readConfig, pascalCase, eachPlugins } = this.app.bajo
5
+ const { readConfig, eachPlugins } = this.app.bajo
6
+ const { pascalCase } = this.lib.aneka
6
7
  const { get, isPlainObject, each, find, has, isArray, forOwn, isString, merge } = this.lib._
7
8
  const { fastGlob } = this.lib
8
9
 
@@ -1,5 +1,5 @@
1
1
  async function multiRelRows ({ schema, records, options = {} }) {
2
- const { isSet } = this.app.bajo
2
+ const { isSet } = this.lib.aneka
3
3
  const { uniq, find, map } = this.lib._
4
4
  const props = schema.properties.filter(p => isSet(p.rel) && !(options.hidden ?? []).includes(p.name))
5
5
  // const props = schema.properties.filter(p => isSet(p.rel))
@@ -37,7 +37,8 @@ async function sanitizeFullText (item) {
37
37
  }
38
38
 
39
39
  async function sanitizeSchema (items) {
40
- const { freeze, fatal, importModule, defaultsDeep, join, breakNsPath, runHook } = this.app.bajo
40
+ const { defaultsDeep } = this.lib.aneka
41
+ const { freeze, fatal, importModule, join, breakNsPath, runHook } = this.app.bajo
41
42
  const { isEmpty, orderBy, map, keys, findIndex, find, each, isString, get, isPlainObject, camelCase, uniq, filter } = this.lib._
42
43
  const propTypes = keys(this.propType)
43
44
  const schemas = []
@@ -1,5 +1,5 @@
1
1
  async function singleRelRows ({ schema, record, options = {} }) {
2
- const { isSet } = this.app.bajo
2
+ const { isSet } = this.lib.aneka
3
3
  const { find } = this.lib._
4
4
  const props = schema.properties.filter(p => isSet(p.rel) && !(options.hidden ?? []).includes(p.name))
5
5
  const rels = {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo",
3
- "version": "1.1.17",
3
+ "version": "1.1.19",
4
4
  "description": "Database ORM/ODM for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/plugin/factory.js CHANGED
@@ -267,17 +267,22 @@ async function factory (pkgName) {
267
267
  buildQuery = async ({ filter, schema, options = {} } = {}) => {
268
268
  const { trim, isString, isPlainObject } = this.lib._
269
269
  let query = {}
270
+ if (schema.name === 'SeatrackVessel') this.app.dump(filter)
270
271
  if (isString(filter.query)) {
271
- filter.oquery = filter.query
272
- if (trim(filter.query).startsWith('{')) query = JSON.parse(filter.query)
273
- else query = nql(filter.query).parse()
272
+ try {
273
+ filter.oquery = filter.query
274
+ if (trim(filter.query).startsWith('{')) query = JSON.parse(filter.query)
275
+ else query = nql(filter.query).parse()
276
+ } catch (err) {
277
+ this.error('invalidQuery', { orgMessage: err.message })
278
+ }
274
279
  } else if (isPlainObject(filter.query)) query = filter.query
275
280
  return this.sanitizeQuery(query, schema)
276
281
  }
277
282
 
278
283
  sanitizeQuery = (query, schema, parent) => {
279
284
  const { cloneDeep, isPlainObject, isArray, find } = this.lib._
280
- const { isSet } = this.app.bajo
285
+ const { isSet } = this.lib.aneka
281
286
  const { dayjs } = this.lib
282
287
  const obj = cloneDeep(query)
283
288
  const keys = Object.keys(obj)
@@ -336,8 +341,9 @@ async function factory (pkgName) {
336
341
 
337
342
  getSchema = (input, cloned = true) => {
338
343
  const { find, isPlainObject, cloneDeep } = this.lib._
344
+ const { pascalCase } = this.lib.aneka
339
345
  let name = isPlainObject(input) ? input.name : input
340
- name = this.app.bajo.pascalCase(name)
346
+ name = pascalCase(name)
341
347
  const schema = find(this.schemas, { name })
342
348
  if (!schema) throw this.error('unknownModelSchema%s', name)
343
349
  return cloned ? cloneDeep(schema) : schema
@@ -1,5 +1,6 @@
1
1
  async function getPath (name, id, field, file, options = {}) {
2
- const { pascalCase, getPluginDataDir } = this.app.bajo
2
+ const { getPluginDataDir } = this.app.bajo
3
+ const { pascalCase } = this.lib.aneka
3
4
  const { fs } = this.lib
4
5
  const dir = `${getPluginDataDir(this.name)}/attachment/${pascalCase(name)}/${id}`
5
6
  if (options.dirOnly) return dir
@@ -1,5 +1,6 @@
1
1
  function preCheck (name) {
2
- name = this.app.bajo.pascalCase(name)
2
+ const { pascalCase } = this.lib.aneka
3
+ name = pascalCase(name)
3
4
  const schema = this.getSchema(name)
4
5
  if (!schema.attachment) return false
5
6
  return name
@@ -3,7 +3,8 @@ import execValidation from '../../../lib/exec-validation.js'
3
3
  import execFeatureHook from '../../../lib/exec-feature-hook.js'
4
4
 
5
5
  async function create (name, inputs, options) {
6
- const { generateId, runHook, isSet } = this.app.bajo
6
+ const { isSet } = this.lib.aneka
7
+ const { generateId, runHook } = this.app.bajo
7
8
  const { clearModel } = this.cache ?? {}
8
9
  const { find } = this.lib._
9
10
  options.dataOnly = options.dataOnly ?? true
@@ -7,7 +7,8 @@ import execFeatureHook from '../../../lib/exec-feature-hook.js'
7
7
  import singleRelRows from '../../../lib/single-rel-rows.js'
8
8
 
9
9
  async function create (name, input, opts = {}) {
10
- const { generateId, runHook, isSet } = this.app.bajo
10
+ const { generateId, runHook } = this.app.bajo
11
+ const { isSet } = this.lib.aneka
11
12
  const { clearModel } = this.cache ?? {}
12
13
  const { find, forOwn, cloneDeep, camelCase, omit, get, pick } = this.lib._
13
14
  delete opts.record
@@ -3,7 +3,8 @@ import singleRelRows from '../../../lib/single-rel-rows.js'
3
3
  import execFeatureHook from '../../../lib/exec-feature-hook.js'
4
4
 
5
5
  async function findOne (name, filter = {}, opts = {}) {
6
- const { runHook, isSet } = this.app.bajo
6
+ const { isSet } = this.lib.aneka
7
+ const { runHook } = this.app.bajo
7
8
  const { get, set } = this.cache ?? {}
8
9
  const { cloneDeep, camelCase, omit } = this.lib._
9
10
  delete opts.record
@@ -3,7 +3,8 @@ import multiRelRows from '../../../lib/multi-rel-rows.js'
3
3
  import execFeatureHook from '../../../lib/exec-feature-hook.js'
4
4
 
5
5
  async function find (name, filter = {}, opts = {}) {
6
- const { runHook, isSet } = this.app.bajo
6
+ const { isSet } = this.lib.aneka
7
+ const { runHook } = this.app.bajo
7
8
  const { get, set } = this.cache ?? {}
8
9
  const { cloneDeep, camelCase, omit } = this.lib._
9
10
  delete opts.records
@@ -3,7 +3,8 @@ import singleRelRows from '../../../lib/single-rel-rows.js'
3
3
  import execFeatureHook from '../../../lib/exec-feature-hook.js'
4
4
 
5
5
  async function get (name, id, opts = {}) {
6
- const { runHook, isSet } = this.app.bajo
6
+ const { isSet } = this.lib.aneka
7
+ const { runHook } = this.app.bajo
7
8
  const { get, set } = this.cache ?? {}
8
9
  const { cloneDeep, camelCase, omit } = this.lib._
9
10
  delete opts.record
@@ -6,7 +6,8 @@ import execFeatureHook from '../../../lib/exec-feature-hook.js'
6
6
  import singleRelRows from '../../../lib/single-rel-rows.js'
7
7
 
8
8
  async function update (name, id, input, opts = {}) {
9
- const { runHook, isSet } = this.app.bajo
9
+ const { isSet } = this.lib.aneka
10
+ const { runHook } = this.app.bajo
10
11
  const { clearModel } = this.cache ?? {}
11
12
  const { forOwn, find, cloneDeep, camelCase, omit, get } = this.lib._
12
13
  delete opts.record
@@ -1,5 +1,7 @@
1
1
  async function sanitizeBody ({ body = {}, schema = {}, partial, strict, extFields = [] }) {
2
- const { isSet, dayjs, callHandler } = this.app.bajo
2
+ const { isSet } = this.lib.aneka
3
+ const { dayjs } = this.lib
4
+ const { callHandler } = this.app.bajo
3
5
  const { has, isString, isNumber, concat, isNaN } = this.lib._
4
6
  const result = {}
5
7
  for (const p of concat(schema.properties, extFields)) {
@@ -126,7 +126,7 @@ function buildFromDbSchema (schema, { fields = [], rule = {}, extFields = [] } =
126
126
  }
127
127
 
128
128
  async function validate (value, joiSchema, { ns, fields, extFields, params } = {}) {
129
- const { defaultsDeep, isSet } = this.app.bajo
129
+ const { defaultsDeep, isSet } = this.lib.aneka
130
130
  const { isString, forOwn, find } = this.lib._
131
131
 
132
132
  ns = ns ?? [this.name]
@@ -2,7 +2,7 @@ import path from 'path'
2
2
 
3
3
  async function attachment (req, reply) {
4
4
  const { isString, isEmpty, find } = this.lib._
5
- const { pascalCase } = this.app.bajo
5
+ const { pascalCase } = this.lib.aneka
6
6
  const { routePath } = this.app.waibu
7
7
  const { fs } = this.lib
8
8
  const items = await this.listAttachments({