@mikro-orm/core
Version:
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.
538 lines (537 loc) • 36.2 kB
TypeScript
import type { EntityManager } from '../EntityManager';
import type { ColumnType, PropertyOptions, ReferenceOptions } from '../decorators/Property';
import type { EnumOptions } from '../decorators/Enum';
import type { EmbeddedOptions, EmbeddedPrefixMode } from '../decorators/Embedded';
import type { ManyToOneOptions } from '../decorators/ManyToOne';
import type { OneToManyOptions } from '../decorators/OneToMany';
import type { OneToOneOptions } from '../decorators/OneToOne';
import type { ManyToManyOptions } from '../decorators/ManyToMany';
import type { AnyString, GeneratedColumnCallback, Constructor, Opt, Hidden, CheckCallback, FilterQuery, EntityName, Dictionary, EntityMetadata } from '../typings';
import type { Reference, ScalarReference } from './Reference';
import type { SerializeOptions } from '../serialization/EntitySerializer';
import type { Cascade, DeferMode, LoadStrategy, QueryOrderMap } from '../enums';
import type { Collection } from './Collection';
import type { IType, Type } from '../types/Type';
import { types } from '../types';
import { EntitySchema } from '../metadata/EntitySchema';
/** @internal */
export declare class PropertyOptionsBuilder<Value> {
'~options': PropertyOptions<any>;
'~type'?: {
value: Value;
};
constructor(options: PropertyOptionsBuilder<Value>['~options']);
/**
* Alias for `fieldName`.
*/
name(name: string): PropertyOptionsBuilder<Value>;
/**
* Specify database column name for this property.
*
* @see https://mikro-orm.io/docs/naming-strategy
*/
fieldName(fieldName: string): PropertyOptionsBuilder<Value>;
/**
* Specify database column names for this property.
* Same as `fieldName` but for composite FKs.
*
* @see https://mikro-orm.io/docs/naming-strategy
*/
fieldNames(...fieldNames: string[]): PropertyOptionsBuilder<Value>;
/**
* Specify an exact database column type for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. This option is only for simple properties represented by a single column. (SQL only)
*/
columnType(columnType: ColumnType | AnyString): PropertyOptionsBuilder<Value>;
/**
* Specify an exact database column type for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. This option is suitable for composite keys, where one property is represented by multiple columns. (SQL only)
*/
columnTypes(...columnTypes: (ColumnType | AnyString)[]): PropertyOptionsBuilder<Value>;
/**
* Explicitly specify the runtime type.
*
* @see https://mikro-orm.io/docs/metadata-providers
* @see https://mikro-orm.io/docs/custom-types
*/
type<TType extends PropertyValueType>(type: TType): PropertyOptionsBuilder<InferPropertyValueType<TType>>;
/**
* Runtime type of the property. This is the JS type that your property is mapped to, e.g. `string` or `number`, and is normally inferred automatically via `reflect-metadata`.
* In some cases, the inference won't work, and you might need to specify the `runtimeType` explicitly - the most common one is when you use a union type with null like `foo: number | null`.
*/
runtimeType(runtimeType: string): PropertyOptionsBuilder<Value>;
/**
* Set length of database column, used for datetime/timestamp/varchar column types for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
*/
length(length: number): PropertyOptionsBuilder<Value>;
/**
* Set precision of database column to represent the number of significant digits. (SQL only)
*/
precision(precision: number): PropertyOptionsBuilder<Value>;
/**
* Set scale of database column to represents the number of digits after the decimal point. (SQL only)
*/
scale(scale: number): PropertyOptionsBuilder<Value>;
/**
* Explicitly specify the auto increment of the primary key.
*/
autoincrement(autoincrement?: boolean): PropertyOptionsBuilder<Value>;
/**
* Add the property to the `returning` statement.
*/
returning(returning?: boolean): PropertyOptionsBuilder<Value>;
/**
* Automatically set the property value when entity gets created, executed during flush operation.
* @param entity
*/
onCreate(onCreate: (entity: any, em: EntityManager) => Value): PropertyOptionsBuilder<Opt<Value>>;
/**
* Automatically update the property value every time entity gets updated, executed during flush operation.
* @param entity
*/
onUpdate(onUpdate: (entity: any, em: EntityManager) => Value): PropertyOptionsBuilder<Value>;
/**
* Specify default column value for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
* This is a runtime value, assignable to the entity property. (SQL only)
*/
default(defaultValue: string | string[] | number | number[] | boolean | null): PropertyOptionsBuilder<Opt<Value>>;
/**
* Specify SQL functions for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
* Since v4 you should use defaultRaw for SQL functions. e.g. now()
*/
defaultRaw(defaultRaw: string): PropertyOptionsBuilder<Value>;
/**
* Set to map some SQL snippet for the entity.
*
* @see https://mikro-orm.io/docs/defining-entities#formulas Formulas
*/
formula(formula: string | ((alias: string) => string)): PropertyOptionsBuilder<Value>;
/**
* For generated columns. This will be appended to the column type after the `generated always` clause.
*/
generated(generated: string | GeneratedColumnCallback<any>): PropertyOptionsBuilder<Value>;
/**
* Set column as nullable for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
*/
nullable<T extends boolean = true>(nullable?: T): PropertyOptionsBuilder<T extends true ? Value extends ScalarReference<infer InnerValue> ? ScalarReference<InnerValue | null> : Value | null | undefined : NonNullable<Value>>;
/**
* Set column as unsigned for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
*/
unsigned(unsigned?: boolean): PropertyOptionsBuilder<Value>;
/**
* Set false to define {@link https://mikro-orm.io/docs/serializing#shadow-properties Shadow Property}.
*/
persist(persist?: boolean): PropertyOptionsBuilder<Value>;
/**
* Set false to disable hydration of this property. Useful for persisted getters.
*/
hydrate(hydrate?: boolean): PropertyOptionsBuilder<Value>;
/**
* Enable `ScalarReference` wrapper for lazy values. Use this in combination with `lazy: true` to have a type-safe accessor object in place of the value.
*/
ref<T extends boolean = true>(ref?: T): PropertyOptionsBuilder<T extends true ? ScalarReference<Value> : UnwrapRef<Value>>;
/**
* Set false to disable change tracking on a property level.
*
* @see https://mikro-orm.io/docs/unit-of-work#change-tracking-and-performance-considerations
*/
trackChanges(trackChanges?: boolean): PropertyOptionsBuilder<Value>;
/**
* Set to true to omit the property when {@link https://mikro-orm.io/docs/serializing Serializing}.
*/
hidden<T extends boolean = true>(hidden?: T): PropertyOptionsBuilder<T extends true ? Hidden<Value> : Value>;
/**
* Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via version field. (SQL only)
*/
version(version?: boolean): PropertyOptionsBuilder<Value>;
/**
* Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via concurrency fields.
*/
concurrencyCheck(concurrencyCheck?: boolean): PropertyOptionsBuilder<Value>;
/**
* Explicitly specify index on a property.
*/
index(index?: boolean | string): PropertyOptionsBuilder<Value>;
/**
* Set column as unique for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
*/
unique(unique?: boolean | string): PropertyOptionsBuilder<Value>;
/**
* Specify column with check constraints. (Postgres driver only)
*
* @see https://mikro-orm.io/docs/defining-entities#check-constraints
*/
check(check: string | CheckCallback<any>): PropertyOptionsBuilder<Value>;
/**
* Set to omit the property from the select clause for lazy loading.
*
* @see https://mikro-orm.io/docs/defining-entities#lazy-scalar-properties
*/
lazy<T extends boolean = true>(lazy?: boolean, ref?: T): PropertyOptionsBuilder<T extends true ? ScalarReference<Value> : UnwrapRef<Value>>;
/**
* Set true to define entity's unique primary key identifier.
*
* @see https://mikro-orm.io/docs/decorators#primarykey
*/
primary(primary?: boolean): PropertyOptionsBuilder<Value>;
/**
* Set true to define the properties as setter. (virtual)
*
* @example
* ```
* @Property({ setter: true })
* set address(value: string) {
* this._address = value.toLocaleLowerCase();
* }
* ```
*/
setter(setter?: boolean): PropertyOptionsBuilder<Value>;
/**
* Set true to define the properties as getter. (virtual)
*
* @example
* ```
* @Property({ getter: true })
* get fullName() {
* return this.firstName + this.lastName;
* }
* ```
*/
getter(getter?: boolean): PropertyOptionsBuilder<Value>;
/**
* When defining a property over a method (not a getter, a regular function), you can use this option to point
* to the method name.
*
* @example
* ```
* @Property({ getter: true })
* getFullName() {
* return this.firstName + this.lastName;
* }
* ```
*/
getterName(getterName: string): PropertyOptionsBuilder<Value>;
/**
* Set to define serialized primary key for MongoDB. (virtual)
* Alias for `@SerializedPrimaryKey()` decorator.
*
* @see https://mikro-orm.io/docs/decorators#serializedprimarykey
*/
serializedPrimaryKey(serializedPrimaryKey?: boolean): PropertyOptionsBuilder<Value>;
/**
* Set to use serialize property. Allow to specify a callback that will be used when serializing a property.
*
* @see https://mikro-orm.io/docs/serializing#property-serializers
*/
serializer(serializer: (value: Value, options?: SerializeOptions<any>) => any): PropertyOptionsBuilder<Value>;
/**
* Specify name of key for the serialized value.
*/
serializedName(serializedName: string): PropertyOptionsBuilder<Value>;
/**
* Specify serialization groups for `serialize()` calls. If a property does not specify any group, it will be included,
* otherwise only properties with a matching group are included.
*/
groups(...groups: string[]): PropertyOptionsBuilder<Value>;
/**
* Specify a custom order based on the values. (SQL only)
*/
customOrder(...customOrder: (string[] | number[] | boolean[])): PropertyOptionsBuilder<Value>;
/**
* Specify comment of column for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
*/
comment(comment: string): PropertyOptionsBuilder<Value>;
/** mysql only */
extra(extra: string): PropertyOptionsBuilder<Value>;
/**
* Set to avoid a perpetual diff from the {@link https://mikro-orm.io/docs/schema-generator Schema Generator} when columns are generated.
*
* @see https://mikro-orm.io/docs/defining-entities#sql-generated-columns
*/
ignoreSchemaChanges(...ignoreSchemaChanges: ('type' | 'extra' | 'default')[]): PropertyOptionsBuilder<Value>;
/**
* Set the TypeScript type of the property.
*/
$type<T>(): PropertyOptionsBuilder<T>;
/**
* Set the TypeScript type for custom types that map to objects.
* This method provides type safety for custom types by specifying the runtime type,
* raw database value type, and optional serialized type.
*
* @template Runtime - The runtime type that the property will have in JavaScript
* @template Raw - The raw value type as stored in the database
* @template Serialized - The type when serialized (defaults to Raw)
* @returns PropertyOptionsBuilder with IType wrapper for type safety
*/
$type<Runtime, Raw, Serialized = Raw>(): PropertyOptionsBuilder<IType<Runtime, Raw, Serialized>>;
}
/** @internal */
export declare class EnumOptionsBuilder<Value> extends PropertyOptionsBuilder<Value> {
'~options': {
enum: true;
} & EnumOptions<any>;
constructor(options: EnumOptionsBuilder<Value>['~options']);
array<T extends boolean = true>(array?: T): EnumOptionsBuilder<T extends true ? Value[] : UnwrapArray<Value>>;
/** for postgres, by default it uses text column with check constraint */
nativeEnumName(nativeEnumName: string): EnumOptionsBuilder<Value>;
}
/** @internal */
export declare class EmbeddedOptionsBuilder<Value> extends PropertyOptionsBuilder<Value> {
'~options': ({
kind: 'embedded';
entity: () => EntitySchema<any, any> | EntitySchema<any, any>[];
} & EmbeddedOptions<any, any> & PropertyOptions<any>);
constructor(options: EmbeddedOptionsBuilder<Value>['~options']);
prefix(prefix: string): EmbeddedOptionsBuilder<Value>;
prefixMode(prefixMode: EmbeddedPrefixMode): EmbeddedOptionsBuilder<Value>;
object(object?: boolean): EmbeddedOptionsBuilder<Value>;
array<T extends boolean = true>(array?: T): EmbeddedOptionsBuilder<T extends true ? Value[] : UnwrapArray<Value>>;
}
/** @internal */
export declare class ReferenceOptionsBuilder<Value extends object> extends PropertyOptionsBuilder<Value> {
'~options': ReferenceOptions<any, any>;
constructor(options: ReferenceOptionsBuilder<Value>['~options']);
/** Set what actions on owning entity should be cascaded to the relationship. Defaults to [Cascade.PERSIST, Cascade.MERGE] (see {@doclink cascading}). */
cascade(...cascade: Cascade[]): ReferenceOptionsBuilder<Value>;
/** Always load the relationship. Discouraged for use with to-many relations for performance reasons. */
eager(eager?: boolean): ReferenceOptionsBuilder<Value>;
/** Override the default loading strategy for this property. This option has precedence over the global `loadStrategy`, but can be overridden by `FindOptions.strategy`. */
strategy(strategy: LoadStrategy | `${LoadStrategy}`): ReferenceOptionsBuilder<Value>;
/**
* @internal
* re-declare to override type inference
*/
ref(ref?: boolean): ReferenceOptionsBuilder<any>;
/**
* @internal
* re-declare to override type inference
*/
primary(primary?: boolean): ReferenceOptionsBuilder<any>;
}
/** @internal */
export declare class ManyToManyOptionsBuilder<TargetValue extends object> extends ReferenceOptionsBuilder<TargetValue> {
'~options': ({
kind: 'm:n';
entity: () => EntitySchema<any, any>;
} & ManyToManyOptions<any, UnwrapCollection<TargetValue>>);
constructor(options: ManyToManyOptionsBuilder<TargetValue>['~options']);
/** Set this side as owning. Owning side is where the foreign key is defined. This option is not required if you use `inversedBy` or `mappedBy` to distinguish owning and inverse side. */
owner(owner?: boolean): ManyToManyOptionsBuilder<TargetValue>;
/** Point to the inverse side property name. */
inversedBy(inversedBy: (string & keyof UnwrapCollection<TargetValue>) | ((e: UnwrapCollection<TargetValue>) => any)): ManyToManyOptionsBuilder<TargetValue>;
/** Point to the owning side property name. */
mappedBy(mappedBy: string | ((e: any) => any)): ManyToManyOptionsBuilder<TargetValue>;
/** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
where(...where: FilterQuery<object>[]): ManyToManyOptionsBuilder<TargetValue>;
/** Set default ordering. */
orderBy(...orderBy: QueryOrderMap<object>[]): ManyToManyOptionsBuilder<TargetValue>;
/** Force stable insertion order of items in the collection (see {@doclink collections | Collections}). */
fixedOrder(fixedOrder?: boolean): ManyToManyOptionsBuilder<TargetValue>;
/** Override default order column name (`id`) for fixed ordering. */
fixedOrderColumn(fixedOrderColumn: string): ManyToManyOptionsBuilder<TargetValue>;
/** Override default name for pivot table (see {@doclink naming-strategy | Naming Strategy}). */
pivotTable(pivotTable: string): ManyToManyOptionsBuilder<TargetValue>;
/** Set pivot entity for this relation (see {@doclink collections#custom-pivot-table-entity | Custom pivot table entity}). */
pivotEntity(pivotEntity: string | (() => EntityName<any>)): ManyToManyOptionsBuilder<TargetValue>;
/** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
joinColumn(joinColumn: string): ManyToManyOptionsBuilder<TargetValue>;
/** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
joinColumns(...joinColumns: string[]): ManyToManyOptionsBuilder<TargetValue>;
/** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
inverseJoinColumn(inverseJoinColumn: string): ManyToManyOptionsBuilder<TargetValue>;
/** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
inverseJoinColumns(...inverseJoinColumns: string[]): ManyToManyOptionsBuilder<TargetValue>;
/** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
referenceColumnName(referenceColumnName: string): ManyToManyOptionsBuilder<TargetValue>;
/** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
referencedColumnNames(...referencedColumnNames: string[]): ManyToManyOptionsBuilder<TargetValue>;
/** What to do when the target entity gets deleted. */
deleteRule(deleteRule: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString): ManyToManyOptionsBuilder<TargetValue>;
/** What to do when the reference to the target entity gets updated. */
updateRule(updateRule: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString): ManyToManyOptionsBuilder<TargetValue>;
}
/** @internal */
export declare class ManyToOneOptionsBuilder<TargetValue extends object> extends ReferenceOptionsBuilder<TargetValue> {
'~options': ({
kind: 'm:1';
entity: () => EntitySchema<any, any>;
} & ManyToOneOptions<any, UnwrapRef<TargetValue>>);
constructor(options: ManyToOneOptionsBuilder<TargetValue>['~options']);
/** Point to the inverse side property name. */
inversedBy(inversedBy: (string & keyof UnwrapRef<TargetValue>) | ((e: UnwrapRef<TargetValue>) => any)): ManyToOneOptionsBuilder<TargetValue>;
/** Wrap the entity in {@apilink Reference} wrapper. */
ref<T extends boolean = true>(ref?: T): ManyToOneOptionsBuilder<T extends true ? Reference<TargetValue> : UnwrapRef<TargetValue>>;
/** Use this relation as a primary key. */
primary(primary?: boolean): ManyToOneOptionsBuilder<TargetValue>;
/** Map this relation to the primary key value instead of an entity. */
mapToPk(mapToPk?: boolean): ManyToOneOptionsBuilder<TargetValue>;
/** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
joinColumn(joinColumn: string): ManyToOneOptionsBuilder<TargetValue>;
/** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
joinColumns(...joinColumns: string[]): ManyToOneOptionsBuilder<TargetValue>;
/** When a part of a composite column is shared in other properties, use this option to specify what columns are considered as owned by this property. This is useful when your composite property is nullable, but parts of it are not. */
ownColumns(...ownColumns: string[]): ManyToOneOptionsBuilder<TargetValue>;
/** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
referenceColumnName(referenceColumnName: string): ManyToOneOptionsBuilder<TargetValue>;
/** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
referencedColumnNames(...referencedColumnNames: string[]): ManyToOneOptionsBuilder<TargetValue>;
/** What to do when the target entity gets deleted. */
deleteRule(deleteRule: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString): ManyToOneOptionsBuilder<TargetValue>;
/** What to do when the reference to the target entity gets updated. */
updateRule(updateRule: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString): ManyToOneOptionsBuilder<TargetValue>;
/** Set the constraint type. Immediate constraints are checked for each statement, while deferred ones are only checked at the end of the transaction. Only for postgres unique constraints. */
deferMode(deferMode: DeferMode | `${DeferMode}`): ManyToOneOptionsBuilder<TargetValue>;
}
/** @internal */
export declare class OneToManyOptionsBuilder<TargetValue extends object> extends ReferenceOptionsBuilder<TargetValue> {
'~options': ({
kind: '1:m';
entity: () => EntitySchema<TargetValue>;
} & OneToManyOptions<any, UnwrapCollection<TargetValue>>);
constructor(options: OneToManyOptionsBuilder<TargetValue>['~options']);
/** Remove the entity when it gets disconnected from the relationship (see {@doclink cascading | Cascading}). */
orphanRemoval(orphanRemoval?: boolean): OneToManyOptionsBuilder<TargetValue>;
/** Set default ordering. */
orderBy(orderBy: QueryOrderMap<UnwrapCollection<TargetValue>> | QueryOrderMap<UnwrapCollection<TargetValue>>[]): OneToManyOptionsBuilder<TargetValue>;
/** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
where(where: FilterQuery<UnwrapCollection<TargetValue>>): OneToManyOptionsBuilder<TargetValue>;
/** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
joinColumn(joinColumn: string): OneToManyOptionsBuilder<TargetValue>;
/** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
joinColumns(...joinColumns: string[]): OneToManyOptionsBuilder<TargetValue>;
/** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
inverseJoinColumn(inverseJoinColumn: string): OneToManyOptionsBuilder<TargetValue>;
/** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
inverseJoinColumns(...inverseJoinColumns: string[]): OneToManyOptionsBuilder<TargetValue>;
/** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
referenceColumnName(referenceColumnName: string): OneToManyOptionsBuilder<TargetValue>;
/** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
referencedColumnNames(...referencedColumnNames: string[]): OneToManyOptionsBuilder<TargetValue>;
}
/** @internal */
export declare class OneToManyOptionsBuilderOnlyMappedBy<TargetValue extends object> {
'~options': ({
kind: '1:m';
entity: () => EntitySchema<TargetValue>;
} & Omit<OneToManyOptions<any, UnwrapCollection<TargetValue>>, 'mappedBy'>);
constructor(options: OneToManyOptionsBuilderOnlyMappedBy<TargetValue>['~options']);
/** Point to the owning side property name. */
mappedBy(mappedBy: (AnyString & keyof UnwrapCollection<TargetValue>) | ((e: UnwrapCollection<TargetValue>) => any)): OneToManyOptionsBuilder<TargetValue>;
}
/** @internal */
export declare class OneToOneOptionsBuilder<TargetValue extends object> extends ReferenceOptionsBuilder<TargetValue> {
'~options': ({
kind: '1:1';
entity: () => EntitySchema<any, any>;
} & OneToOneOptions<any, UnwrapRef<TargetValue>>);
constructor(options: OneToOneOptionsBuilder<TargetValue>['~options']);
/** Set this side as owning. Owning side is where the foreign key is defined. This option is not required if you use `inversedBy` or `mappedBy` to distinguish owning and inverse side. */
owner(owner?: boolean): OneToOneOptionsBuilder<TargetValue>;
/** Point to the inverse side property name. */
inversedBy(inversedBy: (string & keyof UnwrapRef<TargetValue>) | ((e: UnwrapRef<TargetValue>) => any)): OneToOneOptionsBuilder<TargetValue>;
/** Wrap the entity in {@apilink Reference} wrapper. */
ref<T extends boolean = true>(ref?: T): OneToOneOptionsBuilder<T extends true ? Reference<TargetValue> : UnwrapRef<TargetValue>>;
/** Use this relation as a primary key. */
primary(primary?: boolean): OneToOneOptionsBuilder<TargetValue>;
/** Map this relation to the primary key value instead of an entity. */
mapToPk(mapToPk?: boolean): OneToOneOptionsBuilder<TargetValue>;
/** When a part of a composite column is shared in other properties, use this option to specify what columns are considered as owned by this property. This is useful when your composite property is nullable, but parts of it are not. */
ownColumns(...ownColumns: string[]): OneToOneOptionsBuilder<TargetValue>;
/** What to do when the target entity gets deleted. */
deleteRule(deleteRule: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString): OneToOneOptionsBuilder<TargetValue>;
/** What to do when the reference to the target entity gets updated. */
updateRule(updateRule: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString): OneToOneOptionsBuilder<TargetValue>;
/** Set the constraint type. Immediate constraints are checked for each statement, while deferred ones are only checked at the end of the transaction. Only for postgres unique constraints. */
deferMode(deferMode: DeferMode | `${DeferMode}`): OneToOneOptionsBuilder<TargetValue>;
}
declare const propertyBuilders: {
json: <T>() => PropertyOptionsBuilder<T>;
formula: <T>(formula: string | ((alias: string) => string)) => PropertyOptionsBuilder<T>;
type: <T extends PropertyValueType>(type: T) => PropertyOptionsBuilder<InferPropertyValueType<T>>;
enum: <const T extends (number | string)[] | (() => Dictionary)>(items?: T) => EnumOptionsBuilder<T extends () => Dictionary ? ValueOf<ReturnType<T>> : T extends (infer Value)[] ? Value : T>;
embedded: <Target extends EntitySchema<any, any> | EntitySchema<any, any>[]>(target: Target) => EmbeddedOptionsBuilder<InferEntity<Target extends (infer T)[] ? T : Target>>;
manyToMany: <Target extends EntitySchema<any, any>>(target: Target) => ManyToManyOptionsBuilder<Collection<InferEntity<Target>, object>>;
manyToOne: <Target extends EntitySchema<any, any>>(target: Target) => ManyToOneOptionsBuilder<Reference<InferEntity<Target>>>;
oneToMany: <Target extends EntitySchema<any, any>>(target: Target) => OneToManyOptionsBuilderOnlyMappedBy<Collection<InferEntity<Target>, object>>;
oneToOne: <Target extends EntitySchema<any, any>>(target: Target) => OneToOneOptionsBuilder<Reference<InferEntity<Target>>>;
date: () => PropertyOptionsBuilder<string>;
time: () => PropertyOptionsBuilder<any>;
datetime: () => PropertyOptionsBuilder<Date>;
bigint: () => PropertyOptionsBuilder<NonNullable<string | number | bigint | null | undefined>>;
blob: () => PropertyOptionsBuilder<NonNullable<Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike> | null>>;
uint8array: () => PropertyOptionsBuilder<Uint8Array<ArrayBufferLike>>;
array: () => PropertyOptionsBuilder<unknown[]>;
enumArray: () => PropertyOptionsBuilder<(string | number)[]>;
integer: () => PropertyOptionsBuilder<number>;
smallint: () => PropertyOptionsBuilder<number>;
tinyint: () => PropertyOptionsBuilder<number>;
mediumint: () => PropertyOptionsBuilder<number>;
float: () => PropertyOptionsBuilder<number>;
double: () => PropertyOptionsBuilder<NonNullable<string | number>>;
boolean: () => PropertyOptionsBuilder<NonNullable<boolean | null | undefined>>;
decimal: () => PropertyOptionsBuilder<NonNullable<string | number>>;
character: () => PropertyOptionsBuilder<string>;
string: () => PropertyOptionsBuilder<string>;
uuid: () => PropertyOptionsBuilder<string>;
text: () => PropertyOptionsBuilder<string>;
interval: () => PropertyOptionsBuilder<string>;
unknown: () => PropertyOptionsBuilder<{}>;
};
export declare function defineEntity<Properties extends Record<string, any>>(meta: Omit<Partial<EntityMetadata<InferEntityFromProperties<Properties>>>, 'properties' | 'extends'> & {
name: string;
properties: Properties | ((properties: typeof propertyBuilders) => Properties);
}): EntitySchema<InferEntityFromProperties<Properties>, never>;
export declare namespace defineEntity {
var properties: {
json: <T>() => PropertyOptionsBuilder<T>;
formula: <T>(formula: string | ((alias: string) => string)) => PropertyOptionsBuilder<T>;
type: <T extends PropertyValueType>(type: T) => PropertyOptionsBuilder<InferPropertyValueType<T>>;
enum: <const T extends (number | string)[] | (() => Dictionary)>(items?: T) => EnumOptionsBuilder<T extends () => Dictionary ? ValueOf<ReturnType<T>> : T extends (infer Value)[] ? Value : T>;
embedded: <Target extends EntitySchema<any, any> | EntitySchema<any, any>[]>(target: Target) => EmbeddedOptionsBuilder<InferEntity<Target extends (infer T)[] ? T : Target>>;
manyToMany: <Target extends EntitySchema<any, any>>(target: Target) => ManyToManyOptionsBuilder<Collection<InferEntity<Target>, object>>;
manyToOne: <Target extends EntitySchema<any, any>>(target: Target) => ManyToOneOptionsBuilder<Reference<InferEntity<Target>>>;
oneToMany: <Target extends EntitySchema<any, any>>(target: Target) => OneToManyOptionsBuilderOnlyMappedBy<Collection<InferEntity<Target>, object>>;
oneToOne: <Target extends EntitySchema<any, any>>(target: Target) => OneToOneOptionsBuilder<Reference<InferEntity<Target>>>;
date: () => PropertyOptionsBuilder<string>;
time: () => PropertyOptionsBuilder<any>;
datetime: () => PropertyOptionsBuilder<Date>;
bigint: () => PropertyOptionsBuilder<NonNullable<string | number | bigint | null | undefined>>;
blob: () => PropertyOptionsBuilder<NonNullable<Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike> | null>>;
uint8array: () => PropertyOptionsBuilder<Uint8Array<ArrayBufferLike>>;
array: () => PropertyOptionsBuilder<unknown[]>;
enumArray: () => PropertyOptionsBuilder<(string | number)[]>;
integer: () => PropertyOptionsBuilder<number>;
smallint: () => PropertyOptionsBuilder<number>;
tinyint: () => PropertyOptionsBuilder<number>;
mediumint: () => PropertyOptionsBuilder<number>;
float: () => PropertyOptionsBuilder<number>;
double: () => PropertyOptionsBuilder<NonNullable<string | number>>;
boolean: () => PropertyOptionsBuilder<NonNullable<boolean | null | undefined>>;
decimal: () => PropertyOptionsBuilder<NonNullable<string | number>>;
character: () => PropertyOptionsBuilder<string>;
string: () => PropertyOptionsBuilder<string>;
uuid: () => PropertyOptionsBuilder<string>;
text: () => PropertyOptionsBuilder<string>;
interval: () => PropertyOptionsBuilder<string>;
unknown: () => PropertyOptionsBuilder<{}>;
};
}
type PropertyValueType = PropertyOptions<any>['type'];
type InferPropertyValueType<T extends PropertyValueType> = T extends string ? InferTypeByString<T> : T extends NumberConstructor ? number : T extends StringConstructor ? string : T extends BooleanConstructor ? boolean : T extends DateConstructor ? Date : T extends ArrayConstructor ? string[] : T extends Constructor<infer TType> ? TType extends Type<infer TValue, any> ? NonNullable<TValue> : TType : T extends Type<infer TValue, any> ? NonNullable<TValue> : any;
type InferTypeByString<T extends string> = T extends keyof typeof types ? InferJSType<typeof types[T]> : InferColumnType<T>;
type InferJSType<T> = T extends typeof Type<infer TValue, any> ? NonNullable<TValue> : never;
type InferColumnType<T extends string> = T extends 'int' | 'int4' | 'integer' | 'bigint' | 'int8' | 'int2' | 'tinyint' | 'smallint' | 'mediumint' ? number : T extends 'double' | 'double precision' | 'real' | 'float8' | 'decimal' | 'numeric' | 'float' | 'float4' ? number : T extends 'datetime' | 'time' | 'time with time zone' | 'timestamp' | 'timestamp with time zone' | 'timetz' | 'timestamptz' | 'date' | 'interval' ? Date : T extends 'ObjectId' | 'objectId' | 'character varying' | 'varchar' | 'char' | 'character' | 'uuid' | 'text' | 'tinytext' | 'mediumtext' | 'longtext' | 'enum' ? string : T extends 'boolean' | 'bool' | 'bit' ? boolean : T extends 'blob' | 'tinyblob' | 'mediumblob' | 'longblob' | 'bytea' ? Buffer : T extends 'point' | 'line' | 'lseg' | 'box' | 'circle' | 'path' | 'polygon' | 'geometry' ? number[] : T extends 'tsvector' | 'tsquery' ? string[] : T extends 'json' | 'jsonb' ? any : any;
export type InferEntityFromProperties<Properties extends Record<string, any>> = {
-readonly [K in keyof Properties]: Properties[K] extends (() => any) ? InferBuilderValue<ReturnType<Properties[K]>> : InferBuilderValue<Properties[K]>;
};
type InferBuilderValue<Builder> = Builder extends {
'~type'?: {
value: infer T;
};
} ? T : never;
type UnwrapRef<T> = T extends ScalarReference<any> ? UnwrapScalarReference<T> : T extends Reference<any> ? UnwrapReference<T> : T;
type UnwrapScalarReference<T extends ScalarReference<any>> = T extends ScalarReference<infer Value> ? Value : T;
type UnwrapReference<T extends Reference<any>> = T extends Reference<infer Value> ? Value : T;
type UnwrapCollection<T> = T extends Collection<infer Value> ? Value : T;
type UnwrapArray<T> = T extends (infer Value)[] ? Value : T;
type ValueOf<T extends Dictionary> = T[keyof T];
export type InferEntity<Schema> = Schema extends EntitySchema<infer Entity, any> ? Entity : never;
export {};