@iamnnort/nestjs-serializer 1.1.8 → 1.1.10
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 +12 -10
- package/dist/index.d.ts +12 -10
- package/dist/index.js +14 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -10,19 +10,20 @@ declare const SerializeRelation: (configs: {
|
|
|
10
10
|
scopes: string[];
|
|
11
11
|
relationScopes: string[];
|
|
12
12
|
fieldName?: string;
|
|
13
|
-
fieldTransform?: (entity: any) => Promise<any>;
|
|
13
|
+
fieldTransform?: (entity: any) => any | Promise<any>;
|
|
14
14
|
}[]) => (target: object, name: string) => void;
|
|
15
15
|
|
|
16
16
|
declare global {
|
|
17
|
-
var serializerFieldConfigs:
|
|
18
|
-
scopes: string[];
|
|
19
|
-
relationScopes?: string[];
|
|
20
|
-
target: Function;
|
|
21
|
-
name: string;
|
|
22
|
-
fieldName?: string;
|
|
23
|
-
fieldTransform?: (entity: any) => Promise<any>;
|
|
24
|
-
}[];
|
|
17
|
+
var serializerFieldConfigs: SerializerFieldConfig[];
|
|
25
18
|
}
|
|
19
|
+
type SerializerFieldConfig = {
|
|
20
|
+
scopes: string[];
|
|
21
|
+
relationScopes?: string[];
|
|
22
|
+
target: Function;
|
|
23
|
+
name: string;
|
|
24
|
+
fieldName?: string;
|
|
25
|
+
fieldTransform?: (entity: any) => any | Promise<any>;
|
|
26
|
+
};
|
|
26
27
|
type SerializerConfig = {
|
|
27
28
|
globalEntityNames?: string[];
|
|
28
29
|
};
|
|
@@ -35,6 +36,7 @@ declare class SerializerService {
|
|
|
35
36
|
scopes?: string[];
|
|
36
37
|
fields?: string[];
|
|
37
38
|
}): Promise<any>;
|
|
39
|
+
transformRelationEntity(fieldValue: any, fieldConfig: SerializerFieldConfig): Promise<any>;
|
|
38
40
|
transformEntity(entity: any, config: {
|
|
39
41
|
scopes?: string[];
|
|
40
42
|
fields?: string[];
|
|
@@ -69,4 +71,4 @@ declare const ConfigurableModuleClass: _nestjs_common.ConfigurableModuleCls<Seri
|
|
|
69
71
|
declare class SerializerModule extends ConfigurableModuleClass {
|
|
70
72
|
}
|
|
71
73
|
|
|
72
|
-
export { SerializeField, SerializeRelation, type SerializerConfig, SerializerIdInterceptor, SerializerInterceptor, SerializerModule, SerializerService };
|
|
74
|
+
export { SerializeField, SerializeRelation, type SerializerConfig, type SerializerFieldConfig, SerializerIdInterceptor, SerializerInterceptor, SerializerModule, SerializerService };
|
package/dist/index.d.ts
CHANGED
|
@@ -10,19 +10,20 @@ declare const SerializeRelation: (configs: {
|
|
|
10
10
|
scopes: string[];
|
|
11
11
|
relationScopes: string[];
|
|
12
12
|
fieldName?: string;
|
|
13
|
-
fieldTransform?: (entity: any) => Promise<any>;
|
|
13
|
+
fieldTransform?: (entity: any) => any | Promise<any>;
|
|
14
14
|
}[]) => (target: object, name: string) => void;
|
|
15
15
|
|
|
16
16
|
declare global {
|
|
17
|
-
var serializerFieldConfigs:
|
|
18
|
-
scopes: string[];
|
|
19
|
-
relationScopes?: string[];
|
|
20
|
-
target: Function;
|
|
21
|
-
name: string;
|
|
22
|
-
fieldName?: string;
|
|
23
|
-
fieldTransform?: (entity: any) => Promise<any>;
|
|
24
|
-
}[];
|
|
17
|
+
var serializerFieldConfigs: SerializerFieldConfig[];
|
|
25
18
|
}
|
|
19
|
+
type SerializerFieldConfig = {
|
|
20
|
+
scopes: string[];
|
|
21
|
+
relationScopes?: string[];
|
|
22
|
+
target: Function;
|
|
23
|
+
name: string;
|
|
24
|
+
fieldName?: string;
|
|
25
|
+
fieldTransform?: (entity: any) => any | Promise<any>;
|
|
26
|
+
};
|
|
26
27
|
type SerializerConfig = {
|
|
27
28
|
globalEntityNames?: string[];
|
|
28
29
|
};
|
|
@@ -35,6 +36,7 @@ declare class SerializerService {
|
|
|
35
36
|
scopes?: string[];
|
|
36
37
|
fields?: string[];
|
|
37
38
|
}): Promise<any>;
|
|
39
|
+
transformRelationEntity(fieldValue: any, fieldConfig: SerializerFieldConfig): Promise<any>;
|
|
38
40
|
transformEntity(entity: any, config: {
|
|
39
41
|
scopes?: string[];
|
|
40
42
|
fields?: string[];
|
|
@@ -69,4 +71,4 @@ declare const ConfigurableModuleClass: _nestjs_common.ConfigurableModuleCls<Seri
|
|
|
69
71
|
declare class SerializerModule extends ConfigurableModuleClass {
|
|
70
72
|
}
|
|
71
73
|
|
|
72
|
-
export { SerializeField, SerializeRelation, type SerializerConfig, SerializerIdInterceptor, SerializerInterceptor, SerializerModule, SerializerService };
|
|
74
|
+
export { SerializeField, SerializeRelation, type SerializerConfig, type SerializerFieldConfig, SerializerIdInterceptor, SerializerInterceptor, SerializerModule, SerializerService };
|
package/dist/index.js
CHANGED
|
@@ -9084,6 +9084,19 @@ var SerializerService = class {
|
|
|
9084
9084
|
const transformedEntity = await this.transformEntity(response, config);
|
|
9085
9085
|
return transformedEntity;
|
|
9086
9086
|
}
|
|
9087
|
+
async transformRelationEntity(fieldValue, fieldConfig) {
|
|
9088
|
+
const fieldTransform = _lodash.isFunction.call(void 0, fieldConfig.fieldTransform) ? fieldConfig.fieldTransform : (_) => _;
|
|
9089
|
+
if (_lodash.isArray.call(void 0, fieldValue)) {
|
|
9090
|
+
return fieldTransform(await Promise.all(fieldValue.map(async (relationEntity) => {
|
|
9091
|
+
return this.transformEntity(relationEntity, {
|
|
9092
|
+
scopes: fieldConfig.relationScopes
|
|
9093
|
+
});
|
|
9094
|
+
})));
|
|
9095
|
+
}
|
|
9096
|
+
return fieldTransform(await this.transformEntity(fieldValue, {
|
|
9097
|
+
scopes: fieldConfig.relationScopes
|
|
9098
|
+
}));
|
|
9099
|
+
}
|
|
9087
9100
|
async transformEntity(entity, config) {
|
|
9088
9101
|
if (!entity) {
|
|
9089
9102
|
return entity;
|
|
@@ -9115,24 +9128,7 @@ var SerializerService = class {
|
|
|
9115
9128
|
const fieldName = fieldConfig.fieldName || fieldConfig.name;
|
|
9116
9129
|
let fieldValue = await entity[fieldConfig.name];
|
|
9117
9130
|
if (!_lodash.isNil.call(void 0, fieldConfig.relationScopes)) {
|
|
9118
|
-
|
|
9119
|
-
fieldValue = await Promise.all(fieldValue.map(async (relationEntity) => {
|
|
9120
|
-
let relationEntityFieldValue = await this.transformEntity(relationEntity, {
|
|
9121
|
-
scopes: fieldConfig.relationScopes
|
|
9122
|
-
});
|
|
9123
|
-
if (_lodash.isFunction.call(void 0, fieldConfig.fieldTransform)) {
|
|
9124
|
-
relationEntityFieldValue = await fieldConfig.fieldTransform(relationEntityFieldValue);
|
|
9125
|
-
}
|
|
9126
|
-
return relationEntityFieldValue;
|
|
9127
|
-
}));
|
|
9128
|
-
} else {
|
|
9129
|
-
fieldValue = await this.transformEntity(fieldValue, {
|
|
9130
|
-
scopes: fieldConfig.relationScopes
|
|
9131
|
-
});
|
|
9132
|
-
if (_lodash.isFunction.call(void 0, fieldConfig.fieldTransform)) {
|
|
9133
|
-
fieldValue = await fieldConfig.fieldTransform(fieldValue);
|
|
9134
|
-
}
|
|
9135
|
-
}
|
|
9131
|
+
fieldValue = await this.transformRelationEntity(fieldValue, fieldConfig);
|
|
9136
9132
|
} else {
|
|
9137
9133
|
if (_lodash.isFunction.call(void 0, fieldConfig.fieldTransform)) {
|
|
9138
9134
|
fieldValue = await fieldConfig.fieldTransform(fieldValue);
|