// Type definitions for Fluorite.js // Project: https://github.com/pldin601/Fluorite.js // Definitions by: Roman Lakhtadyr // TypeScript Version: 2.5 import * as Knex from 'knex'; declare namespace Fluorite { type Scope = (qb: BaseQuery>, ...args: Array) => BaseQuery>; type Attributes = { [name: string]: any }; type OrderDirection = 'DESC' | 'ASC' | 'desc' | 'asc'; type ModelSubclass> = { new(attributes: Attributes, previousAttributes: Attributes): T; } abstract class Model> { static table: string | null; static idAttribute: string; static scopes: { [name: string]: Scope }; static fluorite: Fluorite; static knex: Knex; static find>(id: any): SingleRowQuery; static objects>(): MultipleRowsQuery; id: any; attributes: Attributes; isNew: boolean; constructor(attributes: Attributes, previousAttributes?: Attributes); get(column: string): any; set(column: string, value: any): void; set(attributes: Attributes): void; save(): Promise; save(name: string, value: any): Promise; save(attributes: Attributes): Promise; remove(): Promise; refresh(): Promise; toJSON(): any; hasMany>( relatedClass: ModelSubclass, foreignKey?: string, foreignKeyTarget?: string, ): HasMany; belongsTo>( relatedClass: ModelSubclass, foreignKey?: string, foreignKeyTarget?: string, ): BelongsTo; belongsToMany>( relatedClass: ModelSubclass, pivotTableName?: string, thisForeignKey?: string, thatForeignKey?: string, thisForeignKeyTarget?: string, thatForeignKeyTarget?: string, ): BelongsToMany; related(name: string): any; load(relation: string): Promise; setRelatedData(name: string, data: Model | Array>): void; static NotFoundError: typeof Error; static IntegrityError: typeof Error; } interface BaseQuery> { filter(attributes: Attributes): this; query(cb: (qb: Knex.QueryBuilder) => void): this; including(...relations: Array): this; limit(limit: number): this; offset(offset: number): this; orderBy(column: string, direction?: OrderDirection): this; create(attributes: Attributes): Promise; update(attributes: Attributes): Promise; remove(): Promise; } interface MultipleRowsQuery> extends BaseQuery, Promise> { count(column?: string): Promise; min(column: string): Promise; max(column: string): Promise; sum(column: string): Promise; avg(column: string): Promise; pluck(column: string): Promise>; single(attributes?: Attributes): SingleRowQuery; first(attributes?: Attributes): SingleRowQuery; } interface SingleRowQuery> extends BaseQuery, Promise {} interface BelongsTo> extends SingleRowQuery {} interface HasMany> extends MultipleRowsQuery {} interface BelongsToMany> extends MultipleRowsQuery {} interface Fluorite { Model: typeof Fluorite.Model; transaction(callback: () => Promise): Promise; } } declare function Fluorite(knex: Knex): Fluorite.Fluorite; export = Fluorite;