@punks/backend-entity-manager 0.0.81 → 0.0.83

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.
@@ -2,6 +2,7 @@ import { IEntityDeleteAction } from "../abstractions/actions";
2
2
  import { EntityServiceLocator } from "../providers/services";
3
3
  export declare class EntityDeleteAction<TEntity, TEntityId> implements IEntityDeleteAction<TEntity, TEntityId> {
4
4
  private readonly services;
5
+ private readonly logger;
5
6
  constructor(services: EntityServiceLocator<TEntity, TEntityId>);
6
7
  execute(id: TEntityId): Promise<void>;
7
8
  }
@@ -3,6 +3,7 @@ import { IEntitiesDeleteParameters } from "../abstractions/commands";
3
3
  import { EntityServiceLocator } from "../providers/services";
4
4
  export declare class EntitiesDeleteAction<TEntity, TEntitiesDeleteParameters extends IEntitiesDeleteParameters<TSorting>, TSorting> implements IEntitiesDeleteAction<TEntity, TEntitiesDeleteParameters, TSorting> {
5
5
  private readonly services;
6
+ private readonly logger;
6
7
  constructor(services: EntityServiceLocator<TEntity, unknown>);
7
8
  execute(params: TEntitiesDeleteParameters): Promise<void>;
8
9
  }
@@ -2,6 +2,7 @@ import { IEntityUpdateAction } from "../abstractions/actions";
2
2
  import { EntityServiceLocator } from "../providers/services";
3
3
  export declare class EntityUpdateAction<TEntity, TEntityId, TEntityUpdateData, TEntityDto> implements IEntityUpdateAction<TEntity, TEntityId, TEntityUpdateData, TEntityDto> {
4
4
  private readonly services;
5
+ private readonly logger;
5
6
  constructor(services: EntityServiceLocator<TEntity, TEntityId>);
6
7
  execute(id: TEntityId, input: TEntityUpdateData): Promise<TEntityDto>;
7
8
  }
@@ -2,6 +2,7 @@ import { IEntityUpsertAction } from "../abstractions/actions";
2
2
  import { EntityServiceLocator } from "../providers/services";
3
3
  export declare class EntityUpsertAction<TEntity, TEntityId, TEntityUpdateData, TEntityDto> implements IEntityUpsertAction<TEntity, TEntityId, TEntityUpdateData, TEntityDto> {
4
4
  private readonly services;
5
+ private readonly logger;
5
6
  constructor(services: EntityServiceLocator<TEntity, TEntityId>);
6
7
  execute(id: TEntityId, input: TEntityUpdateData): Promise<TEntityDto>;
7
8
  }
@@ -5,6 +5,7 @@ export type UpdateCriteria<TEntity extends ObjectLiteral> = string | string[] |
5
5
  export type DeleteCriteria<TEntity extends ObjectLiteral> = string | string[] | number | number[] | Date | Date[] | ObjectId | ObjectId[] | FindOptionsWhere<TEntity>;
