import type BaseRepository from "./baseRepository.ts"; import type { AnyRelationQuery, RelatedModelClass } from "./relationQuery.ts"; import { BelongsToManyRelationQuery, BelongsToRelationQuery, HasManyRelationQuery, HasManyThroughRelationQuery, HasOneRelationQuery, MorphManyRelationQuery, MorphOneRelationQuery, MorphToRelationQuery } from "./relationQuery.ts"; import type { BelongsToManyRelation, BelongsToRelation, HasManyRelation, HasOneRelation } from "./relationships.ts"; import type { RepositoryQuery } from "./repositoryQuery.ts"; import type { QueryOptions, QueryWhere } from "./types.ts"; type CastType = "date" | "datetime" | "json" | "bool" | "boolean" | "integer" | "int" | "hashed"; type LoadedAttributes = Record; type ModelCasts = Partial>; type GlobalScopeFn = (query: RepositoryQuery) => RepositoryQuery; type ModelClassType = typeof Model & (new (attributes: TEntity, repository: BaseRepository, exists?: boolean) => Model); interface ModelConstructor> extends ModelClassType { new (attributes: TEntity, repository: BaseRepository, exists?: boolean): TModel; } type AnyModel = Model, "id">; type RelatedRef = RelatedModelClass | string | (() => RelatedModelClass); type RelationNameInput = string | readonly string[]; type ModelObserver = { retrieved?: (model: AnyModel) => unknown; creating?: (model: AnyModel) => unknown; created?: (model: AnyModel) => unknown; updating?: (model: AnyModel) => unknown; updated?: (model: AnyModel) => unknown; saving?: (model: AnyModel) => unknown; saved?: (model: AnyModel) => unknown; deleting?: (model: AnyModel) => unknown; deleted?: (model: AnyModel) => unknown; }; /** Alias for `hasMany("Name")` when `Name` is not `constructor.name` or `$morphClass`. */ declare function registerModelClass(name: string, model: object): void; declare function hydrateValue(value: unknown, cast: CastType): unknown; declare function dehydrateValue(value: unknown, cast: CastType): unknown; declare function filterMassAssignable(fillable: readonly string[] | undefined, guarded: readonly string[] | true | undefined, input: LoadedAttributes): LoadedAttributes; declare function applyCasts(values: LoadedAttributes, casts: ModelCasts, direction: "hydrate" | "dehydrate"): LoadedAttributes; declare class ModelQuery { private readonly modelClass; readonly query: RepositoryQuery, "id">; private readonly eager; constructor(modelClass: object, query: RepositoryQuery, "id">); with(...relations: RelationNameInput[]): this; where(input: QueryWhere | ((builder: import("./whereBuilder.ts").WhereBuilder) => void)): this; orWhere(input: QueryWhere | ((builder: import("./whereBuilder.ts").WhereBuilder) => void)): this; orderBy(orderBy: QueryOptions["orderBy"]): this; limit(limit: number): this; offset(offset: number): this; whereNull(column: string): this; whereNotNull(column: string): this; whereIn(column: string, values: readonly unknown[]): this; whereNotIn(column: string, values: readonly unknown[]): this; groupBy(groupBy: QueryOptions["groupBy"]): this; having(having: QueryWhere): this; join(left: `${string}.${string}`, right: `${string}.${string}`): this; leftJoin(left: `${string}.${string}`, right: `${string}.${string}`): this; paginate(options: { page: number; perPage: number; }): Promise<{ data: Array, "id">>; meta: Awaited, "id">["paginate"]>>["meta"]; }>; whereExists(sql: string, params?: readonly unknown[]): this; whereNotExists(sql: string, params?: readonly unknown[]): this; whereHas(name: string, constrain?: (query: AnyRelationQuery) => void): this; has(name: string): this; doesntHave(name: string): this; whereDoesntHave(name: string, constrain?: (query: AnyRelationQuery) => void): this; withHasMany(...args: Parameters, "id">["withHasMany"]>): this; withBelongsTo(...args: Parameters, "id">["withBelongsTo"]>): this; withBelongsToMany(...args: Parameters, "id">["withBelongsToMany"]>): this; withMorphMany(...args: Parameters, "id">["withMorphMany"]>): this; withMorphOne(...args: Parameters, "id">["withMorphOne"]>): this; withMorphTo(...args: Parameters, "id">["withMorphTo"]>): this; withHasManyThrough(...args: Parameters, "id">["withHasManyThrough"]>): this; withTrashed(): this; onlyTrashed(): this; get(): Promise, "id">>>; private hydrateRows; first(): Promise, "id"> | null>; count(): Promise; pluck(column: string): Promise; pluck(column: string, keyBy: string): Promise>; value(column: string): Promise; find(id: unknown): Promise, "id"> | null>; findOrFail(id: unknown, errorFactory?: (id: unknown) => Error): Promise, "id">>; then(onfulfilled?: ((value: Array, "id">>) => unknown) | null, onrejected?: ((reason: unknown) => unknown) | null): Promise; withCount(name: string, alias?: string): this; private constrainExists; } declare class Model { protected attributes: TEntity; protected readonly repository: BaseRepository; static $fillable?: readonly string[]; static $guarded?: readonly string[] | true; static $casts: ModelCasts; static $timestamps: boolean; static $hidden?: readonly string[]; static $visible?: readonly string[]; static $appends?: readonly string[]; static $morphClass?: string; private _exists; private readonly loadedRelations; private hiddenOverrides; private visibleOverrides; private appended; constructor(attributes: TEntity, repository: BaseRepository, exists?: boolean); getRepository(): BaseRepository; get $exists(): boolean; get(key: K): TEntity[K]; get id(): TEntity[PrimaryKey]; toObject(): TEntity; toArray(): Record; toJSON(): Record; makeHidden(...keys: string[]): this; makeVisible(...keys: string[]): this; append(...keys: string[]): this; protected primaryKey(): PrimaryKey; protected static primaryKeyField(this: object): string; protected static hydrateAttributes(this: object, attributes: TEntity): TEntity; protected static dehydrateAttributes(this: object, attributes: LoadedAttributes): LoadedAttributes; protected static fromRecord(this: object, record: TEntity, repository: BaseRepository, exists?: boolean): Model; static boot(): void; static observe(this: object, observer: ModelObserver): void; static addGlobalScope(this: object, _name: string, scope: GlobalScopeFn): void; static repository(this: object): BaseRepository; static query(this: object): ModelQuery; static newFromRecord(this: object, record: object, exists?: boolean): Model, "id">; static create(this: object, attributes: Record, forced?: Record): Promise, "id">>; static with(this: object, ...relations: RelationNameInput[]): ModelQuery; static withTrashed(this: object): ModelQuery; static onlyTrashed(this: object): ModelQuery; static chunk(this: object, count: number, callback: (models: Array, "id">>) => Promise): Promise; static cursorPaginate(this: object, options: { perPage: number; cursor?: unknown; }): Promise<{ data: Array, "id">>; meta: { per_page: number; next_cursor: unknown; prev_cursor: unknown; has_more: boolean; }; }>; static whereHas(this: object, name: string, constrain?: (query: AnyRelationQuery) => void): ModelQuery; static has(this: object, name: string): ModelQuery; static doesntHave(this: object, name: string): ModelQuery; static whereDoesntHave(this: object, name: string, constrain?: (query: AnyRelationQuery) => void): ModelQuery; static find(this: object, id: unknown): Promise, "id"> | null>; static findOrFail(this: object, id: unknown, errorFactory?: (id: unknown) => Error): Promise, "id">>; static all(this: object, options?: Omit, "where">): Promise, "id">>>; static where(this: object, where: QueryWhere): ModelQuery; static count(this: object): Promise; static pluck(this: object, column: string): Promise; static pluck(this: object, column: string, keyBy: string): Promise>; static value(this: object, column: string): Promise; static firstWhere(this: object, where: QueryWhere, options?: Omit, "where">): Promise, "id"> | null>; static firstOrNew(this: object, where: QueryWhere, values?: Record): Promise, "id">>; static firstOrCreate(this: object, where: QueryWhere, values?: Record): Promise, "id">>; static updateOrCreate(this: object, where: QueryWhere, values?: Record): Promise, "id">>; save(): Promise; update(changes: Partial): Promise; delete(): Promise; forceDelete(): Promise; restore(): Promise; loadHasMany(as: Alias, relation: HasManyRelation, childRepository: BaseRepository, options?: Omit, "where">): Promise>; loadHasOne(as: Alias, relation: HasOneRelation, childRepository: BaseRepository, options?: Omit, "where">): Promise>; loadBelongsTo(as: Alias, relation: BelongsToRelation, parentRepository: BaseRepository, options?: Omit, "where">): Promise>; loadBelongsToMany(as: Alias, relation: BelongsToManyRelation, relatedRepository: BaseRepository, options?: Omit, "where">): Promise>; hasMany(related: RelatedRef, foreignKey?: keyof TRelated & string, localKey?: PrimaryKey): HasManyRelationQuery; hasOne(related: RelatedRef, foreignKey?: keyof TRelated & string, localKey?: PrimaryKey): HasOneRelationQuery; belongsTo(related: RelatedRef, foreignKey?: keyof TEntity & string, ownerKey?: RelatedKey): BelongsToRelationQuery; hasManyThrough(related: RelatedRef, through: RelatedRef, firstKey?: string, secondKey?: keyof TRelated & string, localKey?: PrimaryKey, secondLocalKey?: ThroughKey): HasManyThroughRelationQuery; belongsToMany>(related: RelatedRef, pivotTable?: string, foreignPivotKey?: keyof Pivot & string, relatedPivotKey?: keyof Pivot & string): BelongsToManyRelationQuery; morphMany(related: RelatedRef, morphName: string, typeKey?: keyof TRelated & string, idKey?: keyof TRelated & string, morphType?: string): MorphManyRelationQuery; morphOne(related: RelatedRef, morphName: string, typeKey?: keyof TRelated & string, idKey?: keyof TRelated & string, morphType?: string): MorphOneRelationQuery; morphTo(relatedByType: Record, "id">>, morphName?: string, typeKey?: keyof TEntity & string, idKey?: keyof TEntity & string): MorphToRelationQuery; load(...names: RelationNameInput[]): Promise; loaded(name: string): T | undefined; setLoaded(name: string, value: unknown): this; mergeAttributes(patch: Partial): this; } /** Binds a Model class to its table/connection and names it for `hasMany("User")`. */ declare function registerModelRepository(model: TModelClass, repository: object): TModelClass; export { BelongsToManyRelationQuery, BelongsToRelationQuery, HasManyRelationQuery, HasManyThroughRelationQuery, HasOneRelationQuery, MorphManyRelationQuery, MorphOneRelationQuery, MorphToRelationQuery, } from "./relationQuery.ts"; export type { CastType, GlobalScopeFn, ModelClassType, ModelConstructor }; export { applyCasts, dehydrateValue, filterMassAssignable, hydrateValue, Model, ModelQuery, registerModelClass, registerModelRepository, };