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"; import {Omit} from "../type"; import {CandidateKeyImpl} from "../candidate-key"; export type SuperKeyImpl = ( K extends Key ? CandidateKeyImpl & Partial< TypeMapUtil.FromColumnMap< Omit > > : never ); export type SuperKey = ( SuperKeyImpl< TableT["columns"], TableT["candidateKeys"][number] > ); export namespace SuperKeyUtil { export type AssertDelegate = ( sd.SafeMapper> ); export function assertDelegate ( table : TableT ) : ( AssertDelegate ) { return sd.unsafeOr( ...table.candidateKeys.map((candidateKey) => { return sd.deepMerge( ColumnMapUtil.assertDelegate( ColumnMapUtil.pick(table.columns, candidateKey) ), ColumnMapUtil.partialAssertDelegate( ColumnMapUtil.omit(table.columns, candidateKey) ) ); }) ) as any; } }