@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.
- package/dist/cjs/index.js +42 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/actions/delete.d.ts +1 -0
- package/dist/cjs/types/actions/deleteItems.d.ts +1 -0
- package/dist/cjs/types/actions/update.d.ts +1 -0
- package/dist/cjs/types/actions/upsert.d.ts +1 -0
- package/dist/cjs/types/integrations/repository/typeorm/repository.d.ts +1 -0
- package/dist/esm/index.js +42 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/actions/delete.d.ts +1 -0
- package/dist/esm/types/actions/deleteItems.d.ts +1 -0
- package/dist/esm/types/actions/update.d.ts +1 -0
- package/dist/esm/types/actions/upsert.d.ts +1 -0
- package/dist/esm/types/integrations/repository/typeorm/repository.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
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
|
-
|
|
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
|
-
|
|
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,14 +21037,16 @@ 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;
|
|
21029
21044
|
}
|
|
21030
21045
|
async exists(id) {
|
|
21031
|
-
if (
|
|
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
|
-
if (
|
|
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,35 +21070,46 @@ 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
|
});
|
|
21071
21094
|
}
|
|
21072
21095
|
async delete(id) {
|
|
21096
|
+
if (backendCore.isNullOrUndefined(id)) {
|
|
21097
|
+
throw new Error("Invalid 'id' parameter.");
|
|
21098
|
+
}
|
|
21099
|
+
this.logger.debug("Deleting entity by id", { id });
|
|
21073
21100
|
await this.innerRepository.delete({
|
|
21074
21101
|
id: id,
|
|
21075
21102
|
});
|
|
21076
21103
|
}
|
|
21077
21104
|
async deleteBy(condition) {
|
|
21078
21105
|
const result = await this.innerRepository.delete(condition);
|
|
21106
|
+
this.logger.debug("Deleting entities by condition", { condition, result });
|
|
21079
21107
|
return {
|
|
21080
21108
|
deletedCount: result.affected,
|
|
21081
21109
|
};
|
|
21082
21110
|
}
|
|
21083
21111
|
async create(entity) {
|
|
21112
|
+
this.logger.debug("Creating entity", { entity });
|
|
21084
21113
|
const createResult = await this.innerRepository.insert(entity);
|
|
21085
21114
|
const current = await this.get(createResult.identifiers[0].id);
|
|
21086
21115
|
if (!current) {
|
|
@@ -21089,6 +21118,10 @@ class TypeOrmRepository {
|
|
|
21089
21118
|
return current;
|
|
21090
21119
|
}
|
|
21091
21120
|
async update(id, entity) {
|
|
21121
|
+
if (backendCore.isNullOrUndefined(id)) {
|
|
21122
|
+
throw new Error("Invalid 'id' parameter.");
|
|
21123
|
+
}
|
|
21124
|
+
this.logger.debug("Updating entity", { id, entity });
|
|
21092
21125
|
await this.innerRepository.update(id, entity);
|
|
21093
21126
|
const current = await this.get(id);
|
|
21094
21127
|
if (!current) {
|
|
@@ -21097,10 +21130,15 @@ class TypeOrmRepository {
|
|
|
21097
21130
|
return current;
|
|
21098
21131
|
}
|
|
21099
21132
|
async updateBy(entity, condition) {
|
|
21133
|
+
this.logger.debug("Updating entities by condition", { entity, condition });
|
|
21100
21134
|
const updateResult = await this.innerRepository.update(condition, entity);
|
|
21101
21135
|
return await this.findById(updateResult.generatedMaps.map((x) => x.id));
|
|
21102
21136
|
}
|
|
21103
21137
|
async upsert(id, entity) {
|
|
21138
|
+
if (backendCore.isNullOrUndefined(id)) {
|
|
21139
|
+
throw new Error("Invalid 'id' parameter.");
|
|
21140
|
+
}
|
|
21141
|
+
this.logger.debug("Upserting entity", { id, entity });
|
|
21104
21142
|
if (await this.exists(id)) {
|
|
21105
21143
|
return await this.update(id, entity);
|
|
21106
21144
|
}
|