import { PathItem, Query, ILens } from './types'; import { Type, apply } from 'free-types-core'; import { Next } from './utils'; import { ModifyPath } from './Modify'; import { FollowPath, NOT_FOUND } from './Follow'; import { Lens } from './Lens'; export { Over, $Over, ValidTransform }; type Over> = _Over, Data, Extract>; type ValidTransform['path']> = $V extends Type ? Path extends [...any[], infer $T extends Type] ? RelatedTo<$T['constraints'], $V['constraints']> extends true ? Type<$V['constraints']['length'], $T['constraints']> : Audit<$T['constraints'], $V['constraints'], $T['constraints']> : Path extends [...any[], infer $T extends Type, infer N extends number] ? RelatedTo<[$T['constraints'][N]], $V['constraints']> extends true ? Type<1, $T['constraints'][N]> : Audit<[$T['constraints'][N]], $V['constraints'], $T['constraints'][N]> : Type : Type; type Audit = V['length'] extends T['length'] ? I extends T['length'] ? Type : Audit, [...C, RelatedTo extends true ? V[I] : Unrelated]> : Type; type _Over> = I extends L['path']['length'] ? apply<$V, [Data]> : F extends NOT_FOUND ? Data : ModifyPath>>; interface $Over extends Type<1> { type: _Over, this[0], $V>; } type Unrelated = [V, 'and', T, 'are unrelated']; type RelatedTo = T extends U ? true : U extends T ? true : false;