diff --git a/.travis.yml b/.travis.yml index 3b6e4b6..d8fda00 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,12 @@ language: node_js node_js: - - 4.2 - - 6.0 + - 6.10 + - 8.10 jdk: - oraclejdk8 install: - mkdir /tmp/dynamodb - - wget -O - http://dynamodb-local.s3-website-us-west-2.amazonaws.com/dynamodb_local_latest | tar xz --directory /tmp/dynamodb + - wget -O - https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.tar.gz | tar xz --directory /tmp/dynamodb - npm install script: make test-cov before_script: diff --git a/README.md b/README.md index 4e37545..8e652ac 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ DynamoDB processor operates a process by simple JSON expression. ## Features * If it have failed to set child objects to Map Type field, auto trying to update with initial fields again. futhermore, If it have failed by the conflict, auto trying the updating process at first once more. -* Node.js 4.2 or later +* Node.js 6.10 or later ## Install diff --git a/lib/doc_client.js b/lib/doc_client.js index 26b8ce2..fb8e575 100644 --- a/lib/doc_client.js +++ b/lib/doc_client.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = function(docClient) { +module.exports = (docClient) => { function get(params) { return docClient.get(params).promise(); @@ -16,23 +16,19 @@ module.exports = function(docClient) { function update(params) { return docClient.update(params).promise() - .then(data => { - return data.Attributes; - }); + .then(data => data.Attributes); } function batchWrite(params) { return docClient.batchWrite(params).promise() - .then(data => { - return data.UnprocessedItems; - }); + .then(data => data.UnprocessedItems); } return { - get: get, - put: put, - update: update, - batchGet: batchGet, - batchWrite: batchWrite, - }; + get, + put, + update, + batchGet, + batchWrite + } } diff --git a/lib/expression.js b/lib/expression.js index 96c9669..cf20ae1 100644 --- a/lib/expression.js +++ b/lib/expression.js @@ -5,11 +5,12 @@ const AWS = require('aws-sdk'); const docClient = new AWS.DynamoDB.DocumentClient(); -function Expression(initFields) { - this._initFields = initFields || {}; -} -Expression.prototype = { - generate: function(table, key, ops, withInit) { +class Expression { + constructor(initFields) { + this._initFields = initFields || {}; + } + + generate(table, key, ops, withInit) { this._reset(); const init = withInit || false; @@ -62,8 +63,9 @@ Expression.prototype = { } return result; - }, - _reset: function() { + } + + _reset() { this._inits = _.cloneDeep(this._initFields); this._sets = []; this._adds = []; @@ -73,22 +75,25 @@ Expression.prototype = { this._fldIdx = 0; this._valIdx = 0; this._conds = []; - }, - _addSet: function(name, val, init) { + } + + _addSet(name, val, init) { if (!init || !this._addInitSet(name, val)) { const path = this._registerName(name); const i = this._regVal(val); this._sets.push(`${path} = :v${i}`); } - }, - _addAdd: function(name, val, init) { + } + + _addAdd(name, val, init) { if (!init || !this._addInitSet(name, val)) { const path = this._registerName(name); const i = this._regVal(val); this._adds.push(`${path} :v${i}`); } - }, - _addPushSet: function(name, val, init) { + } + + _addPushSet(name, val, init) { const valSet = docClient.createSet(val); if (!init || !this._addInitSet(name, valSet)) { @@ -96,12 +101,14 @@ Expression.prototype = { const i = this._regVal(valSet); this._adds.push(`${path} :v${i}`); } - }, - _addRemove: function(name) { + } + + _addRemove(name) { const path = this._registerName(name); this._removes.push(path); - }, - _addInitSet: function(name, val) { + } + + _addInitSet(name, val) { const paths = name.split(' '); const rootPath = paths[0]; const initVal = this._inits[rootPath]; @@ -114,20 +121,23 @@ Expression.prototype = { initVal.push(val); } return true; - }, - _registerName: function(name) { + } + + _registerName(name) { return name.split(' ').map((nm) => { const fn = '#f' + ++this._fldIdx; this._attrNames[fn] = nm; return fn; }).join('.'); - }, - _regVal: function(val) { + } + + _regVal(val) { const vi = ++this._valIdx; this._attrValues[`:v${vi}`] = val; return vi; - }, - _geneInits: function(fields) { + } + + _geneInits(fields) { for (let field in this._inits) { const val = this._inits[field]; const i = this._regVal(val); @@ -144,8 +154,9 @@ Expression.prototype = { this._conds.push(`attribute_not_exists(${fn})`); } } - }, - _getExpression: function() { + } + + _getExpression() { const exp = []; if (this._sets.length) { diff --git a/lib/processor.js b/lib/processor.js index 2f7f48a..d71fb31 100644 --- a/lib/processor.js +++ b/lib/processor.js @@ -161,7 +161,7 @@ class Processor { this.logger.info('Updated %s on %s table', itemKey, table); return data; }) - .catch((err) => { + .catch(err => { if (init && err.code === 'ValidationException' && err.message === MSG_INVALID_EXPRESSION) { @@ -211,9 +211,7 @@ class Processor { if (useBatch) { return this.batchWrite(table, data.items); } else { - return data.items.map((item) => { - return this.put(table, item); - }); + return data.items.map((item) => this.put(table, item)); } } } else if (data.action === 'update' || data.set @@ -233,9 +231,7 @@ class Processor { if (useBatch) { return this.batchGet(table, data.keys); } else { - return data.keys.map((key) => { - return this.get(table, key); - }); + return data.keys.map((key) => this.get(table, key)); } } }