import { type Ref } from './Reference.js'; import type { AutoPath, EntityData, EntityDTO, Loaded, LoadedReference, AddEager, EntityKey, FromEntityType, IsSubset, MergeSelected, SerializeDTO } from '../typings.js'; import { type AssignOptions } from './EntityAssigner.js'; import type { EntityLoaderOptions } from './EntityLoader.js'; import { type SerializeOptions } from '../serialization/EntitySerializer.js'; import type { FindOneOptions } from '../drivers/IDatabaseDriver.js'; import type { PopulatePath } from '../enums.js'; /** Base class for entities providing convenience methods like `assign()`, `toObject()`, and `populate()`. */ export declare abstract class BaseEntity { /** Returns whether the entity has been fully loaded from the database. */ isInitialized(): boolean; /** Marks the entity as populated or not for serialization purposes. */ populated(populated?: boolean): void; /** Loads the specified relations on this entity. */ populate(populate: AutoPath[] | false, options?: EntityLoaderOptions): Promise>; /** Returns a Reference wrapper for this entity. */ toReference(): Ref & LoadedReference>>; /** * Converts the entity to a plain object representation. * * **Note on typing with `Loaded` entities:** When called on a `Loaded` type, * the return type will be `EntityDTO` (with relations as primary keys), not * `EntityDTO>` (with loaded relations as nested objects). * This is a TypeScript limitation - the `this` type resolves to the class, not the `Loaded` wrapper. * * For correct typing that reflects loaded relations, use `wrap()`: * ```ts * const result = await em.find(User, {}, { populate: ['profile'] }); * // Type: EntityDTO (profile is number) * const obj1 = result[0].toObject(); * // Type: EntityDTO> (profile is nested object) * const obj2 = wrap(result[0]).toObject(); * ``` * * Runtime values are correct in both cases - only the static types differ. */ toObject(): EntityDTO; /** * Converts the entity to a plain object representation. * * **Note on typing with `Loaded` entities:** When called on a `Loaded` type, * the return type will be `EntityDTO` (with relations as primary keys), not * `EntityDTO>` (with loaded relations as nested objects). * This is a TypeScript limitation - the `this` type resolves to the class, not the `Loaded` wrapper. * * For correct typing that reflects loaded relations, use `wrap()`: * ```ts * const result = await em.find(User, {}, { populate: ['profile'] }); * // Type: EntityDTO (profile is number) * const obj1 = result[0].toObject(); * // Type: EntityDTO> (profile is nested object) * const obj2 = wrap(result[0]).toObject(); * ``` * * Runtime values are correct in both cases - only the static types differ. */ toObject(ignoreFields: never[]): EntityDTO; /** * Converts the entity to a plain object representation. * * **Note on typing with `Loaded` entities:** When called on a `Loaded` type, * the return type will be `EntityDTO` (with relations as primary keys), not * `EntityDTO>` (with loaded relations as nested objects). * This is a TypeScript limitation - the `this` type resolves to the class, not the `Loaded` wrapper. * * For correct typing that reflects loaded relations, use `wrap()`: * ```ts * const result = await em.find(User, {}, { populate: ['profile'] }); * // Type: EntityDTO (profile is number) * const obj1 = result[0].toObject(); * // Type: EntityDTO> (profile is nested object) * const obj2 = wrap(result[0]).toObject(); * ``` * * Runtime values are correct in both cases - only the static types differ. * * @param ignoreFields - Array of field names to omit from the result. */ toObject = never>(ignoreFields: Ignored[]): Omit, Ignored>; /** Converts the entity to a plain object, including all properties regardless of serialization rules. */ toPOJO(): EntityDTO; /** Serializes the entity with control over which relations and fields to include or exclude. */ serialize = FromEntityType, Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions): SerializeDTO; /** Assigns the given data to this entity, updating its properties and relations. */ assign = FromEntityType, Convert extends boolean = false, Data extends EntityData | Partial> = EntityData | Partial>>(data: Data & IsSubset, Data>, options?: AssignOptions): MergeSelected; /** Initializes (refreshes) the entity by reloading it from the database. Returns null if not found. */ init(options?: FindOneOptions): Promise | null>; /** Returns the database schema this entity belongs to. */ getSchema(): string | undefined; /** Sets the database schema for this entity. */ setSchema(schema?: string): void; }