@punks/backend-entity-manager 0.0.343 → 0.0.345

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.
@@ -1,17 +1,17 @@
1
1
  import { DeepPartial } from "../types";
2
2
  import { IAuthenticationContext } from "./authentication";
3
3
  export interface IEntitiesSearchActionConverter<TEntity, TListItemDto> {
4
- toListItemDto(entity: TEntity): TListItemDto;
4
+ toListItemDto(entity: TEntity): TListItemDto | Promise<TListItemDto>;
5
5
  }
6
6
  export interface IEntityGetActionConverter<TEntity, TEntityDto> {
7
- toEntityDto(entity: TEntity): TEntityDto;
7
+ toEntityDto(entity: TEntity): TEntityDto | Promise<TEntityDto>;
8
8
  }
9
9
  export interface IEntityCreateActionConverter<TEntity, TEntityDto, TEntityCreateDto> {
10
10
  createDtoToEntity(data: TEntityCreateDto, context?: IAuthenticationContext<unknown>): DeepPartial<TEntity>;
11
- toEntityDto(entity: TEntity): TEntityDto;
11
+ toEntityDto(entity: TEntity): TEntityDto | Promise<TEntityDto>;
12
12
  }
13
13
  export interface IEntityUpdateActionConverter<TEntity, TEntityDto, TEntityUpdateDto> {
14
- toEntityDto(entity: TEntity): TEntityDto;
14
+ toEntityDto(entity: TEntity): TEntityDto | Promise<TEntityDto>;
15
15
  updateDtoToEntity(data: TEntityUpdateDto, context?: IAuthenticationContext<unknown>): DeepPartial<TEntity>;
16
16
  }
17
17
  export interface IEntityConverter<TEntity, TEntityDto, TListItemDto, TEntityCreateDto, TEntityUpdateDto> extends IEntitiesSearchActionConverter<TEntity, TListItemDto>, IEntityGetActionConverter<TEntity, TEntityDto>, IEntityCreateActionConverter<TEntity, TEntityDto, TEntityCreateDto>, IEntityUpdateActionConverter<TEntity, TEntityDto, TEntityUpdateDto> {
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Log, csvParse, excelParse, excelBuild, csvBuild, isNullOrUndefined, addTime, newUuid as newUuid$1, buildObject, toDict, sleep, sort, byField, toArrayDict, toItemsDict, ensureTailingSlash, ensureStartSlash, removeUndefinedProps } from '@punks/backend-core';
1
+ import { Log, csvParse, excelParse, excelBuild, csvBuild, mapAsync, isNullOrUndefined, addTime, newUuid as newUuid$1, buildObject, toDict, sleep, sort, byField, toArrayDict, toItemsDict, ensureTailingSlash, ensureStartSlash, removeUndefinedProps } from '@punks/backend-core';
2
2
  import { QueryCommand, ScanCommand, GetItemCommand, PutItemCommand, DeleteItemCommand, DynamoDBClient } from '@aws-sdk/client-dynamodb';
3
3
  import { unmarshall, marshall } from '@aws-sdk/util-dynamodb';
4
4
  import { Module, applyDecorators, Injectable, SetMetadata, createParamDecorator, Global, Scope, Inject, Logger, StreamableFile, HttpException, HttpStatus } from '@nestjs/common';
@@ -398,7 +398,7 @@ class EntityCreateAction {
398
398
  if (!entity) {
399
399
  throw new Error(`Newly created entity not found with id ${ref.id}`);
400
400
  }
401
- const result = converter?.toEntityDto(entity) ?? entity;
401
+ const result = (await converter?.toEntityDto(entity)) ?? entity;
402
402
  this.logger.debug("Create action completed", { input, result });
403
403
  return result;
404
404
  }
@@ -466,7 +466,7 @@ class EntityGetAction {
466
466
  const entity = await this.services.resolveGetQuery().execute(id);
467
467
  const converter = this.services.resolveConverter();
468
468
  return entity
469
- ? converter?.toEntityDto(entity) ?? entity
469
+ ? (await converter?.toEntityDto(entity)) ?? entity
470
470
  : undefined;
471
471
  }
472
472
  }
@@ -508,7 +508,7 @@ class EntitiesSearchAction {
508
508
  const results = await searchQuery.execute(request);
509
509
  const converter = this.services.resolveConverter();
510
510
  return {
511
- items: results.items.map((x) => (converter?.toListItemDto(x) ?? x)),
511
+ items: await mapAsync(results.items, async (x) => ((await converter?.toListItemDto(x)) ?? x)),
512
512
  paging: results.paging,
513
513
  childrenMap: results.childrenMap,
514
514
  facets: results.facets,
@@ -535,7 +535,7 @@ class EntityUpdateAction {
535
535
  if (!entity) {
536
536
  throw new Error(`Newly created entity not found with id ${id}`);
537
537
  }
538
- const result = converter?.toEntityDto(entity) ?? entity;
538
+ const result = (await converter?.toEntityDto(entity)) ?? entity;
539
539
  this.logger.debug("Update action started", { id, input, result });
540
540
  return result;
541
541
  }
@@ -567,7 +567,7 @@ class EntityUpsertAction {
567
567
  if (!entity) {
568
568
  throw new Error(`Newly created entity not found with id ${id}`);
569
569
  }
570
- const result = converter?.toEntityDto(entity) ?? entity;
570
+ const result = (await converter?.toEntityDto(entity)) ?? entity;
571
571
  this.logger.debug("Upsert action started", { id, input, result });
572
572
  return result;
573
573
  }