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E,CAAC,OAAO,CAAC,IAAI,CAAC;YAClC,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY,EAAE,YAAY;YAC1B,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,OAAO;SACG,CAAC,CAAA;QAExB,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;YACpB,IAAA,gCAAsB,GAAE,CAAC,WAAW,CAAC,IAAI,CAAC;gBACtC,MAAM,EAAE,MAAM,CAAC,WAAW;gBAC1B,YAAY,EAAE,YAAY;gBAC1B,QAAQ,EACJ,OAAO,OAAO,CAAC,SAAS,KAAK,QAAQ;oBACjC,CAAC,CAAC,OAAO,CAAC,SAAS;oBACnB,CAAC,CAAC,WAAW;aACC,CAAC,CAAA;QAC/B,CAAC;IACL,CAAC,CAAA;AACL,CAAC;AA/DD,sCA+DC","file":"PrimaryColumn.js","sourcesContent":["import { getMetadataArgsStorage } from \"../../globals\"\nimport { ColumnTypeUndefinedError } from \"../../error/ColumnTypeUndefinedError\"\nimport { PrimaryColumnCannotBeNullableError } from \"../../error/PrimaryColumnCannotBeNullableError\"\nimport { ColumnMetadataArgs } from \"../../metadata-args/ColumnMetadataArgs\"\nimport { GeneratedMetadataArgs } from \"../../metadata-args/GeneratedMetadataArgs\"\nimport { ColumnOptions } from \"../options/ColumnOptions\"\nimport { ColumnType } from \"../../driver/types/ColumnTypes\"\n\n/**\n * Describes all primary key column's options.\n * If specified, the nullable field must be set to false.\n */\nexport type PrimaryColumnOptions = ColumnOptions & { nullable?: false }\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 * Primary columns also creates a PRIMARY KEY for this column in a db.\n */\nexport function PrimaryColumn(options?: PrimaryColumnOptions): PropertyDecorator\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 * Primary columns also creates a PRIMARY KEY for this column in a db.\n */\nexport function PrimaryColumn(\n type?: ColumnType,\n options?: PrimaryColumnOptions,\n): PropertyDecorator\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 * Primary columns also creates a PRIMARY KEY for this column in a db.\n */\nexport function PrimaryColumn(\n typeOrOptions?: ColumnType | PrimaryColumnOptions,\n options?: PrimaryColumnOptions,\n): PropertyDecorator {\n return function (object: Object, propertyName: string) {\n // normalize parameters\n let type: ColumnType | undefined\n if (\n typeof typeOrOptions === \"string\" ||\n typeOrOptions === String ||\n typeOrOptions === Boolean ||\n typeOrOptions === Number\n ) {\n type = typeOrOptions as ColumnType\n } else {\n options = Object.assign({}, typeOrOptions)\n }\n if (!options) options = {} as PrimaryColumnOptions\n\n // if type is not given explicitly then try to guess it\n const reflectMetadataType =\n Reflect && (Reflect as any).getMetadata\n ? (Reflect as any).getMetadata(\n \"design:type\",\n object,\n propertyName,\n )\n : undefined\n if (!type && reflectMetadataType) 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) options.type = type\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 // check if column is not nullable, because we cannot allow a primary key to be nullable\n if (options.nullable)\n throw new PrimaryColumnCannotBeNullableError(object, propertyName)\n\n // explicitly set a primary to column options\n options.primary = true\n\n // create and register a new column metadata\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:\n typeof options.generated === \"string\"\n ? options.generated\n : \"increment\",\n } as GeneratedMetadataArgs)\n }\n }\n}\n"],"sourceRoot":"../.."}