@@ -17,6 +17,9 @@ import { SessionValidityEnsurer } from './session-validity-ensurer.type'
1717import { TableNameResolver } from './table-name-resolver.type'
1818
1919export class DynamoStore < T > {
20+ /* http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-naming-rules */
21+ private static REGEX_TABLE_NAME = / ^ [ a - z A - Z 0 - 9 _ \- . ] { 3 , 255 } $ /
22+
2023 private readonly dynamoRx : DynamoRx
2124 private readonly mapper : Mapper
2225
@@ -28,7 +31,14 @@ export class DynamoStore<T> {
2831 sessionValidityEnsurer : SessionValidityEnsurer = DEFAULT_SESSION_VALIDITY_ENSURER
2932 ) {
3033 this . dynamoRx = new DynamoRx ( sessionValidityEnsurer )
31- this . tableName = tableNameResolver ( MetadataHelper . get ( this . modelClazz ) . modelOptions . tableName )
34+ const tableName = tableNameResolver ( MetadataHelper . get ( this . modelClazz ) . modelOptions . tableName )
35+ if ( ! DynamoStore . REGEX_TABLE_NAME . test ( tableName ) ) {
36+ throw new Error (
37+ 'make sure the table name only contains these characters «a-z A-Z 0-9 - _ .» and is between 3 and 255 characters long'
38+ )
39+ }
40+
41+ this . tableName = tableName
3242 }
3343
3444 get dynamoDb ( ) : DynamoDB {
@@ -111,12 +121,6 @@ export class DynamoStore<T> {
111121 } )
112122 }
113123
114- // private findBySingleKey(partitionKeyValue: any): Observable<T[]> {
115- // return this.query()
116- // .wherePartitionKey(partitionKeyValue)
117- // .exec()
118- // }
119-
120124 private createBaseParams ( ) : { TableName : string } {
121125 const params : { TableName : string } = {
122126 TableName : this . tableName ,
0 commit comments