import DynamoPromise from '../../../../database-operations/dynamo-to-promise' ; import { TableSchema } from '../../../../schema' ; import { DynamoIndexWithCompositeKey , DynamoIndexWithSimpleKey } from '../../../../schema/dynamo-index' ; import { DynamoORMWithCompositeKey } from '../../../../schema/dynamo-orm' ; export class CompositeKeyWithGlobalIndex < Table , PartitionKey extends keyof Table , SortKey extends keyof Table , CurrentGlobalIndexes , CurrentLocalIndexes > { private dynamoPromise : DynamoPromise ; private tableSchema : TableSchema ; private currentGlobalIndexes : CurrentGlobalIndexes ; private currentLocalIndexes : CurrentLocalIndexes ; constructor ( dynamoPromise , tableSchema , currentGlobalIndexes , currentLocalIndexes ) { this . dynamoPromise = dynamoPromise ; this . tableSchema = tableSchema ; this . currentGlobalIndexes = currentGlobalIndexes ; this . currentLocalIndexes = currentLocalIndexes ; } public getInstance ( ) { return new DynamoORMWithCompositeKey ( this . tableSchema , this . currentGlobalIndexes , this . currentLocalIndexes , 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 ) { this . currentGlobalIndexes = { ... this . currentGlobalIndexes as any , [ config . indexName ] : new DynamoIndexWithCompositeKey ( config ) , } ; return new CompositeKeyWithGlobalIndex ( this . dynamoPromise , this . tableSchema , this . currentGlobalIndexes , this . currentLocalIndexes ) ; } this . currentGlobalIndexes = { ... this . currentGlobalIndexes as any , [ config . indexName ] : new DynamoIndexWithSimpleKey ( config ) , } ; return new CompositeKeyWithGlobalIndex ( this . dynamoPromise , this . tableSchema , this . currentGlobalIndexes , this . currentLocalIndexes ) ; } }