sumba 2.49.3 → 2.50.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.
@@ -1,12 +1,10 @@
1
- import slug from 'slug'
2
-
3
1
  async function autoInc (body, opts) {
4
2
  const { set, last } = this.app.lib._
5
3
  const query = set({}, opts.field, { $regex: new RegExp('^' + body[opts.field]) })
6
4
  const sort = set({}, opts.field, -1)
7
5
  const options = { noHook: true, skipCache: true, throwNotFound: false }
8
6
  const resp = await this.findOneRecord({ query, sort }, options)
9
- if (resp) return body[opts.field]
7
+ if (!resp) return body[opts.field]
10
8
  const rslugs = resp[opts.field].split('-')
11
9
  const slugs = body[opts.field].split('-')
12
10
  let num
@@ -28,7 +26,8 @@ async function autoInc (body, opts) {
28
26
  async function mainFn (opts = {}) {
29
27
  opts.field = opts.field ?? 'slug'
30
28
  opts.fieldSource = opts.fieldSource ?? ['name']
31
- opts.autoInc = true
29
+ opts.autoInc = opts.autoInc ?? true
30
+ opts.required = opts.required ?? true
32
31
  return {
33
32
  properties: [{
34
33
  name: opts.field ?? 'slug',
@@ -36,10 +35,13 @@ async function mainFn (opts = {}) {
36
35
  maxLength: 255,
37
36
  index: 'unique'
38
37
  }],
39
- hook: {
40
- beforeCreate: async function (body) {
38
+ hooks: [{
39
+ name: 'beforeCreateRecord',
40
+ handler: async function (body, options) {
41
41
  const { error } = this.app.bajo
42
42
  const { isEmpty, isString } = this.app.lib._
43
+ const { importPkg } = this.app.bajo
44
+ const slugify = await importPkg('waibuExtra:slugify')
43
45
  if (isEmpty(body[opts.field])) {
44
46
  if (isString(opts.fieldSource)) opts.fieldSource = [opts.fieldSource]
45
47
  const source = []
@@ -50,11 +52,11 @@ async function mainFn (opts = {}) {
50
52
  const details = [{ field: opts.fieldSource.join(', '), error: 'required' }]
51
53
  throw error('\'%s\' is required', opts.fieldSource.join(', '), { details })
52
54
  }
53
- body[opts.field] = slug(source.join(' '))
55
+ body[opts.field] = slugify(source.join(' '))
54
56
  }
55
57
  if (opts.autoInc) body[opts.field] = await autoInc.call(this, body, opts)
56
58
  }
57
- }
59
+ }]
58
60
  }
59
61
  }
60
62
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sumba",
3
- "version": "2.49.3",
3
+ "version": "2.50.0",
4
4
  "description": "Biz Suite for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -36,8 +36,7 @@
36
36
  },
37
37
  "homepage": "https://github.com/ardhi/sumba#readme",
38
38
  "dependencies": {
39
- "joi-password": "^4.3.0",
40
- "slug": "^11.0.1"
39
+ "joi-password": "^4.3.0"
41
40
  },
42
41
  "devDependencies": {
43
42
  "chai": "^6.2.2",
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-11-22
4
+
5
+ - [2.50.0] Remove `slug` package and now using `slugify` from `waibu-extra` instead
6
+
3
7
  ## 2026-11-20
4
8
 
5
9
  - [2.49.3] Bug fix in `trouble-tickets/list.js`