dobo 1.0.8 → 1.0.10

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.
@@ -0,0 +1,38 @@
1
+ import resolveMethod from '../../../lib/resolve-method.js'
2
+
3
+ async function count (name, filter = {}, opts = {}) {
4
+ const { runHook } = this.app.bajo
5
+ const { get, set } = this.cache ?? {}
6
+ const { cloneDeep, camelCase, omit } = this.app.bajo.lib._
7
+ const options = cloneDeep(omit(opts, ['req']))
8
+ options.req = opts.req
9
+ options.dataOnly = options.dataOnly ?? true
10
+ let { dataOnly, noHook, noCache } = options
11
+ options.dataOnly = false
12
+ await this.modelExists(name, true)
13
+ const { handler, schema, driver } = await resolveMethod.call(this, name, 'record-count', options)
14
+ if (!schema.cacheable) noCache = true
15
+ filter.query = await this.buildQuery({ filter, schema, options }) ?? {}
16
+ if (options.queryHandler) filter.query = await options.queryHandler.call(opts.req ? this.app[opts.req.ns] : this, filter.query, opts.req)
17
+ filter.match = this.buildMatch({ input: filter.match, schema, options }) ?? {}
18
+ if (!noHook) {
19
+ await runHook(`${this.name}:beforeRecordCount`, name, filter, options)
20
+ await runHook(`${this.name}.${camelCase(name)}:beforeRecordCount`, filter, options)
21
+ }
22
+ if (get && !noCache) {
23
+ const cachedResult = await get({ model: name, filter, options })
24
+ if (cachedResult) {
25
+ cachedResult.cached = true
26
+ return dataOnly ? cachedResult.data : cachedResult
27
+ }
28
+ }
29
+ const count = await handler.call(this.app[driver.ns], { schema, filter, options })
30
+ if (!noHook) {
31
+ await runHook(`${this.name}.${camelCase(name)}:afterRecordFind`, filter, options, count)
32
+ await runHook(`${this.name}:afterRecordFind`, name, filter, options, count)
33
+ }
34
+ if (set && !noCache) await set({ model: name, filter, options, count })
35
+ return dataOnly ? count.data : count
36
+ }
37
+
38
+ export default count
@@ -18,9 +18,8 @@ async function addFixture (name, { spinner } = {}) {
18
18
  const overrides = await readConfig(`${getPluginDataDir(this.name)}/override/fixture/${schema.name}.*`, { ns: this.name, ignoreError: true })
19
19
  if (isArray(overrides) && !isEmpty(overrides)) items = overrides
20
20
  // extend
21
- const me = this
22
21
  await eachPlugins(async function ({ dir, ns }) {
23
- const extend = await readConfig(`${dir}/${me.name}/extend/fixture/${schema.name}.*`, { ns, ignoreError: true })
22
+ const extend = await readConfig(`${dir}/dobo/extend/${schema.ns}/fixture/${base}.*`, { ns, ignoreError: true })
24
23
  if (isArray(extend) && !isEmpty(extend)) items.push(...extend)
25
24
  })
26
25
  if (isEmpty(items)) return result
@@ -33,7 +33,7 @@ async function handler ({ file, alias, ns }) {
33
33
  if ((mod.properties ?? []).length === 0) this.fatal('Schema \'%s\' doesn\'t have properties at all', mod.name)
34
34
  // schema extender
35
35
  await eachPlugins(async function (opts) {
36
- const glob = `${opts.dir}/dobo/extend/schema/${mod.name}.*`
36
+ const glob = `${opts.dir}/dobo/extend/${mod.ns}/schema/${base}.*`
37
37
  const files = await fastGlob(glob)
38
38
  for (const file of files) {
39
39
  const extender = await readConfig(file, { ns: opts.ns, ignoreError: true })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Database ORM/ODM for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {