Skip to content

Commit f7e504c

Browse files
committed
style: Prettify (automatic)
1 parent 38d1310 commit f7e504c

File tree

7 files changed

+188
-191
lines changed

7 files changed

+188
-191
lines changed

.github/workflows/nodejs.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Integration Tests
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [master]
66

77
jobs:
88
build:
@@ -13,16 +13,16 @@ jobs:
1313
node-version: [12.x]
1414

1515
steps:
16-
- uses: actions/checkout@v2
17-
- name: Use Node.js ${{ matrix.node-version }}
18-
uses: actions/setup-node@v1
19-
with:
20-
node-version: ${{ matrix.node-version }}
21-
- name: Install Dependencies
22-
run: npm install
23-
- name: Run Integration Tests
24-
run: npm test
25-
env:
26-
SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }}
27-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
28-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
16+
- uses: actions/checkout@v2
17+
- name: Use Node.js ${{ matrix.node-version }}
18+
uses: actions/setup-node@v1
19+
with:
20+
node-version: ${{ matrix.node-version }}
21+
- name: Install Dependencies
22+
run: npm install
23+
- name: Run Integration Tests
24+
run: npm test
25+
env:
26+
SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }}
27+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
28+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

CODE_OF_CONDUCT.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ orientation.
1414
Examples of behavior that contributes to creating a positive environment
1515
include:
1616

17-
* Using welcoming and inclusive language
18-
* Being respectful of differing viewpoints and experiences
19-
* Gracefully accepting constructive criticism
20-
* Focusing on what is best for the community
21-
* Showing empathy towards other community members
17+
- Using welcoming and inclusive language
18+
- Being respectful of differing viewpoints and experiences
19+
- Gracefully accepting constructive criticism
20+
- Focusing on what is best for the community
21+
- Showing empathy towards other community members
2222

2323
Examples of unacceptable behavior by participants include:
2424

25-
* The use of sexualized language or imagery and unwelcome sexual attention or
26-
advances
27-
* Trolling, insulting/derogatory comments, and personal or political attacks
28-
* Public or private harassment
29-
* Publishing others' private information, such as a physical or electronic
25+
- The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
- Trolling, insulting/derogatory comments, and personal or political attacks
28+
- Public or private harassment
29+
- Publishing others' private information, such as a physical or electronic
3030
address, without explicit permission
31-
* Other conduct which could reasonably be considered inappropriate in a
31+
- Other conduct which could reasonably be considered inappropriate in a
3232
professional setting
3333

3434
## Our Responsibilities

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ stage: dev # (optional) serverless dashboard stage. defaul
9494

9595
inputs:
9696
name: my-table
97-
attributeDefinitions:
97+
attributeDefinitions:
9898
- AttributeName: id
9999
AttributeType: S
100100
- AttributeName: attribute1
@@ -137,22 +137,24 @@ $ serverless dev
137137

138138
### 6. Monitor
139139

140-
Anytime you need to know more about your running `aws-dynamodb` instance, you can run the following command to view the most critical info.
140+
Anytime you need to know more about your running `aws-dynamodb` instance, you can run the following command to view the most critical info.
141141

142142
```
143143
$ serverless info
144144
```
145145
146146
This is especially helpful when you want to know the outputs of your instances so that you can reference them in another instance. It also shows you the status of your instance, when it was last deployed, and how many times it was deployed. You will also see a url where you'll be able to view more info about your instance on the Serverless Dashboard.
147147
148-
To digg even deeper, you can pass the `--debug` flag to view the state of your component instance in case the deployment failed for any reason.
148+
To digg even deeper, you can pass the `--debug` flag to view the state of your component instance in case the deployment failed for any reason.
149149
150150
```
151151
$ serverless info --debug
152152
```
153+
153154
### 7. Remove
154155
155-
If you wanna tear down your entire `aws-dynamodb` infrastructure that was created during deployment, just run the following command in the directory containing the `serverless.yml` file.
156+
If you wanna tear down your entire `aws-dynamodb` infrastructure that was created during deployment, just run the following command in the directory containing the `serverless.yml` file.
157+
156158
```
157159
$ serverless remove
158160
```

src/serverless.js

Lines changed: 63 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,164 +1,162 @@
1-
'use strict'
1+
'use strict';
22

3-
const { mergeDeepRight, pick } = require('ramda')
3+
const { mergeDeepRight, pick } = require('ramda');
44
// eslint-disable-next-line import/no-extraneous-dependencies
5-
const AWS = require('aws-sdk')
5+
const AWS = require('aws-sdk');
66
// eslint-disable-next-line import/no-unresolved
7-
const { Component } = require('@serverless/core')
8-
const { log, createTable, deleteTable, describeTable, updateTable } = require('./utils')
7+
const { Component } = require('@serverless/core');
8+
const { log, createTable, deleteTable, describeTable, updateTable } = require('./utils');
99

10-
const outputsList = ['name', 'arn', 'region']
10+
const outputsList = ['name', 'arn', 'region'];
1111

1212
const defaults = {
1313
attributeDefinitions: [
1414
{
1515
AttributeName: 'id',
16-
AttributeType: 'S'
17-
}
16+
AttributeType: 'S',
17+
},
1818
],
1919
keySchema: [
2020
{
2121
AttributeName: 'id',
22-
KeyType: 'HASH'
23-
}
22+
KeyType: 'HASH',
23+
},
2424
],
2525
globalSecondaryIndexes: [],
2626
localSecondaryIndexes: [],
2727
name: null,
2828
region: 'us-east-1',
29-
deletionPolicy: 'delete'
30-
}
29+
deletionPolicy: 'delete',
30+
};
3131

3232
class AwsDynamoDb extends Component {
3333
async deploy(inputs = {}) {
3434
// this error message assumes that the user is running via the CLI though...
3535
if (Object.keys(this.credentials.aws).length === 0) {
3636
const msg =
37-
'Credentials not found. Make sure you have a .env file in the cwd. - Docs: https://git.io/JvArp'
38-
throw new Error(msg)
37+
'Credentials not found. Make sure you have a .env file in the cwd. - Docs: https://git.io/JvArp';
38+
throw new Error(msg);
3939
}
4040

41-
const config = mergeDeepRight(defaults, inputs)
42-
config.name = config.name || this.name
41+
const config = mergeDeepRight(defaults, inputs);
42+
config.name = config.name || this.name;
4343

4444
// If first deploy and no name is found, set default name..
4545
if (!config.name && !this.state.name) {
46-
config.name = `dynamodb-table-${Math.random()
47-
.toString(36)
48-
.substring(6)}`
49-
this.state.name = config.name
46+
config.name = `dynamodb-table-${Math.random().toString(36).substring(6)}`;
47+
this.state.name = config.name;
5048
}
5149
// If first deploy, and a name is set...
5250
else if (config.name && !this.state.name) {
53-
this.state.name = config.name
51+
this.state.name = config.name;
5452
}
5553
// If subequent deploy, and name is different from a previously used name, throw error.
5654
else if (config.name && this.state.name && config.name !== this.state.name) {
5755
throw new Error(
5856
'You cannot change the name of your DynamoDB table once it has been deployed (or this will deploy a new table). Please remove this Component Instance first by running "serverless remove", then redeploy it with "serverless deploy".'
59-
)
57+
);
6058
}
6159

62-
console.log(`Starting deployment of table ${config.name} in the ${config.region} region.`)
60+
console.log(`Starting deployment of table ${config.name} in the ${config.region} region.`);
6361

6462
const dynamodb = new AWS.DynamoDB({
6563
region: config.region,
66-
credentials: this.credentials.aws
67-
})
64+
credentials: this.credentials.aws,
65+
});
6866

69-
console.log(`Checking if table ${config.name} already exists in the ${config.region} region.`)
67+
console.log(`Checking if table ${config.name} already exists in the ${config.region} region.`);
7068

71-
const prevTable = await describeTable({ dynamodb, name: config.name })
69+
const prevTable = await describeTable({ dynamodb, name: config.name });
7270

7371
if (!prevTable) {
74-
log(`Table ${config.name} does not exist. Creating...`)
72+
log(`Table ${config.name} does not exist. Creating...`);
7573

76-
config.arn = await createTable({ dynamodb, ...config })
74+
config.arn = await createTable({ dynamodb, ...config });
7775
} else {
78-
console.log(`Table ${config.name} already exists. Comparing config changes...`)
76+
console.log(`Table ${config.name} already exists. Comparing config changes...`);
7977

8078
// Check region
8179
if (config.region && this.state.region && config.region !== this.state.region) {
8280
throw new Error(
8381
'You cannot change the region of a DynamoDB Table. Please remove it and redeploy in your desired region.'
84-
)
82+
);
8583
}
8684

87-
config.arn = prevTable.arn
85+
config.arn = prevTable.arn;
8886

89-
const prevGlobalSecondaryIndexes = prevTable.globalSecondaryIndexes || []
90-
await updateTable.call(this, { dynamodb, prevGlobalSecondaryIndexes, ...config })
87+
const prevGlobalSecondaryIndexes = prevTable.globalSecondaryIndexes || [];
88+
await updateTable.call(this, { dynamodb, prevGlobalSecondaryIndexes, ...config });
9189
}
9290

93-
log(`Table ${config.name} was successfully deployed to the ${config.region} region.`)
91+
log(`Table ${config.name} was successfully deployed to the ${config.region} region.`);
9492

95-
this.state.arn = config.arn
96-
this.state.name = config.name
97-
this.state.region = config.region
98-
this.state.deletionPolicy = config.deletionPolicy
93+
this.state.arn = config.arn;
94+
this.state.name = config.name;
95+
this.state.region = config.region;
96+
this.state.deletionPolicy = config.deletionPolicy;
9997

100-
const outputs = pick(outputsList, config)
98+
const outputs = pick(outputsList, config);
10199

102100
// Add indexes to outputs as objects, which are easier to reference as serverless variables
103101
if (config.globalSecondaryIndexes) {
104-
outputs.indexes = outputs.indexes || {}
102+
outputs.indexes = outputs.indexes || {};
105103
config.globalSecondaryIndexes.forEach((index) => {
106104
outputs.indexes[index.IndexName] = {
107105
name: index.IndexName,
108-
arn: `${outputs.arn}/index/${index.IndexName}`
109-
}
110-
})
106+
arn: `${outputs.arn}/index/${index.IndexName}`,
107+
};
108+
});
111109
}
112110

113111
if (config.localSecondaryIndexes) {
114-
outputs.indexes = outputs.indexes || {}
112+
outputs.indexes = outputs.indexes || {};
115113
config.localSecondaryIndexes.forEach((index) => {
116114
outputs.indexes[index.IndexName] = {
117115
name: index.IndexName,
118-
arn: `${outputs.arn}/index/${index.IndexName}`
119-
}
120-
})
116+
arn: `${outputs.arn}/index/${index.IndexName}`,
117+
};
118+
});
121119
}
122120

123-
return outputs
121+
return outputs;
124122
}
125123

126124
/**
127125
* Remove
128126
*/
129127
async remove() {
130-
console.log('Removing')
128+
console.log('Removing');
131129

132130
// If "delete: false", don't delete the table, and warn instead
133131
if (this.state.deletionPolicy && this.state.deletionPolicy === 'retain') {
134-
console.log('Skipping table removal because "deletionPolicy" is set to "retain".')
135-
this.state = {}
136-
return {}
132+
console.log('Skipping table removal because "deletionPolicy" is set to "retain".');
133+
this.state = {};
134+
return {};
137135
}
138136

139-
const { name, region } = this.state
137+
const { name, region } = this.state;
140138

141139
if (!name) {
142-
console.log('Aborting removal. Table name not found in state.')
143-
return null
140+
console.log('Aborting removal. Table name not found in state.');
141+
return null;
144142
}
145143

146144
const dynamodb = new AWS.DynamoDB({
147145
region,
148-
credentials: this.credentials.aws
149-
})
146+
credentials: this.credentials.aws,
147+
});
150148

151-
console.log(`Removing table ${name} from the ${region} region.`)
149+
console.log(`Removing table ${name} from the ${region} region.`);
152150

153-
await deleteTable({ dynamodb, name })
151+
await deleteTable({ dynamodb, name });
154152

155-
const outputs = pick(outputsList, this.state)
153+
const outputs = pick(outputsList, this.state);
156154

157-
console.log(`Table ${name} was successfully removed from the ${region} region.`)
155+
console.log(`Table ${name} was successfully removed from the ${region} region.`);
158156

159-
this.state = {}
160-
return outputs
157+
this.state = {};
158+
return outputs;
161159
}
162160
}
163161

164-
module.exports = AwsDynamoDb
162+
module.exports = AwsDynamoDb;

0 commit comments

Comments
 (0)