@hg-ts/http-controller 0.3.4 → 0.4.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/dist/decorators/decorators.js +12 -16
- package/dist/decorators/decorators.js.map +1 -1
- package/dist/decorators/index.d.ts +1 -1
- package/dist/decorators/index.d.ts.map +1 -1
- package/dist/decorators/index.js +1 -4
- package/dist/decorators/index.js.map +1 -1
- package/dist/exceptions/exception-schema-already-exists.exception.js +2 -6
- package/dist/exceptions/exception-schema-already-exists.exception.js.map +1 -1
- package/dist/exceptions/exception-schema-not-found.exception.js +2 -6
- package/dist/exceptions/exception-schema-not-found.exception.js.map +1 -1
- package/dist/exceptions/exception-status-already-defined.exception.js +2 -6
- package/dist/exceptions/exception-status-already-defined.exception.js.map +1 -1
- package/dist/exceptions/index.d.ts +3 -3
- package/dist/exceptions/index.d.ts.map +1 -1
- package/dist/exceptions/index.js +3 -6
- package/dist/exceptions/index.js.map +1 -1
- package/dist/http-controller.module.js +15 -18
- package/dist/http-controller.module.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -10
- package/dist/index.js.map +1 -1
- package/dist/middlewares/database.interceptor.js +17 -20
- package/dist/middlewares/database.interceptor.js.map +1 -1
- package/dist/middlewares/exception-mapper.interceptor.js +22 -25
- package/dist/middlewares/exception-mapper.interceptor.js.map +1 -1
- package/dist/middlewares/index.d.ts +3 -3
- package/dist/middlewares/index.d.ts.map +1 -1
- package/dist/middlewares/index.js +3 -6
- package/dist/middlewares/index.js.map +1 -1
- package/dist/middlewares/validation.pipe.js +4 -9
- package/dist/middlewares/validation.pipe.js.map +1 -1
- package/dist/services/exception.service.js +4 -8
- package/dist/services/exception.service.js.map +1 -1
- package/dist/services/index.d.ts +2 -2
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +2 -5
- package/dist/services/index.js.map +1 -1
- package/dist/services/swagger.service.js +12 -16
- package/dist/services/swagger.service.js.map +1 -1
- package/dist/tests/abstracts/base-controller-suite.js +11 -16
- package/dist/tests/abstracts/base-controller-suite.js.map +1 -1
- package/dist/tests/abstracts/index.d.ts +1 -1
- package/dist/tests/abstracts/index.d.ts.map +1 -1
- package/dist/tests/abstracts/index.js +1 -4
- package/dist/tests/abstracts/index.js.map +1 -1
- package/dist/tests/echo/controllers/dto/echo-get.query.js +3 -7
- package/dist/tests/echo/controllers/dto/echo-get.query.js.map +1 -1
- package/dist/tests/echo/controllers/dto/echo-post.body.js +3 -7
- package/dist/tests/echo/controllers/dto/echo-post.body.js.map +1 -1
- package/dist/tests/echo/controllers/dto/index.d.ts +2 -2
- package/dist/tests/echo/controllers/dto/index.d.ts.map +1 -1
- package/dist/tests/echo/controllers/dto/index.js +2 -5
- package/dist/tests/echo/controllers/dto/index.js.map +1 -1
- package/dist/tests/echo/controllers/echo.controller.d.ts +1 -1
- package/dist/tests/echo/controllers/echo.controller.d.ts.map +1 -1
- package/dist/tests/echo/controllers/echo.controller.js +32 -35
- package/dist/tests/echo/controllers/echo.controller.js.map +1 -1
- package/dist/tests/echo/controllers/index.d.ts +1 -1
- package/dist/tests/echo/controllers/index.d.ts.map +1 -1
- package/dist/tests/echo/controllers/index.js +1 -4
- package/dist/tests/echo/controllers/index.js.map +1 -1
- package/dist/tests/echo/echo.test.d.ts +1 -1
- package/dist/tests/echo/echo.test.d.ts.map +1 -1
- package/dist/tests/echo/echo.test.js +46 -49
- package/dist/tests/echo/echo.test.js.map +1 -1
- package/dist/tests/echo/echo.test.module.js +6 -9
- package/dist/tests/echo/echo.test.module.js.map +1 -1
- package/dist/tests/exception/controllers/dtos/common-exception.dto.js +7 -11
- package/dist/tests/exception/controllers/dtos/common-exception.dto.js.map +1 -1
- package/dist/tests/exception/controllers/dtos/index.d.ts +1 -1
- package/dist/tests/exception/controllers/dtos/index.d.ts.map +1 -1
- package/dist/tests/exception/controllers/dtos/index.js +1 -4
- package/dist/tests/exception/controllers/dtos/index.js.map +1 -1
- package/dist/tests/exception/controllers/exception.controller.js +19 -22
- package/dist/tests/exception/controllers/exception.controller.js.map +1 -1
- package/dist/tests/exception/controllers/index.d.ts +1 -1
- package/dist/tests/exception/controllers/index.d.ts.map +1 -1
- package/dist/tests/exception/controllers/index.js +1 -4
- package/dist/tests/exception/controllers/index.js.map +1 -1
- package/dist/tests/exception/exception.test.d.ts +1 -1
- package/dist/tests/exception/exception.test.d.ts.map +1 -1
- package/dist/tests/exception/exception.test.js +20 -23
- package/dist/tests/exception/exception.test.js.map +1 -1
- package/dist/tests/exception/exception.test.module.js +6 -9
- package/dist/tests/exception/exception.test.module.js.map +1 -1
- package/dist/tests/exception/exceptions/index.d.ts +2 -2
- package/dist/tests/exception/exceptions/index.d.ts.map +1 -1
- package/dist/tests/exception/exceptions/index.js +2 -5
- package/dist/tests/exception/exceptions/index.js.map +1 -1
- package/dist/tests/exception/exceptions/mock-conflict.exception.js +2 -6
- package/dist/tests/exception/exceptions/mock-conflict.exception.js.map +1 -1
- package/dist/tests/exception/exceptions/mock-not-found.exception.js +2 -6
- package/dist/tests/exception/exceptions/mock-not-found.exception.js.map +1 -1
- package/dist/tests/http-methods/controllers/empty-response.controller.js +57 -60
- package/dist/tests/http-methods/controllers/empty-response.controller.js.map +1 -1
- package/dist/tests/http-methods/controllers/index.d.ts +1 -1
- package/dist/tests/http-methods/controllers/index.d.ts.map +1 -1
- package/dist/tests/http-methods/controllers/index.js +1 -4
- package/dist/tests/http-methods/controllers/index.js.map +1 -1
- package/dist/tests/http-methods/http-methods.test.d.ts +1 -1
- package/dist/tests/http-methods/http-methods.test.d.ts.map +1 -1
- package/dist/tests/http-methods/http-methods.test.js +62 -65
- package/dist/tests/http-methods/http-methods.test.js.map +1 -1
- package/dist/tests/http-methods/http-methods.test.module.js +6 -9
- package/dist/tests/http-methods/http-methods.test.module.js.map +1 -1
- package/dist/types.js +2 -5
- package/dist/types.js.map +1 -1
- package/package.json +16 -15
- package/tsconfig.json +1 -1
|
@@ -1,34 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const services_1 = require("../services");
|
|
8
|
-
exports.EXCEPTION_METADATA_KEY = Symbol('EXCEPTION_METADATA_KEY');
|
|
9
|
-
class Http {
|
|
1
|
+
import { createSchema } from '@hg-ts/validation';
|
|
2
|
+
import { ApiResponse } from '@nestjs/swagger';
|
|
3
|
+
import { ExceptionStatusAlreadyDefinedException } from '../exceptions/index.js';
|
|
4
|
+
import { ExceptionService } from '../services/index.js';
|
|
5
|
+
export const EXCEPTION_METADATA_KEY = Symbol('EXCEPTION_METADATA_KEY');
|
|
6
|
+
export class Http {
|
|
10
7
|
constructor() { }
|
|
11
8
|
static ExceptionStatus(exception, statusCode) {
|
|
12
9
|
return (target, propertyKey, descriptor) => {
|
|
13
|
-
const statusMap = Reflect.getMetadata(
|
|
10
|
+
const statusMap = Reflect.getMetadata(EXCEPTION_METADATA_KEY, target, propertyKey) ?? new Map();
|
|
14
11
|
if (statusMap.has(exception)) {
|
|
15
|
-
throw new
|
|
12
|
+
throw new ExceptionStatusAlreadyDefinedException(exception);
|
|
16
13
|
}
|
|
17
14
|
statusMap.set(exception, statusCode);
|
|
18
|
-
Reflect.defineMetadata(
|
|
15
|
+
Reflect.defineMetadata(EXCEPTION_METADATA_KEY, statusMap, target, propertyKey);
|
|
19
16
|
const exceptionVariants = [...statusMap.entries()];
|
|
20
17
|
const schemas = exceptionVariants
|
|
21
18
|
.filter(([, exceptionStatusCode]) => exceptionStatusCode === statusCode)
|
|
22
|
-
.map(([item]) =>
|
|
19
|
+
.map(([item]) => ExceptionService.getSchema(item))
|
|
23
20
|
.map(item => item.schema)
|
|
24
|
-
.map(item =>
|
|
21
|
+
.map(item => createSchema(item, { io: 'input' }))
|
|
25
22
|
.map(item => item.schema);
|
|
26
|
-
|
|
23
|
+
ApiResponse({
|
|
27
24
|
schema: schemas.length === 1 ? schemas[0] : { oneOf: schemas },
|
|
28
25
|
status: statusCode,
|
|
29
26
|
})(target, propertyKey, descriptor);
|
|
30
27
|
};
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
|
-
exports.Http = Http;
|
|
34
30
|
//# sourceMappingURL=decorators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/decorators/decorators.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/decorators/decorators.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,sCAAsC,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAIxD,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAC;AAEvE,MAAM,OAAO,IAAI;IAChB,gBAAuB,CAAC;IAEjB,MAAM,CAAC,eAAe,CAAC,SAAsC,EAAE,UAAkB;QACvF,OAAO,CAAC,MAAW,EAAE,WAA4B,EAAE,UAA8B,EAAE,EAAE;YACpF,MAAM,SAAS,GACd,OAAO,CAAC,WAAW,CAAC,sBAAsB,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC;YAE/E,IAAI,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC9B,MAAM,IAAI,sCAAsC,CAAC,SAAS,CAAC,CAAC;YAC7D,CAAC;YAED,SAAS,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;YACrC,OAAO,CAAC,cAAc,CAAC,sBAAsB,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;YAE/E,MAAM,iBAAiB,GAAG,CAAC,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;YAEnD,MAAM,OAAO,GAAG,iBAAiB;iBAC/B,MAAM,CAAC,CAAC,CAAC,EAAE,mBAAmB,CAAC,EAAE,EAAE,CAAC,mBAAmB,KAAK,UAAU,CAAC;iBACvE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;iBACjD,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC;iBACxB,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;iBAChD,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAa,CAAC,CAAC;YAElC,WAAW,CAAC;gBACX,MAAM,EAAE,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE;gBAC9D,MAAM,EAAE,UAAU;aAClB,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;QACrC,CAAC,CAAC;IACH,CAAC;CACD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './decorators';
|
|
1
|
+
export * from './decorators.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
package/dist/decorators/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ExceptionSchemaAlreadyExistsException = void 0;
|
|
4
|
-
const exception_1 = require("@hg-ts/exception");
|
|
5
|
-
class ExceptionSchemaAlreadyExistsException extends exception_1.BaseException {
|
|
1
|
+
import { BaseException } from '@hg-ts/exception';
|
|
2
|
+
export class ExceptionSchemaAlreadyExistsException extends BaseException {
|
|
6
3
|
constructor(exception) {
|
|
7
4
|
super(`Schema for exception "${exception.name}" already exists`);
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
exports.ExceptionSchemaAlreadyExistsException = ExceptionSchemaAlreadyExistsException;
|
|
11
7
|
//# sourceMappingURL=exception-schema-already-exists.exception.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exception-schema-already-exists.exception.js","sourceRoot":"","sources":["../../src/exceptions/exception-schema-already-exists.exception.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"exception-schema-already-exists.exception.js","sourceRoot":"","sources":["../../src/exceptions/exception-schema-already-exists.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,OAAO,qCAAsC,SAAQ,aAAa;IACvE,YAAmB,SAAsC;QACxD,KAAK,CAAC,yBAAyB,SAAS,CAAC,IAAI,kBAAkB,CAAC,CAAC;IAClE,CAAC;CACD"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ExceptionSchemaNotFoundException = void 0;
|
|
4
|
-
const exception_1 = require("@hg-ts/exception");
|
|
5
|
-
class ExceptionSchemaNotFoundException extends exception_1.BaseException {
|
|
1
|
+
import { BaseException } from '@hg-ts/exception';
|
|
2
|
+
export class ExceptionSchemaNotFoundException extends BaseException {
|
|
6
3
|
constructor(exception) {
|
|
7
4
|
super(`Schema for exception "${exception.name}" not found`);
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
exports.ExceptionSchemaNotFoundException = ExceptionSchemaNotFoundException;
|
|
11
7
|
//# sourceMappingURL=exception-schema-not-found.exception.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exception-schema-not-found.exception.js","sourceRoot":"","sources":["../../src/exceptions/exception-schema-not-found.exception.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"exception-schema-not-found.exception.js","sourceRoot":"","sources":["../../src/exceptions/exception-schema-not-found.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,OAAO,gCAAiC,SAAQ,aAAa;IAClE,YAAmB,SAAsC;QACxD,KAAK,CAAC,yBAAyB,SAAS,CAAC,IAAI,aAAa,CAAC,CAAC;IAC7D,CAAC;CACD"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ExceptionStatusAlreadyDefinedException = void 0;
|
|
4
|
-
const exception_1 = require("@hg-ts/exception");
|
|
5
|
-
class ExceptionStatusAlreadyDefinedException extends exception_1.BaseException {
|
|
1
|
+
import { BaseException } from '@hg-ts/exception';
|
|
2
|
+
export class ExceptionStatusAlreadyDefinedException extends BaseException {
|
|
6
3
|
constructor(exception) {
|
|
7
4
|
super(`Status for exception "${exception.name}" already defined`);
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
exports.ExceptionStatusAlreadyDefinedException = ExceptionStatusAlreadyDefinedException;
|
|
11
7
|
//# sourceMappingURL=exception-status-already-defined.exception.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exception-status-already-defined.exception.js","sourceRoot":"","sources":["../../src/exceptions/exception-status-already-defined.exception.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"exception-status-already-defined.exception.js","sourceRoot":"","sources":["../../src/exceptions/exception-status-already-defined.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,OAAO,sCAAuC,SAAQ,aAAa;IACxE,YAAmB,SAAsC;QACxD,KAAK,CAAC,yBAAyB,SAAS,CAAC,IAAI,mBAAmB,CAAC,CAAC;IACnE,CAAC;CACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './exception-schema-already-exists.exception';
|
|
2
|
-
export * from './exception-schema-not-found.exception';
|
|
3
|
-
export * from './exception-status-already-defined.exception';
|
|
1
|
+
export * from './exception-schema-already-exists.exception.js';
|
|
2
|
+
export * from './exception-schema-not-found.exception.js';
|
|
3
|
+
export * from './exception-status-already-defined.exception.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":"AAAA,cAAc,gDAAgD,CAAC;AAC/D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,iDAAiD,CAAC"}
|
package/dist/exceptions/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./exception-schema-already-exists.exception"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./exception-schema-not-found.exception"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./exception-status-already-defined.exception"), exports);
|
|
1
|
+
export * from './exception-schema-already-exists.exception.js';
|
|
2
|
+
export * from './exception-schema-not-found.exception.js';
|
|
3
|
+
export * from './exception-status-already-defined.exception.js';
|
|
7
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":"AAAA,cAAc,gDAAgD,CAAC;AAC/D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,iDAAiD,CAAC"}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var HttpControllerModule_1;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const middlewares_1 = require("./middlewares");
|
|
9
|
-
const services_1 = require("./services");
|
|
2
|
+
import { __decorate } from "tslib";
|
|
3
|
+
import { Module, } from '@nestjs/common';
|
|
4
|
+
import { APP_INTERCEPTOR, APP_PIPE, } from '@nestjs/core';
|
|
5
|
+
import { DatabaseInterceptor, ExceptionMapperInterceptor, ValidationPipe, } from './middlewares/index.js';
|
|
6
|
+
import { SwaggerService } from './services/index.js';
|
|
10
7
|
let HttpControllerModule = HttpControllerModule_1 = class HttpControllerModule {
|
|
11
8
|
static forRoot(options = {}) {
|
|
12
9
|
const { disableTransactions = false } = options;
|
|
@@ -16,27 +13,27 @@ let HttpControllerModule = HttpControllerModule_1 = class HttpControllerModule {
|
|
|
16
13
|
? []
|
|
17
14
|
: [
|
|
18
15
|
{
|
|
19
|
-
provide:
|
|
20
|
-
useClass:
|
|
16
|
+
provide: APP_INTERCEPTOR,
|
|
17
|
+
useClass: DatabaseInterceptor,
|
|
21
18
|
},
|
|
22
19
|
],
|
|
23
20
|
};
|
|
24
21
|
}
|
|
25
22
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
(0, common_1.Module)({
|
|
23
|
+
HttpControllerModule = HttpControllerModule_1 = __decorate([
|
|
24
|
+
Module({
|
|
29
25
|
providers: [
|
|
30
|
-
|
|
26
|
+
SwaggerService,
|
|
31
27
|
{
|
|
32
|
-
provide:
|
|
33
|
-
useClass:
|
|
28
|
+
provide: APP_INTERCEPTOR,
|
|
29
|
+
useClass: ExceptionMapperInterceptor,
|
|
34
30
|
},
|
|
35
31
|
{
|
|
36
|
-
provide:
|
|
37
|
-
useClass:
|
|
32
|
+
provide: APP_PIPE,
|
|
33
|
+
useClass: ValidationPipe,
|
|
38
34
|
},
|
|
39
35
|
],
|
|
40
36
|
})
|
|
41
37
|
], HttpControllerModule);
|
|
38
|
+
export { HttpControllerModule };
|
|
42
39
|
//# sourceMappingURL=http-controller.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-controller.module.js","sourceRoot":"","sources":["../src/http-controller.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http-controller.module.js","sourceRoot":"","sources":["../src/http-controller.module.ts"],"names":[],"mappings":";;AAAA,OAAO,EAEN,MAAM,GACN,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,eAAe,EACf,QAAQ,GACR,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,mBAAmB,EACnB,0BAA0B,EAC1B,cAAc,GACd,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAmB9C,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IACzB,MAAM,CAAC,OAAO,CAAC,UAAuC,EAAE;QAC9D,MAAM,EAAE,mBAAmB,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;QAChD,OAAO;YACN,MAAM,EAAE,sBAAoB;YAC5B,SAAS,EAAE,mBAAmB;gBAC7B,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC;oBACD;wBACC,OAAO,EAAE,eAAe;wBACxB,QAAQ,EAAE,mBAAmB;qBAC7B;iBACD;SACF,CAAC;IACH,CAAC;CACD,CAAA;AAfY,oBAAoB;IAbhC,MAAM,CAAC;QACP,SAAS,EAAE;YACV,cAAc;YACd;gBACC,OAAO,EAAE,eAAe;gBACxB,QAAQ,EAAE,0BAA0B;aACpC;YACD;gBACC,OAAO,EAAE,QAAQ;gBACjB,QAAQ,EAAE,cAAc;aACxB;SACD;KACD,CAAC;GACW,oBAAoB,CAehC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Http } from './decorators';
|
|
2
|
-
export { ExceptionService, SwaggerService } from './services';
|
|
3
|
-
export * from './http-controller.module';
|
|
1
|
+
export { Http } from './decorators/index.js';
|
|
2
|
+
export { ExceptionService, SwaggerService } from './services/index.js';
|
|
3
|
+
export * from './http-controller.module.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACvE,cAAc,6BAA6B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
var decorators_1 = require("./decorators");
|
|
6
|
-
Object.defineProperty(exports, "Http", { enumerable: true, get: function () { return decorators_1.Http; } });
|
|
7
|
-
var services_1 = require("./services");
|
|
8
|
-
Object.defineProperty(exports, "ExceptionService", { enumerable: true, get: function () { return services_1.ExceptionService; } });
|
|
9
|
-
Object.defineProperty(exports, "SwaggerService", { enumerable: true, get: function () { return services_1.SwaggerService; } });
|
|
10
|
-
tslib_1.__exportStar(require("./http-controller.module"), exports);
|
|
1
|
+
export { Http } from './decorators/index.js';
|
|
2
|
+
export { ExceptionService, SwaggerService } from './services/index.js';
|
|
3
|
+
export * from './http-controller.module.js';
|
|
11
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACvE,cAAc,6BAA6B,CAAC"}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const logger_1 = require("@hg-ts/logger");
|
|
7
|
-
const common_1 = require("@nestjs/common");
|
|
8
|
-
const rxjs_1 = require("rxjs");
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { KnexService } from '@hg-ts/knex';
|
|
3
|
+
import { Logger } from '@hg-ts/logger';
|
|
4
|
+
import { Catch, Inject, Optional, } from '@nestjs/common';
|
|
5
|
+
import { from, lastValueFrom, } from 'rxjs';
|
|
9
6
|
let DatabaseInterceptor = class DatabaseInterceptor {
|
|
10
7
|
logger;
|
|
11
8
|
postgresService;
|
|
@@ -14,21 +11,21 @@ let DatabaseInterceptor = class DatabaseInterceptor {
|
|
|
14
11
|
this.logger.warning('PostgresService not provided');
|
|
15
12
|
return next.handle();
|
|
16
13
|
}
|
|
17
|
-
const transactionalPromise = this.postgresService.runInTransaction(async () =>
|
|
18
|
-
return
|
|
14
|
+
const transactionalPromise = this.postgresService.runInTransaction(async () => lastValueFrom(next.handle()));
|
|
15
|
+
return from(transactionalPromise);
|
|
19
16
|
}
|
|
20
17
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
(
|
|
24
|
-
tslib_1.__metadata("design:type", logger_1.Logger)
|
|
18
|
+
__decorate([
|
|
19
|
+
Inject(),
|
|
20
|
+
__metadata("design:type", Logger)
|
|
25
21
|
], DatabaseInterceptor.prototype, "logger", void 0);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
__decorate([
|
|
23
|
+
Optional(),
|
|
24
|
+
Inject(),
|
|
25
|
+
__metadata("design:type", KnexService)
|
|
30
26
|
], DatabaseInterceptor.prototype, "postgresService", void 0);
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
DatabaseInterceptor = __decorate([
|
|
28
|
+
Catch()
|
|
33
29
|
], DatabaseInterceptor);
|
|
30
|
+
export { DatabaseInterceptor };
|
|
34
31
|
//# sourceMappingURL=database.interceptor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.interceptor.js","sourceRoot":"","sources":["../../src/middlewares/database.interceptor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"database.interceptor.js","sourceRoot":"","sources":["../../src/middlewares/database.interceptor.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAEN,KAAK,EAEL,MAAM,EAEN,QAAQ,GACR,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACN,IAAI,EACJ,aAAa,GAEb,MAAM,MAAM,CAAC;AAGP,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAEZ,MAAM,CAAS;IAIjB,eAAe,CAAe;IAExC,SAAS,CACf,QAA0B,EAC1B,IAAiB;QAEjB,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,8BAA8B,CAAC,CAAC;YACpD,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;QACtB,CAAC;QACD,MAAM,oBAAoB,GAAG,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,KAAK,IAAG,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAE5G,OAAO,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACnC,CAAC;CACD,CAAA;AAlBmB;IADlB,MAAM,EAAE;8BACkB,MAAM;mDAAC;AAIjB;IAFhB,QAAQ,EAAE;IACV,MAAM,EAAE;8BAC0B,WAAW;4DAAC;AANnC,mBAAmB;IAD/B,KAAK,EAAE;GACK,mBAAmB,CAoB/B"}
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const axios_1 = require("axios");
|
|
10
|
-
const rxjs_1 = require("rxjs");
|
|
11
|
-
const decorators_1 = require("../decorators");
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { BaseException, ErrorException, } from '@hg-ts/exception';
|
|
3
|
+
import { Logger } from '@hg-ts/logger';
|
|
4
|
+
import { ValidationException } from '@hg-ts/validation';
|
|
5
|
+
import { Catch, Inject, } from '@nestjs/common';
|
|
6
|
+
import { isAxiosError } from 'axios';
|
|
7
|
+
import { tap, } from 'rxjs';
|
|
8
|
+
import { EXCEPTION_METADATA_KEY, } from '../decorators/index.js';
|
|
12
9
|
let ExceptionMapperInterceptor = class ExceptionMapperInterceptor {
|
|
13
10
|
logger;
|
|
14
11
|
intercept(context, next) {
|
|
15
|
-
return next.handle().pipe(
|
|
12
|
+
return next.handle().pipe(tap({
|
|
16
13
|
error: error => {
|
|
17
14
|
const response = context.switchToHttp().getResponse();
|
|
18
|
-
if (
|
|
15
|
+
if (isAxiosError(error)) {
|
|
19
16
|
response.status(error.status ?? 500).send(error.response?.data);
|
|
20
17
|
return;
|
|
21
18
|
}
|
|
@@ -28,9 +25,9 @@ let ExceptionMapperInterceptor = class ExceptionMapperInterceptor {
|
|
|
28
25
|
}));
|
|
29
26
|
}
|
|
30
27
|
getExceptionMap(context) {
|
|
31
|
-
const exceptionMap = Reflect.getMetadata(
|
|
32
|
-
if (!exceptionMap.has(
|
|
33
|
-
exceptionMap.set(
|
|
28
|
+
const exceptionMap = Reflect.getMetadata(EXCEPTION_METADATA_KEY, context.getClass().prototype, context.getHandler().name) ?? new Map();
|
|
29
|
+
if (!exceptionMap.has(ValidationException)) {
|
|
30
|
+
exceptionMap.set(ValidationException, 404);
|
|
34
31
|
}
|
|
35
32
|
return exceptionMap;
|
|
36
33
|
}
|
|
@@ -38,21 +35,21 @@ let ExceptionMapperInterceptor = class ExceptionMapperInterceptor {
|
|
|
38
35
|
return Object.getPrototypeOf(exception).constructor;
|
|
39
36
|
}
|
|
40
37
|
getException(exception) {
|
|
41
|
-
if (exception instanceof
|
|
38
|
+
if (exception instanceof BaseException) {
|
|
42
39
|
return exception;
|
|
43
40
|
}
|
|
44
41
|
if (exception instanceof Error) {
|
|
45
|
-
return new
|
|
42
|
+
return new ErrorException(exception);
|
|
46
43
|
}
|
|
47
|
-
return new
|
|
44
|
+
return new ErrorException(new Error(String(exception)));
|
|
48
45
|
}
|
|
49
46
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
(
|
|
53
|
-
tslib_1.__metadata("design:type", logger_1.Logger)
|
|
47
|
+
__decorate([
|
|
48
|
+
Inject(),
|
|
49
|
+
__metadata("design:type", Logger)
|
|
54
50
|
], ExceptionMapperInterceptor.prototype, "logger", void 0);
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
ExceptionMapperInterceptor = __decorate([
|
|
52
|
+
Catch()
|
|
57
53
|
], ExceptionMapperInterceptor);
|
|
54
|
+
export { ExceptionMapperInterceptor };
|
|
58
55
|
//# sourceMappingURL=exception-mapper.interceptor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exception-mapper.interceptor.js","sourceRoot":"","sources":["../../src/middlewares/exception-mapper.interceptor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"exception-mapper.interceptor.js","sourceRoot":"","sources":["../../src/middlewares/exception-mapper.interceptor.ts"],"names":[],"mappings":";AAAA,OAAO,EACN,aAAa,EACb,cAAc,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAEN,KAAK,EAEL,MAAM,GAEN,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAErC,OAAO,EAEN,GAAG,GACH,MAAM,MAAM,CAAC;AACd,OAAO,EACN,sBAAsB,GAEtB,MAAM,wBAAwB,CAAC;AAGzB,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IAEnB,MAAM,CAAS;IAE3B,SAAS,CACf,OAAyB,EACzB,IAAiB;QAEjB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;YAC7B,KAAK,EAAE,KAAK,CAAC,EAAE;gBACd,MAAM,QAAQ,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,WAAW,EAAgB,CAAC;gBAEpE,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;oBACzB,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;oBAEhE,OAAO;gBACR,CAAC;gBACD,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;gBAC3C,MAAM,YAAY,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;gBACnD,MAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;gBACvD,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;gBAE/C,QAAQ,CAAC,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;YACzD,CAAC;SACD,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,eAAe,CAAC,OAAyB;QAChD,MAAM,YAAY,GAAiB,OAAO,CAAC,WAAW,CACrD,sBAAsB,EACtB,OAAO,CAAC,QAAQ,EAAE,CAAC,SAAS,EAC5B,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,CACzB,IAAI,IAAI,GAAG,EAAE,CAAC;QAEf,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAE,CAAC;YAC5C,YAAY,CAAC,GAAG,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,YAAY,CAAC;IACrB,CAAC;IAEO,gBAAgB,CAA0B,SAAY;QAC7D,OAAO,MAAM,CAAC,cAAc,CAAC,SAAS,CAAE,CAAC,WAA8B,CAAC;IACzE,CAAC;IAGO,YAAY,CAAC,SAAkB;QACtC,IAAI,SAAS,YAAY,aAAa,EAAE,CAAC;YACxC,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,IAAI,SAAS,YAAY,KAAK,EAAE,CAAC;YAChC,OAAO,IAAI,cAAc,CAAC,SAAS,CAAC,CAAC;QACtC,CAAC;QAED,OAAO,IAAI,cAAc,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACzD,CAAC;CACD,CAAA;AAtDmB;IADlB,MAAM,EAAE;8BACkB,MAAM;0DAAC;AAFtB,0BAA0B;IADtC,KAAK,EAAE;GACK,0BAA0B,CAwDtC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './validation.pipe';
|
|
2
|
-
export * from './exception-mapper.interceptor';
|
|
3
|
-
export * from './database.interceptor';
|
|
1
|
+
export * from './validation.pipe.js';
|
|
2
|
+
export * from './exception-mapper.interceptor.js';
|
|
3
|
+
export * from './database.interceptor.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middlewares/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middlewares/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,mCAAmC,CAAC;AAClD,cAAc,2BAA2B,CAAC"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./validation.pipe"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./exception-mapper.interceptor"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./database.interceptor"), exports);
|
|
1
|
+
export * from './validation.pipe.js';
|
|
2
|
+
export * from './exception-mapper.interceptor.js';
|
|
3
|
+
export * from './database.interceptor.js';
|
|
7
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middlewares/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middlewares/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,mCAAmC,CAAC;AAClD,cAAc,2BAA2B,CAAC"}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const validation_1 = require("@hg-ts/validation");
|
|
6
|
-
const strict_1 = tslib_1.__importDefault(require("node:assert/strict"));
|
|
7
|
-
class ValidationPipe {
|
|
1
|
+
import { isZodDto, } from '@hg-ts/validation';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
export class ValidationPipe {
|
|
8
4
|
dto;
|
|
9
5
|
constructor(dto) {
|
|
10
6
|
this.dto = dto ?? null;
|
|
@@ -20,9 +16,8 @@ class ValidationPipe {
|
|
|
20
16
|
if (this.dto) {
|
|
21
17
|
return this.dto;
|
|
22
18
|
}
|
|
23
|
-
|
|
19
|
+
assert.ok(isZodDto(metatype));
|
|
24
20
|
return metatype.schema;
|
|
25
21
|
}
|
|
26
22
|
}
|
|
27
|
-
exports.ValidationPipe = ValidationPipe;
|
|
28
23
|
//# sourceMappingURL=validation.pipe.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.pipe.js","sourceRoot":"","sources":["../../src/middlewares/validation.pipe.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validation.pipe.js","sourceRoot":"","sources":["../../src/middlewares/validation.pipe.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,QAAQ,GAER,MAAM,mBAAmB,CAAC;AAO3B,OAAO,MAAM,MAAM,oBAAoB,CAAC;AAExC,MAAM,OAAO,cAAc;IACT,GAAG,CAAiB;IAErC,YAAmB,GAAa;QAC/B,IAAI,CAAC,GAAG,GAAG,GAAG,IAAI,IAAI,CAAC;IACxB,CAAC;IAEM,SAAS,CAAC,KAAc,EAAE,EAAE,QAAQ,EAAoB;QAC9D,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAExC,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAEM,MAAM,CAAC,WAAW;QACxB,OAAO,IAAI,cAAc,EAAE,CAAC;IAC7B,CAAC;IAEO,SAAS,CAAC,QAA4B;QAC7C,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;YACd,OAAO,IAAI,CAAC,GAAG,CAAC;QACjB,CAAC;QAED,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;QAE9B,OAAO,QAAQ,CAAC,MAAM,CAAC;IACxB,CAAC;CACD"}
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ExceptionService = void 0;
|
|
4
|
-
const exceptions_1 = require("../exceptions");
|
|
5
|
-
class ExceptionService {
|
|
1
|
+
import { ExceptionSchemaAlreadyExistsException, ExceptionSchemaNotFoundException, } from '../exceptions/index.js';
|
|
2
|
+
export class ExceptionService {
|
|
6
3
|
static exceptionMap = new Map();
|
|
7
4
|
static registerSchema(exception, schema) {
|
|
8
5
|
if (this.exceptionMap.has(exception)) {
|
|
9
|
-
throw new
|
|
6
|
+
throw new ExceptionSchemaAlreadyExistsException(exception);
|
|
10
7
|
}
|
|
11
8
|
this.exceptionMap.set(exception, schema);
|
|
12
9
|
}
|
|
13
10
|
static getSchema(exception) {
|
|
14
11
|
const schema = this.exceptionMap.get(exception);
|
|
15
12
|
if (!schema) {
|
|
16
|
-
throw new
|
|
13
|
+
throw new ExceptionSchemaNotFoundException(exception);
|
|
17
14
|
}
|
|
18
15
|
return schema;
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
|
-
exports.ExceptionService = ExceptionService;
|
|
22
18
|
//# sourceMappingURL=exception.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exception.service.js","sourceRoot":"","sources":["../../src/services/exception.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"exception.service.js","sourceRoot":"","sources":["../../src/services/exception.service.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,qCAAqC,EACrC,gCAAgC,GAChC,MAAM,wBAAwB,CAAC;AAEhC,MAAM,OAAO,gBAAgB;IACpB,MAAM,CAAU,YAAY,GAAG,IAAI,GAAG,EAAgC,CAAC;IAExE,MAAM,CAAC,cAAc,CAE3B,SAA0B,EAC1B,MAAuC;QAEvC,IAAI,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,qCAAqC,CAAC,SAAS,CAAC,CAAC;QAC5D,CAAC;QAED,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC1C,CAAC;IAEM,MAAM,CAAC,SAAS,CAEtB,SAA0B;QAE1B,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAChD,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,gCAAgC,CAAC,SAAS,CAAC,CAAC;QACvD,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC"}
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './swagger.service';
|
|
2
|
-
export * from './exception.service';
|
|
1
|
+
export * from './swagger.service.js';
|
|
2
|
+
export * from './exception.service.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC"}
|
package/dist/services/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./swagger.service"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./exception.service"), exports);
|
|
1
|
+
export * from './swagger.service.js';
|
|
2
|
+
export * from './exception.service.js';
|
|
6
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC"}
|
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const swagger_1 = require("@nestjs/swagger");
|
|
7
|
-
const schema_object_factory_1 = require("@nestjs/swagger/dist/services/schema-object-factory");
|
|
8
|
-
class SwaggerService {
|
|
1
|
+
import { WillNeverHappenedException } from '@hg-ts/exception';
|
|
2
|
+
import { createSchema, isZodDto, } from '@hg-ts/validation';
|
|
3
|
+
import { DocumentBuilder, SwaggerModule, } from '@nestjs/swagger';
|
|
4
|
+
import { SchemaObjectFactory } from '@nestjs/swagger/dist/services/schema-object-factory.js';
|
|
5
|
+
export class SwaggerService {
|
|
9
6
|
setup(app) {
|
|
10
7
|
this.patchSwaggerModule();
|
|
11
|
-
const config = new
|
|
8
|
+
const config = new DocumentBuilder()
|
|
12
9
|
.setOpenAPIVersion('3.0.0')
|
|
13
10
|
.build();
|
|
14
|
-
const document =
|
|
15
|
-
|
|
11
|
+
const document = SwaggerModule.createDocument(app, config);
|
|
12
|
+
SwaggerModule.setup('/api', app, document, { jsonDocumentUrl: '/api/json' });
|
|
16
13
|
}
|
|
17
14
|
patchSwaggerModule() {
|
|
18
|
-
|
|
19
|
-
if (!
|
|
20
|
-
throw new
|
|
15
|
+
SchemaObjectFactory.prototype.exploreModelSchema = function (type, schemas) {
|
|
16
|
+
if (!isZodDto(type)) {
|
|
17
|
+
throw new WillNeverHappenedException('Type will be zod schema');
|
|
21
18
|
}
|
|
22
|
-
schemas[type.name] =
|
|
19
|
+
schemas[type.name] = createSchema(type.schema, { io: 'input' }).schema;
|
|
23
20
|
return type.name;
|
|
24
21
|
};
|
|
25
22
|
}
|
|
26
23
|
}
|
|
27
|
-
exports.SwaggerService = SwaggerService;
|
|
28
24
|
//# sourceMappingURL=swagger.service.js.map
|