@punks/backend-entity-manager 0.0.81 → 0.0.82

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/dist/cjs/index.js CHANGED
@@ -516,18 +516,24 @@ class EntityCreateAction {
516
516
  class EntityDeleteAction {
517
517
  constructor(services) {
518
518
  this.services = services;
519
+ this.logger = backendCore.Log.getLogger(`${services.getEntityName()} -> Delete`);
519
520
  }
520
521
  async execute(id) {
522
+ this.logger.debug("Delete action started", { id });
521
523
  await this.services.resolveDeleteCommand().execute(id);
524
+ this.logger.debug("Delete action completed", { id });
522
525
  }
523
526
  }
524
527
 
525
528
  class EntitiesDeleteAction {
526
529
  constructor(services) {
527
530
  this.services = services;
531
+ this.logger = backendCore.Log.getLogger(`${services.getEntityName()} -> DeleteItems`);
528
532
  }
529
533
  async execute(params) {
534
+ this.logger.debug("DeleteItems action started");
530
535
  await this.services.resolveDeleteItemsCommand().execute(params);
536
+ this.logger.debug("DeleteItems action completed");
531
537
  }
532
538
  }
533
539
 
@@ -574,28 +580,36 @@ class EntitiesSearchAction {
574
580
  class EntityUpdateAction {
575
581
  constructor(services) {
576
582
  this.services = services;
583
+ this.logger = backendCore.Log.getLogger(`${services.getEntityName()} -> Update`);
577
584
  }
578
585
  async execute(id, input) {
586
+ this.logger.debug("Update action started", { id, input });
579
587
  const converter = this.services.resolveConverter();
580
588
  const updateInput = converter?.updateDtoToEntity(input) ?? input;
581
589
  const entity = await this.services
582
590
  .resolveUpdateCommand()
583
591
  .execute(id, updateInput);
584
- return converter?.toEntityDto(entity) ?? entity;
592
+ const result = converter?.toEntityDto(entity) ?? entity;
593
+ this.logger.debug("Update action started", { id, input, result });
594
+ return result;
585
595
  }
586
596
  }
587
597
 
588
598
  class EntityUpsertAction {
589
599
  constructor(services) {
590
600
  this.services = services;
601
+ this.logger = backendCore.Log.getLogger(`${services.getEntityName()} -> Upsert`);
591
602
  }
592
603
  async execute(id, input) {
604
+ this.logger.debug("Upsert action started", { id, input });
593
605
  const converter = this.services.resolveConverter();
594
606
  const updateInput = converter?.updateDtoToEntity(input) ?? input;
595
607
  const entity = await this.services
596
608
  .resolveUpsertCommand()
597
609
  .execute(id, updateInput);
598
- return converter?.toEntityDto(entity) ?? entity;
610
+ const result = converter?.toEntityDto(entity) ?? entity;
611
+ this.logger.debug("Upsert action started", { id, input, result });
612
+ return result;
599
613
  }
600
614
  }
601
615
 
@@ -21023,6 +21037,7 @@ class TypeOrmQueryBuilder extends QueryBuilderBase {
21023
21037
  class TypeOrmRepository {
21024
21038
  constructor(innerRepository) {
21025
21039
  this.innerRepository = innerRepository;
21040
+ this.logger = backendCore.Log.getLogger("TypeOrm Repository");
21026
21041
  }
21027
21042
  getInnerRepository() {
21028
21043
  return this.innerRepository;
@@ -21031,6 +21046,7 @@ class TypeOrmRepository {
21031
21046
  if (backendCore.isNullOrUndefined(id)) {
21032
21047
  throw new Error("Invalid 'id' parameter.");
21033
21048
  }
21049
+ this.logger.debug("Checking entity exists by id", { id });
21034
21050
  return await this.innerRepository.exist({
21035
21051
  where: {
21036
21052
  id: id,
@@ -21038,12 +21054,14 @@ class TypeOrmRepository {
21038
21054
  });
21039
21055
  }
21040
21056
  async existsBy(condition) {
21057
+ this.logger.debug("Checking entity exists by condition", { condition });
21041
21058
  return await this.innerRepository.exist(condition);
21042
21059
  }
21043
21060
  async get(id) {
21044
21061
  if (backendCore.isNullOrUndefined(id)) {
21045
21062
  throw new Error("Invalid 'id' parameter.");
21046
21063
  }
21064
+ this.logger.debug("Getting entity by id", { id });
21047
21065
  const result = await this.innerRepository.findOne({
21048
21066
  where: {
21049
21067
  id: id,
@@ -21052,19 +21070,24 @@ class TypeOrmRepository {
21052
21070
  return result ?? undefined;
21053
21071
  }
21054
21072
  async getBy(condition) {
21073
+ this.logger.debug("Getting entity by condition", { condition });
21055
21074
  const result = await this.innerRepository.findOne(condition);
21056
21075
  return result ?? undefined;
21057
21076
  }
21058
21077
  async all() {
21078
+ this.logger.debug("Getting all entities");
21059
21079
  return await this.innerRepository.find();
21060
21080
  }
21061
21081
  async count(condition) {
21082
+ this.logger.debug("Counting entities", { condition });
21062
21083
  return await this.innerRepository.count(condition);
21063
21084
  }
21064
21085
  async find(condition) {
21086
+ this.logger.debug("Finding entities by condition", { condition });
21065
21087
  return await this.innerRepository.find(condition);
21066
21088
  }
21067
21089
  async findById(id) {
21090
+ this.logger.debug("Finding entities by id", { id });
21068
21091
  return await this.innerRepository.findBy({
21069
21092
  id: typeorm.In(id),
21070
21093
  });
@@ -21073,17 +21096,20 @@ class TypeOrmRepository {
21073
21096
  if (backendCore.isNullOrUndefined(id)) {
21074
21097
  throw new Error("Invalid 'id' parameter.");
21075
21098
  }
21099
+ this.logger.debug("Deleting entity by id", { id });
21076
21100
  await this.innerRepository.delete({
21077
21101
  id: id,
21078
21102
  });
21079
21103
  }
21080
21104
  async deleteBy(condition) {
21081
21105
  const result = await this.innerRepository.delete(condition);
21106
+ this.logger.debug("Deleting entities by condition", { condition, result });
21082
21107
  return {
21083
21108
  deletedCount: result.affected,
21084
21109
  };
21085
21110
  }
21086
21111
  async create(entity) {
21112
+ this.logger.debug("Creating entity", { entity });
21087
21113
  const createResult = await this.innerRepository.insert(entity);
21088
21114
  const current = await this.get(createResult.identifiers[0].id);
21089
21115
  if (!current) {
@@ -21095,6 +21121,7 @@ class TypeOrmRepository {
21095
21121
  if (backendCore.isNullOrUndefined(id)) {
21096
21122
  throw new Error("Invalid 'id' parameter.");
21097
21123
  }
21124
+ this.logger.debug("Updating entity", { id, entity });
21098
21125
  await this.innerRepository.update(id, entity);
21099
21126
  const current = await this.get(id);
21100
21127
  if (!current) {
@@ -21103,6 +21130,7 @@ class TypeOrmRepository {
21103
21130
  return current;
21104
21131
  }
21105
21132
  async updateBy(entity, condition) {
21133
+ this.logger.debug("Updating entities by condition", { entity, condition });
21106
21134
  const updateResult = await this.innerRepository.update(condition, entity);
21107
21135
  return await this.findById(updateResult.generatedMaps.map((x) => x.id));
21108
21136
  }
@@ -21110,6 +21138,7 @@ class TypeOrmRepository {
21110
21138
  if (backendCore.isNullOrUndefined(id)) {
21111
21139
  throw new Error("Invalid 'id' parameter.");
21112
21140
  }
21141
+ this.logger.debug("Upserting entity", { id, entity });
21113
21142
  if (await this.exists(id)) {
21114
21143
  return await this.update(id, entity);
21115
21144
  }