import { type AnyObject, type RequiredKeysOf } from '@augment-vir/core'; import { type IsAny, type IsNever, type OptionalKeysOf, type Primitive, type UnionToIntersection } from 'type-fest'; import { type TsRecurse, type TsRecursionStart, type TsRecursionTracker, type TsTooMuchRecursion } from '../type/type-recursion.js'; /** All types that won't be recursed into when defining a {@link SelectionSet}. */ type SelectionTypesToPreserve = Primitive | RegExp | Promise; /** * A generic selection set without specific keys. Useful for type parameter baselines. * * @category Selection * @category Package : @augment-vir/common * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export type GenericSelectionSet = { [Key in PropertyKey]: unknown; }; type MakeKeysOptional = IsNever, keyof T>> extends true ? { [Key in keyof T]: T[Key]; } : IsNever, keyof T>> extends true ? { [Key in keyof T]?: T[Key]; } : /** Optional and required keys. */ { [Key in Extract, keyof T>]: T[Key]; } & { [Key in Extract, keyof T>]?: T[Key]; }; /** * Performs a SQL-like nested selection on an object, extracting the selected values. This produces * the output type for `selectFrom`. * * @category Selection * @category Package : @augment-vir/common * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export type SelectFrom, Selection extends SelectionSet, Depth extends TsRecursionTracker = TsRecursionStart> = Depth extends TsTooMuchRecursion ? ['Error: recursive object depth is too deep.'] : Full extends ReadonlyArray ? (SelectFrom, Selection, TsRecurse> | Exclude)[] : MakeKeysOptional>, Selection[Key], TsRecurse> : Full[Key]) | Exclude; }>; /** * Defines a selection set for a given object type. This is used in {@link SelectFrom}. * * @category Selection * @category Package : @augment-vir/common * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export type SelectionSet, Depth extends TsRecursionTracker = TsRecursionStart> = IsAny extends true ? any : Depth extends TsTooMuchRecursion ? boolean : Full extends ReadonlyArray ? SelectionSet> : Partial<{ [Key in keyof Full]: IsNever> extends true ? boolean : UnionToIntersection[Key]>, TsRecurse>> | boolean; }>; export {};