import { Type, apply, Checked, Lossy } from "free-types-core"; import { $SearchMode, $TotalSearch, $ShallowSearch, ShallowSearchResult, ShouldStop, NonEmpty, IsNeedle, $DeepSearch } from "./types.js"; import { Next, Prev } from "../utils.js"; import { $Iterator } from "./Iterators/index.js"; export { SearchMode }; type SearchMode = { total: $Total; shallow: $Shallow; deep: $Deep; }; interface $Total extends $TotalSearch { type: unknown extends this[0] ? never : TotalSeach, Checked<1, this>, Checked<2, this>, SearchMode>; } interface $Shallow extends $ShallowSearch { type: this[0] extends infer Limit ? [unknown] extends [Limit] ? ShallowSearchResult : ShallowSearch, Checked<1, this>> : never; } type TotalSeach = ShouldStop extends true ? NonEmpty> : TotalSeach, apply<$I['path'], [I]> extends infer Path ? Path extends unknown[] ? Path extends Shallow['total'][number] ? Deep : [ ...MergeDeduplicate, ...apply<$Search['deep'], [Shallow['limit'], Acc, apply<$I['value'], [I]>, Path, $Search]> ] : never : never>; type MergeDeduplicate = I extends A['length'] ? [...R, ...B] : MergeDeduplicate, A[I] extends B[number] ? R : [...R, A[I]]>; type PrependType = I extends T['length'] ? R : PrependType, T[I][0] extends Type ? [T[I][0]] extends R[number] ? [...R, T[I]] : [...R, [T[I][0]], T[I]] : [...R, T[I]]>; type ShallowSearch = ShouldStop extends true ? { partial: PartialMatch; total: TotalMatch; limit: Limit; } : true extends IsNeedle, Needle> ? apply<$I['path'], [I]> extends infer P extends unknown[] ? IsNeedle, Needle> extends true ? ShallowSearch, $I, Next, [...TotalMatch, P], PartialMatch> : ShallowSearch, $I, Next, TotalMatch, [...PartialMatch, P]> : never : ShallowSearch, TotalMatch>;