lakutata
Version:
An IoC-based universal application framework.
1,523 lines (1,489 loc) • 731 kB
TypeScript
import './TypeDef.2.js';
import { ReadStream } from 'fs';
import { ConnectionOptions as ConnectionOptions$1, TLSSocketOptions, TLSSocket, TlsOptions } from 'tls';
import { TcpNetConnectOpts, Socket } from 'net';
import { SrvRecord } from 'dns';
import { EventEmitter } from 'events';
import { Readable } from 'stream';
/**
* Options passed to QueryResultCache class.
*/
interface QueryResultCacheOptions {
/**
* Cache identifier set by user.
* Can be empty.
*/
identifier?: string;
/**
* Time, when cache was created.
*/
time?: number;
/**
* Duration in milliseconds during which results will be returned from cache.
*/
duration: number;
/**
* Cached query.
*/
query?: string;
/**
* Query result that will be cached.
*/
result?: any;
}
/**
* Table's column options.
*/
interface TableColumnOptions {
/**
* Column name.
*/
name: string;
/**
* Column type.
*/
type: string;
/**
* Column's default value.
*/
default?: any;
/**
* ON UPDATE trigger. Works only for MySQL.
*/
onUpdate?: string;
/**
* Indicates if column is NULL, or is NOT NULL in the database.
*/
isNullable?: boolean;
/**
* Indicates if column is auto-generated sequence.
*/
isGenerated?: boolean;
/**
* Specifies generation strategy if this column will use auto increment.
*/
generationStrategy?: "uuid" | "increment" | "rowid" | "identity";
/**
* Indicates if column is a primary key.
*/
isPrimary?: boolean;
/**
* Indicates if column has unique value.
*/
isUnique?: boolean;
/**
* Indicates if column stores array.
*/
isArray?: boolean;
/**
* Column's comment.
*/
comment?: string;
/**
* Column type's length. Used only on some column types.
* For example type = "string" and length = "100" means that ORM will create a column with type varchar(100).
*/
length?: string;
/**
* Column type's display width. Used only on some column types in MySQL.
* For example, INT(4) specifies an INT with a display width of four digits.
*/
width?: number;
/**
* Defines column character set.
*/
charset?: string;
/**
* Defines column collation.
*/
collation?: 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.
*/
enum?: string[];
/**
* Exact name of enum
*/
enumName?: string;
/**
* 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;
/**
* Generated column expression.
*/
asExpression?: string;
/**
* Generated column type.
*/
generatedType?: "VIRTUAL" | "STORED";
/**
* Identity column type. Supports only in Postgres 10+.
*/
generatedIdentity?: "ALWAYS" | "BY DEFAULT";
/**
* Spatial Feature Type (Geometry, Point, Polygon, etc.)
*/
spatialFeatureType?: string;
/**
* SRID (Spatial Reference ID (EPSG code))
*/
srid?: number;
}
/**
* Table's columns in the database represented in this class.
*/
declare class TableColumn {
readonly "@instanceof": symbol;
/**
* Column name.
*/
name: string;
/**
* Column type.
*/
type: string;
/**
* Column's default value.
*/
default?: any;
/**
* ON UPDATE trigger. Works only for MySQL.
*/
onUpdate?: string;
/**
* Indicates if column is NULL, or is NOT NULL in the database.
*/
isNullable: boolean;
/**
* Indicates if column is auto-generated sequence.
*/
isGenerated: boolean;
/**
* Specifies generation strategy if this column will use auto increment.
* `rowid` option supported only in CockroachDB.
*/
generationStrategy?: "uuid" | "increment" | "rowid" | "identity";
/**
* Indicates if column is a primary key.
*/
isPrimary: boolean;
/**
* Indicates if column has unique value.
*/
isUnique: boolean;
/**
* Indicates if column stores array.
*/
isArray: boolean;
/**
* Column's comment.
*/
comment?: string;
/**
* Column type's length. Used only on some column types.
* For example type = "string" and length = "100" means that ORM will create a column with type varchar(100).
*/
length: string;
/**
* Column type's display width. Used only on some column types in MySQL.
* For example, INT(4) specifies an INT with a display width of four digits.
*/
width?: number;
/**
* Defines column character set.
*/
charset?: string;
/**
* Defines column collation.
*/
collation?: 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.
*/
enum?: string[];
/**
* Exact name of enum
*/
enumName?: string;
/**
* Name of the primary key constraint for primary column.
*/
primaryKeyConstraintName?: string;
/**
* Generated column expression.
*/
asExpression?: string;
/**
* Generated column type.
*/
generatedType?: "VIRTUAL" | "STORED";
/**
* Identity column type. Supports only in Postgres 10+.
*/
generatedIdentity?: "ALWAYS" | "BY DEFAULT";
/**
* Spatial Feature Type (Geometry, Point, Polygon, etc.)
*/
spatialFeatureType?: string;
/**
* SRID (Spatial Reference ID (EPSG code))
*/
srid?: number;
constructor(options?: TableColumnOptions);
/**
* Clones this column to a new column with exact same properties as this column has.
*/
clone(): TableColumn;
}
/**
* All types that relation can be.
*/
type RelationType = "one-to-one" | "one-to-many" | "many-to-one" | "many-to-many";
/**
* DEFERRABLE type to be used to specify if foreign key constraints can be deferred.
*/
type DeferrableType = "INITIALLY IMMEDIATE" | "INITIALLY DEFERRED";
/**
* ON_DELETE type to be used to specify delete strategy when some relation is being deleted from the database.
*/
type OnDeleteType = "RESTRICT" | "CASCADE" | "SET NULL" | "DEFAULT" | "NO ACTION";
/**
* ON_UPDATE type to be used to specify update strategy when some relation is being updated.
*/
type OnUpdateType = "RESTRICT" | "CASCADE" | "SET NULL" | "DEFAULT" | "NO ACTION";
/**
* Describes all relation's options.
*/
interface RelationOptions {
/**
* Sets cascades options for the given relation.
* If set to true then it means that related object can be allowed to be inserted or updated in the database.
* You can separately restrict cascades to insertion or updation using following syntax:
*
* cascade: ["insert", "update", "remove", "soft-remove", "recover"] // include or exclude one of them
*/
cascade?: boolean | ("insert" | "update" | "remove" | "soft-remove" | "recover")[];
/**
* Indicates if relation column value can be nullable or not.
*/
nullable?: boolean;
/**
* Database cascade action on delete.
*/
onDelete?: OnDeleteType;
/**
* Database cascade action on update.
*/
onUpdate?: OnUpdateType;
/**
* Indicate if foreign key constraints can be deferred.
*/
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;
/**
* Set this relation to be lazy. Note: lazy relations are promises. When you call them they return promise
* which resolve relation result then. If your property's type is Promise then this relation is set to lazy automatically.
*/
lazy?: boolean;
/**
* Set this relation to be eager.
* Eager relations are always loaded automatically when relation's owner entity is loaded using find* methods.
* Only using QueryBuilder prevents loading eager relations.
* Eager flag cannot be set from both sides of relation - you can eager load only one side of the relationship.
*/
eager?: 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.
*/
persistence?: 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.
* disable will keep the relation intact. Removal of related item is only possible through its own repo.
*/
orphanedRowAction?: "nullify" | "delete" | "soft-delete" | "disable";
}
/**
* Contains the name of the property of the object, or the function that returns this name.
*/
type PropertyTypeFactory<T> = string | ((t: T) => string | any);
/**
* Represents some Type of the Object.
*/
type ObjectType<T> = {
new (): T;
} | Function;
/**
* Entity target.
*/
type EntityTarget<Entity> = ObjectType<Entity> | EntitySchema<Entity> | string | {
type: Entity;
name: string;
};
/**
* Function that returns a type of the field. Returned value must be a class used on the relation.
*/
type RelationTypeInFunction = ((type?: any) => Function) | EntityTarget<any>;
/**
* Arguments for RelationMetadata class.
*/
interface RelationMetadataArgs {
/**
* Class to which this relation is applied.
*/
readonly target: Function | string;
/**
* In the case if this relation is without a target, targetId must be specified.
* This is used for entity schemas without classes.
*/
/**
* Class's property name to which this relation is applied.
*/
readonly propertyName: string;
/**
* Indicates if this relation will be lazily loaded.
*/
readonly isLazy: boolean;
/**
* Original (reflected) class's property type.
*
* todo: this can be empty for relations from entity schemas.
*/
/**
* Type of relation. Can be one of the value of the RelationTypes class.
*/
readonly relationType: RelationType;
/**
* Type of the relation. This type is in function because of language specifics and problems with recursive
* referenced classes.
*/
readonly type: RelationTypeInFunction;
/**
* Inverse side of the relation.
*/
readonly inverseSideProperty?: PropertyTypeFactory<any>;
/**
* Additional relation options.
*/
readonly options: RelationOptions;
/**
* Indicates if this is a parent (can be only many-to-one relation) relation in the tree tables.
*/
readonly isTreeParent?: boolean;
/**
* Indicates if this is a children (can be only one-to-many relation) relation in the tree tables.
*/
readonly isTreeChildren?: boolean;
}
/**
* Column types used for @PrimaryGeneratedColumn() decorator.
*/
type PrimaryGeneratedColumnType = "int" | "int2" | "int4" | "int8" | "integer" | "tinyint" | "smallint" | "mediumint" | "bigint" | "dec" | "decimal" | "smalldecimal" | "fixed" | "numeric" | "number";
/**
* Column types where spatial properties are used.
*/
type SpatialColumnType = "geometry" | "geography" | "st_geometry" | "st_point";
/**
* Column types where precision and scale properties are used.
*/
type WithPrecisionColumnType = "float" | "double" | "dec" | "decimal" | "smalldecimal" | "fixed" | "numeric" | "real" | "double precision" | "number" | "datetime" | "datetime2" | "datetimeoffset" | "time" | "time with time zone" | "time without time zone" | "timestamp" | "timestamp without time zone" | "timestamp with time zone" | "timestamp with local time zone";
/**
* Column types where column length is used.
*/
type WithLengthColumnType = "character varying" | "varying character" | "char varying" | "nvarchar" | "national varchar" | "character" | "native character" | "varchar" | "char" | "nchar" | "national char" | "varchar2" | "nvarchar2" | "alphanum" | "shorttext" | "raw" | "binary" | "varbinary" | "string";
type WithWidthColumnType = "tinyint" | "smallint" | "mediumint" | "int" | "bigint";
/**
* All other regular column types.
*/
type SimpleColumnType = "simple-array" | "simple-json" | "simple-enum" | "int2" | "integer" | "int4" | "int8" | "int64" | "unsigned big int" | "float" | "float4" | "float8" | "float64" | "smallmoney" | "money" | "boolean" | "bool" | "tinyblob" | "tinytext" | "mediumblob" | "mediumtext" | "blob" | "text" | "ntext" | "citext" | "hstore" | "longblob" | "longtext" | "alphanum" | "shorttext" | "bytes" | "bytea" | "long" | "raw" | "long raw" | "bfile" | "clob" | "nclob" | "image" | "timetz" | "timestamptz" | "timestamp with local time zone" | "smalldatetime" | "date" | "interval year to month" | "interval day to second" | "interval" | "year" | "seconddate" | "point" | "line" | "lseg" | "box" | "circle" | "path" | "polygon" | "geography" | "geometry" | "linestring" | "multipoint" | "multilinestring" | "multipolygon" | "geometrycollection" | "st_geometry" | "st_point" | "int4range" | "int8range" | "numrange" | "tsrange" | "tstzrange" | "daterange" | "int4multirange" | "int8multirange" | "nummultirange" | "tsmultirange" | "tstzmultirange" | "datemultirange" | "enum" | "set" | "cidr" | "inet" | "inet4" | "inet6" | "macaddr" | "macaddr8" | "bit" | "bit varying" | "varbit" | "tsvector" | "tsquery" | "uuid" | "xml" | "json" | "jsonb" | "varbinary" | "hierarchyid" | "sql_variant" | "rowid" | "urowid" | "uniqueidentifier" | "rowversion" | "array" | "cube" | "ltree";
/**
* Any column type column can be.
*/
type ColumnType = WithPrecisionColumnType | WithLengthColumnType | WithWidthColumnType | SpatialColumnType | SimpleColumnType | BooleanConstructor | DateConstructor | NumberConstructor | StringConstructor;
/**
* Interface for objects that deal with (un)marshalling data.
*/
interface ValueTransformer {
/**
* Used to marshal data when writing to the database.
*/
to(value: any): any;
/**
* Used to unmarshal data when reading from the database.
*/
from(value: any): any;
}
/**
* Column options specific to all column types.
*/
interface ColumnCommonOptions {
/**
* Indicates if column is always selected by QueryBuilder and find operations.
* Default value is "true".
*/
select?: boolean;
/**
* Column name in the database.
*/
name?: string;
/**
* Indicates if this column is a primary key.
* Same can be achieved when @PrimaryColumn decorator is used.
*/
primary?: boolean;
/**
* Specifies if this column will use auto increment (sequence, generated identity, rowid).
* Note that in some databases only one column in entity can be marked as generated, and it must be a primary column.
*/
generated?: boolean | "increment" | "uuid" | "rowid" | "identity";
/**
* Specifies if column's value must be unique or not.
*/
unique?: boolean;
/**
* Indicates if column's value can be set to NULL.
*/
nullable?: boolean;
/**
* Default database value.
* Note that default value is not supported when column type is 'json' of mysql.
*/
default?: any;
/**
* ON UPDATE trigger. Works only for MySQL.
*/
onUpdate?: string;
/**
* Column comment. Not supported by all database types.
*/
comment?: string;
/**
* Indicates if this column is an array.
* Can be simply set to true or array length can be specified.
* Supported only by postgres.
*/
array?: boolean;
/**
* Specifies a value transformer that is to be used to (un)marshal
* this column when reading or writing to the database.
*/
transformer?: ValueTransformer | ValueTransformer[];
}
/**
* Describes all column's options.
*/
interface ColumnOptions extends ColumnCommonOptions {
/**
* Column type. Must be one of the value from the ColumnTypes class.
*/
type?: ColumnType;
/**
* Column name in the database.
*/
name?: string;
/**
* Column type's length. Used only on some column types.
* For example type = "string" and length = "100" means that ORM will create a column with type varchar(100).
*/
length?: string | number;
/**
* Column type's display width. Used only on some column types in MySQL.
* For example, INT(4) specifies an INT with a display width of four digits.
*/
width?: number;
/**
* Indicates if column's value can be set to NULL.
* Default value is "false".
*/
nullable?: boolean;
/**
* Indicates if column value is not updated by "save" operation.
* It means you'll be able to write this value only when you first time insert the object.
* Default value is "false".
*
* @deprecated Please use the `update` option instead. Careful, it takes
* the opposite value to readonly.
*
*/
readonly?: boolean;
/**
* Indicates if column value is updated by "save" operation.
* If false, you'll be able to write this value only when you first time insert the object.
* Default value is "true".
*/
update?: boolean;
/**
* Indicates if column is always selected by QueryBuilder and find operations.
* Default value is "true".
*/
select?: boolean;
/**
* Indicates if column is inserted by default.
* Default value is "true".
*/
insert?: boolean;
/**
* Default database value.
*/
default?: any;
/**
* ON UPDATE trigger. Works only for MySQL.
*/
onUpdate?: string;
/**
* Indicates if this column is a primary key.
* Same can be achieved when @PrimaryColumn decorator is used.
*/
primary?: boolean;
/**
* Specifies if column's value must be unique or not.
*/
unique?: boolean;
/**
* Column comment. Not supported by all database types.
*/
comment?: 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 this column
*/
zerofill?: boolean;
/**
* Puts UNSIGNED attribute on to numeric column. Works only for MySQL.
*/
unsigned?: boolean;
/**
* Defines a column character set.
* Not supported by all database types.
*/
charset?: string;
/**
* Defines a column collation.
*/
collation?: string;
/**
* Array of possible enumerated values.
*/
enum?: (string | number)[] | Object;
/**
* Exact name of enum
*/
enumName?: string;
/**
* 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;
/**
* Generated column expression.
*/
asExpression?: string;
/**
* Generated column type.
*/
generatedType?: "VIRTUAL" | "STORED";
/**
* Identity column type. Supports only in Postgres 10+.
*/
generatedIdentity?: "ALWAYS" | "BY DEFAULT";
/**
* Return type of HSTORE column.
* Returns value as string or as object.
*/
hstoreType?: "object" | "string";
/**
* Indicates if this column is an array.
* Can be simply set to true or array length can be specified.
* Supported only by postgres.
*/
array?: boolean;
/**
* Specifies a value transformer that is to be used to (un)marshal
* this column when reading or writing to the database.
*/
transformer?: ValueTransformer | ValueTransformer[];
/**
* Spatial Feature Type (Geometry, Point, Polygon, etc.)
*/
spatialFeatureType?: string;
/**
* SRID (Spatial Reference ID (EPSG code))
*/
srid?: number;
}
/**
* Kinda type of the column. Not a type in the database, but locally used type to determine what kind of column
* we are working with.
* For example, "primary" means that it will be a primary column, or "createDate" means that it will create a create
* date column.
*/
type ColumnMode = "regular" | "virtual" | "virtual-property" | "createDate" | "updateDate" | "deleteDate" | "version" | "treeChildrenCount" | "treeLevel" | "objectId" | "array";
/**
* Arguments for ColumnMetadata class.
*/
interface ColumnMetadataArgs {
/**
* Class to which column is applied.
*/
readonly target: Function | string;
/**
* Class's property name to which column is applied.
*/
readonly propertyName: string;
/**
* Column mode in which column will work.
*
* todo: find name better then "mode".
*/
readonly mode: ColumnMode;
/**
* Extra column options.
*/
readonly options: ColumnOptions;
}
/**
* Interface of the simple literal object with any string keys.
*/
interface ObjectLiteral {
[key: string]: any;
}
/**
* View options.
*/
interface ViewOptions {
/**
* Database name that this table resides in if it applies.
*/
database?: string;
/**
* Schema name that this table resides in if it applies.
*/
schema?: string;
/**
* View name.
*/
name: string;
/**
* View expression.
*/
expression: string | ((connection: DataSource) => SelectQueryBuilder<any>);
/**
* Indicates if view is materialized
*/
materialized?: boolean;
}
/**
* View in the database represented in this class.
*/
declare class View {
readonly "@instanceof": symbol;
/**
* Database name that this view resides in if it applies.
*/
database?: string;
/**
* Schema name that this view resides in if it applies.
*/
schema?: string;
/**
* View name
*/
name: string;
/**
* Indicates if view is materialized.
*/
materialized: boolean;
/**
* View Indices
*/
indices: TableIndex[];
/**
* View definition.
*/
expression: string | ((connection: DataSource) => SelectQueryBuilder<any>);
constructor(options?: ViewOptions);
/**
* Clones this table to a new table with all properties cloned.
*/
clone(): View;
/**
* Add index
*/
addIndex(index: TableIndex): void;
/**
* Remove index
*/
removeIndex(viewIndex: TableIndex): void;
/**
* Creates view from a given entity metadata.
*/
static create(entityMetadata: EntityMetadata, driver: Driver): View;
}
/**
* Naming strategy defines how auto-generated names for such things like table name, or table column gonna be
* generated.
*/
interface NamingStrategyInterface {
/**
* Naming strategy name.
*/
name?: string;
/**
* Normalizes table name.
*
* @param targetName Name of the target entity that can be used to generate a table name.
* @param userSpecifiedName For example if user specified a table name in a decorator, e.g. @Entity("name")
*/
tableName(targetName: string, userSpecifiedName: string | undefined): string;
/**
* Creates a table name for a junction table of a closure table.
*
* @param originalClosureTableName Name of the closure table which owns this junction table.
*/
closureJunctionTableName(originalClosureTableName: string): string;
/**
* Gets the table's column name from the given property name.
*/
columnName(propertyName: string, customName: string | undefined, embeddedPrefixes: string[]): string;
/**
* Gets the table's relation name from the given property name.
*/
relationName(propertyName: string): string;
/**
* Gets the table's primary key name from the given table name and column names.
*/
primaryKeyName(tableOrName: Table | string, columnNames: string[]): string;
/**
* Gets the table's unique constraint name from the given table name and column names.
*/
uniqueConstraintName(tableOrName: Table | string, columnNames: string[]): string;
/**
* Gets the relation constraint (UNIQUE or UNIQUE INDEX) name from the given table name, column names
* and WHERE condition, if UNIQUE INDEX used.
*/
relationConstraintName(tableOrName: Table | string, columnNames: string[], where?: string): string;
/**
* Gets the table's default constraint name from the given table name and column name.
*/
defaultConstraintName(tableOrName: Table | string, columnName: string): string;
/**
* Gets the name of the foreign key.
*/
foreignKeyName(tableOrName: Table | string, columnNames: string[], referencedTablePath?: string, referencedColumnNames?: string[]): string;
/**
* Gets the name of the index - simple and compose index.
*/
indexName(tableOrName: Table | View | string, columns: string[], where?: string): string;
/**
* Gets the name of the check constraint.
*
* "isEnum" parameter is used to indicate if this check constraint used
* to handle "simple-enum" type for databases that are not supporting "enum"
* type out of the box. If "true", constraint is ignored during CHECK constraints
* synchronization.
*/
checkConstraintName(tableOrName: Table | string, expression: string, isEnum?: boolean): string;
/**
* Gets the name of the exclusion constraint.
*/
exclusionConstraintName(tableOrName: Table | string, expression: string): string;
/**
* Gets the name of the join column used in the one-to-one and many-to-one relations.
*/
joinColumnName(relationName: string, referencedColumnName: string): string;
/**
* Gets the name of the join table used in the many-to-many relations.
*/
joinTableName(firstTableName: string, secondTableName: string, firstPropertyName: string, secondPropertyName: string): string;
/**
* Columns in join tables can have duplicate names in case of self-referencing.
* This method provide a resolution for such column names.
*/
joinTableColumnDuplicationPrefix(columnName: string, index: number): string;
/**
* Gets the name of the column used for columns in the junction tables.
*
* The reverse?:boolean parameter denotes if the joinTableColumnName is called for the junctionColumn (false)
* or the inverseJunctionColumns (true)
*/
joinTableColumnName(tableName: string, propertyName: string, columnName?: string): string;
/**
* Gets the name of the column used for columns in the junction tables from the invers side of the relationship.
*/
joinTableInverseColumnName(tableName: string, propertyName: string, columnName?: string): string;
/**
* Adds globally set prefix to the table name.
* This method is executed no matter if prefix was set or not.
* Table name is either user's given table name, either name generated from entity target.
* Note that table name comes here already normalized by #tableName method.
*/
prefixTableName(prefix: string, tableName: string): string;
/**
* Column names for nested sets.
*/
nestedSetColumnNames: {
left: string;
right: string;
};
/**
* Column name for materialized paths.
*/
materializedPathColumnName: string;
}
/**
* 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;
}
/**
* Arguments for EmbeddedMetadata class.
*/
interface EmbeddedMetadataArgs {
/**
* Class to which this column is applied.
*/
target: Function | string;
/**
* Class's property name to which this column is applied.
*/
propertyName: string;
/**
* Indicates if this embedded is array or not.
*/
isArray: boolean;
/**
* Prefix of the embedded, used instead of propertyName.
* If set to empty string, then prefix is not set at all.
*/
prefix?: string | boolean;
/**
* Type of the class to be embedded.
*/
type: (type?: any) => Function | string;
}
/**
* Arguments for RelationIdMetadataArgs class.
*/
interface RelationIdMetadataArgs {
/**
* Class to which this decorator is applied.
*/
readonly target: Function | string;
/**
* Class's property name to which this decorator is applied.
*/
readonly propertyName: string;
/**
* Target's relation which it should count.
*/
readonly relation: string | ((object: any) => any);
/**
* Alias of the joined (destination) table.
*/
readonly alias?: string;
/**
* Extra condition applied to "ON" section of join.
*/
readonly queryBuilderFactory?: (qb: SelectQueryBuilder<any>) => SelectQueryBuilder<any>;
}
/**
* 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;
}
/**
* All types that entity listener can be.
*/
type EventListenerType = "after-load" | "before-insert" | "after-insert" | "before-update" | "after-update" | "before-remove" | "after-remove" | "before-soft-remove" | "after-soft-remove" | "before-recover" | "after-recover";
/**
* Arguments for EntityListenerMetadata class.
*/
interface EntityListenerMetadataArgs {
/**
* Class to which listener is applied.
*/
readonly target: Function;
/**
* Class's property name to which listener is applied.
*/
readonly propertyName: string;
/**
* The type of the listener.
*/
readonly type: EventListenerType;
}
/**
* 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;
}
/**
* Arguments for UniqueMetadata class.
*/
interface UniqueMetadataArgs {
/**
* Class to which index is applied.
*/
target: Function | string;
/**
* Unique constraint name.
*/
name?: string;
/**
* Columns combination to be unique.
*/
columns?: ((object?: any) => any[] | {
[key: string]: number;
}) | string[];
/**
* Indicate if unique constraints can be deferred.
*/
deferrable?: DeferrableType;
}
/**
* 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 c