diff --git a/.eslintrc.yml b/.eslintrc.yml index 2ab1dd6..acb7e9d 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -3,7 +3,9 @@ env: es6: true node: true mocha: true -extends: 'eslint:recommended' +extends: ['eslint:recommended', 'nodejs'] +plugins: + - 'you-dont-need-lodash-underscore' rules: indent: - error @@ -28,3 +30,38 @@ rules: arrow-parens: ["warn", "as-needed"] arrow-body-style: ["warn", "as-needed"] prefer-const: warn + 'you-dont-need-lodash-underscore/concat': warn + 'you-dont-need-lodash-underscore/fill': warn + 'you-dont-need-lodash-underscore/find': warn + 'you-dont-need-lodash-underscore/detect': warn + 'you-dont-need-lodash-underscore/find-index': warn + 'you-dont-need-lodash-underscore/index-of': warn + 'you-dont-need-lodash-underscore/join': warn + 'you-dont-need-lodash-underscore/last-index-of': warn + 'you-dont-need-lodash-underscore/reverse': warn + 'you-dont-need-lodash-underscore/each': warn + 'you-dont-need-lodash-underscore/for-each': warn + 'you-dont-need-lodash-underscore/every': warn + 'you-dont-need-lodash-underscore/all': warn + 'you-dont-need-lodash-underscore/filter': warn + 'you-dont-need-lodash-underscore/select': warn + 'you-dont-need-lodash-underscore/includes': warn + 'you-dont-need-lodash-underscore/contains': warn + 'you-dont-need-lodash-underscore/map': warn + 'you-dont-need-lodash-underscore/collect': warn + 'you-dont-need-lodash-underscore/reduce': warn + 'you-dont-need-lodash-underscore/inject': warn + 'you-dont-need-lodash-underscore/foldl': warn + 'you-dont-need-lodash-underscore/reduce-right': warn + 'you-dont-need-lodash-underscore/foldr': warn + 'you-dont-need-lodash-underscore/size': warn + 'you-dont-need-lodash-underscore/some': warn + 'you-dont-need-lodash-underscore/any': warn + 'you-dont-need-lodash-underscore/is-na-n': warn + 'you-dont-need-lodash-underscore/extend-own': warn + 'you-dont-need-lodash-underscore/assign': warn + 'you-dont-need-lodash-underscore/keys': warn + 'you-dont-need-lodash-underscore/repeat': warn + 'you-dont-need-lodash-underscore/to-lower': warn + 'you-dont-need-lodash-underscore/to-upper': warn + 'you-dont-need-lodash-underscore/trim': warn diff --git a/gulpfile.js b/gulpfile.js index fba7ce8..f872f56 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,28 +1,30 @@ -const _ = require('lodash') - , fs = require('fs') - , path = require('path') - , p = require('bluebird') - , chalk = require('chalk') - , coveralls = require('gulp-coveralls') - , debug = require('gulp-debug') - , del = require('del') - , gulp = require('gulp') - , gulpif = require('gulp-if') - , gutil = require('gulp-util') - , istanbul = require('gulp-istanbul') - , eslint = require('gulp-eslint') - , licenseFinder = require('gulp-license-finder') - , minimist = require('minimist') - , mkdirp = require('mkdirp') - , mocha = require('gulp-mocha') - , notify = require('gulp-notify') - , f = require('util').format.bind(null) - , pkg = require('./package') - , jenkins = !!process.env['JENKINS_URL']; +'use strict'; + +const _ = require('lodash'); +const fs = require('fs'); +const path = require('path'); +const Promise = require('bluebird'); +const chalk = require('chalk'); +const coveralls = require('gulp-coveralls'); +const debug = require('gulp-debug'); +const del = require('del'); +const gulp = require('gulp'); +const gulpif = require('gulp-if'); +const gutil = require('gulp-util'); +const istanbul = require('gulp-istanbul'); +const eslint = require('gulp-eslint'); +const licenseFinder = require('gulp-license-finder'); +const minimist = require('minimist'); +const mkdirp = require('mkdirp'); +const mocha = require('gulp-mocha'); +const notify = require('gulp-notify'); +const f = (...args) => require('util').format(...args); +const pkg = require('./package'); +const jenkins = !!process.env['JENKINS_URL']; let taskSpecs; -p.promisifyAll(fs); +Promise.promisifyAll(fs); process.env['NODE_ENV'] = 'test'; const toRelativePath = (file, baseDir) => { @@ -38,7 +40,8 @@ const toArray = (s, sep, format) => s.split(sep || ',').map(item => f(format || const rm = src => del([src], {dryRun: cmdOpt['dry-run']}) .then(files => { if (cmdOpt.verbose) { - gutil.log(files && files.length ? $.yellow(f('Files and folders deleted :', toRelativePath(files).join(', '))) : $.yellow(f('Nothing deleted'))); + gutil.log(files && files.length ? $.yellow(f('Files and folders deleted :', toRelativePath(files) + .join(', '))) : $.yellow(f('Nothing deleted'))); } }); @@ -67,6 +70,9 @@ if (cmdOpt['log-level']) { const $ = new chalk.constructor({enabled: cmdOpt.color}); process.env['HW_LOG_COLORS'] = cmdOpt.color; +/** + * Configuration + */ const config = { distDir: 'dist', reportDir: 'dist/reports', @@ -167,7 +173,7 @@ taskSpecs = { log($.bold('Tasks')); const tasks = []; _.forIn(taskSpecs, (taskSpec, taskSpecName) => { - const task = _.omit(taskSpec, 'task'); + const task = _.pick(taskSpec, ['name', 'desc', 'deps', 'config', 'providesFn']); l = Math.max(taskSpecName.length, l); task.name = taskSpecName; task.providesFn = typeof taskSpec.task === 'function'; @@ -176,7 +182,7 @@ taskSpecs = { tasks.forEach(task => { log(false, ' %s : %s', $.cyan(_.padEnd(task.name, l)), task.desc); if (task.deps) { - log(false, ' %s', $.yellow(f('[%s]', task.deps.join(', ')))); + log(false, ' %s', $.yellow(f('[%s]', (Array.isArray(task.deps) ? task.deps : [task.deps]).join(', ')))); } log(false, ' '); if (task.config) { @@ -200,7 +206,7 @@ taskSpecs = { config: { src: [config.distDir, config.reportDir, config.lintReportDir, config.testReportDir] }, - task: t => p.each(t.config.src, dir => p.fromNode(mkdirp.bind(mkdirp, dir)) + task: t => Promise.each(t.config.src, dir => Promise.fromNode(mkdirp.bind(mkdirp, dir)) .then(dir => { if (cmdOpt.verbose) { gutil.log(dir ? $.yellow(f('Directory created :', toRelativePath(dir))) : $.yellow(f('Nothing created'))); @@ -270,18 +276,18 @@ taskSpecs = { desc: 'Find licenses in node project and dependencies', task: () => { const dest = path.join(config.distDir, 'licenses.csv'); - return licenseFinder(path.basename(dest), - { - csv: true, - depth: 1 - }) - .once('finish', function () { - if (cmdOpt.verbose) { - gutil.log($.yellow(f('Created license report : %s', dest))); - } - this.emit('end'); - }) - .pipe(gulp.dest(path.dirname(dest))); + const lf = licenseFinder(path.basename(dest), { + csv: true, + depth: 1 + }); + lf.once('finish', () => { + if (cmdOpt.verbose) { + gutil.log($.yellow(f('Created license report : %s', dest))); + } + lf.emit('end'); + }); + lf.pipe(gulp.dest(path.dirname(dest))); + return lf; } }, sources: { @@ -299,72 +305,78 @@ taskSpecs = { } }; -const initTasks = () => { - const taskSpecTransformer = baseNs => (result, taskSpec, taskSpecName) => { - const isTaskGroup = () => !Object.keys(_.pick(taskSpec, ['deps', 'task', 'desc'])).length; - const dryRun = () => { - if (cmdOpt['dry-run']) { - if (_.get(item, 'config.src')) { - return gulp.src(item.config.src) - .pipe(debug({title: ns})); - } - return true; +const taskSpecTransformer = baseNs => (result, taskSpec, taskSpecName) => { + const isTaskGroup = () => !Object.keys(_.pick(taskSpec, ['deps', 'task', 'desc'])).length; + const dryRun = () => { + if (cmdOpt['dry-run']) { + if (_.get(item, 'config.src')) { + return gulp.src(item.config.src) + .pipe(debug({title: ns})); } - }; - const ns = baseNs ? (taskSpecName === (_.get(config, 'taskSpecs.defaultGroupTask') || 'default') ? baseNs : path.join(baseNs, taskSpecName)) : taskSpecName; - if (isTaskGroup()) { - _.transform(taskSpec, taskSpecTransformer(ns), result); - return; + return true; } - const item = result[ns] = _.omit(taskSpec, ['desc', 'deps', 'task', 'config']); - if (taskSpec.desc) { - item.desc = typeof taskSpec.desc === 'function' ? taskSpec.desc(taskSpecName, taskSpec) : taskSpec.desc; - } - if (taskSpec.deps) { - item.deps = []; - (Array.isArray(taskSpec.deps) ? taskSpec.deps : [taskSpec.deps]).forEach(dep => { - if (dep.indexOf('/') === 0) { - item.deps.push(dep.substring(1)); - } else { - item.deps.push(baseNs ? path.join(baseNs, dep) : dep); + }; + const ns = baseNs ? + ( + taskSpecName === (_.get(config, 'taskSpecs.defaultGroupTask') || 'default') ? + baseNs : + path.join(baseNs, taskSpecName) + ) : + taskSpecName; + const group = isTaskGroup(); + if (group) { + _.transform(taskSpec, taskSpecTransformer(ns), result); + return; + } + const item = result[ns] = _.omit(taskSpec, ['desc', 'deps', 'task', 'config']); + if (taskSpec.desc) { + item.desc = typeof taskSpec.desc === 'function' ? taskSpec.desc(taskSpecName, taskSpec) : taskSpec.desc; + } + if (taskSpec.deps) { + item.deps = []; + (Array.isArray(taskSpec.deps) ? taskSpec.deps : [taskSpec.deps]).forEach(dep => { + if (dep.indexOf('/') === 0) { + item.deps.push(dep.substring(1)); + } else { + item.deps.push(baseNs ? path.join(baseNs, dep) : dep); + } + }); + } + if (typeof taskSpec.task === 'function') { + item.task = cb => { + if (dryRun(item.config)) { + if (!_.get(item, 'config.continueOnDryRun')) { + return cb(); } + } + return taskSpec.task(_.omit(item, 'task'), (err, data) => { + if (cmdOpt.verbose && data) { + gutil.log($.yellow('Task result :', data)); + } + cb(err); }); + }; + } + if (taskSpec.config) { + item.config = taskSpec.config; + } +}; + +taskSpecs = _.transform(taskSpecs, taskSpecTransformer(), {}); + +const registerTasks = taskSpecs => { + _.forIn(taskSpecs, (taskSpec, taskSpecName) => { + const args = [taskSpecName]; + if (!taskSpec.desc && taskSpec.deps && taskSpec.deps.length === 1) { + taskSpec.desc = taskSpecs[_.first(taskSpec.deps)].desc; } - if (typeof taskSpec.task === 'function') { - item.task = cb => { - if (dryRun(item.config)) { - if (!_.get(item, 'config.continueOnDryRun')) { - return cb(); - } - } - return taskSpec.task.call(this, _.omit(item, 'task'), (err, data) => { - if (cmdOpt.verbose && data) { - gutil.log($.yellow('Task result :', data)); - } - cb(err); - }); - }; + if (taskSpec.deps) { + args.push(taskSpec.deps); } - if (taskSpec.config) { - item.config = taskSpec.config; + if (taskSpec.task) { + args.push(taskSpec.task); } - }; - const registerTasks = () => { - _.forIn(taskSpecs, (taskSpec, taskSpecName) => { - const args = [taskSpecName]; - if (!taskSpec.desc && taskSpec.deps && taskSpec.deps.length === 1) { - taskSpec.desc = taskSpecs[_.first(taskSpec.deps)].desc; - } - if (taskSpec.deps) { - args.push(taskSpec.deps); - } - if (taskSpec.task) { - args.push(taskSpec.task); - } - gulp.task(...args); - }); - }; - taskSpecs = _.transform(taskSpecs, taskSpecTransformer(), {}); - registerTasks(); + gulp.task(...args); + }); }; -initTasks(); \ No newline at end of file +registerTasks(taskSpecs); diff --git a/lib/entity.js b/lib/entity.js index d46de33..407fd72 100644 --- a/lib/entity.js +++ b/lib/entity.js @@ -1,3 +1,5 @@ +'use strict'; + const Promise = require('bluebird'); const util = require('util'); const _ = require('lodash'); @@ -48,7 +50,11 @@ class Entity { const type = clazz.type; return Promise.resolve() .then(() => { - logger.enabledLevels.debug && log.debug('searching %s entity ID with index "%s" matching "%s"', type, name, value); + logger.enabledLevels.debug && log.debug('searching %s entity ID with index "%s" matching "%s"', + type, + name, + value + ); const index = clazz.indexes && clazz.indexes[name]; if (!index) { logger.enabledLevels.debug && log.debug('no index "%s" for entity "%s"', name, type); @@ -67,7 +73,11 @@ class Entity { if (result) { return result; } - logger.enabledLevels.debug && log.debug('searching %s entity ID with link "%s" matching "%s"', type, name, value); + logger.enabledLevels.debug && log.debug('searching %s entity ID with link "%s" matching "%s"', + type, + name, + value + ); const link = clazz.links && clazz.links[name]; if (!link) { logger.enabledLevels.debug && log.debug('no link "%s" for entity "%s"', name, type); @@ -170,7 +180,9 @@ class Entity { return ohm.exec('exists', k).then(result => { let nameValue; if (result) { - nameValue = name.indexOf(',') !== -1 ? name.split(',').map(item => entity.value[item]).join(',') : entity.value[name]; + nameValue = name.indexOf(',') !== -1 ? + name.split(',').map(item => entity.value[item]).join(',') : + entity.value[name]; ohm.e.throwEntityConflict({type, attrName: name, attrValue: nameValue}); } }); @@ -616,4 +628,4 @@ class Entity { } } -exports = module.exports = Entity; \ No newline at end of file +exports = module.exports = Entity; diff --git a/lib/errors.js b/lib/errors.js index 793bc3d..1615a18 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -1,3 +1,5 @@ +'use strict'; + const util = require('util'); const _ = require('lodash'); @@ -23,41 +25,61 @@ class OhmError extends Error { class UnsupportedOhmError extends OhmError { constructor(...args) { super(...args); - this.message = _.get(this, 'extra.cmd') ? util.format('unsupported operation "%s" error', this.extra.cmd) : 'unknown unsupported operation error'; + this.message = _.get(this, 'extra.cmd') ? + util.format('unsupported operation "%s" error', this.extra.cmd) : + 'unknown unsupported operation error'; } } class RedisOhmError extends OhmError { constructor(...args) { super(...args); - this.message = _.get(this, 'extra.redisError') ? util.format('redis error "%s"', this.extra.redisError) : 'unknown redis error'; + this.message = _.get(this, 'extra.redisError') ? + util.format('redis error "%s"', this.extra.redisError) : + 'unknown redis error'; } } class EntityError extends OhmError { constructor(...args) { super(...args); - this.message = _.get(this, 'extra.type') ? util.format('entity "%s" error', this.extra.type) : 'unknown entity error'; + this.message = _.get(this, 'extra.type') ? + util.format('entity "%s" error', this.extra.type) : + 'unknown entity error'; } } class EntitySchemaNotFoundError extends EntityError { constructor(...args) { super(...args); - this.message = _.get(this, 'extra.schema') ? util.format('entity schema "%s" not found', this.extra.schema) : 'unknown entity schema not found'; + this.message = _.get(this, 'extra.schema') ? + util.format('entity schema "%s" not found', this.extra.schema) : + 'unknown entity schema not found'; } } class EntityConflictError extends EntityError { constructor(...args) { super(...args); - this.message = this.extra ? util.format('entity "%s" conflict for "%s" with value "%s"', this.extra.type, this.extra.attrName, this.extra.attrValue) : 'unknown entity conflict'; + this.message = this.extra ? + util.format('entity "%s" conflict for "%s" with value "%s"', + this.extra.type, + this.extra.attrName, + this.extra.attrValue + ) : + 'unknown entity conflict'; } } class EntityNotFoundError extends EntityError { constructor(...args) { super(...args); - this.message = this.extra ? util.format('entity "%s" not found for "%s" with value "%s"', this.extra.type, this.extra.attrName, this.extra.attrValue) : 'unknown entity not found'; + this.message = this.extra ? + util.format('entity "%s" not found for "%s" with value "%s"', + this.extra.type, + this.extra.attrName, + this.extra.attrValue + ) : + 'unknown entity not found'; } } @@ -65,9 +87,16 @@ class EntityValidationError extends EntityError { constructor(...args) { super(...args); if (_.get(this, 'extra.schemaErrors')) { - this.message = util.format('entity "%s" validation failed because of schema error "%s"', this.extra.type, _.map(this.extra.schemaErrors, 'desc').join(',')); + this.message = util.format('entity "%s" validation failed because of schema error "%s"', + this.extra.type, + this.extra.schemaErrors.map(el => el.desc).join(',') + ); } else if (_.get(this, 'extra.attrName')) { - this.message = util.format('entity "%s" validation failed for "%s" with value "%s"', this.extra.type, this.extra.attrName, this.extra.attrValue); + this.message = util.format('entity "%s" validation failed for "%s" with value "%s"', + this.extra.type, + this.extra.attrName, + this.extra.attrValue + ); } else { this.message = 'unknown entity validation failed'; } @@ -113,4 +142,4 @@ const errors = { } }; -exports = module.exports = errors; \ No newline at end of file +exports = module.exports = errors; diff --git a/lib/ohm.js b/lib/ohm.js index 49138c6..8c39af9 100644 --- a/lib/ohm.js +++ b/lib/ohm.js @@ -1,3 +1,5 @@ +'use strict'; + const Promise = require('bluebird'); const util = require('util'); const assert = require('assert'); @@ -56,11 +58,11 @@ const ohm = { ohm.schemas = {}; _.forIn(ohm.config.schemas, (schemaSpec, schemaName) => { let linkNames, key; - logger.enabledLevels.debug && log.debug('initializing schema "%s"', schemaName); if (!schemaSpec[ohm.config.schemaMetaPrefix]) { logger.enabledLevels.debug && log.debug('schema "%s" has no meta : ignore', schemaName); return; } + logger.enabledLevels.debug && log.debug('initializing schema "%s"', schemaName); const metaPrefix = ohm.config.schemaMetaPrefix; const schema = _.cloneDeep(schemaSpec); ohm.schemas[schemaName] = schema; @@ -169,7 +171,12 @@ const ohm = { } ohm.cli = redis.createClient(ohm.config.port, ohm.config.host, ohm.config.options); if (ohm.config.roHost) { - ohm.roCli = redis.createClient(ohm.config.roPort || ohm.config.port, ohm.config.roHost, ohm.config.roOptions || ohm.config.options); + ohm.roCli = redis + .createClient( + ohm.config.roPort || ohm.config.port, + ohm.config.roHost, + ohm.config.roOptions || ohm.config.options + ); } return ohm.cli.selectAsync(ohm.config.db) .then(() => { @@ -245,7 +252,13 @@ const ohm = { clazz.indexes[index.name.join(',')] = { name: index.name, unique: index.unique, - key: ohm.toHash(ohm.config.idxHashPrefix, schemaName, index.name, _.fill(new Array(index.name.length), '%s')), + key: ohm + .toHash( + ohm.config.idxHashPrefix, + schemaName, + index.name, + new Array(index.name.length).fill('%s') + ), getValue: index.getValue }; } else { @@ -267,7 +280,9 @@ const ohm = { let reverseLink; const reverseSchema = ohm.getSchema(link.target); if (reverseSchema && reverseSchema.links) { - reverseLink = _.first(_.filter(reverseSchema.links, {target: schemaName, foreignKey: link.as})); + reverseLink = _.first(reverseSchema.links + .filter(el => el.target === schemaName && el.foreignKey === link.as) + ); } clazz.links[link.as] = { as: link.as, @@ -298,8 +313,8 @@ const ohm = { exec: (cmd, ...args) => { // TODO : http://redis.io/commands/command#examples _.remove(args, _.isUndefined); - const k = args[1]; - const values = args[2]; + const k = args[0]; + const values = args[1]; return Promise.resolve() .then(() => { let promise; @@ -310,7 +325,12 @@ const ohm = { if (logger.enabledLevels.redis) { promise = promise .then(result => { - log.redis('%s %s%s :', cmd.toUpperCase(), k, values ? ' ' + JSON.stringify(values) : '', JSON.stringify(result)); + log.redis('%s %s%s :', + cmd.toUpperCase(), + k, + values ? ' ' + JSON.stringify(values) : '', + JSON.stringify(result) + ); return result; }); } @@ -356,7 +376,12 @@ const ohm = { const cmd = item.command , k = _.first(item.args) , values = _.tail(item.args); - log.redis('%s %s%s :', cmd.toUpperCase(), k, values ? ' ' + JSON.stringify(values) : '', JSON.stringify(result[index])); + log.redis('%s %s%s :', + cmd.toUpperCase(), + k, + values ? ' ' + JSON.stringify(values) : '', + JSON.stringify(result[index]) + ); }); return result; }) @@ -419,7 +444,11 @@ const ohm = { namespace = _.camelCase(namespace); const schema = ohm.getSchema(namespace, type, op); if (!schema || !schema.properties) { - logger.enabledLevels.debug && log.debug('properties for "%s/%s/%s" not found : ignore filtering', namespace, type, op); + logger.enabledLevels.debug && log.debug('properties for "%s/%s/%s" not found : ignore filtering', + namespace, + type, + op + ); return data; } const propFilter = Object.keys(schema.properties); @@ -465,7 +494,7 @@ const ohm = { }, generateId: type => { if (type === 'date') { - const rnd = () =>Math.floor(Math.random() * 1e9).toString(36); + const rnd = () => Math.floor(Math.random() * 1e9).toString(36); return (+new Date()).toString(36) + rnd() + rnd(); } return rack(); @@ -475,7 +504,9 @@ const ohm = { const entityClassName = schemaName.substring(0, 1).toUpperCase() + _.camelCase(schemaName).substring(1); let entityClass = ohm.entityClasses[schemaName]; if (!entityClass) { - entityClass = ohm.entityClasses[schemaName] = ohm.entityClasses[entityClassName] = ohm.createEntityClass(schemaName); + entityClass = ohm.createEntityClass(schemaName); + ohm.entityClasses[entityClassName] = entityClass; + ohm.entityClasses[schemaName] = entityClass; } return entityClass; }, @@ -488,7 +519,12 @@ const ohm = { type = 'db'; } namespace = _.camelCase(namespace); - const key = _.compact([namespace, ohm.config.schemaMetaPrefix, type && ['operations', type].join('.'), type && op]).join('.'); + const key = _.compact([ + namespace, + ohm.config.schemaMetaPrefix, + type && ['operations', type].join('.'), + type && op + ]).join('.'); const schema = _.get(ohm.schemas, key); if (!schema) { e.throwEntitySchemaNotFound({namespace, type, op}); @@ -519,7 +555,7 @@ const ohm = { hashes = hashes[0].split(':'); } hashes.splice(0, 0, ohm.config.prefix); - return _.compact(hashes.map(item => Array.isArray(item) ? item.join(':') : item)).join(':'); + return _.compact(hashes.map(item => (Array.isArray(item) ? item.join(':') : item))).join(':'); }, toRedis: (data, namespace) => { const schema = ohm.getSchema(namespace, 'save'); @@ -534,6 +570,12 @@ const ohm = { } switch (type) { case 'object': + if (value === null) { + result[key] = null; + } else { + result[key] = JSON.stringify(value); + } + break; case 'array': result[key] = JSON.stringify(value); break; @@ -559,7 +601,11 @@ const ohm = { namespace = _.camelCase(namespace); const schema = ohm.getSchema(namespace, type, op); if (!schema) { - logger.enabledLevels.debug && log.debug('schema for "%s/%s/%s" not found : ignore validation', namespace, type, op); + logger.enabledLevels.debug && log.debug('schema for "%s/%s/%s" not found : ignore validation', + namespace, + type, + op + ); return false; } logger.enabledLevels.debug && log.debug('validating instance with schema "%s/%s/%s"', namespace, type, op); @@ -569,4 +615,4 @@ const ohm = { .asCallback(cb) }; -exports = module.exports = ohm; \ No newline at end of file +exports = module.exports = ohm; diff --git a/package.json b/package.json index 9c96117..ff363ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hw-redis-ohm", - "version": "0.5.3", + "version": "0.5.4", "description": "Redis Object Hash Mapping", "main": "lib/ohm.js", "scripts": { @@ -23,7 +23,7 @@ "hat": "0.0.3", "hw-logger": "^1.1.15", "jayschema": "^0.3.1", - "lodash": "^4.13.1", + "lodash": "^4.14.0", "redis": "^2.6.2" }, "devDependencies": { @@ -31,6 +31,9 @@ "chai": "^3.5.0", "chalk": "^1.1.3", "del": "^2.2.1", + "eslint-config-nodejs": "^1.0.0", + "eslint-plugin-import": "^1.12.0", + "eslint-plugin-you-dont-need-lodash-underscore": "^5.0.1", "gulp": "^3.9.1", "gulp-coveralls": "^0.1.4", "gulp-debug": "^2.1.2", diff --git a/spec/ohmSpec.js b/spec/ohmSpec.js index ef883c3..81b33aa 100644 --- a/spec/ohmSpec.js +++ b/spec/ohmSpec.js @@ -1,3 +1,5 @@ +'use strict'; + const Promise = require('bluebird'); const chai = require('chai'); const _ = require('lodash'); @@ -100,8 +102,11 @@ describe('hw-redis-ohm', () => { .catch(err => { expect(err).to.be.an.instanceof(ohm.e.RedisOhmError); expect(err).to.have.property('name', 'RedisOhmError'); - expect(err).to.have.property('message', 'redis error "ReplyError: ERR wrong number of arguments for \'hmset\' command"'); - expect(err.toString()).to.equal('RedisOhmError: redis error "ReplyError: ERR wrong number of arguments for \'hmset\' command"'); + expect(err).to.have.property('message', + 'redis error "ReplyError: ERR wrong number of arguments for \'hmset\' command"' + ); + expect(err.toString()).to + .equal('RedisOhmError: redis error "ReplyError: ERR wrong number of arguments for \'hmset\' command"'); }); }); @@ -126,9 +131,16 @@ describe('hw-redis-ohm', () => { .catch(err => { expect(err).to.be.an.instanceof(ohm.e.RedisOhmError); expect(err).to.have.property('name', 'RedisOhmError'); - expect(err).to.have.property('message', 'redis error "ReplyError: EXECABORT Transaction discarded because of previous errors."'); - expect(err).to.have.deep.property('extra.redisError.errors[0].message', 'ERR wrong number of arguments for \'hmset\' command'); - expect(err.toString()).to.equal('RedisOhmError: redis error "ReplyError: EXECABORT Transaction discarded because of previous errors."'); + expect(err).to.have.property('message', + 'redis error "ReplyError: EXECABORT Transaction discarded because of previous errors."' + ); + expect(err).to.have.deep.property('extra.redisError.errors[0].message', + 'ERR wrong number of arguments for \'hmset\' command' + ); + expect(err.toString()).to + .equal('RedisOhmError: redis error ' + + '"ReplyError: EXECABORT Transaction discarded because of previous errors."' + ); }); }); @@ -170,7 +182,7 @@ describe('hw-redis-ohm', () => { const subChannels = ['sub1', 'sub2'] , messages = [['hello', 'world'], ['foo', 'bar']]; it('should subscribe and publish', () => { - const counters = _.fill(new Array(subChannels.length), 0); + const counters = new Array(subChannels.length).fill(0); return Promise.map(counters, (counter, index) => new Promise(resolve => { ohm @@ -620,7 +632,11 @@ describe('hw-redis-ohm', () => { expect(err).to.have.deep.property('extra.type', 'contact'); expect(err).to.have.deep.property('extra.attrName', 'email'); expect(err).to.have.deep.property('extra.attrValue', contacts[0].email); - expect(err.toString()).to.equal(util.format('EntityConflictError: entity "contact" conflict for "email" with value "%s"', contacts[0].email)); + expect(err.toString()).to.equal( + util.format('EntityConflictError: entity "contact" conflict for "email" with value "%s"', + contacts[0].email + ) + ); resolve(); }); }); @@ -645,7 +661,11 @@ describe('hw-redis-ohm', () => { expect(err).to.have.deep.property('extra.type', 'dog'); expect(err).to.have.deep.property('extra.attrName', 'masterId'); expect(err).to.have.deep.property('extra.attrValue', contactEntities[0].getId()); - expect(err.toString()).to.equal(util.format('EntityConflictError: entity "dog" conflict for "masterId" with value "%s"', contactEntities[0].getId())); + expect(err.toString()).to.equal( + util.format('EntityConflictError: entity "dog" conflict for "masterId" with value "%s"', + contactEntities[0].getId() + ) + ); resolve(); }); }); @@ -656,7 +676,8 @@ describe('hw-redis-ohm', () => { expect(err).to.have.deep.property('extra.type', 'group'); expect(err).to.have.deep.property('extra.attrName', 'id'); expect(err).to.have.deep.property('extra.attrValue', 'badid'); - expect(err.toString()).to.equal('EntityNotFoundError: entity "group" not found for "id" with value "badid"'); + expect(err.toString()).to + .equal('EntityNotFoundError: entity "group" not found for "id" with value "badid"'); resolve(); }); })) @@ -714,7 +735,8 @@ describe('hw-redis-ohm', () => { expect(err).to.have.deep.property('extra.type', 'group'); expect(err).to.have.deep.property('extra.attrName', 'id'); expect(err).to.have.deep.property('extra.attrValue', 'badid'); - expect(err.toString()).to.equal('EntityNotFoundError: entity "group" not found for "id" with value "badid"'); + expect(err.toString()).to + .equal('EntityNotFoundError: entity "group" not found for "id" with value "badid"'); resolve(); }); }) @@ -732,7 +754,8 @@ describe('hw-redis-ohm', () => { expect(err).to.have.deep.property('extra.type', 'group'); expect(err).to.have.deep.property('extra.attrName', 'id'); expect(err).to.have.deep.property('extra.attrValue').that.is.undefined; - expect(err.toString()).to.equal('EntityValidationError: entity "group" validation failed for "id" with value "undefined"'); + expect(err.toString()).to + .equal('EntityValidationError: entity "group" validation failed for "id" with value "undefined"'); resolve(); }); })) @@ -772,4 +795,4 @@ describe('hw-redis-ohm', () => { }); -}); \ No newline at end of file +}); diff --git a/spec/test-util.js b/spec/test-util.js index 88f36be..a1e24a8 100644 --- a/spec/test-util.js +++ b/spec/test-util.js @@ -1,3 +1,5 @@ +'use strict'; + const Promise = require('bluebird'); const logger = require('hw-logger'); const ohm = require('../lib/ohm'); @@ -11,4 +13,4 @@ const that = { }) }; -exports = module.exports = that; \ No newline at end of file +exports = module.exports = that;