import type { AnyQueryBuilder, WithRelationType } from './query-methods' import type { Hook, RelationNames, ReturnTypeOfMethod, SnakeToCamelCase, TFunction, TGeneric, } from './generics' import type { IBuilder } from './builder' import type { ICollection } from './utils' import type Model from 'src/model' import type { TBaseConfig } from './container' export interface Attribute { make (config: { get?: TFunction | null; set?: TFunction | null }): Attribute get: TFunction | null set: TFunction | null withCaching?: boolean withObjectCaching?: boolean } export interface CastsAttributes { get (): any set (): void } export type Relation = IBuilder & {} export interface HasOneOrMany extends Relation { save (model: M): Promise saveMany (models: M[] | ICollection): Promise> create (attributes?: any): Promise createMany (records: any[]): Promise> } export interface HasOne extends HasOneOrMany { getResults (): Promise withDefault (callback?: TFunction | object): this } export interface HasMany extends HasOneOrMany { getResults (): Promise> } export interface BelongsTo extends Relation { getResults (): Promise withDefault (callback?: TFunction | object): this } export interface BelongsToMany extends Relation { getResults (): Promise> withTimestamps (): this wherePivot ( column: any, operator?: any, value?: any, boolean?: string, ...args: any[] ): this wherePivotBetween ( column: any, values: any, boolean?: string, not?: boolean, ): this orWherePivotBetween (column: any, values: any): this wherePivotNotBetween (column: any, values: any, boolean?: string): this orWherePivotNotBetween (column: any, values: any): this wherePivotIn (column: any, values: any, boolean?: string, not?: boolean): this orWherePivot (column: any, operator?: any, value?: any): this orWherePivotIn (column: any, values: any): this wherePivotNotIn (column: any, values: any, boolean?: string): this orWherePivotNotIn (column: any, values: any): this wherePivotNull (column: any, boolean?: string, not?: boolean): this wherePivotNotNull (column: any, boolean?: string): this orWherePivotNull (column: any, not?: boolean): this orWherePivotNotNull (column: any): this orderByPivot (column: any, direction?: string): this } export interface IModel { [value: string]: any attributes: any relations: any exists: boolean // primaryKey: string // builder?: IBuilder | null // table: string | null connection?: TBaseConfig['client'] | null // keyType: string // incrementing: boolean perPage: number with: string | string[] | TGeneric<(...args: any[]) => IBuilder> // withCount: string[] trx: AnyQueryBuilder | null timestamps: boolean dateFormat: string visible: string[] hidden: string[] query ( this: T, client?: AnyQueryBuilder | null, ): IBuilder on ( this: T, connection: string | null, ): IBuilder boot (): void make (this: new () => T, attributes?: TGeneric): T addHook (hook: Hook, callback: TFunction): void creating (callback: TFunction): void created (callback: TFunction): void updating (callback: TFunction): void updated (callback: TFunction): void deleting (callback: TFunction): void deleted (callback: TFunction): void saving (callback: TFunction): void saved (callback: TFunction): void restoring (callback: TFunction): void restored (callback: TFunction): void trashed (callback: TFunction): void forceDeleted (callback: TFunction): void bootIfNotBooted (): void initialize (): void initializePlugins (): void addPluginInitializer (method: any): void newInstance (attributes?: TGeneric, exists?: boolean): any getKey (): string | number | null | undefined getKeyName (): string getConnectionName (): string getConnection (): any setConnection (connection: TBaseConfig['client'] | null): this usesUniqueIds (): boolean uniqueIds (): string[] // newUniqueId (): string; setUniqueIds (): void getKeyType (): string getIncrementing (): boolean setIncrementing (value: boolean): this getTable (): string setTable (table: string): this getDates (): string[] getDateFormat (): string getAttributes (): object getAttribute (key: string): any setAttribute (key: string, value: any): this fill (attributes: any): this setAppends (appends: string[]): this append (key: string | string[]): this getRelation ( relation: string, ): T | ICollection | null | undefined getRelation ( relation: string ): IsCollection extends true ? ICollection | undefined : T | null | undefined; setRelation ( relation: string, value: T | ICollection | null, ): this unsetRelation (relation: string): this relationLoaded (relation: string): boolean makeVisible (attributes: string | string[]): this makeHidden (attributes: string | string[]): this newCollection (models?: any[]): ICollection load (relations: WithRelationType): Promise load (...relations: WithRelationType[]): Promise loadAggregate ( relations: WithRelationType, column: any, callback?: any, ): Promise loadCount (...relations: WithRelationType[]): Promise loadMax (relations: WithRelationType, column: string): Promise loadMin (relations: WithRelationType, column: string): Promise loadSum (relations: WithRelationType, column: string): Promise usesTimestamps (): boolean updateTimestamps (): this getCreatedAtColumn (): string getUpdatedAtColumn (): string getDeletedAtColumn (): string setCreatedAt (value: string): this setUpdatedAt (value: string): this freshTimestamp (): Date freshTimestampString (): string fromDateTime (value: Date | number | null): string useSoftDeletes (): boolean toData (): any attributesToData (): any relationsToData (): any toJSON (): any toJson (): string toString (): string isDirty (attributes?: string | string[]): boolean getDirty (): string[] save (options?: any): Promise update (attributes?: any, options?: any): Promise increment (column: string, amount?: number, extra?: any): Promise decrement (column: string, amount?: number, extra?: any): Promise serializeDate (date: any): string delete (options?: any): Promise softDelete (options?: any): Promise forceDelete (options?: any): Promise restore (options?: any): Promise trashed (): boolean fresh (): Promise refresh (): Promise push (): Promise is (model: this): boolean isNot (model: this): boolean // related(relation: string): Builder; // getRelated(relation: string): Promise | null>; related> ( relation: T, ): ReturnTypeOfMethod>}`> getRelated> ( relation: T, ): ReturnTypeOfMethod< ReturnTypeOfMethod>}`>, any > //'getResults'>; hasOne ( model: new () => T, foreignKey?: string, localKey?: string, ): HasOne hasMany ( model: new () => T, foreignKey?: string, localKey?: string, ): HasMany belongsTo ( model: new () => T, foreignKey?: string, ownerKey?: string, relation?: string, ): BelongsTo belongsToMany ( model: new () => T, table?: string, foreignPivotKey?: string, relatedPivotKey?: string, parentKey?: string, relatedKey?: string, ): BelongsToMany } export type IPivot = IModel & {}