import type { Prettify } from "../../utils/index.js"; import type { AttioRecord } from "../attio-record.js"; import type { FormArray } from "./array.js"; import type { FormAttioRecord } from "./attio-record.js"; import type { FormBoolean } from "./boolean.js"; import type { FormDateTime } from "./date-time.js"; import type { FormNumber } from "./number.js"; import type { FormPlainDate } from "./plain-date.js"; import type { FormString } from "./string.js"; import type { FormValue } from "./value.js"; type Assert = TCat extends TAnimal ? TCat : never; type Join = A extends null ? B : `${A}.${B}`; export type ValueType = "string" | "number" | "boolean" | "array" | "date-time" | "plain-date" | "attio-record"; export type SchemaNode = FormString | FormNumber | FormBoolean | FormArray | FormDateTime | FormPlainDate | FormAttioRecord | { type: "object"; }; type PathWithTypeRecursive = TState extends FormString ? { path: TRoot; type: "string"; } : TState extends FormBoolean ? { path: TRoot; type: "boolean"; } : TState extends FormNumber ? { path: TRoot; type: "number"; } : TState extends FormDateTime ? { path: TRoot; type: "date-time"; } : TState extends FormPlainDate ? { path: TRoot; type: "plain-date"; } : TState extends FormAttioRecord ? { path: TRoot; type: "attio-record"; } : TState extends FormArray ? { path: TRoot; type: "array"; } | PathWithTypeRecursive> : { [K in keyof TState]: K extends string ? PathWithTypeRecursive> : never; }[keyof TState]; type PathWithType = Assert>, { path: string; type: ValueType; }>; export type Path = PathWithType["path"]; export type PathTo = Extract, { type: TType; }>["path"]; /** * Helper to check if a form value type matches a target type by comparing their type properties. */ type MatchesFormType, TElementType extends FormValue | Record> = TElement extends { type: infer TElementTypeValue; } ? TElementType extends { type: infer TTargetTypeValue; } ? TElementTypeValue extends TTargetTypeValue ? TTargetTypeValue extends TElementTypeValue ? true : false : false : false : false; /** * A helper type that extracts paths to arrays with a specific element type. * This allows for more precise typing when you need arrays of a specific type, * e.g., `PathToArrayOf>` will only match arrays of strings. * * The compatibility check works by comparing the `type` property of both types. * This allows FormString to match FormString because both have type: "string". */ type PathToArrayOfRecursive, TRoot extends string | number | null> = TState extends FormArray ? MatchesFormType extends true ? { path: TRoot; } : never : TState extends Record ? { [K in keyof TState]: K extends string ? PathToArrayOfRecursive> : never; }[keyof TState] : never; export type PathToArrayOf> = PathToArrayOfRecursive extends infer Result ? Result extends { path: infer TPath; } ? TPath extends string ? TPath : never : never : never; export type ValueOf = TState extends FormString ? TOptional extends true ? string | undefined : string : TState extends FormBoolean ? TOptional extends true ? boolean | undefined : boolean : TState extends FormNumber ? TOptional extends true ? number | undefined : number : TState extends FormDateTime ? TOptional extends true ? Date | undefined : Date : TState extends FormPlainDate ? TOptional extends true ? string | undefined : string : TState extends FormAttioRecord ? TOptional extends true ? AttioRecord | undefined : AttioRecord : TState extends FormArray ? TOptional extends true ? Array> | undefined : Array> : { [K in keyof TState]: K extends string ? ValueOf : never; }; export {}; //# sourceMappingURL=path.d.ts.map