import { PartitionKey } from "./keys" import { Model } from "./Model" import { Table } from "./Table" import { ExtractFields } from "./types" type StringKey = keyof ExtractFields & string export class GSI> { private modelTags: string[] constructor( private table: Table, readonly name: string, private models: T[], readonly partitionKeyName: StringKey, readonly sortKeyName: StringKey ) { this.table.registerGSI(this) this.modelTags = models.map((_) => _.modelTag) } key(partitionKey: string): PartitionKey> { return new PartitionKey(this.partitionKeyName, partitionKey, this.modelTags) } } export class GSIBuilder { constructor(private table: Table, private name: string) {} models>(models: T[]): GSIKeyBuilder { return new GSIKeyBuilder(this.table, this.name, models) } } class GSIKeyBuilder> { private partitionKeyName?: StringKey constructor(private table: Table, private name: string, private models: T[]) {} partitionKey(partitionKeyName: PK | SK | StringKey): this { this.partitionKeyName = partitionKeyName return this } sortKey(sortKeyName: PK | SK | StringKey): GSI { return new GSI(this.table, this.name, this.models, this.partitionKeyName!, sortKeyName) } }