import { unwrap, Slice } from 'free-types-core'; import { Fn, Param, Output, Query, ILens, Path, QueryItem } from './types.js'; import { Prev, Next, Parameters, ToNumber, GenericFree, SequenceTo, IsAny } from './utils.js'; import { Lens } from './Lens.js'; import { FollowPath, NOT_FOUND } from './Follow.js'; export type Successful = QueryItem[] extends Check ? true : QueryItem extends Check ? true : false; export type Audit, F = FollowPath> = IsAny extends true ? Success : [F] extends [NOT_FOUND] ? HandleError : Next extends L['path']['length'] ? Success : Audit, L>; type Success = Q extends readonly unknown[] ? Q extends unknown[] ? QueryItem[] : readonly QueryItem[] : QueryItem; type HandleError>> = Q extends ILens ? Lens : Q extends [ILens] ? [Lens] : Q extends readonly QueryItem[] ? WrapIfLens : Q extends QueryItem ? R[0] : R; type SaveReadonly = Q extends unknown[] ? P : readonly [...P]; type WrapIfLens = { [K in keyof R]: K extends keyof Q ? Q[K] extends ILens ? Lens : R[K] : R[K]; }; type ProperPath> = [ N ] extends [never] ? LastPathItem : [...LastPathItem, ...Rest]; type Rest = Next extends L['path']['length'] ? [N] : [N, ...QueryItem[]]; type LastPathItem

= I extends 0 ? [] : Slice; type NextPathItem = readonly any[] extends Model ? number : Model extends readonly unknown[] ? NumericArgs : Model extends Fn ? Output | Param['length']>>> : Model extends GenericFree ? unwrap['type'] : Model extends Record ? { [K in keyof Model]: K; }[keyof Model] : never; type NumericArgs = ToNumber; export {};