export type Prettify = T extends infer o ? { [K in keyof o]: o[K] } : never; export type MaybeArray = T | T[]; export type MaybeMakeArray = T extends any[] ? Out[] : Out; export type ArrayInnerType = T extends Array ? V : T; export type Values = T[keyof T]; export type Overide = Prettify & B>; export type RemoveIndex = { [K in keyof T as string extends K ? never : number extends K ? never : symbol extends K ? never : K]: T[K]; }; export type LooseAutocomplete = T | (string & {}); export type UnionToIntersection = ( T extends any ? (x: T) => any : never ) extends (x: infer R) => any ? R : never; export type BaseRecord = Record; export type BaseSystemFields = { id: string; created: string; updated: string; }; export type GenericCollection = { type: string; collectionId: string; collectionName: string; response: BaseRecord; create?: BaseRecord; update?: BaseRecord; relations: Record; }; export type GenericSchema = { [K: string]: GenericCollection; }; export type TypedRecord< Data extends BaseRecord, Expand extends GenericExpand = {} > = Data & { expand: Expand; }; export interface SystemFields { id: string; created: string; update: string; } export type BaseCollectionRecords = Record; export type Fields = keyof T['response']; export type Columns = T['response']; export type Expands = { [K in keyof T['relations']]?: T['relations'][K] extends GenericCollection[] ? TypedRecord< T['relations'][K][number], Expands >[] : T['relations'][K] extends GenericCollection ? TypedRecord> : never; }; export type GenericExpand = Record< string, TypedRecord | TypedRecord[] >; type JoinPath = Parts extends [ infer A extends string, ...infer Rest extends string[] ] ? Rest['length'] extends 0 ? A : `${A}.${JoinPath}` : never; type _RecordWithExpandToDotPath< T extends GenericCollection, Path extends string[] = [] > = { [K in keyof T['response'] as JoinPath< [...Path, K & string] >]: T['response'][K]; } & (Path['length'] extends 4 // Supports up to 6-levels depth nested relations expansion. ? {} : UnionToIntersection< Values<{ [K in keyof T['relations']]: _RecordWithExpandToDotPath< ArrayInnerType, [...Path, K & string] >; }> >); export type RecordWithExpandToDotPath = Prettify< _RecordWithExpandToDotPath >; export type ReservedRecordNames = 'collectionId' | 'collectionName';