@punks/backend-entity-manager 0.0.224 → 0.0.225
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 +33 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/converters.d.ts +3 -2
- package/dist/cjs/types/actions/create.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/esm/index.js +33 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/converters.d.ts +3 -2
- package/dist/esm/types/actions/create.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/index.d.ts +2 -2
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DeepPartial } from "../types";
|
|
2
|
+
import { IAuthenticationContext } from "./authentication";
|
|
2
3
|
export interface IEntitiesSearchActionConverter<TEntity, TListItemDto> {
|
|
3
4
|
toListItemDto(entity: TEntity): TListItemDto;
|
|
4
5
|
}
|
|
@@ -6,12 +7,12 @@ export interface IEntityGetActionConverter<TEntity, TEntityDto> {
|
|
|
6
7
|
toEntityDto(entity: TEntity): TEntityDto;
|
|
7
8
|
}
|
|
8
9
|
export interface IEntityCreateActionConverter<TEntity, TEntityDto, TEntityCreateDto> {
|
|
9
|
-
createDtoToEntity(data: TEntityCreateDto): DeepPartial<TEntity>;
|
|
10
|
+
createDtoToEntity(data: TEntityCreateDto, context?: IAuthenticationContext<unknown>): DeepPartial<TEntity>;
|
|
10
11
|
toEntityDto(entity: TEntity): TEntityDto;
|
|
11
12
|
}
|
|
12
13
|
export interface IEntityUpdateActionConverter<TEntity, TEntityDto, TEntityUpdateDto> {
|
|
13
14
|
toEntityDto(entity: TEntity): TEntityDto;
|
|
14
|
-
updateDtoToEntity(data: TEntityUpdateDto): DeepPartial<TEntity>;
|
|
15
|
+
updateDtoToEntity(data: TEntityUpdateDto, context?: IAuthenticationContext<unknown>): DeepPartial<TEntity>;
|
|
15
16
|
}
|
|
16
17
|
export interface IEntityConverter<TEntity, TEntityDto, TListItemDto, TEntityCreateDto, TEntityUpdateDto> extends IEntitiesSearchActionConverter<TEntity, TListItemDto>, IEntityGetActionConverter<TEntity, TEntityDto>, IEntityCreateActionConverter<TEntity, TEntityDto, TEntityCreateDto>, IEntityUpdateActionConverter<TEntity, TEntityDto, TEntityUpdateDto> {
|
|
17
18
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -362,7 +362,9 @@ class EntityCreateAction {
|
|
|
362
362
|
async execute(input) {
|
|
363
363
|
this.logger.debug("Create action started", { input });
|
|
364
364
|
const converter = this.services.resolveConverter();
|
|
365
|
-
const
|
|
365
|
+
const context = await this.getContext();
|
|
366
|
+
const createInput = converter?.createDtoToEntity(input, context) ??
|
|
367
|
+
input;
|
|
366
368
|
const ref = await this.services
|
|
367
369
|
.resolveCreateCommand()
|
|
368
370
|
.execute(createInput);
|
|
@@ -376,6 +378,14 @@ class EntityCreateAction {
|
|
|
376
378
|
this.logger.debug("Create action completed", { input, result });
|
|
377
379
|
return result;
|
|
378
380
|
}
|
|
381
|
+
async getContext() {
|
|
382
|
+
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
383
|
+
if (!authorization) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
387
|
+
return await contextService?.getContext();
|
|
388
|
+
}
|
|
379
389
|
}
|
|
380
390
|
|
|
381
391
|
class EntityDeleteAction {
|
|
@@ -491,7 +501,9 @@ class EntityUpdateAction {
|
|
|
491
501
|
async execute(id, input) {
|
|
492
502
|
this.logger.debug("Update action started", { id, input });
|
|
493
503
|
const converter = this.services.resolveConverter();
|
|
494
|
-
const
|
|
504
|
+
const context = await this.getContext();
|
|
505
|
+
const updateInput = converter?.updateDtoToEntity(input, context) ??
|
|
506
|
+
input;
|
|
495
507
|
await this.services
|
|
496
508
|
.resolveUpdateCommand()
|
|
497
509
|
.execute(id, updateInput);
|
|
@@ -503,6 +515,14 @@ class EntityUpdateAction {
|
|
|
503
515
|
this.logger.debug("Update action started", { id, input, result });
|
|
504
516
|
return result;
|
|
505
517
|
}
|
|
518
|
+
async getContext() {
|
|
519
|
+
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
520
|
+
if (!authorization) {
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
524
|
+
return await contextService?.getContext();
|
|
525
|
+
}
|
|
506
526
|
}
|
|
507
527
|
|
|
508
528
|
class EntityUpsertAction {
|
|
@@ -513,7 +533,9 @@ class EntityUpsertAction {
|
|
|
513
533
|
async execute(id, input) {
|
|
514
534
|
this.logger.debug("Upsert action started", { id, input });
|
|
515
535
|
const converter = this.services.resolveConverter();
|
|
516
|
-
const
|
|
536
|
+
const context = await this.getContext();
|
|
537
|
+
const updateInput = converter?.updateDtoToEntity(input, context) ??
|
|
538
|
+
input;
|
|
517
539
|
await this.services
|
|
518
540
|
.resolveUpsertCommand()
|
|
519
541
|
.execute(id, updateInput);
|
|
@@ -525,6 +547,14 @@ class EntityUpsertAction {
|
|
|
525
547
|
this.logger.debug("Upsert action started", { id, input, result });
|
|
526
548
|
return result;
|
|
527
549
|
}
|
|
550
|
+
async getContext() {
|
|
551
|
+
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
552
|
+
if (!authorization) {
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
556
|
+
return await contextService?.getContext();
|
|
557
|
+
}
|
|
528
558
|
}
|
|
529
559
|
|
|
530
560
|
class EntityVersionsSearchAction {
|