dobo 1.0.12 → 1.0.14
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/init.js +2 -2
- package/bajo/method/attachment/copy-uploaded.js +2 -2
- package/bajo/method/attachment/create.js +2 -2
- package/bajo/method/attachment/remove.js +1 -1
- package/bajo/method/get-schema.js +1 -1
- package/bajo/method/model/exists.js +1 -1
- package/bajo/method/prep-pagination.js +1 -1
- package/bajo/method/record/create.js +1 -1
- package/bajo/method/record/remove.js +1 -1
- package/bajo/method/record/update.js +1 -1
- package/bajo/method/sanitize/date.js +1 -1
- package/bajo/method/stat/histogram.js +1 -1
- package/bajo/method/validate.js +1 -1
- package/bajo/start.js +1 -1
- package/bajoCli/applet/connection.js +4 -4
- package/bajoCli/applet/lib/post-process.js +5 -5
- package/bajoCli/applet/model-clear.js +1 -1
- package/bajoCli/applet/model-rebuild.js +14 -14
- package/bajoCli/applet/record-create.js +6 -6
- package/bajoCli/applet/record-find.js +3 -3
- package/bajoCli/applet/record-get.js +1 -1
- package/bajoCli/applet/record-remove.js +1 -1
- package/bajoCli/applet/record-update.js +8 -8
- package/bajoCli/applet/schema.js +4 -4
- package/bajoCli/applet/stat-count.js +3 -3
- package/bajoI18N/resource/en-US.json +157 -27
- package/bajoI18N/resource/id.json +125 -75
- package/lib/add-fixtures.js +5 -5
- package/lib/build-bulk-action.js +2 -2
- package/lib/check-unique.js +2 -2
- package/lib/collect-connections.js +2 -2
- package/lib/collect-drivers.js +3 -3
- package/lib/collect-feature.js +3 -3
- package/lib/collect-schemas.js +3 -3
- package/lib/generic-prop-sanitizer.js +2 -9
- package/lib/mem-db/instantiate.js +1 -1
- package/lib/mem-db/method/record/create.js +1 -1
- package/lib/mem-db/method/record/get.js +1 -1
- package/lib/mem-db/start.js +2 -2
- package/lib/resolve-method.js +2 -2
- package/lib/sanitize-schema.js +5 -5
- package/package.json +1 -1
package/bajo/init.js
CHANGED
|
@@ -6,7 +6,7 @@ import collectSchemas from '../lib/collect-schemas.js'
|
|
|
6
6
|
async function checkType (item, items) {
|
|
7
7
|
const { filter } = this.app.bajo.lib._
|
|
8
8
|
const existing = filter(items, { type: 'dobo:memory' })
|
|
9
|
-
if (existing.length > 1) this.fatal('
|
|
9
|
+
if (existing.length > 1) this.fatal('onlyOneConnType%s', item.type)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
async function init () {
|
|
@@ -21,7 +21,7 @@ async function init () {
|
|
|
21
21
|
})
|
|
22
22
|
}
|
|
23
23
|
this.connections = await buildCollections({ ns: this.name, container: 'connections', handler: collectConnections, dupChecks: ['name', checkType] })
|
|
24
|
-
if (this.connections.length === 0) this.log.warn('
|
|
24
|
+
if (this.connections.length === 0) this.log.warn('notFound%s', this.print.write('connection'))
|
|
25
25
|
await collectFeature.call(this)
|
|
26
26
|
await collectSchemas.call(this)
|
|
27
27
|
}
|
|
@@ -5,11 +5,11 @@ async function copyUploaded (name, id, { req, setField, setFile, mimeType, stats
|
|
|
5
5
|
name = this.attachmentPreCheck(name)
|
|
6
6
|
if (!name) {
|
|
7
7
|
if (silent) return
|
|
8
|
-
throw this.error('
|
|
8
|
+
throw this.error('isMissing%s', this.print.write('field.name'))
|
|
9
9
|
}
|
|
10
10
|
if (!this.bajoWeb) {
|
|
11
11
|
if (silent) return
|
|
12
|
-
throw this.error('
|
|
12
|
+
throw this.error('missingPlugin%s')
|
|
13
13
|
}
|
|
14
14
|
const { dir, files } = await this.bajoWeb.getUploadedFiles(req.id, false, true)
|
|
15
15
|
const result = []
|
|
@@ -5,7 +5,7 @@ async function create (name, id, options = {}) {
|
|
|
5
5
|
name = this.attachmentPreCheck(name)
|
|
6
6
|
if (!name) return
|
|
7
7
|
const { source, field, file } = options
|
|
8
|
-
if (!source) throw this.error('
|
|
8
|
+
if (!source) throw this.error('isMissing%s', this.print.write('field.source'))
|
|
9
9
|
const baseDir = await this.attachmentGetPath(name, id, field, file, { dirOnly: true })
|
|
10
10
|
const { fullPath, stats, mimeType, req } = options
|
|
11
11
|
|
|
@@ -20,7 +20,7 @@ async function create (name, id, options = {}) {
|
|
|
20
20
|
file
|
|
21
21
|
}
|
|
22
22
|
await mergeAttachmentInfo.call(this, rec, dest, { mimeType, fullPath, stats })
|
|
23
|
-
if (req && req.flash) req.flash('notify', req.t('
|
|
23
|
+
if (req && req.flash) req.flash('notify', req.t('attachmentUploaded'))
|
|
24
24
|
return rec
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -5,7 +5,7 @@ async function remove (name, id, field, file, options = {}) {
|
|
|
5
5
|
const path = await this.attachmentGetPath(name, id, field, file)
|
|
6
6
|
const { req } = options
|
|
7
7
|
await fs.remove(path)
|
|
8
|
-
if (req && req.flash) req.flash('notify', req.t('
|
|
8
|
+
if (req && req.flash) req.flash('notify', req.t('attachmentRemoved'))
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export default remove
|
|
@@ -3,7 +3,7 @@ function getSchema (input, cloned = true) {
|
|
|
3
3
|
let name = isPlainObject(input) ? input.name : input
|
|
4
4
|
name = this.app.bajo.pascalCase(name)
|
|
5
5
|
const schema = find(this.schemas, { name })
|
|
6
|
-
if (!schema) throw this.error('
|
|
6
|
+
if (!schema) throw this.error('unknownModelSchema%s', name)
|
|
7
7
|
return cloned ? cloneDeep(schema) : schema
|
|
8
8
|
}
|
|
9
9
|
|
|
@@ -16,7 +16,7 @@ async function exists (name, thrown, options = {}) {
|
|
|
16
16
|
await runHook(`${this.name}.${camelCase(name)}:afterModelExists`, exist, options)
|
|
17
17
|
await runHook(`${this.name}:afterModelExists`, schema, exist, options)
|
|
18
18
|
}
|
|
19
|
-
if (!exist && thrown) throw this.error('
|
|
19
|
+
if (!exist && thrown) throw this.error('modelNotExists%s')
|
|
20
20
|
cache[name] = exist
|
|
21
21
|
return exist
|
|
22
22
|
}
|
|
@@ -42,7 +42,7 @@ function buildSort (input, schema, allowSortUnindexed) {
|
|
|
42
42
|
if (schema) {
|
|
43
43
|
const items = keys(sort)
|
|
44
44
|
each(items, i => {
|
|
45
|
-
if (!schema.sortables.includes(i) && !allowSortUnindexed) throw this.error('
|
|
45
|
+
if (!schema.sortables.includes(i) && !allowSortUnindexed) throw this.error('sortOnUnindexedField%s%s', i, schema.name)
|
|
46
46
|
// if (schema.fullText.fields.includes(i)) throw this.error('Can\'t sort on full-text index: \'%s@%s\'', i, schema.name)
|
|
47
47
|
})
|
|
48
48
|
}
|
|
@@ -50,7 +50,7 @@ async function create (name, input, opts = {}) {
|
|
|
50
50
|
record = await handler.call(this.app[driver.ns], { schema, body: nbody, options })
|
|
51
51
|
if (options.req) {
|
|
52
52
|
if (options.req.file) await handleAttachmentUpload.call(this, { name: schema.name, id: body.id, body, options, action: 'create' })
|
|
53
|
-
if (options.req.flash && !options.noFlash) options.req.flash('notify', options.req.t('
|
|
53
|
+
if (options.req.flash && !options.noFlash) options.req.flash('notify', options.req.t('recordCreated'))
|
|
54
54
|
}
|
|
55
55
|
if (!noFeatureHook) await execFeatureHook.call(this, 'afterCreate', { schema, body, record })
|
|
56
56
|
if (!noHook) {
|
|
@@ -20,7 +20,7 @@ async function remove (name, id, opts = {}) {
|
|
|
20
20
|
const record = await handler.call(this.app[driver.ns], { schema, id, options })
|
|
21
21
|
if (options.req) {
|
|
22
22
|
if (options.req.file) await handleAttachmentUpload.call(this, { name: schema.name, id, options, action: 'remove' })
|
|
23
|
-
if (options.req.flash && !options.noFlash) options.req.flash('notify', options.req.t('
|
|
23
|
+
if (options.req.flash && !options.noFlash) options.req.flash('notify', options.req.t('recordRemoved'))
|
|
24
24
|
}
|
|
25
25
|
if (!noHook) {
|
|
26
26
|
await runHook(`${this.name}.${camelCase(name)}:afterRecordRemove`, id, options, record)
|
|
@@ -40,7 +40,7 @@ async function update (name, id, input, opts = {}) {
|
|
|
40
40
|
const record = await handler.call(this.app[driver.ns], { schema, id, body: nbody, options })
|
|
41
41
|
if (options.req) {
|
|
42
42
|
if (options.req.file) await handleAttachmentUpload.call(this, { name: schema.name, id, body, options, action: 'update' })
|
|
43
|
-
if (options.req.flash && !options.noFlash) options.req.flash('notify', options.req.t('
|
|
43
|
+
if (options.req.flash && !options.noFlash) options.req.flash('notify', options.req.t('recordUpdated'))
|
|
44
44
|
}
|
|
45
45
|
if (!noFeatureHook) await execFeatureHook.call(this, 'afterUpdate', { schema, body: nbody, record })
|
|
46
46
|
if (!noHook) {
|
|
@@ -5,7 +5,7 @@ function sanitizeDate (value, { input, output, silent = true } = {}) {
|
|
|
5
5
|
const dt = dayjs(value, input)
|
|
6
6
|
if (!dt.isValid()) {
|
|
7
7
|
if (silent) return -1
|
|
8
|
-
throw this.error('
|
|
8
|
+
throw this.error('invalidDate')
|
|
9
9
|
}
|
|
10
10
|
if (output === 'native' || !output) return dt.toDate()
|
|
11
11
|
return dt.format(output)
|
|
@@ -6,7 +6,7 @@ async function histogram (name, filter = {}, options = {}) {
|
|
|
6
6
|
const { runHook, join } = this.app.bajo
|
|
7
7
|
const { dataOnly = true, noHook, type } = options
|
|
8
8
|
options.dataOnly = false
|
|
9
|
-
if (!types.includes(type)) throw this.error('
|
|
9
|
+
if (!types.includes(type)) throw this.error('histogramTypeMusBe%s', join(types))
|
|
10
10
|
await this.modelExists(name, true)
|
|
11
11
|
const { handler, schema, driver } = await resolveMethod.call(this, name, 'stat-histogram', options)
|
|
12
12
|
filter.query = await this.buildQuery({ filter, schema, options }) ?? {}
|
package/bajo/method/validate.js
CHANGED
|
@@ -150,7 +150,7 @@ async function validate (value, joiSchema, { ns, fields, extFields, params } = {
|
|
|
150
150
|
try {
|
|
151
151
|
return await joiSchema.validateAsync(value, params)
|
|
152
152
|
} catch (err) {
|
|
153
|
-
throw this.error('
|
|
153
|
+
throw this.error('validationError', { details: err.details, values: err.values, ns, statusCode: 422, code: 'DB_VALIDATION' })
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
|
package/bajo/start.js
CHANGED
|
@@ -12,7 +12,7 @@ async function start (conns = 'all', noRebuild = true) {
|
|
|
12
12
|
const schemas = filter(this.schemas, { connection: c.name })
|
|
13
13
|
const mod = c.type === 'dobo:memory' ? memDbInstantiate : await importModule(`${ns}:/${this.name}/boot/instantiate.js`)
|
|
14
14
|
await mod.call(this.app[ns], { connection: c, noRebuild, schemas })
|
|
15
|
-
this.log.trace('
|
|
15
|
+
this.log.trace('driverInstantiated%s%s', c.driver, c.name)
|
|
16
16
|
}
|
|
17
17
|
await memDbStart.call(this)
|
|
18
18
|
}
|
|
@@ -4,18 +4,18 @@ async function connection (path, ...args) {
|
|
|
4
4
|
const select = await importPkg('bajoCli:@inquirer/select')
|
|
5
5
|
const { getOutputFormat, writeOutput } = this.app.bajoCli
|
|
6
6
|
const format = getOutputFormat()
|
|
7
|
-
if (isEmpty(this.connections)) return this.print.fail('
|
|
7
|
+
if (isEmpty(this.connections)) return this.print.fail('notFound%s', 'connection', { exit: this.app.bajo.applet })
|
|
8
8
|
let name = args[0]
|
|
9
9
|
if (isEmpty(name)) {
|
|
10
10
|
const choices = map(this.connections, s => ({ value: s.name }))
|
|
11
11
|
name = await select({
|
|
12
|
-
message: this.print.write('
|
|
12
|
+
message: this.print.write('chooseConn'),
|
|
13
13
|
choices
|
|
14
14
|
})
|
|
15
15
|
}
|
|
16
16
|
const result = find(this.connections, { name })
|
|
17
|
-
if (!result) return this.print.fail('
|
|
18
|
-
this.print.info('
|
|
17
|
+
if (!result) return this.print.fail('cantFind%s%s', this.print.write('connection'), name, { exit: this.app.bajo.applet })
|
|
18
|
+
this.print.info('done')
|
|
19
19
|
await writeOutput(result, path, format)
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -9,12 +9,12 @@ async function postProcess ({ handler, params, path, processMsg, noConfirmation
|
|
|
9
9
|
params.push({ fields: this.config.fields, dataOnly: !this.config.full })
|
|
10
10
|
|
|
11
11
|
const schema = find(this.schemas, { name: params[0] })
|
|
12
|
-
if (!schema) return this.print.fatal('
|
|
12
|
+
if (!schema) return this.print.fatal('notFound%s', this.print.write('field.schema'))
|
|
13
13
|
let cont = true
|
|
14
14
|
if (!noConfirmation) {
|
|
15
|
-
const answer = await confirm({ message: this.print.write('
|
|
15
|
+
const answer = await confirm({ message: this.print.write('sureContinue'), default: false })
|
|
16
16
|
if (!answer) {
|
|
17
|
-
this.print.fail('
|
|
17
|
+
this.print.fail('aborted')
|
|
18
18
|
cont = false
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -27,7 +27,7 @@ async function postProcess ({ handler, params, path, processMsg, noConfirmation
|
|
|
27
27
|
}
|
|
28
28
|
try {
|
|
29
29
|
const resp = await this[handler](...params)
|
|
30
|
-
spin.succeed('
|
|
30
|
+
spin.succeed('done')
|
|
31
31
|
const result = this.config.pretty ? (await prettyPrint(resp)) : JSON.stringify(resp, null, 2)
|
|
32
32
|
if (this.config.save) {
|
|
33
33
|
const id = resp.id ?? get(resp, 'data.id') ?? get(resp, 'oldData.id')
|
|
@@ -39,7 +39,7 @@ async function postProcess ({ handler, params, path, processMsg, noConfirmation
|
|
|
39
39
|
if (this.config.log.applet) {
|
|
40
40
|
spin.stop()
|
|
41
41
|
console.error(err)
|
|
42
|
-
} else spin.fail('
|
|
42
|
+
} else spin.fail('error%s', err.message)
|
|
43
43
|
}
|
|
44
44
|
process.exit()
|
|
45
45
|
}
|
|
@@ -3,7 +3,7 @@ import postProcess from './lib/post-process.js'
|
|
|
3
3
|
async function modelClear (...args) {
|
|
4
4
|
const { print } = this.app.bajo
|
|
5
5
|
const { isEmpty } = this.app.bajo.lib._
|
|
6
|
-
if (isEmpty(this.schemas)) return print.fail('
|
|
6
|
+
if (isEmpty(this.schemas)) return print.fail('notFound%s', 'schema', { exit: this.app.bajo.applet })
|
|
7
7
|
const [schema] = args
|
|
8
8
|
await postProcess.call(this, { handler: 'modelClear', params: [schema], path: 'modelClear', processMsg: 'Clear records' })
|
|
9
9
|
}
|
|
@@ -8,10 +8,10 @@ async function modelRebuild (...args) {
|
|
|
8
8
|
'bajoCli:@inquirer/confirm', 'bajoCli:boxen')
|
|
9
9
|
const schemas = map(this.schemas, 'name')
|
|
10
10
|
let names = args.join(' ')
|
|
11
|
-
if (isEmpty(schemas)) return this.print.fail('
|
|
11
|
+
if (isEmpty(schemas)) return this.print.fail('notFound%s', 'schema', { exit: this.app.bajo.applet })
|
|
12
12
|
if (isEmpty(names)) {
|
|
13
13
|
names = await input({
|
|
14
|
-
message: this.print.write('
|
|
14
|
+
message: this.print.write('enterSchemaName'),
|
|
15
15
|
default: '*'
|
|
16
16
|
})
|
|
17
17
|
}
|
|
@@ -19,12 +19,12 @@ async function modelRebuild (...args) {
|
|
|
19
19
|
names = schemas.filter(isMatch)
|
|
20
20
|
if (names.length === 0) return this.print.fail('No schema matched', true, { exit: this.app.bajo.applet })
|
|
21
21
|
names = names.sort()
|
|
22
|
-
console.log(boxen(names.join(' '), { title: this.print.write('
|
|
22
|
+
console.log(boxen(names.join(' '), { title: this.print.write('schema%d', names.length), padding: 0.5, borderStyle: 'round' }))
|
|
23
23
|
const answer = await confirm({
|
|
24
|
-
message: this.print.write('
|
|
24
|
+
message: this.print.write('schemasWillBeRebuiltContinue'),
|
|
25
25
|
default: false
|
|
26
26
|
})
|
|
27
|
-
if (!answer) return this.print.fail('
|
|
27
|
+
if (!answer) return this.print.fail('aborted', { exit: this.app.bajo.applet })
|
|
28
28
|
/*
|
|
29
29
|
const conns = []
|
|
30
30
|
for (const s of names) {
|
|
@@ -36,9 +36,9 @@ async function modelRebuild (...args) {
|
|
|
36
36
|
const result = { succed: 0, failed: 0, skipped: 0 }
|
|
37
37
|
for (const s of names) {
|
|
38
38
|
const { schema, instance, connection } = this.getInfo(s)
|
|
39
|
-
const spin = this.print.spinner({ showCounter: true }).start('
|
|
39
|
+
const spin = this.print.spinner({ showCounter: true }).start('rebuilding%s', schema.name)
|
|
40
40
|
if (!instance) {
|
|
41
|
-
spin.warn('
|
|
41
|
+
spin.warn('clientInstanceNotConnected%s', schema.connection, schema.name)
|
|
42
42
|
result.skipped++
|
|
43
43
|
continue
|
|
44
44
|
}
|
|
@@ -47,33 +47,33 @@ async function modelRebuild (...args) {
|
|
|
47
47
|
if (this.app.bajo.config.force) {
|
|
48
48
|
try {
|
|
49
49
|
await this.modelDrop(schema.name, { spinner: spin })
|
|
50
|
-
spin.setText('
|
|
50
|
+
spin.setText('modelDropped%s', schema.name)
|
|
51
51
|
} catch (err) {
|
|
52
|
-
spin.fail('
|
|
52
|
+
spin.fail('errorDroppingModel%s%s', schema.name, err.message)
|
|
53
53
|
result.failed++
|
|
54
54
|
continue
|
|
55
55
|
}
|
|
56
56
|
} else {
|
|
57
|
-
spin.fail('
|
|
57
|
+
spin.fail('modelExistsNeedForce%s', schema.name)
|
|
58
58
|
result.failed++
|
|
59
59
|
continue
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
try {
|
|
63
63
|
await this.modelCreate(schema.name, { spinner: spin })
|
|
64
|
-
if (connection.memory) spin.succeed('
|
|
64
|
+
if (connection.memory) spin.succeed('modelCreated%s', schema.name)
|
|
65
65
|
else {
|
|
66
66
|
const fixture = await addFixtures.call(this, schema.name, { spinner: spin })
|
|
67
|
-
spin.succeed('
|
|
67
|
+
spin.succeed('modelCreatedWithFixture%s%s%s', schema.name, fixture.success, fixture.failed)
|
|
68
68
|
}
|
|
69
69
|
result.succed++
|
|
70
70
|
} catch (err) {
|
|
71
71
|
if (this.app.bajo.config.log.applet && this.app.bajo.config.log.level === 'trace') console.error(err)
|
|
72
|
-
spin.fail('
|
|
72
|
+
spin.fail('errorCreatingModel%s%s', schema.name, err.message)
|
|
73
73
|
result.failed++
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
this.print.info('
|
|
76
|
+
this.print.info('succeedFailSkip%d%d%d', result.succed, result.failed, result.skipped)
|
|
77
77
|
process.exit()
|
|
78
78
|
}
|
|
79
79
|
|
|
@@ -5,24 +5,24 @@ async function createRecord (path, ...args) {
|
|
|
5
5
|
const { isEmpty, map, isPlainObject } = this.app.bajo.lib._
|
|
6
6
|
const [input, select, boxen] = await importPkg('bajoCli:@inquirer/input',
|
|
7
7
|
'bajoCli:@inquirer/select', 'bajoCli:boxen')
|
|
8
|
-
if (isEmpty(this.schemas)) return this.print.fail('
|
|
8
|
+
if (isEmpty(this.schemas)) return this.print.fail('notFound%s', this.print.write('field.schema'), { exit: this.app.bajo.applet })
|
|
9
9
|
let [schema, body] = args
|
|
10
10
|
if (isEmpty(schema)) {
|
|
11
11
|
schema = await select({
|
|
12
|
-
message: this.print.write('
|
|
12
|
+
message: this.print.write('selectSchema'),
|
|
13
13
|
choices: map(this.schemas, s => ({ value: s.name }))
|
|
14
14
|
})
|
|
15
15
|
}
|
|
16
16
|
if (isEmpty(body)) {
|
|
17
17
|
body = await input({
|
|
18
|
-
message: this.print.write('
|
|
18
|
+
message: this.print.write('enterJsonPayload'),
|
|
19
19
|
validate: text => {
|
|
20
|
-
if (isEmpty(text)) return this.print.write('
|
|
20
|
+
if (isEmpty(text)) return this.print.write('payloadRequired')
|
|
21
21
|
try {
|
|
22
22
|
const parsed = JSON.parse(text)
|
|
23
23
|
if (!isPlainObject(parsed)) throw new Error()
|
|
24
24
|
} catch (err) {
|
|
25
|
-
return this.print.write('
|
|
25
|
+
return this.print.write('payloadMustBeJson')
|
|
26
26
|
}
|
|
27
27
|
return true
|
|
28
28
|
}
|
|
@@ -32,7 +32,7 @@ async function createRecord (path, ...args) {
|
|
|
32
32
|
try {
|
|
33
33
|
payload = JSON.parse(body)
|
|
34
34
|
} catch (err) {
|
|
35
|
-
return this.print.fail('
|
|
35
|
+
return this.print.fail('invalidPayloadSyntax', { exit: this.app.bajo.applet })
|
|
36
36
|
}
|
|
37
37
|
console.log(boxen(JSON.stringify(payload, null, 2), { title: schema, padding: 0.5, borderStyle: 'round' }))
|
|
38
38
|
await postProcess.call(this, { handler: 'recordCreate', params: [schema, payload], path, processMsg: 'Creating record' })
|
|
@@ -4,17 +4,17 @@ async function findRecord (path, ...args) {
|
|
|
4
4
|
const { importPkg } = this.app.bajo
|
|
5
5
|
const { isEmpty, map, pick } = this.app.bajo.lib._
|
|
6
6
|
const [select, input] = await importPkg('bajoCli:@inquirer/select', 'bajoCli:@inquirer/input')
|
|
7
|
-
if (isEmpty(this.schemas)) return this.print.fail('
|
|
7
|
+
if (isEmpty(this.schemas)) return this.print.fail('notFound%s', this.print.write('field.schema'), { exit: this.app.bajo.applet })
|
|
8
8
|
let [schema, query] = args
|
|
9
9
|
if (isEmpty(schema)) {
|
|
10
10
|
schema = await select({
|
|
11
|
-
message: this.print.write('
|
|
11
|
+
message: this.print.write('selectSchema'),
|
|
12
12
|
choices: map(this.schemas, s => ({ value: s.name }))
|
|
13
13
|
})
|
|
14
14
|
}
|
|
15
15
|
if (isEmpty(query)) {
|
|
16
16
|
query = await input({
|
|
17
|
-
message: this.print.write('
|
|
17
|
+
message: this.print.write('enterQueryIfAny')
|
|
18
18
|
})
|
|
19
19
|
}
|
|
20
20
|
if (isEmpty(query)) query = {}
|
|
@@ -4,7 +4,7 @@ async function getRecord (path, ...args) {
|
|
|
4
4
|
const { importPkg } = this.app.bajo
|
|
5
5
|
const { isEmpty, map } = this.app.bajo.lib._
|
|
6
6
|
const [input, select] = await importPkg('bajoCli:@inquirer/input', 'bajoCli:@inquirer/select')
|
|
7
|
-
if (isEmpty(this.schemas)) return this.print.fail('
|
|
7
|
+
if (isEmpty(this.schemas)) return this.print.fail('notFound%s', this.print.write('field.schema'), { exit: this.app.bajo.applet })
|
|
8
8
|
let [schema, id] = args
|
|
9
9
|
if (isEmpty(schema)) {
|
|
10
10
|
schema = await select({
|
|
@@ -4,7 +4,7 @@ async function removeRecord (path, ...args) {
|
|
|
4
4
|
const { importPkg } = this.app.bajo
|
|
5
5
|
const { isEmpty, map } = this.app.bajo.lib._
|
|
6
6
|
const [input, select] = await importPkg('bajoCli:@inquirer/input', 'bajoCli:@inquirer/select')
|
|
7
|
-
if (isEmpty(this.schemas)) return this.print.fail('
|
|
7
|
+
if (isEmpty(this.schemas)) return this.print.fail('notFound%s', this.print.write('field.schema'), { exit: this.app.bajo.applet })
|
|
8
8
|
let [schema, id] = args
|
|
9
9
|
if (isEmpty(schema)) {
|
|
10
10
|
schema = await select({
|
|
@@ -5,30 +5,30 @@ async function updateRecord (path, ...args) {
|
|
|
5
5
|
const { isEmpty, map, isPlainObject } = this.app.bajo.lib._
|
|
6
6
|
const [input, select, boxen] = await importPkg('bajoCli:@inquirer/input',
|
|
7
7
|
'bajoCli:@inquirer/select', 'bajoCli:boxen')
|
|
8
|
-
if (isEmpty(this.schemas)) return this.print.fail('
|
|
8
|
+
if (isEmpty(this.schemas)) return this.print.fail('notFound%s', this.print.write('field.schema'), { exit: this.app.bajo.applet })
|
|
9
9
|
let [schema, id, body] = args
|
|
10
10
|
if (isEmpty(schema)) {
|
|
11
11
|
schema = await select({
|
|
12
|
-
message: this.print.write('
|
|
12
|
+
message: this.print.write('selectSchema'),
|
|
13
13
|
choices: map(this.schemas, s => ({ value: s.name }))
|
|
14
14
|
})
|
|
15
15
|
}
|
|
16
16
|
if (isEmpty(id)) {
|
|
17
17
|
id = await input({
|
|
18
|
-
message: this.print.write('
|
|
19
|
-
validate: text => isEmpty(text) ? this.print.write('
|
|
18
|
+
message: this.print.write('enterRecordId'),
|
|
19
|
+
validate: text => isEmpty(text) ? this.print.write('idIsRequired') : true
|
|
20
20
|
})
|
|
21
21
|
}
|
|
22
22
|
if (isEmpty(body)) {
|
|
23
23
|
body = await input({
|
|
24
|
-
message: this.print.write('
|
|
24
|
+
message: this.print.write('enterJsonPayload'),
|
|
25
25
|
validate: text => {
|
|
26
|
-
if (isEmpty(text)) return this.print.write('
|
|
26
|
+
if (isEmpty(text)) return this.print.write('payloadRequired')
|
|
27
27
|
try {
|
|
28
28
|
const parsed = JSON.parse(text)
|
|
29
29
|
if (!isPlainObject(parsed)) throw new Error()
|
|
30
30
|
} catch (err) {
|
|
31
|
-
return this.print.write('
|
|
31
|
+
return this.print.write('payloadMustBeJson')
|
|
32
32
|
}
|
|
33
33
|
return true
|
|
34
34
|
}
|
|
@@ -38,7 +38,7 @@ async function updateRecord (path, ...args) {
|
|
|
38
38
|
try {
|
|
39
39
|
payload = JSON.parse(body)
|
|
40
40
|
} catch (err) {
|
|
41
|
-
return this.print.fail('
|
|
41
|
+
return this.print.fail('invalidPayloadSyntax', { exit: this.app.bajo.applet })
|
|
42
42
|
}
|
|
43
43
|
console.log(boxen(JSON.stringify(payload, null, 2), { title: schema, padding: 0.5, borderStyle: 'round' }))
|
|
44
44
|
await postProcess.call(this, { handler: 'recordUpdate', params: [schema, id, payload], path, processMsg: 'Updating record' })
|
package/bajoCli/applet/schema.js
CHANGED
|
@@ -4,18 +4,18 @@ async function schema (path, ...args) {
|
|
|
4
4
|
const { getOutputFormat, writeOutput } = this.app.bajoCli
|
|
5
5
|
const select = await importPkg('bajoCli:@inquirer/select')
|
|
6
6
|
const format = getOutputFormat()
|
|
7
|
-
if (isEmpty(this.schemas)) return this.print.fail('
|
|
7
|
+
if (isEmpty(this.schemas)) return this.print.fail('notFound%s', this.print.write('field.schema'), { exit: this.app.bajo.applet })
|
|
8
8
|
let name = args[0]
|
|
9
9
|
if (isEmpty(name)) {
|
|
10
10
|
const choices = map(this.schemas, s => ({ value: s.name }))
|
|
11
11
|
name = await select({
|
|
12
|
-
message: this.print.write('
|
|
12
|
+
message: this.print.write('selectSchema'),
|
|
13
13
|
choices
|
|
14
14
|
})
|
|
15
15
|
}
|
|
16
16
|
const result = find(this.schemas, { name })
|
|
17
|
-
if (!result) return this.print.fail('
|
|
18
|
-
this.print.info('
|
|
17
|
+
if (!result) return this.print.fail('cantFindSchema%s', this.print.write('schema'), name, { exit: this.app.bajo.applet })
|
|
18
|
+
this.print.info('done')
|
|
19
19
|
await writeOutput(result, path, format)
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -4,17 +4,17 @@ async function statCount (path, ...args) {
|
|
|
4
4
|
const { importPkg } = this.app.bajo
|
|
5
5
|
const { isEmpty, map } = this.app.bajo.lib._
|
|
6
6
|
const [select, input] = await importPkg('bajoCli:@inquirer/select', 'bajoCli:@inquirer/input')
|
|
7
|
-
if (isEmpty(this.schemas)) return this.print.fail('
|
|
7
|
+
if (isEmpty(this.schemas)) return this.print.fail('notFound%s', this.print.write('field.schema'), { exit: this.app.bajo.applet })
|
|
8
8
|
let [schema, query] = args
|
|
9
9
|
if (isEmpty(schema)) {
|
|
10
10
|
schema = await select({
|
|
11
|
-
message: this.print.write('
|
|
11
|
+
message: this.print.write('selectSchema'),
|
|
12
12
|
choices: map(this.schemas, s => ({ value: s.name }))
|
|
13
13
|
})
|
|
14
14
|
}
|
|
15
15
|
if (isEmpty(query)) {
|
|
16
16
|
query = await input({
|
|
17
|
-
message: this.print.write('
|
|
17
|
+
message: this.print.write('enterQueryIfAny')
|
|
18
18
|
})
|
|
19
19
|
}
|
|
20
20
|
const filter = { query }
|