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