dobo 1.2.9 → 2.0.0

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.
Files changed (61) hide show
  1. package/index.js +2 -2
  2. package/lib/add-fixtures.js +4 -3
  3. package/lib/build-bulk-action.js +1 -1
  4. package/lib/collect-connections.js +2 -2
  5. package/lib/collect-drivers.js +2 -1
  6. package/lib/collect-feature.js +2 -1
  7. package/lib/collect-schemas.js +8 -6
  8. package/lib/multi-rel-rows.js +1 -1
  9. package/lib/resolve-method.js +1 -1
  10. package/lib/sanitize-schema.js +2 -2
  11. package/package.json +1 -1
  12. /package/{bajo → extend/bajo}/intl/en-US.json +0 -0
  13. /package/{bajo → extend/bajo}/intl/id.json +0 -0
  14. /package/{bajoCli → extend/bajoCli}/applet/connection.js +0 -0
  15. /package/{bajoCli → extend/bajoCli}/applet/lib/post-process.js +0 -0
  16. /package/{bajoCli → extend/bajoCli}/applet/model-clear.js +0 -0
  17. /package/{bajoCli → extend/bajoCli}/applet/model-rebuild.js +0 -0
  18. /package/{bajoCli → extend/bajoCli}/applet/record-create.js +0 -0
  19. /package/{bajoCli → extend/bajoCli}/applet/record-find.js +0 -0
  20. /package/{bajoCli → extend/bajoCli}/applet/record-get.js +0 -0
  21. /package/{bajoCli → extend/bajoCli}/applet/record-remove.js +0 -0
  22. /package/{bajoCli → extend/bajoCli}/applet/record-update.js +0 -0
  23. /package/{bajoCli → extend/bajoCli}/applet/schema.js +0 -0
  24. /package/{bajoCli → extend/bajoCli}/applet/stat-count.js +0 -0
  25. /package/{bajoCli → extend/bajoCli}/applet.js +0 -0
  26. /package/{dobo → extend/dobo}/feature/created-at.js +0 -0
  27. /package/{dobo → extend/dobo}/feature/dt.js +0 -0
  28. /package/{dobo → extend/dobo}/feature/int-id.js +0 -0
  29. /package/{dobo → extend/dobo}/feature/removed-at.js +0 -0
  30. /package/{dobo → extend/dobo}/feature/updated-at.js +0 -0
  31. /package/{waibuMpa → extend/waibuMpa}/route/attachment/@model/@id/@field/@file.js +0 -0
  32. /package/{waibuStatic → extend/waibuStatic}/virtual.json +0 -0
  33. /package/{plugin-method → method}/attachment/copy-uploaded.js +0 -0
  34. /package/{plugin-method → method}/attachment/create.js +0 -0
  35. /package/{plugin-method → method}/attachment/find.js +0 -0
  36. /package/{plugin-method → method}/attachment/get-path.js +0 -0
  37. /package/{plugin-method → method}/attachment/get.js +0 -0
  38. /package/{plugin-method → method}/attachment/pre-check.js +0 -0
  39. /package/{plugin-method → method}/attachment/remove.js +0 -0
  40. /package/{plugin-method → method}/attachment/update.js +0 -0
  41. /package/{plugin-method → method}/bulk/create.js +0 -0
  42. /package/{plugin-method → method}/model/clear.js +0 -0
  43. /package/{plugin-method → method}/model/create.js +0 -0
  44. /package/{plugin-method → method}/model/drop.js +0 -0
  45. /package/{plugin-method → method}/model/exists.js +0 -0
  46. /package/{plugin-method → method}/record/clear.js +0 -0
  47. /package/{plugin-method → method}/record/count.js +0 -0
  48. /package/{plugin-method → method}/record/create.js +0 -0
  49. /package/{plugin-method → method}/record/find-all.js +0 -0
  50. /package/{plugin-method → method}/record/find-one.js +0 -0
  51. /package/{plugin-method → method}/record/find.js +0 -0
  52. /package/{plugin-method → method}/record/get.js +0 -0
  53. /package/{plugin-method → method}/record/remove.js +0 -0
  54. /package/{plugin-method → method}/record/update.js +0 -0
  55. /package/{plugin-method → method}/record/upsert.js +0 -0
  56. /package/{plugin-method → method}/sanitize/body.js +0 -0
  57. /package/{plugin-method → method}/sanitize/date.js +0 -0
  58. /package/{plugin-method → method}/sanitize/id.js +0 -0
  59. /package/{plugin-method → method}/stat/aggregate.js +0 -0
  60. /package/{plugin-method → method}/stat/histogram.js +0 -0
  61. /package/{plugin-method → method}/validate.js +0 -0
