dobo 1.0.18 → 1.0.20

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.
@@ -185,7 +185,7 @@
185
185
  "validation": {
186
186
  "any": {
187
187
  "required": "Required",
188
- "only": "Must match with {{ref}}"
188
+ "only": "Must match with %(ref)s"
189
189
  },
190
190
  "string": {
191
191
  "alphanum": "Must only contain alpha-numeric characters",
@@ -200,14 +200,14 @@
200
200
  "hex": "Must only contain hexadecimal characters",
201
201
  "hexAlign": "Hex decoded representation must be byte aligned",
202
202
  "hostname": "Must be a valid hostname",
203
- "ip": "must be a valid ip address with a {{cidr}} CIDR",
204
- "ipVersion": "Must be a valid ip address of one of the following versions {{version}} with a {{cidr}} CIDR",
203
+ "ip": "must be a valid ip address with a %(cidr)s CIDR",
204
+ "ipVersion": "Must be a valid ip address of one of the following versions %(version)s with a %(cidr)s CIDR",
205
205
  "isoDate": "Must be in iso format",
206
206
  "isoDuration": "Must be a valid ISO 8601 duration",
207
- "length": "Length must be {{limit}} characters long",
207
+ "length": "Length must be %(limit)s characters long",
208
208
  "lowercase": "Must only contain lowercase characters",
209
- "max": "Length must be less than or equal to {{limit}} characters long",
210
- "min": "Length must be at least {{limit}} characters long",
209
+ "max": "Length must be less than or equal to %(limit)s characters long",
210
+ "min": "Length must be at least %(limit)s characters long",
211
211
  "token": "Must only contain alpha-numeric and underscore characters",
212
212
  "trim": "Must not have leading or trailing whitespace",
213
213
  "uri": "Must be a valid uri",
package/bajo/intl/id.json CHANGED
@@ -183,7 +183,7 @@
183
183
  "validation": {
184
184
  "any": {
185
185
  "required": "Harus diisi/dipilih",
186
- "only": "Harus sesuai dengan {{ref}}"
186
+ "only": "Harus sesuai dengan %(ref)s"
187
187
  },
188
188
  "string": {
189
189
  "alphanum": "Harus berupa alfa numerik karakter saja",
@@ -198,14 +198,14 @@
198
198
  "hex": "Harus mengandung hexadesimal karakter yang valid saja",
199
199
  "hexAlign": "Representasi hex yang terdekode harus byte aligned",
200
200
  "hostname": "Harus berupa nama host yang valid",
201
- "ip": "Harus berupa alamat ip yang valid dengan CIDR {{cidr}}",
202
- "ipVersion": "Harus berupa alamat ip yang valid dengan versi {{version}} dan CIDR {{cidr}}",
201
+ "ip": "Harus berupa alamat ip yang valid dengan CIDR %(cidr)s",
202
+ "ipVersion": "Harus berupa alamat ip yang valid dengan versi %(version)s dan CIDR %(cidr)s",
203
203
  "isoDate": "Harus dalam format ISO",
204
204
  "isoDuration": "Harus berupa durasi ISO 8601 yang valid",
205
- "length": "Panjang harus pas {{limit}} karakter",
205
+ "length": "Panjang harus pas %(limit)s karakter",
206
206
  "lowercase": "Hanya boleh mengandung huruf kecil saja",
207
- "max": "Panjang karakter harus lebih kecil atau sama dengan {{limit}} karakter",
208
- "min": "Panjang karakter harus setidaknya {{limit}} karakter",
207
+ "max": "Panjang karakter harus lebih kecil atau sama dengan %(limit)s karakter",
208
+ "min": "Panjang karakter harus setidaknya %(limit)s karakter",
209
209
  "token": "Hanya boleh terdiri atas karakter alfanumerik dan garis bawah saja",
210
210
  "trim": "Tidak boleh memiliki spasi didepan atau dibelakang",
211
211
  "uri": "Harus berupa URI yang valid",
@@ -213,17 +213,17 @@
213
213
  },
214
214
  "number": {
215
215
  "base": "Harus berupa angka",
216
- "greater": "Harus lebih besar dari {{limit}}",
216
+ "greater": "Harus lebih besar dari %(limit)s",
217
217
  "infinity": "Tidak bisa tak terbatas",
218
218
  "integer": "Harus berupa integer",
219
- "less": "Harus lebih kecil dari {{limit}}",
220
- "max": "Harus lebih kecil atau sama dengan {{limit}}",
221
- "min": "Harus lebih besar atau sama dengan {{limit}}",
222
- "multiple": "Harus kelipatan dari {{multiple}}",
219
+ "less": "Harus lebih kecil dari %(limit)s",
220
+ "max": "Harus lebih kecil atau sama dengan %(limit)s",
221
+ "min": "Harus lebih besar atau sama dengan %(limit)s",
222
+ "multiple": "Harus kelipatan dari %(multiple)s",
223
223
  "negative": "Harus berupa angka negatif",
224
224
  "port": "Harus berupa nomor port yang valid",
225
225
  "positive": "Harus berupa angka positif",
226
- "precision": "Harus memiliki tidak lebih dari {{limit}} tempat desimal",
226
+ "precision": "Harus memiliki tidak lebih dari %(limit)s tempat desimal",
227
227
  "unsafe": "Harus berupa nomor yang aman"
228
228
  }
229
229
  }
@@ -1,17 +1,19 @@
1
1
  import path from 'path'
2
2
 
3
- async function copyUploaded (name, id, { req, setField, setFile, mimeType, stats, silent = true } = {}) {
3
+ async function copyUploaded (name, id, options = {}) {
4
4
  const { fs } = this.app.bajo.lib
5
+ const { omit } = this.app.bajo.lib._
6
+ const { req, setField, setFile, mimeType, stats, silent = true } = options
5
7
  name = this.attachmentPreCheck(name)
6
8
  if (!name) {
7
9
  if (silent) return
8
10
  throw this.error('isMissing%s', this.print.write('field.name'))
9
11
  }
10
- if (!this.bajoWeb) {
12
+ if (!this.app.waibu) {
11
13
  if (silent) return
12
- throw this.error('missingPlugin%s')
14
+ throw this.error('missingPlugin%s', 'Waibu')
13
15
  }
14
- const { dir, files } = await this.bajoWeb.getUploadedFiles(req.id, false, true)
16
+ const { dir, files } = await this.app.waibu.getUploadedFiles(req.id, false, true)
15
17
  const result = []
16
18
  if (files.length === 0) return result
17
19
  for (const f of files) {
@@ -20,6 +22,7 @@ async function copyUploaded (name, id, { req, setField, setFile, mimeType, stats
20
22
  field = setField ?? field
21
23
  const file = setFile ?? parts.join('@')
22
24
  const opts = { source: f, field, file, mimeType, stats, req }
25
+ console.log(setField, setFile, omit(opts, ['req']))
23
26
  const rec = await this.attachmentCreate(name, id, opts)
24
27
  delete rec.dir
25
28
  result.push(rec)
@@ -4,6 +4,7 @@ import checkUnique from '../../../lib/check-unique.js'
4
4
  import handleAttachmentUpload from '../../../lib/handle-attachment-upload.js'
5
5
  import execValidation from '../../../lib/exec-validation.js'
6
6
  import execFeatureHook from '../../../lib/exec-feature-hook.js'
7
+ import singleRelRows from '../../../lib/single-rel-rows.js'
7
8
 
8
9
  async function create (name, input, opts = {}) {
9
10
  const { generateId, runHook, isSet } = this.app.bajo
@@ -49,6 +50,7 @@ async function create (name, input, opts = {}) {
49
50
  nbody[k] = v
50
51
  })
51
52
  record = await handler.call(this.app[driver.ns], { schema, body: nbody, options })
53
+ if (isSet(options.rels)) await singleRelRows.call(this, { schema, record: record.data, options })
52
54
  if (options.req) {
53
55
  if (options.req.file) await handleAttachmentUpload.call(this, { name: schema.name, id: body.id, body, options, action: 'create' })
54
56
  if (options.req.flash && !options.noFlash) options.req.flash('notify', options.req.t('recordCreated'))
@@ -32,12 +32,12 @@ async function findOne (name, filter = {}, opts = {}) {
32
32
  }
33
33
  const record = await handler.call(this.app[driver.ns], { schema, filter, options })
34
34
  record.data = record.data[0]
35
+ if (isSet(options.rels)) await singleRelRows.call(this, { schema, record: record.data, options })
35
36
  if (!noHook) {
36
37
  await runHook(`${this.name}.${camelCase(name)}:afterRecordFindOne`, filter, options, record)
37
38
  await runHook(`${this.name}:afterRecordFindOne`, name, filter, options, record)
38
39
  }
39
40
  record.data = await this.pickRecord({ record: record.data, fields, schema, hidden, forceNoHidden })
40
- if (isSet(options.rels)) await singleRelRows.call(this, { schema, record: record.data, options })
41
41
  if (set && !noCache) await set({ model: name, filter, options, record })
42
42
  return dataOnly ? record.data : record
43
43
  }
@@ -30,6 +30,7 @@ async function find (name, filter = {}, opts = {}) {
30
30
  }
31
31
  }
32
32
  const records = await handler.call(this.app[driver.ns], { schema, filter, options })
33
+ if (isSet(options.rels)) await multiRelRows.call(this, { schema, records: records.data, options })
33
34
  if (!noHook) {
34
35
  await runHook(`${this.name}.${camelCase(name)}:afterRecordFind`, filter, options, records)
35
36
  await runHook(`${this.name}:afterRecordFind`, name, filter, options, records)
@@ -37,7 +38,6 @@ async function find (name, filter = {}, opts = {}) {
37
38
  for (const idx in records.data) {
38
39
  records.data[idx] = await this.pickRecord({ record: records.data[idx], fields, schema, hidden, forceNoHidden })
39
40
  }
40
- if (isSet(options.rels)) await multiRelRows.call(this, { schema, records: records.data, options })
41
41
  if (set && !noCache) await set({ model: name, filter, options, records })
42
42
  return dataOnly ? records.data : records
43
43
  }
@@ -27,12 +27,12 @@ async function get (name, id, opts = {}) {
27
27
  }
28
28
  }
29
29
  const record = await handler.call(this.app[driver.ns], { schema, id, options })
30
+ if (isSet(options.rels)) await singleRelRows.call(this, { schema, record: record.data, options })
30
31
  if (!noHook) {
31
32
  await runHook(`${this.name}.${camelCase(name)}:afterRecordGet`, id, options, record)
32
33
  await runHook(`${this.name}:afterRecordGet`, name, id, options, record)
33
34
  }
34
35
  record.data = await this.pickRecord({ record: record.data, fields, schema, hidden, forceNoHidden })
35
- if (isSet(options.rels)) await singleRelRows.call(this, { schema, record: record.data, options })
36
36
 
37
37
  if (set && !noCache) await set({ model: name, id, options, record })
38
38
  return dataOnly ? record.data : record
@@ -3,6 +3,7 @@ import checkUnique from '../../../lib/check-unique.js'
3
3
  import handleAttachmentUpload from '../../../lib/handle-attachment-upload.js'
4
4
  import execValidation from '../../../lib/exec-validation.js'
5
5
  import execFeatureHook from '../../../lib/exec-feature-hook.js'
6
+ import singleRelRows from '../../../lib/single-rel-rows.js'
6
7
 
7
8
  async function update (name, id, input, opts = {}) {
8
9
  const { runHook, isSet } = this.app.bajo
@@ -39,6 +40,7 @@ async function update (name, id, input, opts = {}) {
39
40
  })
40
41
  delete nbody.id
41
42
  const record = await handler.call(this.app[driver.ns], { schema, id, body: nbody, options })
43
+ if (isSet(options.rels)) await singleRelRows.call(this, { schema, record: record.data, options })
42
44
  if (options.req) {
43
45
  if (options.req.file) await handleAttachmentUpload.call(this, { name: schema.name, id, body, options, action: 'update' })
44
46
  if (options.req.flash && !options.noFlash) options.req.flash('notify', options.req.t('recordUpdated'))
@@ -2,8 +2,8 @@ async function mergeAttachmentInfo (rec, source, { mimeType, stats, fullPath })
2
2
  const { importPkg } = this.app.bajo
3
3
  const { fs } = this.app.bajo.lib
4
4
  const { pick } = this.app.bajo.lib._
5
- if (!this.bajoWeb) return
6
- const mime = await importPkg('bajoWeb:mime')
5
+ if (!this.app.waibu) return
6
+ const mime = await importPkg('waibu:mime')
7
7
 
8
8
  if (mimeType) rec.mimeType = mime.getType(rec.file)
9
9
  if (fullPath) rec.fullPath = source
@@ -10,7 +10,7 @@ async function singleRelRows ({ schema, record, options = {} }) {
10
10
  const val = prop.rel[key]
11
11
  if (val.fields.length === 0) continue
12
12
  const relschema = this.getSchema(val.schema)
13
- const relFilter = options.filter
13
+ const relFilter = options.filter ?? {}
14
14
  const query = {}
15
15
  query[val.propName] = record[prop.name]
16
16
  relFilter.query = query
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "Database ORM/ODM for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,16 @@
1
+ import path from 'path'
2
+
3
+ async function attachment (req, reply) {
4
+ const { importPkg, getPluginDataDir, pascalCase } = this.app.bajo
5
+ const mime = await importPkg('waibu:mime')
6
+ const { fs } = this.app.bajo.lib
7
+ const file = `${getPluginDataDir('dobo')}/attachment/${pascalCase(req.params.model)}/${req.params.id}/${req.params.field}/${req.params.file}`
8
+ if (!fs.existsSync(file)) throw this.error('_notFound', { noView: true })
9
+ const mimeType = mime.getType(path.extname(file))
10
+ reply.header('Content-Type', mimeType)
11
+ const stream = fs.createReadStream(file)
12
+ reply.send(stream)
13
+ return reply
14
+ }
15
+
16
+ export default attachment