@hodfords/nestjs-response 10.0.0
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/README.md +80 -0
- package/constants/metadata.constant.d.ts +2 -0
- package/constants/metadata.constant.js +6 -0
- package/constants/metadata.constant.js.map +1 -0
- package/constants/native-class-response-names.constant.d.ts +1 -0
- package/constants/native-class-response-names.constant.js +5 -0
- package/constants/native-class-response-names.constant.js.map +1 -0
- package/decorators/response-model.decorator.d.ts +2 -0
- package/decorators/response-model.decorator.js +15 -0
- package/decorators/response-model.decorator.js.map +1 -0
- package/decorators/response-models.decorator.d.ts +2 -0
- package/decorators/response-models.decorator.js +20 -0
- package/decorators/response-models.decorator.js.map +1 -0
- package/decorators/use-response-interceptor.decorator.d.ts +1 -0
- package/decorators/use-response-interceptor.decorator.js +10 -0
- package/decorators/use-response-interceptor.decorator.js.map +1 -0
- package/exceptions/response-validate.exception.d.ts +5 -0
- package/exceptions/response-validate.exception.js +12 -0
- package/exceptions/response-validate.exception.js.map +1 -0
- package/index.d.ts +8 -0
- package/index.js +25 -0
- package/index.js.map +1 -0
- package/interceptors/response.interceptor.d.ts +22 -0
- package/interceptors/response.interceptor.js +197 -0
- package/interceptors/response.interceptor.js.map +1 -0
- package/package.json +95 -0
- package/responses/native-value.response.d.ts +5 -0
- package/responses/native-value.response.js +32 -0
- package/responses/native-value.response.js.map +1 -0
- package/types/handle-result.type.d.ts +5 -0
- package/types/handle-result.type.js +3 -0
- package/types/handle-result.type.js.map +1 -0
- package/types/response-metadata.type.d.ts +7 -0
- package/types/response-metadata.type.js +3 -0
- package/types/response-metadata.type.js.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
|
|
6
|
+
[circleci-url]: https://circleci.com/gh/nestjs/nest
|
|
7
|
+
|
|
8
|
+
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
|
11
|
+
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
|
12
|
+
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
|
|
13
|
+
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
|
|
14
|
+
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
|
|
15
|
+
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
|
|
16
|
+
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
|
17
|
+
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
|
18
|
+
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
|
|
19
|
+
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
|
|
20
|
+
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
|
|
21
|
+
</p>
|
|
22
|
+
<!--[](https://opencollective.com/nest#backer)
|
|
23
|
+
[](https://opencollective.com/nest#sponsor)-->
|
|
24
|
+
|
|
25
|
+
# nestjs-response
|
|
26
|
+
For response, use sync, not async.
|
|
27
|
+
|
|
28
|
+
## Installation 🤖
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
npm install @hodfords/nestjs-response --save
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
class UserResponse {
|
|
37
|
+
@ApiProperty()
|
|
38
|
+
@IsNotEmpty()
|
|
39
|
+
@IsString()
|
|
40
|
+
name: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
class UserController{
|
|
44
|
+
@Get()
|
|
45
|
+
@ResponseModel(UserResponse, true)
|
|
46
|
+
getAllUser() {
|
|
47
|
+
return [{name: "hello"}]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Get()
|
|
51
|
+
@ResponseModel(UserResponse, true, true)
|
|
52
|
+
getUser() {
|
|
53
|
+
return undefined
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
- `Interceptor global`
|
|
60
|
+
```javascript
|
|
61
|
+
{
|
|
62
|
+
providers: [
|
|
63
|
+
{
|
|
64
|
+
provide: APP_INTERCEPTOR,
|
|
65
|
+
useClass: LoggingInterceptor
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
- `Interceptor decorator`
|
|
72
|
+
|
|
73
|
+
This option is not recommended. Just use for microservice, let use global interceptor
|
|
74
|
+
```javascript
|
|
75
|
+
@Controller('test')
|
|
76
|
+
@UseResponseInterceptor()
|
|
77
|
+
export class TestController {
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
```
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RESPONSE_METADATA_KEYS = exports.RESPONSE_METADATA_KEY = void 0;
|
|
4
|
+
exports.RESPONSE_METADATA_KEY = 'response:class';
|
|
5
|
+
exports.RESPONSE_METADATA_KEYS = 'response:classes';
|
|
6
|
+
//# sourceMappingURL=metadata.constant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.constant.js","sourceRoot":"","sources":["../../../libs/constants/metadata.constant.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAG,gBAAgB,CAAC;AACzC,QAAA,sBAAsB,GAAG,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const NativeClassResponseNamesConstant: string[];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NativeClassResponseNamesConstant = void 0;
|
|
4
|
+
exports.NativeClassResponseNamesConstant = ['Boolean', 'String', 'Number'];
|
|
5
|
+
//# sourceMappingURL=native-class-response-names.constant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-class-response-names.constant.js","sourceRoot":"","sources":["../../../libs/constants/native-class-response-names.constant.ts"],"names":[],"mappings":";;;AAAa,QAAA,gCAAgC,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResponseModel = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
6
|
+
const metadata_constant_1 = require("../constants/metadata.constant");
|
|
7
|
+
function ResponseModel(responseClass, isArray = false, isAllowEmpty = false) {
|
|
8
|
+
return (0, common_1.applyDecorators)((0, swagger_1.ApiResponse)({ type: responseClass, isArray }), (0, common_1.SetMetadata)(metadata_constant_1.RESPONSE_METADATA_KEY, {
|
|
9
|
+
responseClass,
|
|
10
|
+
isArray,
|
|
11
|
+
isAllowEmpty
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
exports.ResponseModel = ResponseModel;
|
|
15
|
+
//# sourceMappingURL=response-model.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-model.decorator.js","sourceRoot":"","sources":["../../../libs/decorators/response-model.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA8D;AAC9D,6CAA8C;AAE9C,sEAAuE;AAEvE,SAAgB,aAAa,CACzB,aAAuC,EACvC,OAAO,GAAG,KAAK,EACf,YAAY,GAAG,KAAK;IAEpB,OAAO,IAAA,wBAAe,EAClB,IAAA,qBAAW,EAAC,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC,EAC7C,IAAA,oBAAW,EAAC,yCAAqB,EAAE;QAC/B,aAAa;QACb,OAAO;QACP,YAAY;KACf,CAAC,CACL,CAAC;AACN,CAAC;AAbD,sCAaC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResponseModels = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
6
|
+
const metadata_constant_1 = require("../constants/metadata.constant");
|
|
7
|
+
function ResponseModels(...responseClasses) {
|
|
8
|
+
const metadatas = responseClasses.map((metadata) => {
|
|
9
|
+
const isArray = Array.isArray(metadata);
|
|
10
|
+
const responseClass = isArray ? metadata[0] : metadata;
|
|
11
|
+
const isAllowEmpty = metadata === undefined || metadata === null;
|
|
12
|
+
return { isArray, responseClass, isAllowEmpty };
|
|
13
|
+
});
|
|
14
|
+
const models = metadatas.filter((metadata) => !metadata.isAllowEmpty).map((metadata) => metadata.responseClass);
|
|
15
|
+
return (0, common_1.applyDecorators)((0, swagger_1.ApiExtraModels)(...models), (0, swagger_1.ApiOkResponse)({
|
|
16
|
+
schema: { anyOf: (0, swagger_1.refs)(...models) }
|
|
17
|
+
}), (0, common_1.SetMetadata)(metadata_constant_1.RESPONSE_METADATA_KEYS, metadatas));
|
|
18
|
+
}
|
|
19
|
+
exports.ResponseModels = ResponseModels;
|
|
20
|
+
//# sourceMappingURL=response-models.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-models.decorator.js","sourceRoot":"","sources":["../../../libs/decorators/response-models.decorator.ts"],"names":[],"mappings":";;;AACA,2CAA8D;AAC9D,6CAAsE;AACtE,sEAAwE;AAExE,SAAgB,cAAc,CAAC,GAAG,eAAgC;IAC9D,MAAM,SAAS,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;QAC/C,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACxC,MAAM,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QACvD,MAAM,YAAY,GAAG,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,IAAI,CAAC;QACjE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC;IACpD,CAAC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;IAChH,OAAO,IAAA,wBAAe,EAClB,IAAA,wBAAc,EAAC,GAAG,MAAM,CAAC,EACzB,IAAA,uBAAa,EAAC;QACV,MAAM,EAAE,EAAE,KAAK,EAAE,IAAA,cAAI,EAAC,GAAG,MAAM,CAAC,EAAE;KACrC,CAAC,EACF,IAAA,oBAAW,EAAC,0CAAsB,EAAE,SAAS,CAAC,CACjD,CAAC;AACN,CAAC;AAfD,wCAeC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function UseResponseInterceptor(): MethodDecorator & ClassDecorator;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UseResponseInterceptor = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const response_interceptor_1 = require("../interceptors/response.interceptor");
|
|
6
|
+
function UseResponseInterceptor() {
|
|
7
|
+
return (0, common_1.UseInterceptors)(response_interceptor_1.ResponseInterceptor);
|
|
8
|
+
}
|
|
9
|
+
exports.UseResponseInterceptor = UseResponseInterceptor;
|
|
10
|
+
//# sourceMappingURL=use-response-interceptor.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-response-interceptor.decorator.js","sourceRoot":"","sources":["../../../libs/decorators/use-response-interceptor.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAiD;AACjD,+EAA2E;AAE3E,SAAgB,sBAAsB;IAClC,OAAO,IAAA,wBAAe,EAAC,0CAAmB,CAAC,CAAC;AAChD,CAAC;AAFD,wDAEC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResponseValidateException = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
class ResponseValidateException extends common_1.HttpException {
|
|
6
|
+
constructor(errors) {
|
|
7
|
+
super({}, common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
8
|
+
this.errors = errors;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.ResponseValidateException = ResponseValidateException;
|
|
12
|
+
//# sourceMappingURL=response-validate.exception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-validate.exception.js","sourceRoot":"","sources":["../../../libs/exceptions/response-validate.exception.ts"],"names":[],"mappings":";;;AAAA,2CAA2D;AAE3D,MAAa,yBAA0B,SAAQ,sBAAa;IACxD,YAAmB,MAAM;QACrB,KAAK,CAAC,EAAE,EAAE,mBAAU,CAAC,qBAAqB,CAAC,CAAC;QAD7B,WAAM,GAAN,MAAM,CAAA;IAEzB,CAAC;CACJ;AAJD,8DAIC"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './constants/metadata.constant';
|
|
2
|
+
export * from './decorators/response-model.decorator';
|
|
3
|
+
export * from './decorators/use-response-interceptor.decorator';
|
|
4
|
+
export * from './exceptions/response-validate.exception';
|
|
5
|
+
export * from './interceptors/response.interceptor';
|
|
6
|
+
export * from './types/response-metadata.type';
|
|
7
|
+
export * from './decorators/response-models.decorator';
|
|
8
|
+
export * from './types/handle-result.type';
|
package/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./constants/metadata.constant"), exports);
|
|
18
|
+
__exportStar(require("./decorators/response-model.decorator"), exports);
|
|
19
|
+
__exportStar(require("./decorators/use-response-interceptor.decorator"), exports);
|
|
20
|
+
__exportStar(require("./exceptions/response-validate.exception"), exports);
|
|
21
|
+
__exportStar(require("./interceptors/response.interceptor"), exports);
|
|
22
|
+
__exportStar(require("./types/response-metadata.type"), exports);
|
|
23
|
+
__exportStar(require("./decorators/response-models.decorator"), exports);
|
|
24
|
+
__exportStar(require("./types/handle-result.type"), exports);
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../libs/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA8C;AAC9C,wEAAsD;AACtD,kFAAgE;AAChE,2EAAyD;AACzD,sEAAoD;AACpD,iEAA+C;AAC/C,yEAAuD;AACvD,6DAA2C"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { ResponseMetadata } from '../types/response-metadata.type';
|
|
4
|
+
export declare class ResponseInterceptor implements NestInterceptor {
|
|
5
|
+
private readonly logger;
|
|
6
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
7
|
+
handleResponse(context: ExecutionContext, data: any): any;
|
|
8
|
+
handleOneTypeResponse(context: ExecutionContext, data: any, responseMetadata: ResponseMetadata): any;
|
|
9
|
+
handleMultiTypeResponse(context: ExecutionContext, data: any, responseMetadatas: ResponseMetadata[]): any;
|
|
10
|
+
handleSingleResponse(responseMetadata: ResponseMetadata, data: any): any;
|
|
11
|
+
handleListResponse(context: ExecutionContext, responseMetadata: ResponseMetadata, data: any): object[] | {
|
|
12
|
+
items: object[];
|
|
13
|
+
grpcArray: boolean;
|
|
14
|
+
};
|
|
15
|
+
handleEmptyResponse(responseMetadata: ResponseMetadata, data: any): any;
|
|
16
|
+
private handleNativeValueResponse;
|
|
17
|
+
private getResponseMap;
|
|
18
|
+
private filterResponseMetadatas;
|
|
19
|
+
private getArrayTypeMetadata;
|
|
20
|
+
private getEmptyTypeMetadata;
|
|
21
|
+
private getObjectTypeMetadata;
|
|
22
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var ResponseInterceptor_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ResponseInterceptor = void 0;
|
|
11
|
+
const native_class_response_names_constant_1 = require("./../constants/native-class-response-names.constant");
|
|
12
|
+
const common_1 = require("@nestjs/common");
|
|
13
|
+
const class_transformer_1 = require("class-transformer");
|
|
14
|
+
const class_validator_1 = require("class-validator");
|
|
15
|
+
const rxjs_1 = require("rxjs");
|
|
16
|
+
const metadata_constant_1 = require("../constants/metadata.constant");
|
|
17
|
+
const response_validate_exception_1 = require("../exceptions/response-validate.exception");
|
|
18
|
+
const native_value_response_1 = require("../responses/native-value.response");
|
|
19
|
+
let Metadata = null;
|
|
20
|
+
try {
|
|
21
|
+
const grpc = require('@grpc/grpc-js');
|
|
22
|
+
Metadata = grpc.Metadata;
|
|
23
|
+
}
|
|
24
|
+
catch (ex) { }
|
|
25
|
+
let ResponseInterceptor = ResponseInterceptor_1 = class ResponseInterceptor {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.logger = new common_1.Logger(ResponseInterceptor_1.name);
|
|
28
|
+
}
|
|
29
|
+
intercept(context, next) {
|
|
30
|
+
return next.handle().pipe((0, rxjs_1.map)((data) => this.handleResponse(context, data)));
|
|
31
|
+
}
|
|
32
|
+
handleResponse(context, data) {
|
|
33
|
+
const responseMetadata = Reflect.getMetadata(metadata_constant_1.RESPONSE_METADATA_KEY, context.getHandler());
|
|
34
|
+
const responseMetadatas = Reflect.getMetadata(metadata_constant_1.RESPONSE_METADATA_KEYS, context.getHandler());
|
|
35
|
+
if (responseMetadata) {
|
|
36
|
+
return this.handleMultiTypeResponse(context, data, [responseMetadata]);
|
|
37
|
+
}
|
|
38
|
+
if (responseMetadatas && responseMetadatas.length > 0) {
|
|
39
|
+
return this.handleMultiTypeResponse(context, data, responseMetadatas);
|
|
40
|
+
}
|
|
41
|
+
return data;
|
|
42
|
+
}
|
|
43
|
+
handleOneTypeResponse(context, data, responseMetadata) {
|
|
44
|
+
if (!(0, class_validator_1.isBoolean)(data) && !data) {
|
|
45
|
+
return this.handleEmptyResponse(responseMetadata, data);
|
|
46
|
+
}
|
|
47
|
+
if (responseMetadata.isArray) {
|
|
48
|
+
return this.handleListResponse(context, responseMetadata, data);
|
|
49
|
+
}
|
|
50
|
+
return this.handleSingleResponse(responseMetadata, data);
|
|
51
|
+
}
|
|
52
|
+
handleMultiTypeResponse(context, data, responseMetadatas) {
|
|
53
|
+
const results = [];
|
|
54
|
+
const newMetadatas = this.filterResponseMetadatas(responseMetadatas, data);
|
|
55
|
+
for (const metadata of newMetadatas) {
|
|
56
|
+
try {
|
|
57
|
+
const result = this.handleOneTypeResponse(context, data, metadata);
|
|
58
|
+
results.push({ data: result, error: null });
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
const newError = error.errors ? error.errors : error;
|
|
62
|
+
results.push({ data: null, error: newError });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const resultValid = results.find((result) => result.error === null);
|
|
66
|
+
if (resultValid) {
|
|
67
|
+
return resultValid.data;
|
|
68
|
+
}
|
|
69
|
+
const errors = results.map((result) => result.error);
|
|
70
|
+
this.logger.error(errors);
|
|
71
|
+
throw new response_validate_exception_1.ResponseValidateException(errors);
|
|
72
|
+
}
|
|
73
|
+
handleSingleResponse(responseMetadata, data) {
|
|
74
|
+
if (native_class_response_names_constant_1.NativeClassResponseNamesConstant.includes(responseMetadata.responseClass.name)) {
|
|
75
|
+
return this.handleNativeValueResponse(responseMetadata, data);
|
|
76
|
+
}
|
|
77
|
+
const newData = (0, class_transformer_1.plainToInstance)(responseMetadata.responseClass, data);
|
|
78
|
+
const errors = (0, class_validator_1.validateSync)(newData, {
|
|
79
|
+
whitelist: true,
|
|
80
|
+
stopAtFirstError: true
|
|
81
|
+
});
|
|
82
|
+
if (errors.length) {
|
|
83
|
+
throw new response_validate_exception_1.ResponseValidateException(errors);
|
|
84
|
+
}
|
|
85
|
+
return (0, class_transformer_1.plainToInstance)(responseMetadata.responseClass, data);
|
|
86
|
+
}
|
|
87
|
+
handleListResponse(context, responseMetadata, data) {
|
|
88
|
+
const newData = [];
|
|
89
|
+
for (const item of data) {
|
|
90
|
+
const newItem = this.handleSingleResponse(responseMetadata, item);
|
|
91
|
+
newData.push(newItem);
|
|
92
|
+
}
|
|
93
|
+
if (Metadata && context.switchToRpc().getContext() instanceof Metadata) {
|
|
94
|
+
return { items: newData, grpcArray: true };
|
|
95
|
+
}
|
|
96
|
+
return newData;
|
|
97
|
+
}
|
|
98
|
+
handleEmptyResponse(responseMetadata, data) {
|
|
99
|
+
if (responseMetadata.isAllowEmpty) {
|
|
100
|
+
return data;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
throw new response_validate_exception_1.ResponseValidateException([
|
|
104
|
+
{
|
|
105
|
+
target: data,
|
|
106
|
+
children: [],
|
|
107
|
+
constraints: {
|
|
108
|
+
nullValue: 'an null value was passed to the validate function'
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
]);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
handleNativeValueResponse(responseMetadata, data) {
|
|
115
|
+
const responseMap = this.getResponseMap(responseMetadata, data);
|
|
116
|
+
const newData = (0, class_transformer_1.plainToInstance)(native_value_response_1.NativeValueResponse, responseMap);
|
|
117
|
+
const errors = (0, class_validator_1.validateSync)(newData, {
|
|
118
|
+
whitelist: true,
|
|
119
|
+
stopAtFirstError: true
|
|
120
|
+
});
|
|
121
|
+
if (errors.length) {
|
|
122
|
+
throw new response_validate_exception_1.ResponseValidateException(errors);
|
|
123
|
+
}
|
|
124
|
+
return data;
|
|
125
|
+
}
|
|
126
|
+
getResponseMap(responseMetadata, data) {
|
|
127
|
+
switch (responseMetadata.responseClass.name) {
|
|
128
|
+
case 'Boolean':
|
|
129
|
+
return { ['boolean']: data };
|
|
130
|
+
case 'String':
|
|
131
|
+
return { ['string']: data };
|
|
132
|
+
case 'Number':
|
|
133
|
+
return { ['number']: data };
|
|
134
|
+
default:
|
|
135
|
+
return {};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
filterResponseMetadatas(responseMetadatas, data) {
|
|
139
|
+
if (Array.isArray(data)) {
|
|
140
|
+
return this.getArrayTypeMetadata(responseMetadatas, data);
|
|
141
|
+
}
|
|
142
|
+
if (!(0, class_validator_1.isBoolean)(data) && !data) {
|
|
143
|
+
return this.getEmptyTypeMetadata(responseMetadatas, data);
|
|
144
|
+
}
|
|
145
|
+
return this.getObjectTypeMetadata(responseMetadatas, data);
|
|
146
|
+
}
|
|
147
|
+
getArrayTypeMetadata(responseMetadatas, data) {
|
|
148
|
+
const arrayTypes = responseMetadatas.filter((metadata) => metadata.isArray);
|
|
149
|
+
if (arrayTypes.length == 0) {
|
|
150
|
+
throw new response_validate_exception_1.ResponseValidateException([
|
|
151
|
+
{
|
|
152
|
+
target: data,
|
|
153
|
+
children: [],
|
|
154
|
+
constraints: {
|
|
155
|
+
arrayValue: 'an array value was passed to the validate function'
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
]);
|
|
159
|
+
}
|
|
160
|
+
return arrayTypes;
|
|
161
|
+
}
|
|
162
|
+
getEmptyTypeMetadata(responseMetadatas, data) {
|
|
163
|
+
const emptyType = responseMetadatas.find((metadata) => metadata.isAllowEmpty);
|
|
164
|
+
if (emptyType) {
|
|
165
|
+
return [emptyType];
|
|
166
|
+
}
|
|
167
|
+
throw new response_validate_exception_1.ResponseValidateException([
|
|
168
|
+
{
|
|
169
|
+
target: data,
|
|
170
|
+
children: [],
|
|
171
|
+
constraints: {
|
|
172
|
+
arrayValue: 'an empty value was passed to the validate function'
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
]);
|
|
176
|
+
}
|
|
177
|
+
getObjectTypeMetadata(responseMetadatas, data) {
|
|
178
|
+
const objectTypes = responseMetadatas.filter((metadata) => !metadata.isArray);
|
|
179
|
+
if (objectTypes.length == 0) {
|
|
180
|
+
throw new response_validate_exception_1.ResponseValidateException([
|
|
181
|
+
{
|
|
182
|
+
target: data,
|
|
183
|
+
children: [],
|
|
184
|
+
constraints: {
|
|
185
|
+
arrayValue: 'an object value was passed to the validate function'
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
]);
|
|
189
|
+
}
|
|
190
|
+
return objectTypes;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
exports.ResponseInterceptor = ResponseInterceptor;
|
|
194
|
+
exports.ResponseInterceptor = ResponseInterceptor = ResponseInterceptor_1 = __decorate([
|
|
195
|
+
(0, common_1.Injectable)()
|
|
196
|
+
], ResponseInterceptor);
|
|
197
|
+
//# sourceMappingURL=response.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.interceptor.js","sourceRoot":"","sources":["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Q,CAAC,YAAY,CAAC,CAAC;QAC9E,IAAI,SAAS,EAAE,CAAC;YACZ,OAAO,CAAC,SAAS,CAAC,CAAC;QACvB,CAAC;QACD,MAAM,IAAI,uDAAyB,CAAC;YAChC;gBACI,MAAM,EAAE,IAAI;gBACZ,QAAQ,EAAE,EAAE;gBACZ,WAAW,EAAE;oBACT,UAAU,EAAE,oDAAoD;iBACnE;aACJ;SACJ,CAAC,CAAC;IACP,CAAC;IAEO,qBAAqB,CAAC,iBAAqC,EAAE,IAAS;QAC1E,MAAM,WAAW,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC9E,IAAI,WAAW,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,uDAAyB,CAAC;gBAChC;oBACI,MAAM,EAAE,IAAI;oBACZ,QAAQ,EAAE,EAAE;oBACZ,WAAW,EAAE;wBACT,UAAU,EAAE,qDAAqD;qBACpE;iBACJ;aACJ,CAAC,CAAC;QACP,CAAC;QACD,OAAO,WAAW,CAAC;IACvB,CAAC;CACJ,CAAA;AAlLY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;GACA,mBAAmB,CAkL/B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hodfords/nestjs-response",
|
|
3
|
+
"version": "10.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"author": "",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/hodfords-solutions/nestjs-response.git"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"prebuild": "rimraf dist",
|
|
13
|
+
"build": "nest build",
|
|
14
|
+
"postbuild": "cp package.json dist/libs/package.json",
|
|
15
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"libs/**/*.ts\"",
|
|
16
|
+
"start": "nest start",
|
|
17
|
+
"start:dev": "npm run prebuild && nest start --watch",
|
|
18
|
+
"start:debug": "nest start --debug --watch",
|
|
19
|
+
"start:prod": "node dist/main",
|
|
20
|
+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
|
21
|
+
"test": "jest",
|
|
22
|
+
"test:watch": "jest --watch",
|
|
23
|
+
"test:cov": "jest --coverage",
|
|
24
|
+
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
|
25
|
+
"test:e2e": "jest --config ./test/jest-e2e.json",
|
|
26
|
+
"wz-command": "wz-command",
|
|
27
|
+
"prepare": "is-ci || husky install",
|
|
28
|
+
"version": "auto-changelog && git add CHANGELOG.md",
|
|
29
|
+
"release:patch": "git add CHANGELOG.md && npm version patch --tag-version-prefix='' -f -m 'chore: release to %s'",
|
|
30
|
+
"release:push": "git push --no-verify && git push --tags --no-verify",
|
|
31
|
+
"lint-staged": "lint-staged",
|
|
32
|
+
"cspell": "cspell"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@nestjs/cli": "10.3.0",
|
|
36
|
+
"@nestjs/common": "10.3.1",
|
|
37
|
+
"@nestjs/core": "10.3.1",
|
|
38
|
+
"@nestjs/platform-express": "10.3.1",
|
|
39
|
+
"@nestjs/schematics": "10.1.0",
|
|
40
|
+
"@nestjs/swagger": "7.2.0",
|
|
41
|
+
"@nestjs/testing": "10.3.1",
|
|
42
|
+
"@types/express": "4.17.21",
|
|
43
|
+
"@types/jest": "29.5.11",
|
|
44
|
+
"@types/node": "20.11.10",
|
|
45
|
+
"@types/supertest": "2.0.16",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "6.20.0",
|
|
47
|
+
"@typescript-eslint/parser": "6.20.0",
|
|
48
|
+
"auto-changelog": "2.4.0",
|
|
49
|
+
"class-transformer": "0.5.1",
|
|
50
|
+
"class-validator": "0.14.0",
|
|
51
|
+
"cspell": "8.3.2",
|
|
52
|
+
"eslint": "8.56.0",
|
|
53
|
+
"eslint-config-prettier": "9.1.0",
|
|
54
|
+
"eslint-plugin-prettier": "5.1.3",
|
|
55
|
+
"husky": "8.0.3",
|
|
56
|
+
"is-ci": "3.0.1",
|
|
57
|
+
"jest": "29.7.0",
|
|
58
|
+
"lint-staged": "15.2.0",
|
|
59
|
+
"prettier": "3.2.4",
|
|
60
|
+
"reflect-metadata": "0.1.13",
|
|
61
|
+
"rimraf": "5.0.5",
|
|
62
|
+
"rxjs": "7.8.1",
|
|
63
|
+
"source-map-support": "0.5.21",
|
|
64
|
+
"supertest": "6.3.4",
|
|
65
|
+
"ts-jest": "29.1.2",
|
|
66
|
+
"ts-loader": "9.5.1",
|
|
67
|
+
"ts-node": "10.9.2",
|
|
68
|
+
"tsconfig-paths": "4.2.0",
|
|
69
|
+
"typescript": "5.3.3"
|
|
70
|
+
},
|
|
71
|
+
"jest": {
|
|
72
|
+
"moduleFileExtensions": [
|
|
73
|
+
"js",
|
|
74
|
+
"json",
|
|
75
|
+
"ts"
|
|
76
|
+
],
|
|
77
|
+
"rootDir": ".",
|
|
78
|
+
"testRegex": ".*\\.spec\\.ts$",
|
|
79
|
+
"transform": {
|
|
80
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
|
81
|
+
},
|
|
82
|
+
"collectCoverageFrom": [
|
|
83
|
+
"**/*.(t|j)s"
|
|
84
|
+
],
|
|
85
|
+
"coverageDirectory": "./coverage",
|
|
86
|
+
"testEnvironment": "node",
|
|
87
|
+
"roots": [
|
|
88
|
+
"<rootDir>/src/",
|
|
89
|
+
"<rootDir>/libs/"
|
|
90
|
+
],
|
|
91
|
+
"moduleNameMapper": {
|
|
92
|
+
"^@hodfords/nestjs-response(|/.*)$": "<rootDir>/libs/nestjs-response/src/$1"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.NativeValueResponse = void 0;
|
|
13
|
+
const class_validator_1 = require("class-validator");
|
|
14
|
+
class NativeValueResponse {
|
|
15
|
+
}
|
|
16
|
+
exports.NativeValueResponse = NativeValueResponse;
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, class_validator_1.IsOptional)(),
|
|
19
|
+
(0, class_validator_1.IsString)(),
|
|
20
|
+
__metadata("design:type", String)
|
|
21
|
+
], NativeValueResponse.prototype, "string", void 0);
|
|
22
|
+
__decorate([
|
|
23
|
+
(0, class_validator_1.IsOptional)(),
|
|
24
|
+
(0, class_validator_1.IsNumber)(),
|
|
25
|
+
__metadata("design:type", Number)
|
|
26
|
+
], NativeValueResponse.prototype, "number", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, class_validator_1.IsOptional)(),
|
|
29
|
+
(0, class_validator_1.IsBoolean)(),
|
|
30
|
+
__metadata("design:type", Boolean)
|
|
31
|
+
], NativeValueResponse.prototype, "boolean", void 0);
|
|
32
|
+
//# sourceMappingURL=native-value.response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-value.response.js","sourceRoot":"","sources":["../../../libs/responses/native-value.response.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAA4E;AAE5E,MAAa,mBAAmB;CAY/B;AAZD,kDAYC;AATG;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;mDACI;AAIf;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;mDACI;AAIf;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;oDACK"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-result.type.js","sourceRoot":"","sources":["../../../libs/types/handle-result.type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-metadata.type.js","sourceRoot":"","sources":["../../../libs/types/response-metadata.type.ts"],"names":[],"mappings":""}
|