package/index.js CHANGED
@@ -10,7 +10,7 @@ import path from 'path'
10
10
  async function factory (pkgName) {
11
11
  const me = this
12
12
 
13
- return class Dobo extends this.lib.BajoPlugin {
13
+ return class Dobo extends this.lib.Plugin {
14
14
  constructor () {
15
15
  super(pkgName, me.app)
16
16
  this.alias = 'db'
@@ -127,7 +127,7 @@ async function factory (pkgName) {
127
127
  for (const c of conns) {
128
128
  const { ns } = breakNsPath(c.type)
129
129
  const schemas = filter(this.schemas, { connection: c.name })
130
- const mod = c.type === 'dobo:memory' ? memDbInstantiate : await importModule(`${ns}:/${this.name}/boot/instantiate.js`)
130
+ const mod = c.type === 'dobo:memory' ? memDbInstantiate : await importModule(`${ns}:/extend/${this.name}/boot/instantiate.js`)
131
131
  await mod.call(this.app[ns], { connection: c, noRebuild, schemas })
132
132
  this.log.trace('driverInstantiated%s%s', c.driver, c.name)
133
133
  }
@@ -16,12 +16,13 @@ async function addFixture (name, { spinner } = {}) {
16
16
  let items = await readConfig(pattern, { ns: schema.ns, ignoreError: true })
17
17
  if (isEmpty(items)) items = []
18
18
  // override
19
- const overrides = await readConfig(`${this.app.main.dir.pkg}/dobo/override/${schema.ns}/fixture/${base}.*`, { ns: this.name, ignoreError: true })
19
+ const overrides = await readConfig(`${this.app.main.dir.pkg}/extend/dobo/override/${schema.ns}/fixture/${base}.*`, { ns: this.name, ignoreError: true })
20
20
 
21
21
  if (isArray(overrides) && !isEmpty(overrides)) items = overrides
22
22
  // extend
23
- await eachPlugins(async function ({ dir, ns }) {
24
- const extend = await readConfig(`${dir}/dobo/extend/${schema.ns}/fixture/${base}.*`, { ns, ignoreError: true })
23
+ await eachPlugins(async function ({ dir }) {
24
+ const { name: ns } = this
25
+ const extend = await readConfig(`${dir}/extend/dobo/extend/${schema.ns}/fixture/${base}.*`, { ns, ignoreError: true })
25
26
  if (isArray(extend) && !isEmpty(extend)) items.push(...extend)
26
27
  })
27
28
  if (isEmpty(items)) return result
@@ -3,7 +3,7 @@ async function buildBulkAction (name, action, options = {}) {
3
3
  const { camelCase } = this.lib._
4
4
  const { schema, driver, connection } = await this.getInfo(name)
5
5
  if (!options.force && (schema.disabled ?? []).includes(action)) throw this.error('methodIsDisabled%s%s', camelCase('bulk ' + action), name)
6
- const file = `${driver.plugin}:/${this.name}/method/bulk/${action}.js`
6
+ const file = `${driver.plugin}:/extend/${this.name}/method/bulk/${action}.js`
7
7
  if (!fs.existsSync(file)) throw this.error('methodUnsupported%s%s', camelCase('bulk ' + action), name)
8
8
  const handler = await importModule(file)
9
9
  return { handler, schema, driver, connection }
@@ -11,9 +11,9 @@ async function collectConnections ({ item, index, options }) {
11
11
  if (isEmpty(type)) type = conn.type
12
12
  const driver = find(this.drivers, { ns, type })
13
13
  if (!driver) this.fatal('unsupportedDbType%s', conn.type)
14
- let file = `${ns}:/${this.name}/lib/${type}/conn-sanitizer.js`
14
+ let file = `${ns}:/extend/${this.name}/lib/${type}/conn-sanitizer.js`
15
15
  if (conn.type === 'dobo:memory') file = `${ns}:/lib/mem-db/conn-sanitizer.js`
16
- if (driver.provider) file = `${driver.provider}:/${ns}/lib/${type}/conn-sanitizer.js`
16
+ if (driver.provider) file = `${driver.provider}:/extend/${ns}/lib/${type}/conn-sanitizer.js`
17
17
  let sanitizer = await importModule(file)
18
18
  if (!sanitizer) sanitizer = defSanitizer
19
19
  const result = await sanitizer.call(this, conn)
@@ -12,7 +12,8 @@ async function collectDrivers () {
12
12
  })
13
13
  // others
14
14
  await runHook(`${this.name}:beforeCollectDrivers`)
15
- await eachPlugins(async function ({ file, ns }) {
15
+ await eachPlugins(async function ({ file }) {
16
+ const { name: ns } = this
16
17
  const info = await readConfig(file, { ns })
17
18
  if (!info.type) this.fatal('driverMustProvideDbType')
18
19
  if (!info.driver) this.fatal('driverMustHaveName')
@@ -1,6 +1,7 @@
1
1
  import path from 'path'
2
2
 
3
- async function handler ({ file, alias, ns }) {
3
+ async function handler ({ file }) {
4
+ const { name: ns } = this
4
5
  const { importModule } = this.app.bajo
5
6
  const { camelCase, isFunction } = this.lib._
6
7
  const me = this.app.dobo
@@ -1,7 +1,8 @@
1
1
  import path from 'path'
2
2
  import sanitizeSchema from './sanitize-schema.js'
3
3
 
4
- async function handler ({ file, alias, ns }) {
4
+ async function handler ({ file }) {
5
+ const { name: ns, alias } = this
5
6
  const { readConfig, eachPlugins } = this.app.bajo
6
7
  const { pascalCase } = this.lib.aneka
7
8
  const { get, isPlainObject, each, find, has, isArray, forOwn, isString, merge } = this.lib._
@@ -35,11 +36,12 @@ async function handler ({ file, alias, ns }) {
35
36
  mod.properties = mod.properties ?? []
36
37
  // if ((mod.properties ?? []).length === 0) this.fatal('noPropsFoundOnSchema%s', mod.name)
37
38
  // schema extender
38
- await eachPlugins(async function (opts) {
39
- const glob = `${opts.dir}/dobo/extend/${mod.ns}/schema/${base}.*`
39
+ await eachPlugins(async function ({ dir }) {
40
+ const { name: ns } = this
41
+ const glob = `${dir}/extend/dobo/extend/${mod.ns}/schema/${base}.*`
40
42
  const files = await fastGlob(glob)
41
43
  for (const file of files) {
42
- const extender = await readConfig(file, { ns: opts.ns, ignoreError: true })
44
+ const extender = await readConfig(file, { ns, ignoreError: true })
43
45
  if (!isPlainObject(extender)) return undefined
44
46
  each(extender.properties ?? [], p => {
45
47
  if (isString(p) && mod.properties.includes(p)) return undefined
@@ -58,13 +60,13 @@ async function handler ({ file, alias, ns }) {
58
60
  })
59
61
  }
60
62
  if (feats.length > 0) mod.feature.push(...feats)
61
- if (opts.plugin === this.app.bajo.mainNs) {
63
+ if (ns === this.app.bajo.mainNs) {
62
64
  each(['connection', 'name'], i => {
63
65
  if (has(extender, i)) mod[i] = extender[i]
64
66
  })
65
67
  }
66
68
  mod.extender = mod.extender ?? []
67
- mod.extender.push(opts.plugin)
69
+ mod.extender.push(ns)
68
70
  }
69
71
  })
70
72
  return mod
@@ -30,7 +30,7 @@ async function multiRelRows ({ schema, records, options = {} }) {
30
30
  for (const i in records) {
31
31
  records[i]._rel = records[i]._rel ?? {}
32
32
  const rec = records[i]
33
- const res = results.find(r => (r[val.propName] + '') === rec[prop.name])
33
+ const res = results.find(r => (r[val.propName] + '') === rec[prop.name] + '')
34
34
  if (res) records[i]._rel[key] = await this.pickRecord({ record: res, fields, schema: relschema })
35
35
  else records[i]._rel[key] = {}
36
36
  }
@@ -7,7 +7,7 @@ async function resolveMethod (name, method, options = {}) {
7
7
  if (!options.force && (schema.disabled ?? []).includes(action)) throw this.error('methodIsDisabled%s%s', camelCase(method), name)
8
8
  let file
9
9
  if (connection.name === 'memory') file = `${this.app[driver.ns].dir.pkg}/lib/mem-db/method/${group}/${action}.js`
10
- else file = `${this.app[driver.ns].dir.pkg}/${this.name}/method/${group}/${action}.js`
10
+ else file = `${this.app[driver.ns].dir.pkg}/extend/${this.name}/method/${group}/${action}.js`
11
11
  if (!fs.existsSync(file)) throw this.error('methodUnsupported%s%s', camelCase(method), name)
12
12
  const handler = await importModule(file)
13
13
  return { handler, schema, driver, connection }
@@ -57,7 +57,7 @@ async function sanitizeSchema (items) {
57
57
  if (isEmpty(type)) type = conn.type
58
58
  const driver = find(this.drivers, { type, ns, driver: conn.driver })
59
59
  if (driver.lowerCaseModel) item.name = item.name.toLowerCase()
60
- let file = `${ns}:/${this.name}/lib/${type}/prop-sanitizer.js`
60
+ let file = `${ns}:/extend/${this.name}/lib/${type}/prop-sanitizer.js`
61
61
  let propSanitizer = await importModule(file)
62
62
  if (!propSanitizer) propSanitizer = genericPropSanitizer
63
63
  for (const idx in item.properties) {
@@ -128,7 +128,7 @@ async function sanitizeSchema (items) {
128
128
  if (!all.includes(p.name)) all.push(p.name)
129
129
  else fatal.call(this, 'Field \'%s@%s\' should be used only once', p.name, item.name)
130
130
  })
131
- file = `${ns}:/${this.name}/lib/${type}/schema-sanitizer.js`
131
+ file = `${ns}:/extend/${this.name}/lib/${type}/schema-sanitizer.js`
132
132
  const schemaSanitizer = await importModule(file)
133
133
  if (schemaSanitizer) await schemaSanitizer.call(this, { schema: item, connection: conn, driver })
134
134
  schemas.push(item)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo",
3
- "version": "1.2.9",
3
+ "version": "2.0.0",
4
4
  "description": "Database ORM/ODM for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes