lakutata
Version:
An IoC-based universal application framework.
1,491 lines (1,480 loc) • 60.5 kB
TypeScript
import './TypeDef.internal.30.js';
import { SelectQueryBuilder } from './TypeDef.internal.38.js';
import { RelationMetadataArgs, RelationIdMetadataArgs, RelationCountMetadataArgs, EntityListenerMetadataArgs, UniqueMetadataArgs, EmbeddedMetadataArgs, ColumnMetadataArgs, CheckMetadataArgs, ExclusionMetadataArgs, TableMetadataArgs, TreeMetadataArgs, IndexMetadataArgs } from './TypeDef.internal.32.js';
import { OrderByCondition } from './TypeDef.internal.74.js';
import { OnDeleteType, OnUpdateType, DeferrableType, RelationType, PropertyTypeFactory, EventListenerType, TableType, TreeType, ClosureTreeOptions } from './TypeDef.internal.73.js';
import { QueryRunner } from './TypeDef.internal.40.js';
import { NamingStrategyInterface } from './TypeDef.internal.43.js';
import { ColumnType } from './TypeDef.internal.44.js';
import { ObjectLiteral } from './TypeDef.internal.36.js';
import { DataSource } from './TypeDef.internal.33.js';
import { ValueTransformer } from './TypeDef.internal.68.js';
/**
* Contains all information about entity's foreign key.
*/
declare class ForeignKeyMetadata {
/**
* Entity metadata where this foreign key is.
*/
entityMetadata: EntityMetadata;
/**
* Entity metadata which this foreign key references.
*/
referencedEntityMetadata: EntityMetadata;
/**
* Array of columns of this foreign key.
*/
columns: ColumnMetadata[];
/**
* Array of referenced columns.
*/
referencedColumns: ColumnMetadata[];
/**
* What to do with a relation on deletion of the row containing a foreign key.
*/
onDelete?: OnDeleteType;
/**
* What to do with a relation on update of the row containing a foreign key.
*/
onUpdate?: OnUpdateType;
/**
* When to check the constraints of a foreign key.
*/
deferrable?: DeferrableType;
/**
* Gets the table name to which this foreign key is referenced.
*/
referencedTablePath: string;
/**
* Gets foreign key name.
* If unique constraint name was given by a user then it stores givenName.
* If unique constraint name was not given then its generated.
*/
name: string;
/**
* Gets array of column names.
*/
columnNames: string[];
/**
* Gets array of referenced column names.
*/
referencedColumnNames: string[];
/**
* User specified unique constraint name.
*/
givenName?: string;
constructor(options: {
entityMetadata: EntityMetadata;
referencedEntityMetadata: EntityMetadata;
namingStrategy?: NamingStrategyInterface;
columns: ColumnMetadata[];
referencedColumns: ColumnMetadata[];
onDelete?: OnDeleteType;
onUpdate?: OnUpdateType;
deferrable?: DeferrableType;
name?: string;
});
/**
* Builds some depend foreign key properties.
* Must be called after all entity metadatas and their columns are built.
*/
build(namingStrategy: NamingStrategyInterface): void;
}
/**
* Contains all information about some entity's relation.
*/
declare class RelationMetadata {
/**
* Entity metadata of the entity where this relation is placed.
*
* For example for @ManyToMany(type => Category) in Post, entityMetadata will be metadata of Post entity.
*/
entityMetadata: EntityMetadata;
/**
* Entity metadata of the entity that is targeted by this relation.
*
* For example for @ManyToMany(type => Category) in Post, inverseEntityMetadata will be metadata of Category entity.
*/
inverseEntityMetadata: EntityMetadata;
/**
* Entity metadata of the junction table.
* Junction tables have their own entity metadata objects.
* Defined only for many-to-many relations.
*/
junctionEntityMetadata?: EntityMetadata;
/**
* Embedded metadata where this relation is.
* If this relation is not in embed then this property value is undefined.
*/
embeddedMetadata?: EmbeddedMetadata;
/**
* Relation type, e.g. is it one-to-one, one-to-many, many-to-one or many-to-many.
*/
relationType: RelationType;
/**
* Target entity to which this relation is applied.
* Target IS NOT equal to entityMetadata.target, because relation
*
* For example for @ManyToMany(type => Category) in Post, target will be Post.
* If @ManyToMany(type => Category) is in Counters which is embedded into Post, target will be Counters.
* If @ManyToMany(type => Category) is in abstract class BaseUser which Post extends, target will be BaseUser.
* Target can be string if its defined in entity schema instead of class.
*/
target: Function | string;
/**
* Target's property name to which relation decorator is applied.
*/
propertyName: string;
/**
* Gets full path to this column property (including relation name).
* Full path is relevant when column is used in embeds (one or multiple nested).
* For example it will return "counters.subcounters.likes".
* If property is not in embeds then it returns just property name of the column.
*/
propertyPath: string;
/**
* Indicates if this is a parent (can be only many-to-one relation) relation in the tree tables.
*/
isTreeParent: boolean;
/**
* Indicates if this is a children (can be only one-to-many relation) relation in the tree tables.
*/
isTreeChildren: boolean;
/**
* Indicates if this relation's column is a primary key.
* Can be used only for many-to-one and owner one-to-one relations.
*/
isPrimary: boolean;
/**
* Indicates if this relation is lazily loaded.
*/
isLazy: boolean;
/**
* Indicates if this relation is eagerly loaded.
*/
isEager: boolean;
/**
* Indicates if persistence is enabled for the relation.
* By default its enabled, but if you want to avoid any changes in the relation to be reflected in the database you can disable it.
* If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.
* This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.
*/
persistenceEnabled: boolean;
/**
* When a parent is saved (with cascading but) without a child row that still exists in database, this will control what shall happen to them.
* delete will remove these rows from database. nullify will remove the relation key.
* skip will keep the relation intact. Removal of related item is only possible through its own repo.
*/
orphanedRowAction?: "nullify" | "delete" | "soft-delete" | "disable";
/**
* If set to true then related objects are allowed to be inserted to the database.
*/
isCascadeInsert: boolean;
/**
* If set to true then related objects are allowed to be updated in the database.
*/
isCascadeUpdate: boolean;
/**
* If set to true then related objects are allowed to be remove from the database.
*/
isCascadeRemove: boolean;
/**
* If set to true then related objects are allowed to be soft-removed from the database.
*/
isCascadeSoftRemove: boolean;
/**
* If set to true then related objects are allowed to be recovered from the database.
*/
isCascadeRecover: boolean;
/**
* Indicates if relation column value can be nullable or not.
*/
isNullable: boolean;
/**
* What to do with a relation on deletion of the row containing a foreign key.
*/
onDelete?: OnDeleteType;
/**
* What to do with a relation on update of the row containing a foreign key.
*/
onUpdate?: OnUpdateType;
/**
* What to do with a relation on update of the row containing a foreign key.
*/
deferrable?: DeferrableType;
/**
* Indicates whether foreign key constraints will be created for join columns.
* Can be used only for many-to-one and owner one-to-one relations.
* Defaults to true.
*/
createForeignKeyConstraints: boolean;
/**
* Gets the property's type to which this relation is applied.
*
* For example for @ManyToMany(type => Category) in Post, target will be Category.
*/
type: Function | string;
/**
* Indicates if this side is an owner of this relation.
*/
isOwning: boolean;
/**
* Checks if this relation's type is "one-to-one".
*/
isOneToOne: boolean;
/**
* Checks if this relation is owner side of the "one-to-one" relation.
* Owner side means this side of relation has a join column in the table.
*/
isOneToOneOwner: boolean;
/**
* Checks if this relation has a join column (e.g. is it many-to-one or one-to-one owner side).
*/
isWithJoinColumn: boolean;
/**
* Checks if this relation is NOT owner side of the "one-to-one" relation.
* NOT owner side means this side of relation does not have a join column in the table.
*/
isOneToOneNotOwner: boolean;
/**
* Checks if this relation's type is "one-to-many".
*/
isOneToMany: boolean;
/**
* Checks if this relation's type is "many-to-one".
*/
isManyToOne: boolean;
/**
* Checks if this relation's type is "many-to-many".
*/
isManyToMany: boolean;
/**
* Checks if this relation's type is "many-to-many", and is owner side of the relationship.
* Owner side means this side of relation has a join table.
*/
isManyToManyOwner: boolean;
/**
* Checks if this relation's type is "many-to-many", and is NOT owner side of the relationship.
* Not owner side means this side of relation does not have a join table.
*/
isManyToManyNotOwner: boolean;
/**
* Gets the property path of the inverse side of the relation.
*/
inverseSidePropertyPath: string;
/**
* Inverse side of the relation set by user.
*
* Inverse side set in the relation can be either string - property name of the column on inverse side,
* either can be a function that accepts a map of properties with the object and returns one of them.
* Second approach is used to achieve type-safety.
*/
givenInverseSidePropertyFactory: PropertyTypeFactory<any>;
/**
* Gets the relation metadata of the inverse side of this relation.
*/
inverseRelation?: RelationMetadata;
/**
* Join table name.
*/
joinTableName: string;
/**
* Foreign keys created for this relation.
*/
foreignKeys: ForeignKeyMetadata[];
/**
* Join table columns.
* Join columns can be obtained only from owner side of the relation.
* From non-owner side of the relation join columns will be empty.
* If this relation is a many-to-one/one-to-one then it takes join columns from the current entity.
* If this relation is many-to-many then it takes all owner join columns from the junction entity.
*/
joinColumns: ColumnMetadata[];
/**
* Inverse join table columns.
* Inverse join columns are supported only for many-to-many relations
* and can be obtained only from owner side of the relation.
* From non-owner side of the relation join columns will be undefined.
*/
inverseJoinColumns: ColumnMetadata[];
constructor(options: {
entityMetadata: EntityMetadata;
embeddedMetadata?: EmbeddedMetadata;
args: RelationMetadataArgs;
});
/**
* Creates join column ids map from the given related entity ids array.
*/
getRelationIdMap(entity: ObjectLiteral): ObjectLiteral | undefined;
/**
* Ensures that given object is an entity id map.
* If given id is an object then it means its already id map.
* If given id isn't an object then it means its a value of the id column
* and it creates a new id map with this value and name of the primary column.
*/
ensureRelationIdMap(id: any): ObjectLiteral;
/**
* Extracts column value from the given entity.
* If column is in embedded (or recursive embedded) it extracts its value from there.
*/
getEntityValue(entity: ObjectLiteral, getLazyRelationsPromiseValue?: boolean): any | undefined;
/**
* Sets given entity's relation's value.
* Using of this method helps to set entity relation's value of the lazy and non-lazy relations.
*
* If merge is set to true, it merges given value into currently
*/
setEntityValue(entity: ObjectLiteral, value: any): void;
/**
* Creates entity id map from the given entity ids array.
*/
createValueMap(value: any): any;
/**
* Builds some depend relation metadata properties.
* This builder method should be used only after embedded metadata tree was build.
*/
build(): void;
/**
* Registers given foreign keys in the relation.
* This builder method should be used to register foreign key in the relation.
*/
registerForeignKeys(...foreignKeys: ForeignKeyMetadata[]): void;
/**
* Registers given join columns in the relation.
* This builder method should be used to register join column in the relation.
*/
registerJoinColumns(joinColumns?: ColumnMetadata[], inverseJoinColumns?: ColumnMetadata[]): void;
/**
* Registers a given junction entity metadata.
* This builder method can be called after junction entity metadata for the many-to-many relation was created.
*/
registerJunctionEntityMetadata(junctionEntityMetadata: EntityMetadata): void;
/**
* Builds inverse side property path based on given inverse side property factory.
* This builder method should be used only after properties map of the inverse entity metadata was build.
*/
buildInverseSidePropertyPath(): string;
/**
* Builds relation's property path based on its embedded tree.
*/
buildPropertyPath(): string;
}
/**
* Contains all information about entity's relation count.
*/
declare class RelationIdMetadata {
/**
* Entity metadata where this column metadata is.
*/
entityMetadata: EntityMetadata;
/**
* Relation from which ids will be extracted.
*/
relation: RelationMetadata;
/**
* Relation name which need to count.
*/
relationNameOrFactory: string | ((object: any) => any);
/**
* Target class to which metadata is applied.
*/
target: Function | string;
/**
* Target's property name to which this metadata is applied.
*/
propertyName: string;
/**
* Alias of the joined (destination) table.
*/
alias?: string;
/**
* Extra condition applied to "ON" section of join.
*/
queryBuilderFactory?: (qb: SelectQueryBuilder<any>) => SelectQueryBuilder<any>;
constructor(options: {
entityMetadata: EntityMetadata;
args: RelationIdMetadataArgs;
});
/**
* Sets relation id value from the given entity.
*
* todo: make it to work in embeds as well.
*/
setValue(entity: ObjectLiteral): void;
/**
* Builds some depend relation id properties.
* This builder method should be used only after entity metadata, its properties map and all relations are build.
*/
build(): void;
}
/**
* Contains all information about entity's relation count.
*/
declare class RelationCountMetadata {
/**
* Entity metadata where this column metadata is.
*/
entityMetadata: EntityMetadata;
/**
* Relation which needs to be counted.
*/
relation: RelationMetadata;
/**
* Relation name which need to count.
*/
relationNameOrFactory: string | ((object: any) => any);
/**
* Target class to which metadata is applied.
*/
target: Function | string;
/**
* Target's property name to which this metadata is applied.
*/
propertyName: string;
/**
* Alias of the joined (destination) table.
*/
alias?: string;
/**
* Extra condition applied to "ON" section of join.
*/
queryBuilderFactory?: (qb: SelectQueryBuilder<any>) => SelectQueryBuilder<any>;
constructor(options: {
entityMetadata: EntityMetadata;
args: RelationCountMetadataArgs;
});
/**
* Builds some depend relation count metadata properties.
* This builder method should be used only after entity metadata, its properties map and all relations are build.
*/
build(): void;
}
/**
* This metadata contains all information about entity's listeners.
*/
declare class EntityListenerMetadata {
/**
* Entity metadata of the listener.
*/
entityMetadata: EntityMetadata;
/**
* Embedded metadata of the listener, in the case if listener is in embedded.
*/
embeddedMetadata?: EmbeddedMetadata;
/**
* Target class to which metadata is applied.
* This can be different then entityMetadata.target in the case if listener is in the embedded.
*/
target: Function | string;
/**
* Target's property name to which this metadata is applied.
*/
propertyName: string;
/**
* The type of the listener.
*/
type: EventListenerType;
constructor(options: {
entityMetadata: EntityMetadata;
embeddedMetadata?: EmbeddedMetadata;
args: EntityListenerMetadataArgs;
});
/**
* Checks if entity listener is allowed to be executed on the given entity.
*/
isAllowed(entity: ObjectLiteral): boolean;
/**
* Executes listener method of the given entity.
*/
execute(entity: ObjectLiteral): any;
/**
* Calls embedded entity listener method no matter how nested it is.
*/
protected callEntityEmbeddedMethod(entity: ObjectLiteral, propertyPaths: string[]): void;
}
/**
* Unique metadata contains all information about table's unique constraints.
*/
declare class UniqueMetadata {
/**
* Entity metadata of the class to which this unique constraint is applied.
*/
entityMetadata: EntityMetadata;
/**
* Embedded metadata if this unique was applied on embedded.
*/
embeddedMetadata?: EmbeddedMetadata;
/**
* Target class to which metadata is applied.
*/
target?: Function | string;
/**
* Unique columns.
*/
columns: ColumnMetadata[];
/**
* Indicate if unique constraints can be deferred.
*/
deferrable?: DeferrableType;
/**
* User specified unique constraint name.
*/
givenName?: string;
/**
* User specified column names.
*/
givenColumnNames?: ((object?: any) => any[] | {
[key: string]: number;
}) | string[];
/**
* Final unique constraint name.
* If unique constraint name was given by a user then it stores normalized (by naming strategy) givenName.
* If unique constraint name was not given then its generated.
*/
name: string;
/**
* Map of column names with order set.
* Used only by MongoDB driver.
*/
columnNamesWithOrderingMap: {
[key: string]: number;
};
constructor(options: {
entityMetadata: EntityMetadata;
embeddedMetadata?: EmbeddedMetadata;
columns?: ColumnMetadata[];
args?: UniqueMetadataArgs;
});
/**
* Builds some depend unique constraint properties.
* Must be called after all entity metadata's properties map, columns and relations are built.
*/
build(namingStrategy: NamingStrategyInterface): this;
}
/**
* Contains all information about entity's embedded property.
*/
declare class EmbeddedMetadata {
/**
* Entity metadata where this embedded is.
*/
entityMetadata: EntityMetadata;
/**
* Parent embedded in the case if this embedded inside other embedded.
*/
parentEmbeddedMetadata?: EmbeddedMetadata;
/**
* Embedded target type.
*/
type: Function | string;
/**
* Property name on which this embedded is attached.
*/
propertyName: string;
/**
* Gets full path to this embedded property (including embedded property name).
* Full path is relevant when embedded is used inside other embeds (one or multiple nested).
* For example it will return "counters.subcounters".
*/
propertyPath: string;
/**
* Columns inside this embed.
*/
columns: ColumnMetadata[];
/**
* Relations inside this embed.
*/
relations: RelationMetadata[];
/**
* Entity listeners inside this embed.
*/
listeners: EntityListenerMetadata[];
/**
* Indices applied to the embed columns.
*/
indices: IndexMetadata[];
/**
* Uniques applied to the embed columns.
*/
uniques: UniqueMetadata[];
/**
* Relation ids inside this embed.
*/
relationIds: RelationIdMetadata[];
/**
* Relation counts inside this embed.
*/
relationCounts: RelationCountMetadata[];
/**
* Nested embeddable in this embeddable (which has current embedded as parent embedded).
*/
embeddeds: EmbeddedMetadata[];
/**
* Indicates if the entity should be instantiated using the constructor
* or via allocating a new object via `Object.create()`.
*/
isAlwaysUsingConstructor: boolean;
/**
* Indicates if this embedded is in array mode.
*
* This option works only in mongodb.
*/
isArray: boolean;
/**
* Prefix of the embedded, used instead of propertyName.
* If set to empty string or false, then prefix is not set at all.
*/
customPrefix: string | boolean | undefined;
/**
* Gets the prefix of the columns.
* By default its a property name of the class where this prefix is.
* But if custom prefix is set then it takes its value as a prefix.
* However if custom prefix is set to empty string or false, then prefix to column is not applied at all.
*/
prefix: string;
/**
* Returns array of property names of current embed and all its parent embeds.
*
* example: post[data][information][counters].id where "data", "information" and "counters" are embeds
* we need to get value of "id" column from the post real entity object.
* this method will return ["data", "information", "counters"]
*/
parentPropertyNames: string[];
/**
* Returns array of prefixes of current embed and all its parent embeds.
*/
parentPrefixes: string[];
/**
* Returns embed metadatas from all levels of the parent tree.
*
* example: post[data][information][counters].id where "data", "information" and "counters" are embeds
* this method will return [embed metadata of data, embed metadata of information, embed metadata of counters]
*/
embeddedMetadataTree: EmbeddedMetadata[];
/**
* Embed metadatas from all levels of the parent tree.
*
* example: post[data][information][counters].id where "data", "information" and "counters" are embeds
* this method will return [embed metadata of data, embed metadata of information, embed metadata of counters]
*/
columnsFromTree: ColumnMetadata[];
/**
* Relations of this embed and all relations from its child embeds.
*/
relationsFromTree: RelationMetadata[];
/**
* Relations of this embed and all relations from its child embeds.
*/
listenersFromTree: EntityListenerMetadata[];
/**
* Indices of this embed and all indices from its child embeds.
*/
indicesFromTree: IndexMetadata[];
/**
* Uniques of this embed and all uniques from its child embeds.
*/
uniquesFromTree: UniqueMetadata[];
/**
* Relation ids of this embed and all relation ids from its child embeds.
*/
relationIdsFromTree: RelationIdMetadata[];
/**
* Relation counts of this embed and all relation counts from its child embeds.
*/
relationCountsFromTree: RelationCountMetadata[];
constructor(options: {
entityMetadata: EntityMetadata;
args: EmbeddedMetadataArgs;
});
/**
* Creates a new embedded object.
*/
create(options?: {
fromDeserializer?: boolean;
}): any;
build(connection: DataSource): this;
protected buildPartialPrefix(): string[];
protected buildPrefix(connection: DataSource): string;
protected buildParentPropertyNames(): string[];
protected buildParentPrefixes(): string[];
protected buildEmbeddedMetadataTree(): EmbeddedMetadata[];
protected buildColumnsFromTree(): ColumnMetadata[];
protected buildRelationsFromTree(): RelationMetadata[];
protected buildListenersFromTree(): EntityListenerMetadata[];
protected buildIndicesFromTree(): IndexMetadata[];
protected buildUniquesFromTree(): UniqueMetadata[];
protected buildRelationIdsFromTree(): RelationIdMetadata[];
protected buildRelationCountsFromTree(): RelationCountMetadata[];
}
/**
* This metadata contains all information about entity's column.
*/
declare class ColumnMetadata {
readonly "@instanceof": symbol;
/**
* Target class where column decorator is used.
* This may not be always equal to entity metadata (for example embeds or inheritance cases).
*/
target: Function | string;
/**
* Entity metadata where this column metadata is.
*
* For example for @Column() name: string in Post, entityMetadata will be metadata of Post entity.
*/
entityMetadata: EntityMetadata;
/**
* Embedded metadata where this column metadata is.
* If this column is not in embed then this property value is undefined.
*/
embeddedMetadata?: EmbeddedMetadata;
/**
* If column is a foreign key of some relation then this relation's metadata will be there.
* If this column does not have a foreign key then this property value is undefined.
*/
relationMetadata?: RelationMetadata;
/**
* Class's property name on which this column is applied.
*/
propertyName: string;
/**
* The database type of the column.
*/
type: ColumnType;
/**
* Type's length in the database.
*/
length: string;
/**
* Type's display width in the database.
*/
width?: number;
/**
* Defines column character set.
*/
charset?: string;
/**
* Defines column collation.
*/
collation?: string;
/**
* Indicates if this column is a primary key.
*/
isPrimary: boolean;
/**
* Indicates if this column is generated (auto increment or generated other way).
*/
isGenerated: boolean;
/**
* Indicates if column can contain nulls or not.
*/
isNullable: boolean;
/**
* Indicates if column is selected by query builder or not.
*/
isSelect: boolean;
/**
* Indicates if column is inserted by default or not.
*/
isInsert: boolean;
/**
* Indicates if column allows updates or not.
*/
isUpdate: boolean;
/**
* Specifies generation strategy if this column will use auto increment.
*/
generationStrategy?: "uuid" | "increment" | "rowid";
/**
* Identity column type. Supports only in Postgres 10+.
*/
generatedIdentity?: "ALWAYS" | "BY DEFAULT";
/**
* Column comment.
* This feature is not supported by all databases.
*/
comment?: string;
/**
* Default database value.
*/
default?: number | boolean | string | null | (number | boolean | string)[] | Record<string, object> | (() => string);
/**
* ON UPDATE trigger. Works only for MySQL.
*/
onUpdate?: string;
/**
* The precision for a decimal (exact numeric) column (applies only for decimal column),
* which is the maximum number of digits that are stored for the values.
*/
precision?: number | null;
/**
* The scale for a decimal (exact numeric) column (applies only for decimal column),
* which represents the number of digits to the right of the decimal point and must not be greater than precision.
*/
scale?: number;
/**
* Puts ZEROFILL attribute on to numeric column. Works only for MySQL.
* If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to the column
*/
zerofill: boolean;
/**
* Puts UNSIGNED attribute on to numeric column. Works only for MySQL.
*/
unsigned: boolean;
/**
* Array of possible enumerated values.
*
* `postgres` and `mysql` store enum values as strings but we want to keep support
* for numeric and heterogeneous based typescript enums, so we need (string|number)[]
*/
enum?: (string | number)[];
/**
* Exact name of enum
*/
enumName?: string;
/**
* Generated column expression.
*/
asExpression?: string;
/**
* Generated column type.
*/
generatedType?: "VIRTUAL" | "STORED";
/**
* Return type of HSTORE column.
* Returns value as string or as object.
*/
hstoreType?: "object" | "string";
/**
* Indicates if this column is an array.
*/
isArray: boolean;
/**
* Gets full path to this column property (including column property name).
* Full path is relevant when column is used in embeds (one or multiple nested).
* For example it will return "counters.subcounters.likes".
* If property is not in embeds then it returns just property name of the column.
*/
propertyPath: string;
/**
* Same as property path, but dots are replaced with '_'.
* Used in query builder statements.
*/
propertyAliasName: string;
/**
* Gets full path to this column database name (including column database name).
* Full path is relevant when column is used in embeds (one or multiple nested).
* For example it will return "counters.subcounters.likes".
* If property is not in embeds then it returns just database name of the column.
*/
databasePath: string;
/**
* Complete column name in the database including its embedded prefixes.
*/
databaseName: string;
/**
* Database name in the database without embedded prefixes applied.
*/
databaseNameWithoutPrefixes: string;
/**
* Database name set by entity metadata builder, not yet passed naming strategy process and without embedded prefixes.
*/
givenDatabaseName?: string;
/**
* Indicates if column is virtual. Virtual columns are not mapped to the entity.
*/
isVirtual: boolean;
/**
* Indicates if column is a virtual property. Virtual properties are not mapped to the entity.
* This property is used in tandem the virtual column decorator.
* @See https://typeorm.io/decorator-reference#virtualcolumn for more details.
*/
isVirtualProperty: boolean;
/**
* Query to be used to populate the column data. This query is used when generating the relational db script.
* The query function is called with the current entities alias either defined by the Entity Decorator or automatically
* @See https://typeorm.io/decorator-reference#virtualcolumn for more details.
*/
query?: (alias: string) => string;
/**
* Indicates if column is discriminator. Discriminator columns are not mapped to the entity.
*/
isDiscriminator: boolean;
/**
* Indicates if column is tree-level column. Tree-level columns are used in closure entities.
*/
isTreeLevel: boolean;
/**
* Indicates if this column contains an entity creation date.
*/
isCreateDate: boolean;
/**
* Indicates if this column contains an entity update date.
*/
isUpdateDate: boolean;
/**
* Indicates if this column contains an entity delete date.
*/
isDeleteDate: boolean;
/**
* Indicates if this column contains an entity version.
*/
isVersion: boolean;
/**
* Indicates if this column contains an object id.
*/
isObjectId: boolean;
/**
* If this column is foreign key then it references some other column,
* and this property will contain reference to this column.
*/
referencedColumn: ColumnMetadata | undefined;
/**
* If this column is primary key then this specifies the name for it.
*/
primaryKeyConstraintName?: string;
/**
* If this column is foreign key then this specifies the name for it.
*/
foreignKeyConstraintName?: string;
/**
* Specifies a value transformer that is to be used to (un)marshal
* this column when reading or writing to the database.
*/
transformer?: ValueTransformer | ValueTransformer[];
/**
* Column type in the case if this column is in the closure table.
* Column can be ancestor or descendant in the closure tables.
*/
closureType?: "ancestor" | "descendant";
/**
* Indicates if this column is nested set's left column.
* Used only in tree entities with nested-set type.
*/
isNestedSetLeft: boolean;
/**
* Indicates if this column is nested set's right column.
* Used only in tree entities with nested-set type.
*/
isNestedSetRight: boolean;
/**
* Indicates if this column is materialized path's path column.
* Used only in tree entities with materialized path type.
*/
isMaterializedPath: boolean;
/**
* Spatial Feature Type (Geometry, Point, Polygon, etc.)
*/
spatialFeatureType?: string;
/**
* SRID (Spatial Reference ID (EPSG code))
*/
srid?: number;
constructor(options: {
connection: DataSource;
entityMetadata: EntityMetadata;
embeddedMetadata?: EmbeddedMetadata;
referencedColumn?: ColumnMetadata;
args: ColumnMetadataArgs;
closureType?: "ancestor" | "descendant";
nestedSetLeft?: boolean;
nestedSetRight?: boolean;
materializedPath?: boolean;
});
/**
* Creates entity id map from the given entity ids array.
*/
createValueMap(value: any, useDatabaseName?: boolean): any;
/**
* Extracts column value and returns its column name with this value in a literal object.
* If column is in embedded (or recursive embedded) it returns complex literal object.
*
* Examples what this method can return depend if this column is in embeds.
* { id: 1 } or { title: "hello" }, { counters: { code: 1 } }, { data: { information: { counters: { code: 1 } } } }
*/
getEntityValueMap(entity: ObjectLiteral, options?: {
skipNulls?: boolean;
}): ObjectLiteral | undefined;
/**
* Extracts column value from the given entity.
* If column is in embedded (or recursive embedded) it extracts its value from there.
*/
getEntityValue(entity: ObjectLiteral, transform?: boolean): any | undefined;
/**
* Sets given entity's column value.
* Using of this method helps to set entity relation's value of the lazy and non-lazy relations.
*/
setEntityValue(entity: ObjectLiteral, value: any): void;
/**
* Compares given entity's column value with a given value.
*/
compareEntityValue(entity: any, valueToCompareWith: any): any;
build(connection: DataSource): this;
protected buildPropertyPath(): string;
protected buildDatabasePath(): string;
protected buildDatabaseName(connection: DataSource): string;
}
/**
* Check metadata contains all information about table's check constraints.
*/
declare class CheckMetadata {
/**
* Entity metadata of the class to which this check constraint is applied.
*/
entityMetadata: EntityMetadata;
/**
* Target class to which metadata is applied.
*/
target?: Function | string;
/**
* Check expression.
*/
expression: string;
/**
* User specified check constraint name.
*/
givenName?: string;
/**
* Final check constraint name.
* If check constraint name was given by a user then it stores normalized (by naming strategy) givenName.
* If check constraint name was not given then its generated.
*/
name: string;
constructor(options: {
entityMetadata: EntityMetadata;
args?: CheckMetadataArgs;
});
/**
* Builds some depend check constraint properties.
* Must be called after all entity metadata's properties map, columns and relations are built.
*/
build(namingStrategy: NamingStrategyInterface): this;
}
/**
* Exclusion metadata contains all information about table's exclusion constraints.
*/
declare class ExclusionMetadata {
/**
* Entity metadata of the class to which this exclusion constraint is applied.
*/
entityMetadata: EntityMetadata;
/**
* Target class to which metadata is applied.
*/
target?: Function | string;
/**
* Exclusion expression.
*/
expression: string;
/**
* User specified exclusion constraint name.
*/
givenName?: string;
/**
* Final exclusion constraint name.
* If exclusion constraint name was given by a user then it stores normalized (by naming strategy) givenName.
* If exclusion constraint name was not given then its generated.
*/
name: string;
constructor(options: {
entityMetadata: EntityMetadata;
args?: ExclusionMetadataArgs;
});
/**
* Builds some depend exclusion constraint properties.
* Must be called after all entity metadata's properties map, columns and relations are built.
*/
build(namingStrategy: NamingStrategyInterface): this;
}
/**
* Contains all entity metadata.
*/
declare class EntityMetadata {
readonly "@instanceof": symbol;
/**
* Connection where this entity metadata is created.
*/
connection: DataSource;
/**
* Metadata arguments used to build this entity metadata.
*/
tableMetadataArgs: TableMetadataArgs;
/**
* If entity's table is a closure-typed table, then this entity will have a closure junction table metadata.
*/
closureJunctionTable: EntityMetadata;
/**
* If this is entity metadata for a junction closure table then its owner closure table metadata will be set here.
*/
parentClosureEntityMetadata: EntityMetadata;
/**
* Parent's entity metadata. Used in inheritance patterns.
*/
parentEntityMetadata: EntityMetadata;
/**
* Children entity metadatas. Used in inheritance patterns.
*/
childEntityMetadatas: EntityMetadata[];
/**
* All "inheritance tree" from a target entity.
* For example for target Post < ContentModel < Unit it will be an array of [Post, ContentModel, Unit].
* It also contains child entities for single table inheritance.
*/
inheritanceTree: Function[];
/**
* Table type. Tables can be closure, junction, etc.
*/
tableType: TableType;
/**
* Target class to which this entity metadata is bind.
* Note, that when using table inheritance patterns target can be different rather then table's target.
* For virtual tables which lack of real entity (like junction tables) target is equal to their table name.
*/
target: Function | string;
/**
* Gets the name of the target.
*/
targetName: string;
/**
* Entity's name.
* Equal to entity target class's name if target is set to table.
* If target class is not then then it equals to table name.
*/
name: string;
/**
* View's expression.
* Used in views
*/
expression?: string | ((connection: DataSource) => SelectQueryBuilder<any>);
/**
* View's dependencies.
* Used in views
*/
dependsOn?: Set<Function | string>;
/**
* Enables Sqlite "WITHOUT ROWID" modifier for the "CREATE TABLE" statement
*/
withoutRowid?: boolean;
/**
* Original user-given table name (taken from schema or @Entity(tableName) decorator).
* If user haven't specified a table name this property will be undefined.
*/
givenTableName?: string;
/**
* Entity table name in the database.
* This is final table name of the entity.
* This name already passed naming strategy, and generated based on
* multiple criteria, including user table name and global table prefix.
*/
tableName: string;
/**
* Entity table path. Contains database name, schema name and table name.
* E.g. myDB.mySchema.myTable
*/
tablePath: string;
/**
* Gets the table name without global table prefix.
* When querying table you need a table name with prefix, but in some scenarios,
* for example when you want to name a junction table that contains names of two other tables,
* you may want a table name without prefix.
*/
tableNameWithoutPrefix: string;
/**
* Indicates if schema will be synchronized for this entity or not.
*/
synchronize: boolean;
/**
* Table's database engine type (like "InnoDB", "MyISAM", etc).
*/
engine?: string;
/**
* Database name.
*/
database?: string;
/**
* Schema name. Used in Postgres and Sql Server.
*/
schema?: string;
/**
* Specifies a default order by used for queries from this table when no explicit order by is specified.
*/
orderBy?: OrderByCondition;
/**
* If this entity metadata's table using one of the inheritance patterns,
* then this will contain what pattern it uses.
*/
inheritancePattern?: "STI";
/**
* Checks if there any non-nullable column exist in this entity.
*/
hasNonNullableRelations: boolean;
/**
* Indicates if this entity metadata of a junction table, or not.
* Junction table is a table created by many-to-many relationship.
*
* Its also possible to understand if entity is junction via tableType.
*/
isJunction: boolean;
/**
* Indicates if the entity should be instantiated using the constructor
* or via allocating a new object via `Object.create()`.
*/
isAlwaysUsingConstructor: boolean;
/**
* Indicates if this entity is a tree, what type of tree it is.
*/
treeType?: TreeType;
/**
* Indicates if this entity is a tree, what options of tree it has.
*/
treeOptions?: ClosureTreeOptions;
/**
* Checks if this table is a junction table of the closure table.
* This type is for tables that contain junction metadata of the closure tables.
*/
isClosureJunction: boolean;
/**
* Checks if entity's table has multiple primary columns.
*/
hasMultiplePrimaryKeys: boolean;
/**
* Indicates if this entity metadata has uuid generated columns.
*/
hasUUIDGeneratedColumns: boolean;
/**
* If this entity metadata is a child table of some table, it should have a discriminator value.
* Used to store a value in a discriminator column.
*/
discriminatorValue?: string;
/**
* Entity's column metadatas defined by user.
*/
ownColumns: ColumnMetadata[];
/**
* Columns of the entity, including columns that are coming from the embeddeds of this entity.
*/
columns: ColumnMetadata[];
/**
* Ancestor columns used only in closure junction tables.
*/
ancestorColumns: ColumnMetadata[];
/**
* Descendant columns used only in closure junction tables.
*/
descendantColumns: ColumnMetadata[];
/**
* All columns except for virtual columns.
*/
nonVirtualColumns: ColumnMetadata[];
/**
* In the case if this entity metadata is junction table's entity metadata,
* this will contain all referenced columns of owner entity.
*/
ownerColumns: ColumnMetadata[];
/**
* In the case if this entity metadata is junction table's entity metadata,
* this will contain all referenced columns of inverse entity.
*/
inverseColumns: ColumnMetadata[];
/**
* Gets the column with generated flag.
*/
generatedColumns: ColumnMetadata[];
/**
* Gets the object id column used with mongodb database.
*/
objectIdColumn?: ColumnMetadata;
/**
* Gets entity column which contains a create date value.
*/
createDateColumn?: ColumnMetadata;
/**
* Gets entity column which contains an update date value.
*/
updateDateColumn?: ColumnMetadata;
/**
* Gets entity column which contains a delete date value.
*/
deleteDateColumn?: ColumnMetadata;
/**
* Gets entity column which contains an entity version.
*/
versionColumn?: ColumnMetadata;
/**
* Gets the discriminator column used to store entity identificator in single-table inheritance tables.
*/
discriminatorColumn?: ColumnMetadata;
/**
* Special column that stores tree level in tree entities.
*/
treeLevelColumn?: ColumnMetadata;
/**
* Nested set's left value column.
* Used only in tree entities with nested set pattern applied.
*/
nestedSetLeftColumn?: ColumnMetadata;
/**
* Nested set's right value column.
* Used only in tree entities with nested set pattern applied.
*/
nestedSetRightColumn?: ColumnMetadata;
/**
* Materialized path column.
* Used only in tree entities with materialized path pattern applied.
*/
materializedPathColumn?: ColumnMetadata;
/**
* Gets the primary columns.
*/
primaryColumns: ColumnMetadata[];
/**
* Entity's relation metadatas.
*/
ownRelations: RelationMetadata[];
/**
* Relations of the entity, including relations that are coming from the embeddeds of this entity.
*/
relations: RelationMetadata[];
/**
* List of eager relations this metadata has.
*/
eagerRelations: RelationMetadata[];
/**
* List of eager relations this metadata has.
*/
lazyRelations: RelationMetadata[];
/**
* Gets only one-to-one relations of the entity.
*/
oneToOneRelations: RelationMetadata[];
/**
* Gets only owner one-to-one relations of the entity.
*/
ownerOneToOneRelations: RelationMetadata[];
/**
* Gets only one-to-many relations of the entity.
*/
oneToManyRelations: RelationMetadata[];
/**
* Gets only many-to-one relations of the entity.
*/
manyToOneRelations: RelationMetadata[];
/**
* Gets only many-to-many relations of the entity.
*/
manyToManyRelations: RelationMetadata[];
/**
* Gets only owner many-to-many relations of the entity.
*/
ownerManyToManyRelations: RelationMetadata[];
/**
* Gets only owner one-to-one and many-to-one relations.
*/
relationsWithJoinColumns: RelationMetadata[];
/**
* Tree parent relation. Used only in tree-tables.
*/
treeParentRelation?: RelationMetadata;
/**
* Tree children relation. Used only in tree-tables.
*/
treeChildrenRelation?: RelationMetadata;
/**
* Entity's relation id metadatas.
*/
relationIds: RelationIdMetadata[];
/**
* Entity's relation id metadatas.
*/
relationCounts: RelationCountMetadata[];
/**
* Entity's foreign key metadatas.
*/
foreignKeys: ForeignKeyMetadata[];
/**
* Entity's embedded metadatas.
*/
embeddeds: EmbeddedMetadata[];
/**
* All embeddeds - embeddeds from this entity metadata and from all child embeddeds, etc.
*/
allEmbeddeds: EmbeddedMetadata[];
/**
* Entity's own indices.
*/
ownIndices: IndexMetadata[];
/**
* Entity's index metadatas.
*/
indices: IndexMetadata[];
/**
* Entity's unique metadatas.
*/
uniques: UniqueMetadata[];
/**
* Entity's own uniques.
*/
ownUniques: UniqueMetadata[];
/**
* Entity's check metadatas.
*/
checks: CheckMetadata[];
/**
* Entity's exclusion metadatas.
*/
exclusions: ExclusionMetadata[];
/**
* Entity's own listener metadatas.
*/
ownListeners: EntityListenerMetadata[];
/**
* Entity listener metadatas.
*/
listeners: EntityListenerMetadata[];
/**
* Listener metadatas with "AFTER LOAD" type.
*/
afterLoadListeners: EntityListenerMetadata[];
/**
* Listener metadatas with "BEFORE INSERT" type.
*/
beforeInsertListeners: EntityListenerMetadata[];
/**
* Listener metadatas with "AFTER INSERT" type.
*/
afterInsertListeners: EntityListenerMetadata[];
/**
* Listener metadatas with "BEFORE UPDATE" type.
*/
beforeUpdateListeners: EntityListenerMetadata[];
/**
* Listener metadatas with "AFTER UPDATE" type.
*/
afterUpdateListeners: EntityListenerMetadata[];
/**
* Listener metadatas with "BEFORE REMOVE" type.
*/
beforeRemoveListeners: EntityListenerMetadata[];
/**
* Listener metadatas with "BEFORE SOFT REMOVE" type.
*/
beforeSoftRemoveListeners: EntityListenerMetadata[];
/**
* Listener metadatas with "BEFORE RECOVER" type.
*/
beforeRecoverListeners: EntityListenerMetadata[];
/**
* Listener metadatas with "AFTER REMOVE" type.
*/
afterRemoveListeners: EntityListenerMetadata[];
/**
* Listener metadatas with "AFTER SOFT REMOVE" type.
*/
afterSoftRemoveListeners: EntityListenerMetadata[];
/**
* Listener metadatas with "AFTER RECOVER" type.
*/
afterRecoverListeners: EntityListenerMetadata[];
/**
* Map of columns and relations of the entity.
*
* example: Post{ id: number, nam