@iamnnort/nestjs-serializer 2.2.4 → 2.2.5

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/index.d.mts CHANGED
@@ -5,7 +5,7 @@ import { ExecutionContext, CallHandler } from '@nestjs/common';
5
5
  declare const SerializeField: (configs: {
6
6
  scopes: string[];
7
7
  fieldName?: string;
8
- fieldTransform?: (entity: any) => any | Promise<any>;
8
+ fieldTransform?: (value: any, entity: any) => any | Promise<any>;
9
9
  }[]) => (target: object, name: string) => void;
10
10
  declare const SerializeRelation: (configs: {
11
11
  scopes: string[];
@@ -24,7 +24,7 @@ type SerializerFieldConfig = {
24
24
  target: Function;
25
25
  name: string;
26
26
  fieldName?: string;
27
- fieldTransform?: (entity: any) => any | Promise<any>;
27
+ fieldTransform?: (value: any, entity: any) => any | Promise<any>;
28
28
  };
29
29
  type SerializerConfig = {
30
30
  globalEntityNames?: string[];
@@ -42,7 +42,7 @@ declare class SerializerService {
42
42
  scopes?: string[];
43
43
  fields?: string[];
44
44
  }): Promise<any>;
45
- transformRelationEntity(fieldValue: any, fieldConfig: SerializerFieldConfig): Promise<any>;
45
+ transformRelationEntity(fieldValue: any, fieldConfig: SerializerFieldConfig, entity: any): Promise<any>;
46
46
  transformEntity(entity: any, config: {
47
47
  scopes?: string[];
48
48
  fields?: string[];
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ import { ExecutionContext, CallHandler } from '@nestjs/common';
5
5
  declare const SerializeField: (configs: {
6
6
  scopes: string[];
7
7
  fieldName?: string;
8
- fieldTransform?: (entity: any) => any | Promise<any>;
8
+ fieldTransform?: (value: any, entity: any) => any | Promise<any>;
9
9
  }[]) => (target: object, name: string) => void;
10
10
  declare const SerializeRelation: (configs: {
11
11
  scopes: string[];
@@ -24,7 +24,7 @@ type SerializerFieldConfig = {
24
24
  target: Function;
25
25
  name: string;
26
26
  fieldName?: string;
27
- fieldTransform?: (entity: any) => any | Promise<any>;
27
+ fieldTransform?: (value: any, entity: any) => any | Promise<any>;
28
28
  };
29
29
  type SerializerConfig = {
30
30
  globalEntityNames?: string[];
@@ -42,7 +42,7 @@ declare class SerializerService {
42
42
  scopes?: string[];
43
43
  fields?: string[];
44
44
  }): Promise<any>;
45
- transformRelationEntity(fieldValue: any, fieldConfig: SerializerFieldConfig): Promise<any>;
45
+ transformRelationEntity(fieldValue: any, fieldConfig: SerializerFieldConfig, entity: any): Promise<any>;
46
46
  transformEntity(entity: any, config: {
47
47
  scopes?: string[];
48
48
  fields?: string[];
package/dist/index.js CHANGED
@@ -9086,18 +9086,18 @@ var SerializerService = class {
9086
9086
  const transformedEntity = await this.transformEntity(response, config);
9087
9087
  return transformedEntity;
9088
9088
  }
9089
- async transformRelationEntity(fieldValue, fieldConfig) {
9089
+ async transformRelationEntity(fieldValue, fieldConfig, entity) {
9090
9090
  const fieldTransform = _lodash.isFunction.call(void 0, fieldConfig.fieldTransform) ? fieldConfig.fieldTransform : (_) => _;
9091
9091
  if (_lodash.isArray.call(void 0, fieldValue)) {
9092
9092
  return fieldTransform(await Promise.all(fieldValue.map(async (relationEntity) => {
9093
9093
  return this.transformEntity(relationEntity, {
9094
9094
  scopes: fieldConfig.relationScopes
9095
9095
  });
9096
- })));
9096
+ })), entity);
9097
9097
  }
9098
9098
  return fieldTransform(await this.transformEntity(fieldValue, {
9099
9099
  scopes: fieldConfig.relationScopes
9100
- }));
9100
+ }), entity);
9101
9101
  }
9102
9102
  async transformEntity(entity, config) {
9103
9103
  if (!entity) {
@@ -9130,10 +9130,10 @@ var SerializerService = class {
9130
9130
  const fieldName = fieldConfig.fieldName || fieldConfig.name;
9131
9131
  let fieldValue = await entity[fieldConfig.name];
9132
9132
  if (!_lodash.isNil.call(void 0, fieldConfig.relationScopes)) {
9133
- fieldValue = await this.transformRelationEntity(fieldValue, fieldConfig);
9133
+ fieldValue = await this.transformRelationEntity(fieldValue, fieldConfig, entity);
9134
9134
  } else {
9135
9135
  if (_lodash.isFunction.call(void 0, fieldConfig.fieldTransform)) {
9136
- fieldValue = await fieldConfig.fieldTransform(fieldValue);
9136
+ fieldValue = await fieldConfig.fieldTransform(fieldValue, entity);
9137
9137
  }
9138
9138
  }
9139
9139
  transformedEntity = _lodash.merge.call(void 0, _lodash.set.call(void 0, {