typeorm 0.2.42-dev.2834729 → 0.2.42-dev.6523fcc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/decorator/options/RelationOptions.d.ts +1 -1
- package/browser/decorator/options/RelationOptions.js.map +1 -1
- package/browser/entity-schema/EntitySchemaRelationOptions.d.ts +1 -1
- package/browser/entity-schema/EntitySchemaRelationOptions.js.map +1 -1
- package/browser/metadata/RelationMetadata.d.ts +1 -1
- package/browser/metadata/RelationMetadata.js.map +1 -1
- package/browser/metadata-builder/EntityMetadataValidator.js +1 -0
- package/browser/metadata-builder/EntityMetadataValidator.js.map +1 -1
- package/browser/persistence/subject-builder/OneToManySubjectBuilder.js +3 -0
- package/browser/persistence/subject-builder/OneToManySubjectBuilder.js.map +1 -1
- package/decorator/options/RelationOptions.d.ts +1 -1
- package/decorator/options/RelationOptions.js.map +1 -1
- package/entity-schema/EntitySchemaRelationOptions.d.ts +1 -1
- package/entity-schema/EntitySchemaRelationOptions.js.map +1 -1
- package/metadata/RelationMetadata.d.ts +1 -1
- package/metadata/RelationMetadata.js.map +1 -1
- package/metadata-builder/EntityMetadataValidator.js +1 -0
- package/metadata-builder/EntityMetadataValidator.js.map +1 -1
- package/package.json +1 -1
- package/persistence/subject-builder/OneToManySubjectBuilder.js +3 -0
- package/persistence/subject-builder/OneToManySubjectBuilder.js.map +1 -1
|
@@ -62,5 +62,5 @@ export interface RelationOptions {
|
|
|
62
62
|
/**
|
|
63
63
|
* When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.
|
|
64
64
|
*/
|
|
65
|
-
orphanedRowAction?: "nullify" | "delete";
|
|
65
|
+
orphanedRowAction?: "nullify" | "delete" | "soft-delete";
|
|
66
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/decorator/options/RelationOptions.ts"],"names":[],"mappings":"","file":"RelationOptions.js","sourcesContent":["import {DeferrableType} from \"../../metadata/types/DeferrableType\";\nimport {OnDeleteType} from \"../../metadata/types/OnDeleteType\";\nimport {OnUpdateType} from \"../../metadata/types/OnUpdateType\";\n\n/**\n * Describes all relation's options.\n */\nexport interface RelationOptions {\n\n /**\n * Sets cascades options for the given relation.\n * If set to true then it means that related object can be allowed to be inserted or updated in the database.\n * You can separately restrict cascades to insertion or updation using following syntax:\n *\n * cascade: [\"insert\", \"update\", \"remove\", \"soft-remove\", \"recover\"] // include or exclude one of them\n */\n cascade?: boolean|(\"insert\"|\"update\"|\"remove\"|\"soft-remove\"|\"recover\")[];\n\n /**\n * Indicates if relation column value can be nullable or not.\n */\n nullable?: boolean;\n\n /**\n * Database cascade action on delete.\n */\n onDelete?: OnDeleteType;\n\n /**\n * Database cascade action on update.\n */\n onUpdate?: OnUpdateType;\n\n /**\n * Indicate if foreign key constraints can be deferred.\n */\n deferrable?: DeferrableType;\n\n /**\n * Indicates if this relation will be a primary key.\n * Can be used only for many-to-one and owner one-to-one relations.\n */\n primary?: boolean;\n\n /**\n * Indicates whether foreign key constraints will be created for join columns.\n * Can be used only for many-to-one and owner one-to-one relations.\n * Defaults to true.\n */\n createForeignKeyConstraints?: boolean;\n\n /**\n * Set this relation to be lazy. Note: lazy relations are promises. When you call them they return promise\n * which resolve relation result then. If your property's type is Promise then this relation is set to lazy automatically.\n */\n lazy?: boolean;\n\n /**\n * Set this relation to be eager.\n * Eager relations are always loaded automatically when relation's owner entity is loaded using find* methods.\n * Only using QueryBuilder prevents loading eager relations.\n * Eager flag cannot be set from both sides of relation - you can eager load only one side of the relationship.\n */\n eager?: boolean;\n\n /**\n * Indicates if persistence is enabled for the relation.\n * 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.\n * If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.\n * This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.\n */\n persistence?: boolean;\n\n /**\n * When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.\n */\n orphanedRowAction?: \"nullify\" | \"delete\";\n\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/decorator/options/RelationOptions.ts"],"names":[],"mappings":"","file":"RelationOptions.js","sourcesContent":["import {DeferrableType} from \"../../metadata/types/DeferrableType\";\nimport {OnDeleteType} from \"../../metadata/types/OnDeleteType\";\nimport {OnUpdateType} from \"../../metadata/types/OnUpdateType\";\n\n/**\n * Describes all relation's options.\n */\nexport interface RelationOptions {\n\n /**\n * Sets cascades options for the given relation.\n * If set to true then it means that related object can be allowed to be inserted or updated in the database.\n * You can separately restrict cascades to insertion or updation using following syntax:\n *\n * cascade: [\"insert\", \"update\", \"remove\", \"soft-remove\", \"recover\"] // include or exclude one of them\n */\n cascade?: boolean|(\"insert\"|\"update\"|\"remove\"|\"soft-remove\"|\"recover\")[];\n\n /**\n * Indicates if relation column value can be nullable or not.\n */\n nullable?: boolean;\n\n /**\n * Database cascade action on delete.\n */\n onDelete?: OnDeleteType;\n\n /**\n * Database cascade action on update.\n */\n onUpdate?: OnUpdateType;\n\n /**\n * Indicate if foreign key constraints can be deferred.\n */\n deferrable?: DeferrableType;\n\n /**\n * Indicates if this relation will be a primary key.\n * Can be used only for many-to-one and owner one-to-one relations.\n */\n primary?: boolean;\n\n /**\n * Indicates whether foreign key constraints will be created for join columns.\n * Can be used only for many-to-one and owner one-to-one relations.\n * Defaults to true.\n */\n createForeignKeyConstraints?: boolean;\n\n /**\n * Set this relation to be lazy. Note: lazy relations are promises. When you call them they return promise\n * which resolve relation result then. If your property's type is Promise then this relation is set to lazy automatically.\n */\n lazy?: boolean;\n\n /**\n * Set this relation to be eager.\n * Eager relations are always loaded automatically when relation's owner entity is loaded using find* methods.\n * Only using QueryBuilder prevents loading eager relations.\n * Eager flag cannot be set from both sides of relation - you can eager load only one side of the relationship.\n */\n eager?: boolean;\n\n /**\n * Indicates if persistence is enabled for the relation.\n * 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.\n * If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.\n * This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.\n */\n persistence?: boolean;\n\n /**\n * When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.\n */\n orphanedRowAction?: \"nullify\" | \"delete\" | \"soft-delete\";\n\n}\n"],"sourceRoot":"../.."}
|
|
@@ -82,5 +82,5 @@ export interface EntitySchemaRelationOptions {
|
|
|
82
82
|
/**
|
|
83
83
|
* When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.
|
|
84
84
|
*/
|
|
85
|
-
orphanedRowAction?: "nullify" | "delete";
|
|
85
|
+
orphanedRowAction?: "nullify" | "delete" | "soft-delete";
|
|
86
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/entity-schema/EntitySchemaRelationOptions.ts"],"names":[],"mappings":"","file":"EntitySchemaRelationOptions.js","sourcesContent":["import {JoinColumnOptions} from \"../decorator/options/JoinColumnOptions\";\nimport {RelationType} from \"../metadata/types/RelationTypes\";\nimport {JoinTableMultipleColumnsOptions} from \"../decorator/options/JoinTableMultipleColumnsOptions\";\nimport {DeferrableType} from \"../metadata/types/DeferrableType\";\nimport {OnDeleteType} from \"../metadata/types/OnDeleteType\";\nimport {OnUpdateType} from \"../metadata/types/OnUpdateType\";\nimport { JoinTableOptions } from \"../decorator/options/JoinTableOptions\";\n\n\nexport interface EntitySchemaRelationOptions {\n\n /**\n * Indicates with which entity this relation is made.\n */\n target: Function|string;\n\n /**\n * Type of relation. Can be one of the value of the RelationTypes class.\n */\n type: RelationType;\n\n /**\n * Inverse side of the relation.\n */\n inverseSide?: string;\n\n /**\n * Indicates if this relation will be lazily loaded.\n */\n lazy?: boolean;\n\n /**\n * Indicates if this relation will be eagerly loaded.\n */\n eager?: boolean;\n\n /**\n * Indicates if persistence is enabled for the relation.\n * 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.\n * If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.\n * This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.\n */\n persistence?: boolean;\n\n /**\n * Indicates if this relation will be a primary key.\n * Can be used only for many-to-one and owner one-to-one relations.\n */\n primary?: boolean;\n\n /**\n * Join table options of this column. If set to true then it simply means that it has a join table.\n */\n joinTable?: boolean|JoinTableOptions|JoinTableMultipleColumnsOptions;\n\n /**\n * Join column options of this column. If set to true then it simply means that it has a join column.\n */\n joinColumn?: boolean|JoinColumnOptions|JoinColumnOptions[];\n\n /**\n * Indicates if this is a parent (can be only many-to-one relation) relation in the tree tables.\n */\n treeParent?: boolean;\n\n /**\n * Indicates if this is a children (can be only one-to-many relation) relation in the tree tables.\n */\n treeChildren?: boolean;\n\n /**\n * If set to true then it means that related object can be allowed to be inserted / updated / removed to the db.\n * This is option a shortcut if you would like to set cascadeInsert, cascadeUpdate and cascadeRemove to true.\n */\n cascade?: boolean|(\"insert\"|\"update\"|\"remove\"|\"soft-remove\"|\"recover\")[];\n\n /**\n * Default database value.\n */\n default?: any;\n\n /**\n * Indicates if relation column value can be nullable or not.\n */\n nullable?: boolean;\n\n /**\n * Database cascade action on delete.\n */\n onDelete?: OnDeleteType;\n\n /**\n * Database cascade action on update.\n */\n onUpdate?: OnUpdateType;\n\n /**\n * Indicate if foreign key constraints can be deferred.\n */\n deferrable?: DeferrableType;\n\n /**\n * When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.\n */\n orphanedRowAction?: \"nullify\" | \"delete\";\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/entity-schema/EntitySchemaRelationOptions.ts"],"names":[],"mappings":"","file":"EntitySchemaRelationOptions.js","sourcesContent":["import {JoinColumnOptions} from \"../decorator/options/JoinColumnOptions\";\nimport {RelationType} from \"../metadata/types/RelationTypes\";\nimport {JoinTableMultipleColumnsOptions} from \"../decorator/options/JoinTableMultipleColumnsOptions\";\nimport {DeferrableType} from \"../metadata/types/DeferrableType\";\nimport {OnDeleteType} from \"../metadata/types/OnDeleteType\";\nimport {OnUpdateType} from \"../metadata/types/OnUpdateType\";\nimport { JoinTableOptions } from \"../decorator/options/JoinTableOptions\";\n\n\nexport interface EntitySchemaRelationOptions {\n\n /**\n * Indicates with which entity this relation is made.\n */\n target: Function|string;\n\n /**\n * Type of relation. Can be one of the value of the RelationTypes class.\n */\n type: RelationType;\n\n /**\n * Inverse side of the relation.\n */\n inverseSide?: string;\n\n /**\n * Indicates if this relation will be lazily loaded.\n */\n lazy?: boolean;\n\n /**\n * Indicates if this relation will be eagerly loaded.\n */\n eager?: boolean;\n\n /**\n * Indicates if persistence is enabled for the relation.\n * 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.\n * If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.\n * This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.\n */\n persistence?: boolean;\n\n /**\n * Indicates if this relation will be a primary key.\n * Can be used only for many-to-one and owner one-to-one relations.\n */\n primary?: boolean;\n\n /**\n * Join table options of this column. If set to true then it simply means that it has a join table.\n */\n joinTable?: boolean|JoinTableOptions|JoinTableMultipleColumnsOptions;\n\n /**\n * Join column options of this column. If set to true then it simply means that it has a join column.\n */\n joinColumn?: boolean|JoinColumnOptions|JoinColumnOptions[];\n\n /**\n * Indicates if this is a parent (can be only many-to-one relation) relation in the tree tables.\n */\n treeParent?: boolean;\n\n /**\n * Indicates if this is a children (can be only one-to-many relation) relation in the tree tables.\n */\n treeChildren?: boolean;\n\n /**\n * If set to true then it means that related object can be allowed to be inserted / updated / removed to the db.\n * This is option a shortcut if you would like to set cascadeInsert, cascadeUpdate and cascadeRemove to true.\n */\n cascade?: boolean|(\"insert\"|\"update\"|\"remove\"|\"soft-remove\"|\"recover\")[];\n\n /**\n * Default database value.\n */\n default?: any;\n\n /**\n * Indicates if relation column value can be nullable or not.\n */\n nullable?: boolean;\n\n /**\n * Database cascade action on delete.\n */\n onDelete?: OnDeleteType;\n\n /**\n * Database cascade action on update.\n */\n onUpdate?: OnUpdateType;\n\n /**\n * Indicate if foreign key constraints can be deferred.\n */\n deferrable?: DeferrableType;\n\n /**\n * When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.\n */\n orphanedRowAction?: \"nullify\" | \"delete\" | \"soft-delete\";\n}\n"],"sourceRoot":".."}
|
|
@@ -92,7 +92,7 @@ export declare class RelationMetadata {
|
|
|
92
92
|
/**
|
|
93
93
|
* When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.
|
|
94
94
|
*/
|
|
95
|
-
orphanedRowAction?: "nullify" | "delete";
|
|
95
|
+
orphanedRowAction?: "nullify" | "delete" | "soft-delete";
|
|
96
96
|
/**
|
|
97
97
|
* If set to true then related objects are allowed to be inserted to the database.
|
|
98
98
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/metadata/RelationMetadata.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAUhD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC;;GAEG;AACH;IAoQI,wEAAwE;IACxE,cAAc;IACd,wEAAwE;IAExE,0BAAY,OAIX;QA9MD;;WAEG;QACH,iBAAY,GAAY,KAAK,CAAC;QAE9B;;WAEG;QACH,mBAAc,GAAY,KAAK,CAAC;QAEhC;;;WAGG;QACH,cAAS,GAAY,KAAK,CAAC;QAE3B;;WAEG;QACH,WAAM,GAAY,KAAK,CAAC;QAExB;;WAEG;QACH,YAAO,GAAY,KAAK,CAAC;QAEzB;;;;;WAKG;QACH,uBAAkB,GAAY,IAAI,CAAC;QAOnC;;WAEG;QACH,oBAAe,GAAY,KAAK,CAAC;QAEjC;;WAEG;QACH,oBAAe,GAAY,KAAK,CAAC;QAEjC;;WAEG;QACH,oBAAe,GAAY,KAAK,CAAC;QAEjC;;WAEG;QACH,wBAAmB,GAAY,KAAK,CAAC;QAErC;;WAEG;QACH,qBAAgB,GAAY,KAAK,CAAC;QAElC;;WAE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;IACzF,CAAC;IAEL,uBAAC;AAAD,CA1iBA,AA0iBC,IAAA","file":"RelationMetadata.js","sourcesContent":["import {RelationType} from \"./types/RelationTypes\";\nimport {EntityMetadata} from \"./EntityMetadata\";\nimport {ForeignKeyMetadata} from \"./ForeignKeyMetadata\";\nimport {ObjectLiteral} from \"../common/ObjectLiteral\";\nimport {ColumnMetadata} from \"./ColumnMetadata\";\nimport {EmbeddedMetadata} from \"./EmbeddedMetadata\";\nimport {RelationMetadataArgs} from \"../metadata-args/RelationMetadataArgs\";\nimport {DeferrableType} from \"./types/DeferrableType\";\nimport {OnUpdateType} from \"./types/OnUpdateType\";\nimport {OnDeleteType} from \"./types/OnDeleteType\";\nimport {PropertyTypeFactory} from \"./types/PropertyTypeInFunction\";\nimport { TypeORMError } from \"../error\";\n\n/**\n * Contains all information about some entity's relation.\n */\nexport class RelationMetadata {\n\n // ---------------------------------------------------------------------\n // Public Properties\n // ---------------------------------------------------------------------\n\n /**\n * Entity metadata of the entity where this relation is placed.\n *\n * For example for @ManyToMany(type => Category) in Post, entityMetadata will be metadata of Post entity.\n */\n entityMetadata: EntityMetadata;\n\n /**\n * Entity metadata of the entity that is targeted by this relation.\n *\n * For example for @ManyToMany(type => Category) in Post, inverseEntityMetadata will be metadata of Category entity.\n */\n inverseEntityMetadata: EntityMetadata;\n\n /**\n * Entity metadata of the junction table.\n * Junction tables have their own entity metadata objects.\n * Defined only for many-to-many relations.\n */\n junctionEntityMetadata?: EntityMetadata;\n\n /**\n * Embedded metadata where this relation is.\n * If this relation is not in embed then this property value is undefined.\n */\n embeddedMetadata?: EmbeddedMetadata;\n\n /**\n * Relation type, e.g. is it one-to-one, one-to-many, many-to-one or many-to-many.\n */\n relationType: RelationType;\n\n /**\n * Target entity to which this relation is applied.\n * Target IS NOT equal to entityMetadata.target, because relation\n *\n * For example for @ManyToMany(type => Category) in Post, target will be Post.\n * If @ManyToMany(type => Category) is in Counters which is embedded into Post, target will be Counters.\n * If @ManyToMany(type => Category) is in abstract class BaseUser which Post extends, target will be BaseUser.\n * Target can be string if its defined in entity schema instead of class.\n */\n target: Function|string;\n\n /**\n * Target's property name to which relation decorator is applied.\n */\n propertyName: string;\n\n /**\n * Gets full path to this column property (including relation name).\n * Full path is relevant when column is used in embeds (one or multiple nested).\n * For example it will return \"counters.subcounters.likes\".\n * If property is not in embeds then it returns just property name of the column.\n */\n propertyPath: string;\n\n /**\n * Indicates if this is a parent (can be only many-to-one relation) relation in the tree tables.\n */\n isTreeParent: boolean = false;\n\n /**\n * Indicates if this is a children (can be only one-to-many relation) relation in the tree tables.\n */\n isTreeChildren: boolean = false;\n\n /**\n * Indicates if this relation's column is a primary key.\n * Can be used only for many-to-one and owner one-to-one relations.\n */\n isPrimary: boolean = false;\n\n /**\n * Indicates if this relation is lazily loaded.\n */\n isLazy: boolean = false;\n\n /**\n * Indicates if this relation is eagerly loaded.\n */\n isEager: boolean = false;\n\n /**\n * Indicates if persistence is enabled for the relation.\n * 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.\n * If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.\n * This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.\n */\n persistenceEnabled: boolean = true;\n\n /**\n * When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.\n */\n orphanedRowAction?: \"nullify\" | \"delete\";\n\n /**\n * If set to true then related objects are allowed to be inserted to the database.\n */\n isCascadeInsert: boolean = false;\n\n /**\n * If set to true then related objects are allowed to be updated in the database.\n */\n isCascadeUpdate: boolean = false;\n\n /**\n * If set to true then related objects are allowed to be remove from the database.\n */\n isCascadeRemove: boolean = false;\n\n /**\n * If set to true then related objects are allowed to be soft-removed from the database.\n */\n isCascadeSoftRemove: boolean = false;\n\n /**\n * If set to true then related objects are allowed to be recovered from the database.\n */\n isCascadeRecover: boolean = false;\n\n /**\n * Indicates if relation column value can be nullable or not.\n */\n isNullable: boolean = true;\n\n /**\n * What to do with a relation on deletion of the row containing a foreign key.\n */\n onDelete?: OnDeleteType;\n\n /**\n * What to do with a relation on update of the row containing a foreign key.\n */\n onUpdate?: OnUpdateType;\n\n /**\n * What to do with a relation on update of the row containing a foreign key.\n */\n deferrable?: DeferrableType;\n\n /**\n * Indicates whether foreign key constraints will be created for join columns.\n * Can be used only for many-to-one and owner one-to-one relations.\n * Defaults to true.\n */\n createForeignKeyConstraints: boolean = true;\n\n /**\n * Gets the property's type to which this relation is applied.\n *\n * For example for @ManyToMany(type => Category) in Post, target will be Category.\n */\n type: Function|string;\n\n /**\n * Indicates if this side is an owner of this relation.\n */\n isOwning: boolean = false;\n\n /**\n * Checks if this relation's type is \"one-to-one\".\n */\n isOneToOne: boolean = false;\n\n /**\n * Checks if this relation is owner side of the \"one-to-one\" relation.\n * Owner side means this side of relation has a join column in the table.\n */\n isOneToOneOwner: boolean = false;\n\n /**\n * Checks if this relation has a join column (e.g. is it many-to-one or one-to-one owner side).\n */\n isWithJoinColumn: boolean = false;\n\n /**\n * Checks if this relation is NOT owner side of the \"one-to-one\" relation.\n * NOT owner side means this side of relation does not have a join column in the table.\n */\n isOneToOneNotOwner: boolean = false;\n\n /**\n * Checks if this relation's type is \"one-to-many\".\n */\n isOneToMany: boolean = false;\n\n /**\n * Checks if this relation's type is \"many-to-one\".\n */\n isManyToOne: boolean = false;\n\n /**\n * Checks if this relation's type is \"many-to-many\".\n */\n isManyToMany: boolean = false;\n\n /**\n * Checks if this relation's type is \"many-to-many\", and is owner side of the relationship.\n * Owner side means this side of relation has a join table.\n */\n isManyToManyOwner: boolean = false;\n\n /**\n * Checks if this relation's type is \"many-to-many\", and is NOT owner side of the relationship.\n * Not owner side means this side of relation does not have a join table.\n */\n isManyToManyNotOwner: boolean = false;\n\n /**\n * Gets the property path of the inverse side of the relation.\n */\n inverseSidePropertyPath: string;\n\n /**\n * Inverse side of the relation set by user.\n *\n * Inverse side set in the relation can be either string - property name of the column on inverse side,\n * either can be a function that accepts a map of properties with the object and returns one of them.\n * Second approach is used to achieve type-safety.\n */\n givenInverseSidePropertyFactory: PropertyTypeFactory<any>;\n\n /**\n * Gets the relation metadata of the inverse side of this relation.\n */\n inverseRelation?: RelationMetadata;\n\n /**\n * Join table name.\n */\n joinTableName: string;\n\n /**\n * Foreign keys created for this relation.\n */\n foreignKeys: ForeignKeyMetadata[] = [];\n\n /**\n * Join table columns.\n * Join columns can be obtained only from owner side of the relation.\n * From non-owner side of the relation join columns will be empty.\n * If this relation is a many-to-one/one-to-one then it takes join columns from the current entity.\n * If this relation is many-to-many then it takes all owner join columns from the junction entity.\n */\n joinColumns: ColumnMetadata[] = [];\n\n /**\n * Inverse join table columns.\n * Inverse join columns are supported only for many-to-many relations\n * and can be obtained only from owner side of the relation.\n * From non-owner side of the relation join columns will be undefined.\n */\n inverseJoinColumns: ColumnMetadata[] = [];\n\n // ---------------------------------------------------------------------\n // Constructor\n // ---------------------------------------------------------------------\n\n constructor(options: {\n entityMetadata: EntityMetadata,\n embeddedMetadata?: EmbeddedMetadata,\n args: RelationMetadataArgs\n }) {\n this.entityMetadata = options.entityMetadata;\n this.embeddedMetadata = options.embeddedMetadata!;\n const args = options.args;\n this.target = args.target;\n this.propertyName = args.propertyName;\n this.relationType = args.relationType;\n\n if (args.inverseSideProperty)\n this.givenInverseSidePropertyFactory = args.inverseSideProperty;\n\n this.isLazy = args.isLazy || false;\n // this.isCascadeInsert = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"insert\") !== -1);\n // this.isCascadeUpdate = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"update\") !== -1);\n // this.isCascadeRemove = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"remove\") !== -1);\n // this.isCascadeSoftRemove = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"soft-remove\") !== -1);\n // this.isCascadeRecover = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"recover\") !== -1);\n this.isCascadeInsert = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"insert\") !== -1);\n this.isCascadeUpdate = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"update\") !== -1);\n this.isCascadeRemove = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"remove\") !== -1);\n this.isCascadeSoftRemove = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"soft-remove\") !== -1);\n this.isCascadeRecover = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"recover\") !== -1);\n this.isPrimary = args.options.primary || false;\n this.isNullable = args.options.nullable === false || this.isPrimary ? false : true;\n this.onDelete = args.options.onDelete;\n this.onUpdate = args.options.onUpdate;\n this.deferrable = args.options.deferrable;\n this.createForeignKeyConstraints = args.options.createForeignKeyConstraints === false ? false : true;\n this.isEager = args.options.eager || false;\n this.persistenceEnabled = args.options.persistence === false ? false : true;\n this.orphanedRowAction = args.options.orphanedRowAction || \"nullify\";\n this.isTreeParent = args.isTreeParent || false;\n this.isTreeChildren = args.isTreeChildren || false;\n this.type = args.type instanceof Function ? (args.type as () => any)() : args.type;\n\n this.isOneToOne = this.relationType === \"one-to-one\";\n this.isOneToMany = this.relationType === \"one-to-many\";\n this.isManyToOne = this.relationType === \"many-to-one\";\n this.isManyToMany = this.relationType === \"many-to-many\";\n this.isOneToOneNotOwner = this.isOneToOne ? true : false;\n this.isManyToManyNotOwner = this.isManyToMany ? true : false;\n }\n\n // ---------------------------------------------------------------------\n // Public Methods\n // ---------------------------------------------------------------------\n\n /**\n * Creates join column ids map from the given related entity ids array.\n */\n getRelationIdMap(entity: ObjectLiteral): ObjectLiteral|undefined {\n const joinColumns = this.isOwning ? this.joinColumns : this.inverseRelation!.joinColumns;\n const referencedColumns = joinColumns.map(joinColumn => joinColumn.referencedColumn!);\n // console.log(\"entity\", entity);\n // console.log(\"referencedColumns\", referencedColumns);\n return EntityMetadata.getValueMap(entity, referencedColumns);\n }\n\n /**\n * Ensures that given object is an entity id map.\n * If given id is an object then it means its already id map.\n * If given id isn't an object then it means its a value of the id column\n * and it creates a new id map with this value and name of the primary column.\n */\n ensureRelationIdMap(id: any): ObjectLiteral {\n if (id instanceof Object)\n return id;\n\n const joinColumns = this.isOwning ? this.joinColumns : this.inverseRelation!.joinColumns;\n const referencedColumns = joinColumns.map(joinColumn => joinColumn.referencedColumn!);\n\n if (referencedColumns.length > 1)\n throw new TypeORMError(`Cannot create relation id map for a single value because relation contains multiple referenced columns.`);\n\n return referencedColumns[0].createValueMap(id);\n }\n\n /**\n * Extracts column value from the given entity.\n * If column is in embedded (or recursive embedded) it extracts its value from there.\n */\n getEntityValue(entity: ObjectLiteral, getLazyRelationsPromiseValue: boolean = false): any|undefined {\n if (entity === null || entity === undefined) return undefined;\n // extract column value from embeddeds of entity if column is in embedded\n if (this.embeddedMetadata) {\n\n // example: post[data][information][counters].id where \"data\", \"information\" and \"counters\" are embeddeds\n // we need to get value of \"id\" column from the post real entity object\n\n // first step - we extract all parent properties of the entity relative to this column, e.g. [data, information, counters]\n const propertyNames = [...this.embeddedMetadata.parentPropertyNames];\n\n // next we need to access post[data][information][counters][this.propertyName] to get column value from the counters\n // this recursive function takes array of generated property names and gets the post[data][information][counters] embed\n const extractEmbeddedColumnValue = (propertyNames: string[], value: ObjectLiteral): any => {\n const propertyName = propertyNames.shift();\n if (propertyName) {\n if (value[propertyName]) {\n return extractEmbeddedColumnValue(propertyNames, value[propertyName]);\n }\n return undefined;\n }\n return value;\n };\n\n // once we get nested embed object we get its column, e.g. post[data][information][counters][this.propertyName]\n const embeddedObject = extractEmbeddedColumnValue(propertyNames, entity);\n\n if (this.isLazy) {\n if (embeddedObject[\"__\" + this.propertyName + \"__\"] !== undefined)\n return embeddedObject[\"__\" + this.propertyName + \"__\"];\n\n if (getLazyRelationsPromiseValue === true)\n return embeddedObject[this.propertyName];\n\n return undefined;\n }\n return embeddedObject ? embeddedObject[this.isLazy ? \"__\" + this.propertyName + \"__\" : this.propertyName] : undefined;\n\n } else { // no embeds - no problems. Simply return column name by property name of the entity\n if (this.isLazy) {\n if (entity[\"__\" + this.propertyName + \"__\"] !== undefined)\n return entity[\"__\" + this.propertyName + \"__\"];\n\n if (getLazyRelationsPromiseValue === true)\n return entity[this.propertyName];\n\n return undefined;\n }\n return entity[this.propertyName];\n }\n }\n\n /**\n * Sets given entity's relation's value.\n * Using of this method helps to set entity relation's value of the lazy and non-lazy relations.\n *\n * If merge is set to true, it merges given value into currently\n */\n setEntityValue(entity: ObjectLiteral, value: any): void {\n const propertyName = this.isLazy ? \"__\" + this.propertyName + \"__\" : this.propertyName;\n\n if (this.embeddedMetadata) {\n\n // first step - we extract all parent properties of the entity relative to this column, e.g. [data, information, counters]\n const extractEmbeddedColumnValue = (embeddedMetadatas: EmbeddedMetadata[], map: ObjectLiteral): any => {\n // if (!object[embeddedMetadata.propertyName])\n // object[embeddedMetadata.propertyName] = embeddedMetadata.create();\n\n const embeddedMetadata = embeddedMetadatas.shift();\n if (embeddedMetadata) {\n if (!map[embeddedMetadata.propertyName])\n map[embeddedMetadata.propertyName] = embeddedMetadata.create();\n\n extractEmbeddedColumnValue(embeddedMetadatas, map[embeddedMetadata.propertyName]);\n return map;\n }\n map[propertyName] = value;\n return map;\n };\n return extractEmbeddedColumnValue([...this.embeddedMetadata.embeddedMetadataTree], entity);\n\n } else {\n entity[propertyName] = value;\n }\n }\n\n /**\n * Creates entity id map from the given entity ids array.\n */\n createValueMap(value: any) {\n\n // extract column value from embeds of entity if column is in embedded\n if (this.embeddedMetadata) {\n\n // example: post[data][information][counters].id where \"data\", \"information\" and \"counters\" are embeddeds\n // we need to get value of \"id\" column from the post real entity object and return it in a\n // { data: { information: { counters: { id: ... } } } } format\n\n // first step - we extract all parent properties of the entity relative to this column, e.g. [data, information, counters]\n const propertyNames = [...this.embeddedMetadata.parentPropertyNames];\n\n // now need to access post[data][information][counters] to get column value from the counters\n // and on each step we need to create complex literal object, e.g. first { data },\n // then { data: { information } }, then { data: { information: { counters } } },\n // then { data: { information: { counters: [this.propertyName]: entity[data][information][counters][this.propertyName] } } }\n // this recursive function helps doing that\n const extractEmbeddedColumnValue = (propertyNames: string[], map: ObjectLiteral): any => {\n const propertyName = propertyNames.shift();\n if (propertyName) {\n map[propertyName] = {};\n extractEmbeddedColumnValue(propertyNames, map[propertyName]);\n return map;\n }\n map[this.propertyName] = value;\n return map;\n };\n return extractEmbeddedColumnValue(propertyNames, {});\n\n } else { // no embeds - no problems. Simply return column property name and its value of the entity\n return { [this.propertyName]: value };\n }\n }\n\n // ---------------------------------------------------------------------\n // Builder Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds some depend relation metadata properties.\n * This builder method should be used only after embedded metadata tree was build.\n */\n build() {\n this.propertyPath = this.buildPropertyPath();\n }\n\n /**\n * Registers given foreign keys in the relation.\n * This builder method should be used to register foreign key in the relation.\n */\n registerForeignKeys(...foreignKeys: ForeignKeyMetadata[]) {\n this.foreignKeys.push(...foreignKeys);\n }\n\n /**\n * Registers given join columns in the relation.\n * This builder method should be used to register join column in the relation.\n */\n registerJoinColumns(joinColumns: ColumnMetadata[] = [], inverseJoinColumns: ColumnMetadata[] = []) {\n this.joinColumns = joinColumns;\n this.inverseJoinColumns = inverseJoinColumns;\n this.isOwning = this.isManyToOne || ((this.isManyToMany || this.isOneToOne) && this.joinColumns.length > 0);\n this.isOneToOneOwner = this.isOneToOne && this.isOwning;\n this.isOneToOneNotOwner = this.isOneToOne && !this.isOwning;\n this.isManyToManyOwner = this.isManyToMany && this.isOwning;\n this.isManyToManyNotOwner = this.isManyToMany && !this.isOwning;\n this.isWithJoinColumn = this.isManyToOne || this.isOneToOneOwner;\n }\n\n /**\n * Registers a given junction entity metadata.\n * This builder method can be called after junction entity metadata for the many-to-many relation was created.\n */\n registerJunctionEntityMetadata(junctionEntityMetadata: EntityMetadata) {\n this.junctionEntityMetadata = junctionEntityMetadata;\n this.joinTableName = junctionEntityMetadata.tableName;\n if (this.inverseRelation) {\n this.inverseRelation.junctionEntityMetadata = junctionEntityMetadata;\n this.joinTableName = junctionEntityMetadata.tableName;\n }\n }\n\n /**\n * Builds inverse side property path based on given inverse side property factory.\n * This builder method should be used only after properties map of the inverse entity metadata was build.\n */\n buildInverseSidePropertyPath(): string {\n\n if (this.givenInverseSidePropertyFactory) {\n const ownerEntityPropertiesMap = this.inverseEntityMetadata.propertiesMap;\n if (typeof this.givenInverseSidePropertyFactory === \"function\")\n return this.givenInverseSidePropertyFactory(ownerEntityPropertiesMap);\n\n if (typeof this.givenInverseSidePropertyFactory === \"string\")\n return this.givenInverseSidePropertyFactory;\n\n } else if (this.isTreeParent && this.entityMetadata.treeChildrenRelation) {\n return this.entityMetadata.treeChildrenRelation.propertyName;\n\n } else if (this.isTreeChildren && this.entityMetadata.treeParentRelation) {\n return this.entityMetadata.treeParentRelation.propertyName;\n }\n\n return \"\";\n }\n\n /**\n * Builds relation's property path based on its embedded tree.\n */\n buildPropertyPath(): string {\n if (!this.embeddedMetadata || !this.embeddedMetadata.parentPropertyNames.length)\n return this.propertyName;\n\n return this.embeddedMetadata.parentPropertyNames.join(\".\") + \".\" + this.propertyName;\n }\n\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/metadata/RelationMetadata.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAUhD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC;;GAEG;AACH;IAoQI,wEAAwE;IACxE,cAAc;IACd,wEAAwE;IAExE,0BAAY,OAIX;QA9MD;;WAEG;QACH,iBAAY,GAAY,KAAK,CAAC;QAE9B;;WAEG;QACH,mBAAc,GAAY,KAAK,CAAC;QAEhC;;;WAGG;QACH,cAAS,GAAY,KAAK,CAAC;QAE3B;;WAEG;QACH,WAAM,GAAY,KAAK,CAAC;QAExB;;WAEG;QACH,YAAO,GAAY,KAAK,CAAC;QAE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;OAEG;IACH,4CAAiB,GAAjB;QACI,IAAI,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,MAAM;YAC3E,OAAO,IAAI,CAAC,YAAY,CAAC;QAE7B,OAAO,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC;IACzF,CAAC;IAEL,uBAAC;AAAD,CA1iBA,AA0iBC,IAAA","file":"RelationMetadata.js","sourcesContent":["import {RelationType} from \"./types/RelationTypes\";\nimport {EntityMetadata} from \"./EntityMetadata\";\nimport {ForeignKeyMetadata} from \"./ForeignKeyMetadata\";\nimport {ObjectLiteral} from \"../common/ObjectLiteral\";\nimport {ColumnMetadata} from \"./ColumnMetadata\";\nimport {EmbeddedMetadata} from \"./EmbeddedMetadata\";\nimport {RelationMetadataArgs} from \"../metadata-args/RelationMetadataArgs\";\nimport {DeferrableType} from \"./types/DeferrableType\";\nimport {OnUpdateType} from \"./types/OnUpdateType\";\nimport {OnDeleteType} from \"./types/OnDeleteType\";\nimport {PropertyTypeFactory} from \"./types/PropertyTypeInFunction\";\nimport { TypeORMError } from \"../error\";\n\n/**\n * Contains all information about some entity's relation.\n */\nexport class RelationMetadata {\n\n // ---------------------------------------------------------------------\n // Public Properties\n // ---------------------------------------------------------------------\n\n /**\n * Entity metadata of the entity where this relation is placed.\n *\n * For example for @ManyToMany(type => Category) in Post, entityMetadata will be metadata of Post entity.\n */\n entityMetadata: EntityMetadata;\n\n /**\n * Entity metadata of the entity that is targeted by this relation.\n *\n * For example for @ManyToMany(type => Category) in Post, inverseEntityMetadata will be metadata of Category entity.\n */\n inverseEntityMetadata: EntityMetadata;\n\n /**\n * Entity metadata of the junction table.\n * Junction tables have their own entity metadata objects.\n * Defined only for many-to-many relations.\n */\n junctionEntityMetadata?: EntityMetadata;\n\n /**\n * Embedded metadata where this relation is.\n * If this relation is not in embed then this property value is undefined.\n */\n embeddedMetadata?: EmbeddedMetadata;\n\n /**\n * Relation type, e.g. is it one-to-one, one-to-many, many-to-one or many-to-many.\n */\n relationType: RelationType;\n\n /**\n * Target entity to which this relation is applied.\n * Target IS NOT equal to entityMetadata.target, because relation\n *\n * For example for @ManyToMany(type => Category) in Post, target will be Post.\n * If @ManyToMany(type => Category) is in Counters which is embedded into Post, target will be Counters.\n * If @ManyToMany(type => Category) is in abstract class BaseUser which Post extends, target will be BaseUser.\n * Target can be string if its defined in entity schema instead of class.\n */\n target: Function|string;\n\n /**\n * Target's property name to which relation decorator is applied.\n */\n propertyName: string;\n\n /**\n * Gets full path to this column property (including relation name).\n * Full path is relevant when column is used in embeds (one or multiple nested).\n * For example it will return \"counters.subcounters.likes\".\n * If property is not in embeds then it returns just property name of the column.\n */\n propertyPath: string;\n\n /**\n * Indicates if this is a parent (can be only many-to-one relation) relation in the tree tables.\n */\n isTreeParent: boolean = false;\n\n /**\n * Indicates if this is a children (can be only one-to-many relation) relation in the tree tables.\n */\n isTreeChildren: boolean = false;\n\n /**\n * Indicates if this relation's column is a primary key.\n * Can be used only for many-to-one and owner one-to-one relations.\n */\n isPrimary: boolean = false;\n\n /**\n * Indicates if this relation is lazily loaded.\n */\n isLazy: boolean = false;\n\n /**\n * Indicates if this relation is eagerly loaded.\n */\n isEager: boolean = false;\n\n /**\n * Indicates if persistence is enabled for the relation.\n * 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.\n * If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.\n * This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.\n */\n persistenceEnabled: boolean = true;\n\n /**\n * When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.\n */\n orphanedRowAction?: \"nullify\" | \"delete\" | \"soft-delete\";\n\n /**\n * If set to true then related objects are allowed to be inserted to the database.\n */\n isCascadeInsert: boolean = false;\n\n /**\n * If set to true then related objects are allowed to be updated in the database.\n */\n isCascadeUpdate: boolean = false;\n\n /**\n * If set to true then related objects are allowed to be remove from the database.\n */\n isCascadeRemove: boolean = false;\n\n /**\n * If set to true then related objects are allowed to be soft-removed from the database.\n */\n isCascadeSoftRemove: boolean = false;\n\n /**\n * If set to true then related objects are allowed to be recovered from the database.\n */\n isCascadeRecover: boolean = false;\n\n /**\n * Indicates if relation column value can be nullable or not.\n */\n isNullable: boolean = true;\n\n /**\n * What to do with a relation on deletion of the row containing a foreign key.\n */\n onDelete?: OnDeleteType;\n\n /**\n * What to do with a relation on update of the row containing a foreign key.\n */\n onUpdate?: OnUpdateType;\n\n /**\n * What to do with a relation on update of the row containing a foreign key.\n */\n deferrable?: DeferrableType;\n\n /**\n * Indicates whether foreign key constraints will be created for join columns.\n * Can be used only for many-to-one and owner one-to-one relations.\n * Defaults to true.\n */\n createForeignKeyConstraints: boolean = true;\n\n /**\n * Gets the property's type to which this relation is applied.\n *\n * For example for @ManyToMany(type => Category) in Post, target will be Category.\n */\n type: Function|string;\n\n /**\n * Indicates if this side is an owner of this relation.\n */\n isOwning: boolean = false;\n\n /**\n * Checks if this relation's type is \"one-to-one\".\n */\n isOneToOne: boolean = false;\n\n /**\n * Checks if this relation is owner side of the \"one-to-one\" relation.\n * Owner side means this side of relation has a join column in the table.\n */\n isOneToOneOwner: boolean = false;\n\n /**\n * Checks if this relation has a join column (e.g. is it many-to-one or one-to-one owner side).\n */\n isWithJoinColumn: boolean = false;\n\n /**\n * Checks if this relation is NOT owner side of the \"one-to-one\" relation.\n * NOT owner side means this side of relation does not have a join column in the table.\n */\n isOneToOneNotOwner: boolean = false;\n\n /**\n * Checks if this relation's type is \"one-to-many\".\n */\n isOneToMany: boolean = false;\n\n /**\n * Checks if this relation's type is \"many-to-one\".\n */\n isManyToOne: boolean = false;\n\n /**\n * Checks if this relation's type is \"many-to-many\".\n */\n isManyToMany: boolean = false;\n\n /**\n * Checks if this relation's type is \"many-to-many\", and is owner side of the relationship.\n * Owner side means this side of relation has a join table.\n */\n isManyToManyOwner: boolean = false;\n\n /**\n * Checks if this relation's type is \"many-to-many\", and is NOT owner side of the relationship.\n * Not owner side means this side of relation does not have a join table.\n */\n isManyToManyNotOwner: boolean = false;\n\n /**\n * Gets the property path of the inverse side of the relation.\n */\n inverseSidePropertyPath: string;\n\n /**\n * Inverse side of the relation set by user.\n *\n * Inverse side set in the relation can be either string - property name of the column on inverse side,\n * either can be a function that accepts a map of properties with the object and returns one of them.\n * Second approach is used to achieve type-safety.\n */\n givenInverseSidePropertyFactory: PropertyTypeFactory<any>;\n\n /**\n * Gets the relation metadata of the inverse side of this relation.\n */\n inverseRelation?: RelationMetadata;\n\n /**\n * Join table name.\n */\n joinTableName: string;\n\n /**\n * Foreign keys created for this relation.\n */\n foreignKeys: ForeignKeyMetadata[] = [];\n\n /**\n * Join table columns.\n * Join columns can be obtained only from owner side of the relation.\n * From non-owner side of the relation join columns will be empty.\n * If this relation is a many-to-one/one-to-one then it takes join columns from the current entity.\n * If this relation is many-to-many then it takes all owner join columns from the junction entity.\n */\n joinColumns: ColumnMetadata[] = [];\n\n /**\n * Inverse join table columns.\n * Inverse join columns are supported only for many-to-many relations\n * and can be obtained only from owner side of the relation.\n * From non-owner side of the relation join columns will be undefined.\n */\n inverseJoinColumns: ColumnMetadata[] = [];\n\n // ---------------------------------------------------------------------\n // Constructor\n // ---------------------------------------------------------------------\n\n constructor(options: {\n entityMetadata: EntityMetadata,\n embeddedMetadata?: EmbeddedMetadata,\n args: RelationMetadataArgs\n }) {\n this.entityMetadata = options.entityMetadata;\n this.embeddedMetadata = options.embeddedMetadata!;\n const args = options.args;\n this.target = args.target;\n this.propertyName = args.propertyName;\n this.relationType = args.relationType;\n\n if (args.inverseSideProperty)\n this.givenInverseSidePropertyFactory = args.inverseSideProperty;\n\n this.isLazy = args.isLazy || false;\n // this.isCascadeInsert = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"insert\") !== -1);\n // this.isCascadeUpdate = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"update\") !== -1);\n // this.isCascadeRemove = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"remove\") !== -1);\n // this.isCascadeSoftRemove = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"soft-remove\") !== -1);\n // this.isCascadeRecover = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"recover\") !== -1);\n this.isCascadeInsert = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"insert\") !== -1);\n this.isCascadeUpdate = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"update\") !== -1);\n this.isCascadeRemove = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"remove\") !== -1);\n this.isCascadeSoftRemove = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"soft-remove\") !== -1);\n this.isCascadeRecover = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"recover\") !== -1);\n this.isPrimary = args.options.primary || false;\n this.isNullable = args.options.nullable === false || this.isPrimary ? false : true;\n this.onDelete = args.options.onDelete;\n this.onUpdate = args.options.onUpdate;\n this.deferrable = args.options.deferrable;\n this.createForeignKeyConstraints = args.options.createForeignKeyConstraints === false ? false : true;\n this.isEager = args.options.eager || false;\n this.persistenceEnabled = args.options.persistence === false ? false : true;\n this.orphanedRowAction = args.options.orphanedRowAction || \"nullify\";\n this.isTreeParent = args.isTreeParent || false;\n this.isTreeChildren = args.isTreeChildren || false;\n this.type = args.type instanceof Function ? (args.type as () => any)() : args.type;\n\n this.isOneToOne = this.relationType === \"one-to-one\";\n this.isOneToMany = this.relationType === \"one-to-many\";\n this.isManyToOne = this.relationType === \"many-to-one\";\n this.isManyToMany = this.relationType === \"many-to-many\";\n this.isOneToOneNotOwner = this.isOneToOne ? true : false;\n this.isManyToManyNotOwner = this.isManyToMany ? true : false;\n }\n\n // ---------------------------------------------------------------------\n // Public Methods\n // ---------------------------------------------------------------------\n\n /**\n * Creates join column ids map from the given related entity ids array.\n */\n getRelationIdMap(entity: ObjectLiteral): ObjectLiteral|undefined {\n const joinColumns = this.isOwning ? this.joinColumns : this.inverseRelation!.joinColumns;\n const referencedColumns = joinColumns.map(joinColumn => joinColumn.referencedColumn!);\n // console.log(\"entity\", entity);\n // console.log(\"referencedColumns\", referencedColumns);\n return EntityMetadata.getValueMap(entity, referencedColumns);\n }\n\n /**\n * Ensures that given object is an entity id map.\n * If given id is an object then it means its already id map.\n * If given id isn't an object then it means its a value of the id column\n * and it creates a new id map with this value and name of the primary column.\n */\n ensureRelationIdMap(id: any): ObjectLiteral {\n if (id instanceof Object)\n return id;\n\n const joinColumns = this.isOwning ? this.joinColumns : this.inverseRelation!.joinColumns;\n const referencedColumns = joinColumns.map(joinColumn => joinColumn.referencedColumn!);\n\n if (referencedColumns.length > 1)\n throw new TypeORMError(`Cannot create relation id map for a single value because relation contains multiple referenced columns.`);\n\n return referencedColumns[0].createValueMap(id);\n }\n\n /**\n * Extracts column value from the given entity.\n * If column is in embedded (or recursive embedded) it extracts its value from there.\n */\n getEntityValue(entity: ObjectLiteral, getLazyRelationsPromiseValue: boolean = false): any|undefined {\n if (entity === null || entity === undefined) return undefined;\n // extract column value from embeddeds of entity if column is in embedded\n if (this.embeddedMetadata) {\n\n // example: post[data][information][counters].id where \"data\", \"information\" and \"counters\" are embeddeds\n // we need to get value of \"id\" column from the post real entity object\n\n // first step - we extract all parent properties of the entity relative to this column, e.g. [data, information, counters]\n const propertyNames = [...this.embeddedMetadata.parentPropertyNames];\n\n // next we need to access post[data][information][counters][this.propertyName] to get column value from the counters\n // this recursive function takes array of generated property names and gets the post[data][information][counters] embed\n const extractEmbeddedColumnValue = (propertyNames: string[], value: ObjectLiteral): any => {\n const propertyName = propertyNames.shift();\n if (propertyName) {\n if (value[propertyName]) {\n return extractEmbeddedColumnValue(propertyNames, value[propertyName]);\n }\n return undefined;\n }\n return value;\n };\n\n // once we get nested embed object we get its column, e.g. post[data][information][counters][this.propertyName]\n const embeddedObject = extractEmbeddedColumnValue(propertyNames, entity);\n\n if (this.isLazy) {\n if (embeddedObject[\"__\" + this.propertyName + \"__\"] !== undefined)\n return embeddedObject[\"__\" + this.propertyName + \"__\"];\n\n if (getLazyRelationsPromiseValue === true)\n return embeddedObject[this.propertyName];\n\n return undefined;\n }\n return embeddedObject ? embeddedObject[this.isLazy ? \"__\" + this.propertyName + \"__\" : this.propertyName] : undefined;\n\n } else { // no embeds - no problems. Simply return column name by property name of the entity\n if (this.isLazy) {\n if (entity[\"__\" + this.propertyName + \"__\"] !== undefined)\n return entity[\"__\" + this.propertyName + \"__\"];\n\n if (getLazyRelationsPromiseValue === true)\n return entity[this.propertyName];\n\n return undefined;\n }\n return entity[this.propertyName];\n }\n }\n\n /**\n * Sets given entity's relation's value.\n * Using of this method helps to set entity relation's value of the lazy and non-lazy relations.\n *\n * If merge is set to true, it merges given value into currently\n */\n setEntityValue(entity: ObjectLiteral, value: any): void {\n const propertyName = this.isLazy ? \"__\" + this.propertyName + \"__\" : this.propertyName;\n\n if (this.embeddedMetadata) {\n\n // first step - we extract all parent properties of the entity relative to this column, e.g. [data, information, counters]\n const extractEmbeddedColumnValue = (embeddedMetadatas: EmbeddedMetadata[], map: ObjectLiteral): any => {\n // if (!object[embeddedMetadata.propertyName])\n // object[embeddedMetadata.propertyName] = embeddedMetadata.create();\n\n const embeddedMetadata = embeddedMetadatas.shift();\n if (embeddedMetadata) {\n if (!map[embeddedMetadata.propertyName])\n map[embeddedMetadata.propertyName] = embeddedMetadata.create();\n\n extractEmbeddedColumnValue(embeddedMetadatas, map[embeddedMetadata.propertyName]);\n return map;\n }\n map[propertyName] = value;\n return map;\n };\n return extractEmbeddedColumnValue([...this.embeddedMetadata.embeddedMetadataTree], entity);\n\n } else {\n entity[propertyName] = value;\n }\n }\n\n /**\n * Creates entity id map from the given entity ids array.\n */\n createValueMap(value: any) {\n\n // extract column value from embeds of entity if column is in embedded\n if (this.embeddedMetadata) {\n\n // example: post[data][information][counters].id where \"data\", \"information\" and \"counters\" are embeddeds\n // we need to get value of \"id\" column from the post real entity object and return it in a\n // { data: { information: { counters: { id: ... } } } } format\n\n // first step - we extract all parent properties of the entity relative to this column, e.g. [data, information, counters]\n const propertyNames = [...this.embeddedMetadata.parentPropertyNames];\n\n // now need to access post[data][information][counters] to get column value from the counters\n // and on each step we need to create complex literal object, e.g. first { data },\n // then { data: { information } }, then { data: { information: { counters } } },\n // then { data: { information: { counters: [this.propertyName]: entity[data][information][counters][this.propertyName] } } }\n // this recursive function helps doing that\n const extractEmbeddedColumnValue = (propertyNames: string[], map: ObjectLiteral): any => {\n const propertyName = propertyNames.shift();\n if (propertyName) {\n map[propertyName] = {};\n extractEmbeddedColumnValue(propertyNames, map[propertyName]);\n return map;\n }\n map[this.propertyName] = value;\n return map;\n };\n return extractEmbeddedColumnValue(propertyNames, {});\n\n } else { // no embeds - no problems. Simply return column property name and its value of the entity\n return { [this.propertyName]: value };\n }\n }\n\n // ---------------------------------------------------------------------\n // Builder Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds some depend relation metadata properties.\n * This builder method should be used only after embedded metadata tree was build.\n */\n build() {\n this.propertyPath = this.buildPropertyPath();\n }\n\n /**\n * Registers given foreign keys in the relation.\n * This builder method should be used to register foreign key in the relation.\n */\n registerForeignKeys(...foreignKeys: ForeignKeyMetadata[]) {\n this.foreignKeys.push(...foreignKeys);\n }\n\n /**\n * Registers given join columns in the relation.\n * This builder method should be used to register join column in the relation.\n */\n registerJoinColumns(joinColumns: ColumnMetadata[] = [], inverseJoinColumns: ColumnMetadata[] = []) {\n this.joinColumns = joinColumns;\n this.inverseJoinColumns = inverseJoinColumns;\n this.isOwning = this.isManyToOne || ((this.isManyToMany || this.isOneToOne) && this.joinColumns.length > 0);\n this.isOneToOneOwner = this.isOneToOne && this.isOwning;\n this.isOneToOneNotOwner = this.isOneToOne && !this.isOwning;\n this.isManyToManyOwner = this.isManyToMany && this.isOwning;\n this.isManyToManyNotOwner = this.isManyToMany && !this.isOwning;\n this.isWithJoinColumn = this.isManyToOne || this.isOneToOneOwner;\n }\n\n /**\n * Registers a given junction entity metadata.\n * This builder method can be called after junction entity metadata for the many-to-many relation was created.\n */\n registerJunctionEntityMetadata(junctionEntityMetadata: EntityMetadata) {\n this.junctionEntityMetadata = junctionEntityMetadata;\n this.joinTableName = junctionEntityMetadata.tableName;\n if (this.inverseRelation) {\n this.inverseRelation.junctionEntityMetadata = junctionEntityMetadata;\n this.joinTableName = junctionEntityMetadata.tableName;\n }\n }\n\n /**\n * Builds inverse side property path based on given inverse side property factory.\n * This builder method should be used only after properties map of the inverse entity metadata was build.\n */\n buildInverseSidePropertyPath(): string {\n\n if (this.givenInverseSidePropertyFactory) {\n const ownerEntityPropertiesMap = this.inverseEntityMetadata.propertiesMap;\n if (typeof this.givenInverseSidePropertyFactory === \"function\")\n return this.givenInverseSidePropertyFactory(ownerEntityPropertiesMap);\n\n if (typeof this.givenInverseSidePropertyFactory === \"string\")\n return this.givenInverseSidePropertyFactory;\n\n } else if (this.isTreeParent && this.entityMetadata.treeChildrenRelation) {\n return this.entityMetadata.treeChildrenRelation.propertyName;\n\n } else if (this.isTreeChildren && this.entityMetadata.treeParentRelation) {\n return this.entityMetadata.treeParentRelation.propertyName;\n }\n\n return \"\";\n }\n\n /**\n * Builds relation's property path based on its embedded tree.\n */\n buildPropertyPath(): string {\n if (!this.embeddedMetadata || !this.embeddedMetadata.parentPropertyNames.length)\n return this.propertyName;\n\n return this.embeddedMetadata.parentPropertyNames.join(\".\") + \".\" + this.propertyName;\n }\n\n}\n"],"sourceRoot":".."}
|
|
@@ -59,6 +59,7 @@ var EntityMetadataValidator = /** @class */ (function () {
|
|
|
59
59
|
var sameDiscriminatorValueEntityMetadata = allEntityMetadatas.find(function (metadata) {
|
|
60
60
|
return metadata !== entityMetadata
|
|
61
61
|
&& (metadata.inheritancePattern === "STI" || metadata.tableType === "entity-child")
|
|
62
|
+
&& metadata.tableName === entityMetadata.tableName
|
|
62
63
|
&& metadata.discriminatorValue === entityMetadata.discriminatorValue
|
|
63
64
|
&& metadata.inheritanceTree.some(function (parent) { return entityMetadata.inheritanceTree.indexOf(parent) !== -1; });
|
|
64
65
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/metadata-builder/EntityMetadataValidator.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,yBAAyB,EAAC,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAC,sBAAsB,EAAC,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAC,yBAAyB,EAAC,MAAM,oCAAoC,CAAC;AAE7E,OAAO,EAAC,WAAW,EAAC,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAC,eAAe,EAAC,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAC,uBAAuB,EAAC,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAC,wBAAwB,EAAC,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAC,mBAAmB,EAAC,MAAM,+CAA+C,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,mEAAmE;AACnE,6FAA6F;AAC7F,sEAAsE;AACtE,mGAAmG;AACnG,2GAA2G;AAC3G,6DAA6D;AAC7D,uEAAuE;AACvE,iFAAiF;AAEjF,2FAA2F;AAC3F,wHAAwH;AACxH,gIAAgI;AAChI,mGAAmG;AACnG,8EAA8E;AAC9E,8CAA8C;AAC9C,yDAAyD;AAEzD;;GAEG;AACH;IAAA;IAmNA,CAAC;IAjNG,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,8CAAY,GAAZ,UAAa,eAAiC,EAAE,MAA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e,CAAC,YAAY,uCAAkC,CAAA;wBACvH,wDAAsD,CAAC,CAAC;YACpE,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAEL,8BAAC;AAAD,CAnNA,AAmNC,IAAA","file":"EntityMetadataValidator.js","sourcesContent":["import {EntityMetadata} from \"../metadata/EntityMetadata\";\nimport {MissingPrimaryColumnError} from \"../error/MissingPrimaryColumnError\";\nimport {CircularRelationsError} from \"../error/CircularRelationsError\";\nimport {DepGraph} from \"../util/DepGraph\";\nimport {Driver} from \"../driver/Driver\";\nimport {DataTypeNotSupportedError} from \"../error/DataTypeNotSupportedError\";\nimport {ColumnType} from \"../driver/types/ColumnTypes\";\nimport {MongoDriver} from \"../driver/mongodb/MongoDriver\";\nimport {SqlServerDriver} from \"../driver/sqlserver/SqlServerDriver\";\nimport {MysqlDriver} from \"../driver/mysql/MysqlDriver\";\nimport {NoConnectionOptionError} from \"../error/NoConnectionOptionError\";\nimport {InitializedRelationError} from \"../error/InitializedRelationError\";\nimport {AuroraDataApiDriver} from \"../driver/aurora-data-api/AuroraDataApiDriver\";\nimport { TypeORMError } from \"../error\";\n\n/// todo: add check if there are multiple tables with the same name\n/// todo: add checks when generated column / table names are too long for the specific driver\n// todo: type in function validation, inverse side function validation\n// todo: check on build for duplicate names, since naming checking was removed from MetadataStorage\n// todo: duplicate name checking for: table, relation, column, index, naming strategy, join tables/columns?\n// todo: check if multiple tree parent metadatas in validator\n// todo: tree decorators can be used only on closure table (validation)\n// todo: throw error if parent tree metadata was not specified in a closure table\n\n// todo: MetadataArgsStorage: type in function validation, inverse side function validation\n// todo: MetadataArgsStorage: check on build for duplicate names, since naming checking was removed from MetadataStorage\n// todo: MetadataArgsStorage: duplicate name checking for: table, relation, column, index, naming strategy, join tables/columns?\n// todo: MetadataArgsStorage: check for duplicate targets too since this check has been removed too\n// todo: check if relation decorator contains primary: true and nullable: true\n// todo: check column length, precision. scale\n// todo: MySQL index can be unique or spatial or fulltext\n\n/**\n * Validates built entity metadatas.\n */\nexport class EntityMetadataValidator {\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Validates all given entity metadatas.\n */\n validateMany(entityMetadatas: EntityMetadata[], driver: Driver) {\n entityMetadatas.forEach(entityMetadata => this.validate(entityMetadata, entityMetadatas, driver));\n this.validateDependencies(entityMetadatas);\n this.validateEagerRelations(entityMetadatas);\n }\n\n /**\n * Validates given entity metadata.\n */\n validate(entityMetadata: EntityMetadata, allEntityMetadatas: EntityMetadata[], driver: Driver) {\n\n // check if table metadata has an id\n if (!entityMetadata.primaryColumns.length && !entityMetadata.isJunction)\n throw new MissingPrimaryColumnError(entityMetadata);\n\n // validate if table is using inheritance it has a discriminator\n // also validate if discriminator values are not empty and not repeated\n if (entityMetadata.inheritancePattern === \"STI\" || entityMetadata.tableType === \"entity-child\") {\n if (!entityMetadata.discriminatorColumn)\n throw new TypeORMError(`Entity ${entityMetadata.name} using single-table inheritance, it should also have a discriminator column. Did you forget to put discriminator column options?`);\n\n if (typeof entityMetadata.discriminatorValue === \"undefined\")\n throw new TypeORMError(`Entity ${entityMetadata.name} has an undefined discriminator value. Discriminator value should be defined.`);\n\n const sameDiscriminatorValueEntityMetadata = allEntityMetadatas.find(metadata => {\n return metadata !== entityMetadata\n && (metadata.inheritancePattern === \"STI\" || metadata.tableType === \"entity-child\")\n && metadata.discriminatorValue === entityMetadata.discriminatorValue\n && metadata.inheritanceTree.some(parent => entityMetadata.inheritanceTree.indexOf(parent) !== -1);\n });\n if (sameDiscriminatorValueEntityMetadata)\n throw new TypeORMError(`Entities ${entityMetadata.name} and ${sameDiscriminatorValueEntityMetadata.name} have the same discriminator values. Make sure they are different while using the @ChildEntity decorator.`);\n }\n\n entityMetadata.relationCounts.forEach(relationCount => {\n if (relationCount.relation.isManyToOne || relationCount.relation.isOneToOne)\n throw new TypeORMError(`Relation count can not be implemented on ManyToOne or OneToOne relations.`);\n });\n\n if (!(driver instanceof MongoDriver)) {\n entityMetadata.columns.forEach(column => {\n const normalizedColumn = driver.normalizeType(column) as ColumnType;\n if (driver.supportedDataTypes.indexOf(normalizedColumn) === -1)\n throw new DataTypeNotSupportedError(column, normalizedColumn, driver.options.type);\n if (column.length && driver.withLengthColumnTypes.indexOf(normalizedColumn) === -1)\n throw new TypeORMError(`Column ${column.propertyName} of Entity ${entityMetadata.name} does not support length property.`);\n if (column.type === \"enum\" && !column.enum && !column.enumName)\n throw new TypeORMError(`Column \"${column.propertyName}\" of Entity \"${entityMetadata.name}\" is defined as enum, but missing \"enum\" or \"enumName\" properties.`);\n });\n }\n\n if (driver instanceof MysqlDriver || driver instanceof AuroraDataApiDriver) {\n const generatedColumns = entityMetadata.columns.filter(column => column.isGenerated && column.generationStrategy !== \"uuid\");\n if (generatedColumns.length > 1)\n throw new TypeORMError(`Error in ${entityMetadata.name} entity. There can be only one auto-increment column in MySql table.`);\n }\n\n // for mysql we are able to not define a default selected database, instead all entities can have their database\n // defined in their decorators. To make everything work either all entities must have database define and we\n // can live without database set in the connection options, either database in the connection options must be set\n if (driver instanceof MysqlDriver) {\n const metadatasWithDatabase = allEntityMetadatas.filter(metadata => metadata.database);\n if (metadatasWithDatabase.length === 0 && !driver.database)\n throw new NoConnectionOptionError(\"database\");\n }\n\n if (driver instanceof SqlServerDriver) {\n const charsetColumns = entityMetadata.columns.filter(column => column.charset);\n if (charsetColumns.length > 1)\n throw new TypeORMError(`Character set specifying is not supported in Sql Server`);\n }\n\n // check if relations are all without initialized properties\n const entityInstance = entityMetadata.create();\n entityMetadata.relations.forEach(relation => {\n if (relation.isManyToMany || relation.isOneToMany) {\n\n // we skip relations for which persistence is disabled since initialization in them cannot harm somehow\n if (relation.persistenceEnabled === false)\n return;\n\n // get entity relation value and check if its an array\n const relationInitializedValue = relation.getEntityValue(entityInstance);\n if (Array.isArray(relationInitializedValue))\n throw new InitializedRelationError(relation);\n }\n });\n\n // validate relations\n entityMetadata.relations.forEach(relation => {\n\n // check join tables:\n // using JoinTable is possible only on one side of the many-to-many relation\n // todo(dima): fix\n // if (relation.joinTable) {\n // if (!relation.isManyToMany)\n // throw new UsingJoinTableIsNotAllowedError(entityMetadata, relation);\n\n // // if there is inverse side of the relation, then check if it does not have join table too\n // if (relation.hasInverseSide && relation.inverseRelation.joinTable)\n // throw new UsingJoinTableOnlyOnOneSideAllowedError(entityMetadata, relation);\n // }\n\n // check join columns:\n // using JoinColumn is possible only on one side of the relation and on one-to-one, many-to-one relation types\n // first check if relation is one-to-one or many-to-one\n // todo(dima): fix\n /*if (relation.joinColumn) {\n\n // join column can be applied only on one-to-one and many-to-one relations\n if (!relation.isOneToOne && !relation.isManyToOne)\n throw new UsingJoinColumnIsNotAllowedError(entityMetadata, relation);\n\n // if there is inverse side of the relation, then check if it does not have join table too\n if (relation.hasInverseSide && relation.inverseRelation.joinColumn && relation.isOneToOne)\n throw new UsingJoinColumnOnlyOnOneSideAllowedError(entityMetadata, relation);\n\n // check if join column really has referenced column\n if (relation.joinColumn && !relation.joinColumn.referencedColumn)\n throw new TypeORMError(`Join column does not have referenced column set`);\n\n }\n\n // if its a one-to-one relation and JoinColumn is missing on both sides of the relation\n // or its one-side relation without JoinColumn we should give an error\n if (!relation.joinColumn && relation.isOneToOne && (!relation.hasInverseSide || !relation.inverseRelation.joinColumn))\n throw new MissingJoinColumnError(entityMetadata, relation);*/\n\n // if its a many-to-many relation and JoinTable is missing on both sides of the relation\n // or its one-side relation without JoinTable we should give an error\n // todo(dima): fix it\n // if (!relation.joinTable && relation.isManyToMany && (!relation.hasInverseSide || !relation.inverseRelation.joinTable))\n // throw new MissingJoinTableError(entityMetadata, relation);\n\n\n // todo: validate if its one-to-one and side which does not have join column MUST have inverse side\n // todo: validate if its many-to-many and side which does not have join table MUST have inverse side\n // todo: if there is a relation, and inverse side is specified only on one side, shall we give error\n // todo: with message like: \"Inverse side is specified only on one side of the relationship. Specify on other side too to prevent confusion\".\n // todo: add validation if there two entities with the same target, and show error message with description of the problem (maybe file was renamed/moved but left in output directory)\n // todo: check if there are multiple columns on the same column applied.\n // todo: check column type if is missing in relational databases (throw new TypeORMError(`Column type of ${type} cannot be determined.`);)\n // todo: include driver-specific checks. for example in mongodb empty prefixes are not allowed\n // todo: if multiple columns with same name - throw exception, including cases when columns are in embeds with same prefixes or without prefix at all\n // todo: if multiple primary key used, at least one of them must be unique or @Index decorator must be set on entity\n // todo: check if entity with duplicate names, some decorators exist\n\n\n });\n\n // make sure cascade remove is not set for both sides of relationships (can be set in OneToOne decorators)\n entityMetadata.relations.forEach(relation => {\n const isCircularCascadeRemove = relation.isCascadeRemove && relation.inverseRelation && relation.inverseRelation!.isCascadeRemove;\n if (isCircularCascadeRemove)\n throw new TypeORMError(`Relation ${entityMetadata.name}#${relation.propertyName} and ${relation.inverseRelation!.entityMetadata.name}#${relation.inverseRelation!.propertyName} both has cascade remove set. ` +\n `This may lead to unexpected circular removals. Please set cascade remove only from one side of relationship.`);\n }); // todo: maybe better just deny removal from one to one relation without join column?\n\n entityMetadata.eagerRelations.forEach(relation => {\n\n });\n }\n\n /**\n * Validates dependencies of the entity metadatas.\n */\n protected validateDependencies(entityMetadatas: EntityMetadata[]) {\n\n const graph = new DepGraph();\n entityMetadatas.forEach(entityMetadata => {\n graph.addNode(entityMetadata.name);\n });\n entityMetadatas.forEach(entityMetadata => {\n entityMetadata.relationsWithJoinColumns\n .filter(relation => !relation.isNullable)\n .forEach(relation => {\n graph.addDependency(entityMetadata.name, relation.inverseEntityMetadata.name);\n });\n });\n try {\n graph.overallOrder();\n\n } catch (err) {\n throw new CircularRelationsError(err.toString().replace(\"Error: Dependency Cycle Found: \", \"\"));\n }\n }\n\n /**\n * Validates eager relations to prevent circular dependency in them.\n */\n protected validateEagerRelations(entityMetadatas: EntityMetadata[]) {\n entityMetadatas.forEach(entityMetadata => {\n entityMetadata.eagerRelations.forEach(relation => {\n if (relation.inverseRelation && relation.inverseRelation.isEager)\n throw new TypeORMError(`Circular eager relations are disallowed. ` +\n `${entityMetadata.targetName}#${relation.propertyPath} contains \"eager: true\", and its inverse side ` +\n `${relation.inverseEntityMetadata.targetName}#${relation.inverseRelation.propertyPath} contains \"eager: true\" as well.` +\n ` Remove \"eager: true\" from one side of the relation.`);\n });\n });\n }\n\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/metadata-builder/EntityMetadataValidator.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,yBAAyB,EAAC,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAC,sBAAsB,EAAC,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAC,yBAAyB,EAAC,MAAM,oCAAoC,CAAC;AAE7E,OAAO,EAAC,WAAW,EAAC,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAC,eAAe,EAAC,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAC,uBAAuB,EAAC,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAC,wBAAwB,EAAC,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAC,mBAAmB,EAAC,MAAM,+CAA+C,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,mEAAmE;AACnE,6FAA6F;AAC7F,sEAAsE;AACtE,mGAAmG;AACnG,2GAA2G;AAC3G,6DAA6D;AAC7D,uEAAuE;AACvE,iFAAiF;AAEjF,2FAA2F;AAC3F,wHAAwH;AACxH,gIAAgI;AAChI,mGAAmG;AACnG,8EAA8E;AAC9E,8CAA8C;AAC9C,yDAAyD;AAEzD;;GAEG;AACH;IAAA;IAoNA,CAAC;IAlNG,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,8CAAY,GAAZ,UAAa,eAAiC,EAAE,MAAc;QAA9D,iBAIC;QAHG,eAAe,CAAC,OAAO,CAA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AC,eAAe,CAAC,YAAY,uCAAkC,CAAA;wBACvH,wDAAsD,CAAC,CAAC;YACpE,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAEL,8BAAC;AAAD,CApNA,AAoNC,IAAA","file":"EntityMetadataValidator.js","sourcesContent":["import {EntityMetadata} from \"../metadata/EntityMetadata\";\nimport {MissingPrimaryColumnError} from \"../error/MissingPrimaryColumnError\";\nimport {CircularRelationsError} from \"../error/CircularRelationsError\";\nimport {DepGraph} from \"../util/DepGraph\";\nimport {Driver} from \"../driver/Driver\";\nimport {DataTypeNotSupportedError} from \"../error/DataTypeNotSupportedError\";\nimport {ColumnType} from \"../driver/types/ColumnTypes\";\nimport {MongoDriver} from \"../driver/mongodb/MongoDriver\";\nimport {SqlServerDriver} from \"../driver/sqlserver/SqlServerDriver\";\nimport {MysqlDriver} from \"../driver/mysql/MysqlDriver\";\nimport {NoConnectionOptionError} from \"../error/NoConnectionOptionError\";\nimport {InitializedRelationError} from \"../error/InitializedRelationError\";\nimport {AuroraDataApiDriver} from \"../driver/aurora-data-api/AuroraDataApiDriver\";\nimport { TypeORMError } from \"../error\";\n\n/// todo: add check if there are multiple tables with the same name\n/// todo: add checks when generated column / table names are too long for the specific driver\n// todo: type in function validation, inverse side function validation\n// todo: check on build for duplicate names, since naming checking was removed from MetadataStorage\n// todo: duplicate name checking for: table, relation, column, index, naming strategy, join tables/columns?\n// todo: check if multiple tree parent metadatas in validator\n// todo: tree decorators can be used only on closure table (validation)\n// todo: throw error if parent tree metadata was not specified in a closure table\n\n// todo: MetadataArgsStorage: type in function validation, inverse side function validation\n// todo: MetadataArgsStorage: check on build for duplicate names, since naming checking was removed from MetadataStorage\n// todo: MetadataArgsStorage: duplicate name checking for: table, relation, column, index, naming strategy, join tables/columns?\n// todo: MetadataArgsStorage: check for duplicate targets too since this check has been removed too\n// todo: check if relation decorator contains primary: true and nullable: true\n// todo: check column length, precision. scale\n// todo: MySQL index can be unique or spatial or fulltext\n\n/**\n * Validates built entity metadatas.\n */\nexport class EntityMetadataValidator {\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Validates all given entity metadatas.\n */\n validateMany(entityMetadatas: EntityMetadata[], driver: Driver) {\n entityMetadatas.forEach(entityMetadata => this.validate(entityMetadata, entityMetadatas, driver));\n this.validateDependencies(entityMetadatas);\n this.validateEagerRelations(entityMetadatas);\n }\n\n /**\n * Validates given entity metadata.\n */\n validate(entityMetadata: EntityMetadata, allEntityMetadatas: EntityMetadata[], driver: Driver) {\n\n // check if table metadata has an id\n if (!entityMetadata.primaryColumns.length && !entityMetadata.isJunction)\n throw new MissingPrimaryColumnError(entityMetadata);\n\n // validate if table is using inheritance it has a discriminator\n // also validate if discriminator values are not empty and not repeated\n if (entityMetadata.inheritancePattern === \"STI\" || entityMetadata.tableType === \"entity-child\") {\n if (!entityMetadata.discriminatorColumn)\n throw new TypeORMError(`Entity ${entityMetadata.name} using single-table inheritance, it should also have a discriminator column. Did you forget to put discriminator column options?`);\n\n if (typeof entityMetadata.discriminatorValue === \"undefined\")\n throw new TypeORMError(`Entity ${entityMetadata.name} has an undefined discriminator value. Discriminator value should be defined.`);\n\n const sameDiscriminatorValueEntityMetadata = allEntityMetadatas.find(metadata => {\n return metadata !== entityMetadata\n && (metadata.inheritancePattern === \"STI\" || metadata.tableType === \"entity-child\")\n && metadata.tableName === entityMetadata.tableName\n && metadata.discriminatorValue === entityMetadata.discriminatorValue\n && metadata.inheritanceTree.some(parent => entityMetadata.inheritanceTree.indexOf(parent) !== -1);\n });\n if (sameDiscriminatorValueEntityMetadata)\n throw new TypeORMError(`Entities ${entityMetadata.name} and ${sameDiscriminatorValueEntityMetadata.name} have the same discriminator values. Make sure they are different while using the @ChildEntity decorator.`);\n }\n\n entityMetadata.relationCounts.forEach(relationCount => {\n if (relationCount.relation.isManyToOne || relationCount.relation.isOneToOne)\n throw new TypeORMError(`Relation count can not be implemented on ManyToOne or OneToOne relations.`);\n });\n\n if (!(driver instanceof MongoDriver)) {\n entityMetadata.columns.forEach(column => {\n const normalizedColumn = driver.normalizeType(column) as ColumnType;\n if (driver.supportedDataTypes.indexOf(normalizedColumn) === -1)\n throw new DataTypeNotSupportedError(column, normalizedColumn, driver.options.type);\n if (column.length && driver.withLengthColumnTypes.indexOf(normalizedColumn) === -1)\n throw new TypeORMError(`Column ${column.propertyName} of Entity ${entityMetadata.name} does not support length property.`);\n if (column.type === \"enum\" && !column.enum && !column.enumName)\n throw new TypeORMError(`Column \"${column.propertyName}\" of Entity \"${entityMetadata.name}\" is defined as enum, but missing \"enum\" or \"enumName\" properties.`);\n });\n }\n\n if (driver instanceof MysqlDriver || driver instanceof AuroraDataApiDriver) {\n const generatedColumns = entityMetadata.columns.filter(column => column.isGenerated && column.generationStrategy !== \"uuid\");\n if (generatedColumns.length > 1)\n throw new TypeORMError(`Error in ${entityMetadata.name} entity. There can be only one auto-increment column in MySql table.`);\n }\n\n // for mysql we are able to not define a default selected database, instead all entities can have their database\n // defined in their decorators. To make everything work either all entities must have database define and we\n // can live without database set in the connection options, either database in the connection options must be set\n if (driver instanceof MysqlDriver) {\n const metadatasWithDatabase = allEntityMetadatas.filter(metadata => metadata.database);\n if (metadatasWithDatabase.length === 0 && !driver.database)\n throw new NoConnectionOptionError(\"database\");\n }\n\n if (driver instanceof SqlServerDriver) {\n const charsetColumns = entityMetadata.columns.filter(column => column.charset);\n if (charsetColumns.length > 1)\n throw new TypeORMError(`Character set specifying is not supported in Sql Server`);\n }\n\n // check if relations are all without initialized properties\n const entityInstance = entityMetadata.create();\n entityMetadata.relations.forEach(relation => {\n if (relation.isManyToMany || relation.isOneToMany) {\n\n // we skip relations for which persistence is disabled since initialization in them cannot harm somehow\n if (relation.persistenceEnabled === false)\n return;\n\n // get entity relation value and check if its an array\n const relationInitializedValue = relation.getEntityValue(entityInstance);\n if (Array.isArray(relationInitializedValue))\n throw new InitializedRelationError(relation);\n }\n });\n\n // validate relations\n entityMetadata.relations.forEach(relation => {\n\n // check join tables:\n // using JoinTable is possible only on one side of the many-to-many relation\n // todo(dima): fix\n // if (relation.joinTable) {\n // if (!relation.isManyToMany)\n // throw new UsingJoinTableIsNotAllowedError(entityMetadata, relation);\n\n // // if there is inverse side of the relation, then check if it does not have join table too\n // if (relation.hasInverseSide && relation.inverseRelation.joinTable)\n // throw new UsingJoinTableOnlyOnOneSideAllowedError(entityMetadata, relation);\n // }\n\n // check join columns:\n // using JoinColumn is possible only on one side of the relation and on one-to-one, many-to-one relation types\n // first check if relation is one-to-one or many-to-one\n // todo(dima): fix\n /*if (relation.joinColumn) {\n\n // join column can be applied only on one-to-one and many-to-one relations\n if (!relation.isOneToOne && !relation.isManyToOne)\n throw new UsingJoinColumnIsNotAllowedError(entityMetadata, relation);\n\n // if there is inverse side of the relation, then check if it does not have join table too\n if (relation.hasInverseSide && relation.inverseRelation.joinColumn && relation.isOneToOne)\n throw new UsingJoinColumnOnlyOnOneSideAllowedError(entityMetadata, relation);\n\n // check if join column really has referenced column\n if (relation.joinColumn && !relation.joinColumn.referencedColumn)\n throw new TypeORMError(`Join column does not have referenced column set`);\n\n }\n\n // if its a one-to-one relation and JoinColumn is missing on both sides of the relation\n // or its one-side relation without JoinColumn we should give an error\n if (!relation.joinColumn && relation.isOneToOne && (!relation.hasInverseSide || !relation.inverseRelation.joinColumn))\n throw new MissingJoinColumnError(entityMetadata, relation);*/\n\n // if its a many-to-many relation and JoinTable is missing on both sides of the relation\n // or its one-side relation without JoinTable we should give an error\n // todo(dima): fix it\n // if (!relation.joinTable && relation.isManyToMany && (!relation.hasInverseSide || !relation.inverseRelation.joinTable))\n // throw new MissingJoinTableError(entityMetadata, relation);\n\n\n // todo: validate if its one-to-one and side which does not have join column MUST have inverse side\n // todo: validate if its many-to-many and side which does not have join table MUST have inverse side\n // todo: if there is a relation, and inverse side is specified only on one side, shall we give error\n // todo: with message like: \"Inverse side is specified only on one side of the relationship. Specify on other side too to prevent confusion\".\n // todo: add validation if there two entities with the same target, and show error message with description of the problem (maybe file was renamed/moved but left in output directory)\n // todo: check if there are multiple columns on the same column applied.\n // todo: check column type if is missing in relational databases (throw new TypeORMError(`Column type of ${type} cannot be determined.`);)\n // todo: include driver-specific checks. for example in mongodb empty prefixes are not allowed\n // todo: if multiple columns with same name - throw exception, including cases when columns are in embeds with same prefixes or without prefix at all\n // todo: if multiple primary key used, at least one of them must be unique or @Index decorator must be set on entity\n // todo: check if entity with duplicate names, some decorators exist\n\n\n });\n\n // make sure cascade remove is not set for both sides of relationships (can be set in OneToOne decorators)\n entityMetadata.relations.forEach(relation => {\n const isCircularCascadeRemove = relation.isCascadeRemove && relation.inverseRelation && relation.inverseRelation!.isCascadeRemove;\n if (isCircularCascadeRemove)\n throw new TypeORMError(`Relation ${entityMetadata.name}#${relation.propertyName} and ${relation.inverseRelation!.entityMetadata.name}#${relation.inverseRelation!.propertyName} both has cascade remove set. ` +\n `This may lead to unexpected circular removals. Please set cascade remove only from one side of relationship.`);\n }); // todo: maybe better just deny removal from one to one relation without join column?\n\n entityMetadata.eagerRelations.forEach(relation => {\n\n });\n }\n\n /**\n * Validates dependencies of the entity metadatas.\n */\n protected validateDependencies(entityMetadatas: EntityMetadata[]) {\n\n const graph = new DepGraph();\n entityMetadatas.forEach(entityMetadata => {\n graph.addNode(entityMetadata.name);\n });\n entityMetadatas.forEach(entityMetadata => {\n entityMetadata.relationsWithJoinColumns\n .filter(relation => !relation.isNullable)\n .forEach(relation => {\n graph.addDependency(entityMetadata.name, relation.inverseEntityMetadata.name);\n });\n });\n try {\n graph.overallOrder();\n\n } catch (err) {\n throw new CircularRelationsError(err.toString().replace(\"Error: Dependency Cycle Found: \", \"\"));\n }\n }\n\n /**\n * Validates eager relations to prevent circular dependency in them.\n */\n protected validateEagerRelations(entityMetadatas: EntityMetadata[]) {\n entityMetadatas.forEach(entityMetadata => {\n entityMetadata.eagerRelations.forEach(relation => {\n if (relation.inverseRelation && relation.inverseRelation.isEager)\n throw new TypeORMError(`Circular eager relations are disallowed. ` +\n `${entityMetadata.targetName}#${relation.propertyPath} contains \"eager: true\", and its inverse side ` +\n `${relation.inverseEntityMetadata.targetName}#${relation.inverseRelation.propertyPath} contains \"eager: true\" as well.` +\n ` Remove \"eager: true\" from one side of the relation.`);\n });\n });\n }\n\n}\n"],"sourceRoot":".."}
|
|
@@ -159,6 +159,9 @@ var OneToManySubjectBuilder = /** @class */ (function () {
|
|
|
159
159
|
else if (relation.inverseRelation.orphanedRowAction === "delete") {
|
|
160
160
|
removedRelatedEntitySubject.mustBeRemoved = true;
|
|
161
161
|
}
|
|
162
|
+
else if (relation.inverseRelation.orphanedRowAction === "soft-delete") {
|
|
163
|
+
removedRelatedEntitySubject.canBeSoftRemoved = true;
|
|
164
|
+
}
|
|
162
165
|
_this.subjects.push(removedRelatedEntitySubject);
|
|
163
166
|
});
|
|
164
167
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/persistence/subject-builder/OneToManySubjectBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,YAAY,CAAC;AACnC,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAC,cAAc,EAAC,MAAM,+BAA+B,CAAC;AAG7D;;;;;;;;;;GAUG;AACH;IAEI,wEAAwE;IACxE,cAAc;IACd,wEAAwE;IAExE,iCAAsB,QAAmB;QAAnB,aAAQ,GAAR,QAAQ,CAAW;IACzC,CAAC;IAED,wEAAwE;IACxE,iBAAiB;IACjB,wEAAwE;IAExE;;OAEG;IACH,uCAAK,GAAL;QAAA,iBAWC;QAVG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAA,OAAO;YACzB,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,UAAA,QAAQ;gBAEhD,mDAAmD;gBACnD,IAAI,QAAQ,CAAC,kBAAkB,KAAK,KAAK;oBACrC,OAAO;gBAEX,KAAI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nimport {ObjectLiteral} from \"../../common/ObjectLiteral\";\nimport {EntityMetadata} from \"../../metadata/EntityMetadata\";\nimport {RelationMetadata} from \"../../metadata/RelationMetadata\";\n\n/**\n * Builds operations needs to be executed for one-to-many relations of the given subjects.\n *\n * by example: post contains one-to-many relation with category in the property called \"categories\", e.g.\n * @OneToMany(type => Category, category => category.post) categories: Category[]\n * If user adds categories into the post and saves post we need to bind them.\n * This operation requires updation of category table since its owner of the relation and contains a join column.\n *\n * note: this class shares lot of things with OneToOneInverseSideOperationBuilder, so when you change this class\n * make sure to reflect changes there as well.\n */\nexport class OneToManySubjectBuilder {\n\n // ---------------------------------------------------------------------\n // Constructor\n // ---------------------------------------------------------------------\n\n constructor(protected subjects: Subject[]) {\n }\n\n // ---------------------------------------------------------------------\n // Public Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds all required operations.\n */\n build(): void {\n this.subjects.forEach(subject => {\n subject.metadata.oneToManyRelations.forEach(relation => {\n\n // skip relations for which persistence is disabled\n if (relation.persistenceEnabled === false)\n return;\n\n this.buildForSubjectRelation(subject, relation);\n });\n });\n }\n\n // ---------------------------------------------------------------------\n // Protected Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds operations for a given subject and relation.\n *\n * by example: subject is \"post\" entity we are saving here and relation is \"categories\" inside it here.\n */\n protected buildForSubjectRelation(subject: Subject, relation: RelationMetadata) {\n // prepare objects (relation id maps) for the database entity\n // by example: since subject is a post, we are expecting to get all post's categories saved in the database here,\n // particularly their relation ids, e.g. category ids stored in the database\n\n\t\t// in most cases relatedEntityDatabaseValues will contain only the entity key properties.\n\t\t// this is because subject.databaseEntity contains relations with loaded relation ids only.\n\t\t// however if the entity uses the afterLoad hook to calculate any properties, the fetched \"key object\" might include ADDITIONAL properties.\n\t\t// to handle such situations, we pass the data to relation.inverseEntityMetadata.getEntityIdMap to extract the key without any other properties.\n\n let relatedEntityDatabaseRelationIds: ObjectLiteral[] = [];\n if (subject.databaseEntity) { // related entities in the database can exist only if this entity (post) is saved\n const relatedEntityDatabaseRelation: ObjectLiteral[] | undefined = relation.getEntityValue(subject.databaseEntity)\n if (relatedEntityDatabaseRelation) {\n relatedEntityDatabaseRelationIds = relatedEntityDatabaseRelation.map((entity) => relation.inverseEntityMetadata.getEntityIdMap(entity)!);\n }\n }\n\n // get related entities of persisted entity\n // by example: get categories from the passed to persist post entity\n let relatedEntities: ObjectLiteral[] = relation.getEntityValue(subject.entity!);\n if (relatedEntities === null) // we treat relations set to null as removed, so we don't skip it\n relatedEntities = [] as ObjectLiteral[];\n if (relatedEntities === undefined) // if relation is undefined then nothing to update\n return;\n\n // extract only relation ids from the related entities, since we only need them for comparison\n // by example: extract from categories only relation ids (category id, or let's say category title, depend on join column options)\n const relatedPersistedEntityRelationIds: ObjectLiteral[] = [];\n relatedEntities.forEach(relatedEntity => { // by example: relatedEntity is a category here\n let relationIdMap = relation.inverseEntityMetadata!.getEntityIdMap(relatedEntity); // by example: relationIdMap is category.id map here, e.g. { id: ... }\n\n // try to find a subject of this related entity, maybe it was loaded or was marked for persistence\n let relatedEntitySubject = this.subjects.find(subject => {\n return subject.entity === relatedEntity;\n });\n\n // if subject with entity was found take subject identifier as relation id map since it may contain extra properties resolved\n if (relatedEntitySubject)\n relationIdMap = relatedEntitySubject.identifier;\n\n // if relationIdMap is undefined then it means user binds object which is not saved in the database yet\n // by example: if post contains categories which does not have ids yet (because they are new)\n // it means they are always newly inserted and relation update operation always must be created for them\n // it does not make sense to perform difference operation for them for both add and remove actions\n if (!relationIdMap) {\n\n // we decided to remove this error because it brings complications when saving object with non-saved entities\n // if (!relatedEntitySubject)\n // throw new TypeORMError(`One-to-many relation \"${relation.entityMetadata.name}.${relation.propertyPath}\" contains ` +\n // `entities which do not exist in the database yet, thus they cannot be bind in the database. ` +\n // `Please setup cascade insertion or save entities before binding it.`);\n if (!relatedEntitySubject)\n return;\n\n // okay, so related subject exist and its marked for insertion, then add a new change map\n // by example: this will tell category to insert into its post relation our post we are working with\n // relatedEntitySubject is newly inserted CategorySubject\n // relation.inverseRelation is ManyToOne relation inside Category\n // subject is Post needs to be inserted into Category\n relatedEntitySubject.changeMaps.push({\n relation: relation.inverseRelation!,\n value: subject\n });\n\n return;\n }\n\n // check if this binding really exist in the database\n // by example: find our category if its already bind in the database\n const relationIdInDatabaseSubjectRelation = relatedEntityDatabaseRelationIds.find(relatedDatabaseEntityRelationId => {\n return OrmUtils.compareIds(relationIdMap, relatedDatabaseEntityRelationId);\n });\n\n // if relationIdMap DOES NOT exist in the subject's relation in the database it means its a new relation and we need to \"bind\" them\n // by example: this will tell category to insert into its post relation our post we are working with\n // relatedEntitySubject is newly inserted CategorySubject\n // relation.inverseRelation is ManyToOne relation inside Category\n // subject is Post needs to be inserted into Category\n if (!relationIdInDatabaseSubjectRelation) {\n\n // if there is no relatedEntitySubject then it means \"category\" wasn't persisted,\n // but since we are going to update \"category\" table (since its an owning side of relation with join column)\n // we create a new subject here:\n if (!relatedEntitySubject) {\n relatedEntitySubject = new Subject({\n metadata: relation.inverseEntityMetadata,\n parentSubject: subject,\n canBeUpdated: true,\n identifier: relationIdMap\n });\n this.subjects.push(relatedEntitySubject);\n }\n\n relatedEntitySubject.changeMaps.push({\n relation: relation.inverseRelation!,\n value: subject\n });\n }\n\n // if related entity has relation id then we add it to the list of relation ids\n // this list will be used later to compare with database relation ids to find a difference\n // what exist in this array and does not exist in the database are newly inserted relations\n // what does not exist in this array, but exist in the database are removed relations\n // removed relations are set to null from inverse side of relation\n relatedPersistedEntityRelationIds.push(relationIdMap);\n });\n\n // find what related entities were added and what were removed based on difference between what we save and what database has\n EntityMetadata\n .difference(relatedEntityDatabaseRelationIds, relatedPersistedEntityRelationIds)\n .forEach(removedRelatedEntityRelationId => { // by example: removedRelatedEntityRelationId is category that was bind in the database before, but now its unbind\n\n // todo: probably we can improve this in the future by finding entity with column those values,\n // todo: maybe it was already in persistence process. This is possible due to unique requirements of join columns\n // we create a new subject which operations will be executed in subject operation executor\n const removedRelatedEntitySubject = new Subject({\n metadata: relation.inverseEntityMetadata,\n parentSubject: subject,\n identifier: removedRelatedEntityRelationId,\n });\n\n if (!relation.inverseRelation || relation.inverseRelation.orphanedRowAction === \"nullify\") {\n removedRelatedEntitySubject.canBeUpdated = true;\n removedRelatedEntitySubject.changeMaps = [{\n relation: relation.inverseRelation!,\n value: null\n }];\n } else if (relation.inverseRelation.orphanedRowAction === \"delete\") {\n removedRelatedEntitySubject.mustBeRemoved = true;\n }\n\n this.subjects.push(removedRelatedEntitySubject);\n });\n }\n\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/persistence/subject-builder/OneToManySubjectBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,YAAY,CAAC;AACnC,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAC,cAAc,EAAC,MAAM,+BAA+B,CAAC;AAG7D;;;;;;;;;;GAUG;AACH;IAEI,wEAAwE;IACxE,cAAc;IACd,wEAAwE;IAExE,iCAAsB,QAAmB;QAAnB,aAAQ,GAAR,QAAQ,CAAW;IACzC,CAAC;IAED,wEAAwE;IACxE,iBAAiB;IACjB,wEAAwE;IAExE;;OAEG;IACH,uCAAK,GAAL;QAAA,iBAWC;QAVG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAA,OAAO;YACzB,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,UAAA,QAAQ;gBAEhD,mDAAmD;gBACnD,IAAI,QAAQ,CAAC,kBAAkB,KAAK,KAAK;oBACrC,OAAO;gBAEX,KAAI,CAAC,uBAAuB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YACpD,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAED,wEAAwE;IACxE,oBAAoB;IACpB,wEAAwE;IAExE;;;;OAIG;IACO,yDAAuB,GAAjC,UAAkC,OAAgB,EAAE,QAA0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AqF;YACrF,kEAAkE;YAClE,iCAAiC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;QAEH,6HAA6H;QAC7H,cAAc;aACT,UAAU,CAAC,gCAAgC,EAAE,iCAAiC,CAAC;aAC/E,OAAO,CAAC,UAAA,8BAA8B;YAEnC,+FAA+F;YAC/F,iHAAiH;YACjH,0FAA0F;YAC1F,IAAM,2BAA2B,GAAG,IAAI,OAAO,CAAC;gBAC5C,QAAQ,EAAE,QAAQ,CAAC,qBAAqB;gBACxC,aAAa,EAAE,OAAO;gBACtB,UAAU,EAAE,8BAA8B;aAC7C,CAAC,CAAC;YAEH,IAAI,CAAC,QAAQ,CAAC,eAAe,IAAI,QAAQ,CAAC,eAAe,CAAC,iBAAiB,KAAK,SAAS,EAAE;gBACvF,2BAA2B,CAAC,YAAY,GAAG,IAAI,CAAC;gBAChD,2BAA2B,CAAC,UAAU,GAAG,CAAC;wBACtC,QAAQ,EAAE,QAAQ,CAAC,eAAgB;wBACnC,KAAK,EAAE,IAAI;qBACd,CAAC,CAAC;aACN;iBAAM,IAAI,QAAQ,CAAC,eAAe,CAAC,iBAAiB,KAAK,QAAQ,EAAE;gBAChE,2BAA2B,CAAC,aAAa,GAAG,IAAI,CAAC;aACpD;iBACI,IAAI,QAAQ,CAAC,eAAe,CAAC,iBAAiB,KAAK,aAAa,EAAE;gBACnE,2BAA2B,CAAC,gBAAgB,GAAG,IAAI,CAAC;aACvD;YAED,KAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACX,CAAC;IAEL,8BAAC;AAAD,CAjLA,AAiLC,IAAA","file":"OneToManySubjectBuilder.js","sourcesContent":["import {Subject} from \"../Subject\";\nimport {OrmUtils} from \"../../util/OrmUtils\";\nimport {ObjectLiteral} from \"../../common/ObjectLiteral\";\nimport {EntityMetadata} from \"../../metadata/EntityMetadata\";\nimport {RelationMetadata} from \"../../metadata/RelationMetadata\";\n\n/**\n * Builds operations needs to be executed for one-to-many relations of the given subjects.\n *\n * by example: post contains one-to-many relation with category in the property called \"categories\", e.g.\n * @OneToMany(type => Category, category => category.post) categories: Category[]\n * If user adds categories into the post and saves post we need to bind them.\n * This operation requires updation of category table since its owner of the relation and contains a join column.\n *\n * note: this class shares lot of things with OneToOneInverseSideOperationBuilder, so when you change this class\n * make sure to reflect changes there as well.\n */\nexport class OneToManySubjectBuilder {\n\n // ---------------------------------------------------------------------\n // Constructor\n // ---------------------------------------------------------------------\n\n constructor(protected subjects: Subject[]) {\n }\n\n // ---------------------------------------------------------------------\n // Public Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds all required operations.\n */\n build(): void {\n this.subjects.forEach(subject => {\n subject.metadata.oneToManyRelations.forEach(relation => {\n\n // skip relations for which persistence is disabled\n if (relation.persistenceEnabled === false)\n return;\n\n this.buildForSubjectRelation(subject, relation);\n });\n });\n }\n\n // ---------------------------------------------------------------------\n // Protected Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds operations for a given subject and relation.\n *\n * by example: subject is \"post\" entity we are saving here and relation is \"categories\" inside it here.\n */\n protected buildForSubjectRelation(subject: Subject, relation: RelationMetadata) {\n // prepare objects (relation id maps) for the database entity\n // by example: since subject is a post, we are expecting to get all post's categories saved in the database here,\n // particularly their relation ids, e.g. category ids stored in the database\n\n\t\t// in most cases relatedEntityDatabaseValues will contain only the entity key properties.\n\t\t// this is because subject.databaseEntity contains relations with loaded relation ids only.\n\t\t// however if the entity uses the afterLoad hook to calculate any properties, the fetched \"key object\" might include ADDITIONAL properties.\n\t\t// to handle such situations, we pass the data to relation.inverseEntityMetadata.getEntityIdMap to extract the key without any other properties.\n\n let relatedEntityDatabaseRelationIds: ObjectLiteral[] = [];\n if (subject.databaseEntity) { // related entities in the database can exist only if this entity (post) is saved\n const relatedEntityDatabaseRelation: ObjectLiteral[] | undefined = relation.getEntityValue(subject.databaseEntity)\n if (relatedEntityDatabaseRelation) {\n relatedEntityDatabaseRelationIds = relatedEntityDatabaseRelation.map((entity) => relation.inverseEntityMetadata.getEntityIdMap(entity)!);\n }\n }\n\n // get related entities of persisted entity\n // by example: get categories from the passed to persist post entity\n let relatedEntities: ObjectLiteral[] = relation.getEntityValue(subject.entity!);\n if (relatedEntities === null) // we treat relations set to null as removed, so we don't skip it\n relatedEntities = [] as ObjectLiteral[];\n if (relatedEntities === undefined) // if relation is undefined then nothing to update\n return;\n\n // extract only relation ids from the related entities, since we only need them for comparison\n // by example: extract from categories only relation ids (category id, or let's say category title, depend on join column options)\n const relatedPersistedEntityRelationIds: ObjectLiteral[] = [];\n relatedEntities.forEach(relatedEntity => { // by example: relatedEntity is a category here\n let relationIdMap = relation.inverseEntityMetadata!.getEntityIdMap(relatedEntity); // by example: relationIdMap is category.id map here, e.g. { id: ... }\n\n // try to find a subject of this related entity, maybe it was loaded or was marked for persistence\n let relatedEntitySubject = this.subjects.find(subject => {\n return subject.entity === relatedEntity;\n });\n\n // if subject with entity was found take subject identifier as relation id map since it may contain extra properties resolved\n if (relatedEntitySubject)\n relationIdMap = relatedEntitySubject.identifier;\n\n // if relationIdMap is undefined then it means user binds object which is not saved in the database yet\n // by example: if post contains categories which does not have ids yet (because they are new)\n // it means they are always newly inserted and relation update operation always must be created for them\n // it does not make sense to perform difference operation for them for both add and remove actions\n if (!relationIdMap) {\n\n // we decided to remove this error because it brings complications when saving object with non-saved entities\n // if (!relatedEntitySubject)\n // throw new TypeORMError(`One-to-many relation \"${relation.entityMetadata.name}.${relation.propertyPath}\" contains ` +\n // `entities which do not exist in the database yet, thus they cannot be bind in the database. ` +\n // `Please setup cascade insertion or save entities before binding it.`);\n if (!relatedEntitySubject)\n return;\n\n // okay, so related subject exist and its marked for insertion, then add a new change map\n // by example: this will tell category to insert into its post relation our post we are working with\n // relatedEntitySubject is newly inserted CategorySubject\n // relation.inverseRelation is ManyToOne relation inside Category\n // subject is Post needs to be inserted into Category\n relatedEntitySubject.changeMaps.push({\n relation: relation.inverseRelation!,\n value: subject\n });\n\n return;\n }\n\n // check if this binding really exist in the database\n // by example: find our category if its already bind in the database\n const relationIdInDatabaseSubjectRelation = relatedEntityDatabaseRelationIds.find(relatedDatabaseEntityRelationId => {\n return OrmUtils.compareIds(relationIdMap, relatedDatabaseEntityRelationId);\n });\n\n // if relationIdMap DOES NOT exist in the subject's relation in the database it means its a new relation and we need to \"bind\" them\n // by example: this will tell category to insert into its post relation our post we are working with\n // relatedEntitySubject is newly inserted CategorySubject\n // relation.inverseRelation is ManyToOne relation inside Category\n // subject is Post needs to be inserted into Category\n if (!relationIdInDatabaseSubjectRelation) {\n\n // if there is no relatedEntitySubject then it means \"category\" wasn't persisted,\n // but since we are going to update \"category\" table (since its an owning side of relation with join column)\n // we create a new subject here:\n if (!relatedEntitySubject) {\n relatedEntitySubject = new Subject({\n metadata: relation.inverseEntityMetadata,\n parentSubject: subject,\n canBeUpdated: true,\n identifier: relationIdMap\n });\n this.subjects.push(relatedEntitySubject);\n }\n\n relatedEntitySubject.changeMaps.push({\n relation: relation.inverseRelation!,\n value: subject\n });\n }\n\n // if related entity has relation id then we add it to the list of relation ids\n // this list will be used later to compare with database relation ids to find a difference\n // what exist in this array and does not exist in the database are newly inserted relations\n // what does not exist in this array, but exist in the database are removed relations\n // removed relations are set to null from inverse side of relation\n relatedPersistedEntityRelationIds.push(relationIdMap);\n });\n\n // find what related entities were added and what were removed based on difference between what we save and what database has\n EntityMetadata\n .difference(relatedEntityDatabaseRelationIds, relatedPersistedEntityRelationIds)\n .forEach(removedRelatedEntityRelationId => { // by example: removedRelatedEntityRelationId is category that was bind in the database before, but now its unbind\n\n // todo: probably we can improve this in the future by finding entity with column those values,\n // todo: maybe it was already in persistence process. This is possible due to unique requirements of join columns\n // we create a new subject which operations will be executed in subject operation executor\n const removedRelatedEntitySubject = new Subject({\n metadata: relation.inverseEntityMetadata,\n parentSubject: subject,\n identifier: removedRelatedEntityRelationId,\n });\n\n if (!relation.inverseRelation || relation.inverseRelation.orphanedRowAction === \"nullify\") {\n removedRelatedEntitySubject.canBeUpdated = true;\n removedRelatedEntitySubject.changeMaps = [{\n relation: relation.inverseRelation!,\n value: null\n }];\n } else if (relation.inverseRelation.orphanedRowAction === \"delete\") {\n removedRelatedEntitySubject.mustBeRemoved = true;\n }\n else if (relation.inverseRelation.orphanedRowAction === \"soft-delete\") {\n removedRelatedEntitySubject.canBeSoftRemoved = true;\n }\n \n this.subjects.push(removedRelatedEntitySubject);\n });\n }\n\n}\n"],"sourceRoot":"../.."}
|
|
@@ -62,5 +62,5 @@ export interface RelationOptions {
|
|
|
62
62
|
/**
|
|
63
63
|
* When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.
|
|
64
64
|
*/
|
|
65
|
-
orphanedRowAction?: "nullify" | "delete";
|
|
65
|
+
orphanedRowAction?: "nullify" | "delete" | "soft-delete";
|
|
66
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/decorator/options/RelationOptions.ts"],"names":[],"mappings":"","file":"RelationOptions.js","sourcesContent":["import {DeferrableType} from \"../../metadata/types/DeferrableType\";\nimport {OnDeleteType} from \"../../metadata/types/OnDeleteType\";\nimport {OnUpdateType} from \"../../metadata/types/OnUpdateType\";\n\n/**\n * Describes all relation's options.\n */\nexport interface RelationOptions {\n\n /**\n * Sets cascades options for the given relation.\n * If set to true then it means that related object can be allowed to be inserted or updated in the database.\n * You can separately restrict cascades to insertion or updation using following syntax:\n *\n * cascade: [\"insert\", \"update\", \"remove\", \"soft-remove\", \"recover\"] // include or exclude one of them\n */\n cascade?: boolean|(\"insert\"|\"update\"|\"remove\"|\"soft-remove\"|\"recover\")[];\n\n /**\n * Indicates if relation column value can be nullable or not.\n */\n nullable?: boolean;\n\n /**\n * Database cascade action on delete.\n */\n onDelete?: OnDeleteType;\n\n /**\n * Database cascade action on update.\n */\n onUpdate?: OnUpdateType;\n\n /**\n * Indicate if foreign key constraints can be deferred.\n */\n deferrable?: DeferrableType;\n\n /**\n * Indicates if this relation will be a primary key.\n * Can be used only for many-to-one and owner one-to-one relations.\n */\n primary?: boolean;\n\n /**\n * Indicates whether foreign key constraints will be created for join columns.\n * Can be used only for many-to-one and owner one-to-one relations.\n * Defaults to true.\n */\n createForeignKeyConstraints?: boolean;\n\n /**\n * Set this relation to be lazy. Note: lazy relations are promises. When you call them they return promise\n * which resolve relation result then. If your property's type is Promise then this relation is set to lazy automatically.\n */\n lazy?: boolean;\n\n /**\n * Set this relation to be eager.\n * Eager relations are always loaded automatically when relation's owner entity is loaded using find* methods.\n * Only using QueryBuilder prevents loading eager relations.\n * Eager flag cannot be set from both sides of relation - you can eager load only one side of the relationship.\n */\n eager?: boolean;\n\n /**\n * Indicates if persistence is enabled for the relation.\n * 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.\n * If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.\n * This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.\n */\n persistence?: boolean;\n\n /**\n * When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.\n */\n orphanedRowAction?: \"nullify\" | \"delete\";\n\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../../src/decorator/options/RelationOptions.ts"],"names":[],"mappings":"","file":"RelationOptions.js","sourcesContent":["import {DeferrableType} from \"../../metadata/types/DeferrableType\";\nimport {OnDeleteType} from \"../../metadata/types/OnDeleteType\";\nimport {OnUpdateType} from \"../../metadata/types/OnUpdateType\";\n\n/**\n * Describes all relation's options.\n */\nexport interface RelationOptions {\n\n /**\n * Sets cascades options for the given relation.\n * If set to true then it means that related object can be allowed to be inserted or updated in the database.\n * You can separately restrict cascades to insertion or updation using following syntax:\n *\n * cascade: [\"insert\", \"update\", \"remove\", \"soft-remove\", \"recover\"] // include or exclude one of them\n */\n cascade?: boolean|(\"insert\"|\"update\"|\"remove\"|\"soft-remove\"|\"recover\")[];\n\n /**\n * Indicates if relation column value can be nullable or not.\n */\n nullable?: boolean;\n\n /**\n * Database cascade action on delete.\n */\n onDelete?: OnDeleteType;\n\n /**\n * Database cascade action on update.\n */\n onUpdate?: OnUpdateType;\n\n /**\n * Indicate if foreign key constraints can be deferred.\n */\n deferrable?: DeferrableType;\n\n /**\n * Indicates if this relation will be a primary key.\n * Can be used only for many-to-one and owner one-to-one relations.\n */\n primary?: boolean;\n\n /**\n * Indicates whether foreign key constraints will be created for join columns.\n * Can be used only for many-to-one and owner one-to-one relations.\n * Defaults to true.\n */\n createForeignKeyConstraints?: boolean;\n\n /**\n * Set this relation to be lazy. Note: lazy relations are promises. When you call them they return promise\n * which resolve relation result then. If your property's type is Promise then this relation is set to lazy automatically.\n */\n lazy?: boolean;\n\n /**\n * Set this relation to be eager.\n * Eager relations are always loaded automatically when relation's owner entity is loaded using find* methods.\n * Only using QueryBuilder prevents loading eager relations.\n * Eager flag cannot be set from both sides of relation - you can eager load only one side of the relationship.\n */\n eager?: boolean;\n\n /**\n * Indicates if persistence is enabled for the relation.\n * 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.\n * If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.\n * This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.\n */\n persistence?: boolean;\n\n /**\n * When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.\n */\n orphanedRowAction?: \"nullify\" | \"delete\" | \"soft-delete\";\n\n}\n"],"sourceRoot":"../.."}
|
|
@@ -82,5 +82,5 @@ export interface EntitySchemaRelationOptions {
|
|
|
82
82
|
/**
|
|
83
83
|
* When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.
|
|
84
84
|
*/
|
|
85
|
-
orphanedRowAction?: "nullify" | "delete";
|
|
85
|
+
orphanedRowAction?: "nullify" | "delete" | "soft-delete";
|
|
86
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/entity-schema/EntitySchemaRelationOptions.ts"],"names":[],"mappings":"","file":"EntitySchemaRelationOptions.js","sourcesContent":["import {JoinColumnOptions} from \"../decorator/options/JoinColumnOptions\";\nimport {RelationType} from \"../metadata/types/RelationTypes\";\nimport {JoinTableMultipleColumnsOptions} from \"../decorator/options/JoinTableMultipleColumnsOptions\";\nimport {DeferrableType} from \"../metadata/types/DeferrableType\";\nimport {OnDeleteType} from \"../metadata/types/OnDeleteType\";\nimport {OnUpdateType} from \"../metadata/types/OnUpdateType\";\nimport { JoinTableOptions } from \"../decorator/options/JoinTableOptions\";\n\n\nexport interface EntitySchemaRelationOptions {\n\n /**\n * Indicates with which entity this relation is made.\n */\n target: Function|string;\n\n /**\n * Type of relation. Can be one of the value of the RelationTypes class.\n */\n type: RelationType;\n\n /**\n * Inverse side of the relation.\n */\n inverseSide?: string;\n\n /**\n * Indicates if this relation will be lazily loaded.\n */\n lazy?: boolean;\n\n /**\n * Indicates if this relation will be eagerly loaded.\n */\n eager?: boolean;\n\n /**\n * Indicates if persistence is enabled for the relation.\n * 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.\n * If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.\n * This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.\n */\n persistence?: boolean;\n\n /**\n * Indicates if this relation will be a primary key.\n * Can be used only for many-to-one and owner one-to-one relations.\n */\n primary?: boolean;\n\n /**\n * Join table options of this column. If set to true then it simply means that it has a join table.\n */\n joinTable?: boolean|JoinTableOptions|JoinTableMultipleColumnsOptions;\n\n /**\n * Join column options of this column. If set to true then it simply means that it has a join column.\n */\n joinColumn?: boolean|JoinColumnOptions|JoinColumnOptions[];\n\n /**\n * Indicates if this is a parent (can be only many-to-one relation) relation in the tree tables.\n */\n treeParent?: boolean;\n\n /**\n * Indicates if this is a children (can be only one-to-many relation) relation in the tree tables.\n */\n treeChildren?: boolean;\n\n /**\n * If set to true then it means that related object can be allowed to be inserted / updated / removed to the db.\n * This is option a shortcut if you would like to set cascadeInsert, cascadeUpdate and cascadeRemove to true.\n */\n cascade?: boolean|(\"insert\"|\"update\"|\"remove\"|\"soft-remove\"|\"recover\")[];\n\n /**\n * Default database value.\n */\n default?: any;\n\n /**\n * Indicates if relation column value can be nullable or not.\n */\n nullable?: boolean;\n\n /**\n * Database cascade action on delete.\n */\n onDelete?: OnDeleteType;\n\n /**\n * Database cascade action on update.\n */\n onUpdate?: OnUpdateType;\n\n /**\n * Indicate if foreign key constraints can be deferred.\n */\n deferrable?: DeferrableType;\n\n /**\n * When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.\n */\n orphanedRowAction?: \"nullify\" | \"delete\";\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../../src/entity-schema/EntitySchemaRelationOptions.ts"],"names":[],"mappings":"","file":"EntitySchemaRelationOptions.js","sourcesContent":["import {JoinColumnOptions} from \"../decorator/options/JoinColumnOptions\";\nimport {RelationType} from \"../metadata/types/RelationTypes\";\nimport {JoinTableMultipleColumnsOptions} from \"../decorator/options/JoinTableMultipleColumnsOptions\";\nimport {DeferrableType} from \"../metadata/types/DeferrableType\";\nimport {OnDeleteType} from \"../metadata/types/OnDeleteType\";\nimport {OnUpdateType} from \"../metadata/types/OnUpdateType\";\nimport { JoinTableOptions } from \"../decorator/options/JoinTableOptions\";\n\n\nexport interface EntitySchemaRelationOptions {\n\n /**\n * Indicates with which entity this relation is made.\n */\n target: Function|string;\n\n /**\n * Type of relation. Can be one of the value of the RelationTypes class.\n */\n type: RelationType;\n\n /**\n * Inverse side of the relation.\n */\n inverseSide?: string;\n\n /**\n * Indicates if this relation will be lazily loaded.\n */\n lazy?: boolean;\n\n /**\n * Indicates if this relation will be eagerly loaded.\n */\n eager?: boolean;\n\n /**\n * Indicates if persistence is enabled for the relation.\n * 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.\n * If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.\n * This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.\n */\n persistence?: boolean;\n\n /**\n * Indicates if this relation will be a primary key.\n * Can be used only for many-to-one and owner one-to-one relations.\n */\n primary?: boolean;\n\n /**\n * Join table options of this column. If set to true then it simply means that it has a join table.\n */\n joinTable?: boolean|JoinTableOptions|JoinTableMultipleColumnsOptions;\n\n /**\n * Join column options of this column. If set to true then it simply means that it has a join column.\n */\n joinColumn?: boolean|JoinColumnOptions|JoinColumnOptions[];\n\n /**\n * Indicates if this is a parent (can be only many-to-one relation) relation in the tree tables.\n */\n treeParent?: boolean;\n\n /**\n * Indicates if this is a children (can be only one-to-many relation) relation in the tree tables.\n */\n treeChildren?: boolean;\n\n /**\n * If set to true then it means that related object can be allowed to be inserted / updated / removed to the db.\n * This is option a shortcut if you would like to set cascadeInsert, cascadeUpdate and cascadeRemove to true.\n */\n cascade?: boolean|(\"insert\"|\"update\"|\"remove\"|\"soft-remove\"|\"recover\")[];\n\n /**\n * Default database value.\n */\n default?: any;\n\n /**\n * Indicates if relation column value can be nullable or not.\n */\n nullable?: boolean;\n\n /**\n * Database cascade action on delete.\n */\n onDelete?: OnDeleteType;\n\n /**\n * Database cascade action on update.\n */\n onUpdate?: OnUpdateType;\n\n /**\n * Indicate if foreign key constraints can be deferred.\n */\n deferrable?: DeferrableType;\n\n /**\n * When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.\n */\n orphanedRowAction?: \"nullify\" | \"delete\" | \"soft-delete\";\n}\n"],"sourceRoot":".."}
|
|
@@ -92,7 +92,7 @@ export declare class RelationMetadata {
|
|
|
92
92
|
/**
|
|
93
93
|
* When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.
|
|
94
94
|
*/
|
|
95
|
-
orphanedRowAction?: "nullify" | "delete";
|
|
95
|
+
orphanedRowAction?: "nullify" | "delete" | "soft-delete";
|
|
96
96
|
/**
|
|
97
97
|
* If set to true then related objects are allowed to be inserted to the database.
|
|
98
98
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/metadata/RelationMetadata.ts"],"names":[],"mappings":";;;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AEnD;aAAM,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,cAAc,CAAC,oBAAoB,EAAE;YACtE,OAAO,IAAI,CAAC,cAAc,CAAC,oBAAoB,CAAC,YAAY,CAAC;SAEhE;aAAM,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,cAAc,CAAC,kBAAkB,EAAE;YACtE,OAAO,IAAI,CAAC,cAAc,CAAC,kBAAkB,CAAC,YAAY,CAAC;SAC9D;QAED,OAAO,EAAE,CAAC;IACd,CAAC;IAED;;OAEG;IACH,4CAAiB,GAAjB;QACI,IAAI,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,MAAM;YAC3E,OAAO,IAAI,CAAC,YAAY,CAAC;QAE7B,OAAO,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC;IACzF,CAAC;IAEL,uBAAC;AAAD,CA1iBA,AA0iBC,IAAA;AA1iBY,4CAAgB","file":"RelationMetadata.js","sourcesContent":["import {RelationType} from \"./types/RelationTypes\";\nimport {EntityMetadata} from \"./EntityMetadata\";\nimport {ForeignKeyMetadata} from \"./ForeignKeyMetadata\";\nimport {ObjectLiteral} from \"../common/ObjectLiteral\";\nimport {ColumnMetadata} from \"./ColumnMetadata\";\nimport {EmbeddedMetadata} from \"./EmbeddedMetadata\";\nimport {RelationMetadataArgs} from \"../metadata-args/RelationMetadataArgs\";\nimport {DeferrableType} from \"./types/DeferrableType\";\nimport {OnUpdateType} from \"./types/OnUpdateType\";\nimport {OnDeleteType} from \"./types/OnDeleteType\";\nimport {PropertyTypeFactory} from \"./types/PropertyTypeInFunction\";\nimport { TypeORMError } from \"../error\";\n\n/**\n * Contains all information about some entity's relation.\n */\nexport class RelationMetadata {\n\n // ---------------------------------------------------------------------\n // Public Properties\n // ---------------------------------------------------------------------\n\n /**\n * Entity metadata of the entity where this relation is placed.\n *\n * For example for @ManyToMany(type => Category) in Post, entityMetadata will be metadata of Post entity.\n */\n entityMetadata: EntityMetadata;\n\n /**\n * Entity metadata of the entity that is targeted by this relation.\n *\n * For example for @ManyToMany(type => Category) in Post, inverseEntityMetadata will be metadata of Category entity.\n */\n inverseEntityMetadata: EntityMetadata;\n\n /**\n * Entity metadata of the junction table.\n * Junction tables have their own entity metadata objects.\n * Defined only for many-to-many relations.\n */\n junctionEntityMetadata?: EntityMetadata;\n\n /**\n * Embedded metadata where this relation is.\n * If this relation is not in embed then this property value is undefined.\n */\n embeddedMetadata?: EmbeddedMetadata;\n\n /**\n * Relation type, e.g. is it one-to-one, one-to-many, many-to-one or many-to-many.\n */\n relationType: RelationType;\n\n /**\n * Target entity to which this relation is applied.\n * Target IS NOT equal to entityMetadata.target, because relation\n *\n * For example for @ManyToMany(type => Category) in Post, target will be Post.\n * If @ManyToMany(type => Category) is in Counters which is embedded into Post, target will be Counters.\n * If @ManyToMany(type => Category) is in abstract class BaseUser which Post extends, target will be BaseUser.\n * Target can be string if its defined in entity schema instead of class.\n */\n target: Function|string;\n\n /**\n * Target's property name to which relation decorator is applied.\n */\n propertyName: string;\n\n /**\n * Gets full path to this column property (including relation name).\n * Full path is relevant when column is used in embeds (one or multiple nested).\n * For example it will return \"counters.subcounters.likes\".\n * If property is not in embeds then it returns just property name of the column.\n */\n propertyPath: string;\n\n /**\n * Indicates if this is a parent (can be only many-to-one relation) relation in the tree tables.\n */\n isTreeParent: boolean = false;\n\n /**\n * Indicates if this is a children (can be only one-to-many relation) relation in the tree tables.\n */\n isTreeChildren: boolean = false;\n\n /**\n * Indicates if this relation's column is a primary key.\n * Can be used only for many-to-one and owner one-to-one relations.\n */\n isPrimary: boolean = false;\n\n /**\n * Indicates if this relation is lazily loaded.\n */\n isLazy: boolean = false;\n\n /**\n * Indicates if this relation is eagerly loaded.\n */\n isEager: boolean = false;\n\n /**\n * Indicates if persistence is enabled for the relation.\n * 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.\n * If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.\n * This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.\n */\n persistenceEnabled: boolean = true;\n\n /**\n * When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.\n */\n orphanedRowAction?: \"nullify\" | \"delete\";\n\n /**\n * If set to true then related objects are allowed to be inserted to the database.\n */\n isCascadeInsert: boolean = false;\n\n /**\n * If set to true then related objects are allowed to be updated in the database.\n */\n isCascadeUpdate: boolean = false;\n\n /**\n * If set to true then related objects are allowed to be remove from the database.\n */\n isCascadeRemove: boolean = false;\n\n /**\n * If set to true then related objects are allowed to be soft-removed from the database.\n */\n isCascadeSoftRemove: boolean = false;\n\n /**\n * If set to true then related objects are allowed to be recovered from the database.\n */\n isCascadeRecover: boolean = false;\n\n /**\n * Indicates if relation column value can be nullable or not.\n */\n isNullable: boolean = true;\n\n /**\n * What to do with a relation on deletion of the row containing a foreign key.\n */\n onDelete?: OnDeleteType;\n\n /**\n * What to do with a relation on update of the row containing a foreign key.\n */\n onUpdate?: OnUpdateType;\n\n /**\n * What to do with a relation on update of the row containing a foreign key.\n */\n deferrable?: DeferrableType;\n\n /**\n * Indicates whether foreign key constraints will be created for join columns.\n * Can be used only for many-to-one and owner one-to-one relations.\n * Defaults to true.\n */\n createForeignKeyConstraints: boolean = true;\n\n /**\n * Gets the property's type to which this relation is applied.\n *\n * For example for @ManyToMany(type => Category) in Post, target will be Category.\n */\n type: Function|string;\n\n /**\n * Indicates if this side is an owner of this relation.\n */\n isOwning: boolean = false;\n\n /**\n * Checks if this relation's type is \"one-to-one\".\n */\n isOneToOne: boolean = false;\n\n /**\n * Checks if this relation is owner side of the \"one-to-one\" relation.\n * Owner side means this side of relation has a join column in the table.\n */\n isOneToOneOwner: boolean = false;\n\n /**\n * Checks if this relation has a join column (e.g. is it many-to-one or one-to-one owner side).\n */\n isWithJoinColumn: boolean = false;\n\n /**\n * Checks if this relation is NOT owner side of the \"one-to-one\" relation.\n * NOT owner side means this side of relation does not have a join column in the table.\n */\n isOneToOneNotOwner: boolean = false;\n\n /**\n * Checks if this relation's type is \"one-to-many\".\n */\n isOneToMany: boolean = false;\n\n /**\n * Checks if this relation's type is \"many-to-one\".\n */\n isManyToOne: boolean = false;\n\n /**\n * Checks if this relation's type is \"many-to-many\".\n */\n isManyToMany: boolean = false;\n\n /**\n * Checks if this relation's type is \"many-to-many\", and is owner side of the relationship.\n * Owner side means this side of relation has a join table.\n */\n isManyToManyOwner: boolean = false;\n\n /**\n * Checks if this relation's type is \"many-to-many\", and is NOT owner side of the relationship.\n * Not owner side means this side of relation does not have a join table.\n */\n isManyToManyNotOwner: boolean = false;\n\n /**\n * Gets the property path of the inverse side of the relation.\n */\n inverseSidePropertyPath: string;\n\n /**\n * Inverse side of the relation set by user.\n *\n * Inverse side set in the relation can be either string - property name of the column on inverse side,\n * either can be a function that accepts a map of properties with the object and returns one of them.\n * Second approach is used to achieve type-safety.\n */\n givenInverseSidePropertyFactory: PropertyTypeFactory<any>;\n\n /**\n * Gets the relation metadata of the inverse side of this relation.\n */\n inverseRelation?: RelationMetadata;\n\n /**\n * Join table name.\n */\n joinTableName: string;\n\n /**\n * Foreign keys created for this relation.\n */\n foreignKeys: ForeignKeyMetadata[] = [];\n\n /**\n * Join table columns.\n * Join columns can be obtained only from owner side of the relation.\n * From non-owner side of the relation join columns will be empty.\n * If this relation is a many-to-one/one-to-one then it takes join columns from the current entity.\n * If this relation is many-to-many then it takes all owner join columns from the junction entity.\n */\n joinColumns: ColumnMetadata[] = [];\n\n /**\n * Inverse join table columns.\n * Inverse join columns are supported only for many-to-many relations\n * and can be obtained only from owner side of the relation.\n * From non-owner side of the relation join columns will be undefined.\n */\n inverseJoinColumns: ColumnMetadata[] = [];\n\n // ---------------------------------------------------------------------\n // Constructor\n // ---------------------------------------------------------------------\n\n constructor(options: {\n entityMetadata: EntityMetadata,\n embeddedMetadata?: EmbeddedMetadata,\n args: RelationMetadataArgs\n }) {\n this.entityMetadata = options.entityMetadata;\n this.embeddedMetadata = options.embeddedMetadata!;\n const args = options.args;\n this.target = args.target;\n this.propertyName = args.propertyName;\n this.relationType = args.relationType;\n\n if (args.inverseSideProperty)\n this.givenInverseSidePropertyFactory = args.inverseSideProperty;\n\n this.isLazy = args.isLazy || false;\n // this.isCascadeInsert = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"insert\") !== -1);\n // this.isCascadeUpdate = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"update\") !== -1);\n // this.isCascadeRemove = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"remove\") !== -1);\n // this.isCascadeSoftRemove = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"soft-remove\") !== -1);\n // this.isCascadeRecover = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"recover\") !== -1);\n this.isCascadeInsert = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"insert\") !== -1);\n this.isCascadeUpdate = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"update\") !== -1);\n this.isCascadeRemove = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"remove\") !== -1);\n this.isCascadeSoftRemove = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"soft-remove\") !== -1);\n this.isCascadeRecover = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"recover\") !== -1);\n this.isPrimary = args.options.primary || false;\n this.isNullable = args.options.nullable === false || this.isPrimary ? false : true;\n this.onDelete = args.options.onDelete;\n this.onUpdate = args.options.onUpdate;\n this.deferrable = args.options.deferrable;\n this.createForeignKeyConstraints = args.options.createForeignKeyConstraints === false ? false : true;\n this.isEager = args.options.eager || false;\n this.persistenceEnabled = args.options.persistence === false ? false : true;\n this.orphanedRowAction = args.options.orphanedRowAction || \"nullify\";\n this.isTreeParent = args.isTreeParent || false;\n this.isTreeChildren = args.isTreeChildren || false;\n this.type = args.type instanceof Function ? (args.type as () => any)() : args.type;\n\n this.isOneToOne = this.relationType === \"one-to-one\";\n this.isOneToMany = this.relationType === \"one-to-many\";\n this.isManyToOne = this.relationType === \"many-to-one\";\n this.isManyToMany = this.relationType === \"many-to-many\";\n this.isOneToOneNotOwner = this.isOneToOne ? true : false;\n this.isManyToManyNotOwner = this.isManyToMany ? true : false;\n }\n\n // ---------------------------------------------------------------------\n // Public Methods\n // ---------------------------------------------------------------------\n\n /**\n * Creates join column ids map from the given related entity ids array.\n */\n getRelationIdMap(entity: ObjectLiteral): ObjectLiteral|undefined {\n const joinColumns = this.isOwning ? this.joinColumns : this.inverseRelation!.joinColumns;\n const referencedColumns = joinColumns.map(joinColumn => joinColumn.referencedColumn!);\n // console.log(\"entity\", entity);\n // console.log(\"referencedColumns\", referencedColumns);\n return EntityMetadata.getValueMap(entity, referencedColumns);\n }\n\n /**\n * Ensures that given object is an entity id map.\n * If given id is an object then it means its already id map.\n * If given id isn't an object then it means its a value of the id column\n * and it creates a new id map with this value and name of the primary column.\n */\n ensureRelationIdMap(id: any): ObjectLiteral {\n if (id instanceof Object)\n return id;\n\n const joinColumns = this.isOwning ? this.joinColumns : this.inverseRelation!.joinColumns;\n const referencedColumns = joinColumns.map(joinColumn => joinColumn.referencedColumn!);\n\n if (referencedColumns.length > 1)\n throw new TypeORMError(`Cannot create relation id map for a single value because relation contains multiple referenced columns.`);\n\n return referencedColumns[0].createValueMap(id);\n }\n\n /**\n * Extracts column value from the given entity.\n * If column is in embedded (or recursive embedded) it extracts its value from there.\n */\n getEntityValue(entity: ObjectLiteral, getLazyRelationsPromiseValue: boolean = false): any|undefined {\n if (entity === null || entity === undefined) return undefined;\n // extract column value from embeddeds of entity if column is in embedded\n if (this.embeddedMetadata) {\n\n // example: post[data][information][counters].id where \"data\", \"information\" and \"counters\" are embeddeds\n // we need to get value of \"id\" column from the post real entity object\n\n // first step - we extract all parent properties of the entity relative to this column, e.g. [data, information, counters]\n const propertyNames = [...this.embeddedMetadata.parentPropertyNames];\n\n // next we need to access post[data][information][counters][this.propertyName] to get column value from the counters\n // this recursive function takes array of generated property names and gets the post[data][information][counters] embed\n const extractEmbeddedColumnValue = (propertyNames: string[], value: ObjectLiteral): any => {\n const propertyName = propertyNames.shift();\n if (propertyName) {\n if (value[propertyName]) {\n return extractEmbeddedColumnValue(propertyNames, value[propertyName]);\n }\n return undefined;\n }\n return value;\n };\n\n // once we get nested embed object we get its column, e.g. post[data][information][counters][this.propertyName]\n const embeddedObject = extractEmbeddedColumnValue(propertyNames, entity);\n\n if (this.isLazy) {\n if (embeddedObject[\"__\" + this.propertyName + \"__\"] !== undefined)\n return embeddedObject[\"__\" + this.propertyName + \"__\"];\n\n if (getLazyRelationsPromiseValue === true)\n return embeddedObject[this.propertyName];\n\n return undefined;\n }\n return embeddedObject ? embeddedObject[this.isLazy ? \"__\" + this.propertyName + \"__\" : this.propertyName] : undefined;\n\n } else { // no embeds - no problems. Simply return column name by property name of the entity\n if (this.isLazy) {\n if (entity[\"__\" + this.propertyName + \"__\"] !== undefined)\n return entity[\"__\" + this.propertyName + \"__\"];\n\n if (getLazyRelationsPromiseValue === true)\n return entity[this.propertyName];\n\n return undefined;\n }\n return entity[this.propertyName];\n }\n }\n\n /**\n * Sets given entity's relation's value.\n * Using of this method helps to set entity relation's value of the lazy and non-lazy relations.\n *\n * If merge is set to true, it merges given value into currently\n */\n setEntityValue(entity: ObjectLiteral, value: any): void {\n const propertyName = this.isLazy ? \"__\" + this.propertyName + \"__\" : this.propertyName;\n\n if (this.embeddedMetadata) {\n\n // first step - we extract all parent properties of the entity relative to this column, e.g. [data, information, counters]\n const extractEmbeddedColumnValue = (embeddedMetadatas: EmbeddedMetadata[], map: ObjectLiteral): any => {\n // if (!object[embeddedMetadata.propertyName])\n // object[embeddedMetadata.propertyName] = embeddedMetadata.create();\n\n const embeddedMetadata = embeddedMetadatas.shift();\n if (embeddedMetadata) {\n if (!map[embeddedMetadata.propertyName])\n map[embeddedMetadata.propertyName] = embeddedMetadata.create();\n\n extractEmbeddedColumnValue(embeddedMetadatas, map[embeddedMetadata.propertyName]);\n return map;\n }\n map[propertyName] = value;\n return map;\n };\n return extractEmbeddedColumnValue([...this.embeddedMetadata.embeddedMetadataTree], entity);\n\n } else {\n entity[propertyName] = value;\n }\n }\n\n /**\n * Creates entity id map from the given entity ids array.\n */\n createValueMap(value: any) {\n\n // extract column value from embeds of entity if column is in embedded\n if (this.embeddedMetadata) {\n\n // example: post[data][information][counters].id where \"data\", \"information\" and \"counters\" are embeddeds\n // we need to get value of \"id\" column from the post real entity object and return it in a\n // { data: { information: { counters: { id: ... } } } } format\n\n // first step - we extract all parent properties of the entity relative to this column, e.g. [data, information, counters]\n const propertyNames = [...this.embeddedMetadata.parentPropertyNames];\n\n // now need to access post[data][information][counters] to get column value from the counters\n // and on each step we need to create complex literal object, e.g. first { data },\n // then { data: { information } }, then { data: { information: { counters } } },\n // then { data: { information: { counters: [this.propertyName]: entity[data][information][counters][this.propertyName] } } }\n // this recursive function helps doing that\n const extractEmbeddedColumnValue = (propertyNames: string[], map: ObjectLiteral): any => {\n const propertyName = propertyNames.shift();\n if (propertyName) {\n map[propertyName] = {};\n extractEmbeddedColumnValue(propertyNames, map[propertyName]);\n return map;\n }\n map[this.propertyName] = value;\n return map;\n };\n return extractEmbeddedColumnValue(propertyNames, {});\n\n } else { // no embeds - no problems. Simply return column property name and its value of the entity\n return { [this.propertyName]: value };\n }\n }\n\n // ---------------------------------------------------------------------\n // Builder Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds some depend relation metadata properties.\n * This builder method should be used only after embedded metadata tree was build.\n */\n build() {\n this.propertyPath = this.buildPropertyPath();\n }\n\n /**\n * Registers given foreign keys in the relation.\n * This builder method should be used to register foreign key in the relation.\n */\n registerForeignKeys(...foreignKeys: ForeignKeyMetadata[]) {\n this.foreignKeys.push(...foreignKeys);\n }\n\n /**\n * Registers given join columns in the relation.\n * This builder method should be used to register join column in the relation.\n */\n registerJoinColumns(joinColumns: ColumnMetadata[] = [], inverseJoinColumns: ColumnMetadata[] = []) {\n this.joinColumns = joinColumns;\n this.inverseJoinColumns = inverseJoinColumns;\n this.isOwning = this.isManyToOne || ((this.isManyToMany || this.isOneToOne) && this.joinColumns.length > 0);\n this.isOneToOneOwner = this.isOneToOne && this.isOwning;\n this.isOneToOneNotOwner = this.isOneToOne && !this.isOwning;\n this.isManyToManyOwner = this.isManyToMany && this.isOwning;\n this.isManyToManyNotOwner = this.isManyToMany && !this.isOwning;\n this.isWithJoinColumn = this.isManyToOne || this.isOneToOneOwner;\n }\n\n /**\n * Registers a given junction entity metadata.\n * This builder method can be called after junction entity metadata for the many-to-many relation was created.\n */\n registerJunctionEntityMetadata(junctionEntityMetadata: EntityMetadata) {\n this.junctionEntityMetadata = junctionEntityMetadata;\n this.joinTableName = junctionEntityMetadata.tableName;\n if (this.inverseRelation) {\n this.inverseRelation.junctionEntityMetadata = junctionEntityMetadata;\n this.joinTableName = junctionEntityMetadata.tableName;\n }\n }\n\n /**\n * Builds inverse side property path based on given inverse side property factory.\n * This builder method should be used only after properties map of the inverse entity metadata was build.\n */\n buildInverseSidePropertyPath(): string {\n\n if (this.givenInverseSidePropertyFactory) {\n const ownerEntityPropertiesMap = this.inverseEntityMetadata.propertiesMap;\n if (typeof this.givenInverseSidePropertyFactory === \"function\")\n return this.givenInverseSidePropertyFactory(ownerEntityPropertiesMap);\n\n if (typeof this.givenInverseSidePropertyFactory === \"string\")\n return this.givenInverseSidePropertyFactory;\n\n } else if (this.isTreeParent && this.entityMetadata.treeChildrenRelation) {\n return this.entityMetadata.treeChildrenRelation.propertyName;\n\n } else if (this.isTreeChildren && this.entityMetadata.treeParentRelation) {\n return this.entityMetadata.treeParentRelation.propertyName;\n }\n\n return \"\";\n }\n\n /**\n * Builds relation's property path based on its embedded tree.\n */\n buildPropertyPath(): string {\n if (!this.embeddedMetadata || !this.embeddedMetadata.parentPropertyNames.length)\n return this.propertyName;\n\n return this.embeddedMetadata.parentPropertyNames.join(\".\") + \".\" + this.propertyName;\n }\n\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../../src/metadata/RelationMetadata.ts"],"names":[],"mappings":";;;;AACA,mDAAgD;AAUhD,kCAAwC;AAExC;;GAEG;AACH;IAoQI,wEAAwE;IACxE,cAAc;IACd,wEAAwE;IAExE,0BAAY,OAIX;QA9MD;;WAEG;QACH,iBAAY,GAAY,KAAK,CAAC;QAE9B;;WAEG;QACH,mBAAc,GAAY,KAAK,CAAC;QAEhC;;;WAGG;QACH,cAAS,GAAY,KAAK,CAAC;QAE3B;;WAEG;QACH,WAAM,GAAY,KAAK,CAAC;QAExB;;WAEG;QACH,YAAO,GAAY,KAAK,CAAC;QAEzB;;;;;WAKG;QACH,uBAAkB,GAAY,IAAI,CAAC;QAOnC;;WAEG;QACH,oBAAe,GAAY,KAAK,CAAC;QAEjC;;WAEG;QACH,oBAAe,GAAY,KAAK,CAAC;QAEjC;;WAEG;QACH,oBAAe,GAAY,KAAK,CAAC;QAEjC;;WAEG;QACH,wBAAmB,GAAY,KAAK,CAAC;QAErC;;WAEG;QACH,qBAAgB,GAAY,KAAK,CAAC;QAElC;;WAEG;QACH,eAAU,GAAY,IAAI,CAAC;QAiB3B;;;;WAIG;QACH,gCAA2B,GAAY,IAAI,CAAC;QAS5C;;WAEG;QACH,aAAQ,GAAY,KAAK,CAAC;QAE1B;;WAEG;QACH,eAAU,GAAY,KAAK,CAAC;QAE5B;;;WAGG;QACH,oBAAe,GAAY,KAAK,CAAC;QAEjC;;WAEG;QACH,qBAAgB,GAAY,KAAK,CAAC;QAElC;;;WAGG;QACH,uBAAkB,GAAY,KAAK,CAAC;QAEpC;;WAEG;QACH,gBAAW,GAAY,KAAK,CAAC;QAE7B;;WAEG;QACH,gBAAW,GAAY,KAAK,C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AAqB,CAAC,aAAa,CAAC;YAC1E,IAAI,OAAO,IAAI,CAAC,+BAA+B,KAAK,UAAU;gBAC1D,OAAO,IAAI,CAAC,+BAA+B,CAAC,wBAAwB,CAAC,CAAC;YAE1E,IAAI,OAAO,IAAI,CAAC,+BAA+B,KAAK,QAAQ;gBACxD,OAAO,IAAI,CAAC,+BAA+B,CAAC;SAEnD;aAAM,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,cAAc,CAAC,oBAAoB,EAAE;YACtE,OAAO,IAAI,CAAC,cAAc,CAAC,oBAAoB,CAAC,YAAY,CAAC;SAEhE;aAAM,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,cAAc,CAAC,kBAAkB,EAAE;YACtE,OAAO,IAAI,CAAC,cAAc,CAAC,kBAAkB,CAAC,YAAY,CAAC;SAC9D;QAED,OAAO,EAAE,CAAC;IACd,CAAC;IAED;;OAEG;IACH,4CAAiB,GAAjB;QACI,IAAI,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,MAAM;YAC3E,OAAO,IAAI,CAAC,YAAY,CAAC;QAE7B,OAAO,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC;IACzF,CAAC;IAEL,uBAAC;AAAD,CA1iBA,AA0iBC,IAAA;AA1iBY,4CAAgB","file":"RelationMetadata.js","sourcesContent":["import {RelationType} from \"./types/RelationTypes\";\nimport {EntityMetadata} from \"./EntityMetadata\";\nimport {ForeignKeyMetadata} from \"./ForeignKeyMetadata\";\nimport {ObjectLiteral} from \"../common/ObjectLiteral\";\nimport {ColumnMetadata} from \"./ColumnMetadata\";\nimport {EmbeddedMetadata} from \"./EmbeddedMetadata\";\nimport {RelationMetadataArgs} from \"../metadata-args/RelationMetadataArgs\";\nimport {DeferrableType} from \"./types/DeferrableType\";\nimport {OnUpdateType} from \"./types/OnUpdateType\";\nimport {OnDeleteType} from \"./types/OnDeleteType\";\nimport {PropertyTypeFactory} from \"./types/PropertyTypeInFunction\";\nimport { TypeORMError } from \"../error\";\n\n/**\n * Contains all information about some entity's relation.\n */\nexport class RelationMetadata {\n\n // ---------------------------------------------------------------------\n // Public Properties\n // ---------------------------------------------------------------------\n\n /**\n * Entity metadata of the entity where this relation is placed.\n *\n * For example for @ManyToMany(type => Category) in Post, entityMetadata will be metadata of Post entity.\n */\n entityMetadata: EntityMetadata;\n\n /**\n * Entity metadata of the entity that is targeted by this relation.\n *\n * For example for @ManyToMany(type => Category) in Post, inverseEntityMetadata will be metadata of Category entity.\n */\n inverseEntityMetadata: EntityMetadata;\n\n /**\n * Entity metadata of the junction table.\n * Junction tables have their own entity metadata objects.\n * Defined only for many-to-many relations.\n */\n junctionEntityMetadata?: EntityMetadata;\n\n /**\n * Embedded metadata where this relation is.\n * If this relation is not in embed then this property value is undefined.\n */\n embeddedMetadata?: EmbeddedMetadata;\n\n /**\n * Relation type, e.g. is it one-to-one, one-to-many, many-to-one or many-to-many.\n */\n relationType: RelationType;\n\n /**\n * Target entity to which this relation is applied.\n * Target IS NOT equal to entityMetadata.target, because relation\n *\n * For example for @ManyToMany(type => Category) in Post, target will be Post.\n * If @ManyToMany(type => Category) is in Counters which is embedded into Post, target will be Counters.\n * If @ManyToMany(type => Category) is in abstract class BaseUser which Post extends, target will be BaseUser.\n * Target can be string if its defined in entity schema instead of class.\n */\n target: Function|string;\n\n /**\n * Target's property name to which relation decorator is applied.\n */\n propertyName: string;\n\n /**\n * Gets full path to this column property (including relation name).\n * Full path is relevant when column is used in embeds (one or multiple nested).\n * For example it will return \"counters.subcounters.likes\".\n * If property is not in embeds then it returns just property name of the column.\n */\n propertyPath: string;\n\n /**\n * Indicates if this is a parent (can be only many-to-one relation) relation in the tree tables.\n */\n isTreeParent: boolean = false;\n\n /**\n * Indicates if this is a children (can be only one-to-many relation) relation in the tree tables.\n */\n isTreeChildren: boolean = false;\n\n /**\n * Indicates if this relation's column is a primary key.\n * Can be used only for many-to-one and owner one-to-one relations.\n */\n isPrimary: boolean = false;\n\n /**\n * Indicates if this relation is lazily loaded.\n */\n isLazy: boolean = false;\n\n /**\n * Indicates if this relation is eagerly loaded.\n */\n isEager: boolean = false;\n\n /**\n * Indicates if persistence is enabled for the relation.\n * 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.\n * If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.\n * This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.\n */\n persistenceEnabled: boolean = true;\n\n /**\n * When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.\n */\n orphanedRowAction?: \"nullify\" | \"delete\" | \"soft-delete\";\n\n /**\n * If set to true then related objects are allowed to be inserted to the database.\n */\n isCascadeInsert: boolean = false;\n\n /**\n * If set to true then related objects are allowed to be updated in the database.\n */\n isCascadeUpdate: boolean = false;\n\n /**\n * If set to true then related objects are allowed to be remove from the database.\n */\n isCascadeRemove: boolean = false;\n\n /**\n * If set to true then related objects are allowed to be soft-removed from the database.\n */\n isCascadeSoftRemove: boolean = false;\n\n /**\n * If set to true then related objects are allowed to be recovered from the database.\n */\n isCascadeRecover: boolean = false;\n\n /**\n * Indicates if relation column value can be nullable or not.\n */\n isNullable: boolean = true;\n\n /**\n * What to do with a relation on deletion of the row containing a foreign key.\n */\n onDelete?: OnDeleteType;\n\n /**\n * What to do with a relation on update of the row containing a foreign key.\n */\n onUpdate?: OnUpdateType;\n\n /**\n * What to do with a relation on update of the row containing a foreign key.\n */\n deferrable?: DeferrableType;\n\n /**\n * Indicates whether foreign key constraints will be created for join columns.\n * Can be used only for many-to-one and owner one-to-one relations.\n * Defaults to true.\n */\n createForeignKeyConstraints: boolean = true;\n\n /**\n * Gets the property's type to which this relation is applied.\n *\n * For example for @ManyToMany(type => Category) in Post, target will be Category.\n */\n type: Function|string;\n\n /**\n * Indicates if this side is an owner of this relation.\n */\n isOwning: boolean = false;\n\n /**\n * Checks if this relation's type is \"one-to-one\".\n */\n isOneToOne: boolean = false;\n\n /**\n * Checks if this relation is owner side of the \"one-to-one\" relation.\n * Owner side means this side of relation has a join column in the table.\n */\n isOneToOneOwner: boolean = false;\n\n /**\n * Checks if this relation has a join column (e.g. is it many-to-one or one-to-one owner side).\n */\n isWithJoinColumn: boolean = false;\n\n /**\n * Checks if this relation is NOT owner side of the \"one-to-one\" relation.\n * NOT owner side means this side of relation does not have a join column in the table.\n */\n isOneToOneNotOwner: boolean = false;\n\n /**\n * Checks if this relation's type is \"one-to-many\".\n */\n isOneToMany: boolean = false;\n\n /**\n * Checks if this relation's type is \"many-to-one\".\n */\n isManyToOne: boolean = false;\n\n /**\n * Checks if this relation's type is \"many-to-many\".\n */\n isManyToMany: boolean = false;\n\n /**\n * Checks if this relation's type is \"many-to-many\", and is owner side of the relationship.\n * Owner side means this side of relation has a join table.\n */\n isManyToManyOwner: boolean = false;\n\n /**\n * Checks if this relation's type is \"many-to-many\", and is NOT owner side of the relationship.\n * Not owner side means this side of relation does not have a join table.\n */\n isManyToManyNotOwner: boolean = false;\n\n /**\n * Gets the property path of the inverse side of the relation.\n */\n inverseSidePropertyPath: string;\n\n /**\n * Inverse side of the relation set by user.\n *\n * Inverse side set in the relation can be either string - property name of the column on inverse side,\n * either can be a function that accepts a map of properties with the object and returns one of them.\n * Second approach is used to achieve type-safety.\n */\n givenInverseSidePropertyFactory: PropertyTypeFactory<any>;\n\n /**\n * Gets the relation metadata of the inverse side of this relation.\n */\n inverseRelation?: RelationMetadata;\n\n /**\n * Join table name.\n */\n joinTableName: string;\n\n /**\n * Foreign keys created for this relation.\n */\n foreignKeys: ForeignKeyMetadata[] = [];\n\n /**\n * Join table columns.\n * Join columns can be obtained only from owner side of the relation.\n * From non-owner side of the relation join columns will be empty.\n * If this relation is a many-to-one/one-to-one then it takes join columns from the current entity.\n * If this relation is many-to-many then it takes all owner join columns from the junction entity.\n */\n joinColumns: ColumnMetadata[] = [];\n\n /**\n * Inverse join table columns.\n * Inverse join columns are supported only for many-to-many relations\n * and can be obtained only from owner side of the relation.\n * From non-owner side of the relation join columns will be undefined.\n */\n inverseJoinColumns: ColumnMetadata[] = [];\n\n // ---------------------------------------------------------------------\n // Constructor\n // ---------------------------------------------------------------------\n\n constructor(options: {\n entityMetadata: EntityMetadata,\n embeddedMetadata?: EmbeddedMetadata,\n args: RelationMetadataArgs\n }) {\n this.entityMetadata = options.entityMetadata;\n this.embeddedMetadata = options.embeddedMetadata!;\n const args = options.args;\n this.target = args.target;\n this.propertyName = args.propertyName;\n this.relationType = args.relationType;\n\n if (args.inverseSideProperty)\n this.givenInverseSidePropertyFactory = args.inverseSideProperty;\n\n this.isLazy = args.isLazy || false;\n // this.isCascadeInsert = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"insert\") !== -1);\n // this.isCascadeUpdate = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"update\") !== -1);\n // this.isCascadeRemove = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"remove\") !== -1);\n // this.isCascadeSoftRemove = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"soft-remove\") !== -1);\n // this.isCascadeRecover = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"recover\") !== -1);\n this.isCascadeInsert = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"insert\") !== -1);\n this.isCascadeUpdate = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"update\") !== -1);\n this.isCascadeRemove = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"remove\") !== -1);\n this.isCascadeSoftRemove = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"soft-remove\") !== -1);\n this.isCascadeRecover = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf(\"recover\") !== -1);\n this.isPrimary = args.options.primary || false;\n this.isNullable = args.options.nullable === false || this.isPrimary ? false : true;\n this.onDelete = args.options.onDelete;\n this.onUpdate = args.options.onUpdate;\n this.deferrable = args.options.deferrable;\n this.createForeignKeyConstraints = args.options.createForeignKeyConstraints === false ? false : true;\n this.isEager = args.options.eager || false;\n this.persistenceEnabled = args.options.persistence === false ? false : true;\n this.orphanedRowAction = args.options.orphanedRowAction || \"nullify\";\n this.isTreeParent = args.isTreeParent || false;\n this.isTreeChildren = args.isTreeChildren || false;\n this.type = args.type instanceof Function ? (args.type as () => any)() : args.type;\n\n this.isOneToOne = this.relationType === \"one-to-one\";\n this.isOneToMany = this.relationType === \"one-to-many\";\n this.isManyToOne = this.relationType === \"many-to-one\";\n this.isManyToMany = this.relationType === \"many-to-many\";\n this.isOneToOneNotOwner = this.isOneToOne ? true : false;\n this.isManyToManyNotOwner = this.isManyToMany ? true : false;\n }\n\n // ---------------------------------------------------------------------\n // Public Methods\n // ---------------------------------------------------------------------\n\n /**\n * Creates join column ids map from the given related entity ids array.\n */\n getRelationIdMap(entity: ObjectLiteral): ObjectLiteral|undefined {\n const joinColumns = this.isOwning ? this.joinColumns : this.inverseRelation!.joinColumns;\n const referencedColumns = joinColumns.map(joinColumn => joinColumn.referencedColumn!);\n // console.log(\"entity\", entity);\n // console.log(\"referencedColumns\", referencedColumns);\n return EntityMetadata.getValueMap(entity, referencedColumns);\n }\n\n /**\n * Ensures that given object is an entity id map.\n * If given id is an object then it means its already id map.\n * If given id isn't an object then it means its a value of the id column\n * and it creates a new id map with this value and name of the primary column.\n */\n ensureRelationIdMap(id: any): ObjectLiteral {\n if (id instanceof Object)\n return id;\n\n const joinColumns = this.isOwning ? this.joinColumns : this.inverseRelation!.joinColumns;\n const referencedColumns = joinColumns.map(joinColumn => joinColumn.referencedColumn!);\n\n if (referencedColumns.length > 1)\n throw new TypeORMError(`Cannot create relation id map for a single value because relation contains multiple referenced columns.`);\n\n return referencedColumns[0].createValueMap(id);\n }\n\n /**\n * Extracts column value from the given entity.\n * If column is in embedded (or recursive embedded) it extracts its value from there.\n */\n getEntityValue(entity: ObjectLiteral, getLazyRelationsPromiseValue: boolean = false): any|undefined {\n if (entity === null || entity === undefined) return undefined;\n // extract column value from embeddeds of entity if column is in embedded\n if (this.embeddedMetadata) {\n\n // example: post[data][information][counters].id where \"data\", \"information\" and \"counters\" are embeddeds\n // we need to get value of \"id\" column from the post real entity object\n\n // first step - we extract all parent properties of the entity relative to this column, e.g. [data, information, counters]\n const propertyNames = [...this.embeddedMetadata.parentPropertyNames];\n\n // next we need to access post[data][information][counters][this.propertyName] to get column value from the counters\n // this recursive function takes array of generated property names and gets the post[data][information][counters] embed\n const extractEmbeddedColumnValue = (propertyNames: string[], value: ObjectLiteral): any => {\n const propertyName = propertyNames.shift();\n if (propertyName) {\n if (value[propertyName]) {\n return extractEmbeddedColumnValue(propertyNames, value[propertyName]);\n }\n return undefined;\n }\n return value;\n };\n\n // once we get nested embed object we get its column, e.g. post[data][information][counters][this.propertyName]\n const embeddedObject = extractEmbeddedColumnValue(propertyNames, entity);\n\n if (this.isLazy) {\n if (embeddedObject[\"__\" + this.propertyName + \"__\"] !== undefined)\n return embeddedObject[\"__\" + this.propertyName + \"__\"];\n\n if (getLazyRelationsPromiseValue === true)\n return embeddedObject[this.propertyName];\n\n return undefined;\n }\n return embeddedObject ? embeddedObject[this.isLazy ? \"__\" + this.propertyName + \"__\" : this.propertyName] : undefined;\n\n } else { // no embeds - no problems. Simply return column name by property name of the entity\n if (this.isLazy) {\n if (entity[\"__\" + this.propertyName + \"__\"] !== undefined)\n return entity[\"__\" + this.propertyName + \"__\"];\n\n if (getLazyRelationsPromiseValue === true)\n return entity[this.propertyName];\n\n return undefined;\n }\n return entity[this.propertyName];\n }\n }\n\n /**\n * Sets given entity's relation's value.\n * Using of this method helps to set entity relation's value of the lazy and non-lazy relations.\n *\n * If merge is set to true, it merges given value into currently\n */\n setEntityValue(entity: ObjectLiteral, value: any): void {\n const propertyName = this.isLazy ? \"__\" + this.propertyName + \"__\" : this.propertyName;\n\n if (this.embeddedMetadata) {\n\n // first step - we extract all parent properties of the entity relative to this column, e.g. [data, information, counters]\n const extractEmbeddedColumnValue = (embeddedMetadatas: EmbeddedMetadata[], map: ObjectLiteral): any => {\n // if (!object[embeddedMetadata.propertyName])\n // object[embeddedMetadata.propertyName] = embeddedMetadata.create();\n\n const embeddedMetadata = embeddedMetadatas.shift();\n if (embeddedMetadata) {\n if (!map[embeddedMetadata.propertyName])\n map[embeddedMetadata.propertyName] = embeddedMetadata.create();\n\n extractEmbeddedColumnValue(embeddedMetadatas, map[embeddedMetadata.propertyName]);\n return map;\n }\n map[propertyName] = value;\n return map;\n };\n return extractEmbeddedColumnValue([...this.embeddedMetadata.embeddedMetadataTree], entity);\n\n } else {\n entity[propertyName] = value;\n }\n }\n\n /**\n * Creates entity id map from the given entity ids array.\n */\n createValueMap(value: any) {\n\n // extract column value from embeds of entity if column is in embedded\n if (this.embeddedMetadata) {\n\n // example: post[data][information][counters].id where \"data\", \"information\" and \"counters\" are embeddeds\n // we need to get value of \"id\" column from the post real entity object and return it in a\n // { data: { information: { counters: { id: ... } } } } format\n\n // first step - we extract all parent properties of the entity relative to this column, e.g. [data, information, counters]\n const propertyNames = [...this.embeddedMetadata.parentPropertyNames];\n\n // now need to access post[data][information][counters] to get column value from the counters\n // and on each step we need to create complex literal object, e.g. first { data },\n // then { data: { information } }, then { data: { information: { counters } } },\n // then { data: { information: { counters: [this.propertyName]: entity[data][information][counters][this.propertyName] } } }\n // this recursive function helps doing that\n const extractEmbeddedColumnValue = (propertyNames: string[], map: ObjectLiteral): any => {\n const propertyName = propertyNames.shift();\n if (propertyName) {\n map[propertyName] = {};\n extractEmbeddedColumnValue(propertyNames, map[propertyName]);\n return map;\n }\n map[this.propertyName] = value;\n return map;\n };\n return extractEmbeddedColumnValue(propertyNames, {});\n\n } else { // no embeds - no problems. Simply return column property name and its value of the entity\n return { [this.propertyName]: value };\n }\n }\n\n // ---------------------------------------------------------------------\n // Builder Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds some depend relation metadata properties.\n * This builder method should be used only after embedded metadata tree was build.\n */\n build() {\n this.propertyPath = this.buildPropertyPath();\n }\n\n /**\n * Registers given foreign keys in the relation.\n * This builder method should be used to register foreign key in the relation.\n */\n registerForeignKeys(...foreignKeys: ForeignKeyMetadata[]) {\n this.foreignKeys.push(...foreignKeys);\n }\n\n /**\n * Registers given join columns in the relation.\n * This builder method should be used to register join column in the relation.\n */\n registerJoinColumns(joinColumns: ColumnMetadata[] = [], inverseJoinColumns: ColumnMetadata[] = []) {\n this.joinColumns = joinColumns;\n this.inverseJoinColumns = inverseJoinColumns;\n this.isOwning = this.isManyToOne || ((this.isManyToMany || this.isOneToOne) && this.joinColumns.length > 0);\n this.isOneToOneOwner = this.isOneToOne && this.isOwning;\n this.isOneToOneNotOwner = this.isOneToOne && !this.isOwning;\n this.isManyToManyOwner = this.isManyToMany && this.isOwning;\n this.isManyToManyNotOwner = this.isManyToMany && !this.isOwning;\n this.isWithJoinColumn = this.isManyToOne || this.isOneToOneOwner;\n }\n\n /**\n * Registers a given junction entity metadata.\n * This builder method can be called after junction entity metadata for the many-to-many relation was created.\n */\n registerJunctionEntityMetadata(junctionEntityMetadata: EntityMetadata) {\n this.junctionEntityMetadata = junctionEntityMetadata;\n this.joinTableName = junctionEntityMetadata.tableName;\n if (this.inverseRelation) {\n this.inverseRelation.junctionEntityMetadata = junctionEntityMetadata;\n this.joinTableName = junctionEntityMetadata.tableName;\n }\n }\n\n /**\n * Builds inverse side property path based on given inverse side property factory.\n * This builder method should be used only after properties map of the inverse entity metadata was build.\n */\n buildInverseSidePropertyPath(): string {\n\n if (this.givenInverseSidePropertyFactory) {\n const ownerEntityPropertiesMap = this.inverseEntityMetadata.propertiesMap;\n if (typeof this.givenInverseSidePropertyFactory === \"function\")\n return this.givenInverseSidePropertyFactory(ownerEntityPropertiesMap);\n\n if (typeof this.givenInverseSidePropertyFactory === \"string\")\n return this.givenInverseSidePropertyFactory;\n\n } else if (this.isTreeParent && this.entityMetadata.treeChildrenRelation) {\n return this.entityMetadata.treeChildrenRelation.propertyName;\n\n } else if (this.isTreeChildren && this.entityMetadata.treeParentRelation) {\n return this.entityMetadata.treeParentRelation.propertyName;\n }\n\n return \"\";\n }\n\n /**\n * Builds relation's property path based on its embedded tree.\n */\n buildPropertyPath(): string {\n if (!this.embeddedMetadata || !this.embeddedMetadata.parentPropertyNames.length)\n return this.propertyName;\n\n return this.embeddedMetadata.parentPropertyNames.join(\".\") + \".\" + this.propertyName;\n }\n\n}\n"],"sourceRoot":".."}
|
|
@@ -62,6 +62,7 @@ var EntityMetadataValidator = /** @class */ (function () {
|
|
|
62
62
|
var sameDiscriminatorValueEntityMetadata = allEntityMetadatas.find(function (metadata) {
|
|
63
63
|
return metadata !== entityMetadata
|
|
64
64
|
&& (metadata.inheritancePattern === "STI" || metadata.tableType === "entity-child")
|
|
65
|
+
&& metadata.tableName === entityMetadata.tableName
|
|
65
66
|
&& metadata.discriminatorValue === entityMetadata.discriminatorValue
|
|
66
67
|
&& metadata.inheritanceTree.some(function (parent) { return entityMetadata.inheritanceTree.indexOf(parent) !== -1; });
|
|
67
68
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/metadata-builder/EntityMetadataValidator.ts"],"names":[],"mappings":";;;AACA,gFAA6E;AAC7E,0EAAuE;AACvE,6CAA0C;AAE1C,gFAA6E;AAE7E,6DAA0D;AAC1D,uEAAoE;AACpE,2DAAwD;AACxD,4EAAyE;AACzE,8EAA2E;AAC3E,qFAAkF;AAClF,kCAAwC;AAExC,mEAAmE;AACnE,6FAA6F;AAC7F,sEAAsE;AACtE,mGAAmG;AACnG,2GAA2G;AAC3G,6DAA6D;AAC7D,uEAAuE;AACvE,iFAAiF;AAEjF,2FAA2F;AAC3F,wHAAwH;AACxH,gIAAgI;AAChI,mGAAmG;AACnG,8EAA8E;A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AAe,CAAC,OAAO;oBAC5D,MAAM,IAAI,oBAAY,CAAC,2CAA2C;yBAC3D,cAAc,CAAC,UAAU,SAAI,QAAQ,CAAC,YAAY,qDAAgD,CAAA;yBAClG,QAAQ,CAAC,qBAAqB,CAAC,UAAU,SAAI,QAAQ,CAAC,eAAe,CAAC,YAAY,uCAAkC,CAAA;wBACvH,wDAAsD,CAAC,CAAC;YACpE,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAEL,8BAAC;AAAD,CAnNA,AAmNC,IAAA;AAnNY,0DAAuB","file":"EntityMetadataValidator.js","sourcesContent":["import {EntityMetadata} from \"../metadata/EntityMetadata\";\nimport {MissingPrimaryColumnError} from \"../error/MissingPrimaryColumnError\";\nimport {CircularRelationsError} from \"../error/CircularRelationsError\";\nimport {DepGraph} from \"../util/DepGraph\";\nimport {Driver} from \"../driver/Driver\";\nimport {DataTypeNotSupportedError} from \"../error/DataTypeNotSupportedError\";\nimport {ColumnType} from \"../driver/types/ColumnTypes\";\nimport {MongoDriver} from \"../driver/mongodb/MongoDriver\";\nimport {SqlServerDriver} from \"../driver/sqlserver/SqlServerDriver\";\nimport {MysqlDriver} from \"../driver/mysql/MysqlDriver\";\nimport {NoConnectionOptionError} from \"../error/NoConnectionOptionError\";\nimport {InitializedRelationError} from \"../error/InitializedRelationError\";\nimport {AuroraDataApiDriver} from \"../driver/aurora-data-api/AuroraDataApiDriver\";\nimport { TypeORMError } from \"../error\";\n\n/// todo: add check if there are multiple tables with the same name\n/// todo: add checks when generated column / table names are too long for the specific driver\n// todo: type in function validation, inverse side function validation\n// todo: check on build for duplicate names, since naming checking was removed from MetadataStorage\n// todo: duplicate name checking for: table, relation, column, index, naming strategy, join tables/columns?\n// todo: check if multiple tree parent metadatas in validator\n// todo: tree decorators can be used only on closure table (validation)\n// todo: throw error if parent tree metadata was not specified in a closure table\n\n// todo: MetadataArgsStorage: type in function validation, inverse side function validation\n// todo: MetadataArgsStorage: check on build for duplicate names, since naming checking was removed from MetadataStorage\n// todo: MetadataArgsStorage: duplicate name checking for: table, relation, column, index, naming strategy, join tables/columns?\n// todo: MetadataArgsStorage: check for duplicate targets too since this check has been removed too\n// todo: check if relation decorator contains primary: true and nullable: true\n// todo: check column length, precision. scale\n// todo: MySQL index can be unique or spatial or fulltext\n\n/**\n * Validates built entity metadatas.\n */\nexport class EntityMetadataValidator {\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Validates all given entity metadatas.\n */\n validateMany(entityMetadatas: EntityMetadata[], driver: Driver) {\n entityMetadatas.forEach(entityMetadata => this.validate(entityMetadata, entityMetadatas, driver));\n this.validateDependencies(entityMetadatas);\n this.validateEagerRelations(entityMetadatas);\n }\n\n /**\n * Validates given entity metadata.\n */\n validate(entityMetadata: EntityMetadata, allEntityMetadatas: EntityMetadata[], driver: Driver) {\n\n // check if table metadata has an id\n if (!entityMetadata.primaryColumns.length && !entityMetadata.isJunction)\n throw new MissingPrimaryColumnError(entityMetadata);\n\n // validate if table is using inheritance it has a discriminator\n // also validate if discriminator values are not empty and not repeated\n if (entityMetadata.inheritancePattern === \"STI\" || entityMetadata.tableType === \"entity-child\") {\n if (!entityMetadata.discriminatorColumn)\n throw new TypeORMError(`Entity ${entityMetadata.name} using single-table inheritance, it should also have a discriminator column. Did you forget to put discriminator column options?`);\n\n if (typeof entityMetadata.discriminatorValue === \"undefined\")\n throw new TypeORMError(`Entity ${entityMetadata.name} has an undefined discriminator value. Discriminator value should be defined.`);\n\n const sameDiscriminatorValueEntityMetadata = allEntityMetadatas.find(metadata => {\n return metadata !== entityMetadata\n && (metadata.inheritancePattern === \"STI\" || metadata.tableType === \"entity-child\")\n && metadata.discriminatorValue === entityMetadata.discriminatorValue\n && metadata.inheritanceTree.some(parent => entityMetadata.inheritanceTree.indexOf(parent) !== -1);\n });\n if (sameDiscriminatorValueEntityMetadata)\n throw new TypeORMError(`Entities ${entityMetadata.name} and ${sameDiscriminatorValueEntityMetadata.name} have the same discriminator values. Make sure they are different while using the @ChildEntity decorator.`);\n }\n\n entityMetadata.relationCounts.forEach(relationCount => {\n if (relationCount.relation.isManyToOne || relationCount.relation.isOneToOne)\n throw new TypeORMError(`Relation count can not be implemented on ManyToOne or OneToOne relations.`);\n });\n\n if (!(driver instanceof MongoDriver)) {\n entityMetadata.columns.forEach(column => {\n const normalizedColumn = driver.normalizeType(column) as ColumnType;\n if (driver.supportedDataTypes.indexOf(normalizedColumn) === -1)\n throw new DataTypeNotSupportedError(column, normalizedColumn, driver.options.type);\n if (column.length && driver.withLengthColumnTypes.indexOf(normalizedColumn) === -1)\n throw new TypeORMError(`Column ${column.propertyName} of Entity ${entityMetadata.name} does not support length property.`);\n if (column.type === \"enum\" && !column.enum && !column.enumName)\n throw new TypeORMError(`Column \"${column.propertyName}\" of Entity \"${entityMetadata.name}\" is defined as enum, but missing \"enum\" or \"enumName\" properties.`);\n });\n }\n\n if (driver instanceof MysqlDriver || driver instanceof AuroraDataApiDriver) {\n const generatedColumns = entityMetadata.columns.filter(column => column.isGenerated && column.generationStrategy !== \"uuid\");\n if (generatedColumns.length > 1)\n throw new TypeORMError(`Error in ${entityMetadata.name} entity. There can be only one auto-increment column in MySql table.`);\n }\n\n // for mysql we are able to not define a default selected database, instead all entities can have their database\n // defined in their decorators. To make everything work either all entities must have database define and we\n // can live without database set in the connection options, either database in the connection options must be set\n if (driver instanceof MysqlDriver) {\n const metadatasWithDatabase = allEntityMetadatas.filter(metadata => metadata.database);\n if (metadatasWithDatabase.length === 0 && !driver.database)\n throw new NoConnectionOptionError(\"database\");\n }\n\n if (driver instanceof SqlServerDriver) {\n const charsetColumns = entityMetadata.columns.filter(column => column.charset);\n if (charsetColumns.length > 1)\n throw new TypeORMError(`Character set specifying is not supported in Sql Server`);\n }\n\n // check if relations are all without initialized properties\n const entityInstance = entityMetadata.create();\n entityMetadata.relations.forEach(relation => {\n if (relation.isManyToMany || relation.isOneToMany) {\n\n // we skip relations for which persistence is disabled since initialization in them cannot harm somehow\n if (relation.persistenceEnabled === false)\n return;\n\n // get entity relation value and check if its an array\n const relationInitializedValue = relation.getEntityValue(entityInstance);\n if (Array.isArray(relationInitializedValue))\n throw new InitializedRelationError(relation);\n }\n });\n\n // validate relations\n entityMetadata.relations.forEach(relation => {\n\n // check join tables:\n // using JoinTable is possible only on one side of the many-to-many relation\n // todo(dima): fix\n // if (relation.joinTable) {\n // if (!relation.isManyToMany)\n // throw new UsingJoinTableIsNotAllowedError(entityMetadata, relation);\n\n // // if there is inverse side of the relation, then check if it does not have join table too\n // if (relation.hasInverseSide && relation.inverseRelation.joinTable)\n // throw new UsingJoinTableOnlyOnOneSideAllowedError(entityMetadata, relation);\n // }\n\n // check join columns:\n // using JoinColumn is possible only on one side of the relation and on one-to-one, many-to-one relation types\n // first check if relation is one-to-one or many-to-one\n // todo(dima): fix\n /*if (relation.joinColumn) {\n\n // join column can be applied only on one-to-one and many-to-one relations\n if (!relation.isOneToOne && !relation.isManyToOne)\n throw new UsingJoinColumnIsNotAllowedError(entityMetadata, relation);\n\n // if there is inverse side of the relation, then check if it does not have join table too\n if (relation.hasInverseSide && relation.inverseRelation.joinColumn && relation.isOneToOne)\n throw new UsingJoinColumnOnlyOnOneSideAllowedError(entityMetadata, relation);\n\n // check if join column really has referenced column\n if (relation.joinColumn && !relation.joinColumn.referencedColumn)\n throw new TypeORMError(`Join column does not have referenced column set`);\n\n }\n\n // if its a one-to-one relation and JoinColumn is missing on both sides of the relation\n // or its one-side relation without JoinColumn we should give an error\n if (!relation.joinColumn && relation.isOneToOne && (!relation.hasInverseSide || !relation.inverseRelation.joinColumn))\n throw new MissingJoinColumnError(entityMetadata, relation);*/\n\n // if its a many-to-many relation and JoinTable is missing on both sides of the relation\n // or its one-side relation without JoinTable we should give an error\n // todo(dima): fix it\n // if (!relation.joinTable && relation.isManyToMany && (!relation.hasInverseSide || !relation.inverseRelation.joinTable))\n // throw new MissingJoinTableError(entityMetadata, relation);\n\n\n // todo: validate if its one-to-one and side which does not have join column MUST have inverse side\n // todo: validate if its many-to-many and side which does not have join table MUST have inverse side\n // todo: if there is a relation, and inverse side is specified only on one side, shall we give error\n // todo: with message like: \"Inverse side is specified only on one side of the relationship. Specify on other side too to prevent confusion\".\n // todo: add validation if there two entities with the same target, and show error message with description of the problem (maybe file was renamed/moved but left in output directory)\n // todo: check if there are multiple columns on the same column applied.\n // todo: check column type if is missing in relational databases (throw new TypeORMError(`Column type of ${type} cannot be determined.`);)\n // todo: include driver-specific checks. for example in mongodb empty prefixes are not allowed\n // todo: if multiple columns with same name - throw exception, including cases when columns are in embeds with same prefixes or without prefix at all\n // todo: if multiple primary key used, at least one of them must be unique or @Index decorator must be set on entity\n // todo: check if entity with duplicate names, some decorators exist\n\n\n });\n\n // make sure cascade remove is not set for both sides of relationships (can be set in OneToOne decorators)\n entityMetadata.relations.forEach(relation => {\n const isCircularCascadeRemove = relation.isCascadeRemove && relation.inverseRelation && relation.inverseRelation!.isCascadeRemove;\n if (isCircularCascadeRemove)\n throw new TypeORMError(`Relation ${entityMetadata.name}#${relation.propertyName} and ${relation.inverseRelation!.entityMetadata.name}#${relation.inverseRelation!.propertyName} both has cascade remove set. ` +\n `This may lead to unexpected circular removals. Please set cascade remove only from one side of relationship.`);\n }); // todo: maybe better just deny removal from one to one relation without join column?\n\n entityMetadata.eagerRelations.forEach(relation => {\n\n });\n }\n\n /**\n * Validates dependencies of the entity metadatas.\n */\n protected validateDependencies(entityMetadatas: EntityMetadata[]) {\n\n const graph = new DepGraph();\n entityMetadatas.forEach(entityMetadata => {\n graph.addNode(entityMetadata.name);\n });\n entityMetadatas.forEach(entityMetadata => {\n entityMetadata.relationsWithJoinColumns\n .filter(relation => !relation.isNullable)\n .forEach(relation => {\n graph.addDependency(entityMetadata.name, relation.inverseEntityMetadata.name);\n });\n });\n try {\n graph.overallOrder();\n\n } catch (err) {\n throw new CircularRelationsError(err.toString().replace(\"Error: Dependency Cycle Found: \", \"\"));\n }\n }\n\n /**\n * Validates eager relations to prevent circular dependency in them.\n */\n protected validateEagerRelations(entityMetadatas: EntityMetadata[]) {\n entityMetadatas.forEach(entityMetadata => {\n entityMetadata.eagerRelations.forEach(relation => {\n if (relation.inverseRelation && relation.inverseRelation.isEager)\n throw new TypeORMError(`Circular eager relations are disallowed. ` +\n `${entityMetadata.targetName}#${relation.propertyPath} contains \"eager: true\", and its inverse side ` +\n `${relation.inverseEntityMetadata.targetName}#${relation.inverseRelation.propertyPath} contains \"eager: true\" as well.` +\n ` Remove \"eager: true\" from one side of the relation.`);\n });\n });\n }\n\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../../src/metadata-builder/EntityMetadataValidator.ts"],"names":[],"mappings":";;;AACA,gFAA6E;AAC7E,0EAAuE;AACvE,6CAA0C;AAE1C,gFAA6E;AAE7E,6DAA0D;AAC1D,uEAAoE;AACpE,2DAAwD;AACxD,4EAAyE;AACzE,8EAA2E;AAC3E,qFAAkF;AAClF,kCAAwC;AAExC,mEAAmE;AACnE,6FAA6F;AAC7F,sEAAsE;AACtE,mGAAmG;AACnG,2GAA2G;AAC3G,6DAA6D;AAC7D,uEAAuE;AACvE,iFAAiF;AAEjF,2FAA2F;AAC3F,wHAAwH;AACxH,gIAAgI;AAChI,mGAAmG;AACnG,8EAA8E;AAC9E,8CAA8C;AAC9C,yDAAyD;AAEzD;;GAEG;AACH;IAAA;IAoNA,CAAC;IAlNG,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,8CAAY,GAAZ,UAAa,eAAiC,EAAE,MAAc;QAA9D,iBAIC;QAHG,eAAe,CAAC,OAAO,CAAC,UAAA,cAAc,IAAI,OAAA,KAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,eAAe,EAAE,MAAM,CAAC,EAAtD,CAAsD,CAAC,CAAC;QAClG,IAAI,CAAC,oBAAoB,CAAC,eAAe,CAAC,CAAC;QAC3C,IAAI,CAAC,sBAAsB,CAAC,eAAe,C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idator.js","sourcesContent":["import {EntityMetadata} from \"../metadata/EntityMetadata\";\nimport {MissingPrimaryColumnError} from \"../error/MissingPrimaryColumnError\";\nimport {CircularRelationsError} from \"../error/CircularRelationsError\";\nimport {DepGraph} from \"../util/DepGraph\";\nimport {Driver} from \"../driver/Driver\";\nimport {DataTypeNotSupportedError} from \"../error/DataTypeNotSupportedError\";\nimport {ColumnType} from \"../driver/types/ColumnTypes\";\nimport {MongoDriver} from \"../driver/mongodb/MongoDriver\";\nimport {SqlServerDriver} from \"../driver/sqlserver/SqlServerDriver\";\nimport {MysqlDriver} from \"../driver/mysql/MysqlDriver\";\nimport {NoConnectionOptionError} from \"../error/NoConnectionOptionError\";\nimport {InitializedRelationError} from \"../error/InitializedRelationError\";\nimport {AuroraDataApiDriver} from \"../driver/aurora-data-api/AuroraDataApiDriver\";\nimport { TypeORMError } from \"../error\";\n\n/// todo: add check if there are multiple tables with the same name\n/// todo: add checks when generated column / table names are too long for the specific driver\n// todo: type in function validation, inverse side function validation\n// todo: check on build for duplicate names, since naming checking was removed from MetadataStorage\n// todo: duplicate name checking for: table, relation, column, index, naming strategy, join tables/columns?\n// todo: check if multiple tree parent metadatas in validator\n// todo: tree decorators can be used only on closure table (validation)\n// todo: throw error if parent tree metadata was not specified in a closure table\n\n// todo: MetadataArgsStorage: type in function validation, inverse side function validation\n// todo: MetadataArgsStorage: check on build for duplicate names, since naming checking was removed from MetadataStorage\n// todo: MetadataArgsStorage: duplicate name checking for: table, relation, column, index, naming strategy, join tables/columns?\n// todo: MetadataArgsStorage: check for duplicate targets too since this check has been removed too\n// todo: check if relation decorator contains primary: true and nullable: true\n// todo: check column length, precision. scale\n// todo: MySQL index can be unique or spatial or fulltext\n\n/**\n * Validates built entity metadatas.\n */\nexport class EntityMetadataValidator {\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Validates all given entity metadatas.\n */\n validateMany(entityMetadatas: EntityMetadata[], driver: Driver) {\n entityMetadatas.forEach(entityMetadata => this.validate(entityMetadata, entityMetadatas, driver));\n this.validateDependencies(entityMetadatas);\n this.validateEagerRelations(entityMetadatas);\n }\n\n /**\n * Validates given entity metadata.\n */\n validate(entityMetadata: EntityMetadata, allEntityMetadatas: EntityMetadata[], driver: Driver) {\n\n // check if table metadata has an id\n if (!entityMetadata.primaryColumns.length && !entityMetadata.isJunction)\n throw new MissingPrimaryColumnError(entityMetadata);\n\n // validate if table is using inheritance it has a discriminator\n // also validate if discriminator values are not empty and not repeated\n if (entityMetadata.inheritancePattern === \"STI\" || entityMetadata.tableType === \"entity-child\") {\n if (!entityMetadata.discriminatorColumn)\n throw new TypeORMError(`Entity ${entityMetadata.name} using single-table inheritance, it should also have a discriminator column. Did you forget to put discriminator column options?`);\n\n if (typeof entityMetadata.discriminatorValue === \"undefined\")\n throw new TypeORMError(`Entity ${entityMetadata.name} has an undefined discriminator value. Discriminator value should be defined.`);\n\n const sameDiscriminatorValueEntityMetadata = allEntityMetadatas.find(metadata => {\n return metadata !== entityMetadata\n && (metadata.inheritancePattern === \"STI\" || metadata.tableType === \"entity-child\")\n && metadata.tableName === entityMetadata.tableName\n && metadata.discriminatorValue === entityMetadata.discriminatorValue\n && metadata.inheritanceTree.some(parent => entityMetadata.inheritanceTree.indexOf(parent) !== -1);\n });\n if (sameDiscriminatorValueEntityMetadata)\n throw new TypeORMError(`Entities ${entityMetadata.name} and ${sameDiscriminatorValueEntityMetadata.name} have the same discriminator values. Make sure they are different while using the @ChildEntity decorator.`);\n }\n\n entityMetadata.relationCounts.forEach(relationCount => {\n if (relationCount.relation.isManyToOne || relationCount.relation.isOneToOne)\n throw new TypeORMError(`Relation count can not be implemented on ManyToOne or OneToOne relations.`);\n });\n\n if (!(driver instanceof MongoDriver)) {\n entityMetadata.columns.forEach(column => {\n const normalizedColumn = driver.normalizeType(column) as ColumnType;\n if (driver.supportedDataTypes.indexOf(normalizedColumn) === -1)\n throw new DataTypeNotSupportedError(column, normalizedColumn, driver.options.type);\n if (column.length && driver.withLengthColumnTypes.indexOf(normalizedColumn) === -1)\n throw new TypeORMError(`Column ${column.propertyName} of Entity ${entityMetadata.name} does not support length property.`);\n if (column.type === \"enum\" && !column.enum && !column.enumName)\n throw new TypeORMError(`Column \"${column.propertyName}\" of Entity \"${entityMetadata.name}\" is defined as enum, but missing \"enum\" or \"enumName\" properties.`);\n });\n }\n\n if (driver instanceof MysqlDriver || driver instanceof AuroraDataApiDriver) {\n const generatedColumns = entityMetadata.columns.filter(column => column.isGenerated && column.generationStrategy !== \"uuid\");\n if (generatedColumns.length > 1)\n throw new TypeORMError(`Error in ${entityMetadata.name} entity. There can be only one auto-increment column in MySql table.`);\n }\n\n // for mysql we are able to not define a default selected database, instead all entities can have their database\n // defined in their decorators. To make everything work either all entities must have database define and we\n // can live without database set in the connection options, either database in the connection options must be set\n if (driver instanceof MysqlDriver) {\n const metadatasWithDatabase = allEntityMetadatas.filter(metadata => metadata.database);\n if (metadatasWithDatabase.length === 0 && !driver.database)\n throw new NoConnectionOptionError(\"database\");\n }\n\n if (driver instanceof SqlServerDriver) {\n const charsetColumns = entityMetadata.columns.filter(column => column.charset);\n if (charsetColumns.length > 1)\n throw new TypeORMError(`Character set specifying is not supported in Sql Server`);\n }\n\n // check if relations are all without initialized properties\n const entityInstance = entityMetadata.create();\n entityMetadata.relations.forEach(relation => {\n if (relation.isManyToMany || relation.isOneToMany) {\n\n // we skip relations for which persistence is disabled since initialization in them cannot harm somehow\n if (relation.persistenceEnabled === false)\n return;\n\n // get entity relation value and check if its an array\n const relationInitializedValue = relation.getEntityValue(entityInstance);\n if (Array.isArray(relationInitializedValue))\n throw new InitializedRelationError(relation);\n }\n });\n\n // validate relations\n entityMetadata.relations.forEach(relation => {\n\n // check join tables:\n // using JoinTable is possible only on one side of the many-to-many relation\n // todo(dima): fix\n // if (relation.joinTable) {\n // if (!relation.isManyToMany)\n // throw new UsingJoinTableIsNotAllowedError(entityMetadata, relation);\n\n // // if there is inverse side of the relation, then check if it does not have join table too\n // if (relation.hasInverseSide && relation.inverseRelation.joinTable)\n // throw new UsingJoinTableOnlyOnOneSideAllowedError(entityMetadata, relation);\n // }\n\n // check join columns:\n // using JoinColumn is possible only on one side of the relation and on one-to-one, many-to-one relation types\n // first check if relation is one-to-one or many-to-one\n // todo(dima): fix\n /*if (relation.joinColumn) {\n\n // join column can be applied only on one-to-one and many-to-one relations\n if (!relation.isOneToOne && !relation.isManyToOne)\n throw new UsingJoinColumnIsNotAllowedError(entityMetadata, relation);\n\n // if there is inverse side of the relation, then check if it does not have join table too\n if (relation.hasInverseSide && relation.inverseRelation.joinColumn && relation.isOneToOne)\n throw new UsingJoinColumnOnlyOnOneSideAllowedError(entityMetadata, relation);\n\n // check if join column really has referenced column\n if (relation.joinColumn && !relation.joinColumn.referencedColumn)\n throw new TypeORMError(`Join column does not have referenced column set`);\n\n }\n\n // if its a one-to-one relation and JoinColumn is missing on both sides of the relation\n // or its one-side relation without JoinColumn we should give an error\n if (!relation.joinColumn && relation.isOneToOne && (!relation.hasInverseSide || !relation.inverseRelation.joinColumn))\n throw new MissingJoinColumnError(entityMetadata, relation);*/\n\n // if its a many-to-many relation and JoinTable is missing on both sides of the relation\n // or its one-side relation without JoinTable we should give an error\n // todo(dima): fix it\n // if (!relation.joinTable && relation.isManyToMany && (!relation.hasInverseSide || !relation.inverseRelation.joinTable))\n // throw new MissingJoinTableError(entityMetadata, relation);\n\n\n // todo: validate if its one-to-one and side which does not have join column MUST have inverse side\n // todo: validate if its many-to-many and side which does not have join table MUST have inverse side\n // todo: if there is a relation, and inverse side is specified only on one side, shall we give error\n // todo: with message like: \"Inverse side is specified only on one side of the relationship. Specify on other side too to prevent confusion\".\n // todo: add validation if there two entities with the same target, and show error message with description of the problem (maybe file was renamed/moved but left in output directory)\n // todo: check if there are multiple columns on the same column applied.\n // todo: check column type if is missing in relational databases (throw new TypeORMError(`Column type of ${type} cannot be determined.`);)\n // todo: include driver-specific checks. for example in mongodb empty prefixes are not allowed\n // todo: if multiple columns with same name - throw exception, including cases when columns are in embeds with same prefixes or without prefix at all\n // todo: if multiple primary key used, at least one of them must be unique or @Index decorator must be set on entity\n // todo: check if entity with duplicate names, some decorators exist\n\n\n });\n\n // make sure cascade remove is not set for both sides of relationships (can be set in OneToOne decorators)\n entityMetadata.relations.forEach(relation => {\n const isCircularCascadeRemove = relation.isCascadeRemove && relation.inverseRelation && relation.inverseRelation!.isCascadeRemove;\n if (isCircularCascadeRemove)\n throw new TypeORMError(`Relation ${entityMetadata.name}#${relation.propertyName} and ${relation.inverseRelation!.entityMetadata.name}#${relation.inverseRelation!.propertyName} both has cascade remove set. ` +\n `This may lead to unexpected circular removals. Please set cascade remove only from one side of relationship.`);\n }); // todo: maybe better just deny removal from one to one relation without join column?\n\n entityMetadata.eagerRelations.forEach(relation => {\n\n });\n }\n\n /**\n * Validates dependencies of the entity metadatas.\n */\n protected validateDependencies(entityMetadatas: EntityMetadata[]) {\n\n const graph = new DepGraph();\n entityMetadatas.forEach(entityMetadata => {\n graph.addNode(entityMetadata.name);\n });\n entityMetadatas.forEach(entityMetadata => {\n entityMetadata.relationsWithJoinColumns\n .filter(relation => !relation.isNullable)\n .forEach(relation => {\n graph.addDependency(entityMetadata.name, relation.inverseEntityMetadata.name);\n });\n });\n try {\n graph.overallOrder();\n\n } catch (err) {\n throw new CircularRelationsError(err.toString().replace(\"Error: Dependency Cycle Found: \", \"\"));\n }\n }\n\n /**\n * Validates eager relations to prevent circular dependency in them.\n */\n protected validateEagerRelations(entityMetadatas: EntityMetadata[]) {\n entityMetadatas.forEach(entityMetadata => {\n entityMetadata.eagerRelations.forEach(relation => {\n if (relation.inverseRelation && relation.inverseRelation.isEager)\n throw new TypeORMError(`Circular eager relations are disallowed. ` +\n `${entityMetadata.targetName}#${relation.propertyPath} contains \"eager: true\", and its inverse side ` +\n `${relation.inverseEntityMetadata.targetName}#${relation.inverseRelation.propertyPath} contains \"eager: true\" as well.` +\n ` Remove \"eager: true\" from one side of the relation.`);\n });\n });\n }\n\n}\n"],"sourceRoot":".."}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "name": "typeorm", "private": false, "version": "0.2.42-dev.
|
|
1
|
+
{ "name": "typeorm", "private": false, "version": "0.2.42-dev.6523fcc", "description": "Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, MongoDB databases.", "license": "MIT", "readmeFilename": "README.md", "author": { "name": "Umed Khudoiberdiev", "email": "pleerock.me@gmail.com" }, "main": "./index.js", "browser": { "./browser/driver/aurora-data-api/AuroraDataApiDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/cockroachdb/CockroachDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/postgres/PostgresDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/oracle/OracleDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sap/SapDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mysql/MysqlDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sqlserver/SqlServerDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/MongoDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/MongoQueryRunner.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/entity-manager/MongoEntityManager.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/repository/MongoRepository.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sqlite/SqliteDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/better-sqlite3/BetterSqlite3Driver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/util/DirectoryExportedClassesLoader.js": "./browser/platform/BrowserDirectoryExportedClassesLoader.js", "./browser/logger/FileLogger.js": "./browser/platform/BrowserFileLoggerDummy.js", "./browser/connection/ConnectionOptionsReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/connection/options-reader/ConnectionOptionsXmlReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/connection/options-reader/ConnectionOptionsYmlReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/platform/PlatformTools.js": "./browser/platform/BrowserPlatformTools.js", "./index.js": "./browser/index.js" }, "repository": { "type": "git", "url": "https://github.com/typeorm/typeorm.git" }, "bugs": { "url": "https://github.com/typeorm/typeorm/issues" }, "tags": [ "orm", "typescript", "typescript-orm", "mysql", "mysql-orm", "postgresql", "postgresql-orm", "mariadb", "mariadb-orm", "sqlite", "sqlite-orm", "sql-server", "sql-server-orm", "oracle", "oracle-orm" ], "devDependencies": { "@types/app-root-path": "^1.2.4", "@types/chai": "^4.2.15", "@types/chai-as-promised": "^7.1.3", "@types/debug": "^4.1.5", "@types/dotenv": "^8.2.0", "@types/js-yaml": "^4.0.0", "@types/mkdirp": "^1.0.1", "@types/mocha": "^8.2.1", "@types/node": "^14.14.31", "@types/rimraf": "^3.0.0", "@types/sha.js": "^2.4.0", "@types/sinon": "^9.0.10", "@types/source-map-support": "^0.5.3", "@types/xml2js": "^0.4.8", "@types/yargs": "^17.0.2", "@typescript-eslint/eslint-plugin": "^4.15.2", "@typescript-eslint/parser": "^4.15.2", "better-sqlite3": "^7.1.2", "chai": "^4.3.0", "chai-as-promised": "^7.1.1", "class-transformer": "^0.4.0", "conventional-changelog-angular": "^5.0.12", "conventional-changelog-cli": "^2.1.1", "del": "^6.0.0", "eslint": "^7.20.0", "gulp": "^4.0.2", "gulp-eslint": "^6.0.0", "gulp-istanbul": "^1.1.3", "gulp-mocha": "^8.0.0", "gulp-rename": "^2.0.0", "gulp-replace": "^1.0.0", "gulp-shell": "^0.8.0", "gulp-sourcemaps": "^3.0.0", "gulp-typescript": "^6.0.0-alpha.1", "gulpclass": "^0.2.0", "husky": "^5.1.1", "lint-staged": "^10.5.4", "mocha": "^8.3.0", "mongodb": "^3.6.4", "mssql": "^6.3.1", "mysql": "^2.18.1", "mysql2": "^2.2.5", "oracledb": "^5.1.0", "pg": "^8.5.1", "pg-query-stream": "^4.0.0", "redis": "^3.1.1", "remap-istanbul": "^0.13.0", "rimraf": "^3.0.2", "sinon": "^9.2.4", "sinon-chai": "^3.5.0", "source-map-support": "^0.5.19", "sql.js": "^1.4.0", "sqlite3": "^5.0.2", "ts-node": "^9.1.1", "typeorm-aurora-data-api-driver": "^2.0.0", "typescript": "^4.2.2" }, "peerDependencies": { "@sap/hana-client": "*", "better-sqlite3": "*", "hdb-pool": "*", "ioredis": "*", "mongodb": "^3.6.0", "mssql": "*", "mysql2": "*", "oracledb": "*", "pg": "*", "pg-native": "*", "pg-query-stream": "*", "redis": "*", "sql.js": "*", "sqlite3": "*", "typeorm-aurora-data-api-driver": "*" }, "peerDependenciesMeta": { "@sap/hana-client": { "optional": true }, "better-sqlite3": { "optional": true }, "hdb-pool": { "optional": true }, "ioredis": { "optional": true }, "mongodb": { "optional": true }, "mssql": { "optional": true }, "mysql2": { "optional": true }, "oracledb": { "optional": true }, "pg": { "optional": true }, "pg-native": { "optional": true }, "pg-query-stream": { "optional": true }, "redis": { "optional": true }, "sql.js": { "optional": true }, "sqlite3": { "optional": true }, "typeorm-aurora-data-api-driver": { "optional": true } }, "dependencies": { "@sqltools/formatter": "^1.2.2", "app-root-path": "^3.0.0", "buffer": "^6.0.3", "chalk": "^4.1.0", "cli-highlight": "^2.1.11", "debug": "^4.3.1", "dotenv": "^8.2.0", "glob": "^7.1.6", "js-yaml": "^4.0.0", "mkdirp": "^1.0.4", "reflect-metadata": "^0.1.13", "sha.js": "^2.4.11", "tslib": "^2.1.0", "xml2js": "^0.4.23", "yargs": "^17.0.1", "zen-observable-ts": "^1.0.0" }, "lint-staged": { "*.ts": [ "eslint --fix", "git add" ] }, "scripts": { "test": "rimraf ./build && tsc && mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test", "test-fast": "mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test", "compile": "rimraf ./build && tsc", "watch": "./node_modules/.bin/tsc -w", "package": "gulp package", "pack": "gulp pack", "lint": "eslint -c ./.eslintrc.js src/**/*.ts test/**/*.ts sample/**/*.ts", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 2" }, "bin": { "typeorm": "./cli.js" }, "funding": "https://opencollective.com/typeorm", "collective": { "type": "opencollective", "url": "https://opencollective.com/typeorm", "logo": "https://opencollective.com/opencollective/logo.txt" }, "nyc": { "all": true, "cache": false, "exclude": [ "**/*.d.ts" ], "extension": [ ".ts" ], "include": [ "build/compiled/src/**", "src/**" ], "reporter": "json" } }
|
|
@@ -162,6 +162,9 @@ var OneToManySubjectBuilder = /** @class */ (function () {
|
|
|
162
162
|
else if (relation.inverseRelation.orphanedRowAction === "delete") {
|
|
163
163
|
removedRelatedEntitySubject.mustBeRemoved = true;
|
|
164
164
|
}
|
|
165
|
+
else if (relation.inverseRelation.orphanedRowAction === "soft-delete") {
|
|
166
|
+
removedRelatedEntitySubject.canBeSoftRemoved = true;
|
|
167
|
+
}
|
|
165
168
|
_this.subjects.push(removedRelatedEntitySubject);
|
|
166
169
|
});
|
|
167
170
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/persistence/subject-builder/OneToManySubjectBuilder.ts"],"names":[],"mappings":";;;AAAA,sCAAmC;AACnC,gDAA6C;AAE7C,gEAA6D;AAG7D;;;;;;;;;;GAUG;AACH;IAEI,wEAAwE;IACxE,cAAc;IACd,wEAAwE;IAExE,iCAAsB,QAAmB;QAAnB,aAAQ,GAAR,QAAQ,CAAW;IACzC,CAAC;IAED,wEAAwE;IACxE,iBAAiB;IACjB,wEAAwE;IAExE;;OAEG;IACH,uCAAK,GAAL;QAAA,iBAWC;QAVG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAA,OAA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AC,CAAC;QACpD,CAAC,CAAC,CAAC;IACX,CAAC;IAEL,8BAAC;AAAD,CA9KA,AA8KC,IAAA;AA9KY,0DAAuB","file":"OneToManySubjectBuilder.js","sourcesContent":["import {Subject} from \"../Subject\";\nimport {OrmUtils} from \"../../util/OrmUtils\";\nimport {ObjectLiteral} from \"../../common/ObjectLiteral\";\nimport {EntityMetadata} from \"../../metadata/EntityMetadata\";\nimport {RelationMetadata} from \"../../metadata/RelationMetadata\";\n\n/**\n * Builds operations needs to be executed for one-to-many relations of the given subjects.\n *\n * by example: post contains one-to-many relation with category in the property called \"categories\", e.g.\n * @OneToMany(type => Category, category => category.post) categories: Category[]\n * If user adds categories into the post and saves post we need to bind them.\n * This operation requires updation of category table since its owner of the relation and contains a join column.\n *\n * note: this class shares lot of things with OneToOneInverseSideOperationBuilder, so when you change this class\n * make sure to reflect changes there as well.\n */\nexport class OneToManySubjectBuilder {\n\n // ---------------------------------------------------------------------\n // Constructor\n // ---------------------------------------------------------------------\n\n constructor(protected subjects: Subject[]) {\n }\n\n // ---------------------------------------------------------------------\n // Public Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds all required operations.\n */\n build(): void {\n this.subjects.forEach(subject => {\n subject.metadata.oneToManyRelations.forEach(relation => {\n\n // skip relations for which persistence is disabled\n if (relation.persistenceEnabled === false)\n return;\n\n this.buildForSubjectRelation(subject, relation);\n });\n });\n }\n\n // ---------------------------------------------------------------------\n // Protected Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds operations for a given subject and relation.\n *\n * by example: subject is \"post\" entity we are saving here and relation is \"categories\" inside it here.\n */\n protected buildForSubjectRelation(subject: Subject, relation: RelationMetadata) {\n // prepare objects (relation id maps) for the database entity\n // by example: since subject is a post, we are expecting to get all post's categories saved in the database here,\n // particularly their relation ids, e.g. category ids stored in the database\n\n\t\t// in most cases relatedEntityDatabaseValues will contain only the entity key properties.\n\t\t// this is because subject.databaseEntity contains relations with loaded relation ids only.\n\t\t// however if the entity uses the afterLoad hook to calculate any properties, the fetched \"key object\" might include ADDITIONAL properties.\n\t\t// to handle such situations, we pass the data to relation.inverseEntityMetadata.getEntityIdMap to extract the key without any other properties.\n\n let relatedEntityDatabaseRelationIds: ObjectLiteral[] = [];\n if (subject.databaseEntity) { // related entities in the database can exist only if this entity (post) is saved\n const relatedEntityDatabaseRelation: ObjectLiteral[] | undefined = relation.getEntityValue(subject.databaseEntity)\n if (relatedEntityDatabaseRelation) {\n relatedEntityDatabaseRelationIds = relatedEntityDatabaseRelation.map((entity) => relation.inverseEntityMetadata.getEntityIdMap(entity)!);\n }\n }\n\n // get related entities of persisted entity\n // by example: get categories from the passed to persist post entity\n let relatedEntities: ObjectLiteral[] = relation.getEntityValue(subject.entity!);\n if (relatedEntities === null) // we treat relations set to null as removed, so we don't skip it\n relatedEntities = [] as ObjectLiteral[];\n if (relatedEntities === undefined) // if relation is undefined then nothing to update\n return;\n\n // extract only relation ids from the related entities, since we only need them for comparison\n // by example: extract from categories only relation ids (category id, or let's say category title, depend on join column options)\n const relatedPersistedEntityRelationIds: ObjectLiteral[] = [];\n relatedEntities.forEach(relatedEntity => { // by example: relatedEntity is a category here\n let relationIdMap = relation.inverseEntityMetadata!.getEntityIdMap(relatedEntity); // by example: relationIdMap is category.id map here, e.g. { id: ... }\n\n // try to find a subject of this related entity, maybe it was loaded or was marked for persistence\n let relatedEntitySubject = this.subjects.find(subject => {\n return subject.entity === relatedEntity;\n });\n\n // if subject with entity was found take subject identifier as relation id map since it may contain extra properties resolved\n if (relatedEntitySubject)\n relationIdMap = relatedEntitySubject.identifier;\n\n // if relationIdMap is undefined then it means user binds object which is not saved in the database yet\n // by example: if post contains categories which does not have ids yet (because they are new)\n // it means they are always newly inserted and relation update operation always must be created for them\n // it does not make sense to perform difference operation for them for both add and remove actions\n if (!relationIdMap) {\n\n // we decided to remove this error because it brings complications when saving object with non-saved entities\n // if (!relatedEntitySubject)\n // throw new TypeORMError(`One-to-many relation \"${relation.entityMetadata.name}.${relation.propertyPath}\" contains ` +\n // `entities which do not exist in the database yet, thus they cannot be bind in the database. ` +\n // `Please setup cascade insertion or save entities before binding it.`);\n if (!relatedEntitySubject)\n return;\n\n // okay, so related subject exist and its marked for insertion, then add a new change map\n // by example: this will tell category to insert into its post relation our post we are working with\n // relatedEntitySubject is newly inserted CategorySubject\n // relation.inverseRelation is ManyToOne relation inside Category\n // subject is Post needs to be inserted into Category\n relatedEntitySubject.changeMaps.push({\n relation: relation.inverseRelation!,\n value: subject\n });\n\n return;\n }\n\n // check if this binding really exist in the database\n // by example: find our category if its already bind in the database\n const relationIdInDatabaseSubjectRelation = relatedEntityDatabaseRelationIds.find(relatedDatabaseEntityRelationId => {\n return OrmUtils.compareIds(relationIdMap, relatedDatabaseEntityRelationId);\n });\n\n // if relationIdMap DOES NOT exist in the subject's relation in the database it means its a new relation and we need to \"bind\" them\n // by example: this will tell category to insert into its post relation our post we are working with\n // relatedEntitySubject is newly inserted CategorySubject\n // relation.inverseRelation is ManyToOne relation inside Category\n // subject is Post needs to be inserted into Category\n if (!relationIdInDatabaseSubjectRelation) {\n\n // if there is no relatedEntitySubject then it means \"category\" wasn't persisted,\n // but since we are going to update \"category\" table (since its an owning side of relation with join column)\n // we create a new subject here:\n if (!relatedEntitySubject) {\n relatedEntitySubject = new Subject({\n metadata: relation.inverseEntityMetadata,\n parentSubject: subject,\n canBeUpdated: true,\n identifier: relationIdMap\n });\n this.subjects.push(relatedEntitySubject);\n }\n\n relatedEntitySubject.changeMaps.push({\n relation: relation.inverseRelation!,\n value: subject\n });\n }\n\n // if related entity has relation id then we add it to the list of relation ids\n // this list will be used later to compare with database relation ids to find a difference\n // what exist in this array and does not exist in the database are newly inserted relations\n // what does not exist in this array, but exist in the database are removed relations\n // removed relations are set to null from inverse side of relation\n relatedPersistedEntityRelationIds.push(relationIdMap);\n });\n\n // find what related entities were added and what were removed based on difference between what we save and what database has\n EntityMetadata\n .difference(relatedEntityDatabaseRelationIds, relatedPersistedEntityRelationIds)\n .forEach(removedRelatedEntityRelationId => { // by example: removedRelatedEntityRelationId is category that was bind in the database before, but now its unbind\n\n // todo: probably we can improve this in the future by finding entity with column those values,\n // todo: maybe it was already in persistence process. This is possible due to unique requirements of join columns\n // we create a new subject which operations will be executed in subject operation executor\n const removedRelatedEntitySubject = new Subject({\n metadata: relation.inverseEntityMetadata,\n parentSubject: subject,\n identifier: removedRelatedEntityRelationId,\n });\n\n if (!relation.inverseRelation || relation.inverseRelation.orphanedRowAction === \"nullify\") {\n removedRelatedEntitySubject.canBeUpdated = true;\n removedRelatedEntitySubject.changeMaps = [{\n relation: relation.inverseRelation!,\n value: null\n }];\n } else if (relation.inverseRelation.orphanedRowAction === \"delete\") {\n removedRelatedEntitySubject.mustBeRemoved = true;\n }\n\n this.subjects.push(removedRelatedEntitySubject);\n });\n }\n\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../../src/persistence/subject-builder/OneToManySubjectBuilder.ts"],"names":[],"mappings":";;;AAAA,sCAAmC;AACnC,gDAA6C;AAE7C,gEAA6D;AAG7D;;;;;;;;;;GAUG;AACH;IAEI,wEAAwE;IACxE,cAAc;IACd,wEAAwE;IAExE,iCAAsB,QAAmB;QAAnB,aAAQ,GAAR,QAAQ,CAAW;IACzC,CAAC;IAED,wEAAwE;IACxE,iBAAiB;IACjB,wEAAwE;IAExE;;OAEG;IACH,uCAAK,GAAL;QAAA,iBAWC;QAVG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAA,OAAO;YACzB,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,UAAA,QAAQ;gBAEhD,mDAAmD;gBACnD,IAAI,QAAQ,CAAC,kBAAkB,KAAK,KAAK;oBACrC,OAAO;gBAEX,KAAI,CAAC,uBAAuB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YACpD,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAED,wEAAwE;IACxE,oBAAoB;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import {ObjectLiteral} from \"../../common/ObjectLiteral\";\nimport {EntityMetadata} from \"../../metadata/EntityMetadata\";\nimport {RelationMetadata} from \"../../metadata/RelationMetadata\";\n\n/**\n * Builds operations needs to be executed for one-to-many relations of the given subjects.\n *\n * by example: post contains one-to-many relation with category in the property called \"categories\", e.g.\n * @OneToMany(type => Category, category => category.post) categories: Category[]\n * If user adds categories into the post and saves post we need to bind them.\n * This operation requires updation of category table since its owner of the relation and contains a join column.\n *\n * note: this class shares lot of things with OneToOneInverseSideOperationBuilder, so when you change this class\n * make sure to reflect changes there as well.\n */\nexport class OneToManySubjectBuilder {\n\n // ---------------------------------------------------------------------\n // Constructor\n // ---------------------------------------------------------------------\n\n constructor(protected subjects: Subject[]) {\n }\n\n // ---------------------------------------------------------------------\n // Public Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds all required operations.\n */\n build(): void {\n this.subjects.forEach(subject => {\n subject.metadata.oneToManyRelations.forEach(relation => {\n\n // skip relations for which persistence is disabled\n if (relation.persistenceEnabled === false)\n return;\n\n this.buildForSubjectRelation(subject, relation);\n });\n });\n }\n\n // ---------------------------------------------------------------------\n // Protected Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds operations for a given subject and relation.\n *\n * by example: subject is \"post\" entity we are saving here and relation is \"categories\" inside it here.\n */\n protected buildForSubjectRelation(subject: Subject, relation: RelationMetadata) {\n // prepare objects (relation id maps) for the database entity\n // by example: since subject is a post, we are expecting to get all post's categories saved in the database here,\n // particularly their relation ids, e.g. category ids stored in the database\n\n\t\t// in most cases relatedEntityDatabaseValues will contain only the entity key properties.\n\t\t// this is because subject.databaseEntity contains relations with loaded relation ids only.\n\t\t// however if the entity uses the afterLoad hook to calculate any properties, the fetched \"key object\" might include ADDITIONAL properties.\n\t\t// to handle such situations, we pass the data to relation.inverseEntityMetadata.getEntityIdMap to extract the key without any other properties.\n\n let relatedEntityDatabaseRelationIds: ObjectLiteral[] = [];\n if (subject.databaseEntity) { // related entities in the database can exist only if this entity (post) is saved\n const relatedEntityDatabaseRelation: ObjectLiteral[] | undefined = relation.getEntityValue(subject.databaseEntity)\n if (relatedEntityDatabaseRelation) {\n relatedEntityDatabaseRelationIds = relatedEntityDatabaseRelation.map((entity) => relation.inverseEntityMetadata.getEntityIdMap(entity)!);\n }\n }\n\n // get related entities of persisted entity\n // by example: get categories from the passed to persist post entity\n let relatedEntities: ObjectLiteral[] = relation.getEntityValue(subject.entity!);\n if (relatedEntities === null) // we treat relations set to null as removed, so we don't skip it\n relatedEntities = [] as ObjectLiteral[];\n if (relatedEntities === undefined) // if relation is undefined then nothing to update\n return;\n\n // extract only relation ids from the related entities, since we only need them for comparison\n // by example: extract from categories only relation ids (category id, or let's say category title, depend on join column options)\n const relatedPersistedEntityRelationIds: ObjectLiteral[] = [];\n relatedEntities.forEach(relatedEntity => { // by example: relatedEntity is a category here\n let relationIdMap = relation.inverseEntityMetadata!.getEntityIdMap(relatedEntity); // by example: relationIdMap is category.id map here, e.g. { id: ... }\n\n // try to find a subject of this related entity, maybe it was loaded or was marked for persistence\n let relatedEntitySubject = this.subjects.find(subject => {\n return subject.entity === relatedEntity;\n });\n\n // if subject with entity was found take subject identifier as relation id map since it may contain extra properties resolved\n if (relatedEntitySubject)\n relationIdMap = relatedEntitySubject.identifier;\n\n // if relationIdMap is undefined then it means user binds object which is not saved in the database yet\n // by example: if post contains categories which does not have ids yet (because they are new)\n // it means they are always newly inserted and relation update operation always must be created for them\n // it does not make sense to perform difference operation for them for both add and remove actions\n if (!relationIdMap) {\n\n // we decided to remove this error because it brings complications when saving object with non-saved entities\n // if (!relatedEntitySubject)\n // throw new TypeORMError(`One-to-many relation \"${relation.entityMetadata.name}.${relation.propertyPath}\" contains ` +\n // `entities which do not exist in the database yet, thus they cannot be bind in the database. ` +\n // `Please setup cascade insertion or save entities before binding it.`);\n if (!relatedEntitySubject)\n return;\n\n // okay, so related subject exist and its marked for insertion, then add a new change map\n // by example: this will tell category to insert into its post relation our post we are working with\n // relatedEntitySubject is newly inserted CategorySubject\n // relation.inverseRelation is ManyToOne relation inside Category\n // subject is Post needs to be inserted into Category\n relatedEntitySubject.changeMaps.push({\n relation: relation.inverseRelation!,\n value: subject\n });\n\n return;\n }\n\n // check if this binding really exist in the database\n // by example: find our category if its already bind in the database\n const relationIdInDatabaseSubjectRelation = relatedEntityDatabaseRelationIds.find(relatedDatabaseEntityRelationId => {\n return OrmUtils.compareIds(relationIdMap, relatedDatabaseEntityRelationId);\n });\n\n // if relationIdMap DOES NOT exist in the subject's relation in the database it means its a new relation and we need to \"bind\" them\n // by example: this will tell category to insert into its post relation our post we are working with\n // relatedEntitySubject is newly inserted CategorySubject\n // relation.inverseRelation is ManyToOne relation inside Category\n // subject is Post needs to be inserted into Category\n if (!relationIdInDatabaseSubjectRelation) {\n\n // if there is no relatedEntitySubject then it means \"category\" wasn't persisted,\n // but since we are going to update \"category\" table (since its an owning side of relation with join column)\n // we create a new subject here:\n if (!relatedEntitySubject) {\n relatedEntitySubject = new Subject({\n metadata: relation.inverseEntityMetadata,\n parentSubject: subject,\n canBeUpdated: true,\n identifier: relationIdMap\n });\n this.subjects.push(relatedEntitySubject);\n }\n\n relatedEntitySubject.changeMaps.push({\n relation: relation.inverseRelation!,\n value: subject\n });\n }\n\n // if related entity has relation id then we add it to the list of relation ids\n // this list will be used later to compare with database relation ids to find a difference\n // what exist in this array and does not exist in the database are newly inserted relations\n // what does not exist in this array, but exist in the database are removed relations\n // removed relations are set to null from inverse side of relation\n relatedPersistedEntityRelationIds.push(relationIdMap);\n });\n\n // find what related entities were added and what were removed based on difference between what we save and what database has\n EntityMetadata\n .difference(relatedEntityDatabaseRelationIds, relatedPersistedEntityRelationIds)\n .forEach(removedRelatedEntityRelationId => { // by example: removedRelatedEntityRelationId is category that was bind in the database before, but now its unbind\n\n // todo: probably we can improve this in the future by finding entity with column those values,\n // todo: maybe it was already in persistence process. This is possible due to unique requirements of join columns\n // we create a new subject which operations will be executed in subject operation executor\n const removedRelatedEntitySubject = new Subject({\n metadata: relation.inverseEntityMetadata,\n parentSubject: subject,\n identifier: removedRelatedEntityRelationId,\n });\n\n if (!relation.inverseRelation || relation.inverseRelation.orphanedRowAction === \"nullify\") {\n removedRelatedEntitySubject.canBeUpdated = true;\n removedRelatedEntitySubject.changeMaps = [{\n relation: relation.inverseRelation!,\n value: null\n }];\n } else if (relation.inverseRelation.orphanedRowAction === \"delete\") {\n removedRelatedEntitySubject.mustBeRemoved = true;\n }\n else if (relation.inverseRelation.orphanedRowAction === \"soft-delete\") {\n removedRelatedEntitySubject.canBeSoftRemoved = true;\n }\n \n this.subjects.push(removedRelatedEntitySubject);\n });\n }\n\n}\n"],"sourceRoot":"../.."}
|