bajo 0.2.17 → 0.2.18

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,8 +1,9 @@
1
- import { filter, isArray, each, pullAt, camelCase } from 'lodash-es'
1
+ import { filter, isArray, each, pullAt, camelCase, has, find, set } from 'lodash-es'
2
2
 
3
3
  async function buildCollections (options = {}) {
4
- const { getConfig, getPluginName, fatal, runHook } = this.bajo.helper
5
- let { plugin, handler, dupChecks = [], container = 'connections' } = options
4
+ const { getConfig, getPluginName, fatal, runHook, error } = this.bajo.helper
5
+ let { plugin, handler, dupChecks = [], container = 'connections', useDefaultName } = options
6
+ useDefaultName = useDefaultName ?? true
6
7
  if (!plugin) plugin = getPluginName(4)
7
8
  const cfg = getConfig(plugin, { full: true })
8
9
  if (!cfg[container]) return []
@@ -12,6 +13,12 @@ async function buildCollections (options = {}) {
12
13
  const deleted = []
13
14
  for (const index in cfg[container]) {
14
15
  const item = cfg[container][index]
16
+ if (useDefaultName) {
17
+ if (!has(item, 'name')) {
18
+ if (find(cfg[container], { name: 'default' })) throw error('Connection \'default\' already exists')
19
+ else item.name = 'default'
20
+ }
21
+ }
15
22
  const result = await handler.call(this, { item, index, cfg })
16
23
  if (result) cfg[container][index] = result
17
24
  else if (result === false) deleted.push(index)
@@ -20,12 +27,11 @@ async function buildCollections (options = {}) {
20
27
 
21
28
  // check for duplicity
22
29
  each(cfg[container], c => {
23
- const checker = {}
24
30
  each(dupChecks, d => {
25
- checker[d] = c[d]
31
+ const checker = set({}, d, c[d])
32
+ const match = filter(cfg[container], checker)
33
+ if (match.length > 1) fatal('One or more %s shared the same \'%s\'', container, dupChecks.join(', '))
26
34
  })
27
- const match = filter(cfg[container], checker)
28
- if (match.length > 1) fatal('One or more %s shared the same \'%s\'', container, dupChecks.join(', '), { code: 'BAJOMQTT_CONNECTION_NOT_UNIQUE' })
29
35
  })
30
36
  await runHook(`${plugin}:${camelCase(`after build ${container}`)}`)
31
37
  return cfg[container]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo",
3
- "version": "0.2.17",
3
+ "version": "0.2.18",
4
4
  "description": "A framework to build a giant monstrous app rapidly",
5
5
  "main": "boot/index.js",
6
6
  "scripts": {