@@ -66,6 +66,18 @@ export interface TableProps {
6666 writeAutoScaling ?: AutoScalingProps ;
6767}
6868
69+ export interface Attribute {
70+ /**
71+ * The name of an attribute.
72+ */
73+ name : string ;
74+
75+ /**
76+ * The data type of an attribute.
77+ */
78+ type : AttributeType ;
79+ }
80+
6981/* tslint:disable:max-line-length */
7082export interface AutoScalingProps {
7183 /**
@@ -150,13 +162,13 @@ export class Table extends Construct {
150162 }
151163 }
152164
153- public addPartitionKey ( name : string , type : KeyAttributeType ) : this {
154- this . addKey ( name , type , HASH_KEY_TYPE ) ;
165+ public addPartitionKey ( attribute : Attribute ) : this {
166+ this . addKey ( attribute . name , attribute . type , HASH_KEY_TYPE ) ;
155167 return this ;
156168 }
157169
158- public addSortKey ( name : string , type : KeyAttributeType ) : this {
159- this . addKey ( name , type , RANGE_KEY_TYPE ) ;
170+ public addSortKey ( attribute : Attribute ) : this {
171+ this . addKey ( attribute . name , attribute . type , RANGE_KEY_TYPE ) ;
160172 return this ;
161173 }
162174
@@ -266,7 +278,7 @@ export class Table extends Construct {
266278 return this . keySchema . find ( prop => prop . keyType === keyType ) ;
267279 }
268280
269- private addKey ( name : string , type : KeyAttributeType , keyType : string ) {
281+ private addKey ( name : string , type : AttributeType , keyType : string ) {
270282 const existingProp = this . findKey ( keyType ) ;
271283 if ( existingProp ) {
272284 throw new Error ( `Unable to set ${ name } as a ${ keyType } key, because ${ existingProp . attributeName } is a ${ keyType } key` ) ;
@@ -279,7 +291,7 @@ export class Table extends Construct {
279291 return this ;
280292 }
281293
282- private registerAttribute ( name : string , type : KeyAttributeType ) {
294+ private registerAttribute ( name : string , type : AttributeType ) {
283295 const existingDef = this . attributeDefinitions . find ( def => def . attributeName === name ) ;
284296 if ( existingDef && existingDef . attributeType !== type ) {
285297 throw new Error ( `Unable to specify ${ name } as ${ type } because it was already defined as ${ existingDef . attributeType } ` ) ;
@@ -293,7 +305,7 @@ export class Table extends Construct {
293305 }
294306}
295307
296- export enum KeyAttributeType {
308+ export enum AttributeType {
297309 Binary = 'B' ,
298310 Number = 'N' ,
299311 String = 'S' ,
0 commit comments