waibu-db 2.35.0 → 2.36.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.
- package/lib/method/create-record.js +4 -2
- package/lib/method/find-all-record.js +3 -3
- package/lib/method/find-one-record.js +4 -2
- package/lib/method/find-record.js +3 -3
- package/lib/method/get-record.js +4 -2
- package/lib/method/update-record.js +4 -2
- package/lib/util.js +8 -5
- package/package.json +1 -1
- package/wiki/CHANGES.md +1 -0
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { prepCrud, processHandler } from '../util.js'
|
|
2
2
|
|
|
3
3
|
async function createRecord ({ model, req, body, reply, options = {}, transaction } = {}) {
|
|
4
|
-
const { isEmpty } = this.app.lib._
|
|
5
4
|
const { model: mdl, opts, attachment } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], transaction })
|
|
6
5
|
|
|
7
6
|
async function handler (trx) {
|
|
8
7
|
if (opts.trx === true) opts.trx = trx
|
|
9
8
|
const ret = await mdl.createRecord(body ?? req.body, { ...opts, dataOnly: false, partial: true, strict: true })
|
|
10
|
-
if (
|
|
9
|
+
if (attachment) {
|
|
10
|
+
const { params, options: attachOpts } = attachment ?? {}
|
|
11
|
+
ret.data._attachment = await mdl.findAttachment(ret.data.id, params, attachOpts)
|
|
12
|
+
}
|
|
11
13
|
return ret
|
|
12
14
|
}
|
|
13
15
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { prepCrud, processHandler } from '../util.js'
|
|
2
2
|
|
|
3
3
|
async function findAllRecord ({ model, req, reply, options = {}, noAutoFilter, transaction } = {}) {
|
|
4
|
-
const { isEmpty } = this.app.lib._
|
|
5
4
|
const { model: mdl, opts, filter, attachment } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], noAutoFilter, transaction })
|
|
6
5
|
|
|
7
6
|
async function handler (trx) {
|
|
8
7
|
if (opts.trx === true) opts.trx = trx
|
|
9
8
|
const ret = await mdl.findAllRecord(filter, { ...opts, dataOnly: false })
|
|
10
|
-
if (
|
|
9
|
+
if (attachment) {
|
|
10
|
+
const { params, options: attachOpts } = attachment ?? {}
|
|
11
11
|
for (const d of ret.data) {
|
|
12
|
-
d._attachment = await mdl.findAttachment(d.id,
|
|
12
|
+
d._attachment = await mdl.findAttachment(d.id, params, attachOpts)
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
return ret
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { prepCrud, processHandler } from '../util.js'
|
|
2
2
|
|
|
3
3
|
async function findOneRecord ({ model, req, reply, options = {}, noAutoFilter, transaction } = {}) {
|
|
4
|
-
const { isEmpty } = this.app.lib._
|
|
5
4
|
const { model: mdl, opts, filter, attachment } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], noAutoFilter, transaction })
|
|
6
5
|
|
|
7
6
|
async function handler (trx) {
|
|
8
7
|
if (opts.trx === true) opts.trx = trx
|
|
9
8
|
const ret = await mdl.findOneRecord(filter, { ...opts, dataOnly: false })
|
|
10
|
-
if (
|
|
9
|
+
if (attachment) {
|
|
10
|
+
const { params, options: attachOpts } = attachment ?? {}
|
|
11
|
+
ret.data._attachment = await mdl.findAttachment(ret.data.id, params, attachOpts)
|
|
12
|
+
}
|
|
11
13
|
return ret
|
|
12
14
|
}
|
|
13
15
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { prepCrud, processHandler } from '../util.js'
|
|
2
2
|
|
|
3
3
|
async function findRecord ({ model, req, reply, noAutoFilter, options = {}, transaction } = {}) {
|
|
4
|
-
const { isEmpty } = this.app.lib._
|
|
5
4
|
const { model: mdl, opts, filter, attachment } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], noAutoFilter, transaction })
|
|
6
5
|
|
|
7
6
|
async function handler (trx) {
|
|
8
7
|
if (opts.trx === true) opts.trx = trx
|
|
9
8
|
const ret = await mdl.findRecord(filter, { ...opts, dataOnly: false })
|
|
10
|
-
if (
|
|
9
|
+
if (attachment) {
|
|
10
|
+
const { params, options: attachOpts } = attachment ?? {}
|
|
11
11
|
for (const d of ret.data) {
|
|
12
|
-
d._attachment = await mdl.findAttachment(d.id,
|
|
12
|
+
d._attachment = await mdl.findAttachment(d.id, params, attachOpts)
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
return ret
|
package/lib/method/get-record.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { prepCrud, getOneRecord, processHandler } from '../util.js'
|
|
2
2
|
|
|
3
3
|
async function getRecord ({ model, req, reply, id, options = {}, transaction, noAutoFilter } = {}) {
|
|
4
|
-
const { isEmpty } = this.app.lib._
|
|
5
4
|
const { model: mdl, recId, filter, attachment, opts } = await prepCrud.call(this, { model, req, reply, id, options, args: ['model', 'id'], transaction, noAutoFilter })
|
|
6
5
|
const me = this
|
|
7
6
|
|
|
8
7
|
async function handler (trx) {
|
|
9
8
|
if (opts.trx === true) opts.trx = trx
|
|
10
9
|
const data = await getOneRecord.call(me, mdl, recId, filter, { ...opts, dataOnly: false })
|
|
11
|
-
if (
|
|
10
|
+
if (attachment) {
|
|
11
|
+
const { params, options: attachOpts } = attachment ?? {}
|
|
12
|
+
data._attachment = await mdl.findAttachment(data.id, params, attachOpts)
|
|
13
|
+
}
|
|
12
14
|
return data
|
|
13
15
|
}
|
|
14
16
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { prepCrud, getOneRecord, processHandler } from '../util.js'
|
|
2
2
|
|
|
3
3
|
async function updateRecord ({ model, req, reply, id, body, options = {}, transaction } = {}) {
|
|
4
|
-
const { isEmpty } = this.app.lib._
|
|
5
4
|
const { model: mdl, filter, opts, recId, attachment } = await prepCrud.call(this, { model, req, reply, id, options, args: ['model', 'id'], transaction })
|
|
6
5
|
const me = this
|
|
7
6
|
|
|
@@ -12,7 +11,10 @@ async function updateRecord ({ model, req, reply, id, body, options = {}, transa
|
|
|
12
11
|
opts._data = resp.data
|
|
13
12
|
}
|
|
14
13
|
const ret = await mdl.updateRecord(recId, body ?? req.body, { ...opts, dataOnly: false, partial: true, strict: true })
|
|
15
|
-
if (
|
|
14
|
+
if (attachment) {
|
|
15
|
+
const { params, options: attachOpts } = attachment ?? {}
|
|
16
|
+
ret.data._attachment = await mdl.findAttachment(recId, params, attachOpts)
|
|
17
|
+
}
|
|
16
18
|
return ret
|
|
17
19
|
}
|
|
18
20
|
|
package/lib/util.js
CHANGED
|
@@ -74,10 +74,13 @@ export async function prepCrud (options = {}) {
|
|
|
74
74
|
opts.reply = reply
|
|
75
75
|
opts.trx = opts.trx ?? _options.trx ?? transaction ?? true
|
|
76
76
|
|
|
77
|
-
let attachment =
|
|
78
|
-
if (attachment
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
let attachment = req.query.attachment ?? opts.attachment ?? false
|
|
78
|
+
if (attachment) {
|
|
79
|
+
if (req.query.attachment || attachment === true) attachment = { params: {}, options: { stats: true, mimeType: true, thumbnail: true } }
|
|
80
|
+
attachment.options.stats = attachment.options.stats ?? req.query.stats
|
|
81
|
+
attachment.options.mimeType = attachment.options.mimeType ?? req.query.mimeType
|
|
82
|
+
attachment.options.thumbnail = attachment.options.thumbnail ?? req.query.thumbnail
|
|
83
|
+
}
|
|
81
84
|
|
|
82
85
|
let refs = []
|
|
83
86
|
const headers = parseObject(req.headers, { parseValue: true })
|
|
@@ -85,7 +88,7 @@ export async function prepCrud (options = {}) {
|
|
|
85
88
|
if (isSet(headers['x-refs'])) refs = headers['x-refs']
|
|
86
89
|
if (typeof refs === 'string' && !['*', 'all'].includes(refs)) refs = [refs]
|
|
87
90
|
if (refs.length > 0) _options.refs = refs
|
|
88
|
-
_options.
|
|
91
|
+
_options.attachment = headers['x-attachments'] === 'true'
|
|
89
92
|
|
|
90
93
|
const recId = id ?? params.id ?? req.query.id
|
|
91
94
|
let mdl = model
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED