@punks/backend-entity-manager 0.0.80 → 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.
@@ -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
 
@@ -21015,14 +21029,16 @@ 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;
21021
21036
  }
21022
21037
  async exists(id) {
21023
- if (typeof id === "undefined") {
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
- if (typeof id === "undefined") {
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,35 +21062,46 @@ 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
  });
21063
21086
  }
21064
21087
  async delete(id) {
21088
+ if (isNullOrUndefined(id)) {
21089
+ throw new Error("Invalid 'id' parameter.");
21090
+ }
21091
+ this.logger.debug("Deleting entity by id", { id });
21065
21092
  await this.innerRepository.delete({
21066
21093
  id: id,
21067
21094
  });
21068
21095
  }
21069
21096
  async deleteBy(condition) {
21070
21097
  const result = await this.innerRepository.delete(condition);
21098
+ this.logger.debug("Deleting entities by condition", { condition, result });
21071
21099
  return {
21072
21100
  deletedCount: result.affected,
21073
21101
  };
21074
21102
  }
21075
21103
  async create(entity) {
21104
+ this.logger.debug("Creating entity", { entity });
21076
21105
  const createResult = await this.innerRepository.insert(entity);
21077
21106
  const current = await this.get(createResult.identifiers[0].id);
21078
21107
  if (!current) {
@@ -21081,6 +21110,10 @@ class TypeOrmRepository {
21081
21110
  return current;
21082
21111
  }
21083
21112
  async update(id, entity) {
21113
+ if (isNullOrUndefined(id)) {
21114
+ throw new Error("Invalid 'id' parameter.");
21115
+ }
21116
+ this.logger.debug("Updating entity", { id, entity });
21084
21117
  await this.innerRepository.update(id, entity);
21085
21118
  const current = await this.get(id);
21086
21119
  if (!current) {
@@ -21089,10 +21122,15 @@ class TypeOrmRepository {
21089
21122
  return current;
21090
21123
  }
21091
21124
  async updateBy(entity, condition) {
21125
+ this.logger.debug("Updating entities by condition", { entity, condition });
21092
21126
  const updateResult = await this.innerRepository.update(condition, entity);
21093
21127
  return await this.findById(updateResult.generatedMaps.map((x) => x.id));
21094
21128
  }
21095
21129
  async upsert(id, entity) {
21130
+ if (isNullOrUndefined(id)) {
21131
+ throw new Error("Invalid 'id' parameter.");
21132
+ }
21133
+ this.logger.debug("Upserting entity", { id, entity });
21096
21134
  if (await this.exists(id)) {
21097
21135
  return await this.update(id, entity);
21098
21136
  }