6
6
  export declare class TypeOrmRepository<TEntity extends ObjectLiteral, TEntityId> implements IEntityRepository<TEntity, TEntityId, FindOneOptions<TEntity>, FindManyOptions<TEntity>, UpdateCriteria<TEntity>, DeleteCriteria<TEntity>> {
7
7
  protected readonly innerRepository: Repository<TEntity>;
8
+ private readonly logger;
8
9
  constructor(innerRepository: Repository<TEntity>);
9
10
  getInnerRepository(): Repository<TEntity>;
10
11
  exists(id: TEntityId): Promise<boolean>;
package/dist/esm/index.js CHANGED
@@ -508,18 +508,24 @@ class EntityCreateAction {
508
508
  class EntityDeleteAction {
509
509
  constructor(services) {
510
510
  this.services = services;
511
+ this.logger = Log.getLogger(`${services.getEntityName()} -> Delete`);
511
512
  }
512
513
  async execute(id) {
514
+ this.logger.debug("Delete action started", { id });
513
515
  await this.services.resolveDeleteCommand().execute(id);
516
+ this.logger.debug("Delete action completed", { id });
514
517
  }
515
518
  }
516
519
 
517
520
  class EntitiesDeleteAction {
518
521
  constructor(services) {
519
522
  this.services = services;
523
+ this.logger = Log.getLogger(`${services.getEntityName()} -> DeleteItems`);
520
524
  }
521
525
  async execute(params) {
526
+ this.logger.debug("DeleteItems action started");
522
527
  await this.services.resolveDeleteItemsCommand().execute(params);
528
+ this.logger.debug("DeleteItems action completed");
523
529
  }
524
530
  }
525
531
 
@@ -566,28 +572,36 @@ class EntitiesSearchAction {
566
572
  class EntityUpdateAction {
567
573
  constructor(services) {
568
574
  this.services = services;
575
+ this.logger = Log.getLogger(`${services.getEntityName()} -> Update`);
569
576
  }
570
577
  async execute(id, input) {
578
+ this.logger.debug("Update action started", { id, input });
571
579
  const converter = this.services.resolveConverter();
572
580
  const updateInput = converter?.updateDtoToEntity(input) ?? input;
573
581
  const entity = await this.services
574
582
  .resolveUpdateCommand()
575
583
  .execute(id, updateInput);
576
- return converter?.toEntityDto(entity) ?? entity;
584
+ const result = converter?.toEntityDto(entity) ?? entity;
585
+ this.logger.debug("Update action started", { id, input, result });
586
+ return result;
577
587
  }
578
588
  }
579
589
 
580
590
  class EntityUpsertAction {
581
591
  constructor(services) {
582
592
  this.services = services;
593
+ this.logger = Log.getLogger(`${services.getEntityName()} -> Upsert`);
583
594
  }
584
595
  async execute(id, input) {
596
+ this.logger.debug("Upsert action started", { id, input });
585
597
  const converter = this.services.resolveConverter();
586
598
  const updateInput = converter?.updateDtoToEntity(input) ?? input;
587
599
  const entity = await this.services
588
600
  .resolveUpsertCommand()
589
601
  .execute(id, updateInput);
590
- return converter?.toEntityDto(entity) ?? entity;
602
+ const result = converter?.toEntityDto(entity) ?? entity;
603
+ this.logger.debug("Upsert action started", { id, input, result });
604
+ return result;
591
605
  }
592
606
  }
593
607
 
@@ -1788,7 +1802,7 @@ class EntityManagerServiceCollection {
1788
1802
  this.locator.registerDeleteCommand(this.entityName, new EntityDeleteCommand(this.resolver));
1789
1803
  this.locator.registerDeleteAction(this.entityName, new EntityDeleteAction(this.resolver));
1790
1804
  this.locator.registerDeleteItemsCommand(this.entityName, new EntitiesDeleteCommand(this.resolver));
1791
- this.locator.registerDeleteAction(this.entityName, new EntitiesDeleteAction(this.resolver));
1805
+ this.locator.registerDeleteItemsAction(this.entityName, new EntitiesDeleteAction(this.resolver));
1792
1806
  return this;
1793
1807
  }
1794
1808
  addAdapter(adapter) {
@@ -21015,6 +21029,7 @@ class TypeOrmQueryBuilder extends QueryBuilderBase {
21015
21029
  class TypeOrmRepository {
21016
21030
  constructor(innerRepository) {
21017
21031
  this.innerRepository = innerRepository;
21032
+ this.logger = Log.getLogger("TypeOrm Repository");
21018
21033
  }
21019
21034
  getInnerRepository() {
21020
21035
  return this.innerRepository;
@@ -21023,6 +21038,7 @@ class TypeOrmRepository {
21023
21038
  if (isNullOrUndefined(id)) {
21024
21039
  throw new Error("Invalid 'id' parameter.");
21025
21040
  }
21041
+ this.logger.debug("Checking entity exists by id", { id });
21026
21042
  return await this.innerRepository.exist({
21027
21043
  where: {
21028
21044
  id: id,
@@ -21030,12 +21046,14 @@ class TypeOrmRepository {
21030
21046
  });
21031
21047
  }
21032
21048
  async existsBy(condition) {
21049
+ this.logger.debug("Checking entity exists by condition", { condition });
21033
21050
  return await this.innerRepository.exist(condition);
21034
21051
  }
21035
21052
  async get(id) {
21036
21053
  if (isNullOrUndefined(id)) {
21037
21054
  throw new Error("Invalid 'id' parameter.");
21038
21055
  }
21056
+ this.logger.debug("Getting entity by id", { id });
21039
21057
  const result = await this.innerRepository.findOne({
21040
21058
  where: {
21041
21059
  id: id,
@@ -21044,19 +21062,24 @@ class TypeOrmRepository {
21044
21062
  return result ?? undefined;
21045
21063
  }
21046
21064
  async getBy(condition) {
21065
+ this.logger.debug("Getting entity by condition", { condition });
21047
21066
  const result = await this.innerRepository.findOne(condition);
21048
21067
  return result ?? undefined;
21049
21068
  }
21050
21069
  async all() {
21070
+ this.logger.debug("Getting all entities");
21051
21071
  return await this.innerRepository.find();
21052
21072
  }
21053
21073
  async count(condition) {
21074
+ this.logger.debug("Counting entities", { condition });
21054
21075
  return await this.innerRepository.count(condition);
21055
21076
  }
21056
21077
  async find(condition) {
21078
+ this.logger.debug("Finding entities by condition", { condition });
21057
21079
  return await this.innerRepository.find(condition);
21058
21080
  }
21059
21081
  async findById(id) {
21082
+ this.logger.debug("Finding entities by id", { id });
21060
21083
  return await this.innerRepository.findBy({
21061
21084
  id: In(id),
21062
21085
  });
@@ -21065,17 +21088,20 @@ class TypeOrmRepository {
21065
21088
  if (isNullOrUndefined(id)) {
21066
21089
  throw new Error("Invalid 'id' parameter.");
21067
21090
  }
21091
+ this.logger.debug("Deleting entity by id", { id });
21068
21092
  await this.innerRepository.delete({
21069
21093
  id: id,
21070
21094
  });
21071
21095
  }
21072
21096
  async deleteBy(condition) {
21073
21097
  const result = await this.innerRepository.delete(condition);
21098
+ this.logger.debug("Deleting entities by condition", { condition, result });
21074
21099
  return {
21075
21100
  deletedCount: result.affected,
21076
21101
  };
21077
21102
  }
21078
21103
  async create(entity) {
21104
+ this.logger.debug("Creating entity", { entity });
21079
21105
  const createResult = await this.innerRepository.insert(entity);
21080
21106
  const current = await this.get(createResult.identifiers[0].id);
21081
21107
  if (!current) {
@@ -21087,6 +21113,7 @@ class TypeOrmRepository {
21087
21113
  if (isNullOrUndefined(id)) {
21088
21114
  throw new Error("Invalid 'id' parameter.");
21089
21115
  }
21116
+ this.logger.debug("Updating entity", { id, entity });
21090
21117
  await this.innerRepository.update(id, entity);
21091
21118
  const current = await this.get(id);
21092
21119
  if (!current) {
@@ -21095,6 +21122,7 @@ class TypeOrmRepository {
21095
21122
  return current;
21096
21123
  }
21097
21124
  async updateBy(entity, condition) {
21125
+ this.logger.debug("Updating entities by condition", { entity, condition });
21098
21126
  const updateResult = await this.innerRepository.update(condition, entity);
21099
21127
  return await this.findById(updateResult.generatedMaps.map((x) => x.id));
21100
21128
  }
@@ -21102,6 +21130,7 @@ class TypeOrmRepository {
21102
21130
  if (isNullOrUndefined(id)) {
21103
21131
  throw new Error("Invalid 'id' parameter.");
21104
21132
  }
21133
+ this.logger.debug("Upserting entity", { id, entity });
21105
21134
  if (await this.exists(id)) {
21106
21135
  return await this.update(id, entity);
21107
21136
  }