mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
renamed subject classes
This commit is contained in:
parent
eb6ed18dec
commit
f0c57dbd45
@ -22,7 +22,7 @@ export interface RelationUpdate {
|
||||
|
||||
/**
|
||||
*/
|
||||
export class PersistenceSubject { // todo: move entity with id creation into metadata? // todo: rename to EntityWithMetadata ?
|
||||
export class Subject { // todo: move entity with id creation into metadata? // todo: rename to EntityWithMetadata ?
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Properties
|
||||
@ -1,7 +1,7 @@
|
||||
import {EntityMetadata} from "../metadata/EntityMetadata";
|
||||
import {ObjectLiteral} from "../common/ObjectLiteral";
|
||||
import {Connection} from "../connection/Connection";
|
||||
import {PersistenceSubject} from "./PersistenceSubject";
|
||||
import {Subject} from "./Subject";
|
||||
|
||||
/**
|
||||
* To be able to execute persistence operations we need to load all entities from the database we need.
|
||||
@ -56,7 +56,7 @@ import {PersistenceSubject} from "./PersistenceSubject";
|
||||
* Remove operation can lead to:
|
||||
* - remove operation
|
||||
*/
|
||||
export class PersistenceSubjectBuilder<Entity extends ObjectLiteral> {
|
||||
export class SubjectBuilder<Entity extends ObjectLiteral> {
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Protected properties
|
||||
@ -67,7 +67,7 @@ export class PersistenceSubjectBuilder<Entity extends ObjectLiteral> {
|
||||
* One of solution can be clone this object and reset all marked states for this persistence.
|
||||
* Or from reused just extract databaseEntities from their subjects? (looks better)
|
||||
*/
|
||||
operateSubjects: PersistenceSubject[] = [];
|
||||
operateSubjects: Subject[] = [];
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructor
|
||||
@ -83,7 +83,7 @@ export class PersistenceSubjectBuilder<Entity extends ObjectLiteral> {
|
||||
async persist(entity: Entity, metadata: EntityMetadata): Promise<void> {
|
||||
|
||||
// create subject for currently persisted entity and mark that it can be inserted and updated
|
||||
const mainPersistedSubject = new PersistenceSubject(metadata, entity);
|
||||
const mainPersistedSubject = new Subject(metadata, entity);
|
||||
mainPersistedSubject.canBeInserted = true;
|
||||
mainPersistedSubject.canBeUpdated = true;
|
||||
this.operateSubjects.push(mainPersistedSubject);
|
||||
@ -111,7 +111,7 @@ export class PersistenceSubjectBuilder<Entity extends ObjectLiteral> {
|
||||
async remove(entity: Entity, metadata: EntityMetadata): Promise<void> {
|
||||
|
||||
// create subject for currently removed entity and mark that it must be removed
|
||||
const mainRemovedSubject = new PersistenceSubject(metadata, entity);
|
||||
const mainRemovedSubject = new Subject(metadata, entity);
|
||||
mainRemovedSubject.mustBeRemoved = true;
|
||||
this.operateSubjects.push(mainRemovedSubject);
|
||||
|
||||
@ -149,7 +149,7 @@ export class PersistenceSubjectBuilder<Entity extends ObjectLiteral> {
|
||||
* That's why we first need to load all changed entities, then extract ids of the removed entities from them,
|
||||
* and only then load removed entities by extracted ids.
|
||||
*/
|
||||
protected buildCascadeUpdateAndInsertOperateSubjects(subject: PersistenceSubject): void {
|
||||
protected buildCascadeUpdateAndInsertOperateSubjects(subject: Subject): void {
|
||||
subject.metadata
|
||||
.extractRelationValuesFromEntity(subject.entity, subject.metadata.relations)
|
||||
.filter(([relation, value, valueMetadata]) => {
|
||||
@ -171,7 +171,7 @@ export class PersistenceSubjectBuilder<Entity extends ObjectLiteral> {
|
||||
|
||||
// mark subject with what we can do with it
|
||||
// and add to the array of subjects to load only if there is no same entity there already
|
||||
const valueSubject = new PersistenceSubject(valueMetadata, value);
|
||||
const valueSubject = new Subject(valueMetadata, value);
|
||||
valueSubject.canBeInserted = relation.isCascadeInsert === true;
|
||||
valueSubject.canBeUpdated = relation.isCascadeUpdate === true;
|
||||
this.operateSubjects.push(valueSubject);
|
||||
@ -184,7 +184,7 @@ export class PersistenceSubjectBuilder<Entity extends ObjectLiteral> {
|
||||
/**
|
||||
* Builds and pushes to array of operate entities all entities that must be removed.
|
||||
*/
|
||||
protected buildCascadeRemoveOperateSubjects(subject: PersistenceSubject): void {
|
||||
protected buildCascadeRemoveOperateSubjects(subject: Subject): void {
|
||||
subject.metadata
|
||||
.extractRelationValuesFromEntity(subject.entity, subject.metadata.relations)
|
||||
.filter(([relation, value, valueMetadata]) => {
|
||||
@ -202,7 +202,7 @@ export class PersistenceSubjectBuilder<Entity extends ObjectLiteral> {
|
||||
}
|
||||
|
||||
// add to the array of subjects to load only if there is no same entity there already
|
||||
const valueSubject = new PersistenceSubject(valueMetadata, value);
|
||||
const valueSubject = new Subject(valueMetadata, value);
|
||||
valueSubject.mustBeRemoved = true;
|
||||
this.operateSubjects.push(valueSubject);
|
||||
|
||||
@ -266,7 +266,7 @@ export class PersistenceSubjectBuilder<Entity extends ObjectLiteral> {
|
||||
* BIG NOTE: objects are being removed by cascades not only when relation is removed, but also when
|
||||
* relation is replaced (e.g. changed with different object).
|
||||
*/
|
||||
protected async buildCascadeRemovedAndRelationUpdateOperateSubjects(subject: PersistenceSubject): Promise<void> {
|
||||
protected async buildCascadeRemovedAndRelationUpdateOperateSubjects(subject: Subject): Promise<void> {
|
||||
|
||||
// note: we can't use extractRelationValuesFromEntity here because it does not handle empty arrays
|
||||
const promises = subject.metadata.relations.map(async relation => {
|
||||
@ -352,7 +352,7 @@ export class PersistenceSubjectBuilder<Entity extends ObjectLiteral> {
|
||||
.getSingleResult();
|
||||
|
||||
if (databaseEntity) {
|
||||
alreadyLoadedRelatedDatabaseSubject = new PersistenceSubject(valueMetadata, undefined, databaseEntity);
|
||||
alreadyLoadedRelatedDatabaseSubject = new Subject(valueMetadata, undefined, databaseEntity);
|
||||
this.operateSubjects.push(alreadyLoadedRelatedDatabaseSubject);
|
||||
}
|
||||
}
|
||||
@ -431,7 +431,7 @@ export class PersistenceSubjectBuilder<Entity extends ObjectLiteral> {
|
||||
// add only if database entity exist - because in the case of inverse side of the one-to-one relation
|
||||
// we cannot check if it was removed or not until we query the database
|
||||
// and it can be a situation that relation wasn't exist at all. This is particular that case
|
||||
alreadyLoadedRelatedDatabaseSubject = new PersistenceSubject(valueMetadata, undefined, databaseEntity);
|
||||
alreadyLoadedRelatedDatabaseSubject = new Subject(valueMetadata, undefined, databaseEntity);
|
||||
this.operateSubjects.push(alreadyLoadedRelatedDatabaseSubject);
|
||||
}
|
||||
|
||||
@ -555,7 +555,7 @@ export class PersistenceSubjectBuilder<Entity extends ObjectLiteral> {
|
||||
subjectInLoadMap.databaseEntity = databaseEntity;
|
||||
|
||||
} else if (!subjectInLoadMap) {
|
||||
const subject = new PersistenceSubject(valueMetadata, undefined, databaseEntity);
|
||||
const subject = new Subject(valueMetadata, undefined, databaseEntity);
|
||||
this.operateSubjects.push(subject);
|
||||
}
|
||||
});
|
||||
@ -582,7 +582,7 @@ export class PersistenceSubjectBuilder<Entity extends ObjectLiteral> {
|
||||
.getRepository<ObjectLiteral>(valueMetadata.target)
|
||||
.findOneById(valueMetadata.getEntityIdMixedMap(persistValue), { alias: qbAlias, enabledOptions: ["RELATION_ID_VALUES"] }); // todo: check if databaseEntity is defined?
|
||||
|
||||
loadedSubject = new PersistenceSubject(valueMetadata, undefined, databaseEntity); // todo: what if entity like object exist in the loaded subjects but without databaseEntity?
|
||||
loadedSubject = new Subject(valueMetadata, undefined, databaseEntity); // todo: what if entity like object exist in the loaded subjects but without databaseEntity?
|
||||
this.operateSubjects.push(loadedSubject);
|
||||
}
|
||||
loadedSubject.relationUpdates.push({ relation: relation.inverseRelation, value: subject.entity });
|
||||
@ -736,7 +736,7 @@ export class PersistenceSubjectBuilder<Entity extends ObjectLiteral> {
|
||||
* Finds subject where entity like given subject's entity.
|
||||
* Comparision made by entity id.
|
||||
*/
|
||||
protected findByEntityLike(entityTarget: Function|string, entity: ObjectLiteral): PersistenceSubject|undefined {
|
||||
protected findByEntityLike(entityTarget: Function|string, entity: ObjectLiteral): Subject|undefined {
|
||||
return this.operateSubjects.find(subject => {
|
||||
return subject.entityTarget === entityTarget && subject.metadata.compareEntities(subject.entity, entity);
|
||||
});
|
||||
@ -746,7 +746,7 @@ export class PersistenceSubjectBuilder<Entity extends ObjectLiteral> {
|
||||
* Finds subject where entity like given subject's database entity.
|
||||
* Comparision made by entity id.
|
||||
*/
|
||||
protected findByDatabaseEntityLike(entityTarget: Function|string, entity: ObjectLiteral): PersistenceSubject|undefined {
|
||||
protected findByDatabaseEntityLike(entityTarget: Function|string, entity: ObjectLiteral): Subject|undefined {
|
||||
return this.operateSubjects.find(subject => {
|
||||
return subject.entityTarget === entityTarget && subject.metadata.compareEntities(subject.databaseEntity, entity);
|
||||
});
|
||||
@ -755,7 +755,7 @@ export class PersistenceSubjectBuilder<Entity extends ObjectLiteral> {
|
||||
/**
|
||||
* Groups given Subject objects into groups separated by entity targets.
|
||||
*/
|
||||
protected groupByEntityTargets(): { target: Function|string, subjects: PersistenceSubject[] }[] {
|
||||
protected groupByEntityTargets(): { target: Function|string, subjects: Subject[] }[] {
|
||||
return this.operateSubjects.reduce((groups, operatedEntity) => {
|
||||
let group = groups.find(group => group.target === operatedEntity.entityTarget);
|
||||
if (!group) {
|
||||
@ -764,7 +764,7 @@ export class PersistenceSubjectBuilder<Entity extends ObjectLiteral> {
|
||||
}
|
||||
group.subjects.push(operatedEntity);
|
||||
return groups;
|
||||
}, [] as { target: Function|string, subjects: PersistenceSubject[] }[]);
|
||||
}, [] as { target: Function|string, subjects: Subject[] }[]);
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,13 +2,13 @@ import {ObjectLiteral} from "../common/ObjectLiteral";
|
||||
import {EntityMetadata} from "../metadata/EntityMetadata";
|
||||
import {Connection} from "../connection/Connection";
|
||||
import {QueryRunner} from "../query-runner/QueryRunner";
|
||||
import {PersistenceSubject, JunctionInsert, JunctionRemove} from "./PersistenceSubject";
|
||||
import {Subject, JunctionInsert, JunctionRemove} from "./Subject";
|
||||
import {OrmUtils} from "../util/OrmUtils";
|
||||
|
||||
/**
|
||||
* Executes PersistOperation in the given connection.
|
||||
*/
|
||||
export class PersistenceSubjectOperationExecutor {
|
||||
export class SubjectOperationExecutor {
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructor
|
||||
@ -24,7 +24,7 @@ export class PersistenceSubjectOperationExecutor {
|
||||
/**
|
||||
* Executes given persist operation.
|
||||
*/
|
||||
async execute(subjects: PersistenceSubject[]) {
|
||||
async execute(subjects: Subject[]) {
|
||||
let isTransactionStartedByItself = false;
|
||||
|
||||
const insertSubjects = subjects.filter(subject => subject.mustBeInserted);
|
||||
@ -109,7 +109,7 @@ export class PersistenceSubjectOperationExecutor {
|
||||
* Insert process of the entities from the second group which can have only non nullable relations is a single-step process:
|
||||
* - we simply insert all entities and get into attention all its dependencies which were inserted in the first group
|
||||
*/
|
||||
private async executeInsertOperations(insertSubjects: PersistenceSubject[]): Promise<void> {
|
||||
private async executeInsertOperations(insertSubjects: Subject[]): Promise<void> {
|
||||
|
||||
// separate insert entities into groups:
|
||||
|
||||
@ -235,7 +235,7 @@ export class PersistenceSubjectOperationExecutor {
|
||||
* If entity has an generated column, then after saving new generated value will be stored to the InsertOperation.
|
||||
* If entity uses class-table-inheritance, then multiple inserts may by performed to save all entities.
|
||||
*/
|
||||
private async insert(subject: PersistenceSubject, alreadyInsertedSubjects: PersistenceSubject[]): Promise<any> {
|
||||
private async insert(subject: Subject, alreadyInsertedSubjects: Subject[]): Promise<any> {
|
||||
|
||||
const parentEntityMetadata = subject.metadata.parentEntityMetadata;
|
||||
const metadata = subject.metadata;
|
||||
@ -259,7 +259,7 @@ export class PersistenceSubjectOperationExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private collectColumnsAndValues(metadata: EntityMetadata, entity: any, date: Date, parentIdColumnValue: any, discriminatorValue: any, alreadyInsertedSubjects: PersistenceSubject[]): ObjectLiteral {
|
||||
private collectColumnsAndValues(metadata: EntityMetadata, entity: any, date: Date, parentIdColumnValue: any, discriminatorValue: any, alreadyInsertedSubjects: Subject[]): ObjectLiteral {
|
||||
|
||||
// extract all columns
|
||||
const columns = metadata.columns.filter(column => {
|
||||
@ -362,7 +362,7 @@ export class PersistenceSubjectOperationExecutor {
|
||||
/**
|
||||
* Executes insert operations for closure tables.
|
||||
*/
|
||||
private executeInsertClosureTableOperations(insertSubjects: PersistenceSubject[]/*, updatesByRelations: Subject[]*/) { // todo: what to do with updatesByRelations
|
||||
private executeInsertClosureTableOperations(insertSubjects: Subject[]/*, updatesByRelations: Subject[]*/) { // todo: what to do with updatesByRelations
|
||||
const promises = insertSubjects
|
||||
.filter(subject => subject.metadata.table.isClosure)
|
||||
.map(async subject => {
|
||||
@ -373,7 +373,7 @@ export class PersistenceSubjectOperationExecutor {
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
private async insertClosureTableValues(subject: PersistenceSubject, insertedSubjects: PersistenceSubject[]): Promise<void> {
|
||||
private async insertClosureTableValues(subject: Subject, insertedSubjects: Subject[]): Promise<void> {
|
||||
// todo: since closure tables do not support compose primary keys - throw an exception?
|
||||
// todo: what if parent entity or parentEntityId is empty?!
|
||||
const tableName = subject.metadata.closureJunctionTable.table.name;
|
||||
@ -407,11 +407,11 @@ export class PersistenceSubjectOperationExecutor {
|
||||
/**
|
||||
* Executes update operations.
|
||||
*/
|
||||
private async executeUpdateOperations(updateSubjects: PersistenceSubject[]): Promise<void> {
|
||||
private async executeUpdateOperations(updateSubjects: Subject[]): Promise<void> {
|
||||
await Promise.all(updateSubjects.map(subject => this.update(subject)));
|
||||
}
|
||||
|
||||
private async update(subject: PersistenceSubject): Promise<void> {
|
||||
private async update(subject: Subject): Promise<void> {
|
||||
const entity = subject.entity;
|
||||
|
||||
// we group by table name, because metadata can have different table names
|
||||
@ -500,11 +500,11 @@ export class PersistenceSubjectOperationExecutor {
|
||||
// Private Methods: Update only relations
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
private executeUpdateRelations(subjects: PersistenceSubject[]) {
|
||||
private executeUpdateRelations(subjects: Subject[]) {
|
||||
return Promise.all(subjects.map(subject => this.updateRelations(subject)));
|
||||
}
|
||||
|
||||
private async updateRelations(subject: PersistenceSubject) {
|
||||
private async updateRelations(subject: Subject) {
|
||||
const values: ObjectLiteral = {};
|
||||
subject.relationUpdates.forEach(setRelation => {
|
||||
const value = setRelation.value ? setRelation.value[setRelation.relation.joinColumn.referencedColumn.propertyName] : null;
|
||||
@ -528,11 +528,11 @@ export class PersistenceSubjectOperationExecutor {
|
||||
/**
|
||||
* Executes remove operations.
|
||||
*/
|
||||
private async executeRemoveOperations(removeSubjects: PersistenceSubject[]): Promise<void> {
|
||||
private async executeRemoveOperations(removeSubjects: Subject[]): Promise<void> {
|
||||
await Promise.all(removeSubjects.map(subject => this.remove(subject)));
|
||||
}
|
||||
|
||||
private async remove(subject: PersistenceSubject): Promise<void> {
|
||||
private async remove(subject: Subject): Promise<void> {
|
||||
if (subject.metadata.parentEntityMetadata) {
|
||||
const parentConditions: ObjectLiteral = {};
|
||||
subject.metadata.parentPrimaryColumns.forEach(column => {
|
||||
@ -557,7 +557,7 @@ export class PersistenceSubjectOperationExecutor {
|
||||
/**
|
||||
* Executes insert junction operations.
|
||||
*/
|
||||
private async executeInsertJunctionsOperations(subjects: PersistenceSubject[], insertSubjects: PersistenceSubject[]): Promise<void> {
|
||||
private async executeInsertJunctionsOperations(subjects: Subject[], insertSubjects: Subject[]): Promise<void> {
|
||||
const promises: Promise<any>[] = [];
|
||||
subjects.forEach(subject => {
|
||||
subject.junctionInserts.forEach(junctionInsert => {
|
||||
@ -571,7 +571,7 @@ export class PersistenceSubjectOperationExecutor {
|
||||
/**
|
||||
* Executes insert junction operation.
|
||||
*/
|
||||
private async insertJunctions(subject: PersistenceSubject, junctionInsert: JunctionInsert, insertSubjects: PersistenceSubject[]): Promise<void> {
|
||||
private async insertJunctions(subject: Subject, junctionInsert: JunctionInsert, insertSubjects: Subject[]): Promise<void> {
|
||||
// I think here we can only support to work only with single primary key entities
|
||||
|
||||
const relation = junctionInsert.relation;
|
||||
@ -633,7 +633,7 @@ export class PersistenceSubjectOperationExecutor {
|
||||
/**
|
||||
* Executes remove junction operations.
|
||||
*/
|
||||
private async executeRemoveJunctionsOperations(subjects: PersistenceSubject[]): Promise<void> {
|
||||
private async executeRemoveJunctionsOperations(subjects: Subject[]): Promise<void> {
|
||||
const promises: Promise<any>[] = [];
|
||||
subjects.forEach(subject => {
|
||||
subject.junctionRemoves.forEach(junctionRemove => {
|
||||
@ -647,7 +647,7 @@ export class PersistenceSubjectOperationExecutor {
|
||||
/**
|
||||
* Executes remove junction operation.
|
||||
*/
|
||||
private async removeJunctions(subject: PersistenceSubject, junctionRemove: JunctionRemove) {
|
||||
private async removeJunctions(subject: Subject, junctionRemove: JunctionRemove) {
|
||||
const junctionMetadata = junctionRemove.relation.junctionEntityMetadata;
|
||||
const ownId = junctionRemove.relation.getOwnEntityRelationId(subject.entity || subject.databaseEntity);
|
||||
const ownColumn = junctionRemove.relation.isOwning ? junctionMetadata.columns[0] : junctionMetadata.columns[1];
|
||||
@ -666,7 +666,7 @@ export class PersistenceSubjectOperationExecutor {
|
||||
/**
|
||||
* Updates all special columns of the saving entities (create date, update date, versioning).
|
||||
*/
|
||||
private updateSpecialColumnsInPersistedEntities(insertSubjects: PersistenceSubject[], updateSubjects: PersistenceSubject[], removeSubjects: PersistenceSubject[]) {
|
||||
private updateSpecialColumnsInPersistedEntities(insertSubjects: Subject[], updateSubjects: Subject[], removeSubjects: Subject[]) {
|
||||
|
||||
// update entity columns that gets updated on each entity insert
|
||||
insertSubjects.forEach(subject => {
|
||||
@ -7,8 +7,8 @@ import {FindOptions} from "../find-options/FindOptions";
|
||||
import {FindOptionsUtils} from "../find-options/FindOptionsUtils";
|
||||
import {ObjectLiteral} from "../common/ObjectLiteral";
|
||||
import {QueryRunnerProvider} from "../query-runner/QueryRunnerProvider";
|
||||
import {PersistenceSubjectOperationExecutor} from "../persistence/PersistenceSubjectOperationExecutor";
|
||||
import {PersistenceSubjectBuilder} from "../persistence/PersistenceSubjectBuilder";
|
||||
import {SubjectOperationExecutor} from "../persistence/SubjectOperationExecutor";
|
||||
import {SubjectBuilder} from "../persistence/SubjectBuilder";
|
||||
|
||||
/**
|
||||
* Repository is supposed to work with your entity objects. Find entities, insert, update, delete, etc.
|
||||
@ -135,10 +135,10 @@ export class Repository<Entity extends ObjectLiteral> {
|
||||
const queryRunner = await queryRunnerProvider.provide();
|
||||
try {
|
||||
|
||||
const databaseEntityLoader = new PersistenceSubjectBuilder(this.connection);
|
||||
const databaseEntityLoader = new SubjectBuilder(this.connection);
|
||||
await databaseEntityLoader.persist(entityOrEntities, this.metadata);
|
||||
|
||||
const executor = new PersistenceSubjectOperationExecutor(this.connection, queryRunner);
|
||||
const executor = new SubjectOperationExecutor(this.connection, queryRunner);
|
||||
await executor.execute(databaseEntityLoader.operateSubjects);
|
||||
|
||||
return entityOrEntities; // await is needed here because we are using finally
|
||||
@ -171,10 +171,10 @@ export class Repository<Entity extends ObjectLiteral> {
|
||||
const queryRunner = await queryRunnerProvider.provide();
|
||||
try {
|
||||
|
||||
const databaseEntityLoader = new PersistenceSubjectBuilder(this.connection);
|
||||
const databaseEntityLoader = new SubjectBuilder(this.connection);
|
||||
await databaseEntityLoader.remove(entityOrEntities, this.metadata);
|
||||
|
||||
const executor = new PersistenceSubjectOperationExecutor(this.connection, queryRunner);
|
||||
const executor = new SubjectOperationExecutor(this.connection, queryRunner);
|
||||
await executor.execute(databaseEntityLoader.operateSubjects);
|
||||
|
||||
return entityOrEntities;
|
||||
|
||||
@ -3,7 +3,7 @@ import {EntityMetadata} from "../metadata/EntityMetadata";
|
||||
import {ObjectLiteral} from "../common/ObjectLiteral";
|
||||
import {Repository} from "./Repository";
|
||||
import {QueryRunnerProvider} from "../query-runner/QueryRunnerProvider";
|
||||
import {PersistenceSubject} from "../persistence/PersistenceSubject";
|
||||
import {Subject} from "../persistence/Subject";
|
||||
import {RelationMetadata} from "../metadata/RelationMetadata";
|
||||
import {ColumnMetadata} from "../metadata/ColumnMetadata";
|
||||
import {QueryBuilder} from "../query-builder/QueryBuilder";
|
||||
@ -506,7 +506,7 @@ export class SpecificRepository<Entity extends ObjectLiteral> {
|
||||
/**
|
||||
* Extracts unique objects from given entity and all its downside relations.
|
||||
*/
|
||||
protected extractObjectsById(entity: any, metadata: EntityMetadata, entityWithIds: PersistenceSubject[] = []): Promise<PersistenceSubject[]> {
|
||||
protected extractObjectsById(entity: any, metadata: EntityMetadata, entityWithIds: Subject[] = []): Promise<Subject[]> {
|
||||
const promises = metadata.relations.map(relation => {
|
||||
const relMetadata = relation.inverseEntityMetadata;
|
||||
|
||||
@ -527,7 +527,7 @@ export class SpecificRepository<Entity extends ObjectLiteral> {
|
||||
|
||||
return Promise.all<any>(promises.filter(result => !!result)).then(() => {
|
||||
if (!entityWithIds.find(entityWithId => entityWithId.entity === entity)) {
|
||||
const entityWithId = new PersistenceSubject(metadata, entity);
|
||||
const entityWithId = new Subject(metadata, entity);
|
||||
entityWithIds.push(entityWithId);
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ import {EventListenerTypes} from "../metadata/types/EventListenerTypes";
|
||||
import {EntityListenerMetadata} from "../metadata/EntityListenerMetadata";
|
||||
import {EntityMetadataCollection} from "../metadata-args/collection/EntityMetadataCollection";
|
||||
import {ObjectLiteral} from "../common/ObjectLiteral";
|
||||
import {PersistenceSubject} from "../persistence/PersistenceSubject";
|
||||
import {Subject} from "../persistence/Subject";
|
||||
|
||||
/**
|
||||
* Broadcaster provides a helper methods to broadcast events to the subscribers.
|
||||
@ -26,7 +26,7 @@ export class Broadcaster {
|
||||
/**
|
||||
* Broadcasts "BEFORE_INSERT", "BEFORE_UPDATE", "BEFORE_REMOVE" events for all given subjects.
|
||||
*/
|
||||
async broadcastBeforeEventsForAll(insertSubjects: PersistenceSubject[], updateSubjects: PersistenceSubject[], removeSubjects: PersistenceSubject[]): Promise<void> {
|
||||
async broadcastBeforeEventsForAll(insertSubjects: Subject[], updateSubjects: Subject[], removeSubjects: Subject[]): Promise<void> {
|
||||
const insertPromises = insertSubjects.map(subject => this.broadcastBeforeInsertEvent(subject));
|
||||
const updatePromises = updateSubjects.map(subject => this.broadcastBeforeUpdateEvent(subject));
|
||||
const removePromises = removeSubjects.map(subject => this.broadcastBeforeRemoveEvent(subject));
|
||||
@ -37,7 +37,7 @@ export class Broadcaster {
|
||||
/**
|
||||
* Broadcasts "AFTER_INSERT", "AFTER_UPDATE", "AFTER_REMOVE" events for all given subjects.
|
||||
*/
|
||||
async broadcastAfterEventsForAll(insertSubjects: PersistenceSubject[], updateSubjects: PersistenceSubject[], removeSubjects: PersistenceSubject[]): Promise<void> {
|
||||
async broadcastAfterEventsForAll(insertSubjects: Subject[], updateSubjects: Subject[], removeSubjects: Subject[]): Promise<void> {
|
||||
const insertPromises = insertSubjects.map(subject => this.broadcastAfterInsertEvent(subject));
|
||||
const updatePromises = updateSubjects.map(subject => this.broadcastAfterUpdateEvent(subject));
|
||||
const removePromises = removeSubjects.map(subject => this.broadcastAfterRemoveEvent(subject));
|
||||
@ -51,7 +51,7 @@ export class Broadcaster {
|
||||
* All subscribers and entity listeners who listened to this event will be executed at this point.
|
||||
* Subscribers and entity listeners can return promises, it will wait until they are resolved.
|
||||
*/
|
||||
async broadcastBeforeInsertEvent(subject: PersistenceSubject): Promise<void> {
|
||||
async broadcastBeforeInsertEvent(subject: Subject): Promise<void> {
|
||||
|
||||
const listeners = this.entityListeners
|
||||
.filter(listener => listener.type === EventListenerTypes.BEFORE_INSERT && this.isAllowedListener(listener, subject.entity))
|
||||
@ -70,7 +70,7 @@ export class Broadcaster {
|
||||
* All subscribers and entity listeners who listened to this event will be executed at this point.
|
||||
* Subscribers and entity listeners can return promises, it will wait until they are resolved.
|
||||
*/
|
||||
async broadcastBeforeUpdateEvent(subject: PersistenceSubject): Promise<void> { // todo: send relations too?
|
||||
async broadcastBeforeUpdateEvent(subject: Subject): Promise<void> { // todo: send relations too?
|
||||
|
||||
const listeners = this.entityListeners
|
||||
.filter(listener => listener.type === EventListenerTypes.BEFORE_UPDATE && this.isAllowedListener(listener, subject.entity))
|
||||
@ -94,7 +94,7 @@ export class Broadcaster {
|
||||
* All subscribers and entity listeners who listened to this event will be executed at this point.
|
||||
* Subscribers and entity listeners can return promises, it will wait until they are resolved.
|
||||
*/
|
||||
async broadcastBeforeRemoveEvent(subject: PersistenceSubject): Promise<void> {
|
||||
async broadcastBeforeRemoveEvent(subject: Subject): Promise<void> {
|
||||
|
||||
const listeners = this.entityListeners
|
||||
.filter(listener => listener.type === EventListenerTypes.BEFORE_REMOVE && this.isAllowedListener(listener, subject.entity))
|
||||
@ -116,7 +116,7 @@ export class Broadcaster {
|
||||
* All subscribers and entity listeners who listened to this event will be executed at this point.
|
||||
* Subscribers and entity listeners can return promises, it will wait until they are resolved.
|
||||
*/
|
||||
async broadcastAfterInsertEvent(subject: PersistenceSubject): Promise<void> {
|
||||
async broadcastAfterInsertEvent(subject: Subject): Promise<void> {
|
||||
|
||||
const listeners = this.entityListeners
|
||||
.filter(listener => listener.type === EventListenerTypes.AFTER_INSERT && this.isAllowedListener(listener, subject.entity))
|
||||
@ -137,7 +137,7 @@ export class Broadcaster {
|
||||
* All subscribers and entity listeners who listened to this event will be executed at this point.
|
||||
* Subscribers and entity listeners can return promises, it will wait until they are resolved.
|
||||
*/
|
||||
async broadcastAfterUpdateEvent(subject: PersistenceSubject): Promise<void> {
|
||||
async broadcastAfterUpdateEvent(subject: Subject): Promise<void> {
|
||||
|
||||
const listeners = this.entityListeners
|
||||
.filter(listener => listener.type === EventListenerTypes.AFTER_UPDATE && this.isAllowedListener(listener, subject.entity))
|
||||
@ -161,7 +161,7 @@ export class Broadcaster {
|
||||
* All subscribers and entity listeners who listened to this event will be executed at this point.
|
||||
* Subscribers and entity listeners can return promises, it will wait until they are resolved.
|
||||
*/
|
||||
async broadcastAfterRemoveEvent(subject: PersistenceSubject): Promise<void> {
|
||||
async broadcastAfterRemoveEvent(subject: Subject): Promise<void> {
|
||||
|
||||
const listeners = this.entityListeners
|
||||
.filter(listener => listener.type === EventListenerTypes.AFTER_REMOVE && this.isAllowedListener(listener, subject.entity))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user