heroku/heroku-pg

View on GitHub
lib/setter.js

Summary

Maintainability
A
1 hr
Test Coverage
'use strict'
 
const cli = require('heroku-cli-util')
const co = require('co')
 
exports.boolean = (value) => {
switch (value) {
case 'true': case 'TRUE': case 'ON': case 'on': case true:
return true
case 'false': case 'FALSE': case 'OFF': case 'off': case null: case false:
return false
default:
throw new TypeError('Invalid value. Valid options are: a boolean value')
}
}
 
exports.enum = (value) => {
return value
}
 
exports.numeric = (value) => {
let n = Number(value)
if (!isFinite(n)) {
throw new TypeError('Invalid value. Valid options are: a numeric value')
}
return n
}
 
Function `generate` has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
exports.generate = (name, convert, explain) => {
return co.wrap(function * run (context, heroku) {
const host = require('./host')
const util = require('./util')
const fetcher = require('./fetcher')(heroku)
const {app, args} = context
const {value, database} = args
 
const db = yield fetcher.addon(app, database)
 
if (util.starterPlan(db)) throw new Error('This operation is not supported by Hobby tier databases.')
if (util.legacyPlan(db)) throw new Error('This operation is not supported by Legacy tier databases.')
 
if (!value) {
let settings = yield heroku.get(`/postgres/v0/databases/${db.id}/config`, {host: host(db)})
let setting = settings[name]
Similar blocks of code found in 2 locations. Consider refactoring.
cli.log(`${name.replace(/_/g, '-')} is set to ${setting.value} for ${db.name}.`)
cli.log(explain(setting))
} else {
let settings = yield heroku.patch(`/postgres/v0/databases/${db.id}/config`, {
host: host(db),
body: { [name]: convert(value) }
})
let setting = settings[name]
Similar blocks of code found in 2 locations. Consider refactoring.
cli.log(`${name.replace(/_/g, '-')} has been set to ${setting.value} for ${db.name}.`)
cli.log(explain(setting))
}
})
}