type BooleanWhere = { $and?: WhereParams[]; $or?: WhereParams[]; $not?: WhereParams; }; type WhereParams = { [K in keyof T]?: T[K]; } & BooleanWhere; type Sortables = { // check sortable [P in keyof T]: P; }[keyof T]; type Direction = 'asc' | 'ASC' | 'DESC' | 'desc'; interface FindParams { select?: (keyof T)[]; // TODO: add nested operators & relations where?: WhereParams; limit?: number; offset?: number; orderBy?: // TODO: add relations | Sortables | Sortables[] | { [K in Sortables]?: Direction } | { [K in Sortables]?: Direction }[]; // TODO: define nested obj populate?: (keyof T)[]; } interface CreateParams { select?: (keyof T)[]; populate?: (keyof T)[]; data: T[keyof T]; } interface CreateManyParams { select?: (keyof T)[]; populate?: (keyof T)[]; data: T[keyof T][]; } interface QueryFromContentType { findOne(params: FindParams): AllTypes[T]; findMany(params: FindParams): AllTypes[T][]; create(params: CreateParams): AllTypes[T][]; createMany(params: CreateManyParams): AllTypes[T][]; } interface ModelConfig { tableName: string; [k: string]: any; } interface ConnectionConfig {} interface DatabaseConfig { connection: ConnectionConfig; models: ModelConfig[]; } interface DatabaseSchema { sync(): Promise; reset(): Promise; create(): Promise; drop(): Promise; } export interface Database { schema: DatabaseSchema; query(uid: T): QueryFromContentType; } export class Database implements Database { static transformContentTypes(contentTypes: any[]): ModelConfig[]; static init(config: DatabaseConfig): Promise; }