import { 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 : TotalSearch, 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 TotalSearch> = ShouldStop extends true ? NonEmpty<[...Acc, ...Shallow['total'], ...Deep]> : TotalSearch, Path extends Shallow['total'][number] ? Deep : [...Deep, ...apply<$Search['deep'], [Shallow['limit'], Acc, apply<$I['value'], [I]>, Path, $Search]>]>; type ShallowSearch = ShouldStop extends true ? { partial: never; total: R; limit: Limit; } : IsNeedle, Needle> extends true ? ShallowSearch, $I, Next, [...R, apply<$I['path'], [I]>]> : ShallowSearch, R>;