dobo 1.0.2 → 1.0.4
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/bajo/.alias +1 -0
- package/bajo/config.json +12 -2
- package/bajo/init.js +14 -3
- package/bajo/method/attachment/create.js +1 -1
- package/bajo/method/attachment/get-path.js +1 -1
- package/bajo/method/attachment/get.js +1 -1
- package/bajo/method/attachment/remove.js +1 -1
- package/bajo/method/build-query.js +1 -0
- package/bajo/method/bulk/create.js +6 -6
- package/bajo/method/get-connection.js +6 -0
- package/bajo/method/get-info.js +2 -2
- package/bajo/method/get-schema.js +2 -2
- package/bajo/method/model/clear.js +7 -5
- package/bajo/method/model/create.js +10 -2
- package/bajo/method/model/drop.js +10 -2
- package/bajo/method/model/exists.js +9 -2
- package/bajo/method/pick-record.js +14 -8
- package/bajo/method/prep-pagination.js +5 -9
- package/bajo/method/record/clear.js +8 -7
- package/bajo/method/record/create.js +26 -28
- package/bajo/method/record/find-one.js +10 -9
- package/bajo/method/record/find.js +11 -9
- package/bajo/method/record/get.js +10 -9
- package/bajo/method/record/remove.js +13 -12
- package/bajo/method/record/update.js +22 -25
- package/bajo/method/record/upsert.js +4 -3
- package/bajo/method/sanitize/body.js +8 -9
- package/bajo/method/stat/aggregate.js +6 -6
- package/bajo/method/stat/histogram.js +5 -5
- package/bajo/method/validate.js +23 -20
- package/bajo/start.js +6 -2
- package/bajoCli/applet/connection.js +1 -1
- package/bajoCli/applet/lib/post-process.js +13 -13
- package/bajoCli/applet/model-clear.js +2 -2
- package/bajoCli/applet/model-rebuild.js +12 -9
- package/bajoCli/applet/record-create.js +2 -2
- package/bajoCli/applet/record-find.js +2 -2
- package/bajoCli/applet/record-get.js +2 -2
- package/bajoCli/applet/record-remove.js +2 -2
- package/bajoCli/applet/record-update.js +2 -2
- package/bajoCli/applet/schema.js +1 -1
- package/bajoCli/applet/stat-count.js +2 -2
- package/bajoI18N/resource/en-US.json +28 -27
- package/bajoI18N/resource/id.json +60 -27
- package/lib/add-fixtures.js +5 -4
- package/lib/check-unique.js +2 -2
- package/lib/collect-connections.js +3 -4
- package/lib/collect-drivers.js +11 -3
- package/lib/collect-feature.js +6 -5
- package/lib/collect-schemas.js +9 -8
- package/lib/exec-validation.js +8 -14
- package/lib/generic-prop-sanitizer.js +1 -1
- package/lib/mem-db/conn-sanitizer.js +8 -0
- package/lib/mem-db/instantiate.js +41 -0
- package/lib/mem-db/method/model/clear.js +6 -0
- package/lib/mem-db/method/model/create.js +5 -0
- package/lib/mem-db/method/model/drop.js +5 -0
- package/lib/mem-db/method/model/exists.js +5 -0
- package/lib/mem-db/method/record/create.js +12 -0
- package/lib/mem-db/method/record/find.js +20 -0
- package/lib/mem-db/method/record/get.js +9 -0
- package/lib/mem-db/method/record/remove.js +13 -0
- package/lib/mem-db/method/record/update.js +15 -0
- package/lib/mem-db/method/stat/count.js +11 -0
- package/lib/mem-db/start.js +25 -0
- package/lib/resolve-method.js +4 -3
- package/lib/sanitize-schema.js +21 -9
- package/package.json +4 -3
- package/bajo/hook/bajoI18N@before-init.js +0 -6
- package/bajoCli/applet/shell.js +0 -48
- /package/bajo/hook/{bajoI18N.db@before-resource-merge.js → bajo-i18n.db@before-resource-merge.js} +0 -0
package/lib/sanitize-schema.js
CHANGED
|
@@ -5,7 +5,7 @@ async function sanitizeFeature (item) {
|
|
|
5
5
|
for (const f of item.feature) {
|
|
6
6
|
const feature = get(this.feature, f.name) // source from collectFeature
|
|
7
7
|
if (!feature) this.fatal('Unknown feature \'%s@%s\'', f.name, item.name)
|
|
8
|
-
let [ns, path] = f.name.split('
|
|
8
|
+
let [ns, path] = f.name.split('.')
|
|
9
9
|
if (!path) ns = this.name
|
|
10
10
|
const input = await feature.call(this.app[ns], f)
|
|
11
11
|
let props = input.properties
|
|
@@ -35,8 +35,8 @@ async function sanitizeFullText (item) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
async function sanitizeSchema (items) {
|
|
38
|
-
const { freeze, fatal, importModule, defaultsDeep, join, breakNsPath } = this.app.bajo
|
|
39
|
-
const { map, keys, findIndex, find, each, isString, get, isPlainObject } = this.app.bajo.lib._
|
|
38
|
+
const { freeze, fatal, importModule, defaultsDeep, join, breakNsPath, runHook } = this.app.bajo
|
|
39
|
+
const { map, keys, findIndex, find, each, isString, get, isPlainObject, camelCase, uniq, filter } = this.app.bajo.lib._
|
|
40
40
|
const properties = keys(this.propType)
|
|
41
41
|
const schemas = []
|
|
42
42
|
this.log.debug('Loading DB schemas')
|
|
@@ -44,13 +44,14 @@ async function sanitizeSchema (items) {
|
|
|
44
44
|
this.log.trace('- %s (%d)', k, keys(items[k]).length)
|
|
45
45
|
for (const f in items[k]) {
|
|
46
46
|
const item = items[k][f]
|
|
47
|
+
await runHook(`dobo.${camelCase(item.name)}:beforeSanitizeSchema`, item)
|
|
47
48
|
const conn = find(this.connections, { name: item.connection })
|
|
48
49
|
if (!conn) fatal.call(this, 'Unknown connection \'%s@%s\'', item.name, item.connection)
|
|
49
50
|
item.fullText = item.fullText ?? { fields: [] }
|
|
50
51
|
item.indexes = item.indexes ?? []
|
|
51
|
-
const
|
|
52
|
+
const { ns, path: type } = breakNsPath(conn.type)
|
|
52
53
|
const driver = find(this.drivers, { type, ns, driver: conn.driver })
|
|
53
|
-
if (driver.lowerCaseColl) item.
|
|
54
|
+
if (driver.lowerCaseColl) item.name = item.name.toLowerCase()
|
|
54
55
|
let file = `${ns}:/${this.name}/lib/${type}/prop-sanitizer.js`
|
|
55
56
|
let propSanitizer = await importModule(file)
|
|
56
57
|
if (!propSanitizer) propSanitizer = genericPropSanitizer
|
|
@@ -75,10 +76,8 @@ async function sanitizeSchema (items) {
|
|
|
75
76
|
item.feature = item.feature ?? []
|
|
76
77
|
await sanitizeFeature.call(this, item)
|
|
77
78
|
item.disabled = item.disabled ?? []
|
|
78
|
-
if (item.
|
|
79
|
-
|
|
80
|
-
delete item.readonly
|
|
81
|
-
}
|
|
79
|
+
if (item.disabled === 'all') item.disabled = ['find', 'get', 'create', 'update', 'remove']
|
|
80
|
+
else if (item.disabled === 'readonly') item.disabled = ['create', 'update', 'remove']
|
|
82
81
|
for (const idx in item.properties) {
|
|
83
82
|
let prop = item.properties[idx]
|
|
84
83
|
if (!prop.type) {
|
|
@@ -132,6 +131,8 @@ async function sanitizeSchema (items) {
|
|
|
132
131
|
}
|
|
133
132
|
for (const i in schemas) {
|
|
134
133
|
const schema = schemas[i]
|
|
134
|
+
const sortables = []
|
|
135
|
+
const hidden = []
|
|
135
136
|
for (const i2 in schema.properties) {
|
|
136
137
|
const prop = schema.properties[i2]
|
|
137
138
|
if (prop.type !== 'string') delete prop.maxLength
|
|
@@ -169,8 +170,19 @@ async function sanitizeSchema (items) {
|
|
|
169
170
|
}
|
|
170
171
|
// TODO: propSanitizer must be called again
|
|
171
172
|
}
|
|
173
|
+
if (prop.hidden) hidden.push(prop.name)
|
|
174
|
+
if (prop.index) sortables.push(prop.name)
|
|
175
|
+
delete prop.hidden
|
|
172
176
|
schema.properties[i2] = prop
|
|
173
177
|
}
|
|
178
|
+
// sortables
|
|
179
|
+
each(schema.indexes, item => {
|
|
180
|
+
sortables.push(...item.fields)
|
|
181
|
+
})
|
|
182
|
+
// hidden
|
|
183
|
+
schema.hidden = uniq(filter((schema.hidden ?? []).concat(hidden), item => map(schema.properties, 'name').includes(item)))
|
|
184
|
+
schema.sortables = sortables
|
|
185
|
+
await runHook(`dobo.${camelCase(schema.name)}:afterSanitizeSchema`, schema)
|
|
174
186
|
}
|
|
175
187
|
this.schemas = schemas
|
|
176
188
|
freeze(this.schemas)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dobo",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Database ORM/ODM for Bajo Framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/ardhi/dobo#readme",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@tryghost/nql": "^0.12.
|
|
30
|
-
"joi": "^17.13.3"
|
|
29
|
+
"@tryghost/nql": "^0.12.7",
|
|
30
|
+
"joi": "^17.13.3",
|
|
31
|
+
"mingo": "^6.5.1"
|
|
31
32
|
}
|
|
32
33
|
}
|
package/bajoCli/applet/shell.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
const mods = [
|
|
2
|
-
{ method: 'recordFind' },
|
|
3
|
-
{ method: 'recordGet' },
|
|
4
|
-
{ method: 'recordCreate' },
|
|
5
|
-
{ method: 'recordUpdate' },
|
|
6
|
-
{ method: 'recordRemove' },
|
|
7
|
-
'-',
|
|
8
|
-
{ method: 'modelRebuild' },
|
|
9
|
-
'-',
|
|
10
|
-
{ method: 'schema' },
|
|
11
|
-
{ method: 'connection' },
|
|
12
|
-
'-',
|
|
13
|
-
{ method: 'quit' },
|
|
14
|
-
'-'
|
|
15
|
-
]
|
|
16
|
-
|
|
17
|
-
async function shell ({ path, args, options }) {
|
|
18
|
-
const { importPkg, importModule, resolvePath, currentLoc } = this.app.bajo
|
|
19
|
-
const prompts = await importPkg('bajoCli:@inquirer/prompts')
|
|
20
|
-
const { map, find, repeat, kebabCase } = this.app.bajo.lib._
|
|
21
|
-
const { select, Separator, confirm } = prompts
|
|
22
|
-
const choices = map(mods, m => m === '-' ? new Separator() : ({ value: m.method }))
|
|
23
|
-
const dir = currentLoc(import.meta).dir
|
|
24
|
-
for (;;) {
|
|
25
|
-
const method = await select({
|
|
26
|
-
message: this.print.write('Select method:'),
|
|
27
|
-
choices
|
|
28
|
-
})
|
|
29
|
-
if (method === 'quit') {
|
|
30
|
-
const answer = await confirm({
|
|
31
|
-
message: this.print.write('Are you sure to quit?')
|
|
32
|
-
})
|
|
33
|
-
if (!answer) continue
|
|
34
|
-
this.print.info('Quitting now, have a nice day!')
|
|
35
|
-
process.kill(process.pid, 'SIGINT')
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
console.log(repeat('-', 80))
|
|
39
|
-
this.print.info('Running: %s', method)
|
|
40
|
-
const mod = find(mods, { method })
|
|
41
|
-
const file = `${dir}/${kebabCase(mod.method)}.js`
|
|
42
|
-
const instance = await importModule(resolvePath(file))
|
|
43
|
-
await instance.call(this, method, [])
|
|
44
|
-
console.log(repeat('-', 80))
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export default shell
|
/package/bajo/hook/{bajoI18N.db@before-resource-merge.js → bajo-i18n.db@before-resource-merge.js}
RENAMED
|
File without changes
|