@punks/backend-entity-manager 0.0.222 → 0.0.224
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 +43 -19
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/adapters.d.ts +3 -2
- package/dist/cjs/types/commands/create.d.ts +1 -0
- package/dist/cjs/types/commands/update.d.ts +1 -0
- package/dist/cjs/types/commands/upsert.d.ts +1 -0
- package/dist/cjs/types/platforms/nest/__test__/server/app/appFiles/templates/file-get-download-url/index.d.ts +2 -2
- package/dist/cjs/types/platforms/nest/__test__/server/app/appFiles/templates/file-upload/index.d.ts +2 -2
- package/dist/cjs/types/platforms/nest/services/files/index.d.ts +1 -1
- package/dist/cjs/types/platforms/nest/services/index.d.ts +1 -1
- package/dist/cjs/types/platforms/nest/services/providers.d.ts +2 -2
- package/dist/esm/index.js +44 -20
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/adapters.d.ts +3 -2
- package/dist/esm/types/commands/create.d.ts +1 -0
- package/dist/esm/types/commands/update.d.ts +1 -0
- package/dist/esm/types/commands/upsert.d.ts +1 -0
- package/dist/esm/types/platforms/nest/__test__/server/app/appFiles/templates/file-get-download-url/index.d.ts +2 -2
- package/dist/esm/types/platforms/nest/__test__/server/app/appFiles/templates/file-upload/index.d.ts +2 -2
- package/dist/esm/types/platforms/nest/services/files/index.d.ts +1 -1
- package/dist/esm/types/platforms/nest/services/index.d.ts +1 -1
- package/dist/esm/types/platforms/nest/services/providers.d.ts +2 -2
- package/dist/index.d.ts +11 -11
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -563,7 +563,7 @@ class EntityCreateCommand {
|
|
|
563
563
|
this.services = services;
|
|
564
564
|
}
|
|
565
565
|
async execute(input) {
|
|
566
|
-
const entity = this.adaptEntity(input);
|
|
566
|
+
const entity = await this.adaptEntity(input);
|
|
567
567
|
await this.authorize(entity);
|
|
568
568
|
const createdItem = await this.services.resolveRepository().create(entity);
|
|
569
569
|
// todo: parametrize id field
|
|
@@ -576,10 +576,11 @@ class EntityCreateCommand {
|
|
|
576
576
|
id,
|
|
577
577
|
};
|
|
578
578
|
}
|
|
579
|
-
adaptEntity(input) {
|
|
579
|
+
async adaptEntity(input) {
|
|
580
|
+
const context = await this.getContext();
|
|
580
581
|
const adapter = this.services.resolveAdapter();
|
|
581
582
|
return adapter
|
|
582
|
-
? adapter.createDataToEntity(input)
|
|
583
|
+
? adapter.createDataToEntity(input, context)
|
|
583
584
|
: input;
|
|
584
585
|
}
|
|
585
586
|
async authorize(entity) {
|
|
@@ -587,8 +588,7 @@ class EntityCreateCommand {
|
|
|
587
588
|
if (!authorization) {
|
|
588
589
|
return;
|
|
589
590
|
}
|
|
590
|
-
const
|
|
591
|
-
const context = await contextService?.getContext();
|
|
591
|
+
const context = await this.getContext();
|
|
592
592
|
if (!context) {
|
|
593
593
|
return;
|
|
594
594
|
}
|
|
@@ -596,6 +596,14 @@ class EntityCreateCommand {
|
|
|
596
596
|
if (!authorizationResult.isAuthorized)
|
|
597
597
|
throw new EntityOperationUnauthorizedException(exports.EntityOperationType.Create, this.services.getEntityName(), entity);
|
|
598
598
|
}
|
|
599
|
+
async getContext() {
|
|
600
|
+
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
601
|
+
if (!authorization) {
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
605
|
+
return await contextService?.getContext();
|
|
606
|
+
}
|
|
599
607
|
async versionEntity(id, entity) {
|
|
600
608
|
if (!this.isVersioningEnabled()) {
|
|
601
609
|
return;
|
|
@@ -833,7 +841,7 @@ class EntityUpdateCommand {
|
|
|
833
841
|
this.services = services;
|
|
834
842
|
}
|
|
835
843
|
async execute(id, input) {
|
|
836
|
-
const entity = this.adaptEntity(input);
|
|
844
|
+
const entity = await this.adaptEntity(input);
|
|
837
845
|
await this.authorize(id);
|
|
838
846
|
const updatedEntity = await this.services
|
|
839
847
|
.resolveRepository()
|
|
@@ -846,10 +854,11 @@ class EntityUpdateCommand {
|
|
|
846
854
|
id,
|
|
847
855
|
};
|
|
848
856
|
}
|
|
849
|
-
adaptEntity(input) {
|
|
857
|
+
async adaptEntity(input) {
|
|
858
|
+
const context = await this.getContext();
|
|
850
859
|
const adapter = this.services.resolveAdapter();
|
|
851
860
|
return adapter
|
|
852
|
-
? adapter.updateDataToEntity(input)
|
|
861
|
+
? adapter.updateDataToEntity(input, context)
|
|
853
862
|
: input;
|
|
854
863
|
}
|
|
855
864
|
async authorize(id) {
|
|
@@ -861,8 +870,7 @@ class EntityUpdateCommand {
|
|
|
861
870
|
if (currentEntity == null) {
|
|
862
871
|
throw new EntityNotFoundException();
|
|
863
872
|
}
|
|
864
|
-
const
|
|
865
|
-
const context = await contextService?.getContext();
|
|
873
|
+
const context = await this.getContext();
|
|
866
874
|
if (!context) {
|
|
867
875
|
return;
|
|
868
876
|
}
|
|
@@ -870,6 +878,14 @@ class EntityUpdateCommand {
|
|
|
870
878
|
if (!authorizationResult.isAuthorized)
|
|
871
879
|
throw new EntityOperationUnauthorizedException(exports.EntityOperationType.Create, this.services.getEntityName(), currentEntity);
|
|
872
880
|
}
|
|
881
|
+
async getContext() {
|
|
882
|
+
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
883
|
+
if (!authorization) {
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
887
|
+
return await contextService?.getContext();
|
|
888
|
+
}
|
|
873
889
|
async versionEntity(id, entity) {
|
|
874
890
|
if (!this.isVersioningEnabled()) {
|
|
875
891
|
return;
|
|
@@ -890,7 +906,7 @@ class EntityUpsertCommand {
|
|
|
890
906
|
this.services = services;
|
|
891
907
|
}
|
|
892
908
|
async execute(id, data) {
|
|
893
|
-
const entity = this.adaptEntity(data);
|
|
909
|
+
const entity = await this.adaptEntity(data);
|
|
894
910
|
await this.authorize(id, entity);
|
|
895
911
|
const updatedEntity = await this.upsertEntity(id, entity);
|
|
896
912
|
await this.versionEntity(id, updatedEntity);
|
|
@@ -904,10 +920,11 @@ class EntityUpsertCommand {
|
|
|
904
920
|
async upsertEntity(id, entity) {
|
|
905
921
|
return await this.services.resolveRepository().upsert(id, entity);
|
|
906
922
|
}
|
|
907
|
-
adaptEntity(input) {
|
|
923
|
+
async adaptEntity(input) {
|
|
924
|
+
const context = await this.getContext();
|
|
908
925
|
const adapter = this.services.resolveAdapter();
|
|
909
926
|
return adapter
|
|
910
|
-
? adapter.updateDataToEntity(input)
|
|
927
|
+
? adapter.updateDataToEntity(input, context)
|
|
911
928
|
: input;
|
|
912
929
|
}
|
|
913
930
|
async authorize(id, entity) {
|
|
@@ -916,8 +933,7 @@ class EntityUpsertCommand {
|
|
|
916
933
|
return;
|
|
917
934
|
}
|
|
918
935
|
const currentEntity = await this.services.resolveRepository().get(id);
|
|
919
|
-
const
|
|
920
|
-
const context = await contextService?.getContext();
|
|
936
|
+
const context = await this.getContext();
|
|
921
937
|
if (!context) {
|
|
922
938
|
return;
|
|
923
939
|
}
|
|
@@ -931,6 +947,14 @@ class EntityUpsertCommand {
|
|
|
931
947
|
if (!authorizationResult.isAuthorized)
|
|
932
948
|
throw new EntityOperationUnauthorizedException(exports.EntityOperationType.Create, this.services.getEntityName(), entity);
|
|
933
949
|
}
|
|
950
|
+
async getContext() {
|
|
951
|
+
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
952
|
+
if (!authorization) {
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
956
|
+
return await contextService?.getContext();
|
|
957
|
+
}
|
|
934
958
|
async versionEntity(id, entity) {
|
|
935
959
|
if (!this.isVersioningEnabled()) {
|
|
936
960
|
return;
|
|
@@ -21469,7 +21493,7 @@ exports.CacheService = __decorate([
|
|
|
21469
21493
|
__metadata("design:paramtypes", [exports.EntityManagerRegistry])
|
|
21470
21494
|
], exports.CacheService);
|
|
21471
21495
|
|
|
21472
|
-
exports.
|
|
21496
|
+
exports.FilesManager = class FilesManager {
|
|
21473
21497
|
constructor(registry) {
|
|
21474
21498
|
this.registry = registry;
|
|
21475
21499
|
}
|
|
@@ -21537,10 +21561,10 @@ exports.FilesService = class FilesService {
|
|
|
21537
21561
|
.resolveFilesReferenceRepositoryProviders();
|
|
21538
21562
|
}
|
|
21539
21563
|
};
|
|
21540
|
-
exports.
|
|
21564
|
+
exports.FilesManager = __decorate([
|
|
21541
21565
|
common.Injectable(),
|
|
21542
21566
|
__metadata("design:paramtypes", [exports.EntityManagerRegistry])
|
|
21543
|
-
], exports.
|
|
21567
|
+
], exports.FilesManager);
|
|
21544
21568
|
|
|
21545
21569
|
exports.EventsService = class EventsService {
|
|
21546
21570
|
constructor(registry) {
|
|
@@ -22336,7 +22360,7 @@ const Services$1 = [
|
|
|
22336
22360
|
exports.EntityManagerService,
|
|
22337
22361
|
exports.EmailService,
|
|
22338
22362
|
exports.EventsService,
|
|
22339
|
-
exports.
|
|
22363
|
+
exports.FilesManager,
|
|
22340
22364
|
exports.MediaLibraryService,
|
|
22341
22365
|
exports.SecretsService,
|
|
22342
22366
|
exports.TrackingService,
|