From 6deda45f6281bd54bc858785fdcda1bc9b4c20c9 Mon Sep 17 00:00:00 2001 From: j3tto Date: Mon, 14 Dec 2020 18:43:24 +0000 Subject: [PATCH] Fix Lint Errors --- src/serverless.js | 14 +++++++--- src/utils.js | 27 ++++++++++--------- .../serverless.template.yml | 2 +- test/integration.test.js | 8 +++--- test/utils.js | 9 ++++++- 5 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/serverless.js b/src/serverless.js index 4c2891f..484fe65 100644 --- a/src/serverless.js +++ b/src/serverless.js @@ -5,7 +5,14 @@ const { mergeDeepRight, pick } = require('ramda'); const AWS = require('aws-sdk'); // eslint-disable-next-line import/no-unresolved const { Component } = require('@serverless/core'); -const { log, createTable, deleteTable, describeTable, updateTable, updateTimeToLive } = require('./utils'); +const { + log, + createTable, + deleteTable, + describeTable, + updateTable, + updateTimeToLive, +} = require('./utils'); const outputsList = ['name', 'arn', 'region']; @@ -27,7 +34,7 @@ const defaults = { name: null, region: 'us-east-1', deletionPolicy: 'delete', - timeToLiveSpecification: undefined + timeToLiveSpecification: undefined, }; class AwsDynamoDb extends Component { @@ -90,8 +97,7 @@ class AwsDynamoDb extends Component { } if (config.timeToLiveSpecification) { - await updateTimeToLive({dynamodb, ...config}) - + await updateTimeToLive({ dynamodb, ...config }); } log(`Table ${config.name} was successfully deployed to the ${config.region} region.`); diff --git a/src/utils.js b/src/utils.js index d7e7abe..2023fc0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -119,18 +119,21 @@ async function deleteTable({ dynamodb, name }) { return !!res; } -async function updateTimeToLive({dynamodb, name, timeToLiveSpecification= {}}) { - return await dynamodb.waitFor('tableExists', { TableName: name}, async function(err, data) { - if (err) throw err; - return await dynamodb - .updateTimeToLive({ - TableName: name, - TimeToLiveSpecification: { - AttributeName: timeToLiveSpecification.AttributeName, - Enabled: timeToLiveSpecification.Enabled, - } - }).promise(); - }).promise(); +async function updateTimeToLive({ dynamodb, name, timeToLiveSpecification = {} }) { + return await dynamodb + .waitFor('tableExists', { TableName: name }, async (err) => { + if (err) throw err; + return await dynamodb + .updateTimeToLive({ + TableName: name, + TimeToLiveSpecification: { + AttributeName: timeToLiveSpecification.AttributeName, + Enabled: timeToLiveSpecification.Enabled, + }, + }) + .promise(); + }) + .promise(); } module.exports = { diff --git a/templates/aws-dynamodb-starter/serverless.template.yml b/templates/aws-dynamodb-starter/serverless.template.yml index 509d303..93488a4 100644 --- a/templates/aws-dynamodb-starter/serverless.template.yml +++ b/templates/aws-dynamodb-starter/serverless.template.yml @@ -3,4 +3,4 @@ org: serverlessinc description: Deploys a serverless NoSQL database powered by AWS DynamoDB keywords: aws, serverless, nosql, database repo: https://github.com/serverless-components/aws-dynamodb -license: MIT \ No newline at end of file +license: MIT diff --git a/test/integration.test.js b/test/integration.test.js index 8775c79..2756d59 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -1,6 +1,6 @@ 'use strict'; -const { sleep, generateId, getCredentials, getServerlessSdk, getTable, getTableTimeToLive } = require('./utils'); +const { sleep, generateId, getCredentials, getServerlessSdk, getTable } = require('./utils'); // set enough timeout for deployment to finish jest.setTimeout(30000); @@ -17,8 +17,8 @@ const instanceYaml = { inputs: { deletionPolicy: 'delete', timeToLiveSpecification: { - AttributeName : 'expires', - Enabled: true + AttributeName: 'expires', + Enabled: true, }, attributeDefinitions: [ { @@ -79,7 +79,7 @@ it('should successfully deploy dynamodb table and local index', async () => { const res = await getTable(credentials, name); - //const resTTL = await getTableTimeToLive(credentials, name); + // const resTTL = await getTableTimeToLive(credentials, name); expect(instance.outputs.name).toBeDefined(); expect(instance.outputs.arn).toBeDefined(); diff --git a/test/utils.js b/test/utils.js index 3849ef5..5e47786 100644 --- a/test/utils.js +++ b/test/utils.js @@ -86,4 +86,11 @@ const getTableTimeToLive = async (credentials, tableName) => { .promise(); }; -module.exports = { sleep, generateId, getCredentials, getServerlessSdk, getTable, getTableTimeToLive }; +module.exports = { + sleep, + generateId, + getCredentials, + getServerlessSdk, + getTable, + getTableTimeToLive, +};