@iamnnort/nestjs-serializer 1.1.7 → 1.1.9
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 +11 -9
- package/dist/index.d.ts +11 -9
- package/dist/index.js +17 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -14,15 +14,16 @@ declare const SerializeRelation: (configs: {
|
|
|
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) => 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
|
@@ -14,15 +14,16 @@ declare const SerializeRelation: (configs: {
|
|
|
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) => 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
|
@@ -9062,6 +9062,9 @@ var SerializerService = class {
|
|
|
9062
9062
|
this.globalEntityNames = config.globalEntityNames || [];
|
|
9063
9063
|
}
|
|
9064
9064
|
async transform(response, config) {
|
|
9065
|
+
if (!response) {
|
|
9066
|
+
return response;
|
|
9067
|
+
}
|
|
9065
9068
|
if (!config.scopes && !config.fields) {
|
|
9066
9069
|
return response;
|
|
9067
9070
|
}
|
|
@@ -9081,6 +9084,19 @@ var SerializerService = class {
|
|
|
9081
9084
|
const transformedEntity = await this.transformEntity(response, config);
|
|
9082
9085
|
return transformedEntity;
|
|
9083
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
|
+
}
|
|
9084
9100
|
async transformEntity(entity, config) {
|
|
9085
9101
|
if (!entity) {
|
|
9086
9102
|
return entity;
|
|
@@ -9112,24 +9128,7 @@ var SerializerService = class {
|
|
|
9112
9128
|
const fieldName = fieldConfig.fieldName || fieldConfig.name;
|
|
9113
9129
|
let fieldValue = await entity[fieldConfig.name];
|
|
9114
9130
|
if (!_lodash.isNil.call(void 0, fieldConfig.relationScopes)) {
|
|
9115
|
-
|
|
9116
|
-
fieldValue = await Promise.all(fieldValue.map(async (relationEntity) => {
|
|
9117
|
-
let relationEntityFieldValue = await this.transformEntity(relationEntity, {
|
|
9118
|
-
scopes: fieldConfig.relationScopes
|
|
9119
|
-
});
|
|
9120
|
-
if (_lodash.isFunction.call(void 0, fieldConfig.fieldTransform)) {
|
|
9121
|
-
relationEntityFieldValue = await fieldConfig.fieldTransform(relationEntityFieldValue);
|
|
9122
|
-
}
|
|
9123
|
-
return relationEntityFieldValue;
|
|
9124
|
-
}));
|
|
9125
|
-
} else {
|
|
9126
|
-
fieldValue = await this.transformEntity(fieldValue, {
|
|
9127
|
-
scopes: fieldConfig.relationScopes
|
|
9128
|
-
});
|
|
9129
|
-
if (_lodash.isFunction.call(void 0, fieldConfig.fieldTransform)) {
|
|
9130
|
-
fieldValue = await fieldConfig.fieldTransform(fieldValue);
|
|
9131
|
-
}
|
|
9132
|
-
}
|
|
9131
|
+
fieldValue = await this.transformRelationEntity(fieldValue, fieldConfig);
|
|
9133
9132
|
} else {
|
|
9134
9133
|
if (_lodash.isFunction.call(void 0, fieldConfig.fieldTransform)) {
|
|
9135
9134
|
fieldValue = await fieldConfig.fieldTransform(fieldValue);
|