Skip to content

Commit

Permalink
Fix Lint Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
J3tto committed Dec 14, 2020
1 parent 5c7fd98 commit 6deda45
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
14 changes: 10 additions & 4 deletions src/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand All @@ -27,7 +34,7 @@ const defaults = {
name: null,
region: 'us-east-1',
deletionPolicy: 'delete',
timeToLiveSpecification: undefined
timeToLiveSpecification: undefined,
};

class AwsDynamoDb extends Component {
Expand Down Expand Up @@ -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.`);
Expand Down
27 changes: 15 additions & 12 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion templates/aws-dynamodb-starter/serverless.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
license: MIT
8 changes: 4 additions & 4 deletions test/integration.test.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -17,8 +17,8 @@ const instanceYaml = {
inputs: {
deletionPolicy: 'delete',
timeToLiveSpecification: {
AttributeName : 'expires',
Enabled: true
AttributeName: 'expires',
Enabled: true,
},
attributeDefinitions: [
{
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 8 additions & 1 deletion test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

0 comments on commit 6deda45

Please sign in to comment.