import { DeepNonNullable } from "../util.js"; import { ExpandKey, SelectKey } from "../common.js"; //#region src/core/interfaces/vertices/util/custom-vertex-export/util.d.ts /** * Lookup type that returns the value type for key K in object Obj, */ type Lookup = K extends keyof Obj ? Obj[K] : ELSE; /** * Intersect two expand/select specifications. * * - For the SelectKey ('select'): returns an array whose element type is the * intersection of the element types from A and B, preserving null/undefined from A. * - For the ExpandKey ('expand'): keeps only keys present in both A and B and * recurses into their sub-specs. * - Other keys are dropped. * * Useful to constrain a requested expand/select spec (A) by an allowed/spec (B), * yielding only the common subset. */ type IntersectExpandSelectPath = _IntersectExpandSelectPath, DeepNonNullable>; type _IntersectExpandSelectPath = [A] extends [never] ? never : { [K in keyof A & keyof B]: K extends SelectKey ? A[K] extends (infer V1)[] ? B[K] extends (infer V2)[] ? (V1 & V2)[] | Extract : never : never : K extends ExpandKey ? { [S in keyof A[K] & keyof B[K]]: A[K][S] extends object ? B[K][S] extends object ? IntersectExpandSelectPath : never : never } : never }; /** * Extracts the parent keys from a set of dot-notation keys. * * @example * Keys: 'a' | 'b.1' | 'c.2' | 'd' => 'a' | 'b' | 'c' | 'd' */ type ExtractParentKeys = Keys extends `${infer B}.${string}` ? B : Keys; /** * Extracts the child keys from a set of dot-notation keys, given a parent key. * * @example * ParentKey: 'a' * Keys: 'a' | 'a.1' | 'a.2' | 'b.1' | 'c' => '1' | '2' */ type ExtractChildKeys = Keys extends `${ParentKey}.${infer K}` ? K : never; /** * Extracts the child object from an object, given a parent key. * * @example * ParentKey: 'a' * Object: { 'a': string; 'a.1': number; 'a.2': boolean; 'b.1': string; 'c': Date } => { '1': number; '2': boolean } */ type ExtractChildObject = { [K in keyof Object as K extends `${ParentKey & string}.${infer S}` ? S : never]: Object[K] }; /** * Does the same as the built-in Pick, but does not restrict the Keys to keyof T. Nullish and undefined values are preserved. */ type RelaxedPick = Extract | (T extends object ? { [K in keyof NonNullable as K extends Keys ? K : never]: NonNullable[K] } : never); //#endregion export { ExtractChildKeys, ExtractChildObject, ExtractParentKeys, IntersectExpandSelectPath, Lookup, RelaxedPick }; //# sourceMappingURL=util.d.ts.map