import DynamoPromise from '../../../../database-operations/dynamo-to-promise' ; import { TableSchema } from '../../../../schema' ; import { DynamoIndexWithCompositeKey , DynamoIndexWithSimpleKey } from '../../../../schema/dynamo-index' ; import { DynamoTableWithSimpleKey } from '../../../../schema/dynamo-table' ; import { SimpleKeyWithGlobalIndex } from './with-global-index' ; export class TypeDynamoDefineTableSimpleKey < Table , PartitionKey extends keyof Table > { private dynamoPromise : DynamoPromise ; private tableSchema : TableSchema ; constructor ( dynamoPromise , schema ) { this . dynamoPromise = dynamoPromise ; this . tableSchema = this . buildTableSchema ( schema ) ; } public getInstance ( ) { return new DynamoTableWithSimpleKey ( this . tableSchema , this . dynamoPromise ) ; } public withGlobalIndex < IndexName extends string , IndexPartitionKey extends keyof Table > ( config ) ; public withGlobalIndex < IndexName extends string , IndexPartitionKey extends keyof Table , IndexSortKey extends keyof Table > ( config ) ; public withGlobalIndex < IndexName extends string , IndexPartitionKey extends keyof Table > ( config ) ; public withGlobalIndex < IndexName extends string , IndexPartitionKey extends keyof Table , IndexSortKey extends keyof Table > ( config ) ; public withGlobalIndex < IndexName extends string , IndexPartitionKey extends keyof Table , IndexAttributes extends keyof Table > ( config ) ; public withGlobalIndex < IndexName extends string , IndexPartitionKey extends keyof Table , IndexSortKey extends keyof Table , IndexAttributes extends keyof Table > ( config ) ; public withGlobalIndex ( config ) { if ( config . sortKey ) { return new SimpleKeyWithGlobalIndex ( this . dynamoPromise , this . tableSchema , { [ config . indexName ] : new DynamoIndexWithCompositeKey ( config ) } , { } ) ; } return new SimpleKeyWithGlobalIndex ( this . dynamoPromise , this . tableSchema , { [ config . indexName ] : new DynamoIndexWithSimpleKey ( config ) } , { } ) ; } private buildTableSchema ( schema ) { const tableSchema = { tableName : schema . tableName , partitionKey : schema . partitionKey , writeCapacity : schema . writeCapacity || 1 , readCapacity : schema . readCapacity || 1 , } ; return tableSchema ; } }