import { CheckConstraint, DMLSchema, EntityCascades, EntityIndex, ExtractEntityRelations, IDmlEntity, IDmlEntityConfig, InferDmlEntityNameFromConfig, QueryCondition } from "@medusajs/types"; import { DMLSchemaWithBigNumber } from "./helpers/entity-builder/create-big-number-properties"; import { DMLSchemaDefaults } from "./helpers/entity-builder/create-default-properties"; declare const IsDmlEntity: unique symbol; /** * Represents an entity with translatable properties */ export type TranslatableEntityEntry = { /** * The entity name (PascalCase) */ entity: string; /** * The list of translatable property names */ fields: string[]; }; export type DMLEntitySchemaBuilder = DMLSchemaWithBigNumber & DMLSchemaDefaults & Schema; /** * Dml entity is a representation of a DML model with a unique * name, its schema and relationships. */ export declare class DmlEntity implements IDmlEntity { #private; [IsDmlEntity]: boolean; name: InferDmlEntityNameFromConfig; schema: Schema; constructor(nameOrConfig: TConfig, schema: Schema); /** * A static method to check if an entity is an instance of DmlEntity. * It allows us to identify a specific object as being an instance of * DmlEntity. * * @param entity */ static isDmlEntity(entity: unknown): entity is DmlEntity; /** * Returns all registered translatable entities with their translatable fields. * Each entry contains the entity name (PascalCase) and an array * of field names that are marked as translatable. * * @example * import { DmlEntity } from "@medusajs/framework/utils" * * const translatables = DmlEntity.getTranslatableEntities() * // Returns: [{ entity: "Store", fields: ["name"] }] * * @customNamespace Model Methods */ static getTranslatableEntities(): TranslatableEntityEntry[]; /** * Clears all registered translatable entities. * This is primarily used for testing purposes. */ static clearTranslatableEntities(): void; /** * Parse entity to get its underlying information */ parse(): { name: InferDmlEntityNameFromConfig; tableName: string; schema: DMLSchema; cascades: EntityCascades; indexes: EntityIndex[]; checks: CheckConstraint[]; }; /** * This method configures which related data models an operation, such as deletion, * should be cascaded to. * * For example, if a store is deleted, its product should also be deleted. * * @param options - The cascades configurations. They object's keys are the names of * the actions, such as `deleted`, and the value is an array of relations that the * action should be cascaded to. * * @example * import { model } from "@medusajs/framework/utils" * * const Store = model.define("store", { * id: model.id(), * products: model.hasMany(() => Product), * }) * .cascades({ * delete: ["products"], * }) * * @customNamespace Model Methods */ cascades(options: EntityCascades, ExtractEntityRelations>): this; /** * This method defines indices on the data model. An index can be on multiple columns * and have conditions. * * @param indexes - The index's configuration. * * @example * An example of a simple index: * * ```ts * import { model } from "@medusajs/framework/utils" * * const MyCustom = model.define("my_custom", { * id: model.id(), * name: model.text(), * age: model.number() * }).indexes([ * { * on: ["name", "age"], * }, * ]) * * export default MyCustom * ``` * * To add a condition on the index, use the `where` option: * * ```ts * import { model } from "@medusajs/framework/utils" * * const MyCustom = model.define("my_custom", { * id: model.id(), * name: model.text(), * age: model.number() * }).indexes([ * { * on: ["name", "age"], * where: { * age: 30 * } * }, * ]) * * export default MyCustom * ``` * * The condition can also be a negation. For example: * * ```ts * import { model } from "@medusajs/framework/utils" * * const MyCustom = model.define("my_custom", { * id: model.id(), * name: model.text(), * age: model.number() * }).indexes([ * { * on: ["name", "age"], * where: { * age: { * $ne: 30 * } * } * }, * ]) * * export default MyCustom * ``` * * In this example, the index is created when the value of `age` doesn't equal `30`. * * @customNamespace Model Methods */ indexes(indexes: EntityIndex>[]): this; checks(checks: CheckConstraint[]): this; } export {}; //# sourceMappingURL=entity.d.ts.map