import * as sd from "type-mapping"; import {ITable} from "../table"; import {ColumnMap, ColumnMapUtil} from "../column-map"; import {TypeMapUtil} from "../type-map"; import {Key} from "../key"; export type CandidateKeyImpl = ( K extends Key ? TypeMapUtil.FromColumnMap< Pick > : never ); export type CandidateKey = ( CandidateKeyImpl< TableT["columns"], TableT["candidateKeys"][number] > ); export namespace CandidateKeyUtil { export type AssertDelegate = ( sd.SafeMapper> ); export function assertDelegate ( table : TableT ) : ( AssertDelegate ) { return sd.unsafeOr( ...table.candidateKeys.map((candidateKey) => { return ColumnMapUtil.assertDelegate( ColumnMapUtil.pick(table.columns, candidateKey) ); }) ) as any; } }