@@ -18,10 +18,28 @@ const defaults = {
1818 KeyType : 'HASH'
1919 }
2020 ] ,
21- name : '' ,
21+ name : false ,
2222 region : 'us-east-1'
2323}
2424
25+ const setTableName = ( component , inputs , config ) => {
26+ const generatedName = inputs . name
27+ ? `${ inputs . name } -${ component . context . resourceId ( ) } `
28+ : component . context . resourceId ( )
29+ 30+ const hasDeployedBefore = 'nameInput' in component . state
31+ const givenNameHasNotChanged =
32+ component . state . nameInput && component . state . nameInput === inputs . name
33+ const bothLastAndCurrentDeployHaveNoNameDefined = ! component . state . nameInput && ! inputs . name
34+ 35+ config . name =
36+ hasDeployedBefore && ( givenNameHasNotChanged || bothLastAndCurrentDeployHaveNoNameDefined )
37+ ? component . state . name
38+ : generatedName
39+ 40+ component . state . nameInput = inputs . name || false
41+ }
42+ 2543class AwsDynamoDb extends Component {
2644 async default ( inputs = { } ) {
2745 this . context . status ( 'Deploying' )
@@ -40,22 +58,7 @@ class AwsDynamoDb extends Component {
4058 `Checking if table ${ config . name } already exists in the ${ config . region } region.`
4159 )
4260
43- const generatedName = inputs . name
44- ? `${ inputs . name } -${ this . context . resourceId ( ) } `
45- : this . context . resourceId ( )
46- 47- const NO_CONTENT = 204
48- const lastDeployHadNoNameDefined = this . state . nameInput === NO_CONTENT
49- const lastDeployHadNameDefined = this . state . nameInput !== NO_CONTENT
50- const givenNameHasNotChanged = lastDeployHadNameDefined && this . state . nameInput === inputs . name
51- const bothLastAndCurrentDeployHaveNoNameDefined = lastDeployHadNoNameDefined && ! inputs . name
52- 53- config . name =
54- this . state . nameInput && ( givenNameHasNotChanged || bothLastAndCurrentDeployHaveNoNameDefined )
55- ? this . state . name
56- : generatedName
57- 58- this . state . nameInput = inputs . name || NO_CONTENT
61+ setTableName ( this , inputs , config )
5962
6063 const prevTable = await describeTable ( { dynamodb, name : this . state . name } )
6164
0 commit comments