diff --git a/src/decorator/Check.ts b/src/decorator/Check.ts index 138eea1174..305fd1e5b8 100644 --- a/src/decorator/Check.ts +++ b/src/decorator/Check.ts @@ -6,21 +6,21 @@ import {CheckMetadataArgs} from "../metadata-args/CheckMetadataArgs"; * Can be used on entity property or on entity. * Can create checks with composite columns when used on entity. */ -export function Check(expression: string): Function; +export function Check(expression: string): ClassDecorator & PropertyDecorator; /** * Creates a database check. * Can be used on entity property or on entity. * Can create checks with composite columns when used on entity. */ -export function Check(name: string, expression: string): Function; +export function Check(name: string, expression: string): ClassDecorator & PropertyDecorator; /** * Creates a database check. * Can be used on entity property or on entity. * Can create checks with composite columns when used on entity. */ -export function Check(nameOrExpression: string, maybeExpression?: string): Function { +export function Check(nameOrExpression: string, maybeExpression?: string): ClassDecorator & PropertyDecorator { const name = maybeExpression ? nameOrExpression : undefined; const expression = maybeExpression ? maybeExpression : nameOrExpression; @@ -28,7 +28,7 @@ export function Check(nameOrExpression: string, maybeExpression?: string): Funct if (!expression) throw new Error(`Check expression is required`); - return function (clsOrObject: Function|Object, propertyName?: string) { + return function (clsOrObject: Function|Object, propertyName?: string | symbol) { getMetadataArgsStorage().checks.push({ target: propertyName ? clsOrObject.constructor : clsOrObject as Function, diff --git a/src/decorator/EntityRepository.ts b/src/decorator/EntityRepository.ts index 996acb395a..b97d58ce15 100644 --- a/src/decorator/EntityRepository.ts +++ b/src/decorator/EntityRepository.ts @@ -7,7 +7,7 @@ import { EntitySchema } from "../entity-schema/EntitySchema"; * Custom repository can manage some specific entity or just be generic. * Custom repository optionally can extend AbstractRepository, Repository or TreeRepository. */ -export function EntityRepository(entity?: Function | EntitySchema): Function { +export function EntityRepository(entity?: Function | EntitySchema): ClassDecorator { return function (target: Function) { getMetadataArgsStorage().entityRepositories.push({ diff --git a/src/decorator/Exclusion.ts b/src/decorator/Exclusion.ts index 75f3434a94..d05394cab8 100644 --- a/src/decorator/Exclusion.ts +++ b/src/decorator/Exclusion.ts @@ -6,21 +6,21 @@ import {ExclusionMetadataArgs} from "../metadata-args/ExclusionMetadataArgs"; * Can be used on entity. * Can create exclusions with composite columns when used on entity. */ -export function Exclusion(expression: string): Function; +export function Exclusion(expression: string): ClassDecorator & PropertyDecorator; /** * Creates a database exclusion. * Can be used on entity. * Can create exclusions with composite columns when used on entity. */ -export function Exclusion(name: string, expression: string): Function; +export function Exclusion(name: string, expression: string): ClassDecorator & PropertyDecorator; /** * Creates a database exclusion. * Can be used on entity. * Can create exclusions with composite columns when used on entity. */ -export function Exclusion(nameOrExpression: string, maybeExpression?: string): Function { +export function Exclusion(nameOrExpression: string, maybeExpression?: string): ClassDecorator & PropertyDecorator { const name = maybeExpression ? nameOrExpression : undefined; const expression = maybeExpression ? maybeExpression : nameOrExpression; @@ -28,7 +28,7 @@ export function Exclusion(nameOrExpression: string, maybeExpression?: string): F if (!expression) throw new Error(`Exclusion expression is required`); - return function (clsOrObject: Function|Object, propertyName?: string) { + return function (clsOrObject: Function|Object, propertyName?: string | symbol) { getMetadataArgsStorage().exclusions.push({ target: propertyName ? clsOrObject.constructor : clsOrObject as Function, diff --git a/src/decorator/Generated.ts b/src/decorator/Generated.ts index 9857c95e49..934ccd4b6c 100644 --- a/src/decorator/Generated.ts +++ b/src/decorator/Generated.ts @@ -10,7 +10,7 @@ import {GeneratedMetadataArgs} from "../metadata-args/GeneratedMetadataArgs"; * * Note, some databases do not support non-primary generation columns. */ -export function Generated(strategy: "increment"|"uuid"|"rowid" = "increment"): Function { +export function Generated(strategy: "increment"|"uuid"|"rowid" = "increment"): PropertyDecorator { return function (object: Object, propertyName: string) { getMetadataArgsStorage().generations.push({ diff --git a/src/decorator/Index.ts b/src/decorator/Index.ts index 17e57ea5c0..2bc63d6826 100644 --- a/src/decorator/Index.ts +++ b/src/decorator/Index.ts @@ -6,49 +6,49 @@ import {IndexMetadataArgs} from "../metadata-args/IndexMetadataArgs"; * Can be used on entity property or on entity. * Can create indices with composite columns when used on entity. */ -export function Index(options?: IndexOptions): Function; +export function Index(options?: IndexOptions): ClassDecorator & PropertyDecorator; /** * Creates a database index. * Can be used on entity property or on entity. * Can create indices with composite columns when used on entity. */ -export function Index(name: string, options?: IndexOptions): Function; +export function Index(name: string, options?: IndexOptions): ClassDecorator & PropertyDecorator; /** * Creates a database index. * Can be used on entity property or on entity. * Can create indices with composite columns when used on entity. */ -export function Index(name: string, options: { synchronize: false }): Function; +export function Index(name: string, options: { synchronize: false }): ClassDecorator & PropertyDecorator; /** * Creates a database index. * Can be used on entity property or on entity. * Can create indices with composite columns when used on entity. */ -export function Index(name: string, fields: string[], options?: IndexOptions): Function; +export function Index(name: string, fields: string[], options?: IndexOptions): ClassDecorator & PropertyDecorator; /** * Creates a database index. * Can be used on entity property or on entity. * Can create indices with composite columns when used on entity. */ -export function Index(fields: string[], options?: IndexOptions): Function; +export function Index(fields: string[], options?: IndexOptions): ClassDecorator & PropertyDecorator; /** * Creates a database index. * Can be used on entity property or on entity. * Can create indices with composite columns when used on entity. */ -export function Index(fields: (object?: any) => (any[]|{ [key: string]: number }), options?: IndexOptions): Function; +export function Index(fields: (object?: any) => (any[]|{ [key: string]: number }), options?: IndexOptions): ClassDecorator & PropertyDecorator; /** * Creates a database index. * Can be used on entity property or on entity. * Can create indices with composite columns when used on entity. */ -export function Index(name: string, fields: (object?: any) => (any[]|{ [key: string]: number }), options?: IndexOptions): Function; +export function Index(name: string, fields: (object?: any) => (any[]|{ [key: string]: number }), options?: IndexOptions): ClassDecorator & PropertyDecorator; /** * Creates a database index. @@ -57,7 +57,7 @@ export function Index(name: string, fields: (object?: any) => (any[]|{ [key: str */ export function Index(nameOrFieldsOrOptions?: string|string[]|((object: any) => (any[]|{ [key: string]: number }))|IndexOptions, maybeFieldsOrOptions?: ((object?: any) => (any[]|{ [key: string]: number }))|IndexOptions|string[]|{ synchronize: false }, - maybeOptions?: IndexOptions): Function { + maybeOptions?: IndexOptions): ClassDecorator & PropertyDecorator { // normalize parameters const name = typeof nameOrFieldsOrOptions === "string" ? nameOrFieldsOrOptions : undefined; @@ -66,7 +66,7 @@ export function Index(nameOrFieldsOrOptions?: string|string[]|((object: any) => if (!options) options = (typeof maybeFieldsOrOptions === "object" && !Array.isArray(maybeFieldsOrOptions)) ? maybeFieldsOrOptions as IndexOptions : maybeOptions; - return function (clsOrObject: Function|Object, propertyName?: string) { + return function (clsOrObject: Function|Object, propertyName?: string | symbol) { getMetadataArgsStorage().indices.push({ target: propertyName ? clsOrObject.constructor : clsOrObject as Function, diff --git a/src/decorator/Unique.ts b/src/decorator/Unique.ts index 871e25c58a..1923af52ad 100644 --- a/src/decorator/Unique.ts +++ b/src/decorator/Unique.ts @@ -1,39 +1,54 @@ -import {getMetadataArgsStorage} from "../index"; -import {UniqueMetadataArgs} from "../metadata-args/UniqueMetadataArgs"; +import { getMetadataArgsStorage } from "../index"; +import { UniqueMetadataArgs } from "../metadata-args/UniqueMetadataArgs"; /** * Composite unique constraint must be set on entity classes and must specify entity's fields to be unique. */ -export function Unique(name: string, fields: string[]): Function; +export function Unique(name: string, fields: string[]): ClassDecorator & PropertyDecorator; /** * Composite unique constraint must be set on entity classes and must specify entity's fields to be unique. */ -export function Unique(fields: string[]): Function; +export function Unique(fields: string[]): ClassDecorator & PropertyDecorator; /** * Composite unique constraint must be set on entity classes and must specify entity's fields to be unique. */ -export function Unique(fields: (object?: any) => (any[]|{ [key: string]: number })): Function; +export function Unique(fields: (object?: any) => (any[] | { [key: string]: number })): ClassDecorator & PropertyDecorator; /** * Composite unique constraint must be set on entity classes and must specify entity's fields to be unique. */ -export function Unique(name: string, fields: (object?: any) => (any[]|{ [key: string]: number })): Function; +export function Unique(name: string, fields: (object?: any) => (any[] | { [key: string]: number })): ClassDecorator & PropertyDecorator; /** * Composite unique constraint must be set on entity classes and must specify entity's fields to be unique. */ -export function Unique(nameOrFields?: string|string[]|((object: any) => (any[]|{ [key: string]: number })), - maybeFields?: ((object?: any) => (any[]|{ [key: string]: number }))|string[]): Function { +export function Unique(nameOrFields?: string | string[] | ((object: any) => (any[] | { [key: string]: number })), + maybeFields?: ((object?: any) => (any[] | { [key: string]: number })) | string[]): ClassDecorator & PropertyDecorator { const name = typeof nameOrFields === "string" ? nameOrFields : undefined; - const fields = typeof nameOrFields === "string" ? <((object?: any) => (any[]|{ [key: string]: number }))|string[]> maybeFields : nameOrFields as string[]; + const fields = typeof nameOrFields === "string" ? <((object?: any) => (any[] | { [key: string]: number })) | string[]>maybeFields : nameOrFields as string[]; + + return function (clsOrObject: Function | Object, propertyName?: string | symbol) { + + let columns = fields; + + if (propertyName !== undefined) { + switch (typeof (propertyName)) { + case "string": + columns = [propertyName]; + break; + + case "symbol": + columns = [propertyName.toString()]; + break; + } + } - return function (clsOrObject: Function|Object, propertyName?: string) { const args: UniqueMetadataArgs = { target: propertyName ? clsOrObject.constructor : clsOrObject as Function, name: name, - columns: propertyName ? [propertyName] : fields + columns, }; getMetadataArgsStorage().uniques.push(args); }; diff --git a/src/decorator/columns/Column.ts b/src/decorator/columns/Column.ts index 834c33119e..84e937a6df 100644 --- a/src/decorator/columns/Column.ts +++ b/src/decorator/columns/Column.ts @@ -20,67 +20,67 @@ import { GeneratedMetadataArgs } from "../../metadata-args/GeneratedMetadataArgs * Column decorator is used to mark a specific class property as a table column. Only properties decorated with this * decorator will be persisted to the database when entity be saved. */ -export function Column(): Function; +export function Column(): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. * Only properties decorated with this decorator will be persisted to the database when entity be saved. */ -export function Column(options: ColumnOptions): Function; +export function Column(options: ColumnOptions): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. * Only properties decorated with this decorator will be persisted to the database when entity be saved. */ -export function Column(type: SimpleColumnType, options?: ColumnCommonOptions): Function; +export function Column(type: SimpleColumnType, options?: ColumnCommonOptions): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. * Only properties decorated with this decorator will be persisted to the database when entity be saved. */ -export function Column(type: SpatialColumnType, options?: ColumnCommonOptions & SpatialColumnOptions): Function; +export function Column(type: SpatialColumnType, options?: ColumnCommonOptions & SpatialColumnOptions): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. * Only properties decorated with this decorator will be persisted to the database when entity be saved. */ -export function Column(type: WithLengthColumnType, options?: ColumnCommonOptions & ColumnWithLengthOptions): Function; +export function Column(type: WithLengthColumnType, options?: ColumnCommonOptions & ColumnWithLengthOptions): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. * Only properties decorated with this decorator will be persisted to the database when entity be saved. */ -export function Column(type: WithWidthColumnType, options?: ColumnCommonOptions & ColumnWithWidthOptions): Function; +export function Column(type: WithWidthColumnType, options?: ColumnCommonOptions & ColumnWithWidthOptions): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. * Only properties decorated with this decorator will be persisted to the database when entity be saved. */ -export function Column(type: WithPrecisionColumnType, options?: ColumnCommonOptions & ColumnNumericOptions): Function; +export function Column(type: WithPrecisionColumnType, options?: ColumnCommonOptions & ColumnNumericOptions): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. * Only properties decorated with this decorator will be persisted to the database when entity be saved. */ -export function Column(type: "enum", options?: ColumnCommonOptions & ColumnEnumOptions): Function; +export function Column(type: "enum", options?: ColumnCommonOptions & ColumnEnumOptions): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. * Only properties decorated with this decorator will be persisted to the database when entity be saved. */ -export function Column(type: "simple-enum", options?: ColumnCommonOptions & ColumnEnumOptions): Function; +export function Column(type: "simple-enum", options?: ColumnCommonOptions & ColumnEnumOptions): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. * Only properties decorated with this decorator will be persisted to the database when entity be saved. */ -export function Column(type: "set", options?: ColumnCommonOptions & ColumnEnumOptions): Function; +export function Column(type: "set", options?: ColumnCommonOptions & ColumnEnumOptions): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. * Only properties decorated with this decorator will be persisted to the database when entity be saved. */ -export function Column(type: "hstore", options?: ColumnCommonOptions & ColumnHstoreOptions): Function; +export function Column(type: "hstore", options?: ColumnCommonOptions & ColumnHstoreOptions): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. @@ -90,13 +90,13 @@ export function Column(type: "hstore", options?: ColumnCommonOptions & ColumnHst * single table of the entity where Embedded is used. And on hydration all columns which supposed to be in the * embedded will be mapped to it from the single table. */ -export function Column(type: (type?: any) => Function, options?: ColumnEmbeddedOptions): Function; +export function Column(type: (type?: any) => Function, options?: ColumnEmbeddedOptions): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. * Only properties decorated with this decorator will be persisted to the database when entity be saved. */ -export function Column(typeOrOptions?: ((type?: any) => Function)|ColumnType|(ColumnOptions&ColumnEmbeddedOptions), options?: (ColumnOptions&ColumnEmbeddedOptions)): Function { +export function Column(typeOrOptions?: ((type?: any) => Function)|ColumnType|(ColumnOptions&ColumnEmbeddedOptions), options?: (ColumnOptions&ColumnEmbeddedOptions)): PropertyDecorator { return function (object: Object, propertyName: string) { // normalize parameters diff --git a/src/decorator/columns/CreateDateColumn.ts b/src/decorator/columns/CreateDateColumn.ts index 6d9acd802d..b14bf5c4f3 100644 --- a/src/decorator/columns/CreateDateColumn.ts +++ b/src/decorator/columns/CreateDateColumn.ts @@ -6,7 +6,7 @@ import {ColumnMetadataArgs} from "../../metadata-args/ColumnMetadataArgs"; * Creation date is generated and inserted only once, * at the first time when you create an object, the value is inserted into the table, and is never touched again. */ -export function CreateDateColumn(options?: ColumnOptions): Function { +export function CreateDateColumn(options?: ColumnOptions): PropertyDecorator { return function (object: Object, propertyName: string) { getMetadataArgsStorage().columns.push({ target: object.constructor, diff --git a/src/decorator/columns/DeleteDateColumn.ts b/src/decorator/columns/DeleteDateColumn.ts index 35ea43b848..deece8bba0 100644 --- a/src/decorator/columns/DeleteDateColumn.ts +++ b/src/decorator/columns/DeleteDateColumn.ts @@ -5,7 +5,7 @@ import { ColumnMetadataArgs } from "../../metadata-args/ColumnMetadataArgs"; * This column will store a delete date of the soft-deleted object. * This date is being updated each time you soft-delete the object. */ -export function DeleteDateColumn(options?: ColumnOptions): Function { +export function DeleteDateColumn(options?: ColumnOptions): PropertyDecorator { return function(object: Object, propertyName: string) { getMetadataArgsStorage().columns.push({ target: object.constructor, diff --git a/src/decorator/columns/ObjectIdColumn.ts b/src/decorator/columns/ObjectIdColumn.ts index 257aebf347..5feeb201de 100644 --- a/src/decorator/columns/ObjectIdColumn.ts +++ b/src/decorator/columns/ObjectIdColumn.ts @@ -5,7 +5,7 @@ import {ColumnMetadataArgs} from "../../metadata-args/ColumnMetadataArgs"; * Special type of column that is available only for MongoDB database. * Marks your entity's column to be an object id. */ -export function ObjectIdColumn(options?: ColumnOptions): Function { +export function ObjectIdColumn(options?: ColumnOptions): PropertyDecorator { return function (object: Object, propertyName: string) { // if column options are not given then create a new empty options diff --git a/src/decorator/columns/PrimaryColumn.ts b/src/decorator/columns/PrimaryColumn.ts index 9c56828bf6..4ac950cc83 100644 --- a/src/decorator/columns/PrimaryColumn.ts +++ b/src/decorator/columns/PrimaryColumn.ts @@ -9,21 +9,21 @@ import { GeneratedMetadataArgs } from "../../metadata-args/GeneratedMetadataArgs * Only properties decorated with this decorator will be persisted to the database when entity be saved. * Primary columns also creates a PRIMARY KEY for this column in a db. */ -export function PrimaryColumn(options?: ColumnOptions): Function; +export function PrimaryColumn(options?: ColumnOptions): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. * Only properties decorated with this decorator will be persisted to the database when entity be saved. * Primary columns also creates a PRIMARY KEY for this column in a db. */ -export function PrimaryColumn(type?: ColumnType, options?: ColumnOptions): Function; +export function PrimaryColumn(type?: ColumnType, options?: ColumnOptions): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. * Only properties decorated with this decorator will be persisted to the database when entity be saved. * Primary columns also creates a PRIMARY KEY for this column in a db. */ -export function PrimaryColumn(typeOrOptions?: ColumnType|ColumnOptions, options?: ColumnOptions): Function { +export function PrimaryColumn(typeOrOptions?: ColumnType|ColumnOptions, options?: ColumnOptions): PropertyDecorator { return function (object: Object, propertyName: string) { // normalize parameters diff --git a/src/decorator/columns/PrimaryGeneratedColumn.ts b/src/decorator/columns/PrimaryGeneratedColumn.ts index afa6c81336..14fbffa55a 100644 --- a/src/decorator/columns/PrimaryGeneratedColumn.ts +++ b/src/decorator/columns/PrimaryGeneratedColumn.ts @@ -6,27 +6,27 @@ import {GeneratedMetadataArgs} from "../../metadata-args/GeneratedMetadataArgs"; /** * Column decorator is used to mark a specific class property as a table column. */ -export function PrimaryGeneratedColumn(): Function; +export function PrimaryGeneratedColumn(): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. */ -export function PrimaryGeneratedColumn(options: PrimaryGeneratedColumnNumericOptions): Function; +export function PrimaryGeneratedColumn(options: PrimaryGeneratedColumnNumericOptions): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. */ -export function PrimaryGeneratedColumn(strategy: "increment", options?: PrimaryGeneratedColumnNumericOptions): Function; +export function PrimaryGeneratedColumn(strategy: "increment", options?: PrimaryGeneratedColumnNumericOptions): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. */ -export function PrimaryGeneratedColumn(strategy: "uuid", options?: PrimaryGeneratedColumnUUIDOptions): Function; +export function PrimaryGeneratedColumn(strategy: "uuid", options?: PrimaryGeneratedColumnUUIDOptions): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. */ -export function PrimaryGeneratedColumn(strategy: "rowid", options?: PrimaryGeneratedColumnUUIDOptions): Function; +export function PrimaryGeneratedColumn(strategy: "rowid", options?: PrimaryGeneratedColumnUUIDOptions): PropertyDecorator; /** * Column decorator is used to mark a specific class property as a table column. @@ -34,7 +34,7 @@ export function PrimaryGeneratedColumn(strategy: "rowid", options?: PrimaryGener * This column creates an integer PRIMARY COLUMN with generated set to true. */ export function PrimaryGeneratedColumn(strategyOrOptions?: "increment"|"uuid"|"rowid"|PrimaryGeneratedColumnNumericOptions|PrimaryGeneratedColumnUUIDOptions, - maybeOptions?: PrimaryGeneratedColumnNumericOptions|PrimaryGeneratedColumnUUIDOptions): Function { + maybeOptions?: PrimaryGeneratedColumnNumericOptions|PrimaryGeneratedColumnUUIDOptions): PropertyDecorator { // normalize parameters const options: ColumnOptions = {}; diff --git a/src/decorator/columns/UpdateDateColumn.ts b/src/decorator/columns/UpdateDateColumn.ts index f4895e76b4..f4627a0df4 100644 --- a/src/decorator/columns/UpdateDateColumn.ts +++ b/src/decorator/columns/UpdateDateColumn.ts @@ -5,7 +5,7 @@ import {ColumnMetadataArgs} from "../../metadata-args/ColumnMetadataArgs"; * This column will store an update date of the updated object. * This date is being updated each time you persist the object. */ -export function UpdateDateColumn(options?: ColumnOptions): Function { +export function UpdateDateColumn(options?: ColumnOptions): PropertyDecorator { return function (object: Object, propertyName: string) { getMetadataArgsStorage().columns.push({ diff --git a/src/decorator/columns/VersionColumn.ts b/src/decorator/columns/VersionColumn.ts index f1f14984a3..1779869783 100644 --- a/src/decorator/columns/VersionColumn.ts +++ b/src/decorator/columns/VersionColumn.ts @@ -6,7 +6,7 @@ import {ColumnMetadataArgs} from "../../metadata-args/ColumnMetadataArgs"; * Every time your entity will be persisted, this number will be increased by one - * so you can organize visioning and update strategies of your entity. */ -export function VersionColumn(options?: ColumnOptions): Function { +export function VersionColumn(options?: ColumnOptions): PropertyDecorator { return function (object: Object, propertyName: string) { getMetadataArgsStorage().columns.push({ diff --git a/src/decorator/columns/ViewColumn.ts b/src/decorator/columns/ViewColumn.ts index e3df7bcd4d..11356f66e3 100644 --- a/src/decorator/columns/ViewColumn.ts +++ b/src/decorator/columns/ViewColumn.ts @@ -5,7 +5,7 @@ import { ViewColumnOptions } from "../options/ViewColumnOptions"; /** * ViewColumn decorator is used to mark a specific class property as a view column. */ -export function ViewColumn(options?: ViewColumnOptions): Function { +export function ViewColumn(options?: ViewColumnOptions): PropertyDecorator { return function (object: Object, propertyName: string) { getMetadataArgsStorage().columns.push({ target: object.constructor, diff --git a/src/decorator/entity-view/ViewEntity.ts b/src/decorator/entity-view/ViewEntity.ts index 50cb0f96a4..7223ed8ce5 100644 --- a/src/decorator/entity-view/ViewEntity.ts +++ b/src/decorator/entity-view/ViewEntity.ts @@ -6,19 +6,19 @@ import {ViewEntityOptions} from "../options/ViewEntityOptions"; * This decorator is used to mark classes that will be an entity view. * Database schema will be created for all classes decorated with it, and Repository can be retrieved and used for it. */ -export function ViewEntity(options?: ViewEntityOptions): Function; +export function ViewEntity(options?: ViewEntityOptions): ClassDecorator; /** * This decorator is used to mark classes that will be an entity view. * Database schema will be created for all classes decorated with it, and Repository can be retrieved and used for it. */ -export function ViewEntity(name?: string, options?: ViewEntityOptions): Function; +export function ViewEntity(name?: string, options?: ViewEntityOptions): ClassDecorator; /** * This decorator is used to mark classes that will be an entity view. * Database schema will be created for all classes decorated with it, and Repository can be retrieved and used for it. */ -export function ViewEntity(nameOrOptions?: string|ViewEntityOptions, maybeOptions?: ViewEntityOptions): Function { +export function ViewEntity(nameOrOptions?: string|ViewEntityOptions, maybeOptions?: ViewEntityOptions): ClassDecorator { const options = (typeof nameOrOptions === "object" ? nameOrOptions as ViewEntityOptions : maybeOptions) || {}; const name = typeof nameOrOptions === "string" ? nameOrOptions : options.name; diff --git a/src/decorator/entity/ChildEntity.ts b/src/decorator/entity/ChildEntity.ts index 644b7d5bab..aee1b9746a 100644 --- a/src/decorator/entity/ChildEntity.ts +++ b/src/decorator/entity/ChildEntity.ts @@ -5,7 +5,7 @@ import {DiscriminatorValueMetadataArgs} from "../../metadata-args/DiscriminatorV /** * Special type of the table used in the single-table inherited tables. */ -export function ChildEntity(discriminatorValue?: any) { +export function ChildEntity(discriminatorValue?: any): ClassDecorator { return function (target: Function) { // register a table metadata diff --git a/src/decorator/entity/TableInheritance.ts b/src/decorator/entity/TableInheritance.ts index 264743713e..f716b5c227 100644 --- a/src/decorator/entity/TableInheritance.ts +++ b/src/decorator/entity/TableInheritance.ts @@ -4,7 +4,7 @@ import {InheritanceMetadataArgs} from "../../metadata-args/InheritanceMetadataAr /** * Sets for entity to use table inheritance pattern. */ -export function TableInheritance(options?: { pattern?: "STI"/*|"CTI"*/, column?: string|ColumnOptions }) { +export function TableInheritance(options?: { pattern?: "STI"/*|"CTI"*/, column?: string|ColumnOptions }): ClassDecorator { return function (target: Function) { getMetadataArgsStorage().inheritances.push({ diff --git a/src/decorator/listeners/AfterInsert.ts b/src/decorator/listeners/AfterInsert.ts index 68c2c1a11c..48be17d67d 100644 --- a/src/decorator/listeners/AfterInsert.ts +++ b/src/decorator/listeners/AfterInsert.ts @@ -5,7 +5,7 @@ import {EntityListenerMetadataArgs} from "../../metadata-args/EntityListenerMeta /** * Calls a method on which this decorator is applied after this entity insertion. */ -export function AfterInsert() { +export function AfterInsert(): PropertyDecorator { return function (object: Object, propertyName: string) { getMetadataArgsStorage().entityListeners.push({ diff --git a/src/decorator/listeners/AfterLoad.ts b/src/decorator/listeners/AfterLoad.ts index 8b810feed7..02e2fe81c6 100644 --- a/src/decorator/listeners/AfterLoad.ts +++ b/src/decorator/listeners/AfterLoad.ts @@ -5,7 +5,7 @@ import {EntityListenerMetadataArgs} from "../../metadata-args/EntityListenerMeta /** * Calls a method on which this decorator is applied after entity is loaded. */ -export function AfterLoad() { +export function AfterLoad(): PropertyDecorator { return function (object: Object, propertyName: string) { getMetadataArgsStorage().entityListeners.push({ diff --git a/src/decorator/listeners/AfterRemove.ts b/src/decorator/listeners/AfterRemove.ts index e9e7d2549c..a2f00f63f4 100644 --- a/src/decorator/listeners/AfterRemove.ts +++ b/src/decorator/listeners/AfterRemove.ts @@ -5,7 +5,7 @@ import {EntityListenerMetadataArgs} from "../../metadata-args/EntityListenerMeta /** * Calls a method on which this decorator is applied after this entity removal. */ -export function AfterRemove() { +export function AfterRemove(): PropertyDecorator { return function (object: Object, propertyName: string) { getMetadataArgsStorage().entityListeners.push({ diff --git a/src/decorator/listeners/AfterUpdate.ts b/src/decorator/listeners/AfterUpdate.ts index fadb31815f..f77241e095 100644 --- a/src/decorator/listeners/AfterUpdate.ts +++ b/src/decorator/listeners/AfterUpdate.ts @@ -5,7 +5,7 @@ import {EntityListenerMetadataArgs} from "../../metadata-args/EntityListenerMeta /** * Calls a method on which this decorator is applied after this entity update. */ -export function AfterUpdate() { +export function AfterUpdate(): PropertyDecorator { return function (object: Object, propertyName: string) { getMetadataArgsStorage().entityListeners.push({ diff --git a/src/decorator/listeners/BeforeInsert.ts b/src/decorator/listeners/BeforeInsert.ts index 10db63ad14..6f2d4c7d98 100644 --- a/src/decorator/listeners/BeforeInsert.ts +++ b/src/decorator/listeners/BeforeInsert.ts @@ -5,7 +5,7 @@ import {EntityListenerMetadataArgs} from "../../metadata-args/EntityListenerMeta /** * Calls a method on which this decorator is applied before this entity insertion. */ -export function BeforeInsert() { +export function BeforeInsert(): PropertyDecorator { return function (object: Object, propertyName: string) { getMetadataArgsStorage().entityListeners.push({ diff --git a/src/decorator/listeners/BeforeRemove.ts b/src/decorator/listeners/BeforeRemove.ts index e108e2e9f6..0fcadd1fa4 100644 --- a/src/decorator/listeners/BeforeRemove.ts +++ b/src/decorator/listeners/BeforeRemove.ts @@ -5,7 +5,7 @@ import {EntityListenerMetadataArgs} from "../../metadata-args/EntityListenerMeta /** * Calls a method on which this decorator is applied before this entity removal. */ -export function BeforeRemove() { +export function BeforeRemove(): PropertyDecorator { return function (object: Object, propertyName: string) { getMetadataArgsStorage().entityListeners.push({ diff --git a/src/decorator/listeners/BeforeUpdate.ts b/src/decorator/listeners/BeforeUpdate.ts index 753e3a1532..d4a15d36d2 100644 --- a/src/decorator/listeners/BeforeUpdate.ts +++ b/src/decorator/listeners/BeforeUpdate.ts @@ -5,7 +5,7 @@ import {EntityListenerMetadataArgs} from "../../metadata-args/EntityListenerMeta /** * Calls a method on which this decorator is applied before this entity update. */ -export function BeforeUpdate() { +export function BeforeUpdate(): PropertyDecorator { return function (object: Object, propertyName: string) { getMetadataArgsStorage().entityListeners.push({ diff --git a/src/decorator/listeners/EventSubscriber.ts b/src/decorator/listeners/EventSubscriber.ts index 99741d0b9a..ea13dc44a8 100644 --- a/src/decorator/listeners/EventSubscriber.ts +++ b/src/decorator/listeners/EventSubscriber.ts @@ -5,7 +5,7 @@ import {EntitySubscriberMetadataArgs} from "../../metadata-args/EntitySubscriber * Classes decorated with this decorator will listen to ORM events and their methods will be triggered when event * occurs. Those classes must implement EventSubscriberInterface interface. */ -export function EventSubscriber() { +export function EventSubscriber(): ClassDecorator { return function (target: Function) { getMetadataArgsStorage().entitySubscribers.push({ diff --git a/src/decorator/relations/JoinColumn.ts b/src/decorator/relations/JoinColumn.ts index 3bded3a080..f619e374ad 100644 --- a/src/decorator/relations/JoinColumn.ts +++ b/src/decorator/relations/JoinColumn.ts @@ -6,28 +6,28 @@ import {JoinColumnMetadataArgs} from "../../metadata-args/JoinColumnMetadataArgs * It also can be used on both one-to-one and many-to-one relations to specify custom column name * or custom referenced column. */ -export function JoinColumn(): Function; +export function JoinColumn(): PropertyDecorator; /** * JoinColumn decorator used on one-to-one relations to specify owner side of relationship. * It also can be used on both one-to-one and many-to-one relations to specify custom column name * or custom referenced column. */ -export function JoinColumn(options: JoinColumnOptions): Function; +export function JoinColumn(options: JoinColumnOptions): PropertyDecorator; /** * JoinColumn decorator used on one-to-one relations to specify owner side of relationship. * It also can be used on both one-to-one and many-to-one relations to specify custom column name * or custom referenced column. */ -export function JoinColumn(options: JoinColumnOptions[]): Function; +export function JoinColumn(options: JoinColumnOptions[]): PropertyDecorator; /** * JoinColumn decorator used on one-to-one relations to specify owner side of relationship. * It also can be used on both one-to-one and many-to-one relations to specify custom column name * or custom referenced column. */ -export function JoinColumn(optionsOrOptionsArray?: JoinColumnOptions|JoinColumnOptions[]): Function { +export function JoinColumn(optionsOrOptionsArray?: JoinColumnOptions|JoinColumnOptions[]): PropertyDecorator { return function (object: Object, propertyName: string) { const options = Array.isArray(optionsOrOptionsArray) ? optionsOrOptionsArray : [optionsOrOptionsArray || {}]; options.forEach(options => { diff --git a/src/decorator/relations/JoinTable.ts b/src/decorator/relations/JoinTable.ts index ed7ddab587..c9d95b0909 100644 --- a/src/decorator/relations/JoinTable.ts +++ b/src/decorator/relations/JoinTable.ts @@ -6,25 +6,25 @@ import {JoinTableMultipleColumnsOptions} from "../options/JoinTableMultipleColum * JoinTable decorator is used in many-to-many relationship to specify owner side of relationship. * Its also used to set a custom junction table's name, column names and referenced columns. */ -export function JoinTable(): Function; +export function JoinTable(): PropertyDecorator; /** * JoinTable decorator is used in many-to-many relationship to specify owner side of relationship. * Its also used to set a custom junction table's name, column names and referenced columns. */ -export function JoinTable(options: JoinTableOptions): Function; +export function JoinTable(options: JoinTableOptions): PropertyDecorator; /** * JoinTable decorator is used in many-to-many relationship to specify owner side of relationship. * Its also used to set a custom junction table's name, column names and referenced columns. */ -export function JoinTable(options: JoinTableMultipleColumnsOptions): Function; +export function JoinTable(options: JoinTableMultipleColumnsOptions): PropertyDecorator; /** * JoinTable decorator is used in many-to-many relationship to specify owner side of relationship. * Its also used to set a custom junction table's name, column names and referenced columns. */ -export function JoinTable(options?: JoinTableOptions|JoinTableMultipleColumnsOptions): Function { +export function JoinTable(options?: JoinTableOptions|JoinTableMultipleColumnsOptions): PropertyDecorator { return function (object: Object, propertyName: string) { options = options || {} as JoinTableOptions|JoinTableMultipleColumnsOptions; getMetadataArgsStorage().joinTables.push({ diff --git a/src/decorator/relations/ManyToMany.ts b/src/decorator/relations/ManyToMany.ts index f287b434f5..e07a124f04 100644 --- a/src/decorator/relations/ManyToMany.ts +++ b/src/decorator/relations/ManyToMany.ts @@ -7,7 +7,7 @@ import {RelationMetadataArgs} from "../../metadata-args/RelationMetadataArgs"; * entity1 and entity2 ids. This is owner side of the relationship. */ export function ManyToMany(typeFunctionOrTarget: string|((type?: any) => ObjectType), - options?: RelationOptions): Function; + options?: RelationOptions): PropertyDecorator; /** * Many-to-many is a type of relationship when Entity1 can have multiple instances of Entity2, and Entity2 can have @@ -16,7 +16,7 @@ export function ManyToMany(typeFunctionOrTarget: string|((type?: any) => Obje */ export function ManyToMany(typeFunctionOrTarget: string|((type?: any) => ObjectType), inverseSide?: string|((object: T) => any), - options?: RelationOptions): Function; + options?: RelationOptions): PropertyDecorator; /** * Many-to-many is a type of relationship when Entity1 can have multiple instances of Entity2, and Entity2 can have @@ -25,7 +25,7 @@ export function ManyToMany(typeFunctionOrTarget: string|((type?: any) => Obje */ export function ManyToMany(typeFunctionOrTarget: string|((type?: any) => ObjectType), inverseSideOrOptions?: string|((object: T) => any)|RelationOptions, - options?: RelationOptions): Function { + options?: RelationOptions): PropertyDecorator { // normalize parameters let inverseSideProperty: string|((object: T) => any); diff --git a/src/decorator/relations/ManyToOne.ts b/src/decorator/relations/ManyToOne.ts index 7c0031e6c0..0c60ba0bf6 100644 --- a/src/decorator/relations/ManyToOne.ts +++ b/src/decorator/relations/ManyToOne.ts @@ -6,7 +6,7 @@ import {RelationMetadataArgs} from "../../metadata-args/RelationMetadataArgs"; * Entity2 can have a multiple instances of Entity1. Entity1 is an owner of the relationship, and storages Entity2 id * on its own side. */ -export function ManyToOne(typeFunctionOrTarget: string|((type?: any) => ObjectType), options?: RelationOptions): Function; +export function ManyToOne(typeFunctionOrTarget: string|((type?: any) => ObjectType), options?: RelationOptions): PropertyDecorator; /** * Many-to-one relation allows to create type of relation when Entity1 can have single instance of Entity2, but @@ -15,7 +15,7 @@ export function ManyToOne(typeFunctionOrTarget: string|((type?: any) => Objec */ export function ManyToOne(typeFunctionOrTarget: string|((type?: any) => ObjectType), inverseSide?: string|((object: T) => any), - options?: RelationOptions): Function; + options?: RelationOptions): PropertyDecorator; /** * Many-to-one relation allows to create type of relation when Entity1 can have single instance of Entity2, but @@ -24,7 +24,7 @@ export function ManyToOne(typeFunctionOrTarget: string|((type?: any) => Objec */ export function ManyToOne(typeFunctionOrTarget: string|((type?: any) => ObjectType), inverseSideOrOptions?: string|((object: T) => any)|RelationOptions, - options?: RelationOptions): Function { + options?: RelationOptions): PropertyDecorator { // normalize parameters let inverseSideProperty: string|((object: T) => any); diff --git a/src/decorator/relations/OneToMany.ts b/src/decorator/relations/OneToMany.ts index 80e1f7175c..802c754e26 100644 --- a/src/decorator/relations/OneToMany.ts +++ b/src/decorator/relations/OneToMany.ts @@ -5,7 +5,7 @@ import {RelationMetadataArgs} from "../../metadata-args/RelationMetadataArgs"; * One-to-many relation allows to create type of relation when Entity2 can have multiple instances of Entity1. * Entity1 have only one Entity2. Entity1 is an owner of the relationship, and storages Entity2 id on its own side. */ -export function OneToMany(typeFunctionOrTarget: string|((type?: any) => ObjectType), inverseSide: string|((object: T) => any), options?: RelationOptions): Function { +export function OneToMany(typeFunctionOrTarget: string|((type?: any) => ObjectType), inverseSide: string|((object: T) => any), options?: RelationOptions): PropertyDecorator { return function (object: Object, propertyName: string) { if (!options) options = {} as RelationOptions; diff --git a/src/decorator/relations/OneToOne.ts b/src/decorator/relations/OneToOne.ts index 85f196b227..e1d8c04982 100644 --- a/src/decorator/relations/OneToOne.ts +++ b/src/decorator/relations/OneToOne.ts @@ -6,7 +6,7 @@ import {RelationMetadataArgs} from "../../metadata-args/RelationMetadataArgs"; * Entity1 is an owner of the relationship, and storages Entity1 id on its own side. */ export function OneToOne(typeFunctionOrTarget: string|((type?: any) => ObjectType), - options?: RelationOptions): Function; + options?: RelationOptions): PropertyDecorator; /** * One-to-one relation allows to create direct relation between two entities. Entity1 have only one Entity2. @@ -14,7 +14,7 @@ export function OneToOne(typeFunctionOrTarget: string|((type?: any) => Object */ export function OneToOne(typeFunctionOrTarget: string|((type?: any) => ObjectType), inverseSide?: string|((object: T) => any), - options?: RelationOptions): Function; + options?: RelationOptions): PropertyDecorator; /** * One-to-one relation allows to create direct relation between two entities. Entity1 have only one Entity2. @@ -22,7 +22,7 @@ export function OneToOne(typeFunctionOrTarget: string|((type?: any) => Object */ export function OneToOne(typeFunctionOrTarget: string|((type?: any) => ObjectType), inverseSideOrOptions?: string|((object: T) => any)|RelationOptions, - options?: RelationOptions): Function { + options?: RelationOptions): PropertyDecorator { // normalize parameters let inverseSideProperty: string|((object: T) => any); diff --git a/src/decorator/relations/RelationCount.ts b/src/decorator/relations/RelationCount.ts index abfb76c2e4..9670c5c895 100644 --- a/src/decorator/relations/RelationCount.ts +++ b/src/decorator/relations/RelationCount.ts @@ -6,7 +6,7 @@ import {RelationCountMetadataArgs} from "../../metadata-args/RelationCountMetada * * @deprecated Do not use this decorator, it may be removed in the future versions */ -export function RelationCount(relation: string|((object: T) => any), alias?: string, queryBuilderFactory?: (qb: SelectQueryBuilder) => SelectQueryBuilder): Function { +export function RelationCount(relation: string|((object: T) => any), alias?: string, queryBuilderFactory?: (qb: SelectQueryBuilder) => SelectQueryBuilder): PropertyDecorator { return function (object: Object, propertyName: string) { getMetadataArgsStorage().relationCounts.push({ diff --git a/src/decorator/relations/RelationId.ts b/src/decorator/relations/RelationId.ts index c7880e17a6..78855aeb4f 100644 --- a/src/decorator/relations/RelationId.ts +++ b/src/decorator/relations/RelationId.ts @@ -6,7 +6,7 @@ import {RelationIdMetadataArgs} from "../../metadata-args/RelationIdMetadataArgs * * @experimental */ -export function RelationId(relation: string|((object: T) => any), alias?: string, queryBuilderFactory?: (qb: SelectQueryBuilder) => SelectQueryBuilder): Function { +export function RelationId(relation: string|((object: T) => any), alias?: string, queryBuilderFactory?: (qb: SelectQueryBuilder) => SelectQueryBuilder): PropertyDecorator { return function (object: Object, propertyName: string) { getMetadataArgsStorage().relationIds.push({ diff --git a/src/decorator/transaction/TransactionManager.ts b/src/decorator/transaction/TransactionManager.ts index 31addbcc76..083dd8d42d 100644 --- a/src/decorator/transaction/TransactionManager.ts +++ b/src/decorator/transaction/TransactionManager.ts @@ -4,7 +4,7 @@ import {TransactionEntityMetadataArgs} from "../../metadata-args/TransactionEnti /** * Injects transaction's entity manager into the method wrapped with @Transaction decorator. */ -export function TransactionManager(): Function { +export function TransactionManager(): ParameterDecorator { return function (object: Object, methodName: string, index: number) { getMetadataArgsStorage().transactionEntityManagers.push({ diff --git a/src/decorator/tree/Tree.ts b/src/decorator/tree/Tree.ts index e93ab0be9c..79da2fc96b 100644 --- a/src/decorator/tree/Tree.ts +++ b/src/decorator/tree/Tree.ts @@ -8,7 +8,7 @@ import {TreeType} from "../../metadata/types/TreeTypes"; * @TreeParent decorator must be used in tree entities. * TreeRepository can be used to manipulate with tree entities. */ -export function Tree(type: TreeType): Function { +export function Tree(type: TreeType): ClassDecorator { return function (target: Function) { getMetadataArgsStorage().trees.push({ diff --git a/src/decorator/tree/TreeChildren.ts b/src/decorator/tree/TreeChildren.ts index 70de9e5995..2ef0935e0a 100644 --- a/src/decorator/tree/TreeChildren.ts +++ b/src/decorator/tree/TreeChildren.ts @@ -5,7 +5,7 @@ import {RelationMetadataArgs} from "../../metadata-args/RelationMetadataArgs"; * Marks a entity property as a children of the tree. * "Tree children" will contain all children (bind) of this entity. */ -export function TreeChildren(options?: { cascade?: boolean|("insert"|"update"|"remove"|"soft-remove"|"recover")[] }): Function { +export function TreeChildren(options?: { cascade?: boolean|("insert"|"update"|"remove"|"soft-remove"|"recover")[] }): PropertyDecorator { return function (object: Object, propertyName: string) { if (!options) options = {} as RelationOptions; diff --git a/src/decorator/tree/TreeLevelColumn.ts b/src/decorator/tree/TreeLevelColumn.ts index f34a4173ed..24d9b5f2b1 100644 --- a/src/decorator/tree/TreeLevelColumn.ts +++ b/src/decorator/tree/TreeLevelColumn.ts @@ -4,7 +4,7 @@ import {ColumnMetadataArgs} from "../../metadata-args/ColumnMetadataArgs"; /** * Creates a "level"/"length" column to the table that holds a closure table. */ -export function TreeLevelColumn(): Function { +export function TreeLevelColumn(): PropertyDecorator { return function (object: Object, propertyName: string) { getMetadataArgsStorage().columns.push({ diff --git a/src/decorator/tree/TreeParent.ts b/src/decorator/tree/TreeParent.ts index 4b0d38b9ef..931b78206e 100644 --- a/src/decorator/tree/TreeParent.ts +++ b/src/decorator/tree/TreeParent.ts @@ -5,7 +5,7 @@ import {RelationMetadataArgs} from "../../metadata-args/RelationMetadataArgs"; * Marks a entity property as a parent of the tree. * "Tree parent" indicates who owns (is a parent) of this entity in tree structure. */ -export function TreeParent(): Function { +export function TreeParent(): PropertyDecorator { return function (object: Object, propertyName: string) { // now try to determine it its lazy relation