dobo 1.1.1 → 1.1.2
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/intl/en-US.json +5 -1
- package/bajo/intl/id.json +0 -1
- package/bajoCli/applet/connection.js +1 -1
- package/bajoCli/applet/lib/post-process.js +1 -1
- package/bajoCli/applet/model-clear.js +1 -1
- package/bajoCli/applet/model-rebuild.js +27 -7
- package/bajoCli/applet/record-create.js +1 -1
- package/bajoCli/applet/record-find.js +1 -1
- package/bajoCli/applet/record-get.js +1 -1
- package/bajoCli/applet/record-remove.js +1 -1
- package/bajoCli/applet/record-update.js +1 -1
- package/bajoCli/applet/schema.js +1 -1
- package/bajoCli/applet/stat-count.js +1 -1
- package/dobo/feature/removed-at.js +3 -3
- package/lib/add-fixtures.js +1 -1
- package/lib/build-bulk-action.js +1 -1
- package/lib/check-unique.js +5 -5
- package/lib/collect-connections.js +1 -1
- package/lib/collect-drivers.js +1 -1
- package/lib/collect-feature.js +1 -1
- package/lib/collect-schemas.js +3 -3
- package/lib/exec-feature-hook.js +1 -1
- package/lib/exec-validation.js +1 -1
- package/lib/generic-prop-sanitizer.js +1 -1
- package/lib/handle-attachment-upload.js +1 -1
- package/lib/mem-db/conn-sanitizer.js +1 -1
- package/lib/mem-db/instantiate.js +2 -2
- package/lib/mem-db/method/record/find.js +1 -1
- package/lib/mem-db/method/record/get.js +1 -1
- package/lib/mem-db/method/record/remove.js +1 -1
- package/lib/mem-db/method/record/update.js +1 -1
- package/lib/mem-db/start.js +1 -1
- package/lib/merge-attachment-info.js +2 -2
- package/lib/resolve-method.js +2 -2
- package/lib/sanitize-schema.js +3 -3
- package/package.json +1 -1
- package/plugin/factory.js +18 -11
- package/plugin/method/attachment/copy-uploaded.js +1 -1
- package/plugin/method/attachment/create.js +1 -1
- package/plugin/method/attachment/find.js +1 -1
- package/plugin/method/attachment/get-path.js +1 -1
- package/plugin/method/attachment/get.js +1 -1
- package/plugin/method/attachment/remove.js +1 -1
- package/plugin/method/bulk/create.js +1 -1
- package/plugin/method/model/clear.js +1 -1
- package/plugin/method/model/create.js +1 -1
- package/plugin/method/model/drop.js +1 -1
- package/plugin/method/model/exists.js +1 -1
- package/plugin/method/record/clear.js +1 -1
- package/plugin/method/record/count.js +1 -1
- package/plugin/method/record/create.js +1 -1
- package/plugin/method/record/find-one.js +1 -1
- package/plugin/method/record/find.js +1 -1
- package/plugin/method/record/get.js +1 -1
- package/plugin/method/record/remove.js +1 -1
- package/plugin/method/record/update.js +1 -1
- package/plugin/method/record/upsert.js +20 -6
- package/plugin/method/sanitize/body.js +1 -1
- package/plugin/method/sanitize/date.js +1 -1
- package/plugin/method/validate.js +2 -2
- package/waibuMpa/route/attachment/@model/@id/@field/@file.js +2 -2
- package/plugin/start.js +0 -20
package/bajo/intl/en-US.json
CHANGED
|
@@ -107,7 +107,6 @@
|
|
|
107
107
|
"unknownFeature%s%s": "'Unknown feature '%s@%s'",
|
|
108
108
|
"onlyAcceptFields%s%s": "Only accept array of field names or single string of field name '%s@%s'",
|
|
109
109
|
"invalidFieldName%s%s": "Invalid field name '%s@%s'",
|
|
110
|
-
"error%s": "Error: %s",
|
|
111
110
|
"succeedFailSkip%d%d%d": "Done! Succeded: %d, failed: %s, skipped: %d",
|
|
112
111
|
"chooseConn": "Please choose a connection:",
|
|
113
112
|
"sureContinue": "Are you sure to continue?",
|
|
@@ -117,6 +116,11 @@
|
|
|
117
116
|
"addingFixtureToMemDb": "Adding fixture for memory database",
|
|
118
117
|
"recordsAdded%s%d%d": "%s: %d of %d records added",
|
|
119
118
|
"driverInstantiated%s%s": "- Driver '%s:%s' instantiated",
|
|
119
|
+
"cantContinueAddFixture": "Can't continue with fixture adding because one or more models failed to rebuilt",
|
|
120
|
+
"addingFixture%s": "Adding fixture '%s'...",
|
|
121
|
+
"fixtureAdded%s%s%s": "Fixture on '%s': added %s, rejected: %s",
|
|
122
|
+
"errorAddingFixture%s%s": "Error adding fixture on model '%s': %s",
|
|
123
|
+
"memoryDbSkipped%s": "'%s' is a memory DB, skipped",
|
|
120
124
|
"field": {
|
|
121
125
|
"id": "ID",
|
|
122
126
|
"code": "Kode",
|
package/bajo/intl/id.json
CHANGED
|
@@ -105,7 +105,6 @@
|
|
|
105
105
|
"unknownFeature%s%s": "'Unknown feature '%s@%s'",
|
|
106
106
|
"onlyAcceptFields%s%s": "Only accept array of field names or single string of field name '%s@%s'",
|
|
107
107
|
"invalidFieldName%s%s": "Invalid field name '%s@%s'",
|
|
108
|
-
"error%s": "Error: %s",
|
|
109
108
|
"succeedFailSkip%d%d%d": "Done! Succeded: %d, failed: %s, skipped: %d",
|
|
110
109
|
"chooseConn": "Please choose a connection:",
|
|
111
110
|
"sureContinue": "Are you sure to continue?",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
async function connection (path, ...args) {
|
|
2
2
|
const { importPkg } = this.app.bajo
|
|
3
|
-
const { isEmpty, map, find } = this.
|
|
3
|
+
const { isEmpty, map, find } = this.lib._
|
|
4
4
|
const select = await importPkg('bajoCli:@inquirer/select')
|
|
5
5
|
const { getOutputFormat, writeOutput } = this.app.bajoCli
|
|
6
6
|
const format = getOutputFormat()
|
|
@@ -3,7 +3,7 @@ const conns = []
|
|
|
3
3
|
async function postProcess ({ handler, params, path, processMsg, noConfirmation } = {}) {
|
|
4
4
|
const { saveAsDownload, importPkg } = this.app.bajo
|
|
5
5
|
const { prettyPrint } = this.app.bajoCli.helper
|
|
6
|
-
const { find, get } = this.
|
|
6
|
+
const { find, get } = this.lib._
|
|
7
7
|
const [stripAnsi, confirm] = await importPkg('bajoCli:strip-ansi', 'bajoCli:@inquirer/confirm')
|
|
8
8
|
if (!noConfirmation && this.config.confirmation === false) noConfirmation = true
|
|
9
9
|
params.push({ fields: this.config.fields, dataOnly: !this.config.full })
|
|
@@ -2,7 +2,7 @@ import postProcess from './lib/post-process.js'
|
|
|
2
2
|
|
|
3
3
|
async function modelClear (...args) {
|
|
4
4
|
const { print } = this.app.bajo
|
|
5
|
-
const { isEmpty } = this.
|
|
5
|
+
const { isEmpty } = this.lib._
|
|
6
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' })
|
|
@@ -2,8 +2,8 @@ import addFixtures from '../../lib/add-fixtures.js'
|
|
|
2
2
|
|
|
3
3
|
async function modelRebuild (...args) {
|
|
4
4
|
const { importPkg } = this.app.bajo
|
|
5
|
-
const { outmatch } = this.
|
|
6
|
-
const { isEmpty, map, trim } = this.
|
|
5
|
+
const { outmatch } = this.lib
|
|
6
|
+
const { isEmpty, map, trim, without } = this.lib._
|
|
7
7
|
const [input, confirm, boxen] = await importPkg('bajoCli:@inquirer/input',
|
|
8
8
|
'bajoCli:@inquirer/confirm', 'bajoCli:boxen')
|
|
9
9
|
const schemas = map(this.schemas, 'name')
|
|
@@ -34,14 +34,20 @@ async function modelRebuild (...args) {
|
|
|
34
34
|
*/
|
|
35
35
|
await this.start('all')
|
|
36
36
|
const result = { succed: 0, failed: 0, skipped: 0 }
|
|
37
|
+
const skipped = []
|
|
37
38
|
for (const s of names) {
|
|
38
39
|
const { schema, instance, connection } = this.getInfo(s)
|
|
39
40
|
const spin = this.print.spinner({ showCounter: true }).start('rebuilding%s', schema.name)
|
|
40
41
|
if (!instance) {
|
|
41
42
|
spin.warn('clientInstanceNotConnected%s', schema.connection, schema.name)
|
|
43
|
+
skipped.push(schema.name)
|
|
42
44
|
result.skipped++
|
|
43
45
|
continue
|
|
44
46
|
}
|
|
47
|
+
if (connection.memory) {
|
|
48
|
+
spin.warn('memoryDbSkipped%s', schema.name)
|
|
49
|
+
continue
|
|
50
|
+
}
|
|
45
51
|
const exists = await this.modelExists(schema.name, false, { spinner: spin })
|
|
46
52
|
if (exists) {
|
|
47
53
|
if (this.app.bajo.config.force) {
|
|
@@ -61,11 +67,7 @@ async function modelRebuild (...args) {
|
|
|
61
67
|
}
|
|
62
68
|
try {
|
|
63
69
|
await this.modelCreate(schema.name, { spinner: spin })
|
|
64
|
-
|
|
65
|
-
else {
|
|
66
|
-
const fixture = await addFixtures.call(this, schema.name, { spinner: spin })
|
|
67
|
-
spin.succeed('modelCreatedWithFixture%s%s%s', schema.name, fixture.success, fixture.failed)
|
|
68
|
-
}
|
|
70
|
+
spin.succeed('modelCreated%s', schema.name)
|
|
69
71
|
result.succed++
|
|
70
72
|
} catch (err) {
|
|
71
73
|
if (this.app.bajo.config.log.applet && this.app.bajo.config.log.level === 'trace') console.error(err)
|
|
@@ -74,6 +76,24 @@ async function modelRebuild (...args) {
|
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
this.print.info('succeedFailSkip%d%d%d', result.succed, result.failed, result.skipped)
|
|
79
|
+
if (result.failed > 0) this.print.fatal('cantContinueAddFixture')
|
|
80
|
+
for (const s of without(names, ...skipped)) {
|
|
81
|
+
const { schema, connection } = this.getInfo(s)
|
|
82
|
+
const spin = this.print.spinner({ showCounter: true }).start('addingFixture%s', schema.name)
|
|
83
|
+
if (connection.memory) {
|
|
84
|
+
spin.warn('memoryDbSkipped%s', schema.name)
|
|
85
|
+
continue
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
const fixture = await addFixtures.call(this, schema.name, { spinner: spin })
|
|
89
|
+
spin.succeed('fixtureAdded%s%s%s', schema.name, fixture.success, fixture.failed)
|
|
90
|
+
result.succed++
|
|
91
|
+
} catch (err) {
|
|
92
|
+
if (this.app.bajo.config.log.applet && this.app.bajo.config.log.level === 'trace') console.error(err)
|
|
93
|
+
spin.fail('errorAddingFixture%s%s', schema.name, err.message)
|
|
94
|
+
result.failed++
|
|
95
|
+
}
|
|
96
|
+
}
|
|
77
97
|
process.exit()
|
|
78
98
|
}
|
|
79
99
|
|
|
@@ -2,7 +2,7 @@ import postProcess from './lib/post-process.js'
|
|
|
2
2
|
|
|
3
3
|
async function createRecord (path, ...args) {
|
|
4
4
|
const { importPkg } = this.app.bajo
|
|
5
|
-
const { isEmpty, map, isPlainObject } = this.
|
|
5
|
+
const { isEmpty, map, isPlainObject } = this.lib._
|
|
6
6
|
const [input, select, boxen] = await importPkg('bajoCli:@inquirer/input',
|
|
7
7
|
'bajoCli:@inquirer/select', 'bajoCli:boxen')
|
|
8
8
|
if (isEmpty(this.schemas)) return this.print.fail('notFound%s', this.print.write('field.schema'), { exit: this.app.bajo.applet })
|
|
@@ -2,7 +2,7 @@ import postProcess from './lib/post-process.js'
|
|
|
2
2
|
|
|
3
3
|
async function findRecord (path, ...args) {
|
|
4
4
|
const { importPkg } = this.app.bajo
|
|
5
|
-
const { isEmpty, map, pick } = this.
|
|
5
|
+
const { isEmpty, map, pick } = this.lib._
|
|
6
6
|
const [select, input] = await importPkg('bajoCli:@inquirer/select', 'bajoCli:@inquirer/input')
|
|
7
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
|
|
@@ -2,7 +2,7 @@ import postProcess from './lib/post-process.js'
|
|
|
2
2
|
|
|
3
3
|
async function getRecord (path, ...args) {
|
|
4
4
|
const { importPkg } = this.app.bajo
|
|
5
|
-
const { isEmpty, map } = this.
|
|
5
|
+
const { isEmpty, map } = this.lib._
|
|
6
6
|
const [input, select] = await importPkg('bajoCli:@inquirer/input', 'bajoCli:@inquirer/select')
|
|
7
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
|
|
@@ -2,7 +2,7 @@ import postProcess from './lib/post-process.js'
|
|
|
2
2
|
|
|
3
3
|
async function removeRecord (path, ...args) {
|
|
4
4
|
const { importPkg } = this.app.bajo
|
|
5
|
-
const { isEmpty, map } = this.
|
|
5
|
+
const { isEmpty, map } = this.lib._
|
|
6
6
|
const [input, select] = await importPkg('bajoCli:@inquirer/input', 'bajoCli:@inquirer/select')
|
|
7
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
|
|
@@ -2,7 +2,7 @@ import postProcess from './lib/post-process.js'
|
|
|
2
2
|
|
|
3
3
|
async function updateRecord (path, ...args) {
|
|
4
4
|
const { importPkg } = this.app.bajo
|
|
5
|
-
const { isEmpty, map, isPlainObject } = this.
|
|
5
|
+
const { isEmpty, map, isPlainObject } = this.lib._
|
|
6
6
|
const [input, select, boxen] = await importPkg('bajoCli:@inquirer/input',
|
|
7
7
|
'bajoCli:@inquirer/select', 'bajoCli:boxen')
|
|
8
8
|
if (isEmpty(this.schemas)) return this.print.fail('notFound%s', this.print.write('field.schema'), { exit: this.app.bajo.applet })
|
package/bajoCli/applet/schema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
async function schema (path, ...args) {
|
|
2
2
|
const { importPkg } = this.app.bajo
|
|
3
|
-
const { isEmpty, map, find } = this.
|
|
3
|
+
const { isEmpty, map, find } = this.lib._
|
|
4
4
|
const { getOutputFormat, writeOutput } = this.app.bajoCli
|
|
5
5
|
const select = await importPkg('bajoCli:@inquirer/select')
|
|
6
6
|
const format = getOutputFormat()
|
|
@@ -2,7 +2,7 @@ import postProcess from './lib/post-process.js'
|
|
|
2
2
|
|
|
3
3
|
async function statCount (path, ...args) {
|
|
4
4
|
const { importPkg } = this.app.bajo
|
|
5
|
-
const { isEmpty, map } = this.
|
|
5
|
+
const { isEmpty, map } = this.lib._
|
|
6
6
|
const [select, input] = await importPkg('bajoCli:@inquirer/select', 'bajoCli:@inquirer/input')
|
|
7
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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
async function beforeFind ({ filter = {}, options }, opts) {
|
|
2
2
|
filter.query = filter.query ?? {}
|
|
3
|
-
const { isEmpty, set } = this.
|
|
3
|
+
const { isEmpty, set } = this.lib._
|
|
4
4
|
const q = { $and: [] }
|
|
5
5
|
if (!isEmpty(filter.query)) {
|
|
6
6
|
if (filter.query.$and) q.$and.push(...filter.query.$and)
|
|
@@ -17,7 +17,7 @@ async function afterFind ({ records }, opts) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
async function afterGet ({ schema, id, record }, opts) {
|
|
20
|
-
const { isEmpty } = this.
|
|
20
|
+
const { isEmpty } = this.lib._
|
|
21
21
|
if (!isEmpty(record.data[opts.fieldName])) throw this.error('recordNotFound%s%s', id, schema.name, { statusCode: 404 })
|
|
22
22
|
delete record.data[opts.fieldName]
|
|
23
23
|
}
|
|
@@ -70,7 +70,7 @@ async function removedAt (opts = {}) {
|
|
|
70
70
|
beforeRemove: async function ({ schema, id, options }) {
|
|
71
71
|
const { recordUpdate, recordGet } = this.app.dobo
|
|
72
72
|
await recordGet(schema.name, id, options)
|
|
73
|
-
const { set } = this.
|
|
73
|
+
const { set } = this.lib._
|
|
74
74
|
const body = set({}, opts.fieldName, new Date())
|
|
75
75
|
const record = await recordUpdate(schema.name, id, body, { dataOnly: false, noValidation: true, noFeatureHook: true })
|
|
76
76
|
options.record = { oldData: record.oldData }
|
package/lib/add-fixtures.js
CHANGED
|
@@ -2,7 +2,7 @@ import path from 'path'
|
|
|
2
2
|
|
|
3
3
|
async function addFixture (name, { spinner } = {}) {
|
|
4
4
|
const { resolvePath, readConfig, eachPlugins } = this.app.bajo
|
|
5
|
-
const { isEmpty, isArray } = this.
|
|
5
|
+
const { isEmpty, isArray } = this.lib._
|
|
6
6
|
const { schema, connection } = this.getInfo(name)
|
|
7
7
|
if (connection.proxy) {
|
|
8
8
|
this.log.warn('proxiedConnBound%s', schema.name)
|
package/lib/build-bulk-action.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
async function buildBulkAction (name, action, options = {}) {
|
|
2
2
|
const { fs, importModule } = this.app.bajo
|
|
3
|
-
const { camelCase } = this.
|
|
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
6
|
const file = `${driver.plugin}:/${this.name}/method/bulk/${action}.js`
|
package/lib/check-unique.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
async function checkUnique ({ schema, body, id }) {
|
|
2
2
|
const { isSet } = this.app.bajo
|
|
3
|
-
const { filter, map, set } = this.
|
|
3
|
+
const { filter, map, set } = this.lib._
|
|
4
4
|
const singles = map(filter(schema.properties, p => (p.index ?? {}).type === 'unique'), 'name')
|
|
5
|
-
const opts = { noHook: true, noCache: true, thrownNotFound: false,
|
|
5
|
+
const opts = { noHook: true, noCache: true, thrownNotFound: false, forceNoHidden: true }
|
|
6
6
|
let old = {}
|
|
7
7
|
if (id) old = (await this.recordGet(schema.name, id, opts)) ?? {}
|
|
8
8
|
for (const s of singles) {
|
|
@@ -12,7 +12,7 @@ async function checkUnique ({ schema, body, id }) {
|
|
|
12
12
|
const resp = await this.recordFind(schema.name, { query, limit: 1 }, opts)
|
|
13
13
|
if (resp.length !== 0) {
|
|
14
14
|
const details = [{ field: s, error: 'uniqueConstraintError', value: id }]
|
|
15
|
-
throw this.error('uniqueConstraintError', { details })
|
|
15
|
+
throw this.error('uniqueConstraintError', { details, body })
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
const multis = filter(schema.indexes, i => i.type === 'unique')
|
|
@@ -26,12 +26,12 @@ async function checkUnique ({ schema, body, id }) {
|
|
|
26
26
|
query[f] = body[f]
|
|
27
27
|
}
|
|
28
28
|
if (empty || same) continue
|
|
29
|
-
const resp = await this.recordFind(schema.name, { query, limit: 1 }, { noHook: true, noCache: true,
|
|
29
|
+
const resp = await this.recordFind(schema.name, { query, limit: 1 }, { noHook: true, noCache: true, forceNoHidden: true })
|
|
30
30
|
if (resp.length !== 0) {
|
|
31
31
|
const details = map(m.fields, f => {
|
|
32
32
|
return { field: f, error: 'Unique constraint error' }
|
|
33
33
|
})
|
|
34
|
-
throw this.error('Unique constraint error', { details })
|
|
34
|
+
throw this.error('Unique constraint error', { details, body })
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -5,7 +5,7 @@ async function defSanitizer (item) {
|
|
|
5
5
|
async function collectConnections ({ item, index, options }) {
|
|
6
6
|
const conn = item
|
|
7
7
|
const { importModule, breakNsPath } = this.app.bajo
|
|
8
|
-
const { has, find } = this.
|
|
8
|
+
const { has, find } = this.lib._
|
|
9
9
|
if (!has(conn, 'type')) this.fatal('mustValidDbType')
|
|
10
10
|
const { ns, path: type } = breakNsPath(conn.type)
|
|
11
11
|
const driver = find(this.drivers, { ns, type })
|
package/lib/collect-drivers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
async function collectDrivers () {
|
|
2
2
|
const { eachPlugins, readConfig, runHook } = this.app.bajo
|
|
3
|
-
const { isString, find, pick, merge, cloneDeep } = this.
|
|
3
|
+
const { isString, find, pick, merge, cloneDeep } = this.lib._
|
|
4
4
|
const me = this
|
|
5
5
|
me.drivers = []
|
|
6
6
|
// built-in memory driver
|
package/lib/collect-feature.js
CHANGED
|
@@ -2,7 +2,7 @@ import path from 'path'
|
|
|
2
2
|
|
|
3
3
|
async function handler ({ file, alias, ns }) {
|
|
4
4
|
const { importModule } = this.app.bajo
|
|
5
|
-
const { camelCase, isFunction } = this.
|
|
5
|
+
const { camelCase, isFunction } = this.lib._
|
|
6
6
|
const me = this.app.dobo
|
|
7
7
|
|
|
8
8
|
let name = camelCase(path.basename(file, '.js'))
|
package/lib/collect-schemas.js
CHANGED
|
@@ -3,8 +3,8 @@ import sanitizeSchema from './sanitize-schema.js'
|
|
|
3
3
|
|
|
4
4
|
async function handler ({ file, alias, ns }) {
|
|
5
5
|
const { readConfig, pascalCase, eachPlugins } = this.app.bajo
|
|
6
|
-
const { get, isPlainObject, each, find, has, isArray, forOwn, isString, merge } = this.
|
|
7
|
-
const { fastGlob } = this.
|
|
6
|
+
const { get, isPlainObject, each, find, has, isArray, forOwn, isString, merge } = this.lib._
|
|
7
|
+
const { fastGlob } = this.lib
|
|
8
8
|
|
|
9
9
|
const base = path.basename(file, path.extname(file))
|
|
10
10
|
const defName = pascalCase(`${alias} ${base}`)
|
|
@@ -70,7 +70,7 @@ async function handler ({ file, alias, ns }) {
|
|
|
70
70
|
|
|
71
71
|
async function collectSchemas () {
|
|
72
72
|
const { eachPlugins } = this.app.bajo
|
|
73
|
-
const { isEmpty } = this.
|
|
73
|
+
const { isEmpty } = this.lib._
|
|
74
74
|
const result = await eachPlugins(handler, { glob: 'schema/*.*', prefix: this.name })
|
|
75
75
|
if (isEmpty(result)) this.log.warn('notFound%s', this.print.write('schema'))
|
|
76
76
|
else await sanitizeSchema.call(this, result)
|
package/lib/exec-feature-hook.js
CHANGED
package/lib/exec-validation.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
async function execValidation ({ name, body, options, partial }) {
|
|
2
2
|
const { runHook } = this.app.bajo
|
|
3
|
-
const { keys, camelCase } = this.
|
|
3
|
+
const { keys, camelCase } = this.lib._
|
|
4
4
|
const { noHook } = options
|
|
5
5
|
if (!noHook) {
|
|
6
6
|
await runHook(`${this.name}:beforeRecordValidation`, name, body, options)
|
|
@@ -2,7 +2,7 @@ const indexTypes = ['default', 'unique', 'primary', 'fulltext']
|
|
|
2
2
|
|
|
3
3
|
async function genericPropSanitizer ({ prop, schema, driver }) {
|
|
4
4
|
const { join } = this.app.bajo
|
|
5
|
-
const { has, get, each } = this.
|
|
5
|
+
const { has, get, each } = this.lib._
|
|
6
6
|
const def = this.propType[prop.type]
|
|
7
7
|
// detect from drivers
|
|
8
8
|
if (prop.type === 'string') {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
async function handleAttachmentUpload ({ action, name, id, options = {} } = {}) {
|
|
2
2
|
const { getPluginDataDir } = this.app.bajo
|
|
3
|
-
const { fs } = this.
|
|
3
|
+
const { fs } = this.lib
|
|
4
4
|
const { req, mimeType, stats, setFile, setField } = options
|
|
5
5
|
|
|
6
6
|
name = this.attachmentPreCheck(name)
|
|
@@ -2,8 +2,8 @@ let saving = false
|
|
|
2
2
|
|
|
3
3
|
async function instantiate ({ connection, schemas, noRebuild }) {
|
|
4
4
|
const { getPluginDataDir } = this.app.bajo
|
|
5
|
-
const { fs } = this.
|
|
6
|
-
const { pick } = this.
|
|
5
|
+
const { fs } = this.lib
|
|
6
|
+
const { pick } = this.lib._
|
|
7
7
|
this.memDb = this.memDb ?? {}
|
|
8
8
|
this.memDb.storage = this.memDb.storage ?? {}
|
|
9
9
|
this.memDb.instances = this.memDb.instances ?? []
|
|
@@ -2,7 +2,7 @@ import { Query } from 'mingo'
|
|
|
2
2
|
|
|
3
3
|
async function find ({ schema, filter = {}, options = {} }) {
|
|
4
4
|
const { prepPagination } = this.app.dobo
|
|
5
|
-
const { omit } = this.
|
|
5
|
+
const { omit } = this.lib._
|
|
6
6
|
const { limit, skip, sort, page } = await prepPagination(filter, schema)
|
|
7
7
|
const criteria = filter.query ?? {}
|
|
8
8
|
const q = new Query(criteria, { idKey: 'id' })
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
async function get ({ schema, id, options = {} }) {
|
|
2
2
|
const { thrownNotFound = true } = options
|
|
3
|
-
const { find } = this.
|
|
3
|
+
const { find } = this.lib._
|
|
4
4
|
const result = find(this.memDb.storage[schema.name], { id })
|
|
5
5
|
if (!result && thrownNotFound) throw this.error('recordNotFound%s%s', id, schema.name, { statusCode: 404 })
|
|
6
6
|
return { data: result }
|
|
@@ -2,7 +2,7 @@ import getRecord from './get.js'
|
|
|
2
2
|
|
|
3
3
|
async function remove ({ schema, id, options = {} }) {
|
|
4
4
|
const { noResult } = options
|
|
5
|
-
const { findIndex, pullAt } = this.
|
|
5
|
+
const { findIndex, pullAt } = this.lib._
|
|
6
6
|
const rec = noResult ? undefined : await getRecord.call(this, { schema, id })
|
|
7
7
|
const idx = findIndex(this.memDb.storage[schema.name], { id })
|
|
8
8
|
pullAt(this.memDb.storage[schema.name], [idx])
|
|
@@ -2,7 +2,7 @@ import getRecord from './get.js'
|
|
|
2
2
|
|
|
3
3
|
async function update ({ schema, id, body, options }) {
|
|
4
4
|
const { noResult } = options
|
|
5
|
-
const { findIndex, merge } = this.
|
|
5
|
+
const { findIndex, merge } = this.lib._
|
|
6
6
|
const old = noResult ? undefined : await getRecord.call(this, { schema, id })
|
|
7
7
|
const idx = findIndex(this.memDb.storage[schema.name], { id })
|
|
8
8
|
const current = this.memDb.storage[schema.name][idx]
|
package/lib/mem-db/start.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import addFixtures from '../add-fixtures.js'
|
|
2
2
|
|
|
3
3
|
async function start () {
|
|
4
|
-
const { filter, map } = this.
|
|
4
|
+
const { filter, map } = this.lib._
|
|
5
5
|
|
|
6
6
|
const conns = filter(this.connections, { type: 'dobo:memory' })
|
|
7
7
|
const schemas = filter(this.schemas, s => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
async function mergeAttachmentInfo (rec, source, { mimeType, stats, fullPath }) {
|
|
2
2
|
const { importPkg } = this.app.bajo
|
|
3
|
-
const { fs } = this.
|
|
4
|
-
const { pick } = this.
|
|
3
|
+
const { fs } = this.lib
|
|
4
|
+
const { pick } = this.lib._
|
|
5
5
|
if (!this.app.waibu) return
|
|
6
6
|
const mime = await importPkg('waibu:mime')
|
|
7
7
|
|
package/lib/resolve-method.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
async function resolveMethod (name, method, options = {}) {
|
|
2
2
|
const { importModule } = this.app.bajo
|
|
3
|
-
const { fs } = this.
|
|
4
|
-
const { camelCase } = this.
|
|
3
|
+
const { fs } = this.lib
|
|
4
|
+
const { camelCase } = this.lib._
|
|
5
5
|
const { schema, driver, connection } = this.getInfo(name)
|
|
6
6
|
const [group, action] = method.split('-')
|
|
7
7
|
if (!options.force && (schema.disabled ?? []).includes(action)) throw this.error('methodIsDisabled%s%s', camelCase(method), name)
|
package/lib/sanitize-schema.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import genericPropSanitizer from './generic-prop-sanitizer.js'
|
|
2
2
|
|
|
3
3
|
async function sanitizeFeature (item) {
|
|
4
|
-
const { get, isPlainObject, mergeWith, isArray } = this.
|
|
4
|
+
const { get, isPlainObject, mergeWith, isArray } = this.lib._
|
|
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('unknownFeature%s%s', f.name, item.name)
|
|
@@ -36,7 +36,7 @@ async function sanitizeFullText (item) {
|
|
|
36
36
|
|
|
37
37
|
async function sanitizeSchema (items) {
|
|
38
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.
|
|
39
|
+
const { map, keys, findIndex, find, each, isString, get, isPlainObject, camelCase, uniq, filter } = this.lib._
|
|
40
40
|
const propTypes = keys(this.propType)
|
|
41
41
|
const schemas = []
|
|
42
42
|
this.log.debug('loadingDbSchemas')
|
|
@@ -151,7 +151,7 @@ async function sanitizeSchema (items) {
|
|
|
151
151
|
}
|
|
152
152
|
const rprop = find(rel.properties, { name: def.propName })
|
|
153
153
|
if (!rprop) fatal.call(this, 'No property found for relationship \'%s@%s:%s\'', `${def.schema}:${def.propName}`, schema.name, prop.name)
|
|
154
|
-
def.fields = def.fields ??
|
|
154
|
+
def.fields = def.fields ?? '*'
|
|
155
155
|
if (['*', 'all'].includes(def.fields)) {
|
|
156
156
|
const relschema = find(schemas, { name: def.schema })
|
|
157
157
|
def.fields = relschema.properties.map(p => p.name)
|
package/package.json
CHANGED
package/plugin/factory.js
CHANGED
|
@@ -95,9 +95,9 @@ async function factory (pkgName) {
|
|
|
95
95
|
|
|
96
96
|
init = async () => {
|
|
97
97
|
const { buildCollections } = this.app.bajo
|
|
98
|
-
const { fs } = this.
|
|
98
|
+
const { fs } = this.lib
|
|
99
99
|
const checkType = async (item, items) => {
|
|
100
|
-
const { filter } = this.
|
|
100
|
+
const { filter } = this.lib._
|
|
101
101
|
const existing = filter(items, { type: 'dobo:memory' })
|
|
102
102
|
if (existing.length > 1) this.fatal('onlyOneConnType%s', item.type)
|
|
103
103
|
}
|
|
@@ -118,7 +118,7 @@ async function factory (pkgName) {
|
|
|
118
118
|
|
|
119
119
|
start = async (conns = 'all', noRebuild = true) => {
|
|
120
120
|
const { importModule, breakNsPath } = this.app.bajo
|
|
121
|
-
const { find, filter, isString, map } = this.
|
|
121
|
+
const { find, filter, isString, map } = this.lib._
|
|
122
122
|
if (conns === 'all') conns = this.connections
|
|
123
123
|
else if (isString(conns)) conns = filter(this.connections, { name: conns })
|
|
124
124
|
else conns = map(conns, c => find(this.connections, { name: c }))
|
|
@@ -133,8 +133,8 @@ async function factory (pkgName) {
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
pickRecord = async ({ record, fields, schema = {}, hidden = [], forceNoHidden } = {}) => {
|
|
136
|
-
const { isArray, pick, clone, isEmpty, omit } = this.
|
|
137
|
-
const { dayjs } = this.
|
|
136
|
+
const { isArray, pick, clone, isEmpty, omit } = this.lib._
|
|
137
|
+
const { dayjs } = this.lib
|
|
138
138
|
|
|
139
139
|
const transform = async ({ record, schema, hidden = [], forceNoHidden } = {}) => {
|
|
140
140
|
if (record._id) {
|
|
@@ -186,7 +186,7 @@ async function factory (pkgName) {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
const buildSort = (input, schema, allowSortUnindexed) => {
|
|
189
|
-
const { isEmpty, map, each, isPlainObject, isString, trim, keys } = this.
|
|
189
|
+
const { isEmpty, map, each, isPlainObject, isString, trim, keys } = this.lib._
|
|
190
190
|
let sort
|
|
191
191
|
if (schema && isEmpty(input)) {
|
|
192
192
|
const columns = map(schema.properties, 'name')
|
|
@@ -231,7 +231,7 @@ async function factory (pkgName) {
|
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
buildMatch = ({ input = '', schema, options }) => {
|
|
234
|
-
const { isPlainObject, trim } = this.
|
|
234
|
+
const { isPlainObject, trim } = this.lib._
|
|
235
235
|
const split = (value, schema) => {
|
|
236
236
|
let [field, val] = value.split(':').map(i => i.trim())
|
|
237
237
|
if (!val) {
|
|
@@ -264,7 +264,7 @@ async function factory (pkgName) {
|
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
buildQuery = async ({ filter, schema, options = {} } = {}) => {
|
|
267
|
-
const { trim, isString, isPlainObject } = this.
|
|
267
|
+
const { trim, isString, isPlainObject } = this.lib._
|
|
268
268
|
let query = {}
|
|
269
269
|
if (isString(filter.query)) {
|
|
270
270
|
filter.oquery = filter.query
|
|
@@ -286,13 +286,13 @@ async function factory (pkgName) {
|
|
|
286
286
|
}
|
|
287
287
|
|
|
288
288
|
getConnection = (name) => {
|
|
289
|
-
const { find } = this.
|
|
289
|
+
const { find } = this.lib._
|
|
290
290
|
return find(this.connections, { name })
|
|
291
291
|
}
|
|
292
292
|
|
|
293
293
|
getInfo = (name) => {
|
|
294
294
|
const { breakNsPath } = this.app.bajo
|
|
295
|
-
const { find, map } = this.
|
|
295
|
+
const { find, map } = this.lib._
|
|
296
296
|
const schema = this.getSchema(name)
|
|
297
297
|
const conn = this.getConnection(schema.connection)
|
|
298
298
|
const { ns, path: type } = breakNsPath(conn.type)
|
|
@@ -304,13 +304,20 @@ async function factory (pkgName) {
|
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
getSchema = (input, cloned = true) => {
|
|
307
|
-
const { find, isPlainObject, cloneDeep } = this.
|
|
307
|
+
const { find, isPlainObject, cloneDeep } = this.lib._
|
|
308
308
|
let name = isPlainObject(input) ? input.name : input
|
|
309
309
|
name = this.app.bajo.pascalCase(name)
|
|
310
310
|
const schema = find(this.schemas, { name })
|
|
311
311
|
if (!schema) throw this.error('unknownModelSchema%s', name)
|
|
312
312
|
return cloned ? cloneDeep(schema) : schema
|
|
313
313
|
}
|
|
314
|
+
|
|
315
|
+
getMemdbStorage = (name, fields = []) => {
|
|
316
|
+
const { map, pick } = this.lib._
|
|
317
|
+
const all = this.memDb.storage[name] ?? []
|
|
318
|
+
if (fields.length === 0) return all
|
|
319
|
+
return map(all, item => pick(item, fields))
|
|
320
|
+
}
|
|
314
321
|
}
|
|
315
322
|
}
|
|
316
323
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
|
|
3
3
|
async function copyUploaded (name, id, options = {}) {
|
|
4
|
-
const { fs } = this.
|
|
4
|
+
const { fs } = this.lib
|
|
5
5
|
const { req, setField, setFile, mimeType, stats, silent = true } = options
|
|
6
6
|
name = this.attachmentPreCheck(name)
|
|
7
7
|
if (!name) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mergeAttachmentInfo from '../../../lib/merge-attachment-info.js'
|
|
2
2
|
|
|
3
3
|
async function create (name, id, options = {}) {
|
|
4
|
-
const { fs } = this.
|
|
4
|
+
const { fs } = this.lib
|
|
5
5
|
name = this.attachmentPreCheck(name)
|
|
6
6
|
if (!name) return
|
|
7
7
|
const { source, field, file } = options
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mergeAttachmentInfo from '../../../lib/merge-attachment-info.js'
|
|
2
2
|
|
|
3
3
|
async function find (name, id, options = {}) {
|
|
4
|
-
const { fastGlob, fs } = this.
|
|
4
|
+
const { fastGlob, fs } = this.lib
|
|
5
5
|
const { getPluginDataDir } = this.app.bajo
|
|
6
6
|
name = this.attachmentPreCheck(name)
|
|
7
7
|
if (!name) return
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
async function getPath (name, id, field, file, options = {}) {
|
|
2
2
|
const { pascalCase, getPluginDataDir } = this.app.bajo
|
|
3
|
-
const { fs } = this.
|
|
3
|
+
const { fs } = this.lib
|
|
4
4
|
const dir = `${getPluginDataDir(this.name)}/attachment/${pascalCase(name)}/${id}`
|
|
5
5
|
if (options.dirOnly) return dir
|
|
6
6
|
const path = field ? `${dir}/${field}/${file}` : `${dir}/${file}`
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
async function get (name, id, field, file, options = {}) {
|
|
2
2
|
name = this.attachmentPreCheck(name)
|
|
3
3
|
if (!name) return
|
|
4
|
-
const { find } = this.
|
|
4
|
+
const { find } = this.lib._
|
|
5
5
|
const all = await this.attachmentFind(name, id, options)
|
|
6
6
|
if (field === 'null') field = null
|
|
7
7
|
const data = find(all, { field, file })
|
|
@@ -5,7 +5,7 @@ import execFeatureHook from '../../../lib/exec-feature-hook.js'
|
|
|
5
5
|
async function create (name, inputs, options) {
|
|
6
6
|
const { generateId, runHook, isSet } = this.app.bajo
|
|
7
7
|
const { clearModel } = this.cache ?? {}
|
|
8
|
-
const { find } = this.
|
|
8
|
+
const { find } = this.lib._
|
|
9
9
|
options.dataOnly = options.dataOnly ?? true
|
|
10
10
|
options.truncateString = options.truncateString ?? true
|
|
11
11
|
const { noHook, noValidation } = options
|
|
@@ -2,7 +2,7 @@ import resolveMethod from '../../../lib/resolve-method.js'
|
|
|
2
2
|
|
|
3
3
|
async function clear (name, options = {}) {
|
|
4
4
|
const { runHook } = this.app.bajo
|
|
5
|
-
const { camelCase } = this.
|
|
5
|
+
const { camelCase } = this.lib._
|
|
6
6
|
|
|
7
7
|
await this.modelExists(name, true)
|
|
8
8
|
const { noHook } = options
|
|
@@ -2,7 +2,7 @@ import resolveMethod from '../../../lib/resolve-method.js'
|
|
|
2
2
|
|
|
3
3
|
async function create (name, options = {}) {
|
|
4
4
|
const { runHook } = this.app.bajo
|
|
5
|
-
const { camelCase } = this.
|
|
5
|
+
const { camelCase } = this.lib._
|
|
6
6
|
|
|
7
7
|
const { handler, schema } = await resolveMethod.call(this, name, 'model-create', options)
|
|
8
8
|
if (!options.noHook) {
|
|
@@ -2,7 +2,7 @@ import resolveMethod from '../../../lib/resolve-method.js'
|
|
|
2
2
|
|
|
3
3
|
async function drop (name, options = {}) {
|
|
4
4
|
const { runHook } = this.app.bajo
|
|
5
|
-
const { camelCase } = this.
|
|
5
|
+
const { camelCase } = this.lib._
|
|
6
6
|
const { handler, schema } = await resolveMethod.call(this, name, 'model-drop', options)
|
|
7
7
|
|
|
8
8
|
if (!options.noHook) {
|
|
@@ -5,7 +5,7 @@ const cache = {}
|
|
|
5
5
|
async function exists (name, thrown, options = {}) {
|
|
6
6
|
if (cache[name]) return cache[name]
|
|
7
7
|
const { runHook } = this.app.bajo
|
|
8
|
-
const { camelCase } = this.
|
|
8
|
+
const { camelCase } = this.lib._
|
|
9
9
|
const { handler, schema } = await resolveMethod.call(this, name, 'model-exists', options)
|
|
10
10
|
if (!options.noHook) {
|
|
11
11
|
await runHook(`${this.name}:beforeModelExists`, schema, options)
|
|
@@ -3,7 +3,7 @@ import resolveMethod from '../../../lib/resolve-method.js'
|
|
|
3
3
|
async function clear (name, opts = {}) {
|
|
4
4
|
const { runHook } = this.app.bajo
|
|
5
5
|
await this.modelExists(name, true)
|
|
6
|
-
const { cloneDeep, camelCase, omit } = this.
|
|
6
|
+
const { cloneDeep, camelCase, omit } = this.lib._
|
|
7
7
|
const options = cloneDeep(omit(opts, ['req', 'reply']))
|
|
8
8
|
options.req = opts.req
|
|
9
9
|
options.reply = opts.reply
|
|
@@ -4,7 +4,7 @@ import execFeatureHook from '../../../lib/exec-feature-hook.js'
|
|
|
4
4
|
async function count (name, filter = {}, opts = {}) {
|
|
5
5
|
const { runHook } = this.app.bajo
|
|
6
6
|
const { get, set } = this.cache ?? {}
|
|
7
|
-
const { cloneDeep, camelCase, omit } = this.
|
|
7
|
+
const { cloneDeep, camelCase, omit } = this.lib._
|
|
8
8
|
delete opts.record
|
|
9
9
|
const options = cloneDeep(omit(opts, ['req', 'reply']))
|
|
10
10
|
options.req = opts.req
|
|
@@ -9,7 +9,7 @@ import singleRelRows from '../../../lib/single-rel-rows.js'
|
|
|
9
9
|
async function create (name, input, opts = {}) {
|
|
10
10
|
const { generateId, runHook, isSet } = this.app.bajo
|
|
11
11
|
const { clearModel } = this.cache ?? {}
|
|
12
|
-
const { find, forOwn, cloneDeep, camelCase, omit, get, pick } = this.
|
|
12
|
+
const { find, forOwn, cloneDeep, camelCase, omit, get, pick } = this.lib._
|
|
13
13
|
delete opts.record
|
|
14
14
|
const options = cloneDeep(omit(opts, ['req', 'reply']))
|
|
15
15
|
options.req = opts.req
|
|
@@ -5,7 +5,7 @@ import execFeatureHook from '../../../lib/exec-feature-hook.js'
|
|
|
5
5
|
async function findOne (name, filter = {}, opts = {}) {
|
|
6
6
|
const { runHook, isSet } = this.app.bajo
|
|
7
7
|
const { get, set } = this.cache ?? {}
|
|
8
|
-
const { cloneDeep, camelCase, omit } = this.
|
|
8
|
+
const { cloneDeep, camelCase, omit } = this.lib._
|
|
9
9
|
delete opts.record
|
|
10
10
|
const options = cloneDeep(omit(opts, ['req', 'reply']))
|
|
11
11
|
options.req = opts.req
|
|
@@ -5,7 +5,7 @@ import execFeatureHook from '../../../lib/exec-feature-hook.js'
|
|
|
5
5
|
async function find (name, filter = {}, opts = {}) {
|
|
6
6
|
const { runHook, isSet } = this.app.bajo
|
|
7
7
|
const { get, set } = this.cache ?? {}
|
|
8
|
-
const { cloneDeep, camelCase, omit } = this.
|
|
8
|
+
const { cloneDeep, camelCase, omit } = this.lib._
|
|
9
9
|
delete opts.records
|
|
10
10
|
const options = cloneDeep(omit(opts, ['req', 'reply']))
|
|
11
11
|
options.req = opts.req
|
|
@@ -5,7 +5,7 @@ import execFeatureHook from '../../../lib/exec-feature-hook.js'
|
|
|
5
5
|
async function get (name, id, opts = {}) {
|
|
6
6
|
const { runHook, isSet } = this.app.bajo
|
|
7
7
|
const { get, set } = this.cache ?? {}
|
|
8
|
-
const { cloneDeep, camelCase, omit } = this.
|
|
8
|
+
const { cloneDeep, camelCase, omit } = this.lib._
|
|
9
9
|
delete opts.record
|
|
10
10
|
const options = cloneDeep(omit(opts, ['req', 'reply']))
|
|
11
11
|
options.req = opts.req
|
|
@@ -5,7 +5,7 @@ import execFeatureHook from '../../../lib/exec-feature-hook.js'
|
|
|
5
5
|
async function remove (name, id, opts = {}) {
|
|
6
6
|
const { runHook } = this.app.bajo
|
|
7
7
|
const { clearModel } = this.cache ?? {}
|
|
8
|
-
const { cloneDeep, camelCase, omit } = this.
|
|
8
|
+
const { cloneDeep, camelCase, omit } = this.lib._
|
|
9
9
|
delete opts.record
|
|
10
10
|
const options = cloneDeep(omit(opts, ['req', 'reply']))
|
|
11
11
|
options.req = opts.req
|
|
@@ -8,7 +8,7 @@ import singleRelRows from '../../../lib/single-rel-rows.js'
|
|
|
8
8
|
async function update (name, id, input, opts = {}) {
|
|
9
9
|
const { runHook, isSet } = this.app.bajo
|
|
10
10
|
const { clearModel } = this.cache ?? {}
|
|
11
|
-
const { forOwn, find, cloneDeep, camelCase, omit, get } = this.
|
|
11
|
+
const { forOwn, find, cloneDeep, camelCase, omit, get } = this.lib._
|
|
12
12
|
delete opts.record
|
|
13
13
|
const options = cloneDeep(omit(opts, ['req', 'reply']))
|
|
14
14
|
options.req = opts.req
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
async function upsert (name, input, opts = {}) {
|
|
2
2
|
const { generateId } = this.app.bajo
|
|
3
|
-
const { find } = this.
|
|
4
|
-
const { cloneDeep, omit } = this.
|
|
5
|
-
const
|
|
3
|
+
const { find } = this.lib._
|
|
4
|
+
const { cloneDeep, omit, merge } = this.lib._
|
|
5
|
+
const { query, omitOnUpdate = [], omitOnCreate = [] } = opts
|
|
6
|
+
const options = cloneDeep(omit(opts, ['req', 'reply', 'query', 'omitOnUpdate', 'omitOnCreate']))
|
|
6
7
|
options.req = opts.req
|
|
7
8
|
options.reply = opts.reply
|
|
8
9
|
options.dataOnly = options.dataOnly ?? true
|
|
@@ -13,9 +14,22 @@ async function upsert (name, input, opts = {}) {
|
|
|
13
14
|
if (idField.type === 'string') id = input.id ?? generateId()
|
|
14
15
|
else if (idField.type === 'integer') id = input.id ?? generateId('int')
|
|
15
16
|
id = this.sanitizeId(id, schema)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
let old
|
|
18
|
+
let body
|
|
19
|
+
const o = { dataOnly: true, noHook: true, noCache: true, hidden: options.hidden, forceNoHidden: options.forceNoHidden }
|
|
20
|
+
if (query) {
|
|
21
|
+
old = await this.recordFindOne(name, { query }, o)
|
|
22
|
+
} else {
|
|
23
|
+
o.thrownNotFound = false
|
|
24
|
+
old = await this.recordGet(name, id, o)
|
|
25
|
+
}
|
|
26
|
+
if (old) {
|
|
27
|
+
body = merge(omit(old, ['id', 'createdAt', 'updatedAt', 'removedAt']), omit(input, omitOnUpdate))
|
|
28
|
+
return await this.recordUpdate(name, old.id, body, options)
|
|
29
|
+
}
|
|
30
|
+
if (!query) input.id = id
|
|
31
|
+
body = omit(input, omitOnCreate)
|
|
32
|
+
return await this.recordCreate(name, body, options)
|
|
19
33
|
}
|
|
20
34
|
|
|
21
35
|
export default upsert
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
async function sanitizeBody ({ body = {}, schema = {}, partial, strict, extFields = [] }) {
|
|
2
2
|
const { isSet, dayjs, callHandler } = this.app.bajo
|
|
3
|
-
const { has, isString, isNumber, concat } = this.
|
|
3
|
+
const { has, isString, isNumber, concat } = this.lib._
|
|
4
4
|
const result = {}
|
|
5
5
|
for (const p of concat(schema.properties, extFields)) {
|
|
6
6
|
if (partial && !has(body, p.name)) continue
|
|
@@ -20,7 +20,7 @@ function buildFromDbSchema (schema, { fields = [], rule = {}, extFields = [] } =
|
|
|
20
20
|
const {
|
|
21
21
|
isPlainObject, get, each, isEmpty, isString, forOwn, keys,
|
|
22
22
|
find, isArray, has, cloneDeep, concat, without
|
|
23
|
-
} = this.
|
|
23
|
+
} = this.lib._
|
|
24
24
|
const obj = {}
|
|
25
25
|
const me = this
|
|
26
26
|
const refs = []
|
|
@@ -127,7 +127,7 @@ function buildFromDbSchema (schema, { fields = [], rule = {}, extFields = [] } =
|
|
|
127
127
|
|
|
128
128
|
async function validate (value, joiSchema, { ns, fields, extFields, params } = {}) {
|
|
129
129
|
const { defaultsDeep, isSet } = this.app.bajo
|
|
130
|
-
const { isString, forOwn, find } = this.
|
|
130
|
+
const { isString, forOwn, find } = this.lib._
|
|
131
131
|
|
|
132
132
|
ns = ns ?? [this.name]
|
|
133
133
|
params = defaultsDeep(params, this.config.validationParams)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
|
|
3
3
|
async function attachment (req, reply) {
|
|
4
|
-
const { isString } = this.
|
|
4
|
+
const { isString } = this.lib._
|
|
5
5
|
const { importPkg, getPluginDataDir, pascalCase } = this.app.bajo
|
|
6
6
|
const { routePath } = this.app.waibu
|
|
7
7
|
const mime = await importPkg('waibu:mime')
|
|
8
|
-
const { fs } = this.
|
|
8
|
+
const { fs } = this.lib
|
|
9
9
|
const file = `${getPluginDataDir('dobo')}/attachment/${pascalCase(req.params.model)}/${req.params.id}/${req.params.field}/${req.params.file}`
|
|
10
10
|
const mimeType = mime.getType(path.extname(file))
|
|
11
11
|
if (!fs.existsSync(file)) {
|
package/plugin/start.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import memDbStart from '../lib/mem-db/start.js'
|
|
2
|
-
import memDbInstantiate from '../lib/mem-db/instantiate.js'
|
|
3
|
-
|
|
4
|
-
async function start (conns = 'all', noRebuild = true) {
|
|
5
|
-
const { importModule, breakNsPath } = this.app.bajo
|
|
6
|
-
const { find, filter, isString, map } = this.app.bajo.lib._
|
|
7
|
-
if (conns === 'all') conns = this.connections
|
|
8
|
-
else if (isString(conns)) conns = filter(this.connections, { name: conns })
|
|
9
|
-
else conns = map(conns, c => find(this.connections, { name: c }))
|
|
10
|
-
for (const c of conns) {
|
|
11
|
-
const { ns } = breakNsPath(c.type)
|
|
12
|
-
const schemas = filter(this.schemas, { connection: c.name })
|
|
13
|
-
const mod = c.type === 'dobo:memory' ? memDbInstantiate : await importModule(`${ns}:/${this.name}/boot/instantiate.js`)
|
|
14
|
-
await mod.call(this.app[ns], { connection: c, noRebuild, schemas })
|
|
15
|
-
this.log.trace('driverInstantiated%s%s', c.driver, c.name)
|
|
16
|
-
}
|
|
17
|
-
await memDbStart.call(this)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default start
|