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umnType, SpatialColumnType, WithLengthColumnType,\n    WithPrecisionColumnType, WithWidthColumnType\n} from \"../../driver/types/ColumnTypes\";\nimport {ColumnMetadataArgs} from \"../../metadata-args/ColumnMetadataArgs\";\nimport {ColumnCommonOptions} from \"../options/ColumnCommonOptions\";\nimport {SpatialColumnOptions} from \"../options/SpatialColumnOptions\";\nimport {ColumnWithLengthOptions} from \"../options/ColumnWithLengthOptions\";\nimport {ColumnNumericOptions} from \"../options/ColumnNumericOptions\";\nimport {ColumnEnumOptions} from \"../options/ColumnEnumOptions\";\nimport {ColumnEmbeddedOptions} from \"../options/ColumnEmbeddedOptions\";\nimport {EmbeddedMetadataArgs} from \"../../metadata-args/EmbeddedMetadataArgs\";\nimport {ColumnTypeUndefinedError} from \"../../error/ColumnTypeUndefinedError\";\nimport {ColumnHstoreOptions} from \"../options/ColumnHstoreOptions\";\nimport {ColumnWithWidthOptions} from \"../options/ColumnWithWidthOptions\";\nimport { GeneratedMetadataArgs } from \"../../metadata-args/GeneratedMetadataArgs\";\n\n/**\n * Column decorator is used to mark a specific class property as a table column. Only properties decorated with this\n * decorator will be persisted to the database when entity be saved.\n */\nexport function Column(): Function;\n\n/**\n * Column decorator is used to mark a specific class property as a table column.\n * Only properties decorated with this decorator will be persisted to the database when entity be saved.\n */\nexport function Column(options: ColumnOptions): Function;\n\n/**\n * Column decorator is used to mark a specific class property as a table column.\n * Only properties decorated with this decorator will be persisted to the database when entity be saved.\n */\nexport function Column(type: SimpleColumnType, options?: ColumnCommonOptions): Function;\n\n/**\n * Column decorator is used to mark a specific class property as a table column.\n * Only properties decorated with this decorator will be persisted to the database when entity be saved.\n */\nexport function Column(type: SpatialColumnType, options?: ColumnCommonOptions & SpatialColumnOptions): Function;\n\n/**\n * Column decorator is used to mark a specific class property as a table column.\n * Only properties decorated with this decorator will be persisted to the database when entity be saved.\n */\nexport function Column(type: WithLengthColumnType, options?: ColumnCommonOptions & ColumnWithLengthOptions): Function;\n\n/**\n * Column decorator is used to mark a specific class property as a table column.\n * Only properties decorated with this decorator will be persisted to the database when entity be saved.\n */\nexport function Column(type: WithWidthColumnType, options?: ColumnCommonOptions & ColumnWithWidthOptions): Function;\n\n/**\n * Column decorator is used to mark a specific class property as a table column.\n * Only properties decorated with this decorator will be persisted to the database when entity be saved.\n */\nexport function Column(type: WithPrecisionColumnType, options?: ColumnCommonOptions & ColumnNumericOptions): Function;\n\n/**\n * Column decorator is used to mark a specific class property as a table column.\n * Only properties decorated with this decorator will be persisted to the database when entity be saved.\n */\nexport function Column(type: \"enum\", options?: ColumnCommonOptions & ColumnEnumOptions): Function;\n\n/**\n * Column decorator is used to mark a specific class property as a table column.\n * Only properties decorated with this decorator will be persisted to the database when entity be saved.\n */\nexport function Column(type: \"simple-enum\", options?: ColumnCommonOptions & ColumnEnumOptions): Function;\n\n/**\n * Column decorator is used to mark a specific class property as a table column.\n * Only properties decorated with this decorator will be persisted to the database when entity be saved.\n */\nexport function Column(type: \"hstore\", options?: ColumnCommonOptions & ColumnHstoreOptions): Function;\n\n/**\n * Column decorator is used to mark a specific class property as a table column.\n * Only properties decorated with this decorator will be persisted to the database when entity be saved.\n *\n * Property in entity can be marked as Embedded, and on persist all columns from the embedded are mapped to the\n * single table of the entity where Embedded is used. And on hydration all columns which supposed to be in the\n * embedded will be mapped to it from the single table.\n */\nexport function Column(type: (type?: any) => Function, options?: ColumnEmbeddedOptions): Function;\n\n/**\n * Column decorator is used to mark a specific class property as a table column.\n * Only properties decorated with this decorator will be persisted to the database when entity be saved.\n */\nexport function Column(typeOrOptions?: ((type?: any) => Function)|ColumnType|(ColumnOptions&ColumnEmbeddedOptions), options?: (ColumnOptions&ColumnEmbeddedOptions)): Function {\n    return function (object: Object, propertyName: string) {\n\n        // normalize parameters\n        let type: ColumnType|undefined;\n        if (typeof typeOrOptions === \"string\" || typeOrOptions instanceof Function) {\n            type = <ColumnType> typeOrOptions;\n\n        } else if (typeOrOptions) {\n            options = <ColumnOptions> typeOrOptions;\n            type = typeOrOptions.type;\n        }\n        if (!options) options = {} as ColumnOptions;\n\n        // if type is not given explicitly then try to guess it\n        const reflectMetadataType = Reflect && (Reflect as any).getMetadata ? (Reflect as any).getMetadata(\"design:type\", object, propertyName) : undefined;\n        if (!type && reflectMetadataType) // if type is not given explicitly then try to guess it\n            type = reflectMetadataType;\n\n        // check if there is no type in column options then set type from first function argument, or guessed one\n        if (!options.type && type)\n            options.type = type;\n\n        // specify HSTORE type if column is HSTORE\n        if (options.type === \"hstore\" && !options.hstoreType)\n            options.hstoreType = reflectMetadataType === Object ? \"object\" : \"string\";\n\n        if (typeOrOptions instanceof Function) { // register an embedded\n            getMetadataArgsStorage().embeddeds.push({\n                target: object.constructor,\n                propertyName: propertyName,\n                isArray: reflectMetadataType === Array || options.array === true,\n                prefix: options.prefix !== undefined ? options.prefix : undefined,\n                type: typeOrOptions as (type?: any) => Function\n            } as EmbeddedMetadataArgs);\n\n        } else { // register a regular column\n\n            // if we still don't have a type then we need to give error to user that type is required\n            if (!options.type)\n                throw new ColumnTypeUndefinedError(object, propertyName);\n\n            // create unique\n            if (options.unique === true)\n                getMetadataArgsStorage().uniques.push({ target: object.constructor, columns: [propertyName] });\n\n            getMetadataArgsStorage().columns.push({\n                target: object.constructor,\n                propertyName: propertyName,\n                mode: \"regular\",\n                options: options\n            } as ColumnMetadataArgs);\n\n            if (options.generated) {\n                getMetadataArgsStorage().generations.push({\n                    target: object.constructor,\n                    propertyName: propertyName,\n                    strategy: typeof options.generated === \"string\" ? options.generated : \"increment\"\n                } as GeneratedMetadataArgs);\n            }\n        }\n    };\n}\n"],"sourceRoot":"../.."}