Skip to content

Commit

Permalink
no empty array as argument on check()
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Nov 28, 2023
1 parent 69f5dab commit ae049c8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/nocap/src/classes/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,18 @@ export default class {
await this.check(this.checks)
return this.results.dump()
}

if(typeof keys === 'string')
return this._check(keys)

if(keys instanceof Array) {
if(keys instanceof Array && keys.length) {
let result = {}
for(const key of keys){
result = { ...result, ...await this._check(key) }
}
return new Promise(resolve => resolve(result))
}
return this.throw(`check(${keys}) failed. keys must be string or populated array`)
}

async _check(key){
Expand All @@ -108,6 +109,7 @@ export default class {

if( typeof key !== 'string')
throw new Error('Key must be string')

if( !this?.adapters?.[adapter]?.[`check_${key}`] )
throw new Error(`check_${key} method not found in ${adapter} Adapter, key should be 'connect', 'read', or 'write'`)

Expand Down

0 comments on commit ae049c8

Please sign in to comment.