export interface Database { name: string; tables: Table[]; } export interface Table { name: string; columns: Column[]; constraints: Constraint[]; } export type ScalarValue = string | number | boolean | Date | null; export type JsonPrimitive = string | number | boolean | null; export type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue; }; export type Value = ScalarValue; export type DocumentValue = Value | JsonValue | Value[] | JsonValue[] | Document | Document[]; /** * A reference to a row by its primary key. Foreign-key fields on a generated * row type resolve to this for the common case of a single `id` column. */ export interface Identifiable { id: T; } export type Document = { [key: string]: DocumentValue; }; export type AnyDocument = { [key: string]: any; }; export type FilterOperator = 'lt' | 'le' | 'ge' | 'gt' | 'ne' | 'in' | 'notIn' | 'like' | 'ilike' | 'null' | 'some' | 'none' | 'exists'; export type FilterValue = T | T[] | null | (NonNullable extends object ? FilterShape> | ScalarValue : never); export type FilterShape = { [K in keyof TRow & string]?: FilterValue; } & { [K in keyof TRow & string as `${K}_${FilterOperator}`]?: FilterValue; } & { and?: FilterShape | FilterShape[]; or?: FilterShape | FilterShape[]; not?: FilterShape | FilterShape[]; }; export type SelectFieldSpec = '*' | (keyof TRow & string) | { [K in keyof TRow & string]?: SelectFieldSpec | RelatedSelectOptions; }; export interface RelatedSelectOptions { fields?: SelectFieldSpec | string | string[]; where?: FilterShape | FilterShape[]; offset?: number; limit?: number; orderBy?: string | string[]; groupBy?: string[]; having?: FilterShape | FilterShape[]; } export type SelectFields = '*' | (keyof TRow & string) | string | string[] | SelectFieldSpec; export interface MutationOptions { returning?: SelectFields; } export interface ParentMutation> { connect?: TFilter; create?: TCreate; update?: TUpdate; } export interface RelatedUpsert> { create: TCreate; update?: TUpdate; } export interface RelatedUpdate { where?: TFilter; data: TUpdate; } export interface RelatedMutation> { connect?: TFilter | TFilter[]; create?: TCreate | TCreate[]; upsert?: RelatedUpsert | RelatedUpsert[]; update?: TUpdate | RelatedUpdate | Array>; delete?: TFilter | TFilter[]; disconnect?: TFilter | TFilter[]; set?: TCreate | TCreate[]; } export interface TableSpec, TUpdate extends object = Partial, TFilter extends object = FilterShape, TInsert extends object = TCreate> { row: TRow; create: TCreate; update: TUpdate; filter: TFilter; insert: TInsert; } export type AnyTableSpec = TableSpec; export type LooseTableSpec = TableSpec; export type TableMap = { [key: string]: AnyTableSpec; }; type IsAny = 0 extends (1 & T) ? true : false; export type TableRow = IsAny extends true ? Document : TSpec extends TableSpec ? TRow : Document; export type TableCreate = IsAny extends true ? Document : TSpec extends TableSpec ? TCreate : Document; export type TableUpdate = IsAny extends true ? Document : TSpec extends TableSpec ? TUpdate : Document; export type TableFilter = IsAny extends true ? Document : TSpec extends TableSpec ? TFilter : Document; export type TableInsert = IsAny extends true ? Document : TSpec extends TableSpec ? TInsert : Document; export interface UserDefinedType { type: 'enum'; name: string; values: string[]; } export interface Column { name: string; type: string; size?: number; nullable?: boolean; autoIncrement?: boolean; default?: Value; userDefinedType?: UserDefinedType; } export interface Constraint { name?: string; columns: string[]; primaryKey?: boolean; unique?: boolean; references?: ReferencedConstraint; isVirtual?: boolean; } export interface ReferencedConstraint extends Constraint { table: string; } export {};