import { IndexOptions } from './index-options' ; import { CompositePrimaryKey } from './metadata/metadata-storage' ; export const IsCompositePrimaryKey = ( key ) : key is CompositePrimaryKey => ! ! ( ( key as CompositePrimaryKey ) . partitionKey && ( key as CompositePrimaryKey ) . sortKey ) ; export interface TableOptions { name : string ; partitionKey : string ; sortKey ? : string ; indexes ? : { [ key ] : IndexOptions ; } ; } export class Table { constructor ( private options ) { } set name ( value ) { this . options . name = value ; } get name ( ) { return this . options . name ; } get partitionKey ( ) { return this . options . partitionKey ; } get sortKey ( ) { if ( ! IsCompositePrimaryKey ( this . options ) ) { throw new Error ( 'Only Tables using composite keys can have sort keys' ) ; } return this . options . sortKey ; } usesCompositeKey ( ) { return ! ! ( this . options . partitionKey && this . options . sortKey ) ; } getIndexByKey ( key ) { const { indexes = { } } = this . options ; return indexes [ key ] ; } }