export declare enum ColumnType { Any = "any", Array = "array", Boolean = "boolean", Date = "date", Enum = "enum", JSON = "json", Number = "number", Object = "object", String = "string" } interface ObjectShape { [propName: string]: ColumnDescription; } export interface ColumnDescription, EnumValues extends string | number, ObjectProps extends ObjectShape> { type: Type; subtype?: SubType; enum?: EnumValues[]; props?: ObjectProps; hasDefault?: boolean; nullable?: boolean; } export declare type ColumnDescriptor = ColumnDescription; export interface TableSchemaDescriptor { [columnName: string]: ColumnDescriptor; } export interface TableSchema { name: string; columns: Columns; } declare type DeriveBuiltinTypeByColumnType> = Column extends { type: infer Col; } ? (Col extends ColumnType.Any ? any : Col extends ColumnType.Boolean ? boolean : Col extends ColumnType.Date ? string : Col extends ColumnType.Number ? number : Col extends ColumnType.String ? string : Col extends ColumnType.Enum ? (Column extends ColumnDescription ? EnumValues : never) : any) : never; declare type DeriveComplexBuiltinType> = Column extends ColumnDescription ? Array> : Column extends ColumnDescription ? DeriveBuiltinTypeByColumnType : Column extends ColumnDescription ? { [propName in keyof ObjectProps]: DeriveBuiltinType; } : DeriveBuiltinTypeByColumnType; declare type DeriveBuiltinType> = Column extends { nullable: true; } ? DeriveComplexBuiltinType | null : DeriveComplexBuiltinType; declare type MandatoryColumnsNames = { [columnName in keyof Columns]: Columns[columnName] extends { hasDefault: true; } ? never : columnName; }[keyof Columns]; declare type ColumnsWithDefaultsNames = { [columnName in keyof Columns]: Columns[columnName] extends { hasDefault: true; } ? columnName : never; }[keyof Columns]; export declare type TableRow> = ConcreteTableSchema extends TableSchema ? { [columnName in keyof Columns]: DeriveBuiltinType; } : never; export declare type NewTableRow> = ConcreteTableSchema extends TableSchema ? { [columnName in MandatoryColumnsNames]: DeriveBuiltinType; } & { [columnName in ColumnsWithDefaultsNames]?: DeriveBuiltinType; } : never; interface SchemaTypes { /** Placeholder. Can stand for any random data type. Avoid using it. */ Any: { type: ColumnType.Any; }; /** Data type for BOOLEAN columns. */ Boolean: { type: ColumnType.Boolean; }; /** Data type for DATE, DATETIME, TIMESTAMP columns. */ Date: { type: ColumnType.Date; }; /** Data type for INTEGER, SMALLINT, BIGINT, FLOAT, REAL, NUMERIC columns. */ Number: { type: ColumnType.Number; }; /** Data type for CHAR, VARCHAR, TEXT columns. */ String: { type: ColumnType.String; }; /** Data type for array columns. Pass the data type of the array elements. */ Array>(subtype: SubType): ColumnDescription; /** Data type for ENUM columns. Pass an array of possible values. */ Enum(values: T[]): ColumnDescription; /** * Data type for JSON, JSONB columns. Pass Schema.Object(), Schema.Array(), ..., Schema.Any * to declare the content of the JSON(B) column. */ JSON>(subtype: SubType): ColumnDescription; /** Pseudo data type to describe the shape of objects stored in a Schema.JSON() column. */ Object(props: Props): ColumnDescription; /** Declare that this column has a DEFAULT value. Pass the actual schema definition. */ default>(column: Column): Column & { hasDefault: true; }; /** Declare that this column allows NULL values. Implies DEFAULT NULL. */ nullable>(column: Column): Column & { hasDefault: true; nullable: true; }; } /** * Schema types to declare the data type of table columns. */ export declare const Schema: SchemaTypes; /** * Declare a table's schema. Registers the schema globally. */ export declare function defineTable(tableName: string, schema: Columns): TableSchema; /** * Return an array of all defined table schemas. */ export declare function getAllTableSchemas(): TableSchema[]; export